Viewing -terms through Maps Masahiko Sato Kyoto University Randy - - PowerPoint PPT Presentation

viewing terms through maps
SMART_READER_LITE
LIVE PREVIEW

Viewing -terms through Maps Masahiko Sato Kyoto University Randy - - PowerPoint PPT Presentation

Viewing -terms through Maps Viewing -terms through Maps Masahiko Sato Kyoto University Randy Pollack Harvard University Helmut Schwichtenberg University of Munich Takafumi Sakurai Chiba University Version of April 28, 2013 Viewing


slide-1
SLIDE 1

Viewing λ -terms through Maps

Viewing λ-terms through Maps

Masahiko Sato

Kyoto University

Randy Pollack

Harvard University

Helmut Schwichtenberg

University of Munich

Takafumi Sakurai

Chiba University

Version of April 28, 2013

slide-2
SLIDE 2

Viewing λ -terms through Maps

Outline

Motivation The Intuition Maps Lambda terms with maps Syntax and well formedness Hole filling Use of parameters Λ : Raw λ -terms Working with Λ The βη -calculus Conclusion

slide-3
SLIDE 3

Viewing λ -terms through Maps Motivation

Motivation: Formal representation of binding with natural reasoning

◮ Concrete: inductively definable in (say) Coq and HOL.

◮ Eliminates nominal: needs extensionality and quotients.

◮ Canonical: α -equivalence is identity.

◮ Eliminates McKinna and Pollack representation (from 1993).

◮ Reasoning: structural.

◮ Eliminates pure de Bruijn.

◮ Reasoning without equivariance, name swapping, special

derived induction principles, etc.

◮ Eliminates locally nameless and Sato canonical representations.

??? The representation of this talk makes some progress.

slide-4
SLIDE 4

Viewing λ -terms through Maps The Intuition

Intuition: Maps for binding

◮ Maps generalize the notion of occurrance. ◮ Maps are binary trees over 0 and 1 . ◮ Example:

◮ Occurrences of x in (xz)(yz)

represented by map (10)(00) .

◮ Occurrences of z in (xz)(yz)

represented by map (01)(01) .

λ -term S = λxyz. (xz)(yz) is represented (10 00)\(00 10)\(01 01)\(✷✷ ✷✷) (We drop some parentheses for readability.)

◮ Bound positions represented only by constant ✷ (called box).

slide-5
SLIDE 5

Viewing λ -terms through Maps The Intuition

Open terms

✷ may occur unbound.

✷ is a distinguished constant.

◮ We accept ✷ as a term. ◮

1\✷ represents λz.z .

0\✷ represents λx.z .

Unbound box is available for binding or substitution,

1\0\✷ represents λz.λx.z .

◮ Free variables may occur in terms,

◮ the informal term λz.(xz) is written as (0 1)\(x ✷) .

◮ There are no bound names or de Bruijn indices.

slide-6
SLIDE 6

Viewing λ -terms through Maps The Intuition

Well-formedness conditions needed

◮ Free variables cannot be bound:

◮ maps can only bind ✷ , ◮

0\x is a term, 1\x is not a term.

◮ We will show how to bind names.

◮ Want canonical representation: one representative per λ -term.

0\1\✷ is our notation for λx.λx.x (which equals λy.λx.x )

1\1\✷ is not a term.

◮ Substitution: Consider the term (0 1)\(✷ ✷) ;

◮ position (1 0) (the red ✷ ) is free, ◮ substitute (✷ ✷) in that position, ◮ get (0 1)\((✷ ✷) ✷) which is not a term because 0 is not a

position in (✷ ✷) .

◮ The solution: identify maps 0 and (0 0) .

slide-7
SLIDE 7

Viewing λ -terms through Maps The Intuition

Compare with other notations

◮ Abstraction by names (raw terms or nominal terms):

◮ Binding information shared between binding occurrences and

bound occurrences (shared names).

◮ Substitution may require α -conversion of the base term.

◮ Abstraction by indexes (de Bruijn):

◮ Binding information only at bound occurrences (indexes). ◮ At binding point, only λ to mark structure. ◮ Substitution may require de Bruijn lifting of the implanted term.

◮ Abstraction by maps:

◮ Binding information only at binding occurrences (maps). ◮ At bound points, only ✷ to mark structure. ◮ No adjustment required for substitution.

slide-8
SLIDE 8

Viewing λ -terms through Maps The Intuition

Formalization

◮ Everything that follows is formalized in Isabelle/HOL.

◮ The apparent quotients and partial functions are coded in HOL

without any actual quotienting of datatypes or “domain predicates”

  • f functions.

◮ Correctness of the map representation is proved w.r.t. Nominal

Isabelle.

◮ Independently, correctness of the map representation is proved

