Nominal Rewriting and Unification Theory Maribel Fern andez FoPSS - - PowerPoint PPT Presentation

nominal rewriting and unification theory
SMART_READER_LITE
LIVE PREVIEW

Nominal Rewriting and Unification Theory Maribel Fern andez FoPSS - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Nominal Rewriting and Unification Theory

Maribel Fern´ andez FoPSS 2019

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-2
SLIDE 2

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

slide-3
SLIDE 3

Further reading

  • C. Urban, A. Pitts, M.J. Gabbay. Nominal Unification.

Theoretical Computer Science 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´
  • n, 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

Substitution: Matching, Unification, Rewriting. Proceedings

  • f FCT 2019, Lecture Notes in Computer Science, Springer.
  • E. Fairweather, M. Fern´
  • andez. Typed Nominal Rewriting.

ACM Transactions on Computational Logic, 2018.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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 62 fv(M))

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-7
SLIDE 7

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 62 fv(M))

  • ⇡-calculus:

P | ⌫a.Q ! ⌫a.(P | Q) (a 62 fv(P))

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-8
SLIDE 8

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 62 fv(M))

  • ⇡-calculus:

P | ⌫a.Q ! ⌫a.(P | Q) (a 62 fv(P))

  • Logic equivalences:

P and (8x.Q) , 8x(P and Q) (x 62 fv(P))

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-9
SLIDE 9

Binding operators - α-equivalence

Terms are defined modulo renaming of bound variables, i.e., ↵-equivalence. Example: In 8x.P the variable x can be renamed (avoiding name capture) 8x.P =↵ 8y.P{x 7! y} How can we formally define (or program) binding operators? There are several alternatives.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-10
SLIDE 10

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

slide-11
SLIDE 11

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language.

  • Simple notion of substitution (first-order) (+)

) Efficient matching and unification algorithms (+)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-12
SLIDE 12

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language.

  • Simple notion of substitution (first-order) (+)
  • Efficient matching and unification algorithms (+)

) No binders (-)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-13
SLIDE 13

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language.

  • Simple notion of substitution (first-order) (+)
  • Efficient 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

slide-14
SLIDE 14

First-order frameworks

We can encode ↵-equivalence in a first-order specification or programming language.

  • Simple notion of substitution (first-order) (+)
  • Efficient 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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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

slide-17
SLIDE 17

Higher-order frameworks

) The syntax includes binders (+)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-18
SLIDE 18

Higher-order frameworks

  • The syntax includes binders (+)

) Implicit ↵-equivalence (+)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-19
SLIDE 19

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

slide-20
SLIDE 20

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

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

slide-23
SLIDE 23

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

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-24
SLIDE 24

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

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-25
SLIDE 25

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)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-26
SLIDE 26

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)

) Efficient matching and unification algorithms

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-27
SLIDE 27

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)
  • Efficient matching and unification algorithms

) Dependencies of terms on names are implicit

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-28
SLIDE 28

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)
  • Efficient 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

slide-29
SLIDE 29

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

  • f swappings, denoted ⇡ (Id empty).

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-30
SLIDE 30

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

  • f swappings, denoted ⇡ (Id empty).
  • Nominal Terms:

s, t ::= a | ⇡ · X | [a]t | f t | (t1, . . . , tn) Id · X written as X.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-31
SLIDE 31

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

  • f swappings, denoted ⇡ (Id empty).
  • Nominal Terms:

s, t ::= a | ⇡ · X | [a]t | f t | (t1, . . . , tn) Id · X written as X.

  • Example (ML): var(a), app(t, t0), lam([a]t), let(t, [a]t0),

letrec[f ]([a]t, t0), subst([a]t, t0) Syntactic sugar: a, (tt0), a.t, let a = t in t0, letrec fa = t in t0, t[a 7! t0]

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-32
SLIDE 32

α-equivalence

We use freshness to avoid name capture: a#X means a 62 fv(X) when X is instantiated. a ⇡↵ a ds(⇡, ⇡0)#X ⇡ · X ⇡↵ ⇡0 · X s1 ⇡↵ t1 · · · sn ⇡↵ tn (s1, . . . , sn) ⇡↵ (t1, . . . , tn) s ⇡↵ t fs ⇡↵ ft s ⇡↵ t [a]s ⇡↵ [a]t a#t s ⇡↵ (a b) · 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

slide-33
SLIDE 33

α-equivalence

We use freshness to avoid name capture: a#X means a 62 fv(X) when X is instantiated. a ⇡↵ a ds(⇡, ⇡0)#X ⇡ · X ⇡↵ ⇡0 · X s1 ⇡↵ t1 · · · sn ⇡↵ tn (s1, . . . , sn) ⇡↵ (t1, . . . , tn) s ⇡↵ t fs ⇡↵ ft s ⇡↵ t [a]s ⇡↵ [a]t a#t s ⇡↵ (a b) · 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

slide-34
SLIDE 34

Freshness

Also defined by induction: a#b a#[a]s ⇡1(a)#X a#⇡ · X a#s1 · · · a#sn a#(s1, . . . , sn) a#s a#fs a#s a#[b]s

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-35
SLIDE 35

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

slide-36
SLIDE 36

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

slide-37
SLIDE 37

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) a#P ` P ^ 9[a]Q ! 9[a](P ^ Q) a#P ` (9[a]Q) ^ P ! 9[a](Q ^ P) a#P ` P _ 9[a]Q ! 9[a](P _ Q) 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

