<<

Nominal Rewriting and Unification Theory

Maribel Fern´andez

FoPSS 2019

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Rewriting and Unification Theory

Introduction First-order languages • Languages with binding operators • Specifying binders: ↵-equivalence • Nominal terms • Nominal unification (unification modulo ↵-equivalence) • Nominal matching (matching modulo ↵-equivalence) • Nominal rewriting Extending first-order rewriting to specify binding operators • Closed rewriting • Confluence • Typed Rewriting Systems • Equational Axioms: AC operators • Maribel Fern´andez Nominal Rewriting and Unification Theory Further reading

C. Urban, A. Pitts, M.J. Gabbay. Nominal Unification. • Theoretical 323, pages 473-497, 2004. C. Calv`es, M. Fern´andez. Matching and Alpha-Equivalence • Check for Nominal Terms. Journal of Computer and System Sciences, 2010. M. Ayala-Rinc´on, M. Fern´andez, D. Nantes-Sobrinho. • Fixed-Point Constraints for Nominal Equational Unification. Proceedings of FSCD 2018, LIPICS. M. Fern´andez, M.J. Gabbay. Nominal Rewriting. Information • and Computation 205, pages 917-965, 2007. J. Dominguez, M. Fern´andez. Nominal Syntax with Atom • : Matching, Unification, Rewriting. Proceedings of FCT 2019, Lecture Notes in Computer Science, Springer. E. Fairweather, M. Fern´andez. Typed Nominal Rewriting. • ACM Transactions on Computational , 2018.

Maribel Fern´andez Nominal Rewriting and Unification Theory First-order languages vs. languages with binders

Most programming languages support first-order data structures and first-order operators.

Examples of first-order data structures: numbers, lists, trees, etc. First-order operator on lists:

append(nil, x) x ! append(cons(x, z), y) cons(x, append(z, y)) ! Very few programming languages support data structures with binding constructs.

However, in many situations, we need to manipulate data with bound names. Example: compilers, type checkers, code optimisation, etc.

Maribel Fern´andez Nominal Rewriting and Unification Theory and ⌘-reductions in the -calculus: • (x.M)N M[x/N] ! (x.Mx) M (x fv(M)) ! 62 ⇡-calculus: • P ⌫a.Q ⌫a.(P Q)(a fv(P)) | ! | 62 Logic equivalences: • Pand( x.Q) x(PandQ)(x fv(P)) 8 ,8 62

Binding operators: Examples

Some concrete examples of binding constructs (informally): Operational semantics: • let a = N in M (fun a.M)N !

Maribel Fern´andez Nominal Rewriting and Unification Theory ⇡-calculus: • P ⌫a.Q ⌫a.(P Q)(a fv(P)) | ! | 62 Logic equivalences: • Pand( x.Q) x(PandQ)(x fv(P)) 8 ,8 62

Binding operators: Examples

Some concrete examples of binding constructs (informally): Operational semantics: • let a = N in M (fun a.M)N ! and ⌘-reductions in the -calculus: • (x.M)N M[x/N] ! (x.Mx) M (x fv(M)) ! 62

Maribel Fern´andez Nominal Rewriting and Unification Theory Logic equivalences: • Pand( x.Q) x(PandQ)(x fv(P)) 8 ,8 62

Binding operators: Examples

Some concrete examples of binding constructs (informally): Operational semantics: • let a = N in M (fun a.M)N ! and ⌘-reductions in the -calculus: • (x.M)N M[x/N] ! (x.Mx) M (x fv(M)) ! 62 ⇡-calculus: • P ⌫a.Q ⌫a.(P Q)(a fv(P)) | ! | 62

Maribel Fern´andez Nominal Rewriting and Unification Theory Binding operators: Examples

Some concrete examples of binding constructs (informally): Operational semantics: • let a = N in M (fun a.M)N ! and ⌘-reductions in the -calculus: • (x.M)N M[x/N] ! (x.Mx) M (x fv(M)) ! 62 ⇡-calculus: • P ⌫a.Q ⌫a.(P Q)(a fv(P)) | ! | 62 Logic equivalences: • Pand( x.Q) x(PandQ)(x fv(P)) 8 ,8 62

Maribel Fern´andez Nominal Rewriting and Unification Theory Binding operators - ↵-equivalence

Terms are defined modulo renaming of bound variables,i.e., ↵-equivalence.

Example: In x.P the variable x can be renamed (avoiding name capture) 8 x.P = y.P x y 8 ↵ 8 { 7! }

How can we formally define (or program) binding operators? There are several alternatives.

Maribel Fern´andez Nominal Rewriting and Unification Theory Ecient matching and unification (+) • No binders (-) • We need to ’implement’ ↵-equivalence and non-capturing • substitution from scratch (-) For example, we can encode a system with binders such as the • lambda-calculus using numbers to represent bound variables and operators such as “lift” and “shift” to encode non-capturing substitution (cf. De Bruijn’s notation)

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language. Simple notion of substitution (first-order) (+) )

Maribel Fern´andez Nominal Rewriting and Unification Theory No binders (-) • We need to ’implement’ ↵-equivalence and non-capturing • substitution from scratch (-) For example, we can encode a system with binders such as the • lambda-calculus using numbers to represent bound variables and operators such as “lift” and “shift” to encode non-capturing substitution (cf. De Bruijn’s notation)

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language. Simple notion of substitution (first-order) (+) • Ecient matching and unification algorithms (+) )

Maribel Fern´andez Nominal Rewriting and Unification Theory We need to ’implement’ ↵-equivalence and non-capturing • substitution from scratch (-) For example, we can encode a system with binders such as the • lambda-calculus using numbers to represent bound variables and operators such as “lift” and “shift” to encode non-capturing substitution (cf. De Bruijn’s notation)

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language. Simple notion of substitution (first-order) (+) • Ecient matching and unification algorithms (+) • No binders (-) )

Maribel Fern´andez Nominal Rewriting and Unification Theory For example, we can encode a system with binders such as the • lambda-calculus using numbers to represent bound variables and operators such as “lift” and “shift” to encode non-capturing substitution (cf. De Bruijn’s notation)

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language. Simple notion of substitution (first-order) (+) • Ecient matching and unification algorithms (+) • No binders (-) • We need to ’implement’ ↵-equivalence and non-capturing ) substitution from scratch (-)

Maribel Fern´andez Nominal Rewriting and Unification Theory First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language. Simple notion of substitution (first-order) (+) • Ecient matching and unification algorithms (+) • No binders (-) • We need to ’implement’ ↵-equivalence and non-capturing • substitution from scratch (-) For example, we can encode a system with binders such as the ) lambda-calculus using numbers to represent bound variables and operators such as “lift” and “shift” to encode non-capturing substitution (cf. De Bruijn’s notation)

Maribel Fern´andez Nominal Rewriting and Unification Theory Logical frameworks based on Higher-Order Abstract Syntax • also work modulo ↵-equivalence.

let a = N in M(a) (fun a M(a))N ! !

Higher-order frameworks

Higher-order rewrite systems (CRS, HRS, etc.) include a • general binding construct and terms are defined modulo ↵-equivalence. Example: -rule

app(lam([a]Z(a)), Z 0) Z(Z 0) ! One step of rewriting:

app(lam([a]f (a, g(a)), b) f (b, g(b)) ! using (a restriction of) higher-order matching.

Maribel Fern´andez Nominal Rewriting and Unification Theory Higher-order frameworks

Higher-order rewrite systems (CRS, HRS, etc.) include a • general binding construct and terms are defined modulo ↵-equivalence. Example: -rule

app(lam([a]Z(a)), Z 0) Z(Z 0) ! One step of rewriting:

app(lam([a]f (a, g(a)), b) f (b, g(b)) ! using (a restriction of) higher-order matching. Logical frameworks based on Higher-Order Abstract Syntax • also work modulo ↵-equivalence.

let a = N in M(a) (fun a M(a))N ! !

Maribel Fern´andez Nominal Rewriting and Unification Theory Implicit ↵-equivalence (+) • We targeted ↵ but now we have to deal with too (-) • Substitution is a meta-operation using (-) • Unification is undecidable in general (-) • Leaving name dependencies implicit is convenient, e.g. • let a = N in M vs. let a = N in M(a)

app(lambda[a]Z, Z 0)vs. app(lam([a]Z(a)), Z 0).

Higher-order frameworks

The syntax includes binders (+) )

Maribel Fern´andez Nominal Rewriting and Unification Theory We targeted ↵ but now we have to deal with too (-) • Substitution is a meta-operation using (-) • Unification is undecidable in general (-) • Leaving name dependencies implicit is convenient, e.g. • let a = N in M vs. let a = N in M(a)

app(lambda[a]Z, Z 0)vs. app(lam([a]Z(a)), Z 0).

Higher-order frameworks

The syntax includes binders (+) • Implicit ↵-equivalence (+) )

Maribel Fern´andez Nominal Rewriting and Unification Theory Substitution is a meta-operation using (-) • Unification is undecidable in general (-) • Leaving name dependencies implicit is convenient, e.g. • let a = N in M vs. let a = N in M(a)

app(lambda[a]Z, Z 0)vs. app(lam([a]Z(a)), Z 0).

Higher-order frameworks

The syntax includes binders (+) • Implicit ↵-equivalence (+) • We targeted ↵ but now we have to deal with too (-) )

Maribel Fern´andez Nominal Rewriting and Unification Theory Unification is undecidable in general (-) • Leaving name dependencies implicit is convenient, e.g. • let a = N in M vs. let a = N in M(a)

app(lambda[a]Z, Z 0)vs. app(lam([a]Z(a)), Z 0).

Higher-order frameworks

The syntax includes binders (+) • Implicit ↵-equivalence (+) • We targeted ↵ but now we have to deal with too (-) • Substitution is a meta-operation using (-) )

Maribel Fern´andez Nominal Rewriting and Unification Theory Leaving name dependencies implicit is convenient, e.g. • let a = N in M vs. let a = N in M(a)

app(lambda[a]Z, Z 0)vs. app(lam([a]Z(a)), Z 0).

Higher-order frameworks

The syntax includes binders (+) • Implicit ↵-equivalence (+) • We targeted ↵ but now we have to deal with too (-) • Substitution is a meta-operation using (-) • Unification is undecidable in general (-) )

Maribel Fern´andez Nominal Rewriting and Unification Theory Higher-order frameworks

The syntax includes binders (+) • Implicit ↵-equivalence (+) • We targeted ↵ but now we have to deal with too (-) • Substitution is a meta-operation using (-) • Unification is undecidable in general (-) • Leaving name dependencies implicit is convenient, e.g. ) let a = N in M vs. let a = N in M(a)

app(lambda[a]Z, Z 0)vs. app(lam([a]Z(a)), Z 0).

Maribel Fern´andez Nominal Rewriting and Unification Theory Built-in ↵-equivalence • Simple notion of substitution (first order) • Ecient matching and unification algorithms • Dependencies of terms on names are implicit • Easy to express conditions such as a fv(M) • 62

Nominal Approach

Key ideas: Freshness conditions a#t, name swapping (ab) t. ·

Example and ⌘ rules as nominal rewriting rules:

app(lam([a]Z), Z ) subst([a]Z, Z ) 0 ! 0 a#M (([a]app(M, a)) M ` ! Terms with binders )