w.r.t. de Bruijn nameless terms in Minlog.

◮ However our favorite form of the map approach is not

representable in HOL or easily representable in Coq:

◮ Requires induction-recursion or induction-induction.

slide-9
SLIDE 9

Viewing λ -terms through Maps Maps

Maps, M, defined inductively

◮ Maps are binary trees over 0 and 1 , with the identification

(0 0) = 0 .

◮ Can formalize this inductively without quotienting using an

auxiliary type M+ not containing 0 : 1 ∈ M+ m+ ∈ M+ inl(m+) ∈ M+ n+ ∈ M+ inr(n+) ∈ M+ m+ ∈ M+ n+ ∈ M+ cons(m+, n+) ∈ M+

◮ Extend M+ with 0 to get M

0 ∈ M m+ ∈ M+ m+ ∈ M

slide-10
SLIDE 10

Viewing λ -terms through Maps Maps

Map application

◮ For “cons” on M we define:

mapp(m, n) :=        if m = n = 0, inl(m) if m = 0 and n = 0, inr(n) if m = 0 and n = 0, cons(m, n) if m = 0 and n = 0. (Eliding explicit inclusion of M+ in M .)

◮ Write (m n) for mapp(m, n) , (m1m2 m3) for ((m1 m2) m3) , etc. ◮

mapp is injective.

slide-11
SLIDE 11

Viewing λ -terms through Maps Maps

Orthoganality on maps

◮ A symmetric orthogonality relation ⊥ :

m ⊥ 0 0 ⊥ n m ⊥ n m′ ⊥ n′ mm′ ⊥ nn′

m ⊥ n means:

m and n have the same shape

m and n bind different positions in that shape.

0 has every shape and binds no positions.

slide-12
SLIDE 12

Viewing λ -terms through Maps Lambda terms with maps Syntax and well formedness

Lambda terms as a subtype

◮ Symbolic expressions ( S ) are raw syntax:

x ∈ S ✷ ∈ S S ∈ S T ∈ S (S T) ∈ S m ∈ M S ∈ S m\S ∈ S

◮ Well formedness ( m | S ; m divides S ):

0 | x 0 | ✷ 1 | ✷ m | S n | T mn | ST m | T n | T m ⊥ n m | (n\T)

m | S means “ S is well-formed and m is a position of unbound boxes in S ”.

m | S = ⇒ 0 | S .

0 | S means “ S is well formed”.

slide-13
SLIDE 13

Viewing λ -terms through Maps Lambda terms with maps Syntax and well formedness

Aside: Syntax and well-formedness simultaneously

L is a type. x ∈ L ✷ ∈ L M ∈ L N ∈ L (M N) ∈ L m ∈ M M ∈ L m | M m\M ∈ L

◮ Divides is a relation | ⊆ M × L .

0 | x 0 | ✷ 1 | ✷ m | M n | N (m n) | (M N) m | N n | N m ⊥ n m | (n\N)

◮ Not simultaneous inductive definition due to L in the type of | . ◮ Need induction-induction or induction-recursion to formalize.

slide-14
SLIDE 14

Viewing λ -terms through Maps Lambda terms with maps Hole filling

Hole filling

◮ Define the partial operation Mm[P] : L × M × L → L :

✷1[P] := P. ✷0[P] := ✷. x0[P] := x. (M N)(m n)[P] := (Mm[P] Nn[P]) if m | M and n | N. (n\N)m[P] := n\(Nm[P]) if m | (n\N).

◮ Only defined if m | M ( m is a position of unbound holes in M ). ◮ Hole filling is a homomorphism, even going under binders. ◮ Hole filling respects well-formedness:

m | M ∧ 0 | N = ⇒ 0 | Mm[N].

◮ Why is the last equation well-formed?

slide-15
SLIDE 15

Viewing λ -terms through Maps Lambda terms with maps Use of parameters

Parameters: map, skeleton, abstraction

◮ map, Mx , computes the map of all the occurrences of x in M . ◮ skel, Mx , replaces all occurrences of x in M by ✷ .

map : X × L → M skel : X × L → L yx := 1 if x = y, if x = y. yx := ✷ if x = y, y if x = y. ✷x := 0. ✷x := ✷. (M N)x := (Mx Nx). (M N)x := (Mx Nx). (m\M)x := Mx. (m\M)x := m\Mx.

◮ With map and skel can define abstraction of a name from a term.

lam(x, M) := Mx\Mx

lam(x, M) does not contain x .

slide-16
SLIDE 16

Viewing λ -terms through Maps Lambda terms with maps Use of parameters

Substitution defined by hole filling

subst : L × X × L → L M{x\P} := (Mx)Mx[P].

◮ Some provable equations of substitution

