Skip to content

Commit 68ab179

Browse files
committed
[ done ] for this week
1 parent 521eb3c commit 68ab179

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

lectures/Week8.agda

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module Week8 where
33

44
open import Relation.Binary.PropositionalEquality
5-
using (_≡_; refl; cong; sym; module ≡-Reasoning)
5+
using (_≡_; refl; cong; cong₂; sym; module ≡-Reasoning)
66

77
open import Function using (_∘′_; id)
88

@@ -80,7 +80,6 @@ monoid-cat .then-assoc f g h = monHomEq _ _ refl
8080
monoid-cat .then-identity f = monHomEq _ _ refl
8181
monoid-cat .identity-then f = monHomEq _ _ refl
8282

83-
8483
open import Data.Unit.Base using (⊤)
8584
{-
8685
@@ -111,10 +110,84 @@ module _ (C : Category) where
111110

112111
squish : {s t} Path M s t M s t
113112
squish [] = C.identity
113+
squish (step ∷ []) = step
114114
squish (step ∷ path) = step C.then squish path
115115

116116
squish-++ : {s m t} (p : Path M s m) (q : Path M m t)
117117
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+
119133

120134
-- 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

Comments
 (0)