Maribel Fern´andez Nominal Rewriting and Unification Theory Simple notion of substitution (first order) • Ecient matching and unification algorithms • Dependencies of terms on names are implicit • Easy to express conditions such as a fv(M) • 62

Nominal Approach

Key ideas: Freshness conditions a#t, name swapping (ab) t. ·

Example and ⌘ rules as nominal rewriting rules:

app(lam([a]Z), Z ) subst([a]Z, Z ) 0 ! 0 a#M (([a]app(M, a)) M ` ! Terms with binders • Built-in ↵-equivalence )

Maribel Fern´andez Nominal Rewriting and Unification Theory Ecient matching and unification algorithms • Dependencies of terms on names are implicit • Easy to express conditions such as a fv(M) • 62

Nominal Approach

Key ideas: Freshness conditions a#t, name swapping (ab) t. ·

Example and ⌘ rules as nominal rewriting rules:

app(lam([a]Z), Z ) subst([a]Z, Z ) 0 ! 0 a#M (([a]app(M, a)) M ` ! Terms with binders • Built-in ↵-equivalence • Simple notion of substitution (first order) )

Maribel Fern´andez Nominal Rewriting and Unification Theory Dependencies of terms on names are implicit • Easy to express conditions such as a fv(M) • 62

Nominal Approach

Key ideas: Freshness conditions a#t, name swapping (ab) t. ·

Example and ⌘ rules as nominal rewriting rules:

app(lam([a]Z), Z ) subst([a]Z, Z ) 0 ! 0 a#M (([a]app(M, a)) M ` ! Terms with binders • Built-in ↵-equivalence • Simple notion of substitution (first order) • Ecient matching and unification algorithms )

Maribel Fern´andez Nominal Rewriting and Unification Theory Easy to express conditions such as a fv(M) • 62

Nominal Approach

Key ideas: Freshness conditions a#t, name swapping (ab) t. ·

Example and ⌘ rules as nominal rewriting rules:

app(lam([a]Z), Z ) subst([a]Z, Z ) 0 ! 0 a#M (([a]app(M, a)) M ` ! Terms with binders • Built-in ↵-equivalence • Simple notion of substitution (first order) • Ecient 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 (ab) t. ·

Example and ⌘ rules as nominal rewriting rules:

app(lam([a]Z), Z ) subst([a]Z, Z ) 0 ! 0 a#M (([a]app(M, a)) M ` ! Terms with binders • Built-in ↵-equivalence • Simple notion of substitution (first order) • Ecient matching and unification algorithms • Dependencies of terms on names are implicit • Easy to express conditions such as a fv(M) ) 62 Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Terms: • s, t ::= a ⇡ X [a]t ft (t ,...,t ) | · | | | 1 n Id X written as X . · Example (ML): var(a), app(t, t ), lam([a]t), let(t, [a]t ), • 0 0 letrec[f ]([a]t, t0), subst([a]t, t0) Syntactic sugar: a,(tt ), a.t,leta = t in t ,letrecfa = t in t , t[a t ] 0 0 0 7! 0

Nominal Syntax [Urban, Pitts, Gabbay 2004]

Variables: M, N, X , Y ,... • Atoms: a, b,... Function symbols ( formers): f , g ...

Swappings:(ab) Def. (ab)a = b,(ab)b = a,(ab)c = c Permutations: finite bijections on names, represented as lists of swappings, denoted ⇡ (Id empty).

Maribel Fern´andez Nominal Rewriting and Unification Theory Example (ML): var(a), app(t, t ), lam([a]t), let(t, [a]t ), • 0 0 letrec[f ]([a]t, t0), subst([a]t, t0) Syntactic sugar: a,(tt ), a.t,leta = t in t ,letrecfa = t in t , t[a t ] 0 0 0 7! 0

Nominal Syntax [Urban, Pitts, Gabbay 2004]

Variables: M, N, X , Y ,... • Atoms: a, b,... Function symbols (term formers): f , g ...

Swappings:(ab) Def. (ab)a = b,(ab)b = a,(ab)c = c Permutations: finite bijections on names, represented as lists of swappings, denoted ⇡ (Id empty). Nominal Terms: • s, t ::= a ⇡ X [a]t ft (t ,...,t ) | · | | | 1 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:(ab) Def. (ab)a = b,(ab)b = a,(ab)c = c Permutations: finite bijections on names, represented as lists of swappings, denoted ⇡ (Id empty). Nominal Terms: • s, t ::= a ⇡ X [a]t ft (t ,...,t ) | · | | | 1 n Id X written as X . · Example (ML): var(a), app(t, t ), lam([a]t), let(t, [a]t ), • 0 0 letrec[f ]([a]t, t0), subst([a]t, t0) Syntactic sugar: a,(tt ), a.t,leta = t in t ,letrecfa = t in t , t[a t ] 0 0 0 7! 0 Maribel Fern´andez Nominal Rewriting and Unification Theory b#X [a]X [b](ab) X • ` ⇡↵ ·

↵-equivalence

We use freshness to avoid name capture: a#X means a fv(X )whenX is instantiated. 62

ds(⇡,⇡0)#X a a ↵ ⇡ X ⇡0 X ⇡ · ⇡↵ · s1 ↵ t1 sn ↵ tn s t ⇡ ··· ⇡ ⇡↵ (s1,...,sn) ↵ (t1,...,tn) fs ft ⇡ ⇡↵ s ↵ t a#ts(ab) t ⇡ ⇡↵ · [a]s ↵ [a]t [a]s [b]t ⇡ ⇡↵ where ds(⇡,⇡0)= n ⇡(n) = ⇡0(n) { | 6 } a#X , b#X (ab) X X • ` · ⇡↵

Maribel Fern´andez Nominal Rewriting and Unification Theory ↵-equivalence

We use freshness to avoid name capture: a#X means a fv(X )whenX is instantiated. 62

ds(⇡,⇡0)#X a a ↵ ⇡ X ⇡0 X ⇡ · ⇡↵ · s1 ↵ t1 sn ↵ tn s t ⇡ ··· ⇡ ⇡↵ (s1,...,sn) ↵ (t1,...,tn) fs ft ⇡ ⇡↵ s ↵ t a#ts(ab) t ⇡ ⇡↵ · [a]s ↵ [a]t [a]s [b]t ⇡ ⇡↵ where ds(⇡,⇡0)= n ⇡(n) = ⇡0(n) { | 6 } a#X , b#X (ab) X X • ` · ⇡↵ b#X [a]X [b](ab) X • ` ⇡↵ ·

Maribel Fern´andez Nominal Rewriting and Unification Theory Freshness

Also defined by induction:

1 ⇡ (a)#X a#b a#[a]s a#⇡ X · a#s a#s a#s a#s 1 ··· n a#(s1,...,sn) a#fs a#[b]s

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 , (xy) 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 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 rV(r) V () V (l) ` ! [ ✓ Example: Prenex Normal Forms

a#P P [a]Q [a](P Q) ` ^8 !8 ^ a#P ( [a]Q) P [a](Q P) ` 8 ^ !8 ^ a#P P [a]Q [a](P Q) ` _8 !8 _ a#P ( [a]Q) P [a](Q P) ` 8 _ !8 _ a#P P [a]Q [a](P Q) ` ^9 !9 ^ a#P ( [a]Q) P [a](Q P) ` 9 ^ !9 ^ a#P P [a]Q [a](P Q) ` _9 !9 _ a#P ( [a]Q) P [a](Q P) ` 9 _ !9 _ ( [a]Q) [a] Q `¬9 !8 ¬ ( [a]Q) [a] Q `¬8 !9 ¬

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Rewriting

Rewriting relation generated by R = l r: s R t r` ! ` ! s rewrites with R to t in the context when: 1 s C[s ]suchthat✓ solves ( l) ( s ) ⌘ 0 r` ?⇡ ` 0 2 C[r✓] t. ` ⇡↵

Example Beta-reduction in the Lambda-calculus:

Beta ([a]X )Y X [a Y ] ! 7! a[a Y ] Y a 7! ! (XX )[a Y ] X [a Y ]X [a Y ] app 0 7! ! 7! 0 7! a#Y Y [a X ] Y ✏ ` 7! ! b#Y ([b]X )[a Y ] [b](X [a Y ]) ` 7! ! 7!

Rewriting steps: ([c]c)Z c[c Z] Z ! 7! ! 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 . Recall: For first order terms, there are very ecient 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. Ecient 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,...)withfixedarities(thearity • of a symbol is the number of arguments associated with it).

A term is either a variable, or has the form f (t1,...,tn)wheref is a function symbol of arity n and t1,...,tn are terms.

Example: f (f (X , g(a)), Y )wherea is a constant, f abinary 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,calledmost general unifiers.

Definition: A substitution is a partial mapping from variables to terms, with a finite domain. We denote a substitution by: X t ,...,X t . { 1 7! 1 n 7! n} dom()= X ,...,X . { 1 n} A substitution is applied to a term t or a literal l by simultaneously replacing each variable occurring in dom()bythe corresponding term. The resulting term is denoted t.

Example: Let = X g(Y ), Y a and t = f (f (X , g(a)), Y ). { 7! 7! } 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 0, L [], Y [1,2], U [0|Z] { 7! 7! 7! 7! } 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 sucient to take Z [1,2] . { 7! } Thus, U [0,1,2] is an answer substitution. { 7! } This method is based on the Principle of Resolution.

Maribel Fern´andez Nominal Rewriting and Unification Theory Unification