y{x\P} = P if x = y, y if x = y. ✷{x\P} = ✷. (M N){x\P} = (M{x\P} N{x\P}) if 0 | M and 0 | N. (m\M){x\P} = (m\M{x\P}) if m | M.

◮ These equations eliminate substitution on concrete terms. ◮ Substitution is a homomorphism.

◮ There are no name-freshness conditions on these equations.

slide-17
SLIDE 17

Viewing λ -terms through Maps Lambda terms with maps Use of parameters

Substitution lemma of λ-calculus: better proof

If x = y and x ♯ P , then M{x\N}{y\P} = M{y\P}{x\N{y\P}}.

◮ In named representations (including locally nameless and

nominal) this proof requires choosing a fresh name.

◮ When M = λz.M′ we must assume z ♯ (x, y, N, P) ◮ By equivariance, strengthened induction principle, . . .

Our proof

◮ By induction on (well-formedness of) M . ◮ Each case completely solved by equational reasoning.

◮ Using the equations of substitution and the IH. ◮ No need for fresh names to appy the equations of substitution.

slide-18
SLIDE 18

Viewing λ -terms through Maps Λ : Raw λ -terms

Datatype Λ of raw λ-syntax

x ∈ Λ ✷ ∈ Λ K ∈ Λ L ∈ Λ (K L) ∈ Λ K ∈ Λ lam(x, K) ∈ Λ

◮ Define map ( Kx ) and skel ( K x ) on Λ

Kx computes the map of occurrences of x in K .

K x replaces every x in K with ✷ . map : X × λ → M skel : X × λ → λ yx :=

  • 1

if x = y, if x = y. yx :=

if x = y, y if x = y. ✷x := 0. ✷x := ✷. (K L)x := (Kx Lx). (K L)x := (K x Lx). lam(y, K)x := if x = y, Kx if x = y. lam(y, K)x := lam(y, K) if x = y, lam(y, K x) if x = y.

slide-19
SLIDE 19

Viewing λ -terms through Maps Λ : Raw λ -terms Working with Λ

α-equivalence on Λ

α -equivalence is defined as a relation: x =α x ✷ =α ✷ K =α K ′ L =α L′ (K L) =α (K ′ L′) Kx = Ly K x =α Ly lam(x, K) =α lam(y, L)

◮ In the paper we prove this corresponds to a standard definition.

◮ Messy proof, like any reasoning about Λ .

=α is clearly decidable.

◮ No fresh names or name swapping is required to decide =α . . .

◮ . . . but the proof of correctness uses fresh names and

equivariance of =α .

slide-20
SLIDE 20

Viewing λ -terms through Maps Λ : Raw λ -terms Working with Λ

Substitution on Λ, defined as a relation

x{x\J} → J x = y y{x\J} → y ✷{x\J} → ✷ K{x\J} → L K ′{x\J} → L′ (K K ′){x\J} → (L L′) z ♯ {x, J} K{x\J} → L lam(z, K){x\J} → lam(z, L) K =α K ′ J =α J′ K ′{x\J′} → L′ L′ =α L K{x\J} → L

◮ Correctness of substitution:

◮ (Existence) ∃L . K{x\J} → L . ◮ (Uniqueness and Congruence)

K{x\J} → L J =α J′ K =α K ′ K ′{x\J′} → L′) ⇔ L =α L′

◮ Messy proof, like any reasoning about Λ .

slide-21
SLIDE 21

Viewing λ -terms through Maps Λ : Raw λ -terms Working with Λ

Relation between L and Λ

◮ View raw terms as names for ideal terms in L .

◮ A raw term K denotes an ideal term [

[K] ] . [ [x] ] := x. [ [✷] ] := ✷. [ [(K L)] ] := ([ [K] ] [ [L] ]). [ [lam(x, K)] ] := lam(x, [ [K] ]).

◮ (Recall the definition lam(x, M) := Mx\Mx .)

◮ Properties of denotation (have been proven directly)

  • 1. M ∈ L =

⇒ ∃K ∈ Λ . [ [K] ] = M . (Every term has a name.)

  • 2. K =α L ⇐

⇒ [ [K] ] = [ [L] ] . ( α -equivalent names denote same term.)

  • 3. K{x\J} → L ⇐

⇒ [ [K] ]{x\[ [J] ]} = [ [L] ] . (Denotation commutes with substitution.)

slide-22
SLIDE 22

Viewing λ -terms through Maps Λ : Raw λ -terms Working with Λ

Correctness of L w.r.t. Nominal Isabelle

◮ Define an inverse to [

[·] ] [ [·] ] : Nom → L ⌊·⌋ : L → Nom [ [x] ] := x ⌊x⌋ := x [ [✷] ] := ✷ ⌊✷⌋ := ✷ [ [(K L)] ] := ([ [K] ] [ [L] ]) ⌊(M1 M2)⌋ := (⌊M1⌋ ⌊M2⌋) [ [lam(x, K)] ] := lam(x, [ [K] ]) ⌊m\M⌋ := lam(x, ⌊Mm[x]⌋) if x ♯ M.

◮ To get a name for m\M , fill hole m in M with fresh parameter

x , compute a name for that term, then abstract x .

[ [·] ] and ⌊·⌋ are provably functions.

◮ Depends on α being identity in nominal.

[ [·] ] and ⌊·⌋ are inverses.

[ [K{x\J}] ] = [ [K] ]{x\[ [J] ]}.

slide-23
SLIDE 23

Viewing λ -terms through Maps The βη -calculus

βη -reduction

(n\N)M →βη Nn[M] β (01\M✷) →βη M η M →βη M′ MN →βη M′N appl N →βη N′ MN →βη MN′ appr M →βη N lam(x, M) →βη lam(x, N) ξ

◮ Implicitly assuming every term is well-formed.

slide-24
SLIDE 24

Viewing λ -terms through Maps The βη -calculus

η rule is name-free

(01\M✷) →βη M η

η rule is about abstraction, not about parameters.

◮ Informal η -rule requires freshness condition x ∈ FP(M) .

x ∈ FP(M) lam(x, Mx) →βη M η

◮ Even canonical representations like de Bruijn need this condition. ◮ Map representation avoids this because

lam(x, Mx) = 01\M✷ if x ∈ FP(M) .

slide-25
SLIDE 25

Viewing λ -terms through Maps The βη -calculus

β rule is name-free

(n\N)M →βη Nn[M] β

β rule is about abstraction and hole filling, not about parameters.

◮ But, β rule is name free only by accident . . .

◮ . . . same abstraction on both sides of the relation. ◮ Rule β of parallel reduction does not have this property.

◮ In the informal β -rule

(λx. M) K →βη M{x\K} β schematic parameter x is bound on the left hand side, and free

  • n the right hand side.
slide-26
SLIDE 26

Viewing λ -terms through Maps The βη -calculus

ξ rule not name-free

M →βη N lam(x, M) →βη lam(x, N) ξ

◮ A name bound in the conclusion is free in the premise.

(1\✷)x →βη x lam(x, (1\✷)x) →βη lam(x, x)

◮ An incorrect name free rule ξ :

M →βη N m\M →βη m\N

◮ A different correct rule ξ :

x ♯ (M, N) Mm[x] →βη Nn[x] m\M →βη n\N

slide-27
SLIDE 27

Viewing λ -terms through Maps The βη -calculus

Why do we care about rules being name-free?

◮ Try to prove

M1 →βη M2 = ⇒ M1{x\N} →βη M2{x\N} by rule induction on M1 →βη M2 .

◮ Case for rule ξ , where M1 = λy. P : ◮ Must α -convert M1 so that y ♯ (x, N) , allowing substitution to go

under the binder so the induction hypothesis can be used.

◮ Requires equivariance and name-swapping: a well-known can of

worms.

◮ One goal of map representation is to avoid equivariance

reasoning.

◮ Rule ξ is not the only problematic rule.

◮ E.g. β rule in parallel reduction.

◮ An outstanding problem for map representation.

slide-28
SLIDE 28

Viewing λ -terms through Maps The βη -calculus

Work in Progress: Defining →β to support rule induction without name swapping.

◮ The relation →β must be annotated to pass information around

the derivation tree.

◮ But will such an approach solve the problem?

◮ Consider our example above:

M1

σ

− → M2 = ⇒ M1{x\N}

?

− → M2{x\N} Whatever annotation we use for σ we must know how to compute the new annotation ? , since the RHS is a different derivation.

◮ Following two suggestions:

◮ One by Steve Chong passes a map around as σ . ◮ One by James McKinna passes a number (of binders we are

working under) around.

slide-29
SLIDE 29

Viewing λ -terms through Maps Conclusion

Conclusion

◮ A canonical presentation of λ -terms using maps.

◮ Proved correct w.r.t. nominal terms (in Isabelle). ◮ Proved correct w.r.t. pure de Bruijn (in Minlog, not discussed

here),

◮ Substitution lemma proved without renaming.

◮ Used maps to study raw λ syntax.

◮ Decide α -conversion without renaming. ◮ Substitution defined and studied. ◮ Relationship with map-terms proved.

◮ Used maps to study de Bruijn terms (not discussed here). ◮

βη -reduction of map-terms defined.

◮ Some rules are pretty in this presentation. ◮ Work in progress: we do not yet have more elegant rule induction

than the usual equivariance approach.