Skip to content

Commit df8bf87

Browse files
Chapter20: Add
1 parent 00bcd38 commit df8bf87

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

Mockingbird/Problems/Chapter20.agda

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
open import Mockingbird.Forest using (Forest)
2+
3+
-- Craig’s Discovery
4+
module Mockingbird.Problems.Chapter20 {ℓb ℓ} (forest : Forest {ℓb} {ℓ}) where
5+
6+
open import Data.Product using (_,_)
7+
open import Data.Vec using ([]; _∷_)
8+
open import Function using (_$_)
9+
open import Relation.Unary using (Pred; _∈_; _⊆_; _⊇_)
10+
11+
open Forest forest
12+
open import Mockingbird.Forest.Birds forest
13+
open import Mockingbird.Forest.Combination.Vec forest
14+
open import Mockingbird.Forest.Combination.Vec.Properties forest
15+
open import Mockingbird.Forest.Extensionality forest
16+
import Mockingbird.Problems.Chapter11 forest as Chapter₁₁
17+
open import Mockingbird.Problems.Chapter19 forest using (_≐_)
18+
19+
problem₁ : ⦃ _ : HasGoldfinch ⦄ ⦃ _ : HasIdentity ⦄ HasQuirkyBird
20+
problem₁ = record
21+
{ Q₃ = G ∙ I
22+
; isQuirkyBird = λ x y z begin
23+
G ∙ I ∙ x ∙ y ∙ z ≈⟨ isGoldfinch I x y z ⟩
24+
I ∙ z ∙ (x ∙ y) ≈⟨ congʳ $ isIdentity z ⟩
25+
z ∙ (x ∙ y) ∎
26+
}
27+
28+
problem₂′ : ⦃ _ : HasQuirkyBird ⦄ ⦃ _ : HasIdentity ⦄ HasThrush
29+
problem₂′ = record
30+
{ T = Q₃ ∙ I
31+
; isThrush = λ x y begin
32+
Q₃ ∙ I ∙ x ∙ y ≈⟨ isQuirkyBird I x y ⟩
33+
y ∙ (I ∙ x) ≈⟨ congˡ $ isIdentity x ⟩
34+
y ∙ x ∎
35+
}
36+
37+
problem₂ : ⦃ _ : HasGoldfinch ⦄ ⦃ _ : HasIdentity ⦄ HasThrush
38+
problem₂ = record
39+
{ T = G ∙ I ∙ I
40+
; isThrush = isThrush ⦃ problem₂′ ⦄
41+
} where
42+
instance hasQuirkyBird = problem₁
43+
44+
problem₃ : ⦃ _ : HasGoldfinch ⦄ ⦃ _ : HasIdentity ⦄ HasCardinal
45+
problem₃ = record
46+
{ C = G ∙ G ∙ I ∙ I
47+
; isCardinal = λ x y z begin
48+
G ∙ G ∙ I ∙ I ∙ x ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isGoldfinch G I I x ⟩
49+
G ∙ x ∙ (I ∙ I) ∙ y ∙ z ≈⟨ isGoldfinch x (I ∙ I) y z ⟩
50+
x ∙ z ∙ (I ∙ I ∙ y) ≈⟨ congˡ $ congʳ $ isIdentity I ⟩
51+
x ∙ z ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩
52+
x ∙ z ∙ y ∎
53+
}
54+
55+
problem₄-Q : ⦃ _ : HasGoldfinch ⦄ ⦃ _ : HasIdentity ⦄ HasQueerBird
56+
problem₄-Q = record
57+
{ Q = G ∙ R ∙ Q₃
58+
; isQueerBird = λ x y z begin
59+
G ∙ R ∙ Q₃ ∙ x ∙ y ∙ z ≈⟨ congʳ $ isGoldfinch R Q₃ x y ⟩
60+
R ∙ y ∙ (Q₃ ∙ x) ∙ z ≈⟨ isRobin y (Q₃ ∙ x) z ⟩
61+
Q₃ ∙ x ∙ z ∙ y ≈⟨ isQuirkyBird x z y ⟩
62+
y ∙ (x ∙ z) ∎
63+
} where
64+
instance
65+
hasQuirkyBird = problem₁
66+
hasCardinal = problem₃
67+
hasRobin = Chapter₁₁.problem₂₃
68+
69+
problem₄-B : ⦃ _ : HasGoldfinch ⦄ ⦃ _ : HasIdentity ⦄ HasBluebird
70+
problem₄-B = record
71+
{ B = C ∙ Q
72+
; isBluebird = λ x y z begin
73+
C ∙ Q ∙ x ∙ y ∙ z ≈⟨ congʳ $ isCardinal Q x y ⟩
74+
Q ∙ y ∙ x ∙ z ≈⟨ isQueerBird y x z ⟩
75+
x ∙ (y ∙ z) ∎
76+
} where
77+
instance
78+
hasCardinal = problem₃
79+
hasQueerBird = problem₄-Q
80+
81+
module _ ⦃ _ : Extensional ⦄
82+
⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄
83+
⦃ _ : HasIdentity ⦄ ⦃ _ : HasGoldfinch ⦄ where
84+
⟨B,T,I⟩ = ⟨ B ∷ T ∷ I ∷ [] ⟩
85+
⟨G,I⟩ = ⟨ G ∷ I ∷ [] ⟩
86+
87+
module _ where
88+
private
89+
instance
90+
hasCardinal = Chapter₁₁.problem₂₁-bonus
91+
hasDove = Chapter₁₁.problem₅
92+
93+
hasGoldfinch = Chapter₁₁.problem₄₇
94+
95+
b : B ∈ ⟨B,T,I⟩
96+
b = [ here refl ]
97+
98+
t : T ∈ ⟨B,T,I⟩
99+
t = [ there (here refl) ]
100+
101+
i : I ∈ ⟨B,T,I⟩
102+
i = [ there (there (here refl)) ]
103+
104+
c : C ∈ ⟨B,T,I⟩
105+
c = b ⟨∙⟩ (t ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ t)) ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ t)
106+
107+
d : D ∈ ⟨B,T,I⟩
108+
d = b ⟨∙⟩ b
109+
110+
g : G ∈ ⟨B,T,I⟩
111+
g = subst′
112+
(ext′ $ ext′ $ ext′ $ ext′ $ trans
113+
(isGoldfinch _ _ _ _)
114+
(sym $ isGoldfinch ⦃ hasGoldfinch ⦄ _ _ _ _))
115+
(d ⟨∙⟩ c)
116+
117+
⟨G,I⟩⊆⟨B,T,I⟩ : ⟨G,I⟩ ⊆ ⟨B,T,I⟩
118+
⟨G,I⟩⊆⟨B,T,I⟩ [ here x≈G ] = subst′ x≈G g
119+
⟨G,I⟩⊆⟨B,T,I⟩ [ there (here x≈I) ] = [ there (there (here x≈I)) ]
120+
⟨G,I⟩⊆⟨B,T,I⟩ (x∈⟨G,I⟩ ⟨∙⟩ y∈⟨G,I⟩ ∣ xy≈z) =
121+
⟨G,I⟩⊆⟨B,T,I⟩ x∈⟨G,I⟩ ⟨∙⟩ ⟨G,I⟩⊆⟨B,T,I⟩ y∈⟨G,I⟩ ∣ xy≈z
122+
123+
module _ where
124+
private
125+
g : G ∈ ⟨G,I⟩
126+
g = [ here refl ]
127+
128+
i : I ∈ ⟨G,I⟩
129+
i = [ there (here refl) ]
130+
131+
t : T ∈ ⟨G,I⟩
132+
t = subst′
133+
(ext′ $ ext′ $ trans
134+
(isThrush _ _)
135+
(sym $ isThrush ⦃ problem₂ ⦄ _ _))
136+
(g ⟨∙⟩ i ⟨∙⟩ i)
137+
138+
b : B ∈ ⟨G,I⟩
139+
b = subst′
140+
(ext′ $ ext′ $ ext′ $ trans
141+
(isBluebird _ _ _)
142+
(sym $ isBluebird ⦃ problem₄-B ⦄ _ _ _))
143+
(g ⟨∙⟩ g ⟨∙⟩ i ⟨∙⟩ i ⟨∙⟩ (g ⟨∙⟩ (g ⟨∙⟩ g ⟨∙⟩ i ⟨∙⟩ i ⟨∙⟩ (g ⟨∙⟩ g ⟨∙⟩ i ⟨∙⟩ i)) ⟨∙⟩ (g ⟨∙⟩ i)))
144+
145+
⟨G,I⟩⊇⟨B,T,I⟩ : ⟨G,I⟩ ⊇ ⟨B,T,I⟩
146+
⟨G,I⟩⊇⟨B,T,I⟩ [ here x≈B ] = subst′ x≈B b
147+
⟨G,I⟩⊇⟨B,T,I⟩ [ there (here x≈T) ] = subst′ x≈T t
148+
⟨G,I⟩⊇⟨B,T,I⟩ [ there (there (here x≈I)) ] = [ there (here x≈I) ]
149+
⟨G,I⟩⊇⟨B,T,I⟩ (x∈⟨B,T,I⟩ ⟨∙⟩ y∈⟨B,T,I⟩ ∣ xy≈z) = ⟨G,I⟩⊇⟨B,T,I⟩ x∈⟨B,T,I⟩ ⟨∙⟩ ⟨G,I⟩⊇⟨B,T,I⟩ y∈⟨B,T,I⟩ ∣ xy≈z
150+
151+
⟨G,I⟩≐⟨B,T,I⟩ : ⟨ G ∷ I ∷ [] ⟩ ≐ ⟨ B ∷ T ∷ I ∷ [] ⟩
152+
⟨G,I⟩≐⟨B,T,I⟩ = (⟨G,I⟩⊆⟨B,T,I⟩ , ⟨G,I⟩⊇⟨B,T,I⟩)

index.agda

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ import Mockingbird.Problems.Chapter16
3131
import Mockingbird.Problems.Chapter17
3232
import Mockingbird.Problems.Chapter18
3333
import Mockingbird.Problems.Chapter19
34+
import Mockingbird.Problems.Chapter20

0 commit comments

Comments
 (0)