Types for Nominal Terms and Rewrite Rules Maribel Fern andez - - PowerPoint PPT Presentation

types for nominal terms and rewrite rules
SMART_READER_LITE
LIVE PREVIEW

Types for Nominal Terms and Rewrite Rules Maribel Fern andez - - PowerPoint PPT Presentation

Types for Nominal Terms and Rewrite Rules Maribel Fern andez Murdoch J. Gabbay DCS, Kings College London TYPES, April 2006 M. Fern andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules Motivations Specifying binding


slide-1
SLIDE 1

Types for Nominal Terms and Rewrite Rules

Maribel Fern´ andez Murdoch J. Gabbay

DCS, King’s College London

TYPES, April 2006

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-2
SLIDE 2

Motivations

Specifying binding operations — informal presentations:

  • Operational semantics:

let a = N in M − → (fun a → M)N

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-3
SLIDE 3

Motivations

Specifying binding operations — informal presentations:

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

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-4
SLIDE 4

Motivations

Specifying binding operations — informal presentations:

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

  • π-calculus:

P | νa.Q → νa.(P | Q) (a ∈ fv(P))

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-5
SLIDE 5

Motivations

Specifying binding operations — informal presentations:

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

  • π-calculus:

P | νa.Q → νa.(P | Q) (a ∈ fv(P))

  • α-conversion is implicit, but
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-6
SLIDE 6

Motivations

Specifying binding operations — informal presentations:

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

  • π-calculus:

P | νa.Q → νa.(P | Q) (a ∈ fv(P))

  • α-conversion is implicit, but
  • (fun a → M) =α (fun b → M) since a may occur in M.
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-7
SLIDE 7

Formally:

There are several alternatives.

  • First-order rewrite systems.

append(nil, x) → x append(cons(x, z), y) → cons(x, append(z, y))

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-8
SLIDE 8

Formally:

There are several alternatives.

  • First-order rewrite systems.

append(nil, x) → x append(cons(x, z), y) → cons(x, append(z, y))

  • No binders. (-)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-9
SLIDE 9

Formally:

There are several alternatives.

  • First-order rewrite systems.

append(nil, x) → x append(cons(x, z), y) → cons(x, append(z, y))

  • No binders. (-)
  • First-order matching: we need to ’specify’ α-conversion. (-)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-10
SLIDE 10

Formally:

There are several alternatives.

  • First-order rewrite systems.

append(nil, x) → x append(cons(x, z), y) → cons(x, append(z, y))

  • No binders. (-)
  • First-order matching: we need to ’specify’ α-conversion. (-)
  • Simple notion of substitution. (+)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-11
SLIDE 11

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-12
SLIDE 12

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-13
SLIDE 13

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • Terms with binders. (+)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-14
SLIDE 14

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • Terms with binders. (+)
  • Implicit α-conversion. (+)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-15
SLIDE 15

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • Terms with binders. (+)
  • Implicit α-conversion. (+)
  • We targeted α but now we have to deal with β too. (-)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-16
SLIDE 16

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • Terms with binders. (+)
  • Implicit α-conversion. (+)
  • We targeted α but now we have to deal with β too. (-)
  • Substitution is a meta-operation using β. (-)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-17
SLIDE 17

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • Terms with binders. (+)
  • Implicit α-conversion. (+)
  • We targeted α but now we have to deal with β too. (-)
  • Substitution is a meta-operation using β. (-)
  • Unification is undecidable in general. (-)
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-18
SLIDE 18

Higher-order frameworks

  • Higher-order rewrite systems (CRS, HRS, etc.)

β-rule: app(lam([a]Z(a)), Z ′) → Z(Z ′) Then app(lam([a]f (a, g(a)), b) → f (b, g(b)) using higher-order matching.

  • Higher-Order Abstract Syntax:

let a = N in M(a) − → (fun a → M(a))N

  • Terms with binders. (+)
  • Implicit α-conversion. (+)
  • 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. ∀x.P).
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-19
SLIDE 19

Nominal Terms, Unification, Rewriting

