Skip to content

Instantly share code, notes, and snippets.

@twanvl
Created December 20, 2013 22:35
Show Gist options
  • Select an option

  • Save twanvl/8062712 to your computer and use it in GitHub Desktop.

Select an option

Save twanvl/8062712 to your computer and use it in GitHub Desktop.
New proof of confluence thing (see https://gist.github.com/twanvl/7453495), which will hopefully also extend to lambda calculus.
module 2013-12-20-confluence-problem-v2 where
open import 2013-12-20-relations
open import Function
open import Data.Unit using (⊀;tt)
open import Relation.Binary hiding (Sym)
open import Relation.Binary.PropositionalEquality as PE hiding (subst;sym;trans;refl)
open import Data.Product as P hiding (map;zip;swap)
open import Data.Nat as Nat hiding (fold)
open import Data.Nat.Properties as NatP
open import Relation.Nullary
open import Induction.WellFounded
open import Induction.Nat
open ≑-Reasoning
open import Algebra.Structures
open IsDistributiveLattice isDistributiveLattice using () renaming (∧-comm to βŠ”-comm)
open IsCommutativeSemiring isCommutativeSemiring using (+-comm;+-assoc)
open DecTotalOrder Nat.decTotalOrder using () renaming (refl to ≀-refl; trans to ≀-trans)
--------------------------------------------------------------------------------
-- Utility
--------------------------------------------------------------------------------
n≀mβŠ”n : βˆ€ m n β†’ n ≀ m βŠ” n
n≀mβŠ”n m n rewrite βŠ”-comm m n = m≀mβŠ”n n m
βŠ”β‰€ : βˆ€ {m n o} β†’ m ≀ o β†’ n ≀ o β†’ m βŠ” n ≀ o
βŠ”β‰€ z≀n n≀o = n≀o
βŠ”β‰€ (s≀s m≀o) z≀n = s≀s m≀o
βŠ”β‰€ (s≀s m≀o) (s≀s n≀o) = s≀s (βŠ”β‰€ m≀o n≀o)
β‰€βŠ”β‰€ : βˆ€ {a b c d} β†’ a ≀ b β†’ c ≀ d β†’ a βŠ” c ≀ b βŠ” d
β‰€βŠ”β‰€ {a} {b} {c} {d} a≀b c≀d = βŠ”β‰€ (≀-trans a≀b (m≀mβŠ”n b d)) (≀-trans c≀d (n≀mβŠ”n b d))
--------------------------------------------------------------------------------------------------
-- The problem
--------------------------------------------------------------------------------------------------
data V : Set where
`A : V
`C : V β†’ V
`D : V β†’ V β†’ V
_==_ : Relβ‚€ V
data _⟢_ : Relβ‚€ V where
aca : `A ⟢ `C `A
d₁ : βˆ€ {a b} β†’ (eq : a == b) β†’ `D a b ⟢ a
dβ‚‚ : βˆ€ {a b} β†’ (eq : a == b) β†’ `D a b ⟢ b
-- Do we also have these? It was not entirely clear from the paper.
-- But I assume so, since otherwise the relation is strongly normalizing and we could prove confluence that way
under-c : βˆ€ {a a'} β†’ (x : a ⟢ a') β†’ `C a ⟢ `C a'
under-d₁ : βˆ€ {a a' b} β†’ (x : a ⟢ a') β†’ `D a b ⟢ `D a' b
under-dβ‚‚ : βˆ€ {a b b'} β†’ (y : b ⟢ b') β†’ `D a b ⟢ `D a b'
_==_ = Star (Sym _⟢_)
-- we want to prove confluence of _⟢_
-- but to do that we need to expand _==_, which needs confluence
--------------------------------------------------------------------------------------------------
-- Inverse d step based solution
--------------------------------------------------------------------------------------------------
module InverseBased where
-- Step with inverse d reduction
-- this doesn't matter when it is used in a symmetric transitive closure
data IStep : Relβ‚€ V where
aca : IStep (`A) (`C `A)
d : βˆ€ {a} β†’ IStep a (`D a a)
under-c : βˆ€ {a a'} β†’ (x : IStep a a') β†’ IStep (`C a) (`C a')
under-d : βˆ€ {a b a' b'} β†’ (x : IStep a a') β†’ (y : IStep b b') β†’ IStep (`D a b) (`D a' b')
Ξ΅ : βˆ€ {a} β†’ IStep a a
iunder-ds : βˆ€ {a b a' b'} β†’ (x : StarSym IStep a a') β†’ (y : StarSym IStep b b') β†’ StarSym IStep (`D a b) (`D a' b')
iunder-ds {a} {b} {a'} {b'} xs ys =
StarSym.map (\x β†’ under-d x Ξ΅) xs β—…β—…
StarSym.map (\y β†’ under-d Ξ΅ y) ys
iconfluent : Confluent IStep
iconfluent Ξ΅ u = u || Ξ΅
iconfluent x Ξ΅ = Ξ΅ || x
iconfluent x d = d || under-d x x
iconfluent d u = under-d u u || d
iconfluent aca aca = Ξ΅ || Ξ΅
iconfluent (under-c x) (under-c u) = CR.map under-c (iconfluent x u)
iconfluent (under-d x y) (under-d u v) = CR.zip under-d (iconfluent x u) (iconfluent y v)
a-to-is : _⟢_ β‡’ StarSym IStep
as-to-is : StarSym _⟢_ β‡’ StarSym IStep
a-to-is aca = fwd aca β—… Ξ΅
a-to-is (d₁ eq) = iunder-ds Ξ΅ (StarSym.sym $ as-to-is eq) β—…β—… bwd d β—… Ξ΅
a-to-is (dβ‚‚ eq) = iunder-ds (as-to-is eq) Ξ΅ β—…β—… bwd d β—… Ξ΅
a-to-is (under-c x) = StarSym.map under-c (a-to-is x)
a-to-is (under-d₁ x) = iunder-ds (a-to-is x) Ξ΅
a-to-is (under-dβ‚‚ x) = iunder-ds Ξ΅ (a-to-is x)
--as-to-is = StarSym.concatMap a-to-is -- doesn't pass termination checker
as-to-is Ξ΅ = Ξ΅
as-to-is (fwd x β—… xs) = a-to-is x β—…β—… as-to-is xs
as-to-is (bwd x β—… xs) = StarSym.sym (a-to-is x) β—…β—… as-to-is xs
i-to-as : IStep β‡’ StarSym _⟢_
i-to-as aca = fwd aca β—… Ξ΅
i-to-as d = bwd (d₁ Ξ΅) β—… Ξ΅
i-to-as (under-c x) = StarSym.map under-c (i-to-as x)
i-to-as (under-d x y) = StarSym.map under-d₁ (i-to-as x) β—…β—… StarSym.map under-dβ‚‚ (i-to-as y)
i-to-as Ξ΅ = Ξ΅
-- We can use IStep as a condition for steps
-- note that we only need d₁
data BStep : Relβ‚€ V where
aca : BStep (`A) (`C `A)
d₁ : βˆ€ {a b} β†’ StarSym IStep a b β†’ BStep (`D a b) a
under-c : βˆ€ {a a'} β†’ (x : BStep a a') β†’ BStep (`C a) (`C a')
under-d : βˆ€ {a b a' b'} β†’ (x : BStep a a') β†’ (y : BStep b b') β†’ BStep (`D a b) (`D a' b')
Ξ΅ : βˆ€ {a} β†’ BStep a a
bunder-ds : βˆ€ {a b a' b'} β†’ (x : Star BStep a a') β†’ (y : Star BStep b b') β†’ Star BStep (`D a b) (`D a' b')
bunder-ds {a} {b} {a'} {b'} xs ys =
Star.map (\x β†’ under-d {b = b} x Ξ΅) xs β—…β—…
Star.map (\y β†’ under-d {a = a'} Ξ΅ y) ys
b-to-is : BStep β‡’ StarSym IStep
b-to-is aca = fwd aca β—… Ξ΅
b-to-is (d₁ x) = StarSym.map (under-d Ξ΅) (StarSym.sym x) β—…β—… bwd d β—… Ξ΅
b-to-is (under-c x) = StarSym.map under-c (b-to-is x)
b-to-is (under-d {b' = b'} x y) = iunder-ds (b-to-is x) (b-to-is y)
b-to-is Ξ΅ = Ξ΅
bconfluent : Confluent BStep
bconfluent Ξ΅ u = u || Ξ΅
bconfluent x Ξ΅ = Ξ΅ || x
bconfluent aca aca = Ξ΅ || Ξ΅
bconfluent (under-c x) (under-c u) = CR.map under-c (bconfluent x u)
bconfluent (d₁ x) (d₁ u) = Ξ΅ || Ξ΅
bconfluent (d₁ x) (under-d u v) = u || d₁ (StarSym.sym (b-to-is u) β—…β—… x β—…β—… b-to-is v)
bconfluent (under-d x y) (d₁ u) = d₁ (StarSym.sym (b-to-is x) β—…β—… u β—…β—… b-to-is y) || x
bconfluent (under-d x y) (under-d u v) = CR.zip under-d (bconfluent x u) (bconfluent y v)
i-to-bs : IStep β‡’ CommonReduct (Star BStep)
i-to-bs aca = aca β—… Ξ΅ || Ξ΅
i-to-bs d = Ξ΅ || d₁ Ξ΅ β—… Ξ΅
i-to-bs (under-c x) with i-to-bs x
... | u || v = Star.map under-c u || Star.map under-c v
i-to-bs (under-d x y) with i-to-bs x | i-to-bs y
... | u || v | p || q = bunder-ds u p || bunder-ds v q
i-to-bs Ξ΅ = Ξ΅ || Ξ΅
is-to-bs : StarSym IStep β‡’ CommonReduct (Star BStep)
is-to-bs Ξ΅ = Ξ΅ || Ξ΅
is-to-bs (fwd ab β—… bc) with i-to-bs ab | is-to-bs bc
... | ad || bd | be || ce with Confluent-Star bconfluent bd be
... | df || ef = ad β—…β—… df || ce β—…β—… ef
is-to-bs (bwd ba β—… bc) with i-to-bs ba | is-to-bs bc
... | bd || ad | be || ce with Confluent-Star bconfluent bd be
... | df || ef = ad β—…β—… df || ce β—…β—… ef
b-to-as : BStep β‡’ Star _⟢_
b-to-as aca = aca β—… Ξ΅
b-to-as (d₁ x) = d₁ (StarSym.concatMap i-to-as x) β—… Ξ΅
b-to-as (under-c x) = Star.map under-c (b-to-as x)
b-to-as (under-d x y) = Star.map under-d₁ (b-to-as x) β—…β—… Star.map under-dβ‚‚ (b-to-as y)
b-to-as Ξ΅ = Ξ΅
aconfluent : GlobalConfluent _⟢_
aconfluent ab ac with is-to-bs (Star.concatMap a-to-is ab) | is-to-bs (Star.concatMap a-to-is ac)
... | ad || bd | ae || ce with Confluent-Star bconfluent ad ae
... | df || ef = Star.concatMap b-to-as (bd β—…β—… df) || Star.concatMap b-to-as (ce β—…β—… ef)
module 2013-12-20-relations where
open import Level hiding (zero;suc)
open import Function
open import Relation.Binary hiding (Sym)
open import Relation.Binary.PropositionalEquality as PE hiding (subst;sym;trans;refl)
open import Data.Empty
open import Data.Product using (βˆƒ)
open import Induction.WellFounded
--------------------------------------------------------------------------------
-- Utility
--------------------------------------------------------------------------------
Relβ‚€ : Set β†’ Set₁
Relβ‚€ A = Rel A Level.zero
Arrow : βˆ€ {a b} β†’ Set a β†’ Set b β†’ Set (a βŠ” b)
Arrow A B = A β†’ B
Any : βˆ€ {a b r} {A : Set a} {B : Set b} β†’ (A β†’ Rel B r) β†’ Rel B _
Any r u v = βˆƒ \x β†’ r x u v
--------------------------------------------------------------------------------
-- Transitive closure
--------------------------------------------------------------------------------
module Star where
open import Data.Star public renaming (map to map'; fold to foldr)
map : βˆ€ {i j t u} {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u} β†’
{f : I β†’ J} β†’ T =[ f ]β‡’ U β†’ Star T =[ f ]β‡’ Star U
map g xs = gmap _ g xs
concatMap : βˆ€ {i j t u}
{I : Set i} {J : Set j} {T : Rel I t} {U : Rel J u}
{f : I β†’ J} β†’ T =[ f ]β‡’ Star U β†’ Star T =[ f ]β‡’ Star U
concatMap g xs = kleisliStar _ g xs
foldMap : βˆ€ {i j t p} {I : Set i} {J : Set j} {T : Rel I t}
{f : I β†’ J} (P : Rel J p) β†’
Transitive P β†’ Reflexive P β†’ T =[ f ]β‡’ P β†’ Star T =[ f ]β‡’ P
foldMap {f = f} P t r g = gfold f P (\a b β†’ t (g a) b) r
fold : βˆ€ {a r} {A : Set a} {R : Rel A r} β†’ {f : A β†’ Set} β†’ (R =[ f ]β‡’ Arrow) β†’ (Star R =[ f ]β‡’ Arrow)
--fold {f = f} g = Data.Star.gfold f Arrow (\a b β†’ b ∘ g a) id
fold {f = f} g = foldMap {f = f} Arrow (\f g x β†’ g (f x)) id g
open Star public using (Star;_β—…_;_β—…β—…_;Ξ΅;_⋆)
--------------------------------------------------------------------------------
-- Non-Reflexive Transitive closure
--------------------------------------------------------------------------------
module Plus where
data Plus {l r} {A : Set l} (R : Rel A r) (a : A) (c : A) : Set (l βŠ” r) where
_β—…_ : βˆ€ {b} β†’ R a b β†’ Star R b c β†’ Plus R a c
plus-acc : βˆ€ {l} {A : Set l} {R : Rel A l} {x} β†’ Acc (flip R) x β†’ Acc (flip (Plus R)) x
plus-acc' : βˆ€ {l} {A : Set l} {R : Rel A l} {x y} β†’ Acc (flip R) x β†’ Plus R x y β†’ Acc (flip (Plus R)) y
star-acc' : βˆ€ {l} {A : Set l} {R : Rel A l} {x y} β†’ Acc (flip R) x β†’ Star R x y β†’ Acc (flip (Plus R)) y
plus-acc a = acc (\_ β†’ plus-acc' a)
plus-acc' (acc a) (ab β—… bc) = star-acc' (a _ ab) bc
star-acc' a Ξ΅ = plus-acc a
star-acc' (acc a) (ab β—… bc) = star-acc' (a _ ab) bc
well-founded : βˆ€ {l} {A : Set l} {R : Rel A l} β†’ Well-founded (flip R) β†’ Well-founded (flip (Plus R))
well-founded wf = plus-acc ∘ wf
open Plus public using (Plus;_β—…_)
--------------------------------------------------------------------------------
-- Reflexive closure
--------------------------------------------------------------------------------
-- reflexive closure
module Refl where
data Refl {l r} {A : Set l} (R : Rel A r) (a : A) : A β†’ Set (l βŠ” r) where
Ξ΅ : Refl R a a
_β—…Ξ΅ : βˆ€ {b} β†’ R a b β†’ Refl R a b
_?β—…_ : βˆ€ {l r} {A : Set l} {R : Rel A r} {x y z : A} β†’ Refl R x y β†’ Star R y z β†’ Star R x z
Ξ΅ ?β—… yz = yz
xy β—…Ξ΅ ?β—… yz = xy β—… yz
map : βˆ€ {la lb r s} {A : Set la} {B : Set lb} {R : Rel A r} {S : Rel B s}
β†’ {f : A β†’ B}
β†’ (βˆ€ {a b} β†’ R a b β†’ S (f a) (f b))
β†’ βˆ€ {a b} β†’ Refl R a b β†’ Refl S (f a) (f b)
map g Ξ΅ = Ξ΅
map g (x β—…Ξ΅) = g x β—…Ξ΅
fromRefl : βˆ€ {a A r} {R : Rel {a} A r} β†’ Reflexive R β†’ Refl R β‡’ R
fromRefl refl Ξ΅ = refl
fromRefl refl (x β—…Ξ΅) = x
open Refl public hiding (module Refl;map)
--------------------------------------------------------------------------------
-- Symmetric closure
--------------------------------------------------------------------------------
module Sym where
data CoSym {l r s} {A : Set l} (R : Rel A r) (S : Rel A s) (a : A) : A β†’ Set (l βŠ” r βŠ” s) where
fwd : βˆ€ {b} β†’ R a b β†’ CoSym R S a b
bwd : βˆ€ {b} β†’ S b a β†’ CoSym R S a b
Sym : βˆ€ {l r} {A : Set l} (R : Rel A r) (a : A) β†’ A β†’ Set (l βŠ” r)
Sym R = CoSym R R
sym : βˆ€ {l r} {A : Set l} {R : Rel A r} {a b : A} β†’ Sym R a b β†’ Sym R b a
sym (fwd x) = bwd x
sym (bwd x) = fwd x
map : βˆ€ {la lb r s} {A : Set la} {B : Set lb} {R : Rel A r} {S : Rel B s}
β†’ {f : A β†’ B}
β†’ (βˆ€ {a b} β†’ R a b β†’ S (f a) (f b))
β†’ βˆ€ {a b} β†’ Sym R a b β†’ Sym S (f a) (f b)
map g (fwd x) = fwd (g x)
map g (bwd x) = bwd (g x)
open Sym public hiding (map;sym)
--------------------------------------------------------------------------------
-- Symmetric-transitive closure
--------------------------------------------------------------------------------
module StarSym where
StarSym : βˆ€ {l r} {A : Set l} (R : Rel A r) β†’ Rel A (l βŠ” r)
StarSym R = Star (Sym R)
map : βˆ€ {la lb r s} {A : Set la} {B : Set lb} {R : Rel A r} {S : Rel B s}
β†’ {f : A β†’ B}
β†’ (βˆ€ {a b} β†’ R a b β†’ S (f a) (f b))
β†’ βˆ€ {a b} β†’ StarSym R a b β†’ StarSym S (f a) (f b)
map g = Star.map (Sym.map g)
sym : βˆ€ {l r A R} β†’ StarSym {l} {r} {A} R β‡’ flip (StarSym R)
sym = Star.reverse Sym.sym
into : βˆ€ {l r A R} β†’ Sym (Star R) β‡’ StarSym {l} {r} {A} R
into (fwd xs) = Star.map fwd xs
into (bwd xs) = Star.reverse bwd xs
symInto : βˆ€ {l r A R} β†’ Sym (StarSym R) β‡’ StarSym {l} {r} {A} R
symInto (fwd xs) = xs
symInto (bwd xs) = sym xs
concat : βˆ€ {l r A R} β†’ StarSym (StarSym {l} {r} {A} R) β‡’ StarSym R
concat = Star.concat ∘ Star.map symInto
concatMap : βˆ€ {la lb r s} {A : Set la} {B : Set lb} {R : Rel A r} {S : Rel B s}
β†’ {f : A β†’ B}
β†’ (βˆ€ {a b} β†’ R a b β†’ StarSym S (f a) (f b))
β†’ βˆ€ {a b} β†’ StarSym R a b β†’ StarSym S (f a) (f b)
concatMap g = Star.concat ∘ Star.map (symInto ∘ Sym.map g)
concatMap' : βˆ€ {la lb r s} {A : Set la} {B : Set lb} {R : Rel A r} {S : Rel B s}
β†’ {f : A β†’ B}
β†’ (βˆ€ {a b} β†’ R a b β†’ Star S (f a) (f b))
β†’ βˆ€ {a b} β†’ StarSym R a b β†’ StarSym S (f a) (f b)
concatMap' g = Star.concat ∘ Star.map (into ∘ Sym.map g)
open StarSym public using (StarSym)
--------------------------------------------------------------------------------------------------
-- Relations
--------------------------------------------------------------------------------------------------
module Relations where
-- Here are some lemmas about confluence
-- First the generic stuff
infix 3 _||_
record CommonReduct' {la lb lc r s} {A : Set la} {B : Set lb} {C : Set lc}
(R : REL A C r) (S : REL B C s)
(a : A) (b : B) : Set (la βŠ” lb βŠ” lc βŠ” r βŠ” s) where
constructor _||_
field {c} : C
field reduce₁ : R a c
field reduceβ‚‚ : S b c
module CommonReduct where
CommonReduct : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Rel A (a βŠ” r)
CommonReduct R = CommonReduct' R R
maps : βˆ€ {a b c d e f r s t u} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {E : Set e} {F : Set f}
{R : REL A C r} {S : REL B C s} {T : REL D F t} {U : REL E F u}
{f : A β†’ D} {g : B β†’ E} {h : C β†’ F}
β†’ (βˆ€ {u v} β†’ R u v β†’ T (f u) (h v))
β†’ (βˆ€ {u v} β†’ S u v β†’ U (g u) (h v))
β†’ (βˆ€ {u v} β†’ CommonReduct' R S u v β†’ CommonReduct' T U (f u) (g v))
maps f g (u || v) = f u || g v
map : βˆ€ {a b r s} {A : Set a} {B : Set b} {R : Rel A r} {S : Rel B s}
β†’ {f : A β†’ B}
β†’ (R =[ f ]β‡’ S) β†’ (CommonReduct R =[ f ]β‡’ CommonReduct S)
map g (u || v) = g u || g v
zip : βˆ€ {a b c r s t} {A : Set a} {B : Set b} {C : Set c} {R : Rel A r} {S : Rel B s} {T : Rel C t}
β†’ {f : A β†’ B β†’ C}
β†’ (f Preservesβ‚‚ R ⟢ S ⟢ T)
β†’ (f Preservesβ‚‚ CommonReduct R ⟢ CommonReduct S ⟢ CommonReduct T)
zip f (ac || bc) (df || ef) = f ac df || f bc ef
swap : βˆ€ {a r} {A : Set a} {R S : Rel A r}
β†’ βˆ€ {x y} β†’ CommonReduct' R S x y β†’ CommonReduct' S R y x
swap (u || v) = v || u
open CommonReduct public using (CommonReduct)
module CR = CommonReduct
GenConfluent : βˆ€ {a r s t u} {A : Set a} (R : Rel A r) (S : Rel A s) (T : Rel A t) (U : Rel A u)
β†’ Set (a βŠ” r βŠ” s βŠ” t βŠ” u)
GenConfluent R S T U = βˆ€ {a b c} β†’ R a b β†’ S a c β†’ CommonReduct' T U b c
-- With two relations
CoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
CoConfluent R S = GenConfluent R S S R
SemiCoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
SemiCoConfluent R S = GenConfluent R (Star S) (Star S) (Star R)
HalfCoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
HalfCoConfluent R S = GenConfluent R S (Star S) R
StrongCoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
StrongCoConfluent R S = GenConfluent R (Star S) (Star S) (Refl R)
StrongerCoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
StrongerCoConfluent R S = GenConfluent R (Star S) (Star S) R
ReflCoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
ReflCoConfluent R S = GenConfluent R S (Refl S) (Refl R)
GlobalCoConfluent : βˆ€ {a r s} {A : Set a} (R : Rel A r) (S : Rel A s) β†’ Set (a βŠ” r βŠ” s)
GlobalCoConfluent R S = CoConfluent (Star R) (Star S)
-- Now with a single relation
Confluent : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Set (a βŠ” r)
Confluent R = GenConfluent R R R R
LocalConfluent : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Set (a βŠ” r)
LocalConfluent R = GenConfluent R R (Star R) (Star R)
ReflConfluent : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Set (a βŠ” r)
ReflConfluent R = GenConfluent R R (Refl R) (Refl R)
SemiConfluent : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Set (a βŠ” r)
SemiConfluent R = GenConfluent R (Star R) (Star R) (Star R)
GlobalConfluent : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Set (a βŠ” r)
GlobalConfluent R = Confluent (Star R)
--StrongConfluent : βˆ€ {a r} {A : Set a} (R : Rel A r) β†’ Set (a βŠ” r)
--StrongConfluent R = GenConfluent R R (Star R) (MaybeRel R)
-- semi confluence implies confluence for R*
SemiConfluent-to-GlobalConfluent : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ SemiCoConfluent R S β†’ GlobalCoConfluent R S
SemiConfluent-to-GlobalConfluent conf Ξ΅ ab = ab || Ξ΅
SemiConfluent-to-GlobalConfluent conf ab Ξ΅ = Ξ΅ || ab
SemiConfluent-to-GlobalConfluent conf (ab β—… bc) ad with conf ab ad
... | be || de with SemiConfluent-to-GlobalConfluent conf bc be
... | cf || ef = cf || (de β—…β—… ef)
Confluent-to-StrongConfluent : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ CoConfluent R S β†’ StrongCoConfluent R S
Confluent-to-StrongConfluent conf ab Ξ΅ = Ξ΅ || (ab β—…Ξ΅)
Confluent-to-StrongConfluent conf ab (ac β—… cd) with conf ab ac
... | be || ce with Confluent-to-StrongConfluent conf ce cd
... | ef || df = be β—… ef || df
Confluent-to-StrongerConfluent : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ CoConfluent R S β†’ StrongerCoConfluent R S
Confluent-to-StrongerConfluent conf ab Ξ΅ = Ξ΅ || ab
Confluent-to-StrongerConfluent conf ab (ac β—… cd) with conf ab ac
... | be || ce with Confluent-to-StrongerConfluent conf ce cd
... | ef || df = be β—… ef || df
HalfConfluent-to-StrongerConfluent : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ HalfCoConfluent R S β†’ StrongerCoConfluent R S
HalfConfluent-to-StrongerConfluent conf ab Ξ΅ = Ξ΅ || ab
HalfConfluent-to-StrongerConfluent conf ab (ac β—… cd) with conf ab ac
... | be || ce with HalfConfluent-to-StrongerConfluent conf ce cd
... | ef || df = be β—…β—… ef || df
-- note: could be weakened to require StrongConfluent
Confluent-to-SemiConfluent : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ CoConfluent R S β†’ SemiCoConfluent R S
Confluent-to-SemiConfluent conf ab Ξ΅ = Ξ΅ || (ab β—… Ξ΅)
Confluent-to-SemiConfluent conf ab (ac β—… cd) with conf ab ac
... | be || ce with Confluent-to-SemiConfluent conf ce cd
... | ef || df = be β—… ef || df
ReflConfluent-to-SemiConfluent : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ ReflCoConfluent R S β†’ SemiCoConfluent R S
ReflConfluent-to-SemiConfluent conf ab Ξ΅ = Ξ΅ || (ab β—… Ξ΅)
ReflConfluent-to-SemiConfluent conf ab (ac β—… cd) with conf ab ac
... | be || Ξ΅ = be ?β—… cd || Ξ΅
... | be || ce β—…Ξ΅ with ReflConfluent-to-SemiConfluent conf ce cd
... | ef || df = be ?β—… ef || df
Confluent-Star : βˆ€ {a r s A} {R : Rel {a} A r} {S : Rel {a} A s} β†’ CoConfluent R S β†’ GlobalCoConfluent R S
Confluent-Star = SemiConfluent-to-GlobalConfluent ∘ Confluent-to-SemiConfluent
from-StarSym : βˆ€ {a r A} {R : Rel {a} A r} β†’ GlobalConfluent R β†’ Star (Sym R) β‡’ CommonReduct (Star R)
from-StarSym conf Ξ΅ = Ξ΅ || Ξ΅
from-StarSym conf (fwd ab β—… bc) with from-StarSym conf bc
... | bd || cd = ab β—… bd || cd
from-StarSym conf (bwd ba β—… bc) with from-StarSym conf bc
... | bd || cd with conf (ba β—… Ξ΅) bd
... | be || de = be || cd β—…β—… de
to-StarSym : βˆ€ {a r A} {R : Rel {a} A r} β†’ CommonReduct (Star R) β‡’ Star (Sym R)
to-StarSym (xs || ys) = Star.map fwd xs β—…β—… Star.reverse bwd ys
-- strong normalization + local confluence implies global confluence
-- we can write SN R as Well-founded (flip R)
well-founded-confluent : βˆ€ {a A} {R : Rel {a} A a} β†’ Well-founded (flip R) β†’ LocalConfluent R β†’ GlobalConfluent R
well-founded-confluent wf conf = acc-confluent conf (Plus.well-founded wf _)
where
acc-confluent : βˆ€ {a A} {R : Rel {a} A a} β†’ LocalConfluent R β†’ βˆ€ {a b c} β†’ Acc (flip (Plus R)) a β†’ Star R a b β†’ Star R a c β†’ CommonReduct (Star R) b c
acc-confluent conf _ Ξ΅ ac = ac || Ξ΅
acc-confluent conf _ ab Ξ΅ = Ξ΅ || ab
acc-confluent conf (acc a) (ab β—… bc) (ad β—… de) with conf ab ad
... | bf || df with acc-confluent conf (a _ (ab β—… Ξ΅)) bc bf
... | cg || fg with acc-confluent conf (a _ (ad β—… Ξ΅)) de df
... | eh || fh with acc-confluent conf (a _ (ab β—… bf)) fg fh
... | gi || hi = cg β—…β—… gi || eh β—…β—… hi
confluent-by : βˆ€ {a A r s} {R : Rel {a} A r} {S : Rel A s}
β†’ (S β‡’ R) β†’ (R β‡’ S)
β†’ Confluent R β†’ Confluent S
confluent-by toR fromR confR ab ac = CR.map fromR (confR (toR ab) (toR ac))
open Relations public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment