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

178 lines
6.3 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.Typing where
open import Data.Nat using (ℕ; zero; suc) renaming (_⊔_ to _⊔ℕ_)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Data.Fin using (Fin; zero; suc)
open import univTypes.SubjectReduction.Specification.Syntax
open import univTypes.SubjectReduction.Specification.Substitution
open import univTypes.SubjectReduction.Specification.Conversion
infix 4 _⊢_⦂_ _⊢ₗ_
infixl 5 _,_
data Context : ℕ → Set where
∅ : Context zero
_,_ : ∀ {n} → Context n → Term n → Context (suc n)
lookup : ∀ {n} → Context n → Fin n → Term n
lookup (Γ , e) zero = ren wk e
lookup (Γ , e) (suc x) = ren wk (lookup Γ x)
-- Typing of terms, and well-formedness of level expressions (_⊢ₗ_).
data _⊢_⦂_ : ∀ {n} → Context n → Term n → Term n → Set
data _⊢ₗ_ : ∀ {n} → Context n → Lvl n → Set
data _⊢_⦂_ where
⊢-` : ∀ {n t} {Γ : Context n} (x : Fin n)
→ lookup Γ x ≡ t
--------------
→ Γ ⊢ ` x ⦂ t
-- Every type is in some Setω l (small types via ⊢-Set<Setω).
⊢-λ : ∀ {n} {Γ : Context n} {e : Term (suc n)} {t₁ : Term n} {l : ℕ} {t₂ : Term (suc n)}
→ Γ ⊢ t₁ ⦂ `Setω l
→ Γ , t₁ ⊢ e ⦂ t₂
-----------------------
→ Γ ⊢ `λ e ⦂ ∀[x⦂ t₁ ] t₂
⊢-· : ∀ {n} {Γ : Context n} {e₁ e₂ : Term n} {t₁ : Term n} {t₂ : Term (suc n)}
→ Γ ⊢ e₁ ⦂ ∀[x⦂ t₁ ] t₂
→ Γ ⊢ e₂ ⦂ t₁
-----------------------
→ Γ ⊢ e₁ · e₂ ⦂ t₂ [ e₂ ]
-- The codomain level is a weakened outer level, so it cannot mention x.
⊢-∀ : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ l₂ : Lvl n} {t₂ : Term (suc n)}
→ Γ ⊢ t₁ ⦂ `Setn l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setn (ren wk l₂)
------------------------------------
-- succ l₁
→ Γ ⊢ ∀[x⦂ t₁ ] t₂ ⦂ `Setn (l₁ `⊔ l₂)
-- Setω levels are natural numbers, so the codomain level cannot mention x.
⊢-∀ω : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ l₂ : ℕ} {t₂ : Term (suc n)}
→ Γ ⊢ t₁ ⦂ `Setω l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setω l₂
------------------------------------
→ Γ ⊢ ∀[x⦂ t₁ ] t₂ ⦂ `Setω (l₁ ⊔ℕ l₂)
-- The codomain level may mention x (e.g. ∀ l → Set l). Overlaps with
-- ⊢-∀ when it does not, which is harmless because of ⊢-Set<Setω.
⊢-∀-dep : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ : ℕ} {t₂ : Term (suc n)} {l₂ : Lvl (suc n)}
→ Γ ⊢ t₁ ⦂ `Setω l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setn l₂
------------------------------
→ Γ ⊢ ∀[x⦂ t₁ ] t₂ ⦂ `Setω l₁
⊢-≈ : ∀ {n} {Γ : Context n} {e : Term n} {t t' : Term n}
→ t ≈ t'
→ Γ ⊢ e ⦂ t
------------
→ Γ ⊢ e ⦂ t'
-- ∃ mirrors ∀: ⊢-∃, ⊢-∃ω and ⊢-∃-dep.
⊢-∃ : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ l₂ : Lvl n} {t₂ : Term (suc n)}
→ Γ ⊢ t₁ ⦂ `Setn l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setn (ren wk l₂)
------------------------------------
→ Γ ⊢ ∃[x⦂ t₁ ] t₂ ⦂ `Setn (l₁ `⊔ l₂)
⊢-∃ω : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ l₂ : ℕ} {t₂ : Term (suc n)}
→ Γ ⊢ t₁ ⦂ `Setω l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setω l₂
------------------------------------
→ Γ ⊢ ∃[x⦂ t₁ ] t₂ ⦂ `Setω (l₁ ⊔ℕ l₂)
⊢-∃-dep : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ : ℕ} {t₂ : Term (suc n)} {l₂ : Lvl (suc n)}
→ Γ ⊢ t₁ ⦂ `Setω l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setn l₂
------------------------------
→ Γ ⊢ ∃[x⦂ t₁ ] t₂ ⦂ `Setω l₁
⊢-, : ∀ {n} {Γ : Context n} {e₁ e₂ : Term n} {t₁ : Term n} {t₂ : Term (suc n)}
→ Γ ⊢ e₁ ⦂ t₁
→ Γ ⊢ e₂ ⦂ t₂ [ e₁ ]
-----------------------
→ Γ ⊢ (e₁ `, e₂) ⦂ ∃[x⦂ t₁ ] t₂
⊢-proj₁ : ∀ {n} {Γ : Context n} {e : Term n} {t₁ : Term n} {t₂ : Term (suc n)}
→ Γ ⊢ e ⦂ ∃[x⦂ t₁ ] t₂
→ Γ ⊢ `proj₁ e ⦂ t₁
⊢-proj₂ : ∀ {n} {Γ : Context n} {e : Term n} {t₁ : Term n} {t₂ : Term (suc n)}
→ Γ ⊢ e ⦂ ∃[x⦂ t₁ ] t₂
→ Γ ⊢ `proj₂ e ⦂ t₂ [ `proj₁ e ]
⊢-≡ : ∀ {n} {Γ : Context n} {e₁ e₂ t : Term n} {l : Lvl n}
→ Γ ⊢ t ⦂ `Setn l
→ Γ ⊢ e₁ ⦂ t
→ Γ ⊢ e₂ ⦂ t
----------------------------
→ Γ ⊢ (e₁ `≡ e₂) ⦂ `Setn l
⊢-refl : ∀ {n} {Γ : Context n} {e t : Term n}
→ Γ ⊢ e ⦂ t
------------------
→ Γ ⊢ `refl ⦂ e `≡ e
⊢-subst : ∀ {n} {Γ : Context n} {e₁ e₂ u₁ u₂ : Term n} {l : Lvl n} {t' : Term n} {t : Term (suc n)}
→ Γ , t' ⊢ t ⦂ `Setn (ren wk l)
→ Γ ⊢ u₁ ⦂ t'
→ Γ ⊢ u₂ ⦂ t'
→ Γ ⊢ e₁ ⦂ (u₁ `≡ u₂)
→ Γ ⊢ e₂ ⦂ t [ u₁ ]
------------------------------
→ Γ ⊢ `subst t e₁ e₂ ⦂ t [ u₂ ]
-- Extension
⊢-Setn : ∀ {n} {Γ : Context n} {l}
→ Γ ⊢ₗ l
→ Γ ⊢ `Setn l ⦂ (`Setn (`lsuc l))
⊢-Setω : ∀ {n} {Γ : Context n} {l}
→ Γ ⊢ `Setω l ⦂ (`Setω (suc l))
⊢-lvl : ∀ {n} {Γ : Context n} {l}
→ Γ ⊢ₗ l
→ Γ ⊢ `lvl l ⦂ `Level
⊢-Level : ∀ {n} {Γ : Context n}
→ Γ ⊢ `Level ⦂ `Set
-- Cumulativity
⊢-Set<Setω : ∀ {n} {Γ : Context n} {A : Term n} {l : Lvl n}
→ Γ ⊢ A ⦂ `Setn l
-------------------
→ Γ ⊢ A ⦂ `Setω 0
-- ⊢-Setω≤ : ∀ {n} {Γ : Context n} {A : Term n} {l : Lvl n}
-- → Γ ⊢ A ⦂ `Setω l
-- ----------------------
-- → Γ ⊢ A ⦂ `Setω (`lsuc l)
⊢-tt : ∀ {n} {Γ : Context n}
→ Γ ⊢ `tt ⦂ `Unit
⊢-Unit : ∀ {n} {Γ : Context n}
→ Γ ⊢ `Unit ⦂ `Set
data _⊢ₗ_ where
⊢-latom : ∀ {n} {Γ : Context n} {e}
→ Γ ⊢ e ⦂ `Level
→ Γ ⊢ₗ `latom e
⊢-lzero : ∀ {n} {Γ : Context n}
→ Γ ⊢ₗ `lzero
⊢-lsuc : ∀ {n} {Γ : Context n} {l}
→ Γ ⊢ₗ l
→ Γ ⊢ₗ `lsuc l
⊢-⊔ : ∀ {n} {Γ : Context n} {l₁ l₂}
→ Γ ⊢ₗ l₁
→ Γ ⊢ₗ l₂
→ Γ ⊢ₗ (l₁ `⊔ l₂)