slide-38
SLIDE 38

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[s0] such that ✓ solves (r ` l) ?⇡ (∆ ` s0) 2 ∆ ` C[r✓] ⇡↵ t.

Example Beta-reduction in the Lambda-calculus: Beta ([a]X)Y ! X[a7!Y ] a a[a7!Y ] ! Y app (XX 0)[a7!Y ] ! X[a7!Y ]X 0[a7!Y ] ✏ a#Y ` Y [a7!X] ! Y

  • b#Y `

([b]X)[a7!Y ] ! [b](X[a7!Y ]) Rewriting steps: ([c]c)Z ! c[c7!Z] ! Z

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-39
SLIDE 39

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 efficient 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. Efficient algorithms to check ↵-equivalence, matching, unification. = ) Nominal programming languages (Alpha-Prolog, FreshML) = ) Nominal Rewriting.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-40
SLIDE 40

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

slide-41
SLIDE 41

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
  • f a symbol is the number of arguments associated with it).

A term is either a variable, or has the form f (t1, . . . , tn) where f is a function symbol of arity n and t1, . . . , tn 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

slide-42
SLIDE 42

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: {X1 7! t1, . . . , Xn 7! tn}. dom() = {X1, . . . , Xn}. 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

slide-43
SLIDE 43

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 sufficient 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

slide-44
SLIDE 44

Unification

A unification problem U is a set of equations between terms with variables {s1 = t1, . . . , sn = tn} A solution to U, also called a unifier, is a substitution such that for each equation si = ti 2 U, the terms si and ti 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

slide-45
SLIDE 45

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

  • f equations and produce new sets of equations or a failure.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-46
SLIDE 46

Unification Algorithm

Input: A finite set of equations: {s1 = t1, . . . , sn = tn} Output: A substitution (mgu for these terms), or failure. Transformation Rules: Rules are applied non-deterministically, until no rule can be applied

  • r a failure arises.

(1) f (s1, . . . , sn) = f (t1, . . . , tn), E ! s1 = t1, . . . , sn = tn, E (2) f (s1, . . . , sn) = g(t1, . . . , tm), 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

slide-47
SLIDE 47

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

slide-48
SLIDE 48

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

slide-49
SLIDE 49

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#(s1, . . . , sn), Pr = ) a#s1, . . . , a#sn, Pr a#[b]s, Pr = ) a#s, Pr a#[a]s, Pr = ) Pr a#⇡ · X, Pr = ) ⇡-1 · a#X, Pr ⇡ 6⌘ Id a ⇡↵ a, Pr = ) Pr (l1, . . . , ln) ⇡↵ (s1, . . . , sn), Pr = ) l1 ⇡↵ s1, . . . , ln ⇡↵ sn, 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

slide-50
SLIDE 50

Checking α-equivalence of terms

The relation = ) is confluent and strongly normalising: the simplification process terminates, the result is unique: hPrinf hPrinf 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 Γ ` hPrinf .
  • Let hPrinf = ∆ [ Contr [ Eq. Then ∆ ` Pr if and only if

Contr and Eq are empty.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-51
SLIDE 51

Solving Equations [Urban, Pitts, Gabbay 2003]

  • Nominal Unification: l

?⇡? t has solution (∆, ✓) if

∆ ` l✓ ⇡↵ t✓

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-52
SLIDE 52

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

slide-53
SLIDE 53

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

slide-54
SLIDE 54

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

slide-55
SLIDE 55

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[s0] such that ✓ solves (r ` l) ?⇡ (∆ ` s0) 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

slide-56
SLIDE 56

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[s0] such that ✓ solves (r ` l) ?⇡ (∆ ` s0) 2 ∆ ` C[r✓] ⇡↵ t.

  • To define the reduction relation generated by nominal

rewriting rules we use nominal matching.

  • (r ` l) ?⇡ (∆ ` s0) if

r, l ⇡↵ s0 has solution (∆0, ✓), that is, ∆0 ` r✓, l✓ ⇡↵ s0 and ∆ ` ∆0

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-57
SLIDE 57

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:

⇡ · X ⇡↵ u, Pr = )X7!⇡-1·u Pr[X7!⇡-1 · u] No occur-checks needed (left-hand side variables distinct from right-hand side variables).

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-58
SLIDE 58

Back to Nominal Rewriting

Equivariance: Rules defined modulo permutative renamings of atoms. Beta-reduction in the Lambda-calculus: Beta ([a]X)Y ! X[a7!Y ] a a[a7!Y ] ! Y app (XX 0)[a7!Y ] ! X[a7!Y ]X 0[a7!Y ] ✏ a#Y ` Y [a7!X] ! Y

  • b#Y `

([b]X)[a7!Y ] ! [b](X[a7!Y ])

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-59
SLIDE 59

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

slide-60
SLIDE 60

Next questions

  • Efficient nominal matching algorithm?
  • Is nominal matching sufficient (complete) for nominal

rewriting?

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-61
SLIDE 61

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

slide-62
SLIDE 62

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

slide-63
SLIDE 63

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 efficient algorithm, work with a single current

permutation, represented by an environment.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-64
SLIDE 64

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 s1 ⇡↵ ⇠1⌃t1, . . . , sn ⇡↵ ⇠n⌃tn. It is easy to translate a standard problem into an environment problem and vice-versa.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-65
SLIDE 65

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. Pr

c denotes the result of applying the core algorithm on Pr.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-66
SLIDE 66

Core module

Phase 1 - Input: Pr = (si ⇡↵ ⇠i⌃ti)n

i