A unification problem is a set of equations between terms with U variables s = t ,...,s = t { 1 1 n n} A solution to ,alsocalledaunifier, is a substitution such that U for each equation s = t ,thetermss and t coincide. i i 2U i i The most general unifier of is a unifier such that any other U 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,whichapplytosets of equations and produce new sets of equations or a failure.

Maribel Fern´andez Nominal Rewriting and Unification Theory Unification Algorithm

Input: Afiniteset of equations: s = t ,...,s = t { 1 1 n 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 ,...,s )=f (t ,...,t ), E s = t ,...,s = t , E 1 n 1 n ! 1 1 n n (2) f (s ,...,s )=g(t ,...,t ), E failure 1 n 1 m ! (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 t if ! { 7! } X not in t and X in E (6) X = t, E failure if X in t ! and X = t 6

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 we obtain a substitution, which is the most 7! 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 0, L [],Y [1,2], U [0|Z] { 7! 7! 7! 7! }

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 ,...,s ), Pr = a#s ,...,a#s , Pr 1 n ) 1 n a#[b]s, Pr = a#s, Pr ) a#[a]s, Pr = Pr ) a#⇡ X , Pr = ⇡-1 a#X , Pr ⇡ Id · ) · 6⌘ a a, Pr = Pr ⇡↵ ) (l ,...,l ) (s ,...,s ), Pr = l s ,...,l s , Pr 1 n ⇡↵ 1 n ) 1 ⇡↵ 1 n ⇡↵ n fl fs, Pr = l s, Pr ⇡↵ ) ⇡↵ [a]l [a]s, Pr = l s, Pr ⇡↵ ) ⇡↵ [b]l [a]s, Pr = (ab) l s, a#l, Pr ⇡↵ ) · ⇡↵ ⇡ X ⇡ X , Pr = ds(⇡,⇡ )#X , Pr · ⇡↵ 0 · ) 0

Maribel Fern´andez Nominal Rewriting and Unification Theory Checking ↵-equivalence of terms

The relation = is confluent and strongly normalising: ) the simplification process terminates, the result is unique: Pr h inf Pr is of the form Contr Eq where: h inf [ [ contains consistent freshness constraints (a#X ) Contr contains inconsistent freshness constraints (a#a) Eq contains reduced constraints. ⇡↵ Lemma: Pr if and only if Pr . • ` `h inf Let Pr = Contr Eq.Then Pr if and only if • h inf [ [ ` Contr and Eq are empty.

Maribel Fern´andez Nominal Rewriting and Unification Theory 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 a]) and ( a#X , b#X , Id)resp. • ; 7! { }

Solving Equations [Urban, Pitts, Gabbay 2003]

Nominal Unification: l t has solution (,✓)if • ?⇡? l✓ t✓ ` ⇡↵

Maribel Fern´andez Nominal Rewriting and Unification Theory Examples: • ([a]X )=([b]b)?? ([a]X )=([b]X )?? Solutions: ( , [X a]) and ( a#X , b#X , Id)resp. • ; 7! { }

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 Solutions: ( , [X a]) and ( a#X , b#X , Id)resp. • ; 7! { }

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 a]) and ( a#X , b#X , Id)resp. • ; 7! { }

Maribel Fern´andez Nominal Rewriting and Unification Theory ( l) ( s )if • r` ?⇡ ` 0 , l s has solution ( ,✓), that is, ✓, l✓ s r ⇡↵ 0 0 0 `r ⇡↵ 0 and ` 0

Back to Nominal Rewriting

Let R = l r where V (l) V (s)= r` ! \ ; s rewrites with R to t in the context , written s R t, ` ! when: 1 s C[s ]suchthat✓ solves ( l) ( s ) ⌘ 0 r` ?⇡ ` 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 = l r where V (l) V (s)= r` ! \ ; s rewrites with R to t in the context , written s R t, ` ! when: 1 s C[s ]suchthat✓ solves ( l) ( s ) ⌘ 0 r` ?⇡ ` 0 2 C[r✓] t. ` ⇡↵ To define the reduction relation generated by nominal • rewriting rules we use nominal matching. ( l) ( s )if • r` ?⇡ ` 0 , l s has solution ( ,✓), that is, ✓, l✓ s r ⇡↵ 0 0 0 `r ⇡↵ 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: (,✓)suchthat Pr✓. ` Nominal matching algorithm: add an instantiation rule: • -1 ⇡ X u, Pr = X ⇡ u Pr[X ⇡-1 u] · ⇡↵ ) 7! · 7! · 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:

Beta ([a]X )Y X [a Y ] ! 7! a[a Y ] Y a 7! ! (XX )[a Y ] X [a Y ]X [a Y ] app 0 7! ! 7! 0 7! a#Y Y [a X ] Y ✏ ` 7! ! b#Y ([b]X )[a Y ] [b](X [a Y ]) ` 7! ! 7!

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

Ecient nominal matching algorithm? • Is nominal matching sucient (complete) for nominal • rewriting?

Maribel Fern´andez Nominal Rewriting and Unification Theory Problem: lazy permutations may grow (they accumulate). • To obtain an ecient algorithm, work with a single current • permutation, represented by an environment.

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 To obtain an ecient algorithm, work with a single current • permutation, represented by an environment.

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 ecient 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,⇠ # t. ⇡↵ ⌃ ⇡↵ ⇡ · A An environment problem Pr is either or ? s ⇠ t ,...,s ⇠ t . 1 ⇡↵ 1⌃ 1 n ⇡↵ n⌃ 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 ti . 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 Pr denotes the result of applying the core algorithm on Pr.

Maribel Fern´andez Nominal Rewriting and Unification Theory Core module

Phase 1 - Input: Pr =(s ⇠ t )n i ⇡↵ i ⌃ i i

Pr if a = ⇠⇡ t and t ⇠A Pr, a ↵ ⇠⌃t = · 62 ⇡ ) ( otherwise ? n Pr, (si ↵ ⇠⌃ui )1 if t =(u1,...,un) Pr, (s1,...,sn) ↵ ⇠⌃t = ⇡ ⇡ ) ( otherwise ? Pr, s ↵ ⇠⌃u if t = fu Pr, fs ↵ ⇠⌃t = ⇡ ⇡ ) ( otherwise ? Pr, s ↵ ⇠0⌃u if t =[b]u Pr, [a]s ↵ ⇠⌃t = ⇡ ⇡ ) ( otherwise ? where ⇠ =((a ⇠ b) ⇠ , (⇠ ⇠ 1 a ) b )inthelastrule, 0 ⇡ · ⇡ A [{ ⇡ · } \{ } and a, b could be the same atom. The normal forms for phase 1 rules are either or ? (⇡ X ⇠ s )n where s are nominal terms. i · i ⇡↵ i ⌃ i 1 i Maribel Fern´andez Nominal Rewriting and Unification Theory Core module

Phase 2 - Input: A Phase 1 normal form.

1 ⇡ X ⇠ t = X (⇡ ⇠) t (⇡ = Id) · ⇡↵ ⌃ ) ⇡↵ · ⌃ 6 where ⇡ 1 ⇠ =(⇡ 1 ⇠ ,⇠). · ⇡ A Above, ⇡ 1 applies only to ⇠ ,because⇡ X ⇠ t represents ⇡ · ⇡↵ ⌃ ⇡ X ⇠ t,⇠#t. · ⇡↵ ⇡ · A Phase 2 normal forms are either or (X ⇠ t )n,wherethe ? i ⇡↵ i ⌃ i 1 terms ti are standard nominal terms.

Maribel Fern´andez Nominal Rewriting and Unification Theory Core module

Phase 3 - Input: A Phase 2 normal form (X ⇠ t )n. i ⇡↵ i ⌃ i 1

⇠⇡ aa ⇠A ⇠⌃a = · 62 ) ( a ⇠A ? 2 ⇠ ft = f (⇠ t) ⌃ ) ⌃ ⇠ (t ,...,t )= (⇠ t )j ⌃ 1 j ) ⌃ i 1 ⇠ [a]s = [⇠ a]((⇠ a ) s) ⌃ ) ⇡ · \{ } ⌃ ⇠ (⇡ X )= (⇠ ⇡) X ⌃ · ) ⌃ Pr[ ]= ? )? where ⇠ a =(⇠ ,⇠ a )and⇠ ⇡ =((⇠ ⇡),⇡ 1(⇠ )). \{ } ⇡ A \{ } ⇡ A The normal forms are either or (X t )n where t T . ? i ⇡↵ i 1 i 2 ⇠ T = a fT (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] ,⇠ # X 0 ⇡↵ ⌃ ) ⇡↵ ⇡ · A Normal forms are either or (Xi ↵ ui )i I , (Aj # Xj )j J where ui ? ⇡ 2 2 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 If left-hand sides of ↵-constraints in Pr are ground, stop • ⇡ c otherwise reduce the result Pr using:

