A Coinductive Treatment of Infinitary Rewriting Jörg Endrullis, Helle Hvid Hansen, Dimitri Hendriks, Andrew Polonsky, Alexandra Silva
28th of January 2014
Term Rewriting A Term Rewrite System add(0, y ) = y add(S(x), y ) = S(add(x, y ))
Term Rewriting A Term Rewrite System add(0, y ) = y add(S(x), y ) = S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
Term Rewriting A Term Rewrite System add(0, y ) → y add(S(x), y ) → S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
Term Rewriting A Term Rewrite System add(0, y ) → y add(S(x), y ) → S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
An Example Rewrite Sequence add(S(0), S(0))
Term Rewriting A Term Rewrite System add(0, y ) → y add(S(x), y ) → S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
An Example Rewrite Sequence add(S(0), S(0)) → S(add(0, S(0)))
Term Rewriting A Term Rewrite System add(0, y ) → y add(S(x), y ) → S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
An Example Rewrite Sequence add(S(0), S(0)) → S(add(0, S(0))) → S(S(0))
Term Rewriting A Term Rewrite System add(0, y ) → y add(S(x), y ) → S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
An Example Rewrite Sequence add(S(0), S(0)) → S(add(0, S(0))) → S(S(0))
The rewrite relation → is non-deterministic!
Term Rewriting A Term Rewrite System add(0, y ) → y add(S(x), y ) → S(add(x, y )) Equational reasoning, except rules are applied only from left to right.
An Example Rewrite Sequence add(S(0), S(0)) → S(add(0, S(0))) → S(S(0))
The rewrite relation → is non-deterministic! add(S(0), add(0, 0)) → S(add(0, add(0, 0))) add(S(0), add(0, 0)) → add(S(0), 0)
Term Rewriting: Properties A relation → is confluent if a c
b d
Term Rewriting: Properties A relation → is confluent if a c
b d
A relation → is strongly normalizing or terminating if
a
Term Rewriting: Properties A relation → is confluent if a c
b d
A relation → is strongly normalizing or terminating if
a
A relation → is weakly normalizing if ··· a ···
Infinitary Rewriting nats(x) → x : nats(S(x))
nats 0
Infinitary Rewriting nats(x) → x : nats(S(x))
:
nats 0
0
nats S 0
Infinitary Rewriting nats(x) → x : nats(S(x))
:
nats 0
0
: nats
:
0
S
S
nats
0
0
S S 0
Infinitary Rewriting nats(x) → x : nats(S(x))
:
nats 0
0
converges to. . . ω
: nats
:
0
: :
0
S
S
nats
0
0
S
:
S
:
0 S
S
S S
0
0 S S 0
..
.
Infinitary Rewriting nats(x) → x : nats(S(x))
:
nats 0
0
converges to. . . ω
: nats
:
0
: :
0
S
S
nats
0
0
S
:
S
:
0 S
S
S S
0
0 S S
Infinitary rewriting I
infinite rewrite sequences
I
infinite terms
0
..
.
The Set of Infinite Terms as Metric Space We define a metric d on the set terms by: d(t, t) = 0 d(s, t) = 2−d where d largest depth up to which s and t coincide
Example s= f
t=
f
c
c
c
c
c
b
c
c
c
c
b
c .. .
c .. .
The first difference is at depth 2, hence d(s, t) = 2−2 = 0.25.
Infinitary Rewriting Continued. . . nats(x) → x : nats(S(x)) : nats nats 0
0
Infinitary Rewriting Continued. . . nats(x) → x : nats(S(x)) :
ω
nats nats
:
0
0
: nats :
0
0 :
S 0 S S 0
..
.
Infinitary Rewriting Continued. . . nats(x) → x : nats(S(x)) :
ω
nats nats
:
0
0
ω
:
:
nats :
0
0 :
S 0 S
: : :
0
:
S ..
:
S ..
S
S
. 0 S S
0
0
0
.
0 S
:
0
..
.
Infinitary Rewriting Continued. . . nats(x) → x : nats(S(x)) :
ω
nats nats
:
0
0
ω
:
:
nats :
0
0
0 S
: :
0
:
S
:
:
S ..
:
S ..
S
S
. 0 S S
0
0
0
.
Transfinite rewrite sequence of length ω + ω.
0 S
:
0
..
.
Transfinite Reductions have Ordinal Length Visualization of ω 2 :
Visualization of ω 3 :
Infinitary Rewriting — Motivation
Why infinitary rewriting?
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
I
Model theory of λ-calculus (Böhm Trees)
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
I
Model theory of λ-calculus (Böhm Trees)
I
Semantics of programming languages with lazy evaluation.
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
I
Model theory of λ-calculus (Böhm Trees)
I
Semantics of programming languages with lazy evaluation. For example, Haskell allows to write things like: alt = 0:1:alt .
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
I
Model theory of λ-calculus (Böhm Trees)
I
Semantics of programming languages with lazy evaluation. For example, Haskell allows to write things like: alt = 0:1:alt .
I
As a tool for finite rewriting and equational reasoning.
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
I
Model theory of λ-calculus (Böhm Trees)
I
Semantics of programming languages with lazy evaluation. For example, Haskell allows to write things like: alt = 0:1:alt .
I
As a tool for finite rewriting and equational reasoning. E.g. using infinite normal forms to conclude finitary inequality s 6= t.
Infinitary Rewriting — Motivation
Why infinitary rewriting? I
Modelling infinite computations / processes.
I
Model theory of λ-calculus (Böhm Trees)
I
Semantics of programming languages with lazy evaluation. For example, Haskell allows to write things like: alt = 0:1:alt .
I
As a tool for finite rewriting and equational reasoning. E.g. using infinite normal forms to conclude finitary inequality s 6= t. Here equality = is the reflexive, symmetric, transitive closure of →.
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω?
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning.
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U)
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U))
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U)) →ω 0 : 1 : even(0 : 1 : even(0 : 1 : even(0 : 1 : even(. . .))))
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U)) →ω 0 : 1 : even(0 : 1 : even(0 : 1 : even(0 : 1 : even(. . .)))) →ω 0 : 1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(. . .))))
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U)) →ω 0 : 1 : even(0 : 1 : even(0 : 1 : even(0 : 1 : even(. . .)))) →ω 0 : 1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(. . .)))) →ω 0 : 1 : 0 : even(0 : even(0 : even(0 : even(. . .))))
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U)) →ω 0 : 1 : even(0 : 1 : even(0 : 1 : even(0 : 1 : even(. . .)))) →ω 0 : 1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(. . .)))) →ω 0 : 1 : 0 : even(0 : even(0 : even(0 : even(. . .)))) →ω 0 : 1 : 0 : 0 : odd(0 : odd(0 : odd(0 : odd(. . .))))
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U)) →ω 0 : 1 : even(0 : 1 : even(0 : 1 : even(0 : 1 : even(. . .)))) →ω 0 : 1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(. . .)))) →ω 0 : 1 : 0 : even(0 : even(0 : even(0 : even(. . .)))) →ω 0 : 1 : 0 : 0 : odd(0 : odd(0 : odd(0 : odd(. . .)))) →ω 0 : 1 : 0 : 0 : even(even(even(even(. . .))))
Infinitary Rewriting — Motivation Why rewrite sequences longer than ω? I
Interesting on themselves.
I
Often more elegant for reasoning. For example: U → 0 : 1 : even(U)
even(x : s) → x : odd(s) odd(x : s) → even(s)
Does U define a stream? U → 0 : 1 : even(U) → 0 : 1 : even(0 : 1 : even(U)) →ω 0 : 1 : even(0 : 1 : even(0 : 1 : even(0 : 1 : even(. . .)))) →ω 0 : 1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(1 : 0 : odd(. . .)))) →ω 0 : 1 : 0 : even(0 : even(0 : even(0 : even(. . .)))) →ω 0 : 1 : 0 : 0 : odd(0 : odd(0 : odd(0 : odd(. . .)))) →ω 0 : 1 : 0 : 0 : even(even(even(even(. . .)))) We have reached an infinite normal form after ω · 5 steps.
What happens at the limit steps? Visualization of ω 2 :
Visualization of ω 3 :
What happens at the limit steps?
Excluding Jumps in the Limit Example Let R = {a → a, b → b}. a → a → a → . . . |{z} b → b → ... tω
Excluding Jumps in the Limit Example Let R = {a → a, b → b}. a → a → a → . . . |{z} b → b → ... tω
We need convergence at all intermediate limit ordinals!
Excluding Jumps in the Limit Example Let R = {a → a, b → b}. a → a → a → . . . |{z} b → b → ... tω
We need convergence at all intermediate limit ordinals! Two forms of convergence: 1
Metric convergence: terms converge towards the limit term f (x) → f (c(x))
2
f (a) → f (c(a)) → f (c(c(a))) → . . . f (c ω )
Strong convergence: Metric convergence + activity goes down a → b(a)
a → b(a) → b(b(a)) → . . . bω
Excluding Jumps in the Limit Example Let R = {a → a, b → b}. a → a → a → . . . |{z} b → b → ... tω
We need convergence at all intermediate limit ordinals! Two forms of convergence: 1
Metric convergence: terms converge towards the limit term f (x) → f (c(x))
2
f (a) → f (c(a)) → f (c(c(a))) → . . . f (c ω )
Strong convergence: Metric convergence + activity goes down a → b(a)
a → b(a) → b(b(a)) → . . . bω
Usual choice is strong convergence. . . better rewriting properties
Strong Convergence Visualized 0
ω ·1
ω ·2
ω ·3
ω ·4
ω ·5
ω ·6
ω ·7
ω ·8
ω ·9
ω · 10 ω · 11
ω2
ω · 12 ω · 13 ω · 14ω · 15ω · 16ω · 17ω · 18ω · 19
convergence of depths towards ω 2 The black lines indicate the depth of the activity/rewrite steps. The activity tends to infinity when approaching limit ordinals.
Infinite Reduction s→ → → t if there is a strongly convergent reduction from s with limit t
Infinite Reduction s→ → → t if there is a strongly convergent reduction from s with limit t
Example a → c(a) a → c(a) → c(c(a)) → c(c(c(a))) → . . . Thus we have a → → → cω .
Infinite Reduction s→ → → t if there is a strongly convergent reduction from s with limit t
Example a → c(a) a → c(a) → c(c(a)) → c(c(c(a))) → . . . Thus we have a → → → cω .
Example f (x) → f (c(x)) f (a) → f (c(a)) → f (c(c(a))) → . . . This is a divergent reduction; we do not have f (a) → → → f (c ω ).
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b)
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b)
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b)
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b) → → → f (c(c(c(. . .))), b)
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b) → → → f (c(c(c(. . .))), b) → f (c(c(c(. . .))), c(b))
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b) → → → f (c(c(c(. . .))), b) → f (c(c(c(. . .))), c(b)) → f (c(c(c(. . .))), c(c(b)))
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b) → → → f (c(c(c(. . .))), b) → f (c(c(c(. . .))), c(b)) → f (c(c(c(. . .))), c(c(b))) → → → f (c(c(c(. . .))), c(c(c(. . .))))
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b) → → → f (c(c(c(. . .))), b) → f (c(c(c(. . .))), c(b)) → f (c(c(c(. . .))), c(c(b))) → → → f (c(c(c(. . .))), c(c(c(. . .)))) → d
We need Transfinite Reductions. . . Example f (x, x) → d a → c(a) b → c(b) f (a, b) → f (c(a), b) → f (c(c(a)), b) → → → f (c(c(c(. . .))), b) → f (c(c(c(. . .))), c(b)) → f (c(c(c(. . .))), c(c(b))) → → → f (c(c(c(. . .))), c(c(c(. . .)))) → d Shortest reduction from f (a, b) to e has length ω + 1: f (a, b) → f (c(a), b) → f (c(a), c(b)) →ω f (c ω , c ω ) → d
Formal Definition: Infinitary Rewriting We write →p for a rewrite step at position p.
Definition A transfinite rewrite sequence s → → → t of ordinal length α consists of
Formal Definition: Infinitary Rewriting We write →p for a rewrite step at position p.
Definition A transfinite rewrite sequence s → → → t of ordinal length α consists of I
a sequence of terms { tβ }β≤α
Formal Definition: Infinitary Rewriting We write →p for a rewrite step at position p.
Definition A transfinite rewrite sequence s → → → t of ordinal length α consists of I
a sequence of terms { tβ }β≤α
I
s = t0 , and t = tα
Formal Definition: Infinitary Rewriting We write →p for a rewrite step at position p.
Definition A transfinite rewrite sequence s → → → t of ordinal length α consists of I
a sequence of terms { tβ }β≤α
I
s = t0 , and t = tα
I
a sequence of rewrite steps { tβ →p(β) tβ+1 }β