Pr, a ⇡↵ ⇠⌃t = ) ( Pr if a = ⇠⇡ · t and t 62 ⇠A ?

  • therwise

Pr, (s1, . . . , sn)⇡↵ ⇠⌃t = ) ( Pr, (si ⇡↵ ⇠⌃ui)n

1

if t = (u1, . . . , un) ?

  • therwise

Pr, f s ⇡↵ ⇠⌃t = ) ( Pr, s ⇡↵ ⇠⌃u if t = f u ?

  • therwise

Pr, [a]s ⇡↵ ⇠⌃t = ) ( Pr, s ⇡↵ ⇠0⌃u if t = [b]u ?

  • therwise

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 · Xi ⇡↵ ⇠i⌃si)n

1 where si are nominal terms.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-67
SLIDE 67

Core module

Phase 2 - Input: A Phase 1 normal form. ⇡ · X ⇡↵ ⇠⌃t = ) X ⇡↵ (⇡1 · ⇠)⌃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 (Xi ⇡↵ ⇠i⌃ti)n

1, where the

terms ti are standard nominal terms.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-68
SLIDE 68

Core module

Phase 3 - Input: A Phase 2 normal form (Xi ⇡↵ ⇠i⌃ti)n

1.

⇠⌃a = ) ( ⇠⇡ · a a 62 ⇠A ? a 2 ⇠A ⇠⌃f t = ) f (⇠⌃t) ⇠⌃(t1, . . . , tj) = ) (⇠⌃ti)j

1

⇠⌃ [a]s = ) [⇠⇡ · a]((⇠ \ {a})⌃s) ⇠⌃(⇡ · X) = ) (⇠ ⇡)⌃X Pr[?] = ) ? where ⇠ \ {a} = (⇠⇡, ⇠A \ {a}) and ⇠ ⇡ = ((⇠⇡ ⇡), ⇡1(⇠A)). The normal forms are either ? or (Xi ⇡↵ ti)n

1 where ti 2 T⇠.

T⇠ = a | f T⇠ | (T⇠, . . . , T⇠) | [a]T⇠ | ⇠⌃X

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-69
SLIDE 69

Core module

Phase 4: X ⇡↵ C[⇠⌃X 0] = ) X ⇡↵ C[⇠⇡ · X 0] , ⇠A # X 0 Normal forms are either ? or (Xi ⇡↵ ui)i2I, (Aj # Xj)j2J where ui 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

slide-70
SLIDE 70

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

slide-71
SLIDE 71

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
  • therwise reduce the result Pr

c using:

(↵) Pr , X ⇡↵ t = ) ( Pr , supp(⇡) # X if t = ⇡ · X ?

  • therwise

where supp(⇡) = {a | ⇡ · a 6= a}

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-72
SLIDE 72

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
  • therwise reduce the result Pr

c using:

(↵) Pr , X ⇡↵ t = ) ( Pr , supp(⇡) # X if t = ⇡ · X ?

  • therwise

where supp(⇡) = {a | ⇡ · a 6= a}

  • Normal forms: ? or (Ai # Xi)n

1.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-73
SLIDE 73

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
  • therwise reduce the result Pr

c using:

(↵) Pr , X ⇡↵ t = ) ( Pr , supp(⇡) # X if t = ⇡ · X ?

  • therwise

where supp(⇡) = {a | ⇡ · a 6= a}

  • Normal forms: ? or (Ai # Xi)n

1.

  • Correctness: If the normal form is ? then Pr is not valid.

If the normal form of Pr is (Ai # Xi)n

1 then (Ai # Xi)n 1 ` Pr.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-74
SLIDE 74

Solving Matching Problems

To solve a matching problem Pr:

  • Run the core algorithm on Pr

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-75
SLIDE 75

Solving Matching Problems

To solve a matching problem Pr:

  • Run the core algorithm on Pr
  • If the problem is non-linear, normalise the result Pr

c by:

Pr, X ⇡↵ s, X ⇡↵ t = ) ( Pr, X ⇡↵ s, s ⇡↵ t ⇡↵ if s ⇡↵ t ⇡↵ 6= ? ?

  • therwise

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-76
SLIDE 76

Solving Matching Problems

To solve a matching problem Pr:

  • Run the core algorithm on Pr
  • If the problem is non-linear, normalise the result Pr

c by:

Pr, X ⇡↵ s, X ⇡↵ t = ) ( Pr, X ⇡↵ s, s ⇡↵ t ⇡↵ if s ⇡↵ t ⇡↵ 6= ? ?

  • therwise
  • Normal forms: ? or a pair of a substitution and a freshness

context.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-77
SLIDE 77

Solving Matching Problems

To solve a matching problem Pr:

  • Run the core algorithm on Pr
  • If the problem is non-linear, normalise the result Pr

c by:

Pr, X ⇡↵ s, X ⇡↵ t = ) ( Pr, X ⇡↵ s, s ⇡↵ t ⇡↵ if s ⇡↵ t ⇡↵ 6= ? ?

  • therwise
  • 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

slide-78
SLIDE 78

Solving Matching Problems

To solve a matching problem Pr:

  • Run the core algorithm on Pr
  • If the problem is non-linear, normalise the result Pr

c by:

Pr, X ⇡↵ s, X ⇡↵ t = ) ( Pr, X ⇡↵ s, s ⇡↵ t ⇡↵ if s ⇡↵ t ⇡↵ 6= ? ?

  • therwise
  • 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 sufficient.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-79
SLIDE 79

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

slide-80
SLIDE 80

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

slide-81
SLIDE 81

Benchmarks

OCAML implementation: 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 10000 20000 30000 40000 50000 60000 70000 80000 90000100000 Time Size alpha ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ ⌃ match + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ++ + + + + ++ + + + ++ + ++ + + ++ + + + + + + + + ++ + + + + ++ + + + + + + + + + ++ + + + + + + + + + ++ + + + ++ + + + + + + + + + + + + + + + + + + + + + + ++ ++ + + + + + + ++ + + + + + + + + + + ++ + + + + + + + + + + + + + + ++ + + ++ + + + + + + + + + + ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-82
SLIDE 82

Nominal Matching vs. Equivariant Matching

  • Nominal matching is efficient.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-83
SLIDE 83

Nominal Matching vs. Equivariant Matching

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

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-84
SLIDE 84

Nominal Matching vs. Equivariant Matching

  • Nominal matching is efficient.
  • Equivariant nominal matching is exponential... BUT
  • if rules are CLOSED then nominal matching is sufficient.

Intuitively, closed means no free atoms. The rules in the examples above are closed.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-85
SLIDE 85

Closed Rules

R ⌘ r ` l ! r is closed when (r0 ` (l0, r0)) ?⇡ (r, A(R0)#V (R) ` (l, r)) has a solution (where R0 is freshened with respect to R). Given R ⌘ r ` l ! r and ∆ ` s a term-in-context we write ∆ ` s

R

!c t when ∆, A(R0)#V (∆, s) ` s R0 ! t and call this closed rewriting.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-86
SLIDE 86

Examples

The following rules are not closed: g(a) ! a [a]X ! X Why?

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-87
SLIDE 87

Examples

The following rule is closed: a#X ` [a]X ! X Why?

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-88
SLIDE 88

Exercise

Provide a nominal rewriting system defining an explicit substitution

  • perator 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

slide-89
SLIDE 89

Examples

Closed rules that define capture-avoiding substitution in the lambda calculus: (explicit) substitutions, subst([x]M, N) abbreviated M[x7!N]. (Beta) ([a]X)X 0 ! X[a7!X 0] (app) (XX 0)[a7!Y ] ! X[a7!Y ]X 0[a7!Y ] (a) a[a7!X] ! X (✏) a#Y ` Y [a7!X] ! Y () b#Y ` ([b]X)[a7!Y ] ! [b](X[a7!Y ])

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-90
SLIDE 90

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

slide-91
SLIDE 91

Properties of Closed Rewriting

Closed Nominal Rewriting:

  • works uniformly in ↵ equivalence classes of terms.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-92
SLIDE 92

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

slide-93
SLIDE 93

Properties of Closed Rewriting

Closed Nominal Rewriting:

  • works uniformly in ↵ equivalence classes of terms.
  • is expressive: can encode Combinatory Reduction Systems.
  • is efficient: linear matching.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-94
SLIDE 94

Properties of Closed Rewriting

Closed Nominal Rewriting:

  • works uniformly in ↵ equivalence classes of terms.
  • is expressive: can encode Combinatory Reduction Systems.
  • is efficient: linear matching.
  • inherits confluence conditions from first order rewriting.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-95
SLIDE 95

Confluence — Critical Pairs

Suppose

1 Ri = ri ` li ! ri for i = 1, 2 are copies of two rules in R

such that V (R1) \ V (R2) = ; (R1 and R2 could be copies of the same rule).

2 l1 ⌘ L[l0

1] such that r1, r2, l0 1 ?⇡? l2 has a principal solution

(Γ, ✓), so that Γ ` l0

1✓ ⇡↵ l2✓ and Γ ` ri✓ for i = 1, 2.

Then Γ ` (r1✓, L✓[r2✓]) is a critical pair. If L = [-] and R1, R2 are copies of the same rule, or if l0

1 is a

variable, then we say the critical pair is trivial. We distinguish: If R2 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

slide-96
SLIDE 96

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

  • verlaps. 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)

hR,✏,Id,[X7!a]i

{

hR,✏,(a b),[X7!a]i

#

f ([a]a) 6⇡↵ f ([b]a)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-97
SLIDE 97

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 insufficient 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

slide-98
SLIDE 98

Confluence — Critical Pairs

↵-stability is difficult 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

slide-99
SLIDE 99

Confluence — Critical Pairs and Closed Rewriting

More efficient: checking fresh overlaps and fresh critical pairs is sufficient for closed rewriting. Let Ri = ri ` li ! ri (i = 1, 2) be freshened versions of rules. If the nominal unification problem r1 [ r2 [ {l2 ?⇡? l1|p} has a most general solution hΓ, ✓i for some position p, then R1 fresh

  • verlaps with R2, and the pair of terms-in-context

Γ ` (r1✓, l1✓[p r2✓]) is a fresh critical pair. 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

slide-100
SLIDE 100

Confluence — Critical Pairs and Closed Rewriting

The fresh critical pair Γ ` (r1✓, l1✓[p r2✓]) is joinable if there is a term u such that Γ `R r1✓ !c u and Γ `R (l1✓[p r2✓]) !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

slide-101
SLIDE 101

Confluence — Critical Pairs

Since it is sufficient 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 effective criterion for local confluence, similar to 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,

  • btained from ? ` (([a]X)Y )[b 7! Z]:

? ` ((([a]X)[b 7! Z])(Y [b 7! Z]), (X[a 7! Y ])[b 7! Z]).

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-102
SLIDE 102

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

slide-103
SLIDE 103

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: ¬, 8 and 9 of arity 1, and ^, _ of arity 2 (infix). Closed rules to simplify formulas: ` ¬(X^Y ) ! ¬(X)_¬(Y ) and b#X ` ¬(8[a]X) ! 9[b]¬((b a)·X).

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-104
SLIDE 104

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

slide-105
SLIDE 105

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

slide-106
SLIDE 106

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: , ⌧ ::= | ↵ | (⌧1 ⇥ . . . ⇥ ⌧n) | C ⌧ | []⌧ Type declarations: ⇢ ::= 8(↵).h , ! ⌧i Example succ : hNat , ! Nati length: 8(↵).hList ↵ , ! Nati ⌘ 8().hList , ! Nati Instantiation: E.g. 8(↵).h↵ , ! ↵i < hNat , ! Nati

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-107
SLIDE 107

Typing Rules

Quasi-typing judgements: Γ Σ ∆ ` s : ⌧, defined inductively, where Γ is a typing context, Σ a signature (set of declarations for term-formers), ∆ a freshness context, s a term and ⌧ a type. ∆ needed later. Γa ⌘ ⌧ (atm)⌧ Γ Σ ∆ ` a: ⌧ ΓX ⌘ ⌧ (var)⌧ Γ Σ ∆ ` ⇡ · X : ⌧ Σf < h , ! ⌧i Γ Σ ∆ ` t : Γ Σ ∆ ` f t : ⌧ Γ o n (a: ⌧) Σ ∆ ` t : ⌧ 0 Γ Σ ∆ ` [a] t : [⌧] ⌧ 0 Γ Σ ∆ ` t1 : ⌧1 . . . Γ Σ ∆ ` tn : ⌧n (tpl)⌧ Γ Σ ∆ ` (t1, . . . , tn): (⌧1 ⇥ . . . ⇥ ⌧n)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-108
SLIDE 108

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 ∆X is the same for any ⇡ · X in t. The latter is called linearity property. Notation for typing judgements: Γ Σ ∆ ` s : ⌧

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-109
SLIDE 109

Examples

a: ↵, X : ∅ ? ` (a, X): (↵ ⇥ ) ? ∅ ? ` [a] a: [↵] ↵ a: ∅ ? ` [a] a: [↵] ↵ a: ⌧1, b: ⌧2, X : ⌧ ∅ ? ` (a b) · X : ⌧ a: ⌧1, b: ⌧1, X : ⌧ ∅ ? ` ((a b) · X, Id · X): (⌧ ⇥ ⌧) X : ⌧ ∅ a # X ` ([a] Id · X, Id · X): (⌧ ⇥ ⌧) a: ↵, b: , X : ⌧ ∅ ? ` [a] ((a b) · X, Id · X): [] (⌧ ⇥ ⌧) Exercise: Show that each of these typing judgements is valid.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-110
SLIDE 110

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

slide-111
SLIDE 111

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,

  • r 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

slide-112
SLIDE 112

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 Φ Σ r ` t : ⌧, then Γ Σ ∆ ` t ✓: ⌧.

  • ↵-equivalence preserves types:

∆ ` s ⇡↵ t and Γ Σ ∆ ` s : ⌧ imply Γ Σ ∆ ` t : ⌧.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-113
SLIDE 113

Subject Reduction

Typeable rewrite rule Φ Σ r ` l ! r : ⌧

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

Remark: reductions do not generate new atoms (uniform rules); l and r are both typeable with the principal type of l, so the 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

slide-114
SLIDE 114

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

slide-115
SLIDE 115

Why Typed Matching?

Assume Σf = 8(↵).h↵ , ! Nati and Σtrue = h() , ! Booli and a rule X : Nat Σ ? ` f X ! X : Nat The untyped pattern-matching problem ? ` f X ?⇡↵ ? ` f true has a solution X 7! true. The typed pattern matching problem (X : Nat Σ ? ` f X) ?⇡↵ (? Σ ? ` f true) has none: the substitution X 7! true is not well-typed, because X is required to have the type Nat, but it is instantiated with a term of type Bool.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-116
SLIDE 116

More efficient: Typed Closed Nominal Rewriting

Typeable-closed rewrite rule Φ Σ r ` l ! r : ⌧

1 r ` l ! r is closed. 2 pt(Φ Σ r ` l) = (Id, ⌧) and Φ Σ r ` (l, r): (⌧ ⇥ ⌧). 3 Every variable in l has an occurrence within a function

application f t, and for every subderivation Γ0 Σ ∆ ` f t : ⌧ 0 in l where t is not ground, if Σf = 8(↵).h , ! ⌧i, then the 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

slide-117
SLIDE 117

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

slide-118
SLIDE 118

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

slide-119
SLIDE 119

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

slide-120
SLIDE 120

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

slide-121
SLIDE 121

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 r ` s ⇡↵,E t?

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-122
SLIDE 122

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 r ` s ⇡↵,E t? Nominal E-Unification: ↵ and E. Modular extension of first-order equational unification procedures?

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-123
SLIDE 123

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 r ` s ⇡↵,E t? 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

slide-124
SLIDE 124

Interference: Commutative Symbols OR, +

8[a]OR(p(a), p((c d) · X)) ⇡α

? 8[b]OR(p((a b) · X), p(b))

+

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-125
SLIDE 125

Interference: Commutative Symbols OR, +

8[a]OR(p(a), p((c d) · X)) ⇡α

? 8[b]OR(p((a b) · X), p(b))

+ OR(p(a), p((c d) · X))) ⇡α

? (a b) · OR(p((a b) · X), p(b)),

a#?OR(p((a b) · X), p(b)) +⇤

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-126
SLIDE 126

Interference: Commutative Symbols OR, +

8[a]OR(p(a), p((c d) · X)) ⇡α

? 8[b]OR(p((a b) · X), p(b))

+ OR(p(a), p((c d) · X))) ⇡α

? (a b) · OR(p((a b) · X), p(b)),

a#?OR(p((a b) · X), p(b)) +⇤ OR(p(a), p((c d) · X))) ⇡α

? OR(p(X), p(a)), b#?X

+ p(a) ⇡α

? p(X), p((c d) · X) ⇡α ? p(a), b#X

+ a ⇡α

? X, (c d) · X ⇡α ? a, b#X

+ [X 7! a] (c d) · a ⇡α

? a, b#a

+ ?

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-127
SLIDE 127

OR is a commutative symbol: OR(p(a), p((c d) · X))) ⇡↵? OR(p(X), p(a)), b#?X

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-128
SLIDE 128

OR is a commutative symbol: OR(p(a), p((c d) · X))) ⇡?

↵,C OR(p(X), p(a)), b#?X

+ p(a) ⇡↵? p(a), p((c d) · X) ⇡?

↵,C p(X), b#?X

+ p((c d) · X) ⇡?

↵,C p(X), b#?X

+ (c d) · X ⇡?

↵,C X, b#?X

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-129
SLIDE 129

(c d) · X ⇡?

↵,C X has infinite principal solutions!

  • X 7! c + d, X 7! f (c + d), X 7! [e]c + [e]d, . . .

Nominal C-Unification Procedure [Ayala-Rinc´

  • n et al.]:

1 Simplification phase:

Build a derivation tree (branching for C symbols)

2 Solve fixed point constraints X ⇡↵,C ⇡ · X Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-130
SLIDE 130

(c d) · X ⇡?

↵,C X has infinite principal solutions!

  • X 7! c + d, X 7! f (c + d), X 7! [e]c + [e]d, . . .

Nominal C-Unification Procedure [Ayala-Rinc´

  • n et al.]:

1 Simplification phase:

Build a derivation tree (branching for C symbols)

2 Solve fixed point constraints X ⇡↵,C ⇡ · X

First-order C-unification is finitary.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-131
SLIDE 131

(c d) · X ⇡?

↵,C X has infinite principal solutions!

  • X 7! c + d, X 7! f (c + d), X 7! [e]c + [e]d, . . .

Nominal C-Unification Procedure [Ayala-Rinc´

  • n et al.]:

1 Simplification phase:

Build a derivation tree (branching for C symbols)

2 Solve fixed point constraints X ⇡↵,C ⇡ · X

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

slide-132
SLIDE 132

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 2 S if for all ⇡ 2 Perm(A) ((8a 2 A) ⇡(a) = a) ) ⇡ · x = x (1) 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 2 A then supp(a) = {a} supp(app(a, g(c, d))) = {a, c, d}

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-133
SLIDE 133

Freshness vs. Fixed-Point Constraints

Definition of Freshness [Pitts2013]: a#X , N a0.(a a0) · X = X Freshness derived from N and a notion of permutation fixed-point.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-134
SLIDE 134

Freshness vs. Fixed-Point Constraints

Definition of Freshness [Pitts2013]: a#X , N a0.(a a0) · X = X Freshness derived from N and a notion of permutation fixed-point. Let S be a nominal set. The fixed-point relation f ✓ Perm(A)⇥S is defined as: ⇡ f x , ⇡ · x = x Read “⇡ f x” as “⇡ fixes x”.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-135
SLIDE 135

α-equivalence via fixed point constraints

Notation:

  • ↵-equivalence constraint: s

f

⇡↵ t

  • Fixed-point constraint: ⇡ f t

Intuitively, ⇡ fixes t if ⇡ · t

f

⇡↵ t, ⇡ has “no effect” on t except for possible renaming of bound names, for instance, (a b) f [a]a but not (a b) f f a.

  • Primitive fixed-point constraint: ⇡ f X
  • Fixed-point context: Υ = {⇡1 f X1, . . . , ⇡k f Xk}
  • Support of a permutation: supp(⇡) = {a | ⇡(a) 6= a}

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-136
SLIDE 136

Fixed-Point Rules

Notation: perm(Υ|X) permutations that fix X according to Υ ⇡(a) = a (fa) Υ ` ⇡ f a supp(⇡⇡01) ✓ supp(perm(Υ|X)) (fvar) Υ ` ⇡ f ⇡0 · X Υ ` ⇡ f t (ff) Υ ` ⇡ f f t Υ ` ⇡ f t1 . . . Υ ` ⇡ f tn (ftuple) Υ ` ⇡ f (t1, . . . , tn) Υ, (c1 c2) f Var(t) ` ⇡ f (a c1) · t (fabs), c1 and c2 new names Υ ` ⇡ f [a]t

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-137
SLIDE 137

Alpha-Equivalence Rules

(

f

⇡α a) Υ ` a

f

⇡α a supp((⇡0)1 ⇡) ✓ supp(perm(Υ|X)) (

f

⇡α var) Υ ` ⇡ · X

f

⇡α ⇡0 · X Υ ` t

f

⇡α t0 (

f

⇡α f) Υ ` f t

f

⇡α f t0 Υ ` t1

f

⇡α t0

1

. . . Υ ` tn

f

⇡α t0

n ( f

⇡α tuple) Υ ` (t1, . . . , tn)

f

⇡α (t0

1, . . . , t0 n)

Υ ` t

f

⇡α t0 (

f

⇡α [a]) Υ ` [a]t

f

⇡α [a]t0 Υ ` s

f

⇡α (a b) · t Υ, (c1 c2) f Var(t) ` (a c1) f t (

f

⇡α ab) Υ ` [a]s

f

⇡α [b]t

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-138
SLIDE 138

Correctness

Theorem Υ ` ⇡ f t iff Υ ` ⇡ · t

f

⇡↵ t. [ ]f maps freshness constraints in ∆ to fixed-point constraints: [ ]f : ∆

  • !

Ff a#X 7! (a ca) f X where ca is a new name. [ ]#maps fixed-point constraints in Υ to freshness constraints: [ ]# : Υ

  • !

F# ⇡ f X 7! supp(⇡)#X. Theorem

1 ∆ ` s ⇡↵ t ) [∆]f ` s

f

⇡↵ t.

2 Υ ` s

f

⇡↵ t ) [Υ]# ` s ⇡↵ t.

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-139
SLIDE 139

Simplification Rules for Nominal Unification

(fat) Pr ] {π f? a} = ) Pr, if π(a) = a (ff ) Pr ] {π f? ft} = ) Pr [ {π f? t} (ft) Pr ] {π f? (e t)n} = ) Pr [ {π f? t1, . . . , π f? tn} (fabs) Pr ] {π f? [a]t} = ) Pr [ {π f? (a c1) · t, (c1 c2) f? Var(t)} (fvar) Pr ] {π f? π0 · X} = ) Pr [ {π(π0)1 f? X}, if π0 6= Id (

f

⇡α a) Pr ] {a

f

? α a}