Pr , supp(⇡)#X if t = ⇡ X (↵) Pr , X ↵ t = · ⇡ ) ( otherwise ? where supp(⇡)= a ⇡ a = a { | · 6 } Normal forms: or (A # X )n. • ? i i 1 Correctness: If the normal form is then Pr is not valid. • ? If the normal form of Pr is (A # X )n then (A # X )n Pr. i i 1 i i 1 `

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 Normal forms: or (A # X )n. • ? i i 1 Correctness: If the normal form is then Pr is not valid. • ? If the normal form of Pr is (A # X )n then (A # X )n Pr. i i 1 i i 1 `

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 otherwise reduce the result Pr using:

Pr , supp(⇡)#X if t = ⇡ X (↵) Pr , X ↵ t = · ⇡ ) ( otherwise ? where supp(⇡)= a ⇡ a = a { | · 6 }

Maribel Fern´andez Nominal Rewriting and Unification Theory Correctness: If the normal form is then Pr is not valid. • ? If the normal form of Pr is (A # X )n then (A # X )n Pr. i i 1 i i 1 `

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 otherwise reduce the result Pr using:

Pr , supp(⇡)#X if t = ⇡ X (↵) Pr , X ↵ t = · ⇡ ) ( otherwise ? where supp(⇡)= a ⇡ a = a { | · 6 } Normal forms: or (A # X )n. • ? i i 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 otherwise reduce the result Pr using:

Pr , supp(⇡)#X if t = ⇡ X (↵) Pr , X ↵ t = · ⇡ ) ( otherwise ? where supp(⇡)= a ⇡ a = a { | · 6 } Normal forms: or (A # X )n. • ? i i 1 Correctness: If the normal form is then Pr is not valid. • ? If the normal form of Pr is (A # X )n then (A # X )n Pr. i i 1 i i 1 `

Maribel Fern´andez Nominal Rewriting and Unification Theory c If the problem is non-linear, normalise the result Pr by: • Pr, X ↵ s, X ↵ t = ⇡ ⇡ ) ↵ ↵ Pr, X s, s t ⇡ if s t ⇡ = ⇡↵ ⇡↵ ⇡↵ 6 ? ( 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 sucient.

Solving Matching Problems

To solve a matching problem Pr: Run the core algorithm on Pr •

Maribel Fern´andez Nominal Rewriting and Unification Theory 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 sucient.

Solving Matching Problems

To solve a matching problem Pr: Run the core algorithm on Pr • c If the problem is non-linear, normalise the result Pr by: • Pr, X ↵ s, X ↵ t = ⇡ ⇡ ) ↵ ↵ Pr, X s, s t ⇡ if s t ⇡ = ⇡↵ ⇡↵ ⇡↵ 6 ? ( otherwise ?

Maribel Fern´andez Nominal Rewriting and Unification Theory 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 sucient.

Solving Matching Problems

To solve a matching problem Pr: Run the core algorithm on Pr • c If the problem is non-linear, normalise the result Pr by: • Pr, X ↵ s, X ↵ t = ⇡ ⇡ ) ↵ ↵ Pr, X s, s t ⇡ if s t ⇡ = ⇡↵ ⇡↵ ⇡↵ 6 ? ( otherwise ? Normal forms: or a pair of a substitution and a freshness • ? context.

Maribel Fern´andez Nominal Rewriting and Unification Theory Remark: • If variables occur linearly in patterns then the core algorithm is sucient.

Solving Matching Problems

To solve a matching problem Pr: Run the core algorithm on Pr • c If the problem is non-linear, normalise the result Pr by: • Pr, X ↵ s, X ↵ t = ⇡ ⇡ ) ↵ ↵ Pr, X s, s t ⇡ if s t ⇡ = ⇡↵ ⇡↵ ⇡↵ 6 ? ( 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 If the problem is non-linear, normalise the result Pr by: • Pr, X ↵ s, X ↵ t = ⇡ ⇡ ) ↵ ↵ Pr, X s, s t ⇡ if s t ⇡ = ⇡↵ ⇡↵ ⇡↵ 6 ? ( 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 sucient.

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 Equivariant nominal matching is exponential... BUT • if rules are CLOSED then nominal matching is sucient. • Intuitively, closed means no free atoms. The rules in the examples above are closed.

Nominal Matching vs. Equivariant Matching

Nominal matching is ecient. •

Maribel Fern´andez Nominal Rewriting and Unification Theory if rules are CLOSED then nominal matching is sucient. • Intuitively, closed means no free atoms. The rules in the examples above are closed.

Nominal Matching vs. Equivariant Matching

Nominal matching is ecient. • Equivariant nominal matching is exponential... BUT •

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Matching vs. Equivariant Matching

Nominal matching is ecient. • Equivariant nominal matching is exponential... BUT • if rules are CLOSED then nominal matching is sucient. • 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 l r is closed when ⌘r ` !

( 0 (l 0, r 0)) ( , A(R0)#V (R) (l, r)) r ` ?⇡ r `

has a solution (where R0 is freshened with respect to R).

Given R l r and s a term-in-context we write ⌘r ` ! ` R R0 s t when , A(R0)#V (, s) s t ` !c ` ! 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 : (explicit) substitutions, subst([x]M, N)abbreviatedM[x N]. 7!

(Beta) ([a]X )X X [a X ] 0 ! 7! 0 ( )(XX )[a Y ] X [a Y ]X [a Y ] app 0 7! ! 7! 0 7! ( ) a[a X ] X a 7! ! ( ) a#Y Y [a X ] Y ✏ ` 7! ! ( ) b#Y ([b]X )[a Y ] [b](X [a Y ]) ` 7! ! 7!

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 is expressive: can encode Combinatory Reduction Systems. • is ecient: linear matching. • inherits confluence conditions from first order rewriting. •

Properties of Closed Rewriting

Closed Nominal Rewriting: works uniformly in ↵ equivalence classes of terms. •

Maribel Fern´andez Nominal Rewriting and Unification Theory is ecient: linear matching. • inherits confluence conditions from first order rewriting. •

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 inherits confluence conditions from first order rewriting. •

Properties of Closed Rewriting

Closed Nominal Rewriting: works uniformly in ↵ equivalence classes of terms. • is expressive: can encode Combinatory Reduction Systems. • is ecient: 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 ecient: linear matching. • inherits confluence conditions from first order rewriting. •

Maribel Fern´andez Nominal Rewriting and Unification Theory Confluence — Critical Pairs

Suppose 1 R = l r for i =1, 2 are copies of two rules in i ri ` i ! i R such that V (R ) V (R )= (R and R could be copies of 1 \ 2 ; 1 2 the same rule). 2 l L[l ]suchthat , , l l has a principal solution 1 ⌘ 10 r1 r2 10 ?⇡? 2 (,✓), so that l ✓ l ✓ and ✓ for i =1, 2. ` 10 ⇡↵ 2 `ri Then (r ✓, L✓[r ✓]) is a . ` 1 2 If L =[-]andR1, R2 are copies of the same rule, or if l10 is a variable, then we say the critical pair is trivial.

We distinguish: ⇡ If R2 is a copy of R1 , 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

Permutative overlap critical pair between rules R and R⇡. ! 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(ab) =( 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 ) f ([b]X ). ` 6⇡↵ This theory is not confluent; we have for instance:

f (a) R,✏,Id,[X a] R,✏,(ab),[X a] h 7! i h 7! i { # f ([a]a) f ([b]a) 6⇡↵ 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 insucient for local confluence, even for a uniform theory: the rule in Example above is uniform. However, it is not ↵-stable: R = l r is ↵-stable when, for all ,⇡,,, r` ! 0 , ⇡ , l l ⇡ implies r r ⇡ . `r r 0 ⇡↵ 0 ` ⇡↵ 0 Critical Pair Lemma for uniform ↵-stable theories: Let R = (⌃, Rw)beauniformrewritetheorywherealltherewrite 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 dicult 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 ecient: checking fresh overlaps and fresh critical pairs is sucient for closed rewriting. Let R = l r (i =1, 2) be freshened versions of rules. i ri ` i ! i If the nominal unification problem l l has a r1 [r2 [{2 ?⇡? 1|p} most general solution ,✓ for some position p,thenR fresh h i 1 overlaps with R2, and the pair of terms-in-context (r ✓, l ✓[p r ✓]) is a fresh critical pair. ` 1 1 2 If p is a variable position, or if R1 and R2 are equal modulo renaming of variables and p = ✏, then we call the overlap and critical pair trivial. If R1 and R2 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 ✓, l ✓[p r ✓]) is joinable if there is a ` 1 1 2 term u such that r ✓ u and (l ✓[p r ✓]) u. `R 1 !c `R 1 2 !c 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 Confluence — Critical Pairs

Since it is sucient to consider just one freshened version of each rule when computing overlaps of closed rules, the number of fresh critical pairs for a finite set of rules is finite. Thus, we have an e↵ective criterion for local confluence,similarto the criterion for first-order systems.

Example Explicit substitution rules in the -calculus (all rules except Beta) are locally confluent: every proper fresh critical pair is joinable. If we include Beta then the system is not locally confluent. This does not contradict the previous theorem: there is a proper fresh critical pair between (Beta) and (app), which is not joinable, obtained from ? (([a]X )Y )[b Z]: ` 7! ? ((([a]X )[b Z])(Y [b Z]), (X [a Y ])[b Z]). ` 7! 7! 7! 7!

Maribel Fern´andez Nominal Rewriting and Unification Theory Exercise: Critical Pairs

Compute all the proper, fresh critical pairs of the system defining beta-reduction in the lambda-calculus.

Maribel Fern´andez Nominal Rewriting and Unification Theory Confluence — Orthogonality

Theorem Orthogonal (i.e., left-linear, no non-trivial overlaps) uniform nominal rewriting systems are confluent.

Call a rewrite theory R = (⌃, Rw) fresh quasi-orthogonal when all rules are left-linear and there are no proper fresh critical pairs. Theorem If R is a fresh-quasi-orthogonal rewrite system, then the closed rewriting relation generated by R is confluent.

Example First-order logic signature: , and of arity 1, and , of arity ¬ 8 9 ^ _ 2(infix). Closed rules to simplify formulas:

(X Y ) (X ) (Y )andb#X ( [a]X ) [b] ((ba) X ). `¬ ^ !¬ _¬ `¬8 !9 ¬ · Maribel Fern´andez Nominal Rewriting and Unification Theory Confluence — Orthogonality

The criteria for local confluence / confluence of closed rewriting are easy to check using a nominal unification algorithm: just compute overlaps for the set of rules obtained by taking one freshened copy of each given rule.

For comparison, the criteria for general nominal rewriting require the computation of critical pairs for permutative variants of rules, which needs equivariant unification (exponential).

Maribel Fern´andez Nominal Rewriting and Unification Theory Types

So far, we have discussed untyped nominal terms.

There are also typed versions: many-sorted • Simply typed — Church-style and Curry-style • Polymorphic Curry-style systems (next slides) • Intersection type assignment systems • Dependently typed systems •

Maribel Fern´andez Nominal Rewriting and Unification Theory Polymorphic Curry-Style Types for Nominal Terms

Types built from a set of base data sorts (e.g. Nat, Bool, Exp, . . . ), and • type variables ↵, • using type constructors C (e.g. List, ,...) • ! Types: ,⌧ ::= ↵ (⌧ ... ⌧ ) C ⌧ []⌧ | | 1 ⇥ ⇥ n | | Type declarations: ⇢ ::= (↵). , ⌧ 8 h ! i Example succ : Nat , Nat h ! i length: (↵). List ↵, Nat (). List , Nat 8 h ! i⌘8 h ! i

Instantiation: E.g. (↵). ↵, ↵ Nat , Nat 8 h ! i < h ! i Maribel Fern´andez Nominal Rewriting and Unification Theory Typing Rules

Quasi-typing judgements: s : ⌧,definedinductively, ⌃ ` where is a typing context, ⌃a signature (set of declarations for term-formers), a freshness context, s atermand⌧ atype. neededlater.

a ⌧ X ⌧ ⌘ (atm)⌧ ⌘ (var)⌧ a: ⌧ ⇡ X : ⌧ ⌃ ` ⌃ ` ·

⌃f < , ⌧ ⌃ t : on (a: ⌧) ⌃ t : ⌧ 0 h ! i ` `

⌃ f t : ⌧ ⌃ [a] t :[⌧] ⌧ 0 ` `

⌃ t1 : ⌧1 ... ⌃ tn : ⌧n ` ` (tpl)⌧ (t ,...,t ): (⌧ ... ⌧ ) ⌃ ` 1 n 1 ⇥ ⇥ n

Maribel Fern´andez Nominal Rewriting and Unification Theory Typing Judgements

Typing judgement: A derivable quasi-typing judgement such that for every X , all occurrences of X are typed in the same essential environment: 1 ⇡ is the same for any ⇡ X in t. X · The latter is called linearity property.

Notation for typing judgements: s : ⌧ ⌃ `

Maribel Fern´andez Nominal Rewriting and Unification Theory Examples

a: ↵, X : ? (a, X ): (↵ ) ? ` ⇥ ? ? [a] a:[↵] ↵ ? ` a: ? [a] a:[↵] ↵ ? ` a: ⌧1, b : ⌧2, X : ⌧ ? (ab) X : ⌧ ? ` · a: ⌧1, b : ⌧1, X : ⌧ ? ((ab) X , Id X ): (⌧ ⌧) ? ` · · ⇥ X : ⌧ a # X ([a] Id X , Id X ): (⌧ ⌧) ? ` · · ⇥ a: ↵, b : , X : ⌧ ? [a]((ab) X , Id X ): [](⌧ ⌧) ? ` · · ⇥

Exercise: Show that each of these typing judgements is valid.

Maribel Fern´andez Nominal Rewriting and Unification Theory Type System Features

Generalisation of Hindley-Milner’s type system: atoms (can be abstracted or unabstracted), • variables (cannot be abstracted but can be instantiated, with • non-capture-avoiding substitutions), suspended permutations, • declarations for function symbols (term formers). •

Maribel Fern´andez Nominal Rewriting and Unification Theory Principal Types

Every term has a principal type, and type inference is • decidable. Principal types are obtained using a function pt(, ⌃, , s): • given a typeability problem t, pt returns a pair ⌃ ` (S,⌧) of a type substitution and a type, such that the quasi-typing judgement S t : ⌧ is derivable ⌃ ` and satisfies the linearity property, or fails if there is no such S,⌧. pt implemented in two phases: • 1) build a quasi-typing judgement derivation, 2) check essential typings. pt is sound and complete. •

Maribel Fern´andez Nominal Rewriting and Unification Theory Properties

Meta-level equivariance of typing judgements: • if t : ⌧,then⇡ ⇡ ⇡t : ⌧. ⌃ ` ⌃ `

Object-level equivariance of typing judgements: • if t : ⌧ then ⇡ ⇡ t : ⌧. ⌃ ` ⌃ ` ·

Well-typed substitutions preserve types: • If ✓ is well-typed in ,⌃and for t : ⌧,then ⌃ r` t ✓ : ⌧. ⌃ `

↵-equivalence preserves types: • s t and s : ⌧ imply t : ⌧. ` ⇡↵ ⌃ ` ⌃ `

Maribel Fern´andez Nominal Rewriting and Unification Theory Subject Reduction

Typeable rewrite rule l r : ⌧ ⌃ r` ! 1 l r is a uniform rule; r` ! 2 pt( l)=(Id,⌧)and (l, r): (⌧ ⌧). ⌃ r` ⌃ r` ⇥

Remark: reductions do not generate new atoms (uniform rules); l and r are both typeable with the principal type of l,sothe essential environments of both sides of the rule are the same (key!).

Typed Nominal Matching: The substitution must be will be typed.

Subject Reduction: The rewrite relation generated by typeable rewrite rules using typed nominal matching preserves types.

Maribel Fern´andez Nominal Rewriting and Unification Theory Typeable Rewrite Rules

X : ↵, Y : ⌃ ? app ((lam [a] X ), Y ) sub ([a] X , Y ): ↵ ` ! X : ↵ a # X lam [a](app(X , a)) X : ↵ ) ⌃ ` ! )

