{-# OPTIONS --safe --cubical-compatible --guardedness --exact-split --double-check #-}
module ALMA.Cosmos.Carried.LimitSystemS where
open import Agda.Primitive using (Level; lzero)
open import Agda.Builtin.Sigma using (Σ; _,_)
open import Agda.Builtin.Equality using (_≡_; refl)
open import Data.Nat.Base 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; m≥n⇒m⊓n≡n)
open import Data.Fin.Base using (Fin; zero; suc; toℕ; inject₁)
open import Data.Fin.Properties using (toℕ-injective; toℕ-inject₁; toℕ<n)
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
open import Data.Unit.Polymorphic.Base using (⊤; tt)
open import Relation.Binary.PropositionalEquality.Core using (cong; trans; sym)
open import ALMA.Base.MCorr using (M)
open import ALMA.Base.MCorrSetoid using (SysEq; propEqOn; _≈Mˢ_; idAdjˢ)
open import ALMA.Base.MCorrSetoidPush using (PushSimˢ)
open import ALMA.Cosmos.Carried.FinProj using (clamp; clamp-val)
open SysEq
n-at : ℕ → ℕ
n-at m = suc (suc m)
natToFin : (v : ℕ) → Fin (n-at v)
natToFin zero = zero
natToFin (suc v) = suc (natToFin v)
toℕ-natToFin : (v : ℕ) → toℕ (natToFin v) ≡ v
toℕ-natToFin zero = refl
toℕ-natToFin (suc v) = cong suc (toℕ-natToFin v)
TrivDetˢ : {i : Level} (I : Set i) (step : I → I)
→ SysEq i lzero i lzero i
TrivDetˢ {i = i} I step = record
{ I = I
; A = λ _ → ⊤ {lzero}
; E = λ x _ y → Σ (⊤ {lzero}) λ _ → y ≡ step x
; ≈A = λ _ → propEqOn (⊤ {lzero})
; ≈E = λ { x _ y → propEqOn (Σ (⊤ {lzero}) λ _ → y ≡ step x) }
}
module LimitSystemS
(t : (m : ℕ) → Fin (n-at m) → Fin (n-at m))
(embed-compat :
(m : ℕ) (x : Fin (n-at m))
→ t (suc m) (inject₁ x) ≡ inject₁ (t m x))
where
s∞ : ℕ → ℕ
s∞ v = toℕ (t v (natToFin v))
L∞ : SysEq lzero lzero lzero lzero lzero
L∞ = TrivDetˢ ℕ s∞
orbit∞ : (x : ℕ) → M (A L∞) (E L∞) x
orbit∞ x .M.here = tt
orbit∞ x .M.below y _ = orbit∞ y
cl : (m k : ℕ) → Fin (n-at m)
cl m k = clamp {k = suc m} k
cl-toℕ : ∀ m k (le : k ≤ suc m) → toℕ (cl m k) ≡ k
cl-toℕ m k le =
trans (clamp-val {k = suc m} k) (m≥n⇒m⊓n≡n le)
private
up-toℕ : ∀ m x → toℕ (t (suc m) (inject₁ x)) ≡ toℕ (t m x)
up-toℕ m x =
trans (cong toℕ (embed-compat m x)) (toℕ-inject₁ (t m x))
inj-clamp : ∀ p k (le : k ≤ suc p)
→ cl (suc p) k ≡ inject₁ (cl p k)
inj-clamp 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))))
inj-top : ∀ s → inject₁ (cl s (suc s)) ≡ natToFin (suc s)
inj-top s =
toℕ-injective
(trans (trans (toℕ-inject₁ (cl s (suc s)))
(cl-toℕ s (suc s) ≤-refl))
(sym (toℕ-natToFin (suc s))))
top-read : ∀ s → toℕ (t s (cl s (suc s))) ≡ s∞ (suc s)
top-read s =
sym
(trans (cong toℕ (cong (t (suc s)) (sym (inj-top s))))
(trans (cong toℕ (embed-compat s (cl s (suc s))))
(toℕ-inject₁ (t s (cl s (suc s))))))
private
read-cl : ∀ m k (le : k ≤ suc m) → toℕ (t m (cl m k)) ≡ s∞ k
read-cl zero k le
with m≤n⇒m<n∨m≡n le
... | inj₂ eq rewrite eq = top-read zero
... | inj₁ lt rewrite n≤0⇒n≡0 (≤-pred lt) = refl
read-cl (suc p) k le
with m≤n⇒m<n∨m≡n le
... | inj₂ eq rewrite eq = top-read (suc p)
... | inj₁ lt =
let le' : k ≤ suc p
le' = ≤-pred lt
in trans (cong toℕ (cong (t (suc p)) (inj-clamp p k le')))
(trans (up-toℕ p (cl p k))
(read-cl p k le'))
read-coh : ∀ m (x : Fin (n-at m)) → toℕ (t m x) ≡ s∞ (toℕ x)
read-coh m x =
let le : toℕ x ≤ suc m
le = ≤-pred (toℕ<n x)
eqx : x ≡ cl m (toℕ x)
eqx = toℕ-injective (sym (cl-toℕ m (toℕ x) le))
in trans (cong toℕ (cong (t m) eqx))
(read-cl m (toℕ x) le)
module Leg (m : ℕ) where
Stage : SysEq lzero lzero lzero lzero lzero
Stage = TrivDetˢ (Fin (n-at m)) (t m)
orbit-fin : (x : Fin (n-at m)) → M (A Stage) (E Stage) x
orbit-fin x .M.here = tt
orbit-fin x .M.below y _ = orbit-fin y
Rₘ : Fin (n-at m) → ℕ → Set lzero
Rₘ x v = toℕ x ≡ v
Hₘ : (x : Fin (n-at m)) (v : ℕ) → Rₘ x v
→ A Stage x → A L∞ v → Set lzero
Hₘ _ _ _ _ _ = ⊤ {lzero}
leg : ∀ (x : Fin (n-at m)) (v : ℕ) (r : Rₘ x v)
→ PushSimˢ Stage L∞ Rₘ Hₘ r (orbit-fin x) (orbit∞ v)
leg x v r .PushSimˢ.here-eq = tt
leg x v r .PushSimˢ.push y (_ , eq) =
s∞ v , ((tt , refl) , (r' , leg y (s∞ v) r'))
where
r' : toℕ y ≡ s∞ v
r' = trans (cong toℕ eq)
(trans (read-coh m x) (cong s∞ r))
det-unique : ∀ (x : ℕ) (t u : M (A L∞) (E L∞) x)
→ _≈Mˢ_ (≈A L∞) (≈E L∞) t u
det-unique x t u ._≈Mˢ_.here-eq = refl
det-unique x t u ._≈Mˢ_.below-eq y =
idAdjˢ (≈E L∞ x (M.here u) y)
, ( (λ e₁ → det-unique y (M.below t y e₁) (M.below u y e₁))
, (λ e₂ → det-unique y (M.below u y e₂) (M.below t y e₂)) )