Nominal Approach Key ideas: Freshness conditions a # t , name swapping ( a b ) · t . Example � and ⌘ rules as nominal rewriting rules: app ( lam ([ a ] Z ) , Z 0 ) subst ([ a ] Z , Z 0 ) ! a # M ` ( � ([ a ] app ( M , a )) ! M • Terms with binders • Built-in ↵ -equivalence • Simple notion of substitution (first order) ) E ffi cient matching and unification algorithms Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Approach Key ideas: Freshness conditions a # t , name swapping ( a b ) · t . Example � and ⌘ rules as nominal rewriting rules: app ( lam ([ a ] Z ) , Z 0 ) subst ([ a ] Z , Z 0 ) ! a # M ` ( � ([ a ] app ( M , a )) ! M • Terms with binders • Built-in ↵ -equivalence • Simple notion of substitution (first order) • E ffi cient matching and unification algorithms ) Dependencies of terms on names are implicit Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Approach Key ideas: Freshness conditions a # t , name swapping ( a b ) · t . Example � and ⌘ rules as nominal rewriting rules: app ( lam ([ a ] Z ) , Z 0 ) subst ([ a ] Z , Z 0 ) ! a # M ` ( � ([ a ] app ( M , a )) ! M • Terms with binders • Built-in ↵ -equivalence • Simple notion of substitution (first order) • E ffi cient matching and unification algorithms • Dependencies of terms on names are implicit ) Easy to express conditions such as a 62 fv( M ) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Syntax [Urban, Pitts, Gabbay 2004] • Variables: M , N , X , Y , . . . Atoms: a , b , . . . Function symbols (term formers): f , g . . . Swappings: ( a b ) Def. ( a b ) a = b , ( a b ) b = a , ( a b ) c = c Permutations: finite bijections on names, represented as lists of swappings, denoted ⇡ ( Id empty). Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Syntax [Urban, Pitts, Gabbay 2004] • Variables: M , N , X , Y , . . . Atoms: a , b , . . . Function symbols (term formers): f , g . . . Swappings: ( a b ) Def. ( a b ) a = b , ( a b ) b = a , ( a b ) c = c Permutations: finite bijections on names, represented as lists of swappings, denoted ⇡ ( Id empty). • Nominal Terms: s , t ::= a | ⇡ · X | [ a ] t | f t | ( t 1 , . . . , t n ) Id · X written as X . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Syntax [Urban, Pitts, Gabbay 2004] • Variables: M , N , X , Y , . . . Atoms: a , b , . . . Function symbols (term formers): f , g . . . Swappings: ( a b ) Def. ( a b ) a = b , ( a b ) b = a , ( a b ) c = c Permutations: finite bijections on names, represented as lists of swappings, denoted ⇡ ( Id empty). • Nominal Terms: s , t ::= a | ⇡ · X | [ a ] t | f t | ( t 1 , . . . , t n ) Id · X written as X . • Example (ML): var ( a ), app ( t , t 0 ), lam ([ a ] t ), let ( t , [ a ] t 0 ), letrec [ f ]([ a ] t , t 0 ), subst ([ a ] t , t 0 ) Syntactic sugar: a , ( tt 0 ), � a . t , let a = t in t 0 , letrec fa = t in t 0 , t [ a 7! t 0 ] Maribel Fern´ andez Nominal Rewriting and Unification Theory
α -equivalence We use freshness to avoid name capture: a # X means a 62 fv( X ) when X is instantiated. ds ( ⇡ , ⇡ 0 )# X a ⇡ ↵ a ⇡ · X ⇡ ↵ ⇡ 0 · X s 1 ⇡ ↵ t 1 · · · s n ⇡ ↵ t n s ⇡ ↵ t ( s 1 , . . . , s n ) ⇡ ↵ ( t 1 , . . . , t n ) fs ⇡ ↵ ft s ⇡ ↵ t a # t s ⇡ ↵ ( a b ) · t [ a ] s ⇡ ↵ [ a ] t [ a ] s ⇡ ↵ [ b ] t where ds ( ⇡ , ⇡ 0 ) = { n | ⇡ ( n ) 6 = ⇡ 0 ( n ) } • a # X , b # X ` ( a b ) · X ⇡ ↵ X Maribel Fern´ andez Nominal Rewriting and Unification Theory
α -equivalence We use freshness to avoid name capture: a # X means a 62 fv( X ) when X is instantiated. ds ( ⇡ , ⇡ 0 )# X a ⇡ ↵ a ⇡ · X ⇡ ↵ ⇡ 0 · X s 1 ⇡ ↵ t 1 · · · s n ⇡ ↵ t n s ⇡ ↵ t ( s 1 , . . . , s n ) ⇡ ↵ ( t 1 , . . . , t n ) fs ⇡ ↵ ft s ⇡ ↵ t a # t s ⇡ ↵ ( a b ) · t [ a ] s ⇡ ↵ [ a ] t [ a ] s ⇡ ↵ [ b ] t where ds ( ⇡ , ⇡ 0 ) = { n | ⇡ ( n ) 6 = ⇡ 0 ( n ) } • a # X , b # X ` ( a b ) · X ⇡ ↵ X • b # X ` � [ a ] X ⇡ ↵ � [ b ]( a b ) · X Maribel Fern´ andez Nominal Rewriting and Unification Theory
Freshness Also defined by induction: ⇡ � 1 ( a )# X a #[ a ] s a # b a # ⇡ · X a # s 1 · · · a # s n a # s a # s a #( s 1 , . . . , s n ) a #[ b ] s a # fs Maribel Fern´ andez Nominal Rewriting and Unification Theory
Exercises Are the following judgements valid? Justify your answer by giving a derivation or a counterexample. ` � [ x ] x ⇡ ↵ � [ y ] y ` � [ x ] � [ y ] x ⇡ ↵ � [ y ] � [ x ] y ` � [ x ] X ⇡ ↵ � [ y ] Y ` � [ x ] X ⇡ ↵ � [ y ] X x # X ` � [ x ] X ⇡ ↵ � [ y ] X x # X , y # X ` � [ x ] s ( X ) ⇡ ↵ � [ y ] s ( X ) x # X , y # X ` � [ x ] + ( X , Y ) ⇡ ↵ � [ y ] + ( X , ( x y ) · Y ) x # X , y # X ` ⇡ ↵ � [ x ] app ( X , � [ y ] y ) � [ y ] app ( X , � [ y ] y ) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Computing with Nominal Terms Rewrite rules can be used to define • equational theories and theorem provers • algebraic specifications of operators and data structures • operational semantics of programs • a theory of functions • a theory of processes • . . . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Rewriting Nominal Rewriting Rules: ∆ ` l ! r V ( r ) [ V ( ∆ ) ✓ V ( l ) Example: Prenex Normal Forms a # P ` P ^ 8 [ a ] Q ! 8 [ a ]( P ^ Q ) a # P ` ( 8 [ a ] Q ) ^ P ! 8 [ a ]( Q ^ P ) a # P ` P _ 8 [ a ] Q ! 8 [ a ]( P _ Q ) a # P ` ( 8 [ a ] Q ) _ P ! 8 [ a ]( Q _ P ) ` P ^ 9 [ a ] Q ! 9 [ a ]( P ^ Q ) a # P a # P ` ( 9 [ a ] Q ) ^ P ! 9 [ a ]( Q ^ P ) ` P _ 9 [ a ] Q ! 9 [ a ]( P _ Q ) a # P a # P ` ( 9 [ a ] Q ) _ P ! 9 [ a ]( Q _ P ) ` ¬ ( 9 [ a ] Q ) ! 8 [ a ] ¬ Q ` ¬ ( 8 [ a ] Q ) ! 9 [ a ] ¬ Q Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Rewriting Rewriting relation generated by R = r ` l ! r : ∆ ` s R ! t s rewrites with R to t in the context ∆ when: 1 s ⌘ C [ s 0 ] such that ✓ solves ( r ` l ) ? ⇡ ( ∆ ` s 0 ) 2 ∆ ` C [ r ✓ ] ⇡ ↵ t . Example Beta-reduction in the Lambda-calculus: ( � [ a ] X ) Y ! X [ a 7! Y ] Beta � a a [ a 7! Y ] ! Y ( XX 0 )[ a 7! Y ] X [ a 7! Y ] X 0 [ a 7! Y ] ! � app � ✏ a # Y ` Y [ a 7! X ] ! Y b # Y ` ( � [ b ] X )[ a 7! Y ] ! � [ b ]( X [ a 7! Y ]) � � Rewriting steps: ( � [ c ] c ) Z ! c [ c 7! Z ] ! Z Maribel Fern´ andez Nominal Rewriting and Unification Theory
Computing with Nominal Terms - Unification/Matching To implement rewriting, or to implement a functional/logic programming language, we need a matching/unification algorithm. Recall: • For first order terms, there are very e ffi cient algorithms (linear time complexity). • For terms with binders, we need more powerful algorithms that take into account ↵ -equivalence. • Higher-order unification is undecidable. Nominal terms have good computational properties: Nominal unification is decidable and unitary. E ffi cient algorithms to check ↵ -equivalence, matching, unification. = ) Nominal programming languages (Alpha-Prolog, FreshML) = ) Nominal Rewriting. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Revision: First-order unification, Matching Unification is a popular research field (origin: Herbrand thesis, 1930s). Key component of logic programming languages and theorem provers: Unification algorithms play a central role in the implementation of resolution — Prolog . Logic programming languages • use logic to express knowledge, describe a problem; • use inference to compute a solution to a problem. Prolog = Clausal Logic + Resolution + Control Strategy Maribel Fern´ andez Nominal Rewriting and Unification Theory
Unification Algorithms Domain of computation: Herbrand Universe: set of terms over a universal alphabet of • variables : X , Y , . . . • and function symbols ( f , g , h , . . . ) with fixed arities (the arity of a symbol is the number of arguments associated with it). A term is either a variable, or has the form f ( t 1 , . . . , t n ) where f is a function symbol of arity n and t 1 , . . . , t n are terms. Example: f ( f ( X , g ( a )) , Y ) where a is a constant, f a binary function, and g a unary function. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Values: Values are also terms, that are associated to variables by means of automatically generated substitutions , called most general unifiers. Definition: A substitution is a partial mapping from variables to terms, with a finite domain. We denote a substitution � by: { X 1 7! t 1 , . . . , X n 7! t n } . dom ( � ) = { X 1 , . . . , X n } . A substitution � is applied to a term t or a literal l by simultaneously replacing each variable occurring in dom ( � ) by the corresponding term. The resulting term is denoted t � . Example: Let � = { X 7! g ( Y ) , Y 7! a } and t = f ( f ( X , g ( a )) , Y ). Then t � = f ( f ( g ( Y ) , g ( a )) , a ) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Queries in Prolog - Example append([],L,L). append([X|L],Y,[X|Z]) :- append(L,Y,Z). To solve the query :- append([0],[1,2],U) we use the second clause. The substitution { X 7! 0, L 7! [], Y 7! [1,2], U 7! [0|Z] } unifies append([X|L],Y,[X|Z]) with the query append([0],[1,2],U) , and then we have to prove that append([],[1,2],Z) holds. Since we have a fact append([],L,L) in the program, it is su ffi cient to take { Z 7! [1,2] } . Thus, { U 7! [0,1,2] } is an answer substitution . This method is based on the Principle of Resolution. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Unification A unification problem U is a set of equations between terms with variables { s 1 = t 1 , . . . , s n = t n } A solution to U , also called a unifier , is a substitution � such that for each equation s i = t i 2 U , the terms s i � and t i � coincide. The most general unifier of U is a unifier � such that any other unifier ⇢ is an instance of � . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Unification Algorithm Martelli and Montanari’s algorithm finds the most general unifier for a unification problem (if a solution exists, otherwise it fails) by simplification: It simplifies the unification problem until a substitution is generated. It is specified as a set of transformation rules, which apply to sets of equations and produce new sets of equations or a failure. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Unification Algorithm Input: A finite set of equations : { s 1 = t 1 , . . . , s n = t n } Output: A substitution (mgu for these terms), or failure. Transformation Rules: Rules are applied non-deterministically, until no rule can be applied or a failure arises. (1) f ( s 1 , . . . , s n ) = f ( t 1 , . . . , t n ) , E ! s 1 = t 1 , . . . , s n = t n , E (2) f ( s 1 , . . . , s n ) = g ( t 1 , . . . , t m ) , E ! failure (3) X = X , E ! E (4) t = X , E ! X = t , E if t is not a variable (5) X = t , E ! X = t , E { X 7! t } if X not in t and X in E (6) X = t , E ! failure if X in t and X 6 = t Maribel Fern´ andez Nominal Rewriting and Unification Theory
Remarks • We are working with sets of equations, therefore their order in the unification problem is not important. • The test in case (6) is called occur-check , e.g. X = f ( X ) fails. This test is time consuming, and for this reason in some systems it is not implemented. • In case of success, by changing in the final set of equations the “=” by 7! we obtain a substitution, which is the most general unifier (mgu) of the initial set of terms. • Cases (1) and (2) apply also to constants: in the first case the equation is deleted and in the second there is a failure. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Examples: In the example with append , we solved the unification problem: { [X|L] = [0], Y = [1,2], [X|Z] = U } Recall that the notation [ | ] represents a binary list constructor (the arguments are the head and the tail of the list). [0] is a shorthand for [0 | []] , and [] is a constant. We now apply the unification algorithm to this set of the equations: using rule (1) in the first equation, we get: { X = 0, L = [], Y = [1,2], [X|Z] = U } using rule (5) and the first equation we get: { X = 0, L = [], Y = [1,2], [0|Z] = U } using rule (4) and the last equation we get: { X = 0, L = [], Y = [1,2], U = [0|Z] } and the algorithm stops. Therefore the most general unifier is: { X 7! 0, L 7! [],Y 7! [1,2], U 7! [0|Z] } Maribel Fern´ andez Nominal Rewriting and Unification Theory
Back to nominal terms: checking α -equivalence Idea: Turn the ↵ -equivalence derivation rules into simplification rules in the style of Martelli and Montanari’s. a # b , Pr = ) Pr a # fs , Pr = ) a # s , Pr ) a #( s 1 , . . . , s n ) , Pr = a # s 1 , . . . , a # s n , Pr a #[ b ] s , Pr = ) a # s , Pr ) a #[ a ] s , Pr = Pr ⇡ -1 · a # X , Pr a # ⇡ · X , Pr = ) ⇡ 6⌘ Id a ⇡ ↵ a , Pr = ) Pr ( l 1 , . . . , l n ) ⇡ ↵ ( s 1 , . . . , s n ) , Pr ) l 1 ⇡ ↵ s 1 , . . . , l n ⇡ ↵ s n , Pr = fl ⇡ ↵ fs , Pr = ) l ⇡ ↵ s , Pr [ a ] l ⇡ ↵ [ a ] s , Pr = ) l ⇡ ↵ s , Pr [ b ] l ⇡ ↵ [ a ] s , Pr = ) ( a b ) · l ⇡ ↵ s , a # l , Pr ⇡ · X ⇡ ↵ ⇡ 0 · X , Pr ds ( ⇡ , ⇡ 0 )# X , Pr = ) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Checking α -equivalence of terms ) is confluent and strongly normalising: The relation = the simplification process terminates, the result is unique: h Pr i nf h Pr i nf is of the form ∆ [ Contr [ Eq where: ∆ contains consistent freshness constraints ( a # X ) Contr contains inconsistent freshness constraints ( a # a ) Eq contains reduced ⇡ ↵ constraints. Lemma: • Γ ` Pr if and only if Γ ` h Pr i nf . • Let h Pr i nf = ∆ [ Contr [ Eq . Then ∆ ` Pr if and only if Contr and Eq are empty. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Equations [Urban, Pitts, Gabbay 2003] • Nominal Unification: l ? ⇡ ? t has solution ( ∆ , ✓ ) if ∆ ` l ✓ ⇡ ↵ t ✓ Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Equations [Urban, Pitts, Gabbay 2003] • Nominal Unification: l ? ⇡ ? t has solution ( ∆ , ✓ ) if ∆ ` l ✓ ⇡ ↵ t ✓ • Nominal Matching: s = t has solution ( ∆ , ✓ ) if ∆ ` s ✓ ⇡ ↵ t ( t ground or variables disjoint from s ) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Equations [Urban, Pitts, Gabbay 2003] • Nominal Unification: l ? ⇡ ? t has solution ( ∆ , ✓ ) if ∆ ` l ✓ ⇡ ↵ t ✓ • Nominal Matching: s = t has solution ( ∆ , ✓ ) if ∆ ` s ✓ ⇡ ↵ t ( t ground or variables disjoint from s ) • Examples: � ([ a ] X ) = � ([ b ] b ) ?? � ([ a ] X ) = � ([ b ] X ) ?? Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Equations [Urban, Pitts, Gabbay 2003] • Nominal Unification: l ? ⇡ ? t has solution ( ∆ , ✓ ) if ∆ ` l ✓ ⇡ ↵ t ✓ • Nominal Matching: s = t has solution ( ∆ , ✓ ) if ∆ ` s ✓ ⇡ ↵ t ( t ground or variables disjoint from s ) • Examples: � ([ a ] X ) = � ([ b ] b ) ?? � ([ a ] X ) = � ([ b ] X ) ?? • Solutions: ( ; , [ X 7! a ]) and ( { a # X , b # X } , Id ) resp. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Back to Nominal Rewriting Let R = r ` l ! r where V ( l ) \ V ( s ) = ; s rewrites with R to t in the context ∆ , written ∆ ` s R ! t , when: 1 s ⌘ C [ s 0 ] such that ✓ solves ( r ` l ) ? ⇡ ( ∆ ` s 0 ) 2 ∆ ` C [ r ✓ ] ⇡ ↵ t . • To define the reduction relation generated by nominal rewriting rules we use nominal matching. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Back to Nominal Rewriting Let R = r ` l ! r where V ( l ) \ V ( s ) = ; s rewrites with R to t in the context ∆ , written ∆ ` s R ! t , when: 1 s ⌘ C [ s 0 ] such that ✓ solves ( r ` l ) ? ⇡ ( ∆ ` s 0 ) 2 ∆ ` C [ r ✓ ] ⇡ ↵ t . • To define the reduction relation generated by nominal rewriting rules we use nominal matching. • ( r ` l ) ? ⇡ ( ∆ ` s 0 ) if r , l ⇡ ↵ s 0 has solution ( ∆ 0 , ✓ ), that is, ∆ 0 ` r ✓ , l ✓ ⇡ ↵ s 0 and ∆ ` ∆ 0 Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Matching • Nominal matching is decidable [Urban, Pitts, Gabbay 2003] A solvable problem Pr has a unique most general solution: ( Γ , ✓ ) such that Γ ` Pr ✓ . • Nominal matching algorithm: add an instantiation rule : Pr [ X 7! ⇡ -1 · u ] ) X 7! ⇡ -1 · u ⇡ · X ⇡ ↵ u , Pr = No occur-checks needed (left-hand side variables distinct from right-hand side variables). Maribel Fern´ andez Nominal Rewriting and Unification Theory
Back to Nominal Rewriting Equivariance: Rules defined modulo permutative renamings of atoms. Beta-reduction in the Lambda-calculus: ( � [ a ] X ) Y ! X [ a 7! Y ] Beta a [ a 7! Y ] ! � a Y ( XX 0 )[ a 7! Y ] X [ a 7! Y ] X 0 [ a 7! Y ] ! � app � ✏ a # Y ` Y [ a 7! X ] ! Y b # Y ` ( � [ b ] X )[ a 7! Y ] ! � [ b ]( X [ a 7! Y ]) � � Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Rewriting Exercises Exercises: Are the following rewriting derivations valid? If your answer is positive, indicate the rules and substitutions used in each step. ! ⇤ ` ( � [ x ] s ( x )) Y s ( Y ) ! ⇤ y # Y ` ( � [ x ] � [ y ] x ) Y � [ y ] Y ! ⇤ y # X ` ( � [ y ] X ) Y X ! ⇤ y # Y ` (( � [ x ] � [ y ] x ) Y ) Y Y Maribel Fern´ andez Nominal Rewriting and Unification Theory
Next questions • E ffi cient nominal matching algorithm? • Is nominal matching su ffi cient (complete) for nominal rewriting? Maribel Fern´ andez Nominal Rewriting and Unification Theory
A Linear-Time Matching Algorithm • The transformation rules create permutations. In polynomial implementations of nominal unification permutations are lazy: only pushed down a term when needed. Maribel Fern´ andez Nominal Rewriting and Unification Theory
A Linear-Time Matching Algorithm • The transformation rules create permutations. In polynomial implementations of nominal unification permutations are lazy: only pushed down a term when needed. • Problem: lazy permutations may grow (they accumulate). Maribel Fern´ andez Nominal Rewriting and Unification Theory
A Linear-Time Matching Algorithm • The transformation rules create permutations. In polynomial implementations of nominal unification permutations are lazy: only pushed down a term when needed. • Problem: lazy permutations may grow (they accumulate). • To obtain an e ffi cient algorithm, work with a single current permutation, represented by an environment . Maribel Fern´ andez Nominal Rewriting and Unification Theory
A Linear-Time Algorithm An environment ⇠ is a pair ( ⇠ ⇡ , ⇠ A ) of a permutation and a set of atoms. Notation: s ⇡ ↵ ⇠ ⌃ t represents s ⇡ ↵ ⇠ ⇡ · t , ⇠ A # t . An environment problem Pr is either ? or s 1 ⇡ ↵ ⇠ 1 ⌃ t 1 , . . . , s n ⇡ ↵ ⇠ n ⌃ t n . It is easy to translate a standard problem into an environment problem and vice-versa. Maribel Fern´ andez Nominal Rewriting and Unification Theory
A Linear-Time Algorithm The algorithms to check ↵ -equivalence constraints and to solve matching problems are modular. Core module (common to both algorithms) has four phases: Phase 1 reduces environment constraints, by propagating ⇠ i over t i . Phase 2 eliminates permutations on the left-hand side. Phase 3 reduces freshness constraints. Phase 4 computes the standard form of the resulting problem. c denotes the result of applying the core algorithm on Pr . Pr Maribel Fern´ andez Nominal Rewriting and Unification Theory
Core module Phase 1 - Input: Pr = ( s i ⇡ ↵ ⇠ i ⌃ t i ) n i ( Pr if a = ⇠ ⇡ · t and t 62 ⇠ A ⇡ ↵ ⇠ ⌃ t = ) Pr , a ? otherwise ( Pr , ( s i ⇡ ↵ ⇠ ⌃ u i ) n if t = ( u 1 , . . . , u n ) 1 Pr , ( s 1 , . . . , s n ) ⇡ ↵ ⇠ ⌃ t = ) ? otherwise ( Pr , s ⇡ ↵ ⇠ ⌃ u if t = f u Pr , f s ⇡ ↵ ⇠ ⌃ t = ) ? otherwise ( Pr , s ⇡ ↵ ⇠ 0 ⌃ u if t = [ b ] u Pr , [ a ] s ⇡ ↵ ⇠ ⌃ t = ) ? otherwise where ⇠ 0 = (( a ⇠ ⇡ · b ) � ⇠ ⇡ , ( ⇠ A [ { ⇠ � 1 · a } ) \ { b } ) in the last rule, ⇡ and a , b could be the same atom. The normal forms for phase 1 rules are either ? or ( ⇡ i · X i ⇡ ↵ ⇠ i ⌃ s i ) n 1 where s i are nominal terms. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Core module Phase 2 - Input: A Phase 1 normal form. ) X ⇡ ↵ ( ⇡ � 1 · ⇠ ) ⌃ t ⇡ · X ⇡ ↵ ⇠ ⌃ t = ( ⇡ 6 = Id ) where ⇡ � 1 · ⇠ = ( ⇡ � 1 � ⇠ ⇡ , ⇠ A ). Above, ⇡ � 1 applies only to ⇠ ⇡ , because ⇡ · X ⇡ ↵ ⇠ ⌃ t represents ⇡ · X ⇡ ↵ ⇠ ⇡ · t , ⇠ A # t . Phase 2 normal forms are either ? or ( X i ⇡ ↵ ⇠ i ⌃ t i ) n 1 , where the terms t i are standard nominal terms. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Core module Phase 3 - Input: A Phase 2 normal form ( X i ⇡ ↵ ⇠ i ⌃ t i ) n 1 . ( ⇠ ⇡ · a a 62 ⇠ A ⇠ ⌃ a = ) ? a 2 ⇠ A ⇠ ⌃ f t = ) f ( ⇠ ⌃ t ) ( ⇠ ⌃ t i ) j ⇠ ⌃ ( t 1 , . . . , t j ) = ) 1 ⇠ ⌃ [ a ] s = ) [ ⇠ ⇡ · a ](( ⇠ \ { a } ) ⌃ s ) ⇠ ⌃ ( ⇡ · X ) = ) ( ⇠ � ⇡ ) ⌃ X Pr [ ? ] = ) ? where ⇠ \ { a } = ( ⇠ ⇡ , ⇠ A \ { a } ) and ⇠ � ⇡ = (( ⇠ ⇡ � ⇡ ) , ⇡ � 1 ( ⇠ A )). The normal forms are either ? or ( X i ⇡ ↵ t i ) n 1 where t i 2 T ⇠ . T ⇠ = a | f T ⇠ | ( T ⇠ , . . . , T ⇠ ) | [ a ] T ⇠ | ⇠ ⌃ X Maribel Fern´ andez Nominal Rewriting and Unification Theory
Core module Phase 4: X ⇡ ↵ C [ ⇠ ⌃ X 0 ] = ) X ⇡ ↵ C [ ⇠ ⇡ · X 0 ] , ⇠ A # X 0 Normal forms are either ? or ( X i ⇡ ↵ u i ) i 2 I , ( A j # X j ) j 2 J where u i are nominal terms and I , J may be empty. Correctness: The core algorithm terminates, and preserves the set of solutions. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Checking α -equivalence constraints To check that a set Pr of ↵ -equivalence constraints is valid: • Run the core algorithm on Pr Maribel Fern´ andez Nominal Rewriting and Unification Theory
Checking α -equivalence constraints To check that a set Pr of ↵ -equivalence constraints is valid: • Run the core algorithm on Pr • If left-hand sides of ⇡ ↵ -constraints in Pr are ground, stop c using: otherwise reduce the result Pr ( Pr , supp ( ⇡ ) # X if t = ⇡ · X ( ↵ ) Pr , X ⇡ ↵ t = ) ? otherwise where supp ( ⇡ ) = { a | ⇡ · a 6 = a } Maribel Fern´ andez Nominal Rewriting and Unification Theory
Checking α -equivalence constraints To check that a set Pr of ↵ -equivalence constraints is valid: • Run the core algorithm on Pr • If left-hand sides of ⇡ ↵ -constraints in Pr are ground, stop c using: otherwise reduce the result Pr ( Pr , supp ( ⇡ ) # X if t = ⇡ · X ( ↵ ) Pr , X ⇡ ↵ t = ) ? otherwise where supp ( ⇡ ) = { a | ⇡ · a 6 = a } • Normal forms: ? or ( A i # X i ) n 1 . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Checking α -equivalence constraints To check that a set Pr of ↵ -equivalence constraints is valid: • Run the core algorithm on Pr • If left-hand sides of ⇡ ↵ -constraints in Pr are ground, stop c using: otherwise reduce the result Pr ( Pr , supp ( ⇡ ) # X if t = ⇡ · X ( ↵ ) Pr , X ⇡ ↵ t = ) ? otherwise where supp ( ⇡ ) = { a | ⇡ · a 6 = a } • Normal forms: ? or ( A i # X i ) n 1 . • Correctness: If the normal form is ? then Pr is not valid. If the normal form of Pr is ( A i # X i ) n 1 then ( A i # X i ) n 1 ` Pr . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Matching Problems To solve a matching problem Pr : • Run the core algorithm on Pr Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Matching Problems To solve a matching problem Pr : • Run the core algorithm on Pr c by: • If the problem is non-linear, normalise the result Pr Pr , X ⇡ ↵ s , X ⇡ ↵ t = ) if s ⇡ ↵ t ⇡ ↵ 6 = ? ( Pr , X ⇡ ↵ s , s ⇡ ↵ t ⇡ ↵ ? otherwise Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Matching Problems To solve a matching problem Pr : • Run the core algorithm on Pr c by: • If the problem is non-linear, normalise the result Pr Pr , X ⇡ ↵ s , X ⇡ ↵ t = ) if s ⇡ ↵ t ⇡ ↵ 6 = ? ( Pr , X ⇡ ↵ s , s ⇡ ↵ t ⇡ ↵ ? otherwise • Normal forms: ? or a pair of a substitution and a freshness context. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Matching Problems To solve a matching problem Pr : • Run the core algorithm on Pr c by: • If the problem is non-linear, normalise the result Pr Pr , X ⇡ ↵ s , X ⇡ ↵ t = ) if s ⇡ ↵ t ⇡ ↵ 6 = ? ( Pr , X ⇡ ↵ s , s ⇡ ↵ t ⇡ ↵ ? otherwise • Normal forms: ? or a pair of a substitution and a freshness context. • Correctness: The result is a most general solution of the matching problem Pr . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Solving Matching Problems To solve a matching problem Pr : • Run the core algorithm on Pr c by: • If the problem is non-linear, normalise the result Pr Pr , X ⇡ ↵ s , X ⇡ ↵ t = ) if s ⇡ ↵ t ⇡ ↵ 6 = ? ( Pr , X ⇡ ↵ s , s ⇡ ↵ t ⇡ ↵ ? otherwise • Normal forms: ? or a pair of a substitution and a freshness context. • Correctness: The result is a most general solution of the matching problem Pr . • Remark: If variables occur linearly in patterns then the core algorithm is su ffi cient. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Complexity Core algorithm: linear in the size of the initial problem in the ground case, using mutable arrays. In the non-ground case, log-linear using functional maps. Alpha-equivalence check: linear if right-hand sides of constraints are ground (core algorithm). Otherwise, log-linear using functional maps. Matching: quadratic in the non-ground case (traversal of every term in the output of the core algorithm). Worst case complexity: when phase 4 suspends permutations on all variables. If variables in the input problem are ’saturated’ with permutations, then linear (permutations cannot grow). Maribel Fern´ andez Nominal Rewriting and Unification Theory
Complexity Summary: Case Alpha-equivalence Matching Ground linear linear Non-ground and linear log-linear log-linear Non-ground and non-linear log-linear quadratic Remark: The representation using higher-order abstract syntax does saturate the variables (they have to be applied to the set of atoms they can capture). Conjecture: the algorithms are linear wrt HOAS also in the non-ground case. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Benchmarks OCAML implementation: 0.5 alpha ⌃ ⌃ ⌃ 0.45 + match ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ 0.4 ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ 0.35 ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ 0.3 ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ Time 0.25 ⌃ ⌃ ⌃ ⌃ + ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ + + ⌃ + + + ⌃ ⌃ 0.2 ⌃ ⌃ ⌃ + ⌃ ⌃ ⌃ + ⌃ + + + ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ + + + + ⌃ ⌃ + ⌃ ⌃ ⌃ ++ + + + + + + + + + ⌃ + ⌃ ⌃ + ⌃ ⌃ ⌃ + ⌃ + ⌃ + + ⌃ ⌃ + 0.15 ⌃ ⌃ + ⌃ ⌃ + ++ + + + + + + + + + ++ + + ⌃ ⌃ ⌃ ⌃ + + ⌃ ⌃ ⌃ + + ⌃ ⌃ ⌃ + + + + + + ⌃ ⌃ ++ ⌃ ⌃ + + + + + ⌃ + ⌃ ⌃ + + + + 0.1 + + + + ++ ++ ++ + ⌃ ⌃ ⌃ ⌃ + ⌃ ⌃ + + + ⌃ + + + + ⌃ ⌃ + + ⌃ + + + ⌃ ⌃ ⌃ + + ⌃ + + + + ⌃ ⌃ ⌃ + + ++ + ⌃ + + ⌃ ⌃ + ++ + ⌃ ⌃ + + + + 0.05 + ⌃ + + ⌃ ⌃ ++ + + + + + + ⌃ ⌃ ⌃ + + + + + + ⌃ ++ + + ⌃ + + + + ⌃ ++ ++ + ⌃ ++ ++ + + + + + ++ ⌃ + + + + ++ ⌃ + ⌃ + + + ⌃ ⌃ + + + + + + + + + ⌃ + + + + ⌃ + + + + ⌃ + + + + + + + + + + + + + ⌃ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ⌃ + + + ⌃ 0 ⌃ ⌃ 0 10000 20000 30000 40000 50000 60000 70000 80000 90000100000 Size Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Matching vs. Equivariant Matching • Nominal matching is e ffi cient. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Matching vs. Equivariant Matching • Nominal matching is e ffi cient. • Equivariant nominal matching is exponential... BUT Maribel Fern´ andez Nominal Rewriting and Unification Theory
Nominal Matching vs. Equivariant Matching • Nominal matching is e ffi cient. • Equivariant nominal matching is exponential... BUT • if rules are CLOSED then nominal matching is su ffi cient. Intuitively, closed means no free atoms. The rules in the examples above are closed. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Closed Rules R ⌘ r ` l ! r is closed when ( r 0 ` ( l 0 , r 0 )) ? ⇡ ( r , A ( R 0 )# V ( R ) ` ( l , r )) has a solution � (where R 0 is freshened with respect to R ). Given R ⌘ r ` l ! r and ∆ ` s a term-in-context we write ∆ , A ( R 0 )# V ( ∆ , s ) ` s R 0 R ∆ ` s ! c t when ! t and call this closed rewriting . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Examples The following rules are not closed: g ( a ) ! a [ a ] X ! X Why? Maribel Fern´ andez Nominal Rewriting and Unification Theory
Examples The following rule is closed: a # X ` [ a ] X ! X Why? Maribel Fern´ andez Nominal Rewriting and Unification Theory
Exercise Provide a nominal rewriting system defining an explicit substitution operator subst of arity 3 for the lambda-calculus. subst ( x , s , t ) should return the term obtained by substituting x by t in s . Are your rules closed? Maribel Fern´ andez Nominal Rewriting and Unification Theory
Examples Closed rules that define capture-avoiding substitution in the lambda calculus: (explicit) substitutions, subst ([ x ] M , N ) abbreviated M [ x 7! N ]. ( � [ a ] X ) X 0 X [ a 7! X 0 ] (Beta) ! ( XX 0 )[ a 7! Y ] X [ a 7! Y ] X 0 [ a 7! Y ] ! ( � app ) ( � a ) a [ a 7! X ] ! X ( � ✏ ) a # Y ` Y [ a 7! X ] ! Y ( � � ) b # Y ` ( � [ b ] X )[ a 7! Y ] ! � [ b ]( X [ a 7! Y ]) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Exercise Show that the rules defining beta-reduction in the lambda-calculus in the previous slide are closed. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Properties of Closed Rewriting Closed Nominal Rewriting: • works uniformly in ↵ equivalence classes of terms. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Properties of Closed Rewriting Closed Nominal Rewriting: • works uniformly in ↵ equivalence classes of terms. • is expressive: can encode Combinatory Reduction Systems. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Properties of Closed Rewriting Closed Nominal Rewriting: • works uniformly in ↵ equivalence classes of terms. • is expressive: can encode Combinatory Reduction Systems. • is e ffi cient: linear matching. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Properties of Closed Rewriting Closed Nominal Rewriting: • works uniformly in ↵ equivalence classes of terms. • is expressive: can encode Combinatory Reduction Systems. • is e ffi cient: linear matching. • inherits confluence conditions from first order rewriting. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Confluence — Critical Pairs Suppose 1 R i = r i ` l i ! r i for i = 1 , 2 are copies of two rules in R such that V ( R 1 ) \ V ( R 2 ) = ; ( R 1 and R 2 could be copies of the same rule). 2 l 1 ⌘ L [ l 0 1 ] such that r 1 , r 2 , l 0 1 ? ⇡ ? l 2 has a principal solution ( Γ , ✓ ), so that Γ ` l 0 1 ✓ ⇡ ↵ l 2 ✓ and Γ ` r i ✓ for i = 1 , 2. Then Γ ` ( r 1 ✓ , L ✓ [ r 2 ✓ ]) is a critical pair . If L = [-] and R 1 , R 2 are copies of the same rule, or if l 0 1 is a variable, then we say the critical pair is trivial . We distinguish: If R 2 is a copy of R ⇡ 1 , the overlap is permutative . Root-permutative overlap : permutative overlap at the root. Proper overlap : not trivial and not root-permutative Same terminology for critical pairs. Maribel Fern´ andez Nominal Rewriting and Unification Theory
{ # Confluence — Critical Pairs ! critical pair between rules R and R ⇡ . Permutative overlap � Only the root-permutative overlaps where ⇡ is Id are trivial. While overlaps at the root between variable-renamed versions of first-order rules can be discarded (they generate equal terms), in nominal rewriting we must consider non-trivial root-permutative overlaps. Indeed, they do not necessarily produce the same result. Example R = ( ` f ( X ) ! f ([ a ] X )) and R ( a b ) = ( ` f ( X ) ! f ([ b ] X )) have a non-trivial root-permutative overlap. Critical pair: ` ( f ([ a ] X ) , f ([ b ] X )). Note that f ([ a ] X ) 6⇡ ↵ f ([ b ] X ). This theory is not confluent; we have for instance: f ( a ) h R , ✏ , Id , [ X 7! a ] i h R , ✏ , ( a b ) , [ X 7! a ] i f ([ a ] a ) 6⇡ ↵ f ([ b ] a ) Maribel Fern´ andez Nominal Rewriting and Unification Theory
Confluence — Critical Pairs For uniform rules (i.e., rules that do not generate new atoms), joinability of non-trivial critical pairs implies local confluence; also confluence if terminating (Newman’s Lemma). Joinability of proper critical pairs is insu ffi cient for local confluence, even for a uniform theory: the rule in Example above is uniform. However, it is not ↵ -stable: R = r ` l ! r is ↵ -stable when, for all ∆ , ⇡ , � , � 0 , ∆ ` r � , r ⇡ � 0 , l � ⇡ ↵ l ⇡ � 0 implies ∆ ` r � ⇡ ↵ r ⇡ � 0 . Critical Pair Lemma for uniform ↵ -stable theories: Let R = ( Σ , Rw ) be a uniform rewrite theory where all the rewrite rules in Rw are ↵ -stable. If every proper critical pair is joinable, then R is locally confluent. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Confluence — Critical Pairs ↵ -stability is di ffi cult to check, however, closed rules are ↵ -stable . The reverse implication does not hold: ` f ( a ) ! a is ↵ -stable but not closed. Corollary: A closed nominal rewrite system where all proper critical pairs are joinable is locally confluent. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Confluence — Critical Pairs and Closed Rewriting More e ffi cient: checking fresh overlaps and fresh critical pairs is su ffi cient for closed rewriting. Let R i = r i ` l i ! r i ( i = 1 , 2) be freshened versions of rules. If the nominal unification problem r 1 [ r 2 [ { l 2 ? ⇡ ? l 1 | p } has a most general solution h Γ , ✓ i for some position p , then R 1 fresh overlaps with R 2 , and the pair of terms-in-context Γ ` ( r 1 ✓ , l 1 ✓ [ p r 2 ✓ ]) is a fresh critical pair . If p is a variable position, or if R 1 and R 2 are equal modulo renaming of variables and p = ✏ , then we call the overlap and critical pair trivial . If R 1 and R 2 are freshened versions of the same rule and p = ✏ , then we call the overlap and critical pair fresh root-permutative . A fresh overlap (resp. fresh critical pair) that is not trivial and not root-permutative is proper . Maribel Fern´ andez Nominal Rewriting and Unification Theory
Confluence — Critical Pairs and Closed Rewriting The fresh critical pair Γ ` ( r 1 ✓ , l 1 ✓ [ p r 2 ✓ ]) is joinable if there is a term u such that Γ ` R r 1 ✓ ! c u and Γ ` R ( l 1 ✓ [ p r 2 ✓ ]) ! c u . Critical Pair Lemma for Closed Rewriting: Let R = ( Σ , Rw ) be a rewrite theory where every proper fresh critical pair is joinable. Then the closed rewriting relation generated by R is locally confluent. Maribel Fern´ andez Nominal Rewriting and Unification Theory
Recommend
More recommend