X : ↵, Z : a # X sub ([a] X , Z) X : ↵ ⌃ ` !

Z : ⌃ ? sub ([a] a, Z) Z : ` !

X : ↵, Y : , Z : ⌃ ? sub ([a](app(X , Y )), Z) ) ` app (sub ([a] X , Z), sub ([a] Y , Z)): ↵ ! X : ↵, Z : b # Z sub ([a](lam[b] X ), Z) ⌃ ` lam [b](sub([a] X , Z)): ↵0 ↵ ! )

Exercise: Show that the above rules satisfy the conditions in the definition of typeable rule. Maribel Fern´andez Nominal Rewriting and Unification Theory Why Typed Matching?

Assume ⌃ = (↵). ↵, Nat and ⌃ = () , Bool and a rule f 8 h ! i true h ! i

X : Nat ⌃ ? f X X : Nat ` !

? The untyped pattern-matching problem ? f X ↵ ? ftrue ` ⇡ ` has a solution X true. 7! The typed pattern matching problem ? (X : Nat ⌃ ? f X ) ↵ (? ⌃ ? f true) has none: the ` ⇡ ` substitution X true is not well-typed, because X is required to 7! have the type Nat, but it is instantiated with a term of type Bool.

Maribel Fern´andez Nominal Rewriting and Unification Theory More ecient: Typed Closed Nominal Rewriting

Typeable-closed rewrite rule l r : ⌧ ⌃ r` ! 1 l r is closed. r` ! 2 pt( l)=(Id,⌧)and (l, r): (⌧ ⌧). ⌃ r` ⌃ r` ⇥ 3 Every variable in l has an occurrence within a function application f t, and for every subderivation f t : ⌧ 0 ⌃ ` 0 in l where t is not ground, if ⌃ = (↵). , ⌧ ,thenthe f 8 h ! i type of t is as general as .

Subject Reduction: The closed rewriting relation generated by typeable-closed rules preserves types.

Maribel Fern´andez Nominal Rewriting and Unification Theory Exercises: Typed Closed Nominal Rewriting

Consider again the rewrite system defining beta-reduction in the lambda-calculus. Are all the rules typeable-closed?

Maribel Fern´andez Nominal Rewriting and Unification Theory Undecidable in general!

Decidable subcases: C, AC, ACU, . . . [Baader, Kapur, Narendran, Siekmann, Schmidt-Schauß, etc..]

Theories with AC operators

Recall:

First Order E-Unification problem: Instance: given two terms s and t and an equational theory E. Question: is there a substitution such that s =E t?

Maribel Fern´andez Nominal Rewriting and Unification Theory Decidable subcases: C, AC, ACU, . . . [Baader, Kapur, Narendran, Siekmann, Schmidt-Schauß, etc..]

Theories with AC operators

Recall:

First Order E-Unification problem: Instance: given two terms s and t and an equational theory E. Question: is there a substitution such that s =E t?

Undecidable in general!

Maribel Fern´andez Nominal Rewriting and Unification Theory Theories with AC operators

Recall:

First Order E-Unification problem: Instance: given two terms s and t and an equational theory E. Question: is there a substitution such that s =E t?

Undecidable in general!

Decidable subcases: C, AC, ACU, . . . [Baader, Kapur, Narendran, Siekmann, Schmidt-Schauß, etc..]

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal E-Unification: ↵ and E. Modular extension of first-order equational unification procedures?

It depends on the theory E...

Nominal Equational Unification problem: Instance: given two nominal terms s and t and an equational theory E. Question: is there a substitution and a freshness context r such that s t? r` ⇡↵,E

Maribel Fern´andez Nominal Rewriting and Unification Theory It depends on the theory E...

Nominal Equational Unification problem: Instance: given two nominal terms s and t and an equational theory E. Question: is there a substitution and a freshness context r such that s t? r` ⇡↵,E

