-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.agda
235 lines (194 loc) · 13.6 KB
/
Model.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
{-# OPTIONS --cubical #-}
{-# OPTIONS --no-termination-check #-}
module Model where
open import Utils
open import Cubical.Core.Prelude
open import Agda.Primitive
open import Syntax
-- Model of type theory as a CwF
record Model {l} {l'} {l''} {l'''} : Set (lsuc (l ⊔ l' ⊔ l'' ⊔ l''')) where
field
Conᴹ : Set l -- (lsuc l)
Tyᴹ : Conᴹ → Set l' -- (lsuc l)
Tmsᴹ : Conᴹ → Conᴹ → Set l''
Tmᴹ : (Γᴹ : Conᴹ) → Tyᴹ Γᴹ → Set l'''
◇ᴹ : Conᴹ
_,ᴹ_ : (Γᴹ : Conᴹ) → Tyᴹ Γᴹ → Conᴹ
_[_]ᴹ : {Θᴹ Γᴹ : Conᴹ} → Tyᴹ Θᴹ → Tmsᴹ Γᴹ Θᴹ → Tyᴹ Γᴹ
idᴹ : (Γᴹ : Conᴹ) → Tmsᴹ Γᴹ Γᴹ
-- the empty context is the terminal object
εᴹ : ∀{Γᴹ} → Tmsᴹ Γᴹ ◇ᴹ
εηᴹ : ∀{Γᴹ} {σᴹ : Tmsᴹ Γᴹ ◇ᴹ} → σᴹ ≡ εᴹ
_∘ᴹ_ : ∀{Θᴹ Γᴹ Δᴹ} → Tmsᴹ Θᴹ Δᴹ → Tmsᴹ Γᴹ Θᴹ → Tmsᴹ Γᴹ Δᴹ
[id]ᴹ : {Γᴹ : Conᴹ} → (Aᴹ : Tyᴹ Γᴹ) → Aᴹ [ idᴹ Γᴹ ]ᴹ ≡ Aᴹ
[][]ᴹ : ∀{Θᴹ Γᴹ Δᴹ} {σᴹ : Tmsᴹ Θᴹ Δᴹ} {τᴹ : Tmsᴹ Γᴹ Θᴹ} {Aᴹ : Tyᴹ Δᴹ}
→ Aᴹ [ σᴹ ]ᴹ [ τᴹ ]ᴹ ≡ Aᴹ [ σᴹ ∘ᴹ τᴹ ]ᴹ
-- category laws for substitutions
id∘ᴹ : ∀{Γᴹ Δᴹ} → {σᴹ : Tmsᴹ Γᴹ Δᴹ} → idᴹ _ ∘ᴹ σᴹ ≡ σᴹ
∘idᴹ : ∀{Γᴹ Δᴹ} → {σᴹ : Tmsᴹ Γᴹ Δᴹ} → σᴹ ∘ᴹ idᴹ _ ≡ σᴹ
∘∘ᴹ : ∀{Θᴹ Γᴹ Δᴹ ∇ᴹ} {σᴹ : Tmsᴹ Δᴹ ∇ᴹ} {τᴹ : Tmsᴹ Γᴹ Δᴹ} {δᴹ : Tmsᴹ Θᴹ Γᴹ}
→ (σᴹ ∘ᴹ τᴹ) ∘ᴹ δᴹ ≡ σᴹ ∘ᴹ (τᴹ ∘ᴹ δᴹ)
-- substitution extension
_,sᴹ_ : ∀{Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} → (σᴹ : Tmsᴹ Γᴹ Δᴹ) → Tmᴹ Γᴹ (Aᴹ [ σᴹ ]ᴹ)
→ Tmsᴹ Γᴹ (Δᴹ ,ᴹ Aᴹ)
π₁ᴹ : ∀{Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} → Tmsᴹ Γᴹ (Δᴹ ,ᴹ Aᴹ) → Tmsᴹ Γᴹ Δᴹ
π₂ᴹ : ∀{Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} → (σᴹ : Tmsᴹ Γᴹ (Δᴹ ,ᴹ Aᴹ)) → Tmᴹ Γᴹ (Aᴹ [ π₁ᴹ σᴹ ]ᴹ)
π₁βᴹ : ∀{Γᴹ Δᴹ} {σᴹ : Tmsᴹ Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} {tᴹ : Tmᴹ Γᴹ (Aᴹ [ σᴹ ]ᴹ)}
→ π₁ᴹ (σᴹ ,sᴹ tᴹ) ≡ σᴹ
π₂βᴹ : ∀{Γᴹ Δᴹ} {σᴹ : Tmsᴹ Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} {tᴹ : Tmᴹ Γᴹ (Aᴹ [ σᴹ ]ᴹ)}
-- → subst (Tmᴹ Γᴹ) (cong (λ x → Aᴹ [ x ]ᴹ) π₁βᴹ) (π₂ᴹ (σᴹ ,sᴹ tᴹ)) ≡ tᴹ
→ PathP (λ i → Tmᴹ Γᴹ (Aᴹ [ π₁βᴹ {σᴹ = σᴹ} {tᴹ = tᴹ} i ]ᴹ)) (π₂ᴹ (σᴹ ,sᴹ tᴹ)) tᴹ
πηᴹ : ∀{Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} {σᴹ : Tmsᴹ Γᴹ (Δᴹ ,ᴹ Aᴹ)}
→ (π₁ᴹ σᴹ ,sᴹ π₂ᴹ σᴹ) ≡ σᴹ
_[_]'ᴹ : ∀{Γᴹ Δᴹ} {Aᴹ : Tyᴹ Δᴹ} → Tmᴹ Δᴹ Aᴹ → (σᴹ : Tmsᴹ Γᴹ Δᴹ)
→ Tmᴹ Γᴹ (Aᴹ [ σᴹ ]ᴹ)
-- ,∘ᴹ : ∀{Γᴹ Δᴹ ∇ᴹ} {τᴹ : Tmsᴹ Γᴹ Δᴹ} {σᴹ : Tmsᴹ ∇ᴹ Γᴹ}
-- → {Aᴹ : Tyᴹ Δᴹ} {tᴹ : Tmᴹ Γᴹ (Aᴹ [ τᴹ ]ᴹ)}
-- → _≡_ {A = Tmsᴹ ∇ᴹ (Δᴹ ,ᴹ Aᴹ)}
-- ((τᴹ ,sᴹ tᴹ) ∘ᴹ σᴹ)
-- ((τᴹ ∘ᴹ σᴹ) ,sᴹ subst (Tmᴹ ∇ᴹ) [][]ᴹ (tᴹ [ σᴹ ]'ᴹ))
,∘₁ᴹ : ∀{Γᴹ Δᴹ ∇ᴹ} {τᴹ : Tmsᴹ Γᴹ Δᴹ} {σᴹ : Tmsᴹ ∇ᴹ Γᴹ} {Aᴹ : Tyᴹ Δᴹ}
→ {tᴹ : Tmᴹ Γᴹ (Aᴹ [ τᴹ ]ᴹ)}
→ π₁ᴹ ((τᴹ ,sᴹ tᴹ) ∘ᴹ σᴹ) ≡ (τᴹ ∘ᴹ σᴹ)
-- _[_]'∘ᴹ : ∀{Γᴹ Δᴹ ∇ᴹ} {Aᴹ : Tyᴹ ∇ᴹ} {τᴹ : Tmsᴹ Δᴹ ∇ᴹ}
-- → Tmᴹ Δᴹ (Aᴹ [ τᴹ ]ᴹ) → (σᴹ : Tmsᴹ Γᴹ Δᴹ) → Tmᴹ Γᴹ (Aᴹ [ τᴹ ∘ᴹ σᴹ ]ᴹ)
-- [][]∘ᴹ : ∀{Γᴹ Δᴹ ∇ᴹ} {Aᴹ : Tyᴹ ∇ᴹ} {τᴹ : Tmsᴹ Δᴹ ∇ᴹ}
-- → (tᴹ : Tmᴹ Δᴹ (Aᴹ [ τᴹ ]ᴹ)) → (σᴹ : Tmsᴹ Γᴹ Δᴹ)
-- → PathP (λ i → Tmᴹ Γᴹ ([][]ᴹ {σᴹ = τᴹ} {σᴹ} {Aᴹ} i)) (tᴹ [ σᴹ ]'ᴹ) (tᴹ [ σᴹ ]'∘ᴹ)
-- ,∘₂ᴹ : ∀{Γᴹ Δᴹ ∇ᴹ} {τᴹ : Tmsᴹ Γᴹ Δᴹ} {σᴹ : Tmsᴹ ∇ᴹ Γᴹ} {Aᴹ : Tyᴹ Δᴹ}
-- → {tᴹ : Tmᴹ Γᴹ (Aᴹ [ τᴹ ]ᴹ)}
-- → PathP (λ i → Tmᴹ ∇ᴹ (Aᴹ [ ,∘₁ᴹ {τᴹ = τᴹ} {σᴹ} {Aᴹ} {tᴹ} i ]ᴹ))
-- (π₂ᴹ ((τᴹ ,sᴹ tᴹ) ∘ᴹ σᴹ))
-- (tᴹ [ σᴹ ]'∘ᴹ)
,∘₂ᴹ : ∀{Γ Δ ∇} {τ : Tmsᴹ Γ Δ} {σ : Tmsᴹ ∇ Γ} {A : Tyᴹ Δ} {t : Tmᴹ Γ (A [ τ ]ᴹ)}
→ subst (Tmᴹ ∇)
(cong (λ x → A [ x ]ᴹ) ,∘₁ᴹ · sym [][]ᴹ)
(π₂ᴹ ((τ ,sᴹ t) ∘ᴹ σ))
≡ (t [ σ ]'ᴹ)
-- π₂∘ᴹ : ∀{Γ Δ ∇} {A : Tyᴹ ∇} → {τ : Tmsᴹ Δ ∇}
-- → (σ : Tmsᴹ Γ (Δ ,ᴹ (A [ τ ]ᴹ)))
-- → Tmᴹ Γ (A [ τ ∘ᴹ π₁ᴹ σ ]ᴹ)
-- π₂≡ᴹ : ∀{Γ Δ ∇} {A : Tyᴹ ∇} → {τ : Tmsᴹ Δ ∇}
-- → (σ : Tmsᴹ Γ (Δ ,ᴹ (A [ τ ]ᴹ)))
-- → PathP (λ i → Tmᴹ Γ ([][]ᴹ {σᴹ = τ} {π₁ᴹ σ} {A} i)) (π₂ᴹ σ) (π₂∘ᴹ σ)
Uᴹ : ∀{Γ} → Tyᴹ Γ
U[]ᴹ : ∀{Δᴹ Γᴹ} (σᴹ : Tmsᴹ Γᴹ Δᴹ) → Uᴹ [ σᴹ ]ᴹ ≡ Uᴹ
Πᴹ : ∀{Γ} (A : Tyᴹ Γ) (B : Tyᴹ (Γ ,ᴹ A)) → Tyᴹ Γ
Π[]ᴹ : ∀{Γ Δ} (A : Tyᴹ Γ) (B : Tyᴹ (Γ ,ᴹ A)) → (σ : Tmsᴹ Δ Γ)
-> let _↑ᴹ_ : ∀{Γ Δ} → (σ : Tmsᴹ Γ Δ) → (A : Tyᴹ Δ) → Tmsᴹ (Γ ,ᴹ (A [ σ ]ᴹ)) (Δ ,ᴹ A)
σ ↑ᴹ A = (σ ∘ᴹ π₁ᴹ (idᴹ _)) ,sᴹ subst (Tmᴹ _) [][]ᴹ (π₂ᴹ (idᴹ (_ ,ᴹ (A [ σ ]ᴹ))))
in (Πᴹ A B) [ σ ]ᴹ ≡ Πᴹ (A [ σ ]ᴹ) (B [ σ ↑ᴹ A ]ᴹ)
Elᴹ : ∀{Γ} → (A : Tmᴹ Γ Uᴹ) → Tyᴹ Γ
El[]ᴹ : ∀{Γ Δ} → (A : Tmᴹ Γ Uᴹ) → (σ : Tmsᴹ Δ Γ)
→ ((Elᴹ A) [ σ ]ᴹ) ≡ Elᴹ (subst (Tmᴹ Δ) (U[]ᴹ σ) (A [ σ ]'ᴹ))
lamᴹ : ∀{Γ} {A : Tyᴹ Γ} {B : Tyᴹ (Γ ,ᴹ A)} → Tmᴹ (Γ ,ᴹ A) B → Tmᴹ Γ (Πᴹ A B)
appᴹ : ∀{Γ} {A : Tyᴹ Γ} {B : Tyᴹ (Γ ,ᴹ A)} → Tmᴹ Γ (Πᴹ A B) → Tmᴹ (Γ ,ᴹ A) B
βᴹ : ∀{Γ} {A : Tyᴹ Γ} {B : Tyᴹ (Γ ,ᴹ A)} (t : Tmᴹ (Γ ,ᴹ A) B) → appᴹ (lamᴹ t) ≡ t
ηᴹ : ∀{Γ} {A : Tyᴹ Γ} {B : Tyᴹ (Γ ,ᴹ A)} (f : Tmᴹ Γ (Πᴹ A B)) → lamᴹ (appᴹ f) ≡ f
lam[]ᴹ : ∀{Δ Γ} {A : Tyᴹ Γ} {B : Tyᴹ (Γ ,ᴹ A)} (t : Tmᴹ (Γ ,ᴹ A) B) (σ : Tmsᴹ Δ Γ)
-> let _↑ᴹ_ : ∀{Γ Δ} → (σ : Tmsᴹ Γ Δ) → (A : Tyᴹ Δ) → Tmsᴹ (Γ ,ᴹ (A [ σ ]ᴹ)) (Δ ,ᴹ A)
σ ↑ᴹ A = (σ ∘ᴹ π₁ᴹ (idᴹ _)) ,sᴹ subst (Tmᴹ _) [][]ᴹ (π₂ᴹ (idᴹ (_ ,ᴹ (A [ σ ]ᴹ))))
in ((lamᴹ t) [ σ ]'ᴹ) ≡ subst (Tmᴹ Δ) (sym (Π[]ᴹ A B σ)) (lamᴹ (t [ σ ↑ᴹ A ]'ᴹ))
Idᴹ : ∀{Γ} (A : Tyᴹ Γ) -> Tyᴹ ((Γ ,ᴹ A) ,ᴹ (A [ π₁ᴹ (idᴹ _) ]ᴹ))
-- reflᴹ : ∀{Γ} {A : Tyᴹ Γ} (a : Tmᴹ Γ A)
-- -> Tmᴹ Γ (Idᴹ A [ (idᴹ _ ,sᴹ subst (Tmᴹ Γ) (sym ([id]ᴹ A)) a) ,sᴹ subst (Tmᴹ Γ) (sym ([][]ᴹ · (ap (λ z → A [ z ]ᴹ) {!!} · [id]ᴹ A))) a ]ᴹ)
ty-trunc : ∀{Γ} -> isSet (Tyᴹ Γ)
variable
Θ Γ Δ : Con
module _ {l l'} (A : Set l) (aset : isSet A) where
K : (M : A) (C : M ≡ M -> Set l') -> C refl -> (loop : M ≡ M) -> C loop
K M C h p = subst C (aset _ _ _ _) h
module _ {l} {l'} {l''} {l'''} (M : Model {l} {l'} {l''} {l'''}) where
open Model M
mutual
con : Con → Conᴹ
con ◇ = ◇ᴹ
con (Γ , A) = (con Γ) ,ᴹ (ty A)
ty : Ty Γ → Tyᴹ (con Γ)
ty (A [ x ]) = (ty A) [ tms x ]ᴹ
ty ([id] Γ A i) = [id]-proof (ty A) i
ty ([][] {σ = σ} {τ = τ} {A = A} i) = [][]-proof {σᴹ = tms σ} {tms τ} {ty A} i
ty U = Uᴹ
ty (U[] σ i) = U[]ᴹ (tms σ) i
ty (Π A B) = Πᴹ (ty A) (ty B)
ty (Π[] A B σ i) = Π[]-proof A B σ i
ty (El A) = Elᴹ (tm A)
ty (El[] A σ i) = El-proof σ A i
tms : Tms Γ Δ → Tmsᴹ (con Γ) (con Δ)
tms (id Γ) = idᴹ (con Γ)
tms ε = εᴹ
tms (x ∘ y) = tms x ∘ᴹ tms y
tms (∘∘ {σ = σ} {τ} {δ} i) = ∘∘ᴹ {σᴹ = tms σ} {tms τ} {tms δ} i
tms (id∘ {σ = σ} i) = id∘ᴹ {σᴹ = tms σ} i
tms (∘id {σ = σ} i) = ∘idᴹ {σᴹ = tms σ} i
tms (π₁ σ) = π₁ᴹ (tms σ)
tms (εη {σ = σ} i) = εηᴹ {σᴹ = tms σ} i
tms (_,_ σ t) = tms σ ,sᴹ tm t
tms (π₁β {Γ = Γ} {σ = σ} {A} {t} i) = π₁βᴹ {σᴹ = tms σ} {ty A} {tm t} i
tms (πη {Γ = Γ} {Δ = Δ} {A = A} {σ} i) = πη-proof {Aᴹ = ty A} {tms σ} i
tms (,∘₁ {Γ = Γ} {Δ} {∇} {τ = τ} {σ} {A} {t} i) =
,∘₁-proof {τᴹ = tms τ} {tms σ} {ty A} {tm t} i
tm : {A : Ty Γ} → Tm Γ A → Tmᴹ (con Γ) (ty A)
tm (t [ σ ]') = tm t [ tms σ ]'ᴹ
tm (π₂ σ) = π₂ᴹ (tms σ)
tm (π₂β {σ = σ} {A} {t} i) = π₂β-proof {σᴹ = tms σ} {ty A} {tm t} i
tm (,∘₂ {∇ = ∇} {τ = τ} {σ} {A} {t} i) = ,∘₂ᴹ-proof {∇ = ∇} {τ = τ} {σ} {A} {t} i
tm (lam t) = lamᴹ (tm t)
tm (app f) = appᴹ (tm f)
tm (β t i) = βᴹ (tm t) i
tm (η f i) = ηᴹ (tm f) i
tm (lam[] {A = A} {B} t σ i) = lam[]-proof A B σ t i
[id]-proof = [id]ᴹ
[][]-proof = [][]ᴹ
,∘₁-proof = ,∘₁ᴹ
,∘₂-proof = ,∘₂ᴹ
-- [][]∘-proof = [][]∘ᴹ
π₂β-proof = π₂βᴹ
πη-proof = πηᴹ
-- π₂≡-proof = π₂≡ᴹ
lamᴹsub : ∀{Γ Δ} (A : Tyᴹ _) (B : Tyᴹ _) (t : Tmᴹ (Γ ,ᴹ A) B) (σ : Tmsᴹ _ _)
{γ τ : Tmsᴹ (Δ ,ᴹ (A [ σ ]ᴹ)) (Γ ,ᴹ A)} (p : γ ≡ τ)
-> lamᴹ (t [ γ ]'ᴹ) ≡ subst (Tmᴹ _) (ap (λ z → Πᴹ _ (B [ z ]ᴹ)) (sym p)) (lamᴹ (t [ τ ]'ᴹ))
lamᴹsub {Γ} {Δ} A B t σ {γ} =
J (λ τ' p' → lamᴹ (t [ γ ]'ᴹ) ≡ subst (Tmᴹ _) (ap (λ z → Πᴹ _ (B [ z ]ᴹ)) (sym p')) (lamᴹ (t [ τ' ]'ᴹ)))
(sym (transpRefl (Tmᴹ _ (Πᴹ _ _)) (lamᴹ (t [ γ ]'ᴹ))))
swap-subst : ∀{Γ Ty1 Ty2} {t : Tm Γ Ty1}
-> (p : Ty1 ≡ Ty2) (q : ty Ty1 ≡ ty Ty2)
-> tm (subst (Tm Γ) p t) ≡ subst (Tmᴹ (con Γ)) q (tm t)
swap-subst {Γ} {Ty1} {_} {t} = J (λ Ty2' p' → (q : ty Ty1 ≡ ty Ty2')
-> tm (subst (Tm Γ) p' t) ≡ subst (Tmᴹ (con Γ)) q (tm t))
λ q -> K (Tyᴹ (con Γ)) (ty-trunc {con Γ}) (ty Ty1)
(λ q -> tm (subst (Tm Γ) refl t) ≡ subst (Tmᴹ (con Γ)) q (tm t))
(ap tm (transpRefl _ t) · sym (transpRefl _ (tm t))) q
Π[]-proof : ∀{Γ Δ} (A : Ty Γ) (B : Ty (Γ , A)) (σ : Tms Δ Γ)
→ ty ((Π A B) [ σ ]) ≡ ty (Π (A [ σ ]) (B [ σ ↑ A ]))
Π[]-proof {Γ} {Δ} A B σ =
Π[]ᴹ (ty A) (ty B) (tms σ) · ap (λ x → Πᴹ _ (ty B [ _ ,sᴹ x ]ᴹ))
(sym (swap-subst {t = π₂ (id (Δ , (A [ σ ]aux)))} [][] [][]ᴹ))
El-proof : ∀{Γ Δ} (σ : Tms Γ Δ) (A : Tm Δ Uaux)
-> ty (Elaux A [ σ ]) ≡ ty (Elaux (subst (Tm Γ) ([]Uaux σ) (A [ σ ]'aux)))
El-proof σ A = El[]ᴹ (tm A) (tms σ) · ap Elᴹ (sym (swap-subst {t = A [ σ ]'} (U[] σ) (U[]ᴹ (tms σ))))
,∘₂ᴹ-proof : ∀{Γ Δ ∇} {τ : Tms Γ Δ} {σ : Tms ∇ Γ} {A : Ty Δ} {t : Tm Γ (A [ τ ]aux)}
-> tm (subst (Tm ∇) (cong (_[_] A) ,∘₁ · sym [][]) (π₂ ((τ , t) ∘ σ))) ≡ tm (t [ σ ]')
,∘₂ᴹ-proof {Γ} {Δ} {∇} {τ} {σ} {A} {t} =
swap-subst {t = π₂ ((τ , t) ∘ σ)} (cong (_[_] A) ,∘₁ · sym [][])
(cong (_[_]ᴹ (ty A)) ,∘₁ᴹ · sym [][]ᴹ) · ,∘₂ᴹ {τ = tms τ} {tms σ} {ty A} {tm t}
open import Function using (_$_)
lam[]-proof : ∀{Γ Δ} (A : Ty Δ) (B : Ty (Δ , A)) (σ : Tms Γ Δ) (t : Tm (Δ , A) B)
-> tm ((lam t) [ σ ]') ≡ tm (subst (Tm _) (sym (Π[] A B σ)) (lam (t [ σ ↑ A ]'aux)))
lam[]-proof {Γ} {Δ} A B σ t = begin
(lamᴹ (tm t) [ tms σ ]'ᴹ)
≡⟨ lam[]ᴹ {A = ty A} {B = ty B} (tm t) (tms σ) ⟩
(subst (Tmᴹ _) (sym (Π[]ᴹ (ty A) (ty B) (tms σ))) (lamᴹ ((tm t) [ tms σ ↑ᴹ ty A ]'ᴹ)))
≡⟨ ap (subst (Tmᴹ _) (sym (Π[]ᴹ (ty A) (ty B) (tms σ)))) (lamᴹsub (ty A) (ty B) (tm t) (tms σ) aux) ⟩
(subst (Tmᴹ _) (sym (Π[]ᴹ (ty A) (ty B) (tms σ))) (subst (Tmᴹ _) (ap (λ z → Πᴹ (ty (A [ σ ])) (ty B [ z ]ᴹ)) (sym aux)) (tm (lam (t [ σ ↑ A ]')))))
≡⟨ subst· {B = Tmᴹ _} (ap (λ z → Πᴹ (ty (A [ σ ])) (ty B [ z ]ᴹ)) (sym aux)) (sym (Π[]ᴹ (ty A) (ty B) (tms σ))) (tm (lam (t [ σ ↑ A ]'))) ⟩
(subst (Tmᴹ _) (ap (λ z → Πᴹ (ty (A [ σ ])) (ty B [ z ]ᴹ)) (sym aux) · sym (Π[]ᴹ (ty A) (ty B) (tms σ))) (tm (lam (t [ σ ↑ A ]'))))
≡⟨ sym (swap-subst {t = lam (t [ σ ↑ A ]')} (sym (Π[] A B σ)) (ap (λ z → Πᴹ (ty (A [ σ ])) (ty B [ z ]ᴹ)) (sym aux) · sym (Π[]ᴹ (ty A) (ty B) (tms σ)))) ⟩
(tm (subst (Tm _) (sym (Π[] A B σ)) (lam (t [ σ ↑ A ]'))))
∎
where
_↑ᴹ_ : ∀{Γ Δ} → (σ : Tmsᴹ Γ Δ) → (A : Tyᴹ Δ) → Tmsᴹ (Γ ,ᴹ (A [ σ ]ᴹ)) (Δ ,ᴹ A)
σ ↑ᴹ A = (σ ∘ᴹ π₁ᴹ (idᴹ _)) ,sᴹ subst (Tmᴹ _) [][]ᴹ (π₂ᴹ (idᴹ (_ ,ᴹ (A [ σ ]ᴹ))))
aux : tms σ ↑ᴹ ty A ≡ tms (σ ↑ A)
aux = ap (tms (σ ∘ π₁ (id (Γ , (A [ σ ])))) ,sᴹ_) (sym (swap-subst {t = π₂ (id (_ , (A [ σ ])))} [][] [][]ᴹ))