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 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´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 • Substitution: 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 Logic, 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 E cient 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)
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) (+) • E cient 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) (+) • E cient 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) (+) • E cient 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) (+) • E cient 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) • E cient 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) • E cient 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 E cient 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) • E cient 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) • E cient matching and unification algorithms • Dependencies of terms on names are implicit )
Maribel Fern´andez Nominal Rewriting and Unification Theory Nominal Approach
Key ideas: Freshness conditions a#t, name swapping (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) • E cient 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 (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).
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.