Inspired by the work on Nominal Logic and Fresh ML. Key ideas: Freshness conditions a#t, name swapping (ab)t. Example: β and η rules as Nominal Rewriting Systems: app(lam([a]Z), Z ′) → subst([a]Z, Z ′) a#M ⊢ (λ([a]app(M, a)) → M ⇒ Terms with binders.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-20
SLIDE 20

Nominal Terms, Unification, Rewriting

Inspired by the work on Nominal Logic and Fresh ML. Key ideas: Freshness conditions a#t, name swapping (ab)t. Example: β and η rules as Nominal Rewriting Systems: app(lam([a]Z), Z ′) → subst([a]Z, Z ′) a#M ⊢ (λ([a]app(M, a)) → M

  • Terms with binders.

⇒ Matching modulo α (but terms are not defined as α-equivalence classes)

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-21
SLIDE 21

Nominal Terms, Unification, Rewriting

Inspired by the work on Nominal Logic and Fresh ML. Key ideas: Freshness conditions a#t, name swapping (ab)t. Example: β and η rules as Nominal Rewriting Systems: app(lam([a]Z), Z ′) → subst([a]Z, Z ′) a#M ⊢ (λ([a]app(M, a)) → M

  • Terms with binders.
  • Matching modulo α (but terms are not defined as

α-equivalence classes) ⇒ Simple notion of substitution (first order).

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-22
SLIDE 22

Nominal Terms, Unification, Rewriting

Inspired by the work on Nominal Logic and Fresh ML. Key ideas: Freshness conditions a#t, name swapping (ab)t. Example: β and η rules as Nominal Rewriting Systems: app(lam([a]Z), Z ′) → subst([a]Z, Z ′) a#M ⊢ (λ([a]app(M, a)) → M

  • Terms with binders.
  • Matching modulo α (but terms are not defined as

α-equivalence classes)

  • Simple notion of substitution (first order).

⇒ Dependencies of terms on names are implicit.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-23
SLIDE 23

Nominal Terms, Unification, Rewriting

Inspired by the work on Nominal Logic and Fresh ML. Key ideas: Freshness conditions a#t, name swapping (ab)t. Example: β and η rules as Nominal Rewriting Systems: app(lam([a]Z), Z ′) → subst([a]Z, Z ′) a#M ⊢ (λ([a]app(M, a)) → M

  • Terms with binders.
  • Matching modulo α (but terms are not defined as

α-equivalence classes)

  • Simple notion of substitution (first order).
  • Dependencies of terms on names are implicit.

⇒ Easy to express constraints such as a ∈ fv(M).

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-24
SLIDE 24

Nominal Terms, Unification, Rewriting

Inspired by the work on Nominal Logic and Fresh ML. Key ideas: Freshness conditions a#t, name swapping (ab)t. Example: β and η rules as Nominal Rewriting Systems: app(lam([a]Z), Z ′) → subst([a]Z, Z ′) a#M ⊢ (λ([a]app(M, a)) → M

  • Terms with binders.
  • Matching modulo α (but terms are not defined as

α-equivalence classes)

  • Simple notion of substitution (first order).
  • Dependencies of terms on names are implicit.
  • Easy to express constraints such as a ∈ fv(M).

⇒ Can be easily generalised to express more general constraints.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-25
SLIDE 25

Nominal Syntax (Untyped) [ Urban,Pitts,Gabbay: TCS’04]

  • Function symbols: f , g . . .

Variables: M, N, X, Y , . . . Atoms: a, b, . . . Swappings: (a b)

  • Def. (a b)a = b, (a b)b = a, (a b)c = c

Permutations: lists of 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, t′), lam([a]t), let(t, [a]t′),

letrec[f ]([a]t, t′), subst([a]t, t′) Syntactic sugar: a, (tt′), λa.t, let a = t in t′, letrec fa = t in t′, t[a → t′]

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-26
SLIDE 26

Types for Nominal Terms

Types built from

  • a set of base data sorts δ (e.g. Nat, Bool, Exp, . . . )
  • type variables α, and
  • type constructors tf (e.g. ×, →, List, . . . )