Nominal E-Unification: ↵ and E. Modular extension of first-order equational unification procedures?

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Equational Unification problem: Instance: given two nominal terms s and t and an equational theory E. Question: is there a substitution and a freshness context r such that s t? r` ⇡↵,E

Nominal E-Unification: ↵ and E. Modular extension of first-order equational unification procedures?

It depends on the theory E...

Maribel Fern´andez Nominal Rewriting and Unification Theory OR(p(a), p((cd) X ))) ? (ab) OR(p((ab) X ), p(b)), · ⇡↵ · · a#?OR(p((ab) X ), p(b)) · ⇤ + OR(p(a), p((cd) X ))) ? OR(p(X ), p(a)), b#?X · ⇡↵ + p(a) ? p(X ), p((cd) X ) ? p(a), b#X ⇡↵ · ⇡↵ + a ? X , (cd) X ? a, b#X ⇡↵ · ⇡↵ [X a] + 7! (cd) a ? a, b#a · ⇡↵ + ?

Interference: Commutative Symbols OR,+

[a]OR(p(a), p((cd) X )) ? [b]OR(p((ab) X ), p(b)) 8 · ⇡↵ 8 · +

Maribel Fern´andez Nominal Rewriting and Unification Theory OR(p(a), p((cd) X ))) ? OR(p(X ), p(a)), b#?X · ⇡↵ + p(a) ? p(X ), p((cd) X ) ? p(a), b#X ⇡↵ · ⇡↵ + a ? X , (cd) X ? a, b#X ⇡↵ · ⇡↵ [X a] + 7! (cd) a ? a, b#a · ⇡↵ + ?

Interference: Commutative Symbols OR,+

[a]OR(p(a), p((cd) X )) ? [b]OR(p((ab) X ), p(b)) 8 · ⇡↵ 8 · + OR(p(a), p((cd) X ))) ? (ab) OR(p((ab) X ), p(b)), · ⇡↵ · · a#?OR(p((ab) X ), p(b)) · ⇤ +

Maribel Fern´andez Nominal Rewriting and Unification Theory Interference: Commutative Symbols OR,+

[a]OR(p(a), p((cd) X )) ? [b]OR(p((ab) X ), p(b)) 8 · ⇡↵ 8 · + OR(p(a), p((cd) X ))) ? (ab) OR(p((ab) X ), p(b)), · ⇡↵ · · a#?OR(p((ab) X ), p(b)) · ⇤ + OR(p(a), p((cd) X ))) ? OR(p(X ), p(a)), b#?X · ⇡↵ + p(a) ? p(X ), p((cd) X ) ? p(a), b#X ⇡↵ · ⇡↵ + a ? X , (cd) X ? a, b#X ⇡↵ · ⇡↵ [X a] + 7! (cd) a ? a, b#a · ⇡↵ + ?

Maribel Fern´andez Nominal Rewriting and Unification Theory OR is a commutative symbol:

OR(p(a), p((cd) X ))) ? OR(p(X ), p(a)), b#?X · ⇡↵

Maribel Fern´andez Nominal Rewriting and Unification Theory OR is a commutative symbol:

OR(p(a), p((cd) X ))) ? OR(p(X ), p(a)), b#?X · ⇡↵,C + p(a) ? p(a), p((cd) X ) ? p(X ), b#?X ⇡↵ · ⇡↵,C + p((cd) X ) ? p(X ), b#?X · ⇡↵,C + (cd) X ? X , b#?X · ⇡↵,C

Maribel Fern´andez Nominal Rewriting and Unification Theory First-order C-unification is finitary. Nominal C-unification is NOT, if we represent solutions using substitutions and freshness contexts. Alternative representation?

(cd) X ? X has infinite principal solutions! · ⇡↵,C X c + d, X f (c + d), X [e]c +[e]d,... • 7! 7! 7!

Nominal C-Unification Procedure [Ayala-Rinc´onet al.]:

1 Simplification phase: Build a derivation tree (branching for C symbols) 2 Solve fixed point constraints X ⇡ X ⇡↵,C ·

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal C-unification is NOT, if we represent solutions using substitutions and freshness contexts. Alternative representation?

(cd) X ? X has infinite principal solutions! · ⇡↵,C X c + d, X f (c + d), X [e]c +[e]d,... • 7! 7! 7!

Nominal C-Unification Procedure [Ayala-Rinc´onet al.]:

1 Simplification phase: Build a derivation tree (branching for C symbols) 2 Solve fixed point constraints X ⇡ X ⇡↵,C ·

First-order C-unification is finitary.

Maribel Fern´andez Nominal Rewriting and Unification Theory (cd) X ? X has infinite principal solutions! · ⇡↵,C X c + d, X f (c + d), X [e]c +[e]d,... • 7! 7! 7!

Nominal C-Unification Procedure [Ayala-Rinc´onet al.]:

1 Simplification phase: Build a derivation tree (branching for C symbols) 2 Solve fixed point constraints X ⇡ X ⇡↵,C ·

First-order C-unification is finitary. Nominal C-unification is NOT, if we represent solutions using substitutions and freshness contexts. Alternative representation?

Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Sets

Perm(A): group of finite permutations of A S: set equipped with an action of the group Perm(A) Definition A A is a support for an element x S if for all ⇡ Perm(A) ⇢ 2 2 (( a A) ⇡(a)=a) ⇡ x = x (1) 8 2 ) · A nominal set is a set equipped with an action of the group Perm(A), all of whose elements have finite support.

suppS (x): least finite support of x Example: If a A then supp(a)= a 2 { } supp(app(a, g(c, d))) = a, c, d { }

Maribel Fern´andez Nominal Rewriting and Unification Theory Let S be a nominal set. The fixed-point relation Perm(A) S is defined as: f ✓ ⇥ ⇡ x ⇡ x = x f , · Read “⇡ f x”as“⇡ fixes x”.

Freshness vs. Fixed-Point Constraints

Definition of Freshness [Pitts2013]:

a#X N a0.(aa0) X = X , ·

Freshness derived from N and a notion of permutation fixed-point.

Maribel Fern´andez Nominal Rewriting and Unification Theory Freshness vs. Fixed-Point Constraints

Definition of Freshness [Pitts2013]:

a#X N a0.(aa0) X = X , ·

Freshness derived from N and a notion of permutation fixed-point.

Let S be a nominal set. The fixed-point relation Perm(A) S is defined as: f ✓ ⇥ ⇡ x ⇡ x = x f , · Read “⇡ f x”as“⇡ fixes x”.

Maribel Fern´andez Nominal Rewriting and Unification Theory ↵-equivalence via fixed point constraints

Notation: ↵-equivalence constraint: s f t • ⇡↵ Fixed-point constraint: ⇡ t • f Intuitively, ⇡ fixes t if ⇡ t f t, · ⇡↵ ⇡ has “no e↵ect” on t except for possible renaming of bound names, for instance, (ab) f [a]a but not (ab) f f a. Primitive fixed-point constraint: ⇡ X • f Fixed-point context:⌥= ⇡ X ,...,⇡ X • { 1 f 1 k f k } Support of a permutation: supp(⇡)= a ⇡(a) = a • { | 6 }

Maribel Fern´andez Nominal Rewriting and Unification Theory Fixed-Point Rules

Notation: perm(⌥ ) permutations that fix X according to ⌥ |X

1 ⇡0 ⇡(a)=a supp(⇡ ) supp(perm(⌥ X )) (fa) ✓ | (fvar) ⌥ ⇡ f a ⌥ ⇡ ⇡0 X ` ` f ·

⌥ ⇡ t ⌥ ⇡ t1 ... ⌥ ⇡ tn f ` f ` f ` (ff) (ftuple) ⌥ ⇡ f t ⌥ ⇡ f (t1,...,tn) ` f `

Var ⌥, (c1 c2) f (t) ⇡ f (ac1) t c1 and c2 ` · (fabs), ⌥ ⇡ [a]t new names ` f

Maribel Fern´andez Nominal Rewriting and Unification Theory Alpha-Equivalence Rules

1 f supp((⇡0) ⇡) supp(perm(⌥ X )) ( ↵ a) f f ✓ | ( ↵ var) ⌥ a ↵ a ⇡ f ⌥ ⇡ X ⇡0 X ⇡ ` ⇡ ` · ⇡↵ · f f f ⌥ t ↵ t0 ⌥ t1 ↵ t0 ... ⌥ tn ↵ t0 f ` ⇡ 1 ` ⇡ n f ` ⇡ ( ↵ f) ( ↵ tuple) f f ⌥ f t f t0 ⇡ ⌥ (t1,...,tn) ↵ (t0 ,...,t0 ) ⇡ ` ⇡↵ ` ⇡ 1 n

f ⌥ t ↵ t0 f ` ⇡ ( ↵ [a]) f ⌥ [a]t [a]t0 ⇡ ` ⇡↵ f ⌥ s ↵ (ab) t ⌥, (c1 c2) Var(t) (ac1) t f f f ` ⇡ · ` ( ↵ ab) ⌥ [a]s f [b]t ⇡ ` ⇡↵

Maribel Fern´andez Nominal Rewriting and Unification Theory Correctness

Theorem ⌥ ⇡ t i↵ ⌥ ⇡ t f t. ` f ` · ⇡↵

[ ]f maps freshness constraints in to fixed-point constraints: [ ] : F f ! f a#X (ac) X where c is a new name. 7! a f a [ ]#maps fixed-point constraints in ⌥to freshness constraints: [ ] :⌥ F # ! # ⇡ X supp(⇡)#X . f 7!

Theorem f 1 s t [] s t. ` ⇡↵ ) f ` ⇡↵ f 2 ⌥ s t [⌥] s t. ` ⇡↵ ) # ` ⇡↵

Maribel Fern´andez Nominal Rewriting and Unification Theory Simplification Rules for Nominal Unification

? (fat) Pr ⇡ f a = Pr, if ⇡(a)=a ]{ ? } ) ? (ff ) Pr ⇡ f ft = Pr ⇡ f t ]{ ? } ) [{ ? } ? (ft) Pr ⇡ f (t)n = Pr ⇡ f t1,...,⇡f tn ]{ ? } ) [{ ? } ? (fabs) Pr ⇡ f [a]t = Pr ⇡ f (ac1) t, (c1 c2) f Var(t) ]{ ? } ) [{(⇡ ) 1 ? · } (fvar) Pr ⇡ f ⇡e0 X = Pr ⇡ 0 f X , if ⇡0 = Id ]{ ? · } ) [{ } 6 f f ( ↵ a) Pr a ↵ a = Pr ⇡ ]{ ⇡ ? } ) f f ? ( ↵ f ) Pr f t ↵ f t0 = Pr t ↵ t0 ⇡ ]{ ⇡ } ) [{ ⇡ ? } ? f ? f f ( ↵ t) Pr (t)n ↵ (t0)n = Pr t1 ↵ t10 ,...,tn ↵ tn0 ⇡ ]{ ⇡? } ) [{ ⇡? ⇡ } f f f ( ↵ ab1) Pr [a]t ↵ [a]t0 = Pr t ↵ t0 ⇡ ]{ e ⇡? e } ) [{ ⇡? } f f f ? ( ↵ ab2) Pr [a]t ↵ [b]s = Pr t ↵ (ab) s, (ac1) f s, ⇡ ]{ ⇡ } ) [{ ⇡ ? · (c1 c2) f Var(s) ? } f f 1 ? ( ↵ var) Pr ⇡ X ⇡0 X = Pr (⇡0) ⇡ X ⇡ ]{ · ⇡↵ · } ) [{ f } ? [X ⇡ 1.t] f f 7! 1 ( ↵ inst1) Pr ⇡ X ↵ t = Pr X ⇡ .t , if X / Var(t) ⇡ ]{ · ? ⇡ } )1 { 7! } 2 f f [X ⇡ .t] 1 ( ↵ inst2) Pr t ⇡ X 7!= Pr X ⇡ .t , if X / Var(t) ⇡ ]{ ⇡↵ · } ) { 7! } 2

c1 and c2 are new names

