Finish subproof

This commit is contained in:
Leon Vatthauer 2024-01-10 17:46:55 +01:00
parent a6fd66ef29
commit 202d130d33
Signed by: leonv
SSH key fingerprint: SHA256:G4+ddwoZmhLPRB1agvXzZMXIzkVJ36dUYZXf5NxT+u8
2 changed files with 35 additions and 33 deletions

View file

@ -246,6 +246,13 @@ module DelayMonad where
-cong {.(now _)} {.(now _)} (now x≡y) = now-cong (cong f x≡y)
-cong {.(later _)} {.(later _)} (later xy) = later (-cong xy)
lift-comp : ∀ {A B C : Setoid c (c ⊔ )} {f : A ⟶ B} {g : B ⟶ C} {x y : Delay A } → [ A ][ x y ] → [ C ][ liftFₛ (g ∘ f) ⟨$⟩ x (liftFₛ g ∘ liftFₛ f) ⟨$⟩ y ]
lift-comp : ∀ {A B C : Setoid c (c ⊔ )} {f : A ⟶ B} {g : B ⟶ C} {x y : Delay A } → [ A ][ x y ] → [ C ][ liftFₛ (g ∘ f) ⟨$⟩ x (liftFₛ g ∘ liftFₛ f) ⟨$⟩ y ]
lift-comp {A} {B} {C} {f} {g} {.(now _)} {.(now _)} (now x≡y) = now-cong (cong g (cong f (x≡y)))
lift-comp {A} {B} {C} {f} {g} {.(later _)} {.(later _)} (later xy) = later (lift-comp {A} {B} {C} {f} {g} xy)
force (lift-comp {A} {B} {C} {f} {g} {x} {y} xy) = lift-comp {A} {B} {C} {f} {g} {x} {y} (force xy)
-- this needs polymorphic universe levels
_≋_ : ∀ {c' '} {A B : Setoid c' '} → A ⟶ B → A ⟶ B → Set (c' ⊔ ')
_≋_ {c'} {'} {A} {B} f g = Setoid._≈_ (A ⇨ B) f g
@ -360,6 +367,12 @@ module DelayMonad where
identityˡ↓ {A} {now x} {y} x↓y = x↓y
identityˡ↓ {A} {later x} {y} (later↓ x↓y) = later↓ (identityˡ↓ x↓y)
identityˡ : ∀ {A : Setoid c (c ⊔ )} {x y : Delay A } → [ A ][ x y ] → [ A ][ (μₛ A ∘ liftFₛ (ηₛ A)) ⟨$⟩ x y ]
identityˡ : ∀ {A : Setoid c (c ⊔ )} {x y : Delay A } → [ A ][ x y ] → [ A ][ (μₛ A ∘ liftFₛ (ηₛ A)) ⟨$⟩ x y ]
identityˡ {A} {.(now _)} {.(now _)} (now x≡y) = now-cong x≡y
identityˡ {A} {.(later _)} {.(later _)} (later xy) = later (identityˡ {A} xy)
force (identityˡ {A} {x} {y} xy) = identityˡ (force xy)
identityˡ : ∀ {A : Setoid c (c ⊔ )} → (μₛ A ∘ liftFₛ (ηₛ A)) ≋ idₛ
identityˡ : ∀ {A : Setoid c (c ⊔ )} {x y : Delay A } → [ A ][ x ≈′ y ] → [ A ][ (μₛ A ∘ liftFₛ (ηₛ A)) ⟨$⟩ x ≈′ y ]
force≈ (identityˡ {A} {x} {y} x≈y) = identityˡ (force≈ x≈y)

View file

@ -1,7 +1,7 @@
<!--
```agda
{-# OPTIONS --allow-unsolved-metas --guardedness #-}
open import Level
open import Level renaming (zero to -zero; suc to -suc)
open import Relation.Binary
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]; [_,_])
open import Data.Sum.Function.Setoid
@ -211,50 +211,39 @@ module Monad.Instance.Setoids.K' { : Level} where
helper#≈-cong' {z} = ≡-trans ⟦ B ⟧ (≡-sym ⟦ B ⟧ eq₁) eq₂
where
helper₁' : Delay ( A × {}) → ⟦ B ⟧ ⊎ Delay ( A × )
outer : A ⟶ A ×ₛ -setoid {}
outer = record { _⟨$⟩_ = λ z → z , zero ; cong = λ {x} {y} x≡y → x≡y , ≣-refl }
zero-helper : Delayₛ' A ⟶ Delayₛ' (A ×ₛ -setoid {})
zero-helper = liftFₛ outer
ι-cancel : ∀ {x} → [ A ][ (ι ∘′ (λ z → z , zero)) x now x ]
ι-cancel = -refl A
helper₁' : Delay ( A × {}) → ⟦ B ⟧ ⊎ Delay ( A × {})
helper₁' (now (x , zero)) = inj₁ (< f > x)
helper₁' (now (x , suc n)) with helper₁' (now (x , n))
... | inj₁ r = inj₁ r
... | inj₂ y = inj₂ (later (record { force = y }))
helper₁' (now (x , suc n)) = inj₂ (< zero-helper > (ι {A} (x , n)))
helper₁' (later y) = inj₂ (force y)
helper₁-cong' : {x y : Delay ( A × {})} → (xy : [ A ×ₛ -setoid ][ x y ]) → [ ⟦ B ⟧ ⊎ₛ Delayₛ' (A ×ₛ -setoid) ][ helper₁' x ≡ helper₁' y ]
helper₁-cong' {now (x , zero)} (now (x≡y , ≣-refl)) = inj₁ (cong f x≡y)
helper₁-cong' {now (x , suc n)} {now (y , suc _)} (now (x≡y , ≣-refl)) with helper₁' (now (x , n)) | helper₁' (now (y , n)) | helper₁-cong' {now (x , n)} (now (x≡y , ≣-refl))
... | inj₁ r | inj₁ s | inj₁ r≡s = inj₁ r≡s
... | inj₂ x' | inj₂ y' | inj₂ x'y' = inj₂ (later (record { force = x'y' }))
helper₁-cong' (later x≡y) = inj₂ (force x≡y)
helper₁-cong' {now (x , suc n)} {now (y , suc _)} (now (x≡y , ≣-refl)) = inj₂ (cong zero-helper (cong ιₛ' (x≡y , ≣-refl)))
helper₁-cong' (later xy) = inj₂ (force xy)
helper' : Delayₛ' (A ×ₛ -setoid) ⟶ ⟦ B ⟧ ⊎ₛ Delayₛ' (A ×ₛ -setoid)
helper' = record { _⟨$⟩_ = helper₁' ; cong = helper₁-cong'}
-- Should follow by compositionality + fixpoint
eq₁ : [ ⟦ B ⟧ ][ (B Elgot-Algebra.#) helper' ⟨$⟩ z ≡ (B Elgot-Algebra.#) helper ⟨$⟩ liftF proj₁ z ]
eq₁ = {! !}
-- eq : ∀ {x y} → [ A ×ₛ -setoid ][ x y ] → [ ⟦ B ⟧ ⊎ₛ Delayₛ' A ][ [ inj₁ , inj₂ ∘′ μ ∘′ (liftF ι) ] (helper₁' x) ≡ (helper₁ ∘′ μ ∘′ (liftF ι)) y ]
-- eq {now (x , zero)} {now (y , zero)} (now (x≡y , _)) = cong (inj₁ₛ {_} {_} {_} {_} {⟦ B ⟧} {Delayₛ' A}) (cong f x≡y)
-- eq {now (x , suc n)} {now (y , suc m)} (now (x≡y , n≡m)) with helper₁' (now (x , n)) in eqr
-- ... | inj₁ r = {! eq {now (x , n)} {now (y , m)} !} -- problem: recursive call to eq does not pass termination checker
-- where
-- help : [ ⟦ B ⟧ ⊎ₛ Delayₛ' A ][ [ inj₁ , inj₂ ∘′ μ ∘′ (liftF ι) ] (helper₁' (now (x , n))) ≡ inj₁ r ]
-- help = cong [ inj₁ₛ , (inj₂ₛ ∘ μₛ∼ A ∘ liftFₛ ιₛ') ]ₛ (≡→≡ eqr)
-- ... | inj₂ r = {! !}
-- eq {.(later _)} {.(later _)} (later x≡y) = cong (inj₂ₛ {_} {_} {_} {_} {⟦ B ⟧} {Delayₛ' A}) (cong (μₛ∼ A) (cong (liftFₛ ιₛ') (force x≡y)))
eq₁ : ∀ {z} → [ ⟦ B ⟧ ][ (B Elgot-Algebra.#) helper' ⟨$⟩ z ≡ (B Elgot-Algebra.#) helper ⟨$⟩ liftF proj₁ z ]
eq₁ {now (x , n)} = {! !}
eq₁ {later p} = {! !}
eq : ∀ {x y} → [ A ×ₛ -setoid ][ x y ] → [ ⟦ B ⟧ ⊎ₛ Delayₛ' A ][ [ inj₁ , inj₂ ∘′ μ ∘′ (liftF ι) ] (helper₁' x) ≡ (helper₁ ∘′ μ ∘′ (liftF ι)) y ]
eq {now (x , n)} {now (y , m)} (now pq) = eq' {n} {m} {x} {y} (now pq)
eq {now (x , n)} {now (y , .n)} (now (xy , ≣-refl)) = eq'
where
eq' : ∀ {n m x y} → [ A ×ₛ -setoid ][ now (x , n) now (y , m) ] → [ ⟦ B ⟧ ⊎ₛ Delayₛ' A ][ [ inj₁ , inj₂ ∘′ μ ∘′ (liftF ι) ] (helper₁' (now (x , n))) ≡ (helper₁ ∘′ μ ∘′ (liftF ι)) (now (y , m)) ]
eq' {zero} {zero} {x} {y} (now (x≡y , _)) = cong (inj₁ₛ {_} {_} {_} {_} {⟦ B ⟧} {Delayₛ' A}) (cong f x≡y)
eq' {suc n} {suc m} {x} {y} (now (x≡y , sn≡sm)) with helper₁' (now (x , n)) in eqr
... | inj₁ r = ≡-trans (⟦ B ⟧ ⊎ₛ Delayₛ' A) (≡-sym (⟦ B ⟧ ⊎ₛ Delayₛ' A) help) (≡-trans (⟦ B ⟧ ⊎ₛ Delayₛ' A) (eq' {n} {m} {x} {y} (now (x≡y , suc-inj sn≡sm))) {! -should this be provable?- !})
where
help : [ ⟦ B ⟧ ⊎ₛ Delayₛ' A ][ [ inj₁ , inj₂ ∘′ μ ∘′ (liftF ι) ] (helper₁' (now (x , n))) ≡ inj₁ r ]
help = cong [ inj₁ₛ , (inj₂ₛ ∘ μₛ∼ A ∘ liftFₛ ιₛ') ]ₛ (≡→≡ eqr)
... | inj₂ r = {! !}
eq {.(later _)} {.(later _)} (later x≡y) = cong (inj₂ₛ {_} {_} {_} {_} {⟦ B ⟧} {Delayₛ' A}) (cong (μₛ∼ A) (cong (liftFₛ ιₛ') (force x≡y)))
eq' : ∀ {n} → [ ⟦ B ⟧ ⊎ₛ Delayₛ' A ][ [ inj₁ , inj₂ ∘′ μ ∘′ liftF ι ] (helper₁' (now (x , n))) ≡ (helper₁ ∘′ μ {A} ∘′ liftF ι) (now (y , n)) ]
eq' {zero} = inj₁ (cong f xy)
eq' {suc n} = inj₂ (-trans A (cong (μₛ∼ A) (-sym (Delayₛ' A) (lift-comp {f = outer} {g = ιₛ'} {ι (x , n)} (-refl A)))) (identityˡ (cong ιₛ' (xy , ≣-refl))))
eq (later xy) = inj₂ (cong (μₛ∼ A) (cong (liftFₛ ιₛ') (force xy)))
-- Should follow by uniformity
eq₂ : [ ⟦ B ⟧ ][ (B Elgot-Algebra.#) helper' ⟨$⟩ z ≡ (B Elgot-Algebra.#) helper ⟨$⟩ μ {A} (liftF (ι {A}) z)]