Files
Julius FischerandClaude Opus 5.5 48d3f9040b
Typecheck / agda (push) Failing after 7s
⊢-∀ / ⊢-∃: the codomain level must be well formed
Over an empty domain the codomain derivation says nothing about the level
l₂, so the set-theoretic model needs Γ ⊢ₗ l₂ (cf. con-leche's
certification tax). This replaces the planned premise on ⊢-≈, which the
model avoids by stating soundness up to conversion. Proofs, tests and
Examples/Issue pass the premise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q7dfaHQ3dYSfqcxR7V5UrJ
2026-11-22 21:27:08 +01:00

208 lines
7.4 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.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.Specification.Syntax
open import univTypes.Specification.Substitution
open import univTypes.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₂
-----------------------
→ Γ ⊢ `λ[x⦂ 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.
-- It must be well formed: over an empty domain the codomain says nothing
-- about it (needed by the set-theoretic model).
⊢-∀ : ∀ {n} {Γ : Context n} {t₁ : Term n} {l₁ l₂ : Lvl n} {t₂ : Term (suc n)}
→ Γ ⊢ t₁ ⦂ `Setn l₁
→ Γ , t₁ ⊢ t₂ ⦂ `Setn (ren wk l₂)
→ Γ ⊢ₗ 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₂)
→ Γ ⊢ₗ 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₁
-- The codomain must be a type (the second component only fixes it at e₁).
⊢-, : ∀ {n} {Γ : Context n} {e₁ e₂ : Term n} {t₁ : Term n} {t₂ : Term (suc n)} {l : ℕ}
→ Γ ⊢ e₁ ⦂ t₁
→ Γ ⊢ e₂ ⦂ t₂ [ e₁ ]
→ Γ , t₁ ⊢ t₂ ⦂ `Setω l
-----------------------
→ Γ ⊢ (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
⊢-zero : ∀ {n} {Γ : Context n}
→ Γ ⊢ `zero ⦂ `ℕ
⊢-suc : ∀ {n} {Γ : Context n} {k : Term n}
→ Γ ⊢ k ⦂ `ℕ
→ Γ ⊢ (`suc k) ⦂ `ℕ
⊢-ℕ : ∀ {n} {Γ : Context n}
→ Γ ⊢ `ℕ ⦂ `Set
⊢-natrec : ∀ {n} {Γ : Context n} {P z s t : Term n} {l : Lvl n}
→ Γ ⊢ P ⦂ ∀[x⦂ `ℕ ] `Setn (ren wk l)
→ Γ ⊢ z ⦂ P · `zero
→ Γ ⊢ s ⦂ ∀[x⦂ `ℕ ] ∀[x⦂ ren wk P · ` zero ] (ren wk (ren wk P) · `suc (` suc zero))
→ Γ ⊢ t ⦂ `ℕ
→ Γ ⊢ `natrec P z s t ⦂ P · t
⊢-natrecω : ∀ {n} {Γ : Context n} {P z s t : Term n} {m : ℕ}
→ Γ ⊢ P ⦂ ∀[x⦂ `ℕ ] `Setω m
→ Γ ⊢ z ⦂ P · `zero
→ Γ ⊢ s ⦂ ∀[x⦂ `ℕ ] ∀[x⦂ ren wk P · ` zero ] (ren wk (ren wk P) · `suc (` suc zero))
→ Γ ⊢ t ⦂ `ℕ
→ Γ ⊢ `natrec P z s t ⦂ P · t
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₂)