2023-12-01 12:52:23 -05:00
|
|
|
|
namespace pair {
|
|
|
|
|
|
2023-12-19 20:08:54 -05:00
|
|
|
|
def0 Σ : (A : ★) → (A → ★) → ★ = λ A B ⇒ (x : A) × B x
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def uncurry :
|
|
|
|
|
0.(A : ★) → 0.(B : A → ★) → 0.(C : (x : A) → (B x) → ★) →
|
|
|
|
|
(f : (x : A) → (y : B x) → C x y) →
|
|
|
|
|
(p : Σ A B) → C (fst p) (snd p) =
|
|
|
|
|
λ A B C f p ⇒
|
2023-12-19 20:08:54 -05:00
|
|
|
|
case p return p' ⇒ C (fst p') (snd p') of { (x, y) ⇒ f x y }
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def uncurry' :
|
|
|
|
|
0.(A B C : ★) → (A → B → C) → (A × B) → C =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B C ⇒ uncurry A (λ _ ⇒ B) (λ _ _ ⇒ C)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def curry :
|
|
|
|
|
0.(A : ★) → 0.(B : A → ★) → 0.(C : (Σ A B) → ★) →
|
|
|
|
|
(f : (p : Σ A B) → C p) → (x : A) → (y : B x) → C (x, y) =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B C f x y ⇒ f (x, y)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def curry' :
|
|
|
|
|
0.(A B C : ★) → (A × B → C) → A → B → C =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B C ⇒ curry A (λ _ ⇒ B) (λ _ ⇒ C)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def0 fst-snd :
|
|
|
|
|
(A : ★) → (B : A → ★) →
|
|
|
|
|
(p : Σ A B) → p ≡ (fst p, snd p) : Σ A B =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B p ⇒ δ 𝑖 ⇒ p -- η
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def0 fst-eq :
|
|
|
|
|
(A : ★) → (B : A → ★) →
|
|
|
|
|
(p q : Σ A B) → p ≡ q : Σ A B → fst p ≡ fst q : A =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B p q eq ⇒ δ 𝑖 ⇒ fst (eq @𝑖)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def0 snd-eq :
|
|
|
|
|
(A : ★) → (B : A → ★) →
|
|
|
|
|
(p q : Σ A B) → (eq : p ≡ q : Σ A B) →
|
|
|
|
|
Eq (𝑖 ⇒ B (fst-eq A B p q eq @𝑖)) (snd p) (snd q) =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B p q eq ⇒ δ 𝑖 ⇒ snd (eq @𝑖)
|
|
|
|
|
|
|
|
|
|
def0 pair-eq :
|
|
|
|
|
(A : ★) → (B : A → ★) →
|
|
|
|
|
(x0 x1 : A) → (y0 : B x0) → (y1 : B x1) →
|
|
|
|
|
(xx : x0 ≡ x1 : A) → (yy : Eq (𝑖 ⇒ B (xx @𝑖)) y0 y1) →
|
|
|
|
|
(x0, y0) ≡ (x1, y1) : ((x : A) × B x) =
|
|
|
|
|
λ A B x0 x1 y0 y1 xx yy ⇒ δ 𝑖 ⇒ (xx @𝑖, yy @𝑖)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def map :
|
|
|
|
|
0.(A A' : ★) →
|
|
|
|
|
0.(B : A → ★) → 0.(B' : A' → ★) →
|
|
|
|
|
(f : A → A') → (g : 0.(x : A) → (B x) → B' (f x)) →
|
|
|
|
|
Σ A B → Σ A' B' =
|
|
|
|
|
λ A A' B B' f g p ⇒
|
2023-12-19 20:08:54 -05:00
|
|
|
|
case p return Σ A' B' of { (x, y) ⇒ (f x, g x y) }
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def map' : 0.(A A' B B' : ★) → (A → A') → (B → B') → (A × B) → A' × B' =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A A' B B' f g ⇒ map A A' (λ _ ⇒ B) (λ _ ⇒ B') f (λ _ ⇒ g)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def map-fst : 0.(A A' B : ★) → (A → A') → A × B → A' × B =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A A' B f ⇒ map' A A' B B f (λ x ⇒ x)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def map-snd : 0.(A B B' : ★) → (B → B') → A × B → A × B' =
|
2023-12-19 20:08:54 -05:00
|
|
|
|
λ A B B' f ⇒ map' A A B B' (λ x ⇒ x) f
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-19 20:08:54 -05:00
|
|
|
|
def0 Σ = pair.Σ
|