= ) Pr (

f

⇡α f ) Pr ] {f t

f

? α f t0}

= ) Pr [ {t ⇡α

? t0}

(

f

⇡α t) Pr ] {(e t)n ⇡α

? (e

t0)n} = ) Pr [ {t1

f

? α t0 1, . . . , tn f

? α t0 n}

(

f

⇡α ab1) Pr ] {[a]t

f

? α [a]t0}

= ) Pr [ {t

f

? α t0}

(

f

⇡α ab2) Pr ] {[a]t

f

? α [b]s}

= ) Pr [ {t

f

? α (a b) · s, (a c1) f? s,

(c1 c2) f? Var(s)} (

f

⇡α var) Pr ] {π · X

f

? α π0 · X} =

) Pr [ {(π0)1 π f? X} (

f

⇡α inst1) Pr ] {π · X

f

? α t} [X7!π1.t]

= ) Pr{X 7! π1.t}, if X / 2 Var(t) (

f

⇡α inst2) Pr ] {t

f

? α π · X} [X7!π1.t]

= ) Pr{X 7! π1.t}, if X / 2 Var(t) c1 and c2 are new names

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-140
SLIDE 140

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-141
SLIDE 141

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) +

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-142
SLIDE 142

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-143
SLIDE 143

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-144
SLIDE 144

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W Sol = (a#W , δ)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-145
SLIDE 145

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W Sol = (a#W , δ)

To f constraints:

[a]f(X, a)

f

? α [b]f((b c).W , (a c).Y ))

+

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-146
SLIDE 146

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W Sol = (a#W , δ)

To f constraints:

[a]f(X, a)

f

? α [b]f((b c).W , (a c).Y ))

+ f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? f((b c).W , (a c).Y )) (c1 c2) f? W , (c1 c2) f? Y +

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-147
SLIDE 147

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W Sol = (a#W , δ)

To f constraints:

[a]f(X, a)

f

? α [b]f((b c).W , (a c).Y ))