Maribel Fern´andez Nominal Rewriting and Unification Theory To f constraints: ? [a]f(X , a) f [b]f((bc).W , (ac).Y )) ⇡↵ ? + f ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ⇡ (ac1) f f((bc).W , (ac).Y )) a#f((bc) W , (ac) Y )) ? ? · · (c1 c2) f W , (c1 c2) f Y +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ? + ⇡ f a#(bc) W , a#(ac) Y f(X , a) ↵ (ab).f((bc).W , (ac).Y )) · · ⇡? ? ⇤ (ac1) f (bc).W , (ac1) f (ac).Y ?+ ? ? ? X ↵ (ab)(bc) W , b ↵ Y (c1 c2) f W , (c1 c2) f Y ⇡ · ⇡ a#W , c#Y ? + ? Y b X f (ab)(bc).W , a f (ab)(ac).Y ?+ 7! ↵ ↵ X ↵ (ab)(bc) W ⇡ ? ? ⇡ ⇡ · (ac1) f W , (cc1) f Y a#W , c#b ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc) W + 7! · X (ab)(bc).W , Y b a#W + ?7! ? 7! (ac1) f W , (c1 c2) f W Sol =(a#W , ) Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints:

? [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · +

Maribel Fern´andez Nominal Rewriting and Unification Theory To f constraints: ? [a]f(X , a) f [b]f((bc).W , (ac).Y )) ⇡↵ ? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? (ac1) f f((bc).W , (ac).Y )) ? ? (c1 c2) f W , (c1 c2) f Y ? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ? + ⇡ f a#(bc) W , a#(ac) Y f(X , a) ↵ (ab).f((bc).W , (ac).Y )) · · ⇡? ? ⇤ (ac1) f (bc).W , (ac1) f (ac).Y ?+ ? ? ? X ↵ (ab)(bc) W , b ↵ Y (c1 c2) f W , (c1 c2) f Y ⇡ · ⇡ a#W , c#Y ? + ? Y b X f (ab)(bc).W , a f (ab)(ac).Y ?+ 7! ↵ ↵ X ↵ (ab)(bc) W ⇡ ? ? ⇡ ⇡ · (ac1) f W , (cc1) f Y a#W , c#b ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc) W + 7! · X (ab)(bc).W , Y b a#W + ?7! ? 7! (ac1) f W , (c1 c2) f W Sol =(a#W , ) Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints:

? [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡ a#f((bc) W , (ac) Y )) · · +

Maribel Fern´andez Nominal Rewriting and Unification Theory To f constraints: ? [a]f(X , a) f [b]f((bc).W , (ac).Y )) ⇡↵ ? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? (ac1) f f((bc).W , (ac).Y )) ? ? (c1 c2) f W , (c1 c2) f Y

? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ? (ac1) f (bc).W , (ac1) f (ac).Y ? ? ? ? X ↵ (ab)(bc) W , b ↵ Y (c1 c2) f W , (c1 c2) f Y ⇡ · ⇡ a#W , c#Y ? + ? Y b X f (ab)(bc).W , a f (ab)(ac).Y ?+ 7! ↵ ↵ X ↵ (ab)(bc) W ⇡ ? ? ⇡ ⇡ · (ac1) f W , (cc1) f Y a#W , c#b ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc) W + 7! · X (ab)(bc).W , Y b a#W + ?7! ? 7! (ac1) f W , (c1 c2) f W Sol =(a#W , ) Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints:

? [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡ a#f((bc) W , (ac) Y )) · · +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ⇡ a#(bc) W , a#(ac) Y · · ⇤ +

Maribel Fern´andez Nominal Rewriting and Unification Theory To f constraints: ? [a]f(X , a) f [b]f((bc).W , (ac).Y )) ⇡↵ ? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? (ac1) f f((bc).W , (ac).Y )) ? ? (c1 c2) f W , (c1 c2) f Y

? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ? (ac1) f (bc).W , (ac1) f (ac).Y ? ? (c1 c2) f W , (c1 c2) f Y

? + ? f f X ↵ (ab)(bc).W , a ↵ (ab)(ac).Y ⇡ ? ? ⇡ (ac1) f W , (cc1) f Y ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc).W , Y b + ?7! ? 7! (ac1) f W , (c1 c2) f W Sol =(a#W , ) Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints:

? [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡ a#f((bc) W , (ac) Y )) · · +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ⇡ a#(bc) W , a#(ac) Y · · ⇤ ?+ ? X ↵ (ab)(bc) W , b ↵ Y ⇡ · ⇡ a#W , c#Y Y b ?+ 7! X ↵ (ab)(bc) W ⇡ · a#W , c#b X (ab)(bc) W + 7! · a#W

Maribel Fern´andez Nominal Rewriting and Unification Theory To f constraints: ? [a]f(X , a) f [b]f((bc).W , (ac).Y )) ⇡↵ ? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? (ac1) f f((bc).W , (ac).Y )) ? ? (c1 c2) f W , (c1 c2) f Y

? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ? (ac1) f (bc).W , (ac1) f (ac).Y ? ? (c1 c2) f W , (c1 c2) f Y

? + ? f f X ↵ (ab)(bc).W , a ↵ (ab)(ac).Y ⇡ ? ? ⇡ (ac1) f W , (cc1) f Y ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc).W , Y b + ?7! ? 7! (ac1) f W , (c1 c2) f W

Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints:

? [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡ a#f((bc) W , (ac) Y )) · · +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ⇡ a#(bc) W , a#(ac) Y · · ⇤ ?+ ? X ↵ (ab)(bc) W , b ↵ Y ⇡ · ⇡ a#W , c#Y Y b ?+ 7! X ↵ (ab)(bc) W ⇡ · a#W , c#b X (ab)(bc) W + 7! · a#W

Sol =(a#W , )

Maribel Fern´andez Nominal Rewriting and Unification Theory ? f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? (ac1) f f((bc).W , (ac).Y )) ? ? (c1 c2) f W , (c1 c2) f Y

? + f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ? (ac1) f (bc).W , (ac1) f (ac).Y ? ? (c1 c2) f W , (c1 c2) f Y

? + ? f f X ↵ (ab)(bc).W , a ↵ (ab)(ac).Y ⇡ ? ? ⇡ (ac1) f W , (cc1) f Y ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc).W , Y b + ?7! ? 7! (ac1) f W , (c1 c2) f W

Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints: To f constraints: ? f [a]f(X , a) ↵ [b]f((bc).W , (ac).Y )) ? ⇡ [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · + + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡ a#f((bc) W , (ac) Y )) · · +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ⇡ a#(bc) W , a#(ac) Y · · ⇤ ?+ ? X ↵ (ab)(bc) W , b ↵ Y ⇡ · ⇡ a#W , c#Y Y b ?+ 7! X ↵ (ab)(bc) W ⇡ · a#W , c#b X (ab)(bc) W + 7! · a#W

Sol =(a#W , )

Maribel Fern´andez Nominal Rewriting and Unification Theory ? f f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ? (ac1) f (bc).W , (ac1) f (ac).Y ? ? (c1 c2) f W , (c1 c2) f Y

? + ? f f X ↵ (ab)(bc).W , a ↵ (ab)(ac).Y ⇡ ? ? ⇡ (ac1) f W , (cc1) f Y ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc).W , Y b + ?7! ? 7! (ac1) f W , (c1 c2) f W

Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints: To f constraints: ? f [a]f(X , a) ↵ [b]f((bc).W , (ac).Y )) ? ⇡ [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · ? + f + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ⇡ (ac1) f f((bc).W , (ac).Y )) a#f((bc) W , (ac) Y )) ? ? · · (c1 c2) f W , (c1 c2) f Y +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) + ⇡ a#(bc) W , a#(ac) Y · · ⇤ ?+ ? X ↵ (ab)(bc) W , b ↵ Y ⇡ · ⇡ a#W , c#Y Y b ?+ 7! X ↵ (ab)(bc) W ⇡ · a#W , c#b X (ab)(bc) W + 7! · a#W

Sol =(a#W , )

Maribel Fern´andez Nominal Rewriting and Unification Theory ? ? f f X ↵ (ab)(bc).W , a ↵ (ab)(ac).Y ⇡ ? ? ⇡ (ac1) f W , (cc1) f Y ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc).W , Y b + ?7! ? 7! (ac1) f W , (c1 c2) f W

Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints: To f constraints: ? f [a]f(X , a) ↵ [b]f((bc).W , (ac).Y )) ? ⇡ [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · ? + f + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ⇡ (ac1) f f((bc).W , (ac).Y )) a#f((bc) W , (ac) Y )) ? ? · · (c1 c2) f W , (c1 c2) f Y +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ? + ⇡ f a#(bc) W , a#(ac) Y f(X , a) ↵ (ab).f((bc).W , (ac).Y )) · · ⇡? ? ⇤ (ac1) f (bc).W , (ac1) f (ac).Y ?+ ? ? ? X ↵ (ab)(bc) W , b ↵ Y (c1 c2) f W , (c1 c2) f Y ⇡ · ⇡ a#W , c#Y + Y b ?+ 7! X ↵ (ab)(bc) W ⇡ · a#W , c#b X (ab)(bc) W + 7! · a#W