τ ::= δ | α | (τ1 × . . . × τn | tf τ | [τ]τ ′ σ ::= ∀ατ Type declarations (arity): ρ ::= (τ ′)τ Instantiation relation: σ ≤ τ

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-27
SLIDE 27

Typing Rules

σ ≤ τ Γ, a : σ ⊢ a : τ σ ≤ τ Γ, X : σ ⊢ π · X : τ Γ ⊢ t : τ ′ f : ρ ≤ (τ ′)τ Γ ⊢ f t : τ Γ, a : τ ⊢ t : τ ′ Γ ⊢ [a]t : [τ]τ ′ Γ ⊢ ti : τi Γ ⊢ (t1, . . . , tn) : (τ1 × . . . × τn) Example: X : τ, b : β ⊢ [a]((a b) · X, b) : [α](τ × β) Remark:

  • Permutations are ignored in the typing rules (but will be taken

into account when instantiating terms).

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

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-28
SLIDE 28

Principal Types

  • Every term has a principal type, obtained using the function

pt(Γ ⊢ s). pt is sound and complete.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-29
SLIDE 29

Principal Types

  • Every term has a principal type, obtained using the function

pt(Γ ⊢ s). pt is sound and complete.

  • Type inference is decidable.
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-30
SLIDE 30

Principal Types

  • Every term has a principal type, obtained using the function

pt(Γ ⊢ s). pt is sound and complete.

  • Type inference is decidable.
  • Types are preserved by α-equivalence.
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-31
SLIDE 31

α-equivalence (Freshness)

We use freshness to avoid name capture. a#X means a ∈ fv(X) when X is instantiated. 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

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-32
SLIDE 32

α-equivalence

a ≈α a ds(π, π′)#X π · X ≈α π′ · 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(π, π′) = {n|π(n) = π′(n)}

  • a#X, b#X ⊢ (a b) · X ≈α X
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-33
SLIDE 33

α-equivalence

a ≈α a ds(π, π′)#X π · X ≈α π′ · 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(π, π′) = {n|π(n) = π′(n)}

  • a#X, b#X ⊢ (a b) · X ≈α X
  • b#X ⊢ λ[a]X ≈α λ[b](a b) · X
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-34
SLIDE 34

α-equivalence

a ≈α a ds(π, π′)#X π · X ≈α π′ · 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(π, π′) = {n|π(n) = π′(n)}

  • a#X, b#X ⊢ (a b) · X ≈α X
  • b#X ⊢ λ[a]X ≈α λ[b](a b) · X
  • α-equivalence respects types:

∆ ⊢ s ≈α t and Γ ⊢ s : τ ⇒ Γ ⊢ t : τ.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-35
SLIDE 35

Nominal Unification and Matching

  • l

?≈? t has solution (∆, θ) if

∆ ⊢ lθ ≈α tθ A solvable problem Pr has a unique most general solution: (Γ, θ) such that Γ ⊢ Prθ

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-36
SLIDE 36

Nominal Unification and Matching

  • l

?≈? t has solution (∆, θ) if

∆ ⊢ lθ ≈α tθ A solvable problem Pr has a unique most general solution: (Γ, θ) such that Γ ⊢ Prθ

  • Nominal unification (and matching) is decidable [Urban, Pitts,

Gabbay 2003, TCS 04]

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-37
SLIDE 37

Nominal Unification and Matching

  • l

?≈? t has solution (∆, θ) if

∆ ⊢ lθ ≈α tθ A solvable problem Pr has a unique most general solution: (Γ, θ) such that Γ ⊢ Prθ

  • Nominal unification (and matching) is decidable [Urban, Pitts,

Gabbay 2003, TCS 04]

  • and polynomial [TERMGRAPH 06].
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-38
SLIDE 38

Nominal Rewriting

Rules: ∆ ⊢ l → r V (r) ∪ V (∆) ⊆ V (l) Examples: (λ[a]X)Y → X[a→Y ] (XX ′)[a→Y ] → X[a→Y ]X ′[a→Y ] a#Y ⊢ Y [a→X] → Y b#Y ⊢ (λ[b]X)[a→Y ] → λ[b](X[a→Y ])

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-39
SLIDE 39

Typed Nominal Rewriting

Typed Rules: Φ; ∇ ⊢ l → r : τ where:

  • Φ types only variables and has no type-schemes,
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-40
SLIDE 40

Typed Nominal Rewriting

Typed Rules: Φ; ∇ ⊢ l → r : τ where:

  • Φ types only variables and has no type-schemes,
  • pt(Φ ⊢ l) = (Id, τ) and Φ ⊢ r : τ.
  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-41
SLIDE 41

Typed Nominal Rewriting

Typed Rules: Φ; ∇ ⊢ l → r : τ where:

  • Φ types only variables and has no type-schemes,
  • pt(Φ ⊢ l) = (Id, τ) and Φ ⊢ r : τ.
  • The essential typings of Φ ⊢ r : τ are a subset of the

essential typings of Φ ⊢ l : τ, up to weakening and strengthening of atoms not affected by permutations.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-42
SLIDE 42

Typed Nominal Rewriting

Typed Rules: Φ; ∇ ⊢ l → r : τ where:

  • Φ types only variables and has no type-schemes,
  • pt(Φ ⊢ l) = (Id, τ) and Φ ⊢ r : τ.
  • The essential typings of Φ ⊢ r : τ are a subset of the

essential typings of Φ ⊢ l : τ, up to weakening and strengthening of atoms not affected by permutations.

  • Essential typings of Φ ⊢ r : τ are the typings associated to

π · X during pt(Φ ⊢ r), where we apply π in the typing context.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-43
SLIDE 43

Typed Nominal Rewriting

Typed Rules: Φ; ∇ ⊢ l → r : τ where:

  • Φ types only variables and has no type-schemes,
  • pt(Φ ⊢ l) = (Id, τ) and Φ ⊢ r : τ.
  • The essential typings of Φ ⊢ r : τ are a subset of the

essential typings of Φ ⊢ l : τ, up to weakening and strengthening of atoms not affected by permutations.

  • Essential typings of Φ ⊢ r : τ are the typings associated to

π · X during pt(Φ ⊢ r), where we apply π in the typing context.

  • Example: The essential typings of

a : α, X : τ ⊢ ((a b) · X, [a]X) : τ × [α′]τ are b : α, X : τ ⊢ X : τ and a : α′, X : τ ⊢ X : τ.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-44
SLIDE 44

Nominal Rewriting — Matching

A (typed) matching problem (Φ; ∇ ⊢ l) ?≈ (Γ; ∆ ⊢ s) is a pair of tuples (Φ, Γ are typing contexts, ∇, ∆ are freshness contexts, l, s are terms) such that the atoms, variables and type-variables mentioned on the left-hand side are disjoint from those mentioned in Γ, s. A solution is the least pair (S, θ) of a type- and term-substitution such that:

1 Xθ ≡ X for X ∈ V (Φ, ∇, l) and αS ≡ α for α ∈ TV (Φ). 2 ∆ ⊢ lθ ≈α s and ∆ ⊢ ∇θ are derivable. 3 pt(Φ ⊢ l) = (Id, τ) and pt(Γ ⊢ s) = (Id, τS); 4 For each Φ, Φ′ ⊢ X : φ′ an essential typing of Φ ⊢ l : τ, it

is the case that Γ, (Φ′S) ⊢ Xθ : φ′S.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-45
SLIDE 45

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-46
SLIDE 46

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • s rewrites with R to t in the context Γ; ∆, written

Γ; ∆ ⊢ s R → t, when:

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-47
SLIDE 47

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • s rewrites with R to t in the context Γ; ∆, written

Γ; ∆ ⊢ s R → t, when:

1

s = s′′[s′]

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-48
SLIDE 48

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • s rewrites with R to t in the context Γ; ∆, written

Γ; ∆ ⊢ s R → t, when:

1

s = s′′[s′]

2

Γ′ ⊢ s′ : µ′ is the typing of s′ at the corresponding position in a derivation for Γ ⊢ s′′[s′] : µ;

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-49
SLIDE 49

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • s rewrites with R to t in the context Γ; ∆, written

Γ; ∆ ⊢ s R → t, when:

1

s = s′′[s′]

2

Γ′ ⊢ s′ : µ′ is the typing of s′ at the corresponding position in a derivation for Γ ⊢ s′′[s′] : µ;

3

(Φ; ∇ ⊢ l) ?≈ (Γ′; ∆, A(∇, l)#V (∆, s′) ⊢ s′) has solution (S, θ).

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-50
SLIDE 50

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • s rewrites with R to t in the context Γ; ∆, written

Γ; ∆ ⊢ s R → t, when:

1

s = s′′[s′]

2

Γ′ ⊢ s′ : µ′ is the typing of s′ at the corresponding position in a derivation for Γ ⊢ s′′[s′] : µ;

3

(Φ; ∇ ⊢ l) ?≈ (Γ′; ∆, A(∇, l)#V (∆, s′) ⊢ s′) has solution (S, θ).

4

∆ ⊢ s′′[rθ] ≈α t.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-51
SLIDE 51

Nominal Rewriting — Closed Rewriting

We rewrite terms-in-context ∆ ⊢ s.

  • Take ∆ ⊢ s, ∆ ⊢ t such that pt(Γ ⊢ s) = (Id, µ); and

R ≡ Φ; ∇ ⊢ l → r : τ, such that V (R) ∩ V (Γ, ∆, s, t) = ∅, A(R) ∩ A(Γ, ∆, s, t) = ∅ and TV (R) ∩ TV (Γ) = ∅ (renaming variables and atoms in R if necessary).

  • s rewrites with R to t in the context Γ; ∆, written

Γ; ∆ ⊢ s R → t, when:

1

s = s′′[s′]

2

Γ′ ⊢ s′ : µ′ is the typing of s′ at the corresponding position in a derivation for Γ ⊢ s′′[s′] : µ;

3

(Φ; ∇ ⊢ l) ?≈ (Γ′; ∆, A(∇, l)#V (∆, s′) ⊢ s′) has solution (S, θ).

4

∆ ⊢ s′′[rθ] ≈α t.

  • Subject Reduction:

Let R ≡ Φ; ∇ ⊢ l → r : τ. If Γ ⊢ s : µ and Γ; ∆ ⊢ s R → t then Γ ⊢ t : µ.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-52
SLIDE 52

Applications

A (typed!) implementation of the untyped λ-calculus: Consider a type Λ and term-constructors lam : ([Λ]Λ)Λ, app : (Λ × Λ)Λ, and sub : ([Λ]Λ × Λ)Λ. We sugar these to λ[a]s, st, and s[a→t] respectively. Rewrite rules: X, Y :Λ ⊢ (λ[a]X)Y → X[a→Y ] : Λ X, Y :Λ; a#X ⊢ X[a→Y ] → X : Λ Y :Λ ⊢ a[a→Y ] → Y : Λ X, Y :Λ; b#Y ⊢ (λ[b]X)[a→Y ] → λ[b](X[a→Y ]) : Λ X, Y , Z:Λ ⊢ (XY )[a→Z] → X[a→Z] Y [a→Z] : Λ

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-53
SLIDE 53

Applications

Surjective pairing: Consider fst : (α × β)α and snd : (α × β)β. We can define typable rewrite rules for projections and surjective pairing as follows: X : α, Y : β ⊢ fst(X, Y ) → X : α X : α, Y : β ⊢ snd(X, Y ) → Y : β X : α × β ⊢ (fst(X), snd(X)) → X : α × β Note that this rewrite system cannot be analysed as sugar in the λ-calculus [Barendregt 74].

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-54
SLIDE 54

Conclusion

  • Nominal Rewriting Systems: first-order systems with matching

modulo α (decidable, polynomial). Higher-order rewriting systems can be encoded.

  • α-equivalence preserves types.
  • Typing is decidable and there are principal types.
  • Typing rules ignore permutations but typed-matching and

typed-rewriting take them into account. Rewriting with typed rewrite rules preserves types.

  • Future work: denotational semantics for nominal terms;

normalisation properties of nominal terms (intersection types); type systems for nominal programming languages.

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules

slide-55
SLIDE 55

That’s all!

Questions ?

  • M. Fern´

andez, M.J. Gabbay Types for Nominal Terms and Rewrite Rules