Typecheck / agda (push) Successful in 1m52s
Preparation for the set-theoretic model, where a λ denotes the graph of its body over its domain. ⊢-λ uses the annotation as the domain; reduction also reduces it (ξ-λ₁) and β discards it, so inductive SN and the backward closure get a side condition for it. All proofs, tests and Examples/Issue (annotations only) are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q7dfaHQ3dYSfqcxR7V5UrJ
95 lines
3.5 KiB
Agda
95 lines
3.5 KiB
Agda
module univTypes.Specification.Substitution where
|
||
|
||
open import Data.Nat using (ℕ; suc)
|
||
|
||
open import Data.Fin using (Fin; zero; suc)
|
||
open import univTypes.Specification.Syntax
|
||
|
||
infixl 12 _[_]
|
||
|
||
-- Renamings
|
||
|
||
Ren : ℕ → ℕ → Set
|
||
Ren m n = Fin m → Fin n
|
||
|
||
extᵣ : ∀ {m n} → Ren m n → Ren (suc m) (suc n)
|
||
extᵣ ρ zero = zero
|
||
extᵣ ρ (suc x) = suc (ρ x)
|
||
|
||
ren : ∀ {s m n}
|
||
→ Ren m n
|
||
→ (Tm s m → Tm s n)
|
||
ren ρ (` x) = ` (ρ x)
|
||
ren ρ (`λ[x⦂ A ] e) = `λ[x⦂ ren ρ A ] (ren (extᵣ ρ) e)
|
||
ren ρ (e₁ · e₂) = (ren ρ e₁) · (ren ρ e₂)
|
||
ren ρ (∀[x⦂ e₁ ] e₂) = ∀[x⦂ ren ρ e₁ ] ren (extᵣ ρ) e₂
|
||
ren ρ (`Setω l) = `Setω l
|
||
ren ρ (`Setn x) = `Setn ren ρ x
|
||
ren ρ `Level = `Level
|
||
ren ρ (`lvl l) = `lvl (ren ρ l)
|
||
ren ρ (`latom e) = `latom (ren ρ e)
|
||
ren ρ `lzero = `lzero
|
||
ren ρ (`lsuc l) = `lsuc (ren ρ l)
|
||
ren ρ (l `⊔ r) = (ren ρ l) `⊔ (ren ρ r)
|
||
ren ρ (∃[x⦂ t₁ ] t₂) = ∃[x⦂ ren ρ t₁ ] ren (extᵣ ρ) t₂
|
||
ren ρ (e₁ `, e₂) = (ren ρ e₁) `, (ren ρ e₂)
|
||
ren ρ (`proj₁ e) = `proj₁ (ren ρ e)
|
||
ren ρ (`proj₂ e) = `proj₂ (ren ρ e)
|
||
ren ρ `refl = `refl
|
||
ren ρ (e₁ `≡ e₂) = ren ρ e₁ `≡ ren ρ e₂
|
||
ren ρ (`subst t e₁ e₂) = `subst (ren (extᵣ ρ) t) (ren ρ e₁) (ren ρ e₂)
|
||
ren ρ `tt = `tt
|
||
ren ρ `Unit = `Unit
|
||
ren ρ `zero = `zero
|
||
ren ρ `ℕ = `ℕ
|
||
ren ρ (`suc k) = `suc (ren ρ k)
|
||
ren ρ (`natrec P z s t) = `natrec (ren ρ P) (ren ρ z) (ren ρ s) (ren ρ t)
|
||
|
||
wk : ∀ {n} → Ren n (suc n)
|
||
wk x = suc x
|
||
|
||
-- Substitutions (variables are terms, so a substitution maps to terms)
|
||
|
||
Sub : ℕ → ℕ → Set
|
||
Sub m n = Fin m → Term n
|
||
|
||
extₛ : ∀ {m n} → Sub m n → Sub (suc m) (suc n)
|
||
extₛ σ zero = ` zero
|
||
extₛ σ (suc x) = ren wk (σ x)
|
||
|
||
sub : ∀ {s m n}
|
||
→ Sub m n
|
||
→ (Tm s m → Tm s n)
|
||
sub σ (` x) = σ x
|
||
sub σ (`λ[x⦂ A ] e) = `λ[x⦂ sub σ A ] (sub (extₛ σ) e)
|
||
sub σ (e₁ · e₂) = (sub σ e₁) · (sub σ e₂)
|
||
sub σ (∀[x⦂ e₁ ] e₂) = ∀[x⦂ sub σ e₁ ] sub (extₛ σ) e₂
|
||
sub σ (`Setω l) = `Setω l
|
||
sub σ (`Setn l) = `Setn sub σ l
|
||
sub σ (`Level) = `Level
|
||
sub σ (`lvl l) = `lvl (sub σ l)
|
||
sub σ (`latom e) = `latom (sub σ e)
|
||
sub σ `lzero = `lzero
|
||
sub σ (`lsuc l) = `lsuc (sub σ l)
|
||
sub σ (l `⊔ r) = (sub σ l) `⊔ (sub σ r)
|
||
sub σ (∃[x⦂ t₁ ] t₂) = ∃[x⦂ sub σ t₁ ] sub (extₛ σ) t₂
|
||
sub σ (e₁ `, e₂) = (sub σ e₁) `, (sub σ e₂)
|
||
sub σ (`proj₁ e) = `proj₁ (sub σ e)
|
||
sub σ (`proj₂ e) = `proj₂ (sub σ e)
|
||
sub σ `refl = `refl
|
||
sub σ (e₁ `≡ e₂) = sub σ e₁ `≡ sub σ e₂
|
||
sub σ (`subst t e₁ e₂) = `subst (sub (extₛ σ) t) (sub σ e₁) (sub σ e₂)
|
||
sub σ `tt = `tt
|
||
sub σ `Unit = `Unit
|
||
sub σ `zero = `zero
|
||
sub σ `ℕ = `ℕ
|
||
sub σ (`suc k) = `suc (sub σ k)
|
||
sub σ (`natrec P z s t) = `natrec (sub σ P) (sub σ z) (sub σ s) (sub σ t)
|
||
|
||
0↦ : ∀ {n} → Term n → Sub (suc n) n
|
||
(0↦ e) zero = e
|
||
(0↦ e) (suc x) = ` x
|
||
|
||
_[_] : ∀ {s n} → Tm s (suc n) → Term n → Tm s n
|
||
e₁ [ e₂ ] = sub (0↦ e₂) e₁
|