Sol =(a#W , )

Maribel Fern´andez Nominal Rewriting and Unification Theory Sol =((ac1) f W , (c1 c2) f W , )

Correspondence: freshness/fixed-point constraints

From # constraints: To f constraints: ? f [a]f(X , a) ↵ [b]f((bc).W , (ac).Y )) ? ⇡ [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · ? + f + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ⇡ (ac1) f f((bc).W , (ac).Y )) a#f((bc) W , (ac) Y )) ? ? · · (c1 c2) f W , (c1 c2) f Y +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ? + ⇡ f a#(bc) W , a#(ac) Y f(X , a) ↵ (ab).f((bc).W , (ac).Y )) · · ⇡? ? ⇤ (ac1) f (bc).W , (ac1) f (ac).Y ?+ ? ? ? X ↵ (ab)(bc) W , b ↵ Y (c1 c2) f W , (c1 c2) f Y ⇡ · ⇡ a#W , c#Y ? + ? Y b X f (ab)(bc).W , a f (ab)(ac).Y ?+ 7! ↵ ↵ X ↵ (ab)(bc) W ⇡ ? ? ⇡ ⇡ · (ac1) f W , (cc1) f Y a#W , c#b ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc) W + 7! · X (ab)(bc).W , Y b a#W + ?7! ? 7! (ac1) f W , (c1 c2) f W Sol =(a#W , )

Maribel Fern´andez Nominal Rewriting and Unification Theory Correspondence: freshness/fixed-point constraints

From # constraints: To f constraints: ? f [a]f(X , a) ↵ [b]f((bc).W , (ac).Y )) ? ⇡ [a]f(X , a) ↵ [b]f((bc) W , (ac) Y )) ⇡ · · ? + f + ? f(X , a) ↵ (ab).f((bc).W , (ac).Y )) f(X , a) ↵ (ab).f((bc).W , (ac).Y )) ⇡? ⇡ (ac1) f f((bc).W , (ac).Y )) a#f((bc) W , (ac) Y )) ? ? · · (c1 c2) f W , (c1 c2) f Y +? f(X , a) ↵ f((ab)(bc).W , (ab)(ac).Y )) ? + ⇡ f a#(bc) W , a#(ac) Y f(X , a) ↵ (ab).f((bc).W , (ac).Y )) · · ⇡? ? ⇤ (ac1) f (bc).W , (ac1) f (ac).Y ?+ ? ? ? X ↵ (ab)(bc) W , b ↵ Y (c1 c2) f W , (c1 c2) f Y ⇡ · ⇡ a#W , c#Y ? + ? Y b X f (ab)(bc).W , a f (ab)(ac).Y ?+ 7! ↵ ↵ X ↵ (ab)(bc) W ⇡ ? ? ⇡ ⇡ · (ac1) f W , (cc1) f Y a#W , c#b ? ? (c1 c2) f W , (c1 c2) f Y X (ab)(bc) W + 7! · X (ab)(bc).W , Y b a#W + ?7! ? 7! (ac1) f W , (c1 c2) f W Sol =(a#W , ) Sol =((ac1) f W , (c1 c2) f W , )

Maribel Fern´andez Nominal Rewriting and Unification Theory ? ? f f f? f? (ab) X C Y , a C X (ab) X X , a Y { · ⇡ ⇡ } { · ⇡C ⇡C } [X a] [Y a] + 7!? f + 7!f? (ab) a C Y (ab) X X { · ⇡ } { · ⇡C } f?+ + ? b Y (ab) fC X { ⇡C } { } [Y b] + 7! + ( , X a, Y b ) ((ab) fC X , Y a ) ; { 7! 7! } { 7! }

C-fixed point constraints

+: commutative symbol C-fixed-point constraint: ⇡ fC t f C-↵-equality constraint: s C t ⇡ ? +((ab) X , a) f +(Y , X ) · ⇡C .&

Maribel Fern´andez Nominal Rewriting and Unification Theory ? ? (ab) X f X , a f Y { · ⇡C ⇡C } [Y a] + 7! ? (ab) X f X { · ⇡C } + (ab) ? X { fC } + ((ab) X , Y a ) fC { 7! }

C-fixed point constraints

+: commutative symbol C-fixed-point constraint: ⇡ fC t f C-↵-equality constraint: s C t ⇡ ? +((ab) X , a) f +(Y , X ) · ⇡C .& ? ? (ab) X f Y , a f X { · ⇡C ⇡C } [X a] + 7!? (ab) a f Y { · ⇡C } ?+ b f Y { ⇡C } [Y b] + 7! ( , X a, Y b ) ; { 7! 7! }

Maribel Fern´andez Nominal Rewriting and Unification Theory C-fixed point constraints

+: commutative symbol C-fixed-point constraint: ⇡ fC t f C-↵-equality constraint: s C t ⇡ ? +((ab) X , a) f +(Y , X ) · ⇡C .& ? ? f f f? f? (ab) X C Y , a C X (ab) X X , a Y { · ⇡ ⇡ } { · ⇡C ⇡C } [X a] [Y a] + 7!? f + 7!f? (ab) a C Y (ab) X X { · ⇡ } { · ⇡C } f?+ + ? b Y (ab) fC X { ⇡C } { } [Y b] + 7! + ( , X a, Y b ) ((ab) fC X , Y a ) ; { 7! 7! } { 7! }

Maribel Fern´andez Nominal Rewriting and Unification Theory Fixed Point Rules

1 ⇡0 ⇡(a)=a supp(⇡ ) supp(perm(⌥ X )) (fCa) ✓ | (fCvar) ⌥ ⇡ fC a ⌥ ⇡ ⇡0 X ` ` fC ·

⌥ ⇡ t ⌥ ⇡ t ... ⌥ ⇡ t fC ` fC 1 ` fC n ` f =+(fCf) (fCtuple) ⌥ ⇡ C ft 6 ⌥ ⇡ fC (t1,...,tn) ` f ` f f ⌥ ⇡ t0 C ti ⌥ ⇡ t1 C t(i+1) mod 2 ` · ⇡ ` · ⇡ i =0, 1(fC+) ⌥ ⇡ +(t , t ) ` fC 0 1 ⌥, (c1 c2) fC Var(t) ⇡ fC (ac1) t ` · (fCabs) ⌥ ⇡ [a]t ` fC

Maribel Fern´andez Nominal Rewriting and Unification Theory Alpha-Equality Rules

1 f ⌥ (⇡0) ⇡ fC X ( C a) f f ` ( C var) ⌥ a C a ⇡ f ⌥ ⇡ X ⇡0 X ⇡ ` ⇡ ` · ⇡C · f f f ⌥ t C t0 ⌥ t1 C t0 ... ⌥ tn C t0 f ` ⇡ 1 ` ⇡ n f ` ⇡ ( C f, f =+) ( C tuple) f f ⌥ ft ft0 ⇡ 6 ⌥ (t1,...,tn) C (t0 ,...,t0 ) ⇡ ` ⇡C ` ⇡ 1 n f f ⌥ s0 C ti s1 C t (i+1) mod 2 f ` ⇡ ⇡ i =0, 1( C +) ⌥ + s , s f + t , t ⇡ ` h 0 1i ⇡C h 0 1i f ⌥ t C t0 f ` ⇡ ( C [a]) f ⌥ [a]t [a]t0 ⇡ ` ⇡C f ⌥ s C (ab)t ⌥, (c1 c2) C Var(t) (ac1) C t f f f ` ⇡ ` ( C ab) ⌥ [a]s f [b]t ⇡ ` ⇡C

Maribel Fern´andez Nominal Rewriting and Unification Theory Simplification rules for nominal C-unification

? Pr ⇡ fC a = Pr, if ⇡(a)=a ]{ ? } ) ? Pr ⇡ fC ft = Pr ⇡ fC t , f =+ ]{ ? } ) [{ }? 6 ? Pr ⇡ fC +(t0, t1) = Pr ⇡ t0 t0,⇡ t1 t1 ]{ ? } ) [{ · ⇡? · ⇡? } Pr ⇡ fC +(t0, t1) = Pr ⇡ t0 t1,⇡ t1 t0 ]{ ? } ) [{ · ? ⇡ · ? ⇡ } Pr ⇡ fC (t)n = Pr ⇡ fC t1,...,⇡fC tn ]{ ? } ) [{ ? } ? Pr ⇡ fC [a]t = Pr ⇡ fC (ac1) t, (c1 c2) fC Var(t) ]{ ? } ) [{ (⇡ ) 1 ? · } Pr ⇡ ⇡e0 X = Pr ⇡ 0 X , if ⇡0 = Id ]{ fC · } ) [{ fC } 6 f? f? Pr ft C ft0 = Pr t C t0 , f =+ ]{ ⇡ } ) [{ ⇡ } 6 f? f? f? Pr +(t0, t1) C +(s0, s1) = Pr t0 C s0, t1 C s1 ]{ ⇡ } ) [{ ⇡ ⇡ } f? f? f? Pr +(t0, t1) C +(s0, s1) = Pr t0 C s1, t1 C s0 ]{ ⇡ } ) [{ ⇡ ⇡ } f? f? f? Pr (t)n C (t )n = Pr t1 C t0 ,...,tn C t0 ]{ ⇡ 0 } ) [{ ⇡ 1 ⇡ n} f? f? Pr [a]t C [a]t0 = Pr t C t0 ]{ ⇡ } ) [{ ⇡ } e f? e f? ? Pr [a]t C [b]s = Pr t C (ab) s, (ac1) fC s, ]{ ⇡ } ) [{ ⇡ · ? (c1 c2) Var(s) fC } f? 1 ? Pr ⇡ X C ⇡0 X = Pr (⇡0) ⇡ fC X ]{ · ⇡ · } )1 [{ } f? [X pi .t] 1 Pr ⇡ X C t 7!= Pr X ⇡ .t , if X / Var(t) ]{ · ⇡ } ) { 7! } 2

Maribel Fern´andez Nominal Rewriting and Unification Theory Properties

Termination: There is no infinite chain of reductions = • )C starting from a C-unification problem Pr. Soundess and Completeness • Nominal C Unification is finitary if solutions are represented as • pairs of fixed-point context and substitution

Maribel Fern´andez Nominal Rewriting and Unification Theory Exercise

Show that all the simplification rules, except the instantiation rules, preserve solutions.

Maribel Fern´andez Nominal Rewriting and Unification Theory Generalisation

Associativity (A), AC Theories

Checking ↵-equality modulo A, C, AC: Formalisation in Coq [de Carvalho et al]

C-Unification implemented in OCaml

Maribel Fern´andez Nominal Rewriting and Unification Theory Conclusion

Nominal Terms: first-order syntax with binders. • Nominal unification is quadratic (unknown lower bound) • [Levy&Villaret, Calv`es & F.] Nominal unification is used in the language ↵-Prolog [Cheney • &Urban] Nominal matching is linear, equivariant matching is linear with • closed rules. Applications in functional and logic programming languages, • theorem provers, model checkers (eg. FreshML, AlphaProlog, AlphaCheck, Nominal package in Isabelle-HOL, etc.). Extensions: AC-Nominal Unification, E-Nominal Unification, • Nominal Narrowing [Ayala-Rinc´onet al] Implementations/Formalisations: in OCaML, Haskell, Coq, • Isabelle-HOL, PVS

Maribel Fern´andez Nominal Rewriting and Unification Theory Conclusion

NRSs are first-order systems with built-in ↵-equivalence: • first-order substitutions, matching modulo ↵. Closed NRSs have the expressive power of higher-order • rewriting. Capture-avoiding atom substitutions are easy to define using freshness. They can also be included as primitive BUT unification becomes undecidable [Dominguez&F.] Closed NRSs have the properties of first-order rewriting • (critical pair lemma, orthogonality, completion). Intersection types can be added to give semantics to terms • and to obtain sucient conditions for termination. Hindley-Milner style types [Fairweather&F.]: Typing is • decidable and there are principal types, ↵-equivalence preserves types. Sucient conditions for Subject Reduction (rewriting preserves types).

Maribel Fern´andez Nominal Rewriting and Unification Theory