{-# OPTIONS --safe --cubical-compatible --guardedness --exact-split --double-check #-}
module ALMA.Cosmos.Carried.FinColimit where
open import Agda.Builtin.Sigma using (Σ; _,_)
open import Agda.Builtin.Equality using (_≡_; refl)
open import Data.Nat using (ℕ; zero; suc; _≤_)
open import Data.Nat.Properties using
( ≤-pred; ≤-refl; m≤n⇒m≤1+n; m≤n⇒m<n∨m≡n; n≤0⇒n≡0 )
open import Data.Fin.Base using (Fin; zero; toℕ; inject₁)
open import Data.Fin.Properties using (toℕ-injective; toℕ-inject₁; toℕ<n)
open import Data.Sum.Base using (inj₁; inj₂)
open import Relation.Binary.PropositionalEquality.Core using (cong; sym; trans)
open import ALMA.Cosmos.Carried.SeqColimit using (shift)
open import ALMA.Cosmos.Carried.LimitSystem using
(n-at; natToFin; toℕ-natToFin; embFin; cl; cl-toℕ)
top-eq : ∀ m → inject₁ (cl m (suc m)) ≡ natToFin (suc m)
top-eq m =
toℕ-injective
(trans (toℕ-inject₁ (cl m (suc m)))
(trans (cl-toℕ m (suc m) ≤-refl)
(sym (toℕ-natToFin (suc m)))))
inj-cl : ∀ p k (le : k ≤ suc p)
→ cl (suc p) k ≡ inject₁ (cl p k)
inj-cl p k le =
toℕ-injective
(trans (cl-toℕ (suc p) k (m≤n⇒m≤1+n le))
(sym (trans (toℕ-inject₁ (cl p k))
(cl-toℕ p k le))))
record FinCone (X : Set) : Set where
field
at : ∀ m → Fin (n-at m) → X
compat : ∀ m (x : Fin (n-at m))
→ at (suc m) (inject₁ x) ≡ at m x
compat-emb : ∀ d m (x : Fin (n-at m))
→ at (shift d m) (embFin d m x) ≡ at m x
compat-emb zero m x = refl
compat-emb (suc d) m x =
trans (compat-emb d (suc m) (inject₁ x))
(compat m x)
at-cl : ∀ m k (le : k ≤ suc m)
→ at m (cl m k) ≡ at k (natToFin k)
at-cl zero k le
with m≤n⇒m<n∨m≡n le
... | inj₂ eq rewrite eq =
sym (trans (cong (at (suc zero)) (sym (top-eq zero)))
(compat zero (cl zero (suc zero))))
... | inj₁ lt rewrite n≤0⇒n≡0 (≤-pred lt) = refl
at-cl (suc p) k le
with m≤n⇒m<n∨m≡n le
... | inj₂ eq rewrite eq =
sym (trans (cong (at (suc (suc p))) (sym (top-eq (suc p))))
(compat (suc p) (cl (suc p) (suc (suc p)))))
... | inj₁ lt =
let le' : k ≤ suc p
le' = ≤-pred lt
in trans (cong (at (suc p)) (inj-cl p k le'))
(trans (compat p (cl p k))
(at-cl p k le'))
g∞ : ℕ → X
g∞ k = at k (natToFin k)
extends : ∀ m (x : Fin (n-at m)) → g∞ (toℕ x) ≡ at m x
extends m x =
let k : ℕ
k = toℕ x
le : k ≤ suc m
le = ≤-pred (toℕ<n x)
eqx : x ≡ cl m k
eqx = toℕ-injective (sym (cl-toℕ m k le))
in trans (sym (at-cl m k le))
(cong (at m) (sym eqx))
unique : (h : ℕ → X)
→ (∀ m (x : Fin (n-at m)) → h (toℕ x) ≡ at m x)
→ ∀ k → h k ≡ g∞ k
unique h h-ext k =
trans (cong h (sym (toℕ-natToFin k)))
(h-ext k (natToFin k))
open FinCone public
colimitUniv
: ∀ {X : Set} (cone : FinCone X)
→ Σ (ℕ → X) λ g∞ →
Σ (∀ m (x : Fin (n-at m)) → g∞ (toℕ x) ≡ at cone m x) λ _ →
(∀ (h : ℕ → X)
→ (∀ m (x : Fin (n-at m)) → h (toℕ x) ≡ at cone m x)
→ ∀ k → h k ≡ g∞ k)
colimitUniv cone = g∞ cone , (extends cone , unique cone)