Skip to content

Commit 6b55dc5

Browse files
authored
Added properties of the delay monad termination proof (#1268)
1 parent d5c3bac commit 6b55dc5

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,16 @@ Other minor additions
442442
id-⟶ : A ⟶ A
443443
```
444444

445+
* Added new proofs to `Codata.Delay.Properties`:
446+
```agda
447+
⇓-unique : (d⇓₁ : d ⇓) (d⇓₂ : d ⇓) → d⇓₁ ≡ d⇓₂
448+
bind̅₁ : bind d f ⇓ → d ⇓
449+
bind̅₂ : (bind⇓ : bind d f ⇓) → f (extract (bind̅₁ bind⇓)) ⇓
450+
extract-bind-⇓ : (d⇓ : d ⇓) (f⇓ : f (extract d⇓) ⇓) → extract (bind-⇓ d⇓ f⇓) ≡ extract f⇓
451+
extract-bind̅₂-bind⇓ : (bind⇓ : bind d f ⇓) → extract (bind̅₂ d bind⇓) ≡ extract bind⇓
452+
bind⇓-length : (bind⇓ : bind d f ⇓) (d⇓ : d ⇓) (f⇓ : f (extract d⇓) ⇓) → toℕ (length-⇓ bind⇓) ≡ toℕ (length-⇓ d⇓) ℕ.+ toℕ (length-⇓ f⇓)
453+
```
454+
445455
* Added new function to `Data.List.Base`:
446456
```agda
447457
linesBy : Decidable P → List A → List (List A)

src/Codata/Delay/Properties.agda

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Codata.Delay.Properties where
1010

1111
open import Size
1212
import Data.Sum.Base as Sum
13+
import Data.Nat as ℕ
1314
open import Codata.Thunk using (Thunk; force)
1415
open import Codata.Conat
1516
open import Codata.Conat.Bisimilarity as Coℕ using (zero ; suc)
@@ -48,3 +49,59 @@ module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
4849
map-unfold-fusion f n s with n s
4950
... | Sum.inj₁ s′ = later λ where .force map-unfold-fusion f n s′
5051
... | Sum.inj₂ b = now Eq.refl
52+
53+
54+
------------------------------------------------------------------------
55+
-- ⇓
56+
57+
⇓-unique : {a} {A : Set a}
58+
{d : Delay A ∞}
59+
(d⇓₁ : d ⇓) (d⇓₂ : d ⇓)
60+
d⇓₁ ≡ d⇓₂
61+
⇓-unique {d = now s} (now s) (now s) = Eq.refl
62+
⇓-unique {d = later d'} (later l) (later r) =
63+
Eq.cong later (⇓-unique {d = force d'} l r)
64+
65+
module _ {a} {A B : Set a} where
66+
67+
bind̅₁ : (d : Delay A ∞) {f : A Delay B ∞} bind d f ⇓ d ⇓
68+
bind̅₁ (now s) _ = now s
69+
bind̅₁ (later s) (later x) =
70+
later (bind̅₁ (force s) x)
71+
72+
bind̅₂ : (d : Delay A ∞) {f : A Delay B ∞}
73+
(bind⇓ : bind d f ⇓)
74+
f (extract (bind̅₁ d bind⇓)) ⇓
75+
bind̅₂ (now s) foo = foo
76+
bind̅₂ (later s) {f} (later foo) =
77+
bind̅₂ (force s) foo
78+
79+
-- The extracted value of a bind is equivalent to the extracted value of its
80+
-- second element
81+
extract-bind-⇓ : {d : Delay A Size.∞} {f : A Delay B Size.∞}
82+
(d⇓ : d ⇓) (f⇓ : f (extract d⇓) ⇓)
83+
extract (bind-⇓ d⇓ {f} f⇓) ≡ extract f⇓
84+
extract-bind-⇓ (now a) f⇓ = Eq.refl
85+
extract-bind-⇓ (later t) f⇓ = extract-bind-⇓ t f⇓
86+
87+
-- If the right element of a bind returns a certain value so does the entire
88+
-- bind
89+
extract-bind̅₂-bind⇓ :
90+
(d : Delay A ∞) {f : A Delay B ∞}
91+
(bind⇓ : bind d f ⇓)
92+
extract (bind̅₂ d bind⇓) ≡ extract bind⇓
93+
extract-bind̅₂-bind⇓ (now s) bind⇓ = Eq.refl
94+
extract-bind̅₂-bind⇓ (later s) (later bind⇓) =
95+
extract-bind̅₂-bind⇓ (force s) bind⇓
96+
97+
-- Proof that the length of a bind-⇓ is equal to the sum of the length of its
98+
-- components.
99+
bind⇓-length :
100+
{d : Delay A ∞} {f : A Delay B ∞}
101+
(bind⇓ : bind d f ⇓)
102+
(d⇓ : d ⇓) (f⇓ : f (extract d⇓) ⇓)
103+
toℕ (length-⇓ bind⇓) ≡ toℕ (length-⇓ d⇓) ℕ.+ toℕ (length-⇓ f⇓)
104+
bind⇓-length {f = f} bind⇓ d⇓@(now s') f⇓ =
105+
Eq.cong (toℕ ∘ length-⇓) (⇓-unique bind⇓ f⇓)
106+
bind⇓-length {d = d@(later dt)} {f = f} bind⇓@(later bind'⇓) d⇓@(later r) f⇓ =
107+
Eq.cong ℕ.suc (bind⇓-length bind'⇓ r f⇓)

0 commit comments

Comments
 (0)