+ f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? f((b c).W , (a c).Y )) (c1 c2) f? W , (c1 c2) f? Y + f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? (b c).W , (a c1) f? (a c).Y (c1 c2) f? W , (c1 c2) f? Y +

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-148
SLIDE 148

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W Sol = (a#W , δ)

To f constraints:

[a]f(X, a)

f

? α [b]f((b c).W , (a c).Y ))

+ f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? f((b c).W , (a c).Y )) (c1 c2) f? W , (c1 c2) f? Y + f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? (b c).W , (a c1) f? (a c).Y (c1 c2) f? W , (c1 c2) f? Y + X

f

? α (a b)(b c).W , a f

? α (a b)(a c).Y

(a c1) f? W , (c c1) f? Y (c1 c2) f? W , (c1 c2) f? Y + X 7! (a b)(b c).W , Y 7! b (a c1) f? W , (c1 c2) f? W

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-149
SLIDE 149

Correspondence: freshness/fixed-point constraints

From # constraints:

[a]f(X, a) ⇡α

? [b]f((b c) · W , (a c) · Y ))

+ f(X, a) ⇡α

? (a b).f((b c).W , (a c).Y ))

a#f((b c) · W , (a c) · Y )) + f(X, a) ⇡α

? f((a b)(b c).W , (a b)(a c).Y ))

a#(b c) · W , a#(a c) · Y +⇤ X ⇡α

? (a b)(b c) · W , b ⇡α ? Y

a#W , c#Y + Y 7! b X ⇡α

? (a b)(b c) · W

a#W , c#b + X 7! (a b)(b c) · W a#W Sol = (a#W , δ)

To f constraints:

[a]f(X, a)

f

? α [b]f((b c).W , (a c).Y ))

+ f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? f((b c).W , (a c).Y )) (c1 c2) f? W , (c1 c2) f? Y + f(X, a)

f

? α (a b).f((b c).W , (a c).Y ))

(a c1) f? (b c).W , (a c1) f? (a c).Y (c1 c2) f? W , (c1 c2) f? Y + X

f

? α (a b)(b c).W , a f

? α (a b)(a c).Y

(a c1) f? W , (c c1) f? Y (c1 c2) f? W , (c1 c2) f? Y + X 7! (a b)(b c).W , Y 7! b (a c1) f? W , (c1 c2) f? W Sol = ((a c1) f W , (c1 c2) f W , δ)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-150
SLIDE 150

C-fixed point constraints

+: commutative symbol C-fixed-point constraint: ⇡ fC t C-↵-equality constraint: s

f

⇡C t +((a b) · X, a)

f?

⇡C +(Y , X) . &

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-151
SLIDE 151

C-fixed point constraints

+: commutative symbol C-fixed-point constraint: ⇡ fC t C-↵-equality constraint: s

f

⇡C t +((a b) · X, a)

f?

