Model/SetTheory: the set theory as a record (no postulate), with cumulative universes for the strata fin k / ω+ m. Model/Interpretation: total interpretation of terms (levels as natural numbers), well-denotedness, and the renaming and substitution lemmas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q7dfaHQ3dYSfqcxR7V5UrJ
300 lines
15 KiB
Agda
300 lines
15 KiB
Agda
open import univTypes.Model.SetTheory using (SetTheory)
|
||
|
||
module univTypes.Model.Interpretation (S : SetTheory) where
|
||
|
||
open import Data.Nat using (ℕ; zero; suc; _⊔_)
|
||
open import Data.Fin using (Fin; zero; suc)
|
||
open import Data.Product using (Σ; _×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
|
||
open import Data.Unit using (⊤; tt)
|
||
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; cong₂; subst; subst₂)
|
||
|
||
open import univTypes.Specification
|
||
open import univTypes.Model.SetTheory using (Stratum; fin; ω+)
|
||
open SetTheory S
|
||
|
||
-- The meaning of terms and levels --------------------------------------------------
|
||
|
||
-- Terms denote sets, levels natural numbers. The interpretation is total
|
||
-- and reads no types (as in con-leche): junk terms get some meaning, and
|
||
-- well-denotedness (WD) says where the meaning is the intended one.
|
||
|
||
Den : Sort → Set
|
||
Den tm = V
|
||
Den lv = ℕ
|
||
|
||
Env : ℕ → Set
|
||
Env n = Fin n → V
|
||
|
||
infixl 5 _▹_
|
||
|
||
_▹_ : ∀ {n} → Env n → V → Env (suc n)
|
||
(ρ ▹ x) zero = x
|
||
(ρ ▹ x) (suc i) = ρ i
|
||
|
||
-- natrec on a meta-level number.
|
||
natrecᵛ : V → V → ℕ → V
|
||
natrecᵛ z s zero = z
|
||
natrecᵛ z s (suc k) = app (app s (fromℕ k)) (natrecᵛ z s k)
|
||
|
||
⟦_⟧ : ∀ {s n} → Tm s n → Env n → Den s
|
||
⟦ ` x ⟧ ρ = ρ x
|
||
⟦ `λ[x⦂ A ] b ⟧ ρ = lam (⟦ A ⟧ ρ) (λ x → ⟦ b ⟧ (ρ ▹ x))
|
||
⟦ f · a ⟧ ρ = app (⟦ f ⟧ ρ) (⟦ a ⟧ ρ)
|
||
⟦ ∀[x⦂ A ] B ⟧ ρ = Pi (⟦ A ⟧ ρ) (λ x → ⟦ B ⟧ (ρ ▹ x))
|
||
⟦ `Setω k ⟧ ρ = U (ω+ k)
|
||
⟦ `Setn l ⟧ ρ = U (fin (⟦ l ⟧ ρ))
|
||
⟦ `Level ⟧ ρ = ω
|
||
⟦ `lvl l ⟧ ρ = fromℕ (⟦ l ⟧ ρ)
|
||
⟦ `latom e ⟧ ρ = toℕ (⟦ e ⟧ ρ)
|
||
⟦ `lzero ⟧ ρ = 0
|
||
⟦ `lsuc l ⟧ ρ = suc (⟦ l ⟧ ρ)
|
||
⟦ l₁ `⊔ l₂ ⟧ ρ = ⟦ l₁ ⟧ ρ ⊔ ⟦ l₂ ⟧ ρ
|
||
⟦ ∃[x⦂ A ] B ⟧ ρ = Sig (⟦ A ⟧ ρ) (λ x → ⟦ B ⟧ (ρ ▹ x))
|
||
⟦ a `, b ⟧ ρ = pair (⟦ a ⟧ ρ) (⟦ b ⟧ ρ)
|
||
⟦ `proj₁ p ⟧ ρ = fst (⟦ p ⟧ ρ)
|
||
⟦ `proj₂ p ⟧ ρ = snd (⟦ p ⟧ ρ)
|
||
⟦ a `≡ b ⟧ ρ = Id (⟦ a ⟧ ρ) (⟦ b ⟧ ρ)
|
||
⟦ `refl ⟧ ρ = ⋆
|
||
⟦ `subst t e₁ e₂ ⟧ ρ = ⟦ e₂ ⟧ ρ
|
||
⟦ `Unit ⟧ ρ = ⊤ˢ
|
||
⟦ `tt ⟧ ρ = ⋆
|
||
⟦ `ℕ ⟧ ρ = ω
|
||
⟦ `zero ⟧ ρ = fromℕ 0
|
||
⟦ `suc k ⟧ ρ = fromℕ (suc (toℕ (⟦ k ⟧ ρ)))
|
||
⟦ `natrec P z s t ⟧ ρ = natrecᵛ (⟦ z ⟧ ρ) (⟦ s ⟧ ρ) (toℕ (⟦ t ⟧ ρ))
|
||
|
||
natrecᵛ-cong : ∀ {z z' s s' k k'} → z ≡ z' → s ≡ s' → k ≡ k' → natrecᵛ z s k ≡ natrecᵛ z' s' k'
|
||
natrecᵛ-cong refl refl refl = refl
|
||
|
||
-- Well-denotedness -----------------------------------------------------------------
|
||
|
||
-- The step function of natrec applies at every stage.
|
||
StepOK : V → V → Set
|
||
StepOK z s = ∀ k → fromℕ k ∈ dom s × natrecᵛ z s k ∈ dom (app s (fromℕ k))
|
||
|
||
-- Every application's argument lies in the function's domain (binders:
|
||
-- for every value of the bound variable in the domain); suc is applied to
|
||
-- a natural number; natrec's step applies at every stage. Under these
|
||
-- conditions reduction preserves the meaning (Model/Conversion).
|
||
WD : ∀ {s n} → Tm s n → Env n → Set
|
||
WD (` x) ρ = ⊤
|
||
WD (`λ[x⦂ A ] b) ρ = WD A ρ × (∀ {x} → x ∈ ⟦ A ⟧ ρ → WD b (ρ ▹ x))
|
||
WD (f · a) ρ = WD f ρ × WD a ρ × ⟦ a ⟧ ρ ∈ dom (⟦ f ⟧ ρ)
|
||
WD (∀[x⦂ A ] B) ρ = WD A ρ × (∀ {x} → x ∈ ⟦ A ⟧ ρ → WD B (ρ ▹ x))
|
||
WD (`Setω k) ρ = ⊤
|
||
WD (`Setn l) ρ = WD l ρ
|
||
WD `Level ρ = ⊤
|
||
WD (`lvl l) ρ = WD l ρ
|
||
WD (`latom e) ρ = WD e ρ
|
||
WD `lzero ρ = ⊤
|
||
WD (`lsuc l) ρ = WD l ρ
|
||
WD (l₁ `⊔ l₂) ρ = WD l₁ ρ × WD l₂ ρ
|
||
WD (∃[x⦂ A ] B) ρ = WD A ρ × (∀ {x} → x ∈ ⟦ A ⟧ ρ → WD B (ρ ▹ x))
|
||
WD (a `, b) ρ = WD a ρ × WD b ρ
|
||
WD (`proj₁ p) ρ = WD p ρ
|
||
WD (`proj₂ p) ρ = WD p ρ
|
||
WD (a `≡ b) ρ = WD a ρ × WD b ρ
|
||
WD `refl ρ = ⊤
|
||
WD (`subst t e₁ e₂) ρ = WD e₁ ρ × WD e₂ ρ
|
||
WD `Unit ρ = ⊤
|
||
WD `tt ρ = ⊤
|
||
WD `ℕ ρ = ⊤
|
||
WD `zero ρ = ⊤
|
||
WD (`suc k) ρ = WD k ρ × ⟦ k ⟧ ρ ∈ ω
|
||
WD (`natrec P z s t) ρ = WD z ρ × WD s ρ × WD t ρ × StepOK (⟦ z ⟧ ρ) (⟦ s ⟧ ρ)
|
||
|
||
-- Renaming ---------------------------------------------------------------------------
|
||
|
||
-- Renaming ρ, read in γ, agrees with δ.
|
||
_≗ᵣ_∘_ : ∀ {m n} → Env m → Env n → Ren m n → Set
|
||
δ ≗ᵣ γ ∘ ρ = ∀ i → γ (ρ i) ≡ δ i
|
||
|
||
ext≗ᵣ : ∀ {m n} {ρ : Ren m n} {γ : Env n} {δ : Env m} {x : V}
|
||
→ δ ≗ᵣ γ ∘ ρ → (δ ▹ x) ≗ᵣ (γ ▹ x) ∘ extᵣ ρ
|
||
ext≗ᵣ h zero = refl
|
||
ext≗ᵣ h (suc i) = h i
|
||
|
||
ren-⟦⟧ : ∀ {s m n} (ρ : Ren m n) {γ : Env n} {δ : Env m}
|
||
→ δ ≗ᵣ γ ∘ ρ → (e : Tm s m) → ⟦ ren ρ e ⟧ γ ≡ ⟦ e ⟧ δ
|
||
ren-⟦⟧ ρ h (` x) = h x
|
||
ren-⟦⟧ ρ h (`λ[x⦂ A ] b) = cong₂ lam (ren-⟦⟧ ρ h A) (fun-ext λ x → ren-⟦⟧ (extᵣ ρ) (ext≗ᵣ h) b)
|
||
ren-⟦⟧ ρ h (f · a) = cong₂ app (ren-⟦⟧ ρ h f) (ren-⟦⟧ ρ h a)
|
||
ren-⟦⟧ ρ h (∀[x⦂ A ] B) = cong₂ Pi (ren-⟦⟧ ρ h A) (fun-ext λ x → ren-⟦⟧ (extᵣ ρ) (ext≗ᵣ h) B)
|
||
ren-⟦⟧ ρ h (`Setω k) = refl
|
||
ren-⟦⟧ ρ h (`Setn l) = cong (λ k → U (fin k)) (ren-⟦⟧ ρ h l)
|
||
ren-⟦⟧ ρ h `Level = refl
|
||
ren-⟦⟧ ρ h (`lvl l) = cong fromℕ (ren-⟦⟧ ρ h l)
|
||
ren-⟦⟧ ρ h (`latom e) = cong toℕ (ren-⟦⟧ ρ h e)
|
||
ren-⟦⟧ ρ h `lzero = refl
|
||
ren-⟦⟧ ρ h (`lsuc l) = cong suc (ren-⟦⟧ ρ h l)
|
||
ren-⟦⟧ ρ h (l₁ `⊔ l₂) = cong₂ _⊔_ (ren-⟦⟧ ρ h l₁) (ren-⟦⟧ ρ h l₂)
|
||
ren-⟦⟧ ρ h (∃[x⦂ A ] B) = cong₂ Sig (ren-⟦⟧ ρ h A) (fun-ext λ x → ren-⟦⟧ (extᵣ ρ) (ext≗ᵣ h) B)
|
||
ren-⟦⟧ ρ h (a `, b) = cong₂ pair (ren-⟦⟧ ρ h a) (ren-⟦⟧ ρ h b)
|
||
ren-⟦⟧ ρ h (`proj₁ p) = cong fst (ren-⟦⟧ ρ h p)
|
||
ren-⟦⟧ ρ h (`proj₂ p) = cong snd (ren-⟦⟧ ρ h p)
|
||
ren-⟦⟧ ρ h (a `≡ b) = cong₂ Id (ren-⟦⟧ ρ h a) (ren-⟦⟧ ρ h b)
|
||
ren-⟦⟧ ρ h `refl = refl
|
||
ren-⟦⟧ ρ h (`subst t e₁ e₂) = ren-⟦⟧ ρ h e₂
|
||
ren-⟦⟧ ρ h `Unit = refl
|
||
ren-⟦⟧ ρ h `tt = refl
|
||
ren-⟦⟧ ρ h `ℕ = refl
|
||
ren-⟦⟧ ρ h `zero = refl
|
||
ren-⟦⟧ ρ h (`suc k) = cong (λ v → fromℕ (suc (toℕ v))) (ren-⟦⟧ ρ h k)
|
||
ren-⟦⟧ ρ h (`natrec P z s t) =
|
||
natrecᵛ-cong (ren-⟦⟧ ρ h z) (ren-⟦⟧ ρ h s) (cong toℕ (ren-⟦⟧ ρ h t))
|
||
|
||
-- Weakening: the new variable is not read.
|
||
wk-⟦⟧ : ∀ {s n} (e : Tm s n) (ρ : Env n) (x : V) → ⟦ ren wk e ⟧ (ρ ▹ x) ≡ ⟦ e ⟧ ρ
|
||
wk-⟦⟧ e ρ x = ren-⟦⟧ wk (λ i → refl) e
|
||
|
||
-- Membership in a renamed set.
|
||
∈-ren : ∀ {m n} {ρ : Ren m n} {γ : Env n} {δ : Env m} (h : δ ≗ᵣ γ ∘ ρ) (A : Term m) {x : V}
|
||
→ x ∈ ⟦ ren ρ A ⟧ γ → x ∈ ⟦ A ⟧ δ
|
||
∈-ren {ρ = ρ} h A = subst (_ ∈_) (ren-⟦⟧ ρ h A)
|
||
|
||
WD-ren : ∀ {s m n} (ρ : Ren m n) {γ : Env n} {δ : Env m}
|
||
→ δ ≗ᵣ γ ∘ ρ → (e : Tm s m) → WD e δ → WD (ren ρ e) γ
|
||
WD-ren ρ h (` x) w = tt
|
||
WD-ren ρ h (`λ[x⦂ A ] b) ⟨ wA , wb ⟩ =
|
||
⟨ WD-ren ρ h A wA , (λ x∈ → WD-ren (extᵣ ρ) (ext≗ᵣ h) b (wb (∈-ren h A x∈))) ⟩
|
||
WD-ren ρ h (f · a) ⟨ wf , ⟨ wa , d ⟩ ⟩ =
|
||
⟨ WD-ren ρ h f wf , ⟨ WD-ren ρ h a wa
|
||
, subst₂ (λ u v → u ∈ dom v) (sym (ren-⟦⟧ ρ h a)) (sym (ren-⟦⟧ ρ h f)) d ⟩ ⟩
|
||
WD-ren ρ h (∀[x⦂ A ] B) ⟨ wA , wB ⟩ =
|
||
⟨ WD-ren ρ h A wA , (λ x∈ → WD-ren (extᵣ ρ) (ext≗ᵣ h) B (wB (∈-ren h A x∈))) ⟩
|
||
WD-ren ρ h (`Setω k) w = tt
|
||
WD-ren ρ h (`Setn l) w = WD-ren ρ h l w
|
||
WD-ren ρ h `Level w = tt
|
||
WD-ren ρ h (`lvl l) w = WD-ren ρ h l w
|
||
WD-ren ρ h (`latom e) w = WD-ren ρ h e w
|
||
WD-ren ρ h `lzero w = tt
|
||
WD-ren ρ h (`lsuc l) w = WD-ren ρ h l w
|
||
WD-ren ρ h (l₁ `⊔ l₂) ⟨ w₁ , w₂ ⟩ = ⟨ WD-ren ρ h l₁ w₁ , WD-ren ρ h l₂ w₂ ⟩
|
||
WD-ren ρ h (∃[x⦂ A ] B) ⟨ wA , wB ⟩ =
|
||
⟨ WD-ren ρ h A wA , (λ x∈ → WD-ren (extᵣ ρ) (ext≗ᵣ h) B (wB (∈-ren h A x∈))) ⟩
|
||
WD-ren ρ h (a `, b) ⟨ wa , wb ⟩ = ⟨ WD-ren ρ h a wa , WD-ren ρ h b wb ⟩
|
||
WD-ren ρ h (`proj₁ p) w = WD-ren ρ h p w
|
||
WD-ren ρ h (`proj₂ p) w = WD-ren ρ h p w
|
||
WD-ren ρ h (a `≡ b) ⟨ wa , wb ⟩ = ⟨ WD-ren ρ h a wa , WD-ren ρ h b wb ⟩
|
||
WD-ren ρ h `refl w = tt
|
||
WD-ren ρ h (`subst t e₁ e₂) ⟨ w₁ , w₂ ⟩ = ⟨ WD-ren ρ h e₁ w₁ , WD-ren ρ h e₂ w₂ ⟩
|
||
WD-ren ρ h `Unit w = tt
|
||
WD-ren ρ h `tt w = tt
|
||
WD-ren ρ h `ℕ w = tt
|
||
WD-ren ρ h `zero w = tt
|
||
WD-ren ρ h (`suc k) ⟨ wk , k∈ ⟩ = ⟨ WD-ren ρ h k wk , subst (_∈ ω) (sym (ren-⟦⟧ ρ h k)) k∈ ⟩
|
||
WD-ren ρ h (`natrec P z s t) ⟨ wz , ⟨ ws , ⟨ wt , ok ⟩ ⟩ ⟩ =
|
||
⟨ WD-ren ρ h z wz , ⟨ WD-ren ρ h s ws , ⟨ WD-ren ρ h t wt
|
||
, subst₂ StepOK (sym (ren-⟦⟧ ρ h z)) (sym (ren-⟦⟧ ρ h s)) ok ⟩ ⟩ ⟩
|
||
|
||
WD-wk : ∀ {s n} (e : Tm s n) {ρ : Env n} {x : V} → WD e ρ → WD (ren wk e) (ρ ▹ x)
|
||
WD-wk e = WD-ren wk (λ i → refl) e
|
||
|
||
-- Substitution -----------------------------------------------------------------------
|
||
|
||
-- Substitution σ, read in γ, agrees with δ and is well-denoted.
|
||
record _≗ₛ_∘_ {m n} (δ : Env m) (γ : Env n) (σ : Sub m n) : Set where
|
||
field
|
||
val : ∀ i → ⟦ σ i ⟧ γ ≡ δ i
|
||
wd : ∀ i → WD (σ i) γ
|
||
open _≗ₛ_∘_
|
||
|
||
ext≗ₛ : ∀ {m n} {σ : Sub m n} {γ : Env n} {δ : Env m} {x : V}
|
||
→ δ ≗ₛ γ ∘ σ → (δ ▹ x) ≗ₛ (γ ▹ x) ∘ extₛ σ
|
||
val (ext≗ₛ h) zero = refl
|
||
val (ext≗ₛ {σ = σ} {γ} {x = x} h) (suc i) = trans (wk-⟦⟧ (σ i) γ x) (val h i)
|
||
wd (ext≗ₛ h) zero = tt
|
||
wd (ext≗ₛ {σ = σ} h) (suc i) = WD-wk (σ i) (wd h i)
|
||
|
||
-- Only the values matter for the meaning.
|
||
ext-val : ∀ {m n} {σ : Sub m n} {γ : Env n} {δ : Env m} {x : V}
|
||
→ (∀ i → ⟦ σ i ⟧ γ ≡ δ i) → ∀ i → ⟦ extₛ σ i ⟧ (γ ▹ x) ≡ (δ ▹ x) i
|
||
ext-val h zero = refl
|
||
ext-val {σ = σ} {γ} {x = x} h (suc i) = trans (wk-⟦⟧ (σ i) γ x) (h i)
|
||
|
||
sub-⟦⟧ : ∀ {s m n} (σ : Sub m n) {γ : Env n} {δ : Env m}
|
||
→ (∀ i → ⟦ σ i ⟧ γ ≡ δ i) → (e : Tm s m) → ⟦ sub σ e ⟧ γ ≡ ⟦ e ⟧ δ
|
||
sub-⟦⟧ σ h (` x) = h x
|
||
sub-⟦⟧ σ h (`λ[x⦂ A ] b) = cong₂ lam (sub-⟦⟧ σ h A) (fun-ext λ x → sub-⟦⟧ (extₛ σ) (ext-val h) b)
|
||
sub-⟦⟧ σ h (f · a) = cong₂ app (sub-⟦⟧ σ h f) (sub-⟦⟧ σ h a)
|
||
sub-⟦⟧ σ h (∀[x⦂ A ] B) = cong₂ Pi (sub-⟦⟧ σ h A) (fun-ext λ x → sub-⟦⟧ (extₛ σ) (ext-val h) B)
|
||
sub-⟦⟧ σ h (`Setω k) = refl
|
||
sub-⟦⟧ σ h (`Setn l) = cong (λ k → U (fin k)) (sub-⟦⟧ σ h l)
|
||
sub-⟦⟧ σ h `Level = refl
|
||
sub-⟦⟧ σ h (`lvl l) = cong fromℕ (sub-⟦⟧ σ h l)
|
||
sub-⟦⟧ σ h (`latom e) = cong toℕ (sub-⟦⟧ σ h e)
|
||
sub-⟦⟧ σ h `lzero = refl
|
||
sub-⟦⟧ σ h (`lsuc l) = cong suc (sub-⟦⟧ σ h l)
|
||
sub-⟦⟧ σ h (l₁ `⊔ l₂) = cong₂ _⊔_ (sub-⟦⟧ σ h l₁) (sub-⟦⟧ σ h l₂)
|
||
sub-⟦⟧ σ h (∃[x⦂ A ] B) = cong₂ Sig (sub-⟦⟧ σ h A) (fun-ext λ x → sub-⟦⟧ (extₛ σ) (ext-val h) B)
|
||
sub-⟦⟧ σ h (a `, b) = cong₂ pair (sub-⟦⟧ σ h a) (sub-⟦⟧ σ h b)
|
||
sub-⟦⟧ σ h (`proj₁ p) = cong fst (sub-⟦⟧ σ h p)
|
||
sub-⟦⟧ σ h (`proj₂ p) = cong snd (sub-⟦⟧ σ h p)
|
||
sub-⟦⟧ σ h (a `≡ b) = cong₂ Id (sub-⟦⟧ σ h a) (sub-⟦⟧ σ h b)
|
||
sub-⟦⟧ σ h `refl = refl
|
||
sub-⟦⟧ σ h (`subst t e₁ e₂) = sub-⟦⟧ σ h e₂
|
||
sub-⟦⟧ σ h `Unit = refl
|
||
sub-⟦⟧ σ h `tt = refl
|
||
sub-⟦⟧ σ h `ℕ = refl
|
||
sub-⟦⟧ σ h `zero = refl
|
||
sub-⟦⟧ σ h (`suc k) = cong (λ v → fromℕ (suc (toℕ v))) (sub-⟦⟧ σ h k)
|
||
sub-⟦⟧ σ h (`natrec P z s t) =
|
||
natrecᵛ-cong (sub-⟦⟧ σ h z) (sub-⟦⟧ σ h s) (cong toℕ (sub-⟦⟧ σ h t))
|
||
|
||
∈-sub : ∀ {m n} {σ : Sub m n} {γ : Env n} {δ : Env m} (h : ∀ i → ⟦ σ i ⟧ γ ≡ δ i) (A : Term m) {x : V}
|
||
→ x ∈ ⟦ sub σ A ⟧ γ → x ∈ ⟦ A ⟧ δ
|
||
∈-sub {σ = σ} h A = subst (_ ∈_) (sub-⟦⟧ σ h A)
|
||
|
||
WD-sub : ∀ {s m n} (σ : Sub m n) {γ : Env n} {δ : Env m}
|
||
→ δ ≗ₛ γ ∘ σ → (e : Tm s m) → WD e δ → WD (sub σ e) γ
|
||
WD-sub σ h (` x) w = wd h x
|
||
WD-sub σ h (`λ[x⦂ A ] b) ⟨ wA , wb ⟩ =
|
||
⟨ WD-sub σ h A wA , (λ x∈ → WD-sub (extₛ σ) (ext≗ₛ h) b (wb (∈-sub (val h) A x∈))) ⟩
|
||
WD-sub σ h (f · a) ⟨ wf , ⟨ wa , d ⟩ ⟩ =
|
||
⟨ WD-sub σ h f wf , ⟨ WD-sub σ h a wa
|
||
, subst₂ (λ u v → u ∈ dom v) (sym (sub-⟦⟧ σ (val h) a)) (sym (sub-⟦⟧ σ (val h) f)) d ⟩ ⟩
|
||
WD-sub σ h (∀[x⦂ A ] B) ⟨ wA , wB ⟩ =
|
||
⟨ WD-sub σ h A wA , (λ x∈ → WD-sub (extₛ σ) (ext≗ₛ h) B (wB (∈-sub (val h) A x∈))) ⟩
|
||
WD-sub σ h (`Setω k) w = tt
|
||
WD-sub σ h (`Setn l) w = WD-sub σ h l w
|
||
WD-sub σ h `Level w = tt
|
||
WD-sub σ h (`lvl l) w = WD-sub σ h l w
|
||
WD-sub σ h (`latom e) w = WD-sub σ h e w
|
||
WD-sub σ h `lzero w = tt
|
||
WD-sub σ h (`lsuc l) w = WD-sub σ h l w
|
||
WD-sub σ h (l₁ `⊔ l₂) ⟨ w₁ , w₂ ⟩ = ⟨ WD-sub σ h l₁ w₁ , WD-sub σ h l₂ w₂ ⟩
|
||
WD-sub σ h (∃[x⦂ A ] B) ⟨ wA , wB ⟩ =
|
||
⟨ WD-sub σ h A wA , (λ x∈ → WD-sub (extₛ σ) (ext≗ₛ h) B (wB (∈-sub (val h) A x∈))) ⟩
|
||
WD-sub σ h (a `, b) ⟨ wa , wb ⟩ = ⟨ WD-sub σ h a wa , WD-sub σ h b wb ⟩
|
||
WD-sub σ h (`proj₁ p) w = WD-sub σ h p w
|
||
WD-sub σ h (`proj₂ p) w = WD-sub σ h p w
|
||
WD-sub σ h (a `≡ b) ⟨ wa , wb ⟩ = ⟨ WD-sub σ h a wa , WD-sub σ h b wb ⟩
|
||
WD-sub σ h `refl w = tt
|
||
WD-sub σ h (`subst t e₁ e₂) ⟨ w₁ , w₂ ⟩ = ⟨ WD-sub σ h e₁ w₁ , WD-sub σ h e₂ w₂ ⟩
|
||
WD-sub σ h `Unit w = tt
|
||
WD-sub σ h `tt w = tt
|
||
WD-sub σ h `ℕ w = tt
|
||
WD-sub σ h `zero w = tt
|
||
WD-sub σ h (`suc k) ⟨ wk , k∈ ⟩ =
|
||
⟨ WD-sub σ h k wk , subst (_∈ ω) (sym (sub-⟦⟧ σ (val h) k)) k∈ ⟩
|
||
WD-sub σ h (`natrec P z s t) ⟨ wz , ⟨ ws , ⟨ wt , ok ⟩ ⟩ ⟩ =
|
||
⟨ WD-sub σ h z wz , ⟨ WD-sub σ h s ws , ⟨ WD-sub σ h t wt
|
||
, subst₂ StepOK (sym (sub-⟦⟧ σ (val h) z)) (sym (sub-⟦⟧ σ (val h) s)) ok ⟩ ⟩ ⟩
|
||
|
||
-- Single substitution.
|
||
0↦-val : ∀ {n} (a : Term n) (ρ : Env n) → ∀ i → ⟦ 0↦ a i ⟧ ρ ≡ (ρ ▹ ⟦ a ⟧ ρ) i
|
||
0↦-val a ρ zero = refl
|
||
0↦-val a ρ (suc i) = refl
|
||
|
||
[]-⟦⟧ : ∀ {s n} (e : Tm s (suc n)) (a : Term n) (ρ : Env n) → ⟦ e [ a ] ⟧ ρ ≡ ⟦ e ⟧ (ρ ▹ ⟦ a ⟧ ρ)
|
||
[]-⟦⟧ e a ρ = sub-⟦⟧ (0↦ a) (0↦-val a ρ) e
|
||
|
||
WD-[] : ∀ {s n} (e : Tm s (suc n)) {a : Term n} {ρ : Env n}
|
||
→ WD a ρ → WD e (ρ ▹ ⟦ a ⟧ ρ) → WD (e [ a ]) ρ
|
||
WD-[] e {a} {ρ} wa = WD-sub (0↦ a) h e
|
||
where
|
||
h : (ρ ▹ ⟦ a ⟧ ρ) ≗ₛ ρ ∘ 0↦ a
|
||
val h = 0↦-val a ρ
|
||
wd h zero = wa
|
||
wd h (suc i) = tt
|