Formal Languages
ε
aa ba ab bb baab
···
and
Formally Coinductively
. . . . . . . . . . . . a b a b a b a b a b a b a b
Dmitriy Traytel
Formal Languages aa bb baab ba ab Formally Coinductively - - PowerPoint PPT Presentation
Formal Languages aa bb baab ba ab Formally Coinductively and a b a b a b a b a b a b a b . . . . . . . . . . . . Dmitriy Traytel Contribution Isabelle H O L = library of formal languages in
ε
aa ba ab bb baab
···
and
. . . . . . . . . . . . a b a b a b a b a b a b a b
Dmitriy Traytel
λ → ∀
=
Isabelle
β α
H O L
define regular operations ∅, ε, Atom, +, ·, ∗ prove axioms of Kleene Algebra
λ → ∀
=
Isabelle
β α
H O L
define regular operations ∅, ε, Atom, +, ·, ∗ prove axioms of Kleene Algebra
λ → ∀
=
Isabelle
β α
H O L
define regular operations ∅, ε, Atom, +, ·, ∗ prove axioms of Kleene Algebra
λ → ∀
=
Isabelle
β α
H O L
define regular operations ∅, ε, Atom, +, ·, ∗ prove axioms of Kleene Algebra
λ → ∀
=
Isabelle
β α
H O L
define regular operations ∅, ε, Atom, +, ·, ∗ prove axioms of Kleene Algebra
λ → ∀
=
Isabelle
β α
H O L
C
a t a t y p e C
e c u r s i
C
n d u c t i
P r
A s s i s t a n t Jacobs, Rutten EATCS’97 stream Rutten CONCUR’98 language Giménez, Castéran ’98 stream, lazy list Rutten MSCS’05 stream Hinze JFP’11 stream Chlipala ’13 stream, while Rot, Rutten, Bonsangue
LATA’13
language Kozen, Silva MSCS’14 stream Setzer Festschrift Jäger’16 stream Traytel FSCD’16 language
λ → ∀ =I s a b e l l e
β α H O L. . . . . . a b a b a b
. . . . . . a b a b a b
. . . . . . a b a b a b
. . . . . . a b a b a b
. . . . . . a b a b a b
. . . . . . a b a b a b
. . . . . . a b a b a b
. . . . . . a b a b a b . . . . . . a b a b a b
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1
pattern match argument
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1 produce 1
pattern match argument copattern match output
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1 produce 1
pattern match argument copattern match output
(Co)recursive call arguments very restricted context arbitrary
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1 produce 1
pattern match argument copattern match output
(Co)recursive call arguments very restricted arbitrary context arbitrary very restricted
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1 produce 1
pattern match argument copattern match output
(Co)recursive call arguments very restricted arbitrary context arbitrary very restricted
. . . . . . a b a b a b . . . . . . a b a b a b
Atom a Atom b
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1 produce 1
pattern match argument copattern match output
(Co)recursive call arguments very restricted arbitrary context arbitrary very restricted
. . . . . . a b a b a b
. . . . . . a b a b a b
Atom a Atom b
. . . . . . a b a b a b
primrec primcorec
Syntactic criterion for termination productivity
αlist ⇒ ··· ··· ⇒ αlang
Philosophy consume 1 produce 1
pattern match argument copattern match output
(Co)recursive call arguments very restricted arbitrary context arbitrary very restricted
. . . . . . a b a b a b
. . . . . . a b a b a b
Atom a Atom b
. . . . . . a b a b a b
✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ · :: αlang ⇒ αlang ⇒ αlang
✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ · :: αlang ⇒ αlang ⇒ αlang
with ˆ
· and ˆ ⊕ primitively
corecursive
with ˆ
· and ˆ ⊕ primitively
corecursive
Blanchette, Popescu, Traytel @ ICFP’15 +
Blanchette, Bouzy, Lochbihler, Popescu, Traytel
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
R K1 K2
∀L1 L2. R L1 L2 − → (o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x))
K1 = K2
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
R K1 K2
∀L1 L2. R L1 L2 − → (o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x))
K1 = K2
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
R K1 K2
∀L1 L2. R L1 L2 − → (o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x))
K1 = K2
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
R K1 K2
∀L1 L2. R L1 L2 − → (o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x))
K1 = K2
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
R K1 K2
∀L1 L2. R L1 L2 − → (o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x))
K1 = K2
∨ o L) = o L = o L2
R (δ L1 x) (δ L2 x) = R (δ (∅ + L) x) (δ L x)
= R (δ ∅ x + δ L x) (δ L x) = R (∅ + δ L x) (δ L x) = (∃L′. ∅ + δ L x = ∅ + L′ ∧ δ L x = L′) =
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
proof (rule coinductlang) define R K1 K2 = (∃L. K1 = ∅ + L ∧ K2 = L) show R (∅ + L) L by simp fix L1 and L2 assume R L1 L2 then obtain L where L1 = ∅ + L and L2 = L by simp then show o L1 = o L2 ∧ ∀x. R (δ L1 x) (δ L2 x) by simp qed
✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿
L2 = (L · M) + (K · M) −
by (coinduction arbitrary : L K rule: coinduct+
lang) auto
by (coinduction arbitrary : L K rule: coinduct+
lang) auto
R K1 K2
∀L1 L2. R L1 L2 − → (o L1 = o L2 ∧ ∀x. R
+(δ L1 x) (δ L2 x))
K1 = K2
codatatype αlang = L bool (α ⇒ αlang)
codatatype αlang = L bool (α ⇒ αlang) codatatype (α, β)langMoore = LMoore β (α ⇒ (α, β)langMoore) codatatype (α, β)langMealy = LMealy (α ⇒ β) (α ⇒ (α, β)langMealy)
codatatype αlang = L bool (α ⇒ αlang) codatatype (α, β)langMoore = LMoore β (α ⇒ (α, β)langMoore) codatatype (α, β)langMealy = LMealy (α ⇒ β) (α ⇒ (α, β)langMealy) codatatype αlangNondet = LNondet bool (α ⇒ αlangNondet setκ)
codatatype αlang = L bool (α ⇒ αlang) codatatype (α, β)langMoore = LMoore β (α ⇒ (α, β)langMoore) codatatype (α, β)langMealy = LMealy (α ⇒ β) (α ⇒ (α, β)langMealy) codatatype αlangNondet = LNondet bool (α ⇒ αlangNondet setκ) codatatype αlangω = Lω (αlang) (α ⇒ αlangω)
codatatype αlang = L bool (α ⇒ αlang) codatatype (α, β)langMoore = LMoore β (α ⇒ (α, β)langMoore) codatatype (α, β)langMealy = LMealy (α ⇒ β) (α ⇒ (α, β)langMealy) codatatype αlangNondet = LNondet bool (α ⇒ αlangNondet setκ) codatatype αlangω = Lω (αlang) (α ⇒ αlangω)
Hölzl, Lochbihler, Traytel, ITP 2015
codatatype αlangMarkov = LMarkov (α×αlangMarkov) pmf codatatype αlangReact = LReact (α ⇒ αlangReact pmf option) codatatype αlangSegala = LSegala (α×αlangSegala) pmf setκ
ε
aa ba ab bb baab
···
and
. . . . . . . . . . . . a b a b a b a b a b a b a b
Dmitriy Traytel
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅
d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s
d a (r∗)
=
d a r · r∗
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
ˆ
d [] r
=
r
ˆ
d aw r
= ˆ
d w (d a r)
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
ˆ
d [] r
=
r
ˆ
d aw r
= ˆ
d w (d a r) Theorem [Brzozowski’64]
{[ˆ
d w r]ACI | w ∈ Σ∗} is finite for all r
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
ˆ
d [] r
=
r
ˆ
d aw r
= ˆ
d w (d a r) Theorem [Brzozowski’64]
{[ˆ
d w r]ACI | w ∈ Σ∗} is finite for all r Corollary
{[ˆ
d w r]ACIUD | w ∈ Σ∗} is finite for all r
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
ˆ
d [] r
=
r
ˆ
d aw r
= ˆ
d w (d a r)
ˆ
dACI [] r
= |r|ACI ˆ
dACI aw r
= ˆ
dACI w |d a r|ACI Theorem [Brzozowski’64]
{[ˆ
d w r]ACI | w ∈ Σ∗} is finite for all r Corollary
{[ˆ
d w r]ACIUD | w ∈ Σ∗} is finite for all r
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
ˆ
d [] r
=
r
ˆ
d aw r
= ˆ
d w (d a r)
ˆ
dACI [] r
= |r|ACI ˆ
dACI aw r
= ˆ
dACI w |d a r|ACI Theorem [Brzozowski’64]
{[ˆ
d w r]ACI | w ∈ Σ∗} is finite for all r Corollary
{[ˆ
d w r]ACIUD | w ∈ Σ∗} is finite for all r Lemma
|d a |r|ACI|ACI = |d a r|ACI
Corollary
{ˆ
dACI w r | w ∈ Σ∗} is finite for all r
Finiteness
d a ∅
= ∅
d a ε
= ∅
d a (Atom b)
=
if a = b then ε else ∅ d a (r + s)
=
d a r + d a s d a (r · s)
=
if o r then d a r · s + d a s else d a r · s d a (r∗)
=
d a r · r∗
ˆ
d [] r
=
r
ˆ
d aw r
= ˆ
d w (d a r)
ˆ
dACI [] r
= |r|ACI ˆ
dACI aw r
= ˆ
dACI w |d a r|ACI Theorem [Brzozowski’64]
{[ˆ
d w r]ACI | w ∈ Σ∗} is finite for all r Corollary
{[ˆ
d w r]ACIUD | w ∈ Σ∗} is finite for all r Lemma
|d a |r|ACI|ACI = |d a r|ACI
Corollary
{ˆ
dACI w r | w ∈ Σ∗} is finite for all r Conjecture
{ˆ
dACIUD w r | w ∈ Σ∗} is finite for all r
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Negative Example R = ACI ∪ {ε · r∗ → r∗ · r∗}
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Negative Example R = ACI ∪ {ε · r∗ → r∗ · r∗}
a∗
d
→ ε · a∗
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Negative Example R = ACI ∪ {ε · r∗ → r∗ · r∗}
a∗
d
→ ε · a∗
R!
→
a∗ · a∗
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Negative Example R = ACI ∪ {ε · r∗ → r∗ · r∗}
a∗
d
→ ε · a∗
R!
→
a∗ · a∗
d
→ (ε · a∗) · a∗ + ε · a∗
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Negative Example R = ACI ∪ {ε · r∗ → r∗ · r∗}
a∗
d
→ ε · a∗
R!
→
a∗ · a∗
d
→ (ε · a∗) · a∗ + ε · a∗
R!
→ (a∗ · a∗) · a∗ + a∗ · a∗
Finiteness as a Rewriting Problem
Input Convergent ordered regex rewriting system R with ACI ⊆ R Question Under which conditions is {ˆ dR w r | w ∈ Σ∗} finite for all r?
Negative Example R = ACI ∪ {ε · r∗ → r∗ · r∗}
a∗
d
→ ε · a∗
R!
→
a∗ · a∗
d
→ (ε · a∗) · a∗ + ε · a∗
R!
→ (a∗ · a∗) · a∗ + a∗ · a∗
d
→ ...