Files
JKFandClaude Opus 5.5 a658081632 Add unit type Unit with tt
`Unit : Set and `tt : `Unit, both values and inert under renaming,
substitution, reduction and level equality. Cases added throughout
confluence, conversion, the level normaliser, substitution lemmas,
subject reduction and progress (new head hUnit for canonical forms).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 16:49:14 +01:00

87 lines
3.1 KiB
Agda
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module univTypes.SubjectReduction.Specification.Substitution where
open import Data.Nat using (ℕ; suc)
open import Data.Fin using (Fin; zero; suc)
open import univTypes.SubjectReduction.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 ρ (`λ e) = `λ (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
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 σ (`λ e) = `λ (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
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₁