⇡C +(Y , X) . & {(a b) · X

f?

⇡C Y , a

f?

⇡C X} + [X 7! a] {(a b) · a

f?

⇡C Y } + {b

f?

⇡C Y } + [Y 7! b] (;, {X 7! a, Y 7! b})

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-152
SLIDE 152

C-fixed point constraints

+: commutative symbol C-fixed-point constraint: ⇡ fC t C-↵-equality constraint: s

f

⇡C t +((a b) · X, a)

f?

⇡C +(Y , X) . & {(a b) · X

f?

⇡C Y , a

f?

⇡C X} + [X 7! a] {(a b) · a

f?

⇡C Y } + {b

f?

⇡C Y } + [Y 7! b] (;, {X 7! a, Y 7! b}) {(a b) · X

f?

⇡C X, a

f?

⇡C Y } + [Y 7! a] {(a b) · X

f?

⇡C X} + {(a b) f?

C X}

+ ((a b) fC X, {Y 7! a})

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-153
SLIDE 153

Fixed Point Rules

⇡(a) = a (fCa) Υ ` ⇡ fC a supp(⇡⇡01) ✓ supp(perm(Υ|X)) (fCvar) Υ ` ⇡ fC ⇡0 · X Υ ` ⇡ fC t f 6= + (fCf) Υ ` ⇡ fC ft Υ ` ⇡ fC t1 . . . Υ ` ⇡ fC tn (fCtuple Υ ` ⇡ fC (t1, . . . , tn) Υ ` ⇡ · t0

f

⇡C ti Υ ` ⇡ · t1

f

⇡C t(i+1) mod 2 i = 0, 1(fC+) Υ ` ⇡ fC +(t0, t1) Υ, (c1 c2) fC Var(t) ` ⇡ fC (a c1) · t (fCabs) Υ ` ⇡ fC [a]t

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-154
SLIDE 154

Alpha-Equality Rules

(

f

⇡C a) Υ ` a

f

⇡C a Υ ` (⇡0)1 ⇡ fC X (

f

⇡C var) Υ ` ⇡ · X

f

⇡C ⇡0 · X Υ ` t

f

⇡C t0 (

f

⇡C f, f 6= +) Υ ` ft

f

⇡C ft0 Υ ` t1

f

⇡C t0

1

. . . Υ ` tn

f

⇡C t0

n ( f

⇡C tuple Υ ` (t1, . . . , tn)

f

⇡C (t0

1, . . . , t0 n)

Υ ` s0

f

⇡C ti s1

f

⇡C t(i+1) mod 2 i = 0, 1 (

f

⇡C +) Υ ` +hs0, s1i

f

⇡C +ht0, t1i Υ ` t

f

⇡C t0 (

f

⇡C [a]) Υ ` [a]t

f

⇡C [a]t0 Υ ` s

f

⇡C (a b)t Υ, (c1 c2) fC Var(t) ` (a c1) fC t (

f

⇡C ab) Υ ` [a]s

f

⇡C [b]t

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-155
SLIDE 155

Simplification rules for nominal C-unification

Pr ] {π f?

C a}

= ) Pr, if π(a) = a Pr ] {π f?

C ft}

= ) Pr [ {π f?

C t}, f 6= +

Pr ] {π f?

C +(t0, t1)}

= ) Pr [ {π · t0 ⇡? t0, π · t1 ⇡? t1} Pr ] {π f?

C +(t0, t1)}

= ) Pr [ {π · t0 ⇡? t1, π · t1 ⇡? t0} Pr ] {π f?

C (e

t)n} = ) Pr [ {π f?

C t1, . . . , π f? C tn}

Pr ] {π f?

C [a]t}

= ) Pr [ {π f?

C (a c1) · t, (c1 c2) f? C Var(t)}

Pr ] {π f?

C π0 · X}

= ) Pr [ {π(π0)1 f?

C X}, if π0 6= Id

Pr ] {ft

f?

⇡C ft0} = ) Pr [ {t

f?

⇡C t0}, f 6= + Pr ] {+(t0, t1)

f?

⇡C +(s0, s1)} = ) Pr [ {t0

f?

⇡C s0, t1

f?

⇡C s1} Pr ] {+(t0, t1)

f?

⇡C +(s0, s1)} = ) Pr [ {t0

f?

⇡C s1, t1

f?

⇡C s0} Pr ] {(e t)n

f?

⇡C (e t0)n} = ) Pr [ {t1

f?

⇡C t0

1, . . . , tn f?

⇡C t0

n}

Pr ] {[a]t

f?

⇡C [a]t0} = ) Pr [ {t

f?

⇡C t0} Pr ] {[a]t

f?

⇡C [b]s} = ) Pr [ {t

f?

⇡C (a b) · s, (a c1) f?

C s,

(c1 c2) f?

C Var(s)}

Pr ] {π · X

f?

⇡C π0 · X} = ) Pr [ {(π0)1 π f?

C X}

Pr ] {π · X

f?

⇡C t}

[X7!pi1.t]

= ) Pr{X 7! π1.t}, if X / 2 Var(t)

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-156
SLIDE 156

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

slide-157
SLIDE 157

Exercise

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

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-158
SLIDE 158

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

slide-159
SLIDE 159

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´

  • n et al]
  • Implementations/Formalisations: in OCaML, Haskell, Coq,

Isabelle-HOL, PVS

Maribel Fern´ andez Nominal Rewriting and Unification Theory

slide-160
SLIDE 160

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 sufficient conditions for termination.

  • Hindley-Milner style types [Fairweather&F.]: Typing is

decidable and there are principal types, ↵-equivalence preserves types. Sufficient conditions for Subject Reduction (rewriting preserves types).

Maribel Fern´ andez Nominal Rewriting and Unification Theory