Relating Nominal and Higher-order Abstract Syntax Specifications Andrew Gacek INRIA Saclay - Île-de-France & LIX/École polytechnique PPDP’10 July 26–28, 2010 Hagenberg, Austria
Relating the nominal and HOAS worlds Many approaches to formalizing systems with binding structure Nominal: names, name-abstraction, freshness, N -quantifier HOAS: λ -terms, raising, ∇ -quantifier Some convergence: Nominal vs higher-order pattern unification [Cheney 2005, Levy and Villaret 2008] Difficulties: α Prolog vs λ Prolog Current work: a translation from α Prolog to G − and from λ Prolog to G −
α Prolog example Encoding of λ -terms � λ x .λ y . x y lam ( � a � lam ( � b � app ( var ( a ) , var ( b )))) Type checking for λ -terms tc ( G , var ( X ) , A ) : − lookup ( X , A , G ) tc ( G , app ( M , N ) , B ) : − ∃ A . tc ( G , M , arr ( A , B )) ∧ tc ( G , N , A ) tc ( G , lam ( � x � E ) , arr ( A , B )) : − x # G ∧ tc ( bind ( x , A , G ) , E , B ) N x . ∀ G . ∀ E . ∀ A . ∀ B . tc ( G , lam ( � x � E ) , arr ( A , B )) : − x # G ∧ tc ( bind ( x , A , G ) , E , B )
α Prolog basics Syntax t , u ::= a | X | f ( � t ) | ( a b ) · t | � a � t t ) | a # t | t ≈ u | G ∧ G ′ | G ∨ G ′ | ∃ X . G | G ::= ⊤ | p ( � N a . G a . ∀ � N X . [ p ( � � D ::= t ) : − G ] Notions Swapping: ( a b ) · ( � a � b ) = � b � a Freshness: a # � a � t α -Equivalence: � a � a ≈ � b � b Variable capture: N a . ∃ X . � a � X ≈ � b � b has solution X �→ a
α Prolog rules | = a # t | = t ≈ u ⇒ ⊤ TRUE ⇒ a # t FRESH ⇒ t ≈ u EQUAL ∆ = ∆ = ∆ = ∆ = ⇒ G 1 ∆ = ⇒ G 2 ∆ = ⇒ G i AND OR ∆ = ⇒ G 1 ∧ G 2 ∆ = ⇒ G 1 ∨ G 2 ∆ = ⇒ G [ t / X ] ⇒ G ∆ = EXISTS a . G NEW N ∆ = ⇒ ∃ X . G ∆ = ⇒ ∆ = ⇒ π. ( G θ ) BACKCHAIN ⇒ p ( � ∆ = t ) a . ∀ � Where N u ) : − G ] ∈ ∆ and π is a permutation and θ is � X . [ p ( � a substitution for � X such that � u θ ) . t ≈ π. ( �
G − example Encoding of λ -terms � λ x .λ y . x y lam ( λ x . lam ( λ y . app ( var x ) ( var y ))) Type checking for λ -terms tc G ( var X ) A � lookup X A G tc G ( app M N ) B � ∃ A . tc G M ( arr A B ) ∧ tc G N A tc G ( lam λ x . E x ) ( arr A B ) � ∇ x . tc ( bind x A G ) ( E x ) B
G − basics Syntax t , u ::= x | c | a | ( t u ) | λ x . t B , C ::= ⊤ | p � t | t = u | B ∧ C | B ∨ C | ∃ x . B | ∇ z . B D ::= ∀ � x . [( ∇ � z . p � u ) � B ] Notions Equality is λ -conversion: λ a . a = λ b . b , ( λ x . t ) u = t [ u / x ] Capture-avoiding substitution: ∃ X .λ a . X = λ b . b has no solution.
G − rules → ⊤ ⊤R → t = t = R − − − → B 1 − → B 2 − → B i ∧R → B 1 ∨ B 2 ∨R − → B 1 ∧ B 2 − − → B [ t / x ] − → B [ a / x ] → ∇ x . B ∇R , a / ∈ supp ( B ) ∃R − → ∃ x . B − − → B θ t def R → p � − Where ∀ � u ) � B ] ∈ D and θ is a substitution for � z and x . [( ∇ � z . p � � x such that each z i θ is a unique nominal constant, z θ } = ∅ , and � u θ . supp ( � x θ ) ∩ { � t = �
A Naive Translation � N � � = �·�· ∇ ≈ λ Problem N � a . ∃ X . � a � X ≈ � b � b ∇ a . ∃ X .λ a . X = λ b . b The first has solution X �→ a , the second has no solution Solution Use raising to explicitly encode dependencies: N � a . ∃ X . � a � X ≈ � b � b ∃ X .λ a . X a = λ b . b Now the second formula has solution X �→ λ y . y
Freshness There is no direct analog of a # t in G − But we can define it: ∀ E . ( ∇ x . fresh x E ) � ⊤ x is quantified inside the scope of E so no substitution for E can contain the value of x
Translation for terms t )) = f − − → φ ( f ( � φ ( a ) = a φ ( t ) φ ( � a � t ) = λ a .φ ( t ) φ ( X � a ) = X � φ (( a b ) · t ) = ( a b ) · φ ( t ) a Example lam ( � a � lam ( � b � app ( X , ( a b ) · X ))) � lam ( λ a . lam ( λ b . app ( X a b ) ( X b a ))))
Translation for goals and clauses φ � a ( ⊤ ) = ⊤ a . p − − → a ( p � t ) = ∇ � φ � φ ( t ) a ( a # t ) = ∇ � φ � a . fresh φ ( a ) φ ( t ) a ( t ≈ u ) = ∇ � φ � a . ( φ ( t ) = φ ( u )) φ � a ( G 1 ∧ G 2 ) = φ � a ( G 1 ) ∧ φ � a ( G 2 ) φ � a ( G 1 ∨ G 2 ) = φ � a ( G 1 ) ∨ φ � a ( G 2 ) a ( G [ X � φ � a ( ∃ X . G ) = ∃ X .φ � a / X ]) N φ � a ( b . G ) = φ � ab ( G ) a . p − − − → � � a . ∀ � = ∀ � N X . [ p ( � � X . [( ∇ � φ ( t σ )) � φ � φ t ) : − G ] a ( G σ ))] a / X | X ∈ � where σ = { X � X }
Correctness of the translation Theorem (Soundness) If ∆ = ⇒ G then − → φ ( G ) with the definitions φ (∆) Theorem (Completeness) If − → φ ( G ) with the definitions φ (∆) then ∆ = ⇒ G
Type checking example tc ( G , var ( X ) , A ) : − lookup ( X , A , G ) tc ( G , app ( M , N ) , B ) : − ∃ A . tc ( G , M , arr ( A , B )) ∧ tc ( G , N , A ) tc ( G , lam ( � x � E ) , arr ( A , B )) : − x # G ∧ tc ( bind ( x , A , G ) , E , B ) tc G ( var X ) A � lookup X A G tc G ( app M N ) B � ∃ A . tc G M ( arr A B ) ∧ tc G N A ( ∇ x . tc ( G x ) ( lam λ x . E x ) ( arr ( A x ) ( B x ))) � ( ∇ x . fresh x ( G x )) ∧ ( ∇ x . tc ( bind x ( A x ) ( G x )) ( E x ) ( B x ))
Simplifications ( ∇ x . tc ( G x ) ( lam λ x . E x ) ( arr ( A x ) ( B x ))) � ( ∇ x . fresh x ( G x )) ∧ ( ∇ x . tc ( bind x ( A x ) ( G x )) ( E x ) ( B x )) 1. Statically solve freshness constraint: ( ∇ x . tc G ( lam λ x . E x ) ( arr ( A x ) ( B x ))) � ∇ x . tc ( bind x ( A x ) G ) ( E x ) ( B x ) 2. Use subordination to elimination vacuous raisings: ( ∇ x . tc G ( lam λ x . E x ) ( arr A B )) � ∇ x . tc ( bind x A G ) ( E x ) B 3. Remove vacuous ∇ s: tc G ( lam λ x . E x ) ( arr A B ) � ∇ x . tc ( bind x A G ) ( E x ) B
Extending the translation α Prolog allows arbitrary abstraction and swapping: � u � t ( u 1 u 2 ) · t t ′ ≈ � u � t � abst u t t ′ t ′ ≈ ( u 1 u 2 ) · t � swap u 1 u 2 t t ′ ∀ E . ( ∇ x . abst x ( E x ) ( λ x . E x )) � ⊤ ∀ E . ( ∇ x , y . swap x y ( E x y ) ( E y x )) � ⊤ ∀ E . ( ∇ x . swap x x ( E x ) ( E x )) � ⊤
Going fully higher-order Encoding of λ -terms � λ x .λ y . x y lam λ x . lam λ y . app x y Type checking for λ -terms in λ Prolog tc ( app M N ) B : − tc M ( arr A B ) ∧ tc N A tc ( lam λ x . R x ) ( arr A B ) : − ∀ x . tc x A ⇒ tc ( R x ) B Free lemma If ∆ ⊢ tc ( lam λ x . R x ) ( arr A B ) and ∆ ⊢ tc N A then ∆ ⊢ tc ( R N ) B
λ Prolog in G − seq L ⊤ � ⊤ seq L ( B ∧ C ) � seq L B ∧ seq L C seq L ( A ⇒ B ) � seq ( A :: L ) B seq L ( ∀ x . B x ) � ∇ x . seq L ( B x ) seq L � A � � member A L seq L � A � � ∃ B . prog A B ∧ seq L B prog ( tc ( app M N ) B ) ( � tc M ( arr A B ) � ∧ � tc N A � ) � ⊤ prog ( tc ( lam λ x . R x ) ( arr A B )) ( ∀ x . tc x A ⇒ � tc ( R x ) B � ) � ⊤
Future Work ◮ Reverse translation [Cheney 2005] ◮ Mixing G − and λ Prolog specifications ◮ Reasoning about α Prolog via G ◮ Identifying special subclasses of α Prolog specifications ◮ Unification, specification, reasoning
Recommend
More recommend