-
Notifications
You must be signed in to change notification settings - Fork 2
/
ccc.agda
137 lines (118 loc) · 6.19 KB
/
ccc.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
{-# OPTIONS --cubical #-}
module ccc where
open import lists
open import contextual
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ ℓ₆ : Level
-- Here is a definition of a Cartesian Closed Contextual Category
record CCC (𝒞 : Contextual ℓ₁ ℓ₂) : Type (ℓ₁ ⊔ ℓ₂) where
open Contextual 𝒞
-- the product is given by ⊹ with pairing given by ⊕
field
_⇛_ : ty → ty → ty
Λ : {Γ : ctx} {A B : ty} → tm (Γ ⊹ A) B → tm Γ (A ⇛ B)
𝑎𝑝𝑝 : {Γ : ctx} {A B : ty} → tm Γ (A ⇛ B) → tm Γ A → tm Γ B
-- Categorical app operator
𝐴𝑝𝑝 : {Γ : ctx} {A B : ty} → tm Γ (A ⇛ B) → tm (Γ ⊹ A) B
𝐴𝑝𝑝 t = 𝑎𝑝𝑝 (t ⟦ π ⟧) 𝑧
field
Λnat : {Γ Δ : ctx} {A B : ty} (t : tm (Δ ⊹ A) B) (σ : tms Γ Δ) →
Λ t ⟦ σ ⟧ ≡ Λ ( t ⟦ W₂tms A σ ⟧)
𝑎𝑝𝑝β : {Γ : ctx} {A B : ty} (t : tm (Γ ⊹ A) B) (s : tm Γ A) →
𝑎𝑝𝑝 (Λ t) s ≡ t ⟦ 𝒾𝒹 Γ ⊕ s ⟧
𝑎𝑝𝑝η : {Γ : ctx} {A B : ty} (t : tm Γ (A ⇛ B)) →
t ≡ Λ (𝐴𝑝𝑝 t)
-- Some useful lemmas
⊕⊚ : {Γ Δ Σ : ctx} {A : ty} (σ : tms Δ Σ) (t : tm Δ A) (τ : tms Γ Δ) →
(σ ⊕ t) ⊚ τ ≡ (σ ⊚ τ) ⊕ (t ⟦ τ ⟧)
⊕⊚ σ t τ =
(σ ⊕ t) ⊚ τ
≡⟨ π𝑧η (σ ⊕ t ⊚ τ) ⁻¹ ⟩
π ⊚ (σ ⊕ t ⊚ τ) ⊕ 𝑧 ⟦ σ ⊕ t ⊚ τ ⟧
≡⟨ (λ i → ⊚Assoc π (σ ⊕ t) τ (~ i) ⊕ ⟦⟧⟦⟧ 𝑧 (σ ⊕ t) τ (~ i)) ⟩
π ⊚ (σ ⊕ t) ⊚ τ ⊕ 𝑧 ⟦ σ ⊕ t ⟧ ⟦ τ ⟧
≡⟨ (λ i → (π⟦⟧ (σ ⊕ t) i ⊚ τ) ⊕ (𝑧⟦⟧ (σ ⊕ t) i ⟦ τ ⟧)) ⟩
(σ ⊚ τ) ⊕ (t ⟦ τ ⟧)
∎
private
lem : {Γ Δ : ctx} {A : ty} (σ : tms Γ Δ) (t : tm Γ A) →
((σ ⊚ π) ⊕ 𝑧) ⊚ (𝒾𝒹 Γ ⊕ t) ≡ σ ⊕ t
lem {Γ} σ t =
((σ ⊚ π) ⊕ 𝑧) ⊚ (𝒾𝒹 Γ ⊕ t)
≡⟨ ⊕⊚ (σ ⊚ π) 𝑧 (𝒾𝒹 Γ ⊕ t) ⟩
σ ⊚ π ⊚ (𝒾𝒹 Γ ⊕ t) ⊕ 𝑧 ⟦ 𝒾𝒹 Γ ⊕ t ⟧
≡⟨ (λ i → ⊚Assoc σ π (𝒾𝒹 Γ ⊕ t) i ⊕ 𝑧⟦⟧ (𝒾𝒹 Γ ⊕ t) i) ⟩
σ ⊚ (π ⊚ (𝒾𝒹 Γ ⊕ t)) ⊕ t
≡⟨ (λ i → σ ⊚ (π⟦⟧ (𝒾𝒹 Γ ⊕ t) i) ⊕ t) ⟩
σ ⊚ 𝒾𝒹 Γ ⊕ t
≡⟨ ap (_⊕ t) (𝒾𝒹R σ) ⟩
σ ⊕ t
∎
𝐴𝑝𝑝β : {Γ : ctx} {A B : ty} (t : tm (Γ ⊹ A) B) →
𝐴𝑝𝑝 (Λ t) ≡ t
𝐴𝑝𝑝β {Γ} {A} {B} t =
𝑎𝑝𝑝 (Λ t ⟦ π ⟧) 𝑧
≡⟨ (λ i → 𝑎𝑝𝑝 (Λnat t π i) 𝑧) ⟩
𝑎𝑝𝑝 (Λ (t ⟦ (π ⊚ π) ⊕ 𝑧 ⟧)) 𝑧
≡⟨ 𝑎𝑝𝑝β (t ⟦ (π ⊚ π) ⊕ 𝑧 ⟧) 𝑧 ⟩
t ⟦ (π ⊚ π) ⊕ 𝑧 ⟧ ⟦ 𝒾𝒹 (Γ ⊹ A) ⊕ 𝑧 ⟧
≡⟨ ⟦⟧⟦⟧ t ((π ⊚ π) ⊕ 𝑧) (𝒾𝒹 (Γ ⊹ A) ⊕ 𝑧) ⟩
t ⟦ ((π ⊚ π) ⊕ 𝑧) ⊚ (𝒾𝒹 (Γ ⊹ A) ⊕ 𝑧) ⟧
≡⟨ ap (t ⟦_⟧) (lem π 𝑧) ⟩
t ⟦ π ⊕ 𝑧 ⟧
≡⟨ ap (t ⟦_⟧) 𝒾𝒹η₁ ⟩
t ⟦ 𝒾𝒹 (Γ ⊹ A) ⟧
≡⟨ 𝒾𝒹⟦⟧ t ⟩
t
∎
𝐴𝑝𝑝⟦⟧ : {Γ Δ : ctx} {A B : ty} (t : tm Δ (A ⇛ B)) (σ : tms Γ Δ) →
𝐴𝑝𝑝 (t ⟦ σ ⟧) ≡ (𝐴𝑝𝑝 t ⟦ σ ⊚ π ⊕ 𝑧 ⟧)
𝐴𝑝𝑝⟦⟧ t σ =
𝐴𝑝𝑝 (t ⟦ σ ⟧)
≡⟨ (λ i → 𝐴𝑝𝑝 (𝑎𝑝𝑝η t i ⟦ σ ⟧)) ⟩
𝐴𝑝𝑝 (Λ (𝐴𝑝𝑝 t) ⟦ σ ⟧)
≡⟨ ap 𝐴𝑝𝑝 (Λnat (𝐴𝑝𝑝 t) σ) ⟩
𝐴𝑝𝑝 (Λ (𝐴𝑝𝑝 t ⟦ σ ⊚ π ⊕ 𝑧 ⟧))
≡⟨ 𝐴𝑝𝑝β (𝐴𝑝𝑝 t ⟦ σ ⊚ π ⊕ 𝑧 ⟧) ⟩
𝐴𝑝𝑝 t ⟦ σ ⊚ π ⊕ 𝑧 ⟧
∎
𝑎𝑝𝑝𝐴𝑝𝑝 : {Γ : ctx} {A B : ty} (t : tm Γ (A ⇛ B)) (s : tm Γ A) →
𝑎𝑝𝑝 t s ≡ 𝐴𝑝𝑝 t ⟦ 𝒾𝒹 Γ ⊕ s ⟧
𝑎𝑝𝑝𝐴𝑝𝑝 {Γ} t s =
𝑎𝑝𝑝 t s
≡⟨ (λ i → 𝑎𝑝𝑝 (𝑎𝑝𝑝η t i) s) ⟩
𝑎𝑝𝑝 (Λ (𝐴𝑝𝑝 t)) s
≡⟨ 𝑎𝑝𝑝β (𝐴𝑝𝑝 t) s ⟩
𝐴𝑝𝑝 t ⟦ 𝒾𝒹 Γ ⊕ s ⟧
∎
-- We finally get to the substitution law for applications;
-- this follows from the axioms, with great difficulty.
𝑎𝑝𝑝⟦⟧ : {Γ Δ : ctx} {A B : ty} (t : tm Δ (A ⇛ B)) (s : tm Δ A) (σ : tms Γ Δ) →
𝑎𝑝𝑝 t s ⟦ σ ⟧ ≡ 𝑎𝑝𝑝 (t ⟦ σ ⟧) (s ⟦ σ ⟧)
𝑎𝑝𝑝⟦⟧ {Γ} {Δ} t s σ =
𝑎𝑝𝑝 t s ⟦ σ ⟧
≡⟨ ap (_⟦ σ ⟧) (𝑎𝑝𝑝𝐴𝑝𝑝 t s) ⟩
𝐴𝑝𝑝 t ⟦ 𝒾𝒹 Δ ⊕ s ⟧ ⟦ σ ⟧
≡⟨ ⟦⟧⟦⟧ (𝐴𝑝𝑝 t) (𝒾𝒹 Δ ⊕ s) σ ⟩
𝐴𝑝𝑝 t ⟦ 𝒾𝒹 Δ ⊕ s ⊚ σ ⟧
≡⟨ ap (𝐴𝑝𝑝 t ⟦_⟧) (⊕⊚ (𝒾𝒹 Δ) s σ) ⟩
𝐴𝑝𝑝 t ⟦ (𝒾𝒹 Δ) ⊚ σ ⊕ s ⟦ σ ⟧ ⟧
≡⟨ (λ i → 𝐴𝑝𝑝 t ⟦ 𝒾𝒹L σ i ⊕ s ⟦ σ ⟧ ⟧) ⟩
𝐴𝑝𝑝 t ⟦ σ ⊕ s ⟦ σ ⟧ ⟧
≡⟨ ap (𝐴𝑝𝑝 t ⟦_⟧) (lem σ (s ⟦ σ ⟧) ⁻¹) ⟩
𝐴𝑝𝑝 t ⟦ (σ ⊚ π ⊕ 𝑧) ⊚ (𝒾𝒹 Γ ⊕ s ⟦ σ ⟧) ⟧
≡⟨ ⟦⟧⟦⟧ (𝐴𝑝𝑝 t) (σ ⊚ π ⊕ 𝑧) (𝒾𝒹 Γ ⊕ s ⟦ σ ⟧) ⁻¹ ⟩
𝐴𝑝𝑝 t ⟦ σ ⊚ π ⊕ 𝑧 ⟧ ⟦ 𝒾𝒹 Γ ⊕ s ⟦ σ ⟧ ⟧
≡⟨ ap _⟦ 𝒾𝒹 Γ ⊕ s ⟦ σ ⟧ ⟧ (𝐴𝑝𝑝⟦⟧ t σ ⁻¹) ⟩
𝐴𝑝𝑝 (t ⟦ σ ⟧) ⟦ 𝒾𝒹 Γ ⊕ s ⟦ σ ⟧ ⟧
≡⟨ 𝑎𝑝𝑝𝐴𝑝𝑝 (t ⟦ σ ⟧) (s ⟦ σ ⟧) ⁻¹ ⟩
𝑎𝑝𝑝 (t ⟦ σ ⟧) (s ⟦ σ ⟧)
∎
-- A transport lemma
transp𝐴𝑝𝑝 : {Γ Δ : ctx} {A B : ty} (a : Γ ≡ Δ) (t : tm Γ (A ⇛ B)) →
transport (λ i → tm (a i ⊹ A) B) (𝐴𝑝𝑝 t) ≡ 𝐴𝑝𝑝 (transport (λ i → tm (a i) (A ⇛ B)) t)
transp𝐴𝑝𝑝 {A = A} {B} a t =
J (λ Δ a → transport (λ i → tm (a i ⊹ A) B) (𝐴𝑝𝑝 t)
≡ 𝐴𝑝𝑝 (transport (λ i → tm (a i) (A ⇛ B)) t))
(transportRefl (𝐴𝑝𝑝 t) ∙ ap 𝐴𝑝𝑝 (transportRefl t ⁻¹)) a