a variant of higher order anti unification
play

A Variant of Higher-Order Anti-Unification Alexander Baumgartner - PowerPoint PPT Presentation

A Variant of Higher-Order Anti-Unification Alexander Baumgartner Temur Kutsia Jordi Levy Mateu Villaret Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification Anti-Unification Problem Given two terms t 1 , t 2 .


  1. A Variant of Higher-Order Anti-Unification Alexander Baumgartner Temur Kutsia Jordi Levy Mateu Villaret Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  2. Anti-Unification Problem ◮ Given two terms t 1 , t 2 . ◮ Find a generalization term t such that t 1 , t 2 are instances of t . ◮ Interesting generalizations are the least general ones (lggs). Input terms f ( a , g ( b ) , b ) and f ( a , g ( c ) , c ) Generalization f ( a , x , y ) Lgg f ( a , g ( x ) , x ) Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  3. Goal / Setting ◮ The Setting: ◮ Input: Simply-typed lambda terms t 1 , t 2 . ◮ Output: Simply-typed higher-order pattern generalization of t 1 , t 2 . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  4. Goal / Setting ◮ The Setting: ◮ Input: Simply-typed lambda terms t 1 , t 2 . ◮ Output: Simply-typed higher-order pattern generalization of t 1 , t 2 . ◮ Provide an anti-unification algorithm to compute lggs: ◮ Design algorithm, ◮ Prove correctness, ◮ Complexity analysis, ◮ Implementation. Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  5. Simply Typed Lambda Calculus ◮ Basic types: δ 1 , δ 2 , . . . ◮ Type constructor: → ◮ Types: τ ::= δ | τ → τ ◮ Variables: X , Y , x , y , . . . ◮ Constants: c , f , g , . . . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  6. Simply Typed Lambda Calculus ◮ λ -terms ( t , s , . . . ) are built using the grammar: t ::= x | c | λ x . t | t 1 t 2 ◮ Terms are assumed to be written in η -long β -normal form: t = λ x 1 , . . . , x n . h ( t 1 , . . . , t m ) were h ( t 1 , . . . , t m ) has a basic type and h is a constant or variable. ◮ The head of t is defined as Head ( t ) = h . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  7. Substitution and Generalization Definition (Substitution σ ) Finite set of pairs { X 1 �→ t 1 , . . . , X n �→ t n } where X i and t i have the same type and the X ’s are pairwise distinct variables. ◮ t σ for substitution application. ◮ t � s if there exists σ such that t σ = s . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  8. Substitution and Generalization Definition (Substitution σ ) Finite set of pairs { X 1 �→ t 1 , . . . , X n �→ t n } where X i and t i have the same type and the X ’s are pairwise distinct variables. ◮ t σ for substitution application. ◮ t � s if there exists σ such that t σ = s . Definition (Generalization and least general generalization) A term t is a generalization of t 1 and t 2 , if t � t 1 and t � t 2 . It is a lgg, if there is no generalization s which satisfies t ≺ s . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  9. Higher-Order Patterns ◮ In general, there is no unique higher-order lgg. Input terms: f ( g ( a , b ) , c ) and f ( c , h ( a )) Higher-order lggs: f ( X , Y ), X ( c , Y ( a )) and X ( Y ( a ) , c ) ◮ Consider special classes to guarantee uniqueness. Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  10. Higher-Order Patterns ◮ In general, there is no unique higher-order lgg. Input terms: f ( g ( a , b ) , c ) and f ( c , h ( a )) Higher-order lggs: f ( X , Y ), X ( c , Y ( a )) and X ( Y ( a ) , c ) ◮ Consider special classes to guarantee uniqueness. Definition (Higher-order pattern) Arguments of free variables are distinct bound variables. ◮ λ x . f ( X ( x ) , Y ), f ( c , λ x . x ) and λ x .λ y . X ( λ z . x ( z ) , y ) are patterns. ◮ λ x . f ( X ( X ( x )) , Y ), f ( X ( c ) , c ) and λ x .λ y . X ( x , x ) are not patterns. Input terms: f ( g ( a , b ) , c ) and f ( c , h ( a )) Pattern-lgg: f ( X , Y ) Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  11. Input / Output ◮ Input: Higher-order terms t 1 and t 2 in η -long β -normal form. ◮ Output: Unique higher-order pattern generalization of t 1 and t 2 . λ x , y . f ( g ( x , x , y ) , g ( x , y , y )) Input terms λ x , y . f ( h ( x , x , y ) , h ( x , y , y )) Pattern-lgg λ x , y . f ( Y 1 ( x , y ) , Y 2 ( x , y )) No pattern λ x , y . f ( Z ( x , x , y ) , Z ( x , y , y )) Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  12. Anti-Unification Problem (AUP) Definition (Anti-unification problem) x ) : t � s where An anti-unification problem is a triple X ( # » ◮ λ # x . X ( # » x ), λ # » x . t , and λ # » » x . s are terms of the same type, ◮ t and s are in η -long β -normal form, ◮ X does not occur in t and s . Example: X ( x , y ) : f ( x , x , y ) � g ( x , x , y ) Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  13. Rule Based System P ◮ P operates on a triple A ; S ; σ . ◮ A is a set of AUPs like { X 1 ( #» x 1 ) : t 1 � s 1 , . . . , X n ( #» x n ) : t n � s n } . ◮ S is a set of already solved AUPs (the store). ◮ σ is a substitution which maps variables to patterns. ◮ Each generalization variable X i occurs only once in A ∪ S . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  14. Compute Pattern Generalization ◮ Initialize A ; S ; σ with { X : t � s } ; ∅ ; ε where X is fresh variable. ◮ Apply the rules of P successively as long as possible. ◮ Final system has the form ∅ ; S ; σ . ◮ Result X σ is a pattern-lgg. ◮ Computed pattern-lgg is unique modulo α -equivalence. ◮ S contains all the differences between t and s . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  15. The Rules of P ◮ Y’s always denote fresh variables of the corresponding types. ◮ Dec: Decomposition x ) : h ( t 1 , . . . , t m ) � h ( s 1 , . . . , s m ) } · { X ( # » ∪ A ; S ; σ = ⇒ x ) : t 1 � s 1 , . . . , Y m ( # x ) : t m � s m } ∪ A ; S ; { Y 1 ( # » » σ { X �→ λ # x . h ( Y 1 ( # » x ) , . . . , Y m ( # » » x )) } , where h is a constant or h ∈ # » x . ◮ Abs: Abstraction { X ( # x ) : λ y . t � λ z . s } · » ∪ A ; S ; σ = ⇒ { Y ( # x , y ) : t � s { z �→ y }} ∪ A ; S ; σ { X �→ λ # » x , y . Y ( # » x , y ) } . » ◮ Sol: Solve { X ( # x ) : t � s } · » ⇒ A ; { Y ( # y ) : t � s } ∪ S ; σ { X �→ λ # » x . Y ( # » » ∪ A ; S ; σ = y ) } , ∈ # » where t and s are of basic type. Head ( t ) � = Head ( s ) or Head ( t ) = Z / x . # y is a subsequence of # » » x consisting of the variables that appear freely in t or s . ◮ Rec: Recover A ; { X ( # x ) : t 1 � t 2 , Z ( # » z ) : s 1 � s 2 } · » ∪ S ; σ = ⇒ A ; { X ( # x ) : t 1 � t 2 } ∪ S ; σ { Z �→ λ # » z . X ( # » x π ) } , » where π : { # x } �→ { # » z } is a bijection, extended as a substitution, such that » t 1 π = s 1 and t 2 π = s 2 . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  16. Demonstration of P ◮ Let t = λ x , y . f ( x , y ) and s = λ x , y . f ( y , x ). { X : λ x , y . f ( x , y ) � λ x , y . f ( y , x ) } ; ∅ ; ε ⇒ Abs { Y 1 ( x ) : λ y . f ( x , y ) � λ y . f ( y , x ) } ; ∅ ; { X �→ λ x . Y 1 ( x ) } = = ⇒ Abs { Y 2 ( x , y ) : f ( x , y ) � f ( y , x ) } ; ∅ ; { X �→ λ x , y . Y 2 ( x , y ) } ⇒ Dec { Y 3 ( x , y ) : x � y , Y 4 ( x , y ) : y � x } ; ∅ ; = { X �→ λ x , y . f ( Y 3 ( x , y ) , Y 4 ( x , y )) } ⇒ Sol { Y 4 ( x , y ) : y � x } ; { Y 3 ( x , y ) : x � y } ; = { X �→ λ x , y . f ( Y 3 ( x , y ) , Y 4 ( x , y )) } ⇒ Sol ∅ ; { Y 3 ( x , y ) : x � y , Y 4 ( x , y ) : y � x } ; = { X �→ λ x , y . f ( Y 3 ( x , y ) , Y 4 ( x , y )) } ⇒ Rec ∅ ; { Y 3 ( x , y ) : x � y } ; = { X �→ λ x , y . f ( Y 3 ( x , y ) , Y 3 ( y , x )) , Y 4 �→ λ x , y . Y 3 ( y , x ) } . ◮ The computed result r = X σ is λ x , y . f ( Y 3 ( x , y ) , Y 3 ( y , x )). ◮ It generalizes t = r { Y 3 �→ λ x , y . x } and s = r { Y 3 �→ λ x , y . y } . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  17. Matching Problem ◮ Rec: Recover x ) : t 1 � t 2 , Z ( # z ) : s 1 � s 2 } · A ; { X ( # » » ∪ S ; σ = ⇒ A ; { X ( # x ) : t 1 � t 2 } ∪ S ; σ { Z �→ λ # » z . X ( # » » x π ) } , where π : { # x } �→ { # » z } is a bijection, extended as a substitution, » such that t 1 π = s 1 and t 2 π = s 2 . ◮ Matching problem P , whose solution bijectively maps variables from a finite set D to a finite set R . ◮ The permuting matcher π is unique, if it exists. Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

  18. Computing Permuted Matchers ◮ M computes a permuting matcher π , if it exists. ◮ M works on quintuples of the form D ; R ; P ; ρ ; π where ◮ D is a set of domain variables, ◮ R is a set of range variables, ◮ P is a set of matching problems of the form { s 1 ⇒ t 1 , . . . , s m ⇒ t m } , ◮ ρ is a substitution which keeps track of bound variable renamings, ◮ π is a substitution which keeps track of the permutations. ◮ M has two final states: ◮ The failure state ⊥ . ◮ The success state D ; R ; ∅ ; ρ ; π . Baumgartner, Kutsia, Levy, Villaret A Variant of Higher-Order Anti-Unification

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend