|
2 | 2 | module Week8 where |
3 | 3 |
|
4 | 4 | open import Relation.Binary.PropositionalEquality |
5 | | - using (_≡_; refl; cong; sym; module ≡-Reasoning) |
| 5 | + using (_≡_; refl; cong; cong₂; sym; module ≡-Reasoning) |
6 | 6 |
|
7 | 7 | open import Function using (_∘′_; id) |
8 | 8 |
|
@@ -80,7 +80,6 @@ monoid-cat .then-assoc f g h = monHomEq _ _ refl |
80 | 80 | monoid-cat .then-identity f = monHomEq _ _ refl |
81 | 81 | monoid-cat .identity-then f = monHomEq _ _ refl |
82 | 82 |
|
83 | | - |
84 | 83 | open import Data.Unit.Base using (⊤) |
85 | 84 | {- |
86 | 85 |
|
@@ -111,10 +110,84 @@ module _ (C : Category) where |
111 | 110 |
|
112 | 111 | squish : ∀ {s t} → Path M s t → M s t |
113 | 112 | squish [] = C.identity |
| 113 | + squish (step ∷ []) = step |
114 | 114 | squish (step ∷ path) = step C.then squish path |
115 | 115 |
|
116 | 116 | squish-++ : ∀ {s m t} (p : Path M s m) (q : Path M m t) → |
117 | 117 | squish (p ++ q) ≡ squish p C.then squish q |
118 | | - squish-++ = {!!} |
| 118 | + squish-++ [] q = sym (C.identity-then (squish q)) |
| 119 | + squish-++ (step ∷ []) [] = sym (C.then-identity step) |
| 120 | + squish-++ (step ∷ []) (x ∷ q) = refl |
| 121 | + squish-++ (step ∷ (x ∷ p)) q = let open ≡-Reasoning in begin |
| 122 | + squish ((step ∷ (x ∷ p)) ++ q) |
| 123 | + ≡⟨⟩ |
| 124 | + step C.then squish ((x ∷ p) ++ q) |
| 125 | + ≡⟨ cong (step C.then_) (squish-++ (x ∷ p) q) ⟩ |
| 126 | + step C.then (squish (x ∷ p) C.then squish q) |
| 127 | + ≡⟨ sym (C.then-assoc _ _ _) ⟩ |
| 128 | + (step C.then squish (x ∷ p)) C.then squish q |
| 129 | + ≡⟨ refl ⟩ |
| 130 | + (squish (step ∷ (x ∷ p)) C.then squish q) |
| 131 | + ∎ |
| 132 | + |
119 | 133 |
|
120 | 134 | -- Proof by reflection |
| 135 | + |
| 136 | + |
| 137 | + infixr 5 _`then_ |
| 138 | + data Syntax (s : O) : O → Set where |
| 139 | + _`then_ : ∀ {m t} → Syntax s m → Syntax m t → Syntax s t |
| 140 | + `identity : Syntax s s |
| 141 | + `morphism : ∀ {t} → M s t → Syntax s t |
| 142 | +-- `Functor : |
| 143 | + |
| 144 | + |
| 145 | + ⟦_⟧ : ∀ {s t} → Syntax s t → M s t |
| 146 | + ⟦ synl `then synr ⟧ = ⟦ synl ⟧ C.then ⟦ synr ⟧ |
| 147 | + ⟦ `identity ⟧ = C.identity |
| 148 | + ⟦ `morphism f ⟧ = f |
| 149 | + |
| 150 | + _≋'_ : ∀ {s t} (f g : Syntax s t) → Set |
| 151 | + f ≋' g = ⟦ f ⟧ ≡ ⟦ g ⟧ |
| 152 | + |
| 153 | + normalise : ∀ {s t} → Syntax s t → Path M s t |
| 154 | + normalise (synl `then synr) |
| 155 | + = let norml = normalise synl in |
| 156 | + let normr = normalise synr in |
| 157 | + norml ++ normr |
| 158 | + normalise `identity = [] |
| 159 | + normalise (`morphism f) = f ∷ [] |
| 160 | + |
| 161 | + _≋_ : ∀ {s t} (f g : Syntax s t) → Set |
| 162 | + f ≋ g = squish (normalise f) ≡ squish (normalise g) |
| 163 | + |
| 164 | + correct : ∀ {s t} (f : Syntax s t) → ⟦ f ⟧ ≡ squish (normalise f) |
| 165 | + correct (f `then g) = let open ≡-Reasoning in begin |
| 166 | + ⟦ f `then g ⟧ |
| 167 | + ≡⟨⟩ |
| 168 | + (⟦ f ⟧ C.then ⟦ g ⟧) |
| 169 | + ≡⟨ cong₂ C._then_ (correct f) (correct g) ⟩ |
| 170 | + (squish (normalise f) C.then squish (normalise g)) |
| 171 | + ≡⟨ squish-++ (normalise f) (normalise g) ⟨ |
| 172 | + squish (normalise f ++ normalise g) |
| 173 | + ≡⟨⟩ |
| 174 | + squish (normalise (f `then g)) |
| 175 | + ∎ |
| 176 | + correct `identity = refl |
| 177 | + correct (`morphism f) = refl |
| 178 | + |
| 179 | + magic : ∀ {s t} (f g : Syntax s t) → |
| 180 | + f ≋ g → ⟦ f ⟧ ≡ ⟦ g ⟧ |
| 181 | + magic f g f≋g = let open ≡-Reasoning in begin |
| 182 | + ⟦ f ⟧ ≡⟨ correct f ⟩ |
| 183 | + squish (normalise f) ≡⟨ f≋g ⟩ |
| 184 | + squish (normalise g) ≡⟨ correct g ⟨ |
| 185 | + ⟦ g ⟧ ∎ |
| 186 | + |
| 187 | + _ : ∀ {s m₁ m₂ t} (f : M s m₁) (g : M m₁ m₂) (h : M m₂ t) → |
| 188 | + (`identity `then `morphism f `then `identity `then `morphism g `then `morphism h) |
| 189 | + ≋' ((`morphism f `then `morphism g) `then `morphism h) |
| 190 | + _ = λ f g h → magic |
| 191 | + (`identity `then `morphism f `then `identity `then `morphism g `then `morphism h) |
| 192 | + ((`morphism f `then `morphism g) `then `morphism h) |
| 193 | + refl |
0 commit comments