@@ -7,6 +7,7 @@ open import abstract-set-theory.Prelude hiding (id; _∘_; _⊗_; lookup; Dec;
77import abstract-set-theory.Prelude as P
88open import Data.Vec hiding (init)
99open import Data.Nat using (_+_)
10+ open import Relation.Binary
1011
1112-- M = id, Maybe, Powerset (relation), Giry (probability)
1213-- SFunType A B S = S × A → M (S × B)
@@ -45,6 +46,11 @@ record SFunⁱ (A B : Type) : Type where
4546 apply₁ : A → SFunⁱ A B
4647 apply₁ a = record { fun = λ as → tail (fun (a ∷ as)) ; take-fun = {!!} }
4748
49+ module _ where
50+ open SFunⁱ
51+ fun-∷ : ∀ {f : SFunⁱ A B} {a} {as : Vec A n} → fun f (a ∷ as) ≡ fun₁ f a ∷ fun (apply₁ f a) as
52+ fun-∷ = {!!}
53+
4854eval : SFunᵉ A B → SFunⁱ A B
4955eval f = let open SFunᵉ f in record { fun = trace fun init ; take-fun = take-trace }
5056
@@ -57,12 +63,58 @@ resume f = record
5763_≈ⁱ_ : SFunⁱ A B → SFunⁱ A B → Type
5864f ≈ⁱ g = let open SFunⁱ in ∀ {n} → fun f {n} ≗ fun g {n}
5965
60- open SFunⁱ
61- ≈ⁱ-ind : ∀ {f g : SFunⁱ A B} a → fun₁ f a ≡ fun₁ g a → apply₁ f a ≈ⁱ apply₁ g a → f ≈ⁱ g
62- ≈ⁱ-ind = {!!}
63-
6466_≈ᵉ_ : SFunᵉ A B → SFunᵉ A B → Type
6567f ≈ᵉ g = eval f ≈ⁱ eval g
6668
69+ eval∘resume≡id : ∀ {f : SFunⁱ A B} → eval (resume f) ≈ⁱ f
70+ eval∘resume≡id {f = f} [] with SFunⁱ.fun f []
71+ ... | [] = refl
72+ eval∘resume≡id {f = f} (a ∷ as) = begin
73+ head (fun f (a ∷ [])) ∷ fun (eval (resume (apply₁ f a))) as
74+ ≡⟨ cong (_ ∷_) (eval∘resume≡id as) ⟩
75+ fun₁ f a ∷ fun (apply₁ f a) as
76+ ≡⟨ sym (fun-∷ {f = f}) ⟩
77+ fun f (a ∷ as) ∎
78+ where open ≡-Reasoning
79+ open SFunⁱ
80+
6781resume∘eval≡id : ∀ {f : SFunᵉ A B} → resume (eval f) ≈ᵉ f
68- resume∘eval≡id {f = f} {n} as = {!!}
82+ resume∘eval≡id {f = f} {n} = eval∘resume≡id {f = eval f}
83+
84+ IsEquivalence-≈ⁱ : IsEquivalence (_≈ⁱ_ {A} {B})
85+ IsEquivalence-≈ⁱ = {!!}
86+
87+ IsEquivalence-≈ᵉ : IsEquivalence (_≈ᵉ_ {A} {B})
88+ IsEquivalence-≈ᵉ = {!!}
89+
90+ SFunⁱ-Setoid : (A B : Type) → Setoid ℓ0 ℓ0
91+ SFunⁱ-Setoid A B = record { Carrier = SFunⁱ A B ; _≈_ = _≈ⁱ_ ; isEquivalence = IsEquivalence-≈ⁱ }
92+
93+ SFunᵉ-Setoid : (A B : Type) → Setoid (sucˡ ℓ0) ℓ0
94+ SFunᵉ-Setoid A B = record { Carrier = SFunᵉ A B ; _≈_ = _≈ᵉ_ ; isEquivalence = IsEquivalence-≈ᵉ }
95+
96+ import Relation.Binary.Reasoning.Setoid as SetoidReasoning
97+
98+ Inverse-resume-eval : Inverse (SFunⁱ-Setoid A B) (SFunᵉ-Setoid A B)
99+ Inverse-resume-eval {A} {B} = record { to = resume ; from = eval ; Go }
100+ where
101+ open SetoidReasoning (SFunⁱ-Setoid A B)
102+ module Go where
103+ to-cong : Congruent _≈ⁱ_ _≈ᵉ_ resume
104+ to-cong {x} {y} x≈y = begin
105+ eval (resume x) ≈⟨ eval∘resume≡id ⟩ x ≈⟨ x≈y ⟩ y ≈⟨ eval∘resume≡id ⟨ eval (resume y) ∎
106+ from-cong : Congruent _≈ᵉ_ _≈ⁱ_ eval
107+ from-cong f≈g = f≈g
108+ inverse : Inverseᵇ _≈ⁱ_ _≈ᵉ_ resume eval
109+ inverse = (λ {x} {y} y≈eval[x] → begin
110+ eval (resume y)
111+ ≈⟨ from-cong (to-cong y≈eval[x]) ⟩
112+ eval (resume (eval x))
113+ ≈⟨ resume∘eval≡id ⟩
114+ eval x ∎)
115+ , λ {x} {y} y≈resume[x] → begin
116+ eval y
117+ ≈⟨ from-cong y≈resume[x] ⟩
118+ eval (resume x)
119+ ≈⟨ eval∘resume≡id ⟩
120+ x ∎
0 commit comments