|
| 1 | +open import Mockingbird.Forest using (Forest) |
| 2 | + |
| 3 | +-- To Mock a Mockingbird |
| 4 | +module Mockingbird.Problems.Chapter09 {b ℓ} (forest : Forest {b} {ℓ}) where |
| 5 | + |
| 6 | +open import Data.Product using (_,_; proj₁; proj₂; ∃-syntax) |
| 7 | +open import Function using (_$_) |
| 8 | +open import Level using (_⊔_) |
| 9 | +open import Relation.Nullary using (¬_) |
| 10 | + |
| 11 | +open import Mockingbird.Forest.Birds forest |
| 12 | + |
| 13 | +open Forest forest |
| 14 | + |
| 15 | +module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ where |
| 16 | + problem₁ : ∀ A → ∃[ B ] A IsFondOf B |
| 17 | + problem₁ A = |
| 18 | + let C = A ∘ M |
| 19 | + |
| 20 | + isFond : A IsFondOf (C ∙ C) |
| 21 | + isFond = sym $ begin |
| 22 | + C ∙ C ≈⟨ isComposition A M C ⟩ |
| 23 | + A ∙ (M ∙ C) ≈⟨ ∙-congˡ (isMockingbird C) ⟩ |
| 24 | + A ∙ (C ∙ C) ∎ |
| 25 | + |
| 26 | + in (C ∙ C , isFond) |
| 27 | + |
| 28 | +module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ where |
| 29 | + problem₂ : ∃[ E ] IsEgocentric E |
| 30 | + problem₂ = |
| 31 | + let (E , isFond) = problem₁ M |
| 32 | + |
| 33 | + isEgocentric : IsEgocentric E |
| 34 | + isEgocentric = begin |
| 35 | + E ∙ E ≈˘⟨ isMockingbird E ⟩ |
| 36 | + M ∙ E ≈⟨ isFond ⟩ |
| 37 | + E ∎ |
| 38 | + |
| 39 | + in (E , isEgocentric) |
| 40 | + |
| 41 | +module _ ⦃ _ : HasComposition ⦄ (hasAgreeable : ∃[ A ] IsAgreeable A) where |
| 42 | + A = proj₁ hasAgreeable |
| 43 | + isAgreeable = proj₂ hasAgreeable |
| 44 | + |
| 45 | + problem₃ : ∀ B → ∃[ C ] B IsFondOf C |
| 46 | + problem₃ B = |
| 47 | + let D = B ∘ A |
| 48 | + (x , Ax≈Dx) = isAgreeable D |
| 49 | + |
| 50 | + isFond : B IsFondOf (A ∙ x) |
| 51 | + isFond = begin |
| 52 | + B ∙ (A ∙ x) ≈˘⟨ isComposition B A x ⟩ |
| 53 | + D ∙ x ≈˘⟨ Ax≈Dx ⟩ |
| 54 | + A ∙ x ∎ |
| 55 | + |
| 56 | + in (A ∙ x , isFond) |
| 57 | + |
| 58 | +-- Bonus question of Problem 3. |
| 59 | +C₂→HasAgreeable : ⦃ _ : HasMockingbird ⦄ → ∃[ A ] IsAgreeable A |
| 60 | +C₂→HasAgreeable = (M , λ B → (B , isMockingbird B)) |
| 61 | + |
| 62 | +module _ ⦃ _ : HasComposition ⦄ (A B C : Bird) (Cx≈A[Bx] : IsComposition A B C) where |
| 63 | + problem₄ : IsAgreeable C → IsAgreeable A |
| 64 | + problem₄ C-isAgreeable D = |
| 65 | + let E = D ∘ B |
| 66 | + (x , Cx≈Ex) = C-isAgreeable E |
| 67 | + |
| 68 | + agree : Agree A D (B ∙ x) |
| 69 | + agree = begin |
| 70 | + A ∙ (B ∙ x) ≈˘⟨ Cx≈A[Bx] x ⟩ |
| 71 | + C ∙ x ≈⟨ Cx≈Ex ⟩ |
| 72 | + E ∙ x ≈⟨ isComposition D B x ⟩ |
| 73 | + D ∙ (B ∙ x) ∎ |
| 74 | + |
| 75 | + in (B ∙ x , agree) |
| 76 | + |
| 77 | +module _ ⦃ _ : HasComposition ⦄ where |
| 78 | + problem₅ : ∀ A B C → ∃[ D ] (∀ x → D ∙ x ≈ A ∙ (B ∙ (C ∙ x))) |
| 79 | + problem₅ A B C = |
| 80 | + let E = B ∘ C |
| 81 | + D = A ∘ E |
| 82 | + in (D , λ x → trans (isComposition A E x) $ ∙-congˡ (isComposition B C x)) |
| 83 | + |
| 84 | +module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ where |
| 85 | + problem₆ : ∀ A B → Compatible A B |
| 86 | + problem₆ A B = |
| 87 | + let C = A ∘ B |
| 88 | + (y , Cy≈y) = problem₁ C |
| 89 | + x = B ∙ y |
| 90 | + in (x , y , trans (sym (isComposition A B y)) Cy≈y , refl) |
| 91 | + |
| 92 | +problem₇ : ∀ A → ∃[ B ] A IsFondOf B → IsHappy A |
| 93 | +problem₇ A (B , AB≈B) = (B , B , AB≈B , AB≈B) |
| 94 | +-- problem₇ : ∀ A → IsNormal A → IsHappy A |
| 95 | + |
| 96 | +module _ ⦃ _ : HasComposition ⦄ where |
| 97 | + problem₈ : ∃[ H ] IsHappy H → ∃[ N ] IsNormal N |
| 98 | + problem₈ (H , x , y , Hx≈y , Hy≈x) = |
| 99 | + let N = H ∘ H |
| 100 | + |
| 101 | + isFond : N IsFondOf x |
| 102 | + isFond = begin |
| 103 | + N ∙ x ≈⟨ isComposition H H x ⟩ |
| 104 | + H ∙ (H ∙ x) ≈⟨ ∙-congˡ Hx≈y ⟩ |
| 105 | + H ∙ y ≈⟨ Hy≈x ⟩ |
| 106 | + x ∎ |
| 107 | + |
| 108 | + in (N , x , isFond) |
| 109 | + |
| 110 | +module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasKestrel ⦄ where |
| 111 | + problem₉ : ∃[ A ] IsHopelesslyEgocentric A |
| 112 | + problem₉ = |
| 113 | + let (A , KA≈A) = problem₁ K |
| 114 | + |
| 115 | + isHopelesslyEgocentric : IsHopelesslyEgocentric A |
| 116 | + isHopelesslyEgocentric x = begin |
| 117 | + A ∙ x ≈˘⟨ ∙-congʳ KA≈A ⟩ |
| 118 | + (K ∙ A) ∙ x ≈⟨ isKestrel A x ⟩ |
| 119 | + A ∎ |
| 120 | + |
| 121 | + in (A , isHopelesslyEgocentric) |
| 122 | + |
| 123 | +problem₁₀ : ∀ x y → x IsFixatedOn y → x IsFondOf y |
| 124 | +problem₁₀ x y xz≈y = xz≈y y |
| 125 | + |
| 126 | +problem₁₁ : ∀ K → IsKestrel K → IsEgocentric K → IsHopelesslyEgocentric K |
| 127 | +problem₁₁ K isKestrel KK≈K x = begin |
| 128 | + K ∙ x ≈˘⟨ ∙-congʳ KK≈K ⟩ |
| 129 | + (K ∙ K) ∙ x ≈⟨ isKestrel K x ⟩ |
| 130 | + K ∎ |
| 131 | + |
| 132 | +problem₁₂ : ⦃ _ : HasKestrel ⦄ → ∀ x → IsEgocentric (K ∙ x) → K IsFondOf x |
| 133 | +problem₁₂ x [Kx][Kx]≈Kx = begin |
| 134 | + K ∙ x ≈˘⟨ [Kx][Kx]≈Kx ⟩ |
| 135 | + (K ∙ x) ∙ (K ∙ x) ≈⟨ isKestrel x (K ∙ x) ⟩ |
| 136 | + x ∎ |
| 137 | + |
| 138 | +problem₁₃ : ∀ A x y → IsHopelesslyEgocentric A → A ∙ x ≈ A ∙ y |
| 139 | +problem₁₃ A x y Az≈A = begin |
| 140 | + A ∙ x ≈⟨ Az≈A x ⟩ |
| 141 | + A ≈˘⟨ Az≈A y ⟩ |
| 142 | + A ∙ y ∎ |
| 143 | + |
| 144 | +problem₁₄ : ∀ A x y → IsHopelesslyEgocentric A → (A ∙ x) ∙ y ≈ A |
| 145 | +problem₁₄ A x y Az≈A = begin |
| 146 | + (A ∙ x) ∙ y ≈⟨ ∙-congʳ (Az≈A x) ⟩ |
| 147 | + A ∙ y ≈⟨ Az≈A y ⟩ |
| 148 | + A ∎ |
| 149 | + |
| 150 | +problem₁₅ : ∀ A x → IsHopelesslyEgocentric A → IsHopelesslyEgocentric (A ∙ x) |
| 151 | +problem₁₅ A x Az≈A y = begin |
| 152 | + (A ∙ x) ∙ y ≈⟨ ∙-congʳ (Az≈A x) ⟩ |
| 153 | + A ∙ y ≈⟨ Az≈A y ⟩ |
| 154 | + A ≈˘⟨ Az≈A x ⟩ |
| 155 | + A ∙ x ∎ |
| 156 | + |
| 157 | +problem₁₆ : ∀ K → IsKestrel K → ∀ x y → K ∙ x ≈ K ∙ y → x ≈ y |
| 158 | +problem₁₆ K isKestrel x y Kx≈Ky = begin |
| 159 | + x ≈˘⟨ isKestrel x K ⟩ |
| 160 | + -- NOTE: for the right-most kestrel, we can choose any bird. (Since we know |
| 161 | + -- only of three birds to exist here, the only option is a combination of |
| 162 | + -- {K, x, y}). |
| 163 | + (K ∙ x) ∙ K ≈⟨ ∙-congʳ Kx≈Ky ⟩ |
| 164 | + (K ∙ y) ∙ K ≈⟨ isKestrel y K ⟩ |
| 165 | + y ∎ |
| 166 | + |
| 167 | +problem₁₇ : ∀ A x y → A IsFixatedOn x → A IsFixatedOn y → x ≈ y |
| 168 | +problem₁₇ A x y Az≈x Az≈y = begin |
| 169 | + x ≈˘⟨ Az≈x A ⟩ |
| 170 | + -- NOTE: for the right-most A, we can choose any bird. (In this case a |
| 171 | + -- combination of {A, B, C}). |
| 172 | + A ∙ A ≈⟨ Az≈y A ⟩ |
| 173 | + y ∎ |
| 174 | + |
| 175 | +problem₁₈ : ⦃ _ : HasKestrel ⦄ → ∀ x → K IsFondOf K ∙ x → K IsFondOf x |
| 176 | +problem₁₈ x K[Kx]≈Kx = begin |
| 177 | + K ∙ x ≈˘⟨ isKestrel (K ∙ x) x ⟩ |
| 178 | + -- NOTE: for the right-most x, we can choose any bird. |
| 179 | + (K ∙ (K ∙ x)) ∙ x ≈⟨ ∙-congʳ K[Kx]≈Kx ⟩ |
| 180 | + (K ∙ x) ∙ x ≈⟨ isKestrel x x ⟩ |
| 181 | + x ∎ |
| 182 | + |
| 183 | +-- In the circumstances of Problem 19, the only bird in the forest is the |
| 184 | +-- kestrel. |
| 185 | +problem₁₉ : ∀ K → IsKestrel K → IsEgocentric K → ∀ x → x ≈ K |
| 186 | +problem₁₉ K isKestrel KK≈K x = begin |
| 187 | + x ≈⟨ lemma x x ⟩ |
| 188 | + K ∙ x ≈˘⟨ ∙-congʳ KK≈K ⟩ |
| 189 | + (K ∙ K) ∙ x ≈⟨ isKestrel K x ⟩ |
| 190 | + K ∎ |
| 191 | + where |
| 192 | + lemma : ∀ y z → y ≈ K ∙ z |
| 193 | + lemma y z = begin |
| 194 | + y ≈˘⟨ isKestrel y z ⟩ |
| 195 | + (K ∙ y) ∙ z ≈˘⟨ ∙-congʳ (∙-congʳ KK≈K) ⟩ |
| 196 | + ((K ∙ K) ∙ y) ∙ z ≈⟨ ∙-congʳ (isKestrel K y) ⟩ |
| 197 | + K ∙ z ∎ |
| 198 | + |
| 199 | +module _ ⦃ _ : HasIdentity ⦄ where |
| 200 | + problem₂₀ : IsAgreeable I → ∀ A → ∃[ B ] A IsFondOf B |
| 201 | + problem₂₀ isAgreeable A = |
| 202 | + let (B , IB≈AB) = isAgreeable A |
| 203 | + |
| 204 | + isFond : A IsFondOf B |
| 205 | + isFond = begin |
| 206 | + A ∙ B ≈˘⟨ IB≈AB ⟩ |
| 207 | + I ∙ B ≈⟨ isIdentity B ⟩ |
| 208 | + B ∎ |
| 209 | + |
| 210 | + in (B , isFond) |
| 211 | + |
| 212 | + problem₂₁ : (∀ A → ∃[ B ] A IsFondOf B) → IsAgreeable I |
| 213 | + problem₂₁ isFond A = |
| 214 | + let (B , AB≈B) = isFond A |
| 215 | + |
| 216 | + agree : I ∙ B ≈ A ∙ B |
| 217 | + agree = begin |
| 218 | + I ∙ B ≈⟨ isIdentity B ⟩ |
| 219 | + B ≈˘⟨ AB≈B ⟩ |
| 220 | + A ∙ B ∎ |
| 221 | + |
| 222 | + in (B , agree) |
| 223 | + |
| 224 | + problem₂₂-1 : (∀ A B → Compatible A B) → ∀ A → IsNormal A |
| 225 | + problem₂₂-1 compatible A = |
| 226 | + let (x , y , Ix≈y , Ay≈x) = compatible I A |
| 227 | + |
| 228 | + isFond : A IsFondOf y |
| 229 | + isFond = begin |
| 230 | + A ∙ y ≈⟨ Ay≈x ⟩ |
| 231 | + x ≈˘⟨ isIdentity x ⟩ |
| 232 | + I ∙ x ≈⟨ Ix≈y ⟩ |
| 233 | + y ∎ |
| 234 | + in (y , isFond) |
| 235 | + |
| 236 | + problem₂₂-2 : (∀ A B → Compatible A B) → IsAgreeable I |
| 237 | + problem₂₂-2 compatible A = |
| 238 | + let (x , y , Ix≈y , Ay≈x) = compatible I A |
| 239 | + |
| 240 | + agree : Agree I A y |
| 241 | + agree = begin |
| 242 | + I ∙ y ≈⟨ isIdentity y ⟩ |
| 243 | + y ≈˘⟨ Ix≈y ⟩ |
| 244 | + I ∙ x ≈⟨ isIdentity x ⟩ |
| 245 | + x ≈˘⟨ Ay≈x ⟩ |
| 246 | + A ∙ y ∎ |
| 247 | + |
| 248 | + in (y , agree) |
| 249 | + |
| 250 | + problem₂₃ : IsHopelesslyEgocentric I → ∀ x → I ≈ x |
| 251 | + problem₂₃ isHopelesslyEgocentric x = begin |
| 252 | + I ≈˘⟨ isHopelesslyEgocentric x ⟩ |
| 253 | + I ∙ x ≈⟨ isIdentity x ⟩ |
| 254 | + x ∎ |
| 255 | + |
| 256 | +module _ ⦃ _ : HasLark ⦄ ⦃ _ : HasIdentity ⦄ where |
| 257 | + problem₂₄ : HasMockingbird |
| 258 | + problem₂₄ = record |
| 259 | + { M = L ∙ I |
| 260 | + ; isMockingbird = λ x → begin |
| 261 | + (L ∙ I) ∙ x ≈⟨ isLark I x ⟩ |
| 262 | + I ∙ (x ∙ x) ≈⟨ isIdentity (x ∙ x) ⟩ |
| 263 | + x ∙ x ∎ |
| 264 | + } |
| 265 | + |
| 266 | +module _ ⦃ _ : HasLark ⦄ where |
| 267 | + problem₂₅ : ∀ x → IsNormal x |
| 268 | + problem₂₅ x = |
| 269 | + let isFond : x IsFondOf (L ∙ x) ∙ (L ∙ x) |
| 270 | + isFond = begin |
| 271 | + x ∙ ((L ∙ x) ∙ (L ∙ x)) ≈˘⟨ isLark x (L ∙ x) ⟩ |
| 272 | + (L ∙ x) ∙ (L ∙ x) ∎ |
| 273 | + in ((L ∙ x) ∙ (L ∙ x) , isFond) |
| 274 | + |
| 275 | + problem₂₆ : IsHopelesslyEgocentric L → ∀ x → x IsFondOf L |
| 276 | + problem₂₆ isHopelesslyEgocentric x = begin |
| 277 | + x ∙ L ≈˘⟨ ∙-congˡ $ isHopelesslyEgocentric L ⟩ |
| 278 | + x ∙ (L ∙ L) ≈˘⟨ isLark x L ⟩ |
| 279 | + (L ∙ x) ∙ L ≈⟨ ∙-congʳ $ isHopelesslyEgocentric x ⟩ |
| 280 | + L ∙ L ≈⟨ isHopelesslyEgocentric L ⟩ |
| 281 | + L ∎ |
| 282 | + |
| 283 | +module _ ⦃ _ : HasLark ⦄ ⦃ _ : HasKestrel ⦄ where |
| 284 | + problem₂₇ : L ≉ K → ¬ L IsFondOf K |
| 285 | + problem₂₇ L≉K isFond = |
| 286 | + let K-fondOf-KK : K IsFondOf K ∙ K |
| 287 | + K-fondOf-KK = begin |
| 288 | + K ∙ (K ∙ K) ≈˘⟨ ∙-congʳ isFond ⟩ |
| 289 | + (L ∙ K) ∙ (K ∙ K) ≈⟨ isLark K (K ∙ K) ⟩ |
| 290 | + K ∙ ((K ∙ K) ∙ (K ∙ K)) ≈⟨ ∙-congˡ $ isKestrel K (K ∙ K) ⟩ |
| 291 | + K ∙ K ∎ |
| 292 | + |
| 293 | + isEgocentric : IsEgocentric K |
| 294 | + isEgocentric = problem₁₈ K K-fondOf-KK |
| 295 | + |
| 296 | + L≈K : L ≈ K |
| 297 | + L≈K = problem₁₉ K isKestrel isEgocentric L |
| 298 | + |
| 299 | + in L≉K L≈K |
| 300 | + |
| 301 | + problem₂₈ : K IsFondOf L → ∀ x → x IsFondOf L |
| 302 | + problem₂₈ KL≈L = |
| 303 | + let isHopelesslyEgocentric : IsHopelesslyEgocentric L |
| 304 | + isHopelesslyEgocentric y = begin |
| 305 | + L ∙ y ≈˘⟨ ∙-congʳ KL≈L ⟩ |
| 306 | + (K ∙ L) ∙ y ≈⟨ isKestrel L y ⟩ |
| 307 | + L ∎ |
| 308 | + in problem₂₆ isHopelesslyEgocentric |
| 309 | + |
| 310 | +module _ ⦃ _ : HasLark ⦄ where |
| 311 | + problem₂₉ : ∃[ x ] IsEgocentric x |
| 312 | + problem₂₉ = |
| 313 | + let (y , [LL]y≈y) = problem₂₅ (L ∙ L) |
| 314 | + |
| 315 | + isEgocentric : IsEgocentric (y ∙ y) |
| 316 | + isEgocentric = begin |
| 317 | + (y ∙ y) ∙ (y ∙ y) ≈˘⟨ isLark (y ∙ y) y ⟩ |
| 318 | + (L ∙ (y ∙ y)) ∙ y ≈˘⟨ ∙-congʳ (isLark L y) ⟩ |
| 319 | + ((L ∙ L) ∙ y) ∙ y ≈⟨ ∙-congʳ [LL]y≈y ⟩ |
| 320 | + y ∙ y ∎ |
| 321 | + |
| 322 | + -- The expression of yy in terms of L and brackets. |
| 323 | + _ : y ∙ y ≈ ((L ∙ (L ∙ L)) ∙ (L ∙ (L ∙ L))) ∙ ((L ∙ (L ∙ L)) ∙ (L ∙ (L ∙ L))) |
| 324 | + _ = refl |
| 325 | + |
| 326 | + in (y ∙ y , isEgocentric) |
0 commit comments