open import univTypes.Model.SetTheory using (SetTheory) module univTypes.Model.Soundness (S : SetTheory) where open import Data.Empty using (⊥; ⊥-elim) open import Data.Nat using (ℕ; zero; suc; _⊔_; z≤n) open import Data.Nat.Properties using (m≤m⊔n; m≤n⊔m; n<1+n) open import Data.Fin using (Fin; zero; suc) open import Data.Product using (Σ; _×_; ∃-syntax; 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.Metatheory.Confluence.Conversion using (≈-refl; ≈-sym; ≈-trans; ≈-∀; ≈-∃; ≈-sub; ≈-ext; _≈ᶜ_; ≈-Setn; ≈-⊔) open import univTypes.Metatheory.Typing.Inversion using (↪~*-∀-shape; ↪~*-∃-shape; ↪~*-≡-shape; ↪~*-Setn-shape; ↪~*-Setω-shape) open import univTypes.Metatheory.Levels.Equality using (~→≋; _≋_) open _≋_ open import univTypes.Model.SetTheory using (Stratum; fin; ω+; fin≤; finω; ω≤; fin<; ω<) open SetTheory S open import univTypes.Model.Interpretation S open import univTypes.Model.Conversion S -- Soundness of typing for the set-theoretic model, up to conversion (as -- the fundamental theorem of Decidability/): a well-typed term is -- well-denoted and its meaning is a member of the meaning of some -- well-denoted witness W ≈ T. The witness is syntactic, so it does not -- depend on the environment. Typing does not make types well-denoted -- (⊢-≈ accepts junk such as (λy. Set) · Ω), so T itself need not have a -- meaning; contexts are replaced by convertible semantic contexts Δ for the -- same reason. -- Semantic contexts and judgements ------------------------------------------------------- infix 4 _⊨ᶜ_ _⊨_⦂_ _≃ᶜ_ -- An environment satisfying a context (a record, so that both can be -- inferred). record _⊨ᶜ_ {n} (ρ : Env n) (Δ : Context n) : Set where constructor env field get : ∀ x → WD (lookup Δ x) ρ × ρ x ∈ ⟦ lookup Δ x ⟧ ρ open _⊨ᶜ_ ⊨ᶜ-ext : ∀ {n} {Δ : Context n} {A : Term n} {ρ : Env n} {x : V} → ρ ⊨ᶜ Δ → WD A ρ → x ∈ ⟦ A ⟧ ρ → (ρ ▹ x) ⊨ᶜ (Δ , A) ⊨ᶜ-ext {Δ = Δ} {A} {ρ} {x} h wA x∈ = env g where g : ∀ i → _ g zero = ⟨ WD-wk A wA , subst (x ∈_) (sym (wk-⟦⟧ A ρ x)) x∈ ⟩ g (suc i) = ⟨ WD-wk (lookup Δ i) (proj₁ (get h i)) , subst (ρ i ∈_) (sym (wk-⟦⟧ (lookup Δ i) ρ x)) (proj₂ (get h i)) ⟩ -- Convertible contexts, as a record so that both contexts can be inferred. record _≃ᶜ_ {n} (Δ Γ : Context n) : Set where constructor ctx≃ field at : Δ ≈ᶜ Γ open _≃ᶜ_ ext≃ : ∀ {n} {Δ Γ : Context n} {A B : Term n} → Δ ≃ᶜ Γ → A ≈ B → (Δ , A) ≃ᶜ (Γ , B) ext≃ (ctx≃ p) q = ctx≃ (≈-ext p q) record _⊨_⦂_ {n} (Δ : Context n) (e T : Term n) : Set where constructor sem field W : Term n W≈ : W ≈ T ok : ∀ ρ → ρ ⊨ᶜ Δ → WD e ρ × WD W ρ × ⟦ e ⟧ ρ ∈ ⟦ W ⟧ ρ open _⊨_⦂_ -- Witnesses of type formers ----------------------------------------------------------------- ↪~*→≈ : ∀ {s n} {e e' : Tm s n} → e ↪~* e' → e ≈ e' ↪~*→≈ rs = mk-≈ _ rs ↪~*-refl -- The common reduct of the witness and the type, with the same meaning. reductW : ∀ {n} {Δ : Context n} {e T : Term n} → Δ ⊨ e ⦂ T → Σ (Term n) λ u → T ↪~* u × (∀ ρ → ρ ⊨ᶜ Δ → WD e ρ × WD u ρ × ⟦ e ⟧ ρ ∈ ⟦ u ⟧ ρ) reductW (sem W (mk-≈ u p q) ok) = ⟨ u , ⟨ q , okᵤ ⟩ ⟩ where okᵤ : ∀ ρ → _ → _ okᵤ ρ h with ok ρ h ... | ⟨ we , ⟨ wW , m ⟩ ⟩ with ↪~*-sem p wW ... | ⟨ wu , eq ⟩ = ⟨ we , ⟨ wu , subst (_ ∈_) eq m ⟩ ⟩ record IsΠ {n} (Δ : Context n) (f A : Term n) (B : Term (suc n)) : Set where field A₁ : Term n B₁ : Term (suc n) A≈ : A ≈ A₁ B≈ : B ≈ B₁ okΠ : ∀ ρ → ρ ⊨ᶜ Δ → WD f ρ × WD A₁ ρ × (∀ {x} → x ∈ ⟦ A₁ ⟧ ρ → WD B₁ (ρ ▹ x)) × ⟦ f ⟧ ρ ∈ Pi (⟦ A₁ ⟧ ρ) (λ x → ⟦ B₁ ⟧ (ρ ▹ x)) asΠ : ∀ {n} {Δ : Context n} {f A : Term n} {B : Term (suc n)} → Δ ⊨ f ⦂ ∀[x⦂ A ] B → IsΠ Δ f A B asΠ S with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-∀-shape q ... | ⟨ A₁ , ⟨ B₁ , ⟨ refl , ⟨ rA , rB ⟩ ⟩ ⟩ ⟩ = record { A₁ = A₁ ; B₁ = B₁ ; A≈ = ↪~*→≈ rA ; B≈ = ↪~*→≈ rB ; okΠ = λ ρ h → let ⟨ wf , ⟨ ⟨ wA , wB ⟩ , m ⟩ ⟩ = okᵤ ρ h in ⟨ wf , ⟨ wA , ⟨ wB , m ⟩ ⟩ ⟩ } record IsΣ {n} (Δ : Context n) (p A : Term n) (B : Term (suc n)) : Set where field A₁ : Term n B₁ : Term (suc n) A≈ : A ≈ A₁ B≈ : B ≈ B₁ okΣ : ∀ ρ → ρ ⊨ᶜ Δ → WD p ρ × WD A₁ ρ × (∀ {x} → x ∈ ⟦ A₁ ⟧ ρ → WD B₁ (ρ ▹ x)) × ⟦ p ⟧ ρ ∈ Sig (⟦ A₁ ⟧ ρ) (λ x → ⟦ B₁ ⟧ (ρ ▹ x)) asΣ : ∀ {n} {Δ : Context n} {p A : Term n} {B : Term (suc n)} → Δ ⊨ p ⦂ ∃[x⦂ A ] B → IsΣ Δ p A B asΣ S with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-∃-shape q ... | ⟨ A₁ , ⟨ B₁ , ⟨ refl , ⟨ rA , rB ⟩ ⟩ ⟩ ⟩ = record { A₁ = A₁ ; B₁ = B₁ ; A≈ = ↪~*→≈ rA ; B≈ = ↪~*→≈ rB ; okΣ = λ ρ h → let ⟨ wp , ⟨ ⟨ wA , wB ⟩ , m ⟩ ⟩ = okᵤ ρ h in ⟨ wp , ⟨ wA , ⟨ wB , m ⟩ ⟩ ⟩ } record IsId {n} (Δ : Context n) (e a b : Term n) : Set where field a₁ : Term n b₁ : Term n a≈ : a ≈ a₁ b≈ : b ≈ b₁ okId : ∀ ρ → ρ ⊨ᶜ Δ → WD e ρ × WD a₁ ρ × WD b₁ ρ × ⟦ e ⟧ ρ ∈ Id (⟦ a₁ ⟧ ρ) (⟦ b₁ ⟧ ρ) asId : ∀ {n} {Δ : Context n} {e a b : Term n} → Δ ⊨ e ⦂ a `≡ b → IsId Δ e a b asId S with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-≡-shape q ... | ⟨ a₁ , ⟨ b₁ , ⟨ refl , ⟨ ra , rb ⟩ ⟩ ⟩ ⟩ = record { a₁ = a₁ ; b₁ = b₁ ; a≈ = ↪~*→≈ ra ; b≈ = ↪~*→≈ rb ; okId = λ ρ h → let ⟨ we , ⟨ ⟨ wa , wb ⟩ , m ⟩ ⟩ = okᵤ ρ h in ⟨ we , ⟨ wa , ⟨ wb , m ⟩ ⟩ ⟩ } record IsU {n} (Δ : Context n) (e : Term n) (l : Lvl n) : Set where field l₁ : Lvl n l≈ : l ≈ l₁ okU : ∀ ρ → ρ ⊨ᶜ Δ → WD e ρ × WD l₁ ρ × ⟦ e ⟧ ρ ∈ U (fin (⟦ l₁ ⟧ ρ)) asU : ∀ {n} {Δ : Context n} {e : Term n} {l : Lvl n} → Δ ⊨ e ⦂ `Setn l → IsU Δ e l asU S with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-Setn-shape q ... | ⟨ l₁ , ⟨ refl , rl ⟩ ⟩ = record { l₁ = l₁ ; l≈ = ↪~*→≈ rl ; okU = okᵤ } asUω : ∀ {n} {Δ : Context n} {e : Term n} {k : ℕ} → Δ ⊨ e ⦂ `Setω k → ∀ ρ → ρ ⊨ᶜ Δ → WD e ρ × ⟦ e ⟧ ρ ∈ U (ω+ k) asUω S ρ h with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-Setω-shape q ... | refl = let ⟨ we , ⟨ _ , m ⟩ ⟩ = okᵤ ρ h in ⟨ we , m ⟩ -- ℕ only reaches itself. ↪~*-ℕ-shape : ∀ {n} {t : Term n} → `ℕ ↪~* t → t ≡ `ℕ ↪~*-ℕ-shape ↪~*-refl = refl ↪~*-ℕ-shape (↪~*-step (↪~-↪ ()) _) ↪~*-ℕ-shape (↪~*-step (↪~-~ p) rs) with ~→≋ p ... | ≋-ℕ = ↪~*-ℕ-shape rs asℕ : ∀ {n} {Δ : Context n} {e : Term n} → Δ ⊨ e ⦂ `ℕ → ∀ ρ → ρ ⊨ᶜ Δ → WD e ρ × ⟦ e ⟧ ρ ∈ ω asℕ S ρ h with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-ℕ-shape q ... | refl = let ⟨ we , ⟨ _ , m ⟩ ⟩ = okᵤ ρ h in ⟨ we , m ⟩ -- False only reaches itself, and has no members. ↪~*-False-shape : ∀ {n} {t : Term n} → `False ↪~* t → t ≡ `False ↪~*-False-shape ↪~*-refl = refl ↪~*-False-shape (↪~*-step (↪~-↪ ()) _) ↪~*-False-shape (↪~*-step (↪~-~ p) rs) with ~→≋ p ... | ≋-False = ↪~*-False-shape rs asFalse : ∀ {n} {Δ : Context n} {e : Term n} → Δ ⊨ e ⦂ `False → ∀ ρ → ρ ⊨ᶜ Δ → ⊥ asFalse S ρ h with reductW S ... | ⟨ u , ⟨ q , okᵤ ⟩ ⟩ with ↪~*-False-shape q ... | refl = ∅-empty (proj₂ (proj₂ (okᵤ ρ h))) -- natrec ------------------------------------------------------------------------------------ -- The type of natrec's step function. Step : ∀ {n} → Term n → Term n Step P = ∀[x⦂ `ℕ ] ∀[x⦂ ren wk P · ` zero ] (ren wk (ren wk P) · `suc (` suc zero)) module _ {n} (P : Term n) (ρ : Env n) (wP : WD P ρ) (domP : dom (⟦ P ⟧ ρ) ≡ ω) where wk²-⟦⟧ : ∀ x y → ⟦ ren wk (ren wk P) ⟧ (ρ ▹ x ▹ y) ≡ ⟦ P ⟧ ρ wk²-⟦⟧ x y = trans (wk-⟦⟧ (ren wk P) (ρ ▹ x) y) (wk-⟦⟧ P ρ x) Step-WD : WD (Step P) ρ Step-WD = ⟨ tt , (λ {x} x∈ → ⟨ ⟨ WD-wk P wP , ⟨ tt , subst (x ∈_) (sym (trans (cong dom (wk-⟦⟧ P ρ x)) domP)) x∈ ⟩ ⟩ , (λ {y} y∈ → ⟨ WD-wk (ren wk P) (WD-wk P wP) , ⟨ ⟨ tt , x∈ ⟩ , subst (fromℕ (suc (toℕ x)) ∈_) (sym (trans (cong dom (wk²-⟦⟧ x y)) domP)) fromℕ-∈ ⟩ ⟩) ⟩) ⟩ Step-⟦⟧ : ⟦ Step P ⟧ ρ ≡ Pi ω (λ x → Pi (app (⟦ P ⟧ ρ) x) (λ _ → app (⟦ P ⟧ ρ) (fromℕ (suc (toℕ x))))) Step-⟦⟧ = cong (Pi ω) (fun-ext λ x → cong₂ Pi (cong (λ v → app v x) (wk-⟦⟧ P ρ x)) (fun-ext λ y → cong (λ v → app v (fromℕ (suc (toℕ x)))) (wk²-⟦⟧ x y))) -- The recursion, at every stage. natrec-∈ : ∀ {z s : V} → z ∈ app (⟦ P ⟧ ρ) (fromℕ 0) → s ∈ Pi ω (λ x → Pi (app (⟦ P ⟧ ρ) x) (λ _ → app (⟦ P ⟧ ρ) (fromℕ (suc (toℕ x))))) → ∀ k → natrecᵛ z s k ∈ app (⟦ P ⟧ ρ) (fromℕ k) natrec-∈ z∈ s∈ zero = z∈ natrec-∈ {z} {s} z∈ s∈ (suc k) = subst (λ j → app (app s (fromℕ k)) (natrecᵛ z s k) ∈ app (⟦ P ⟧ ρ) (fromℕ (suc j))) (toℕ-fromℕ k) (app-∈ (app-∈ s∈ fromℕ-∈) (natrec-∈ z∈ s∈ k)) natrec-ok : ∀ {z s : V} → z ∈ app (⟦ P ⟧ ρ) (fromℕ 0) → s ∈ Pi ω (λ x → Pi (app (⟦ P ⟧ ρ) x) (λ _ → app (⟦ P ⟧ ρ) (fromℕ (suc (toℕ x))))) → StepOK z s natrec-ok {z} {s} z∈ s∈ k = ⟨ subst (fromℕ k ∈_) (sym (Pi-dom s∈)) fromℕ-∈ , subst (natrecᵛ z s k ∈_) (sym (Pi-dom (app-∈ s∈ fromℕ-∈))) (natrec-∈ z∈ s∈ k) ⟩ -- The fundamental lemma ----------------------------------------------------------------------- sound : ∀ {n} {Γ Δ : Context n} {e T : Term n} → Δ ≃ᶜ Γ → Γ ⊢ e ⦂ T → Δ ⊨ e ⦂ T soundₗ : ∀ {n} {Γ Δ : Context n} {l : Lvl n} → Δ ≃ᶜ Γ → Γ ⊢ₗ l → ∀ ρ → ρ ⊨ᶜ Δ → WD l ρ -- natrec, for both rules (the motive's codomain is not used). sem-natrec : ∀ {n} {Δ : Context n} {P z s t : Term n} {B : Term (suc n)} → Δ ⊨ P ⦂ ∀[x⦂ `ℕ ] B → Δ ⊨ z ⦂ P · `zero → Δ ⊨ s ⦂ Step P → Δ ⊨ t ⦂ `ℕ → Δ ⊨ `natrec P z s t ⦂ P · t sem-natrec {P = P} {z} {s} {t} SP Sz Ss St = sem (P · t) ≈-refl okN where module Π = IsΠ (asΠ SP) okN : ∀ ρ → _ → _ okN ρ h with Π.okΠ ρ h | ok Sz ρ h | ok Ss ρ h | asℕ St ρ h ... | ⟨ wP , ⟨ wA , ⟨ _ , mP ⟩ ⟩ ⟩ | ⟨ wz , ⟨ wWz , mz ⟩ ⟩ | ⟨ ws , ⟨ wWs , ms ⟩ ⟩ | ⟨ wt , t∈ ⟩ = ⟨ ⟨ wz , ⟨ ws , ⟨ wt , natrec-ok P ρ wP domP z∈ s∈ ⟩ ⟩ ⟩ , ⟨ ⟨ wP , ⟨ wt , subst (⟦ t ⟧ ρ ∈_) (sym domP) t∈ ⟩ ⟩ , subst (λ v → natrecᵛ (⟦ z ⟧ ρ) (⟦ s ⟧ ρ) (toℕ (⟦ t ⟧ ρ)) ∈ app (⟦ P ⟧ ρ) v) (ω-elim t∈) (natrec-∈ P ρ wP domP z∈ s∈ (toℕ (⟦ t ⟧ ρ))) ⟩ ⟩ where A₁ω : ⟦ Π.A₁ ⟧ ρ ≡ ω A₁ω = ≈-sem (≈-sym Π.A≈) wA tt domP : dom (⟦ P ⟧ ρ) ≡ ω domP = trans (Pi-dom mP) A₁ω z∈ : ⟦ z ⟧ ρ ∈ app (⟦ P ⟧ ρ) (fromℕ 0) z∈ = subst (_ ∈_) (≈-sem (W≈ Sz) wWz ⟨ wP , ⟨ tt , subst (_ ∈_) (sym domP) fromℕ-∈ ⟩ ⟩) mz s∈ = subst (_ ∈_) (trans (≈-sem (W≈ Ss) wWs (Step-WD P ρ wP domP)) (Step-⟦⟧ P ρ wP domP)) ms -- Small type formers (∀ and ∃ in Set): the stratum is the join of the -- domain's and the codomain's. sem-formerF : ∀ {n} {Γ Δ : Context n} {A : Term n} {B : Term (suc n)} {l₁ l₂ : Lvl n} (F : V → (V → V) → V) (F-U : ∀ {β A G} → A ∈ U β → (∀ {x} → x ∈ A → G x ∈ U β) → F A G ∈ U β) (former : Term n → Term (suc n) → Term n) (WD-former : ∀ {ρ} → WD A ρ × (∀ {x} → x ∈ ⟦ A ⟧ ρ → WD B (ρ ▹ x)) → WD (former A B) ρ) (⟦former⟧ : ∀ {ρ} → ⟦ former A B ⟧ ρ ≡ F (⟦ A ⟧ ρ) (λ x → ⟦ B ⟧ (ρ ▹ x))) → Δ ≃ᶜ Γ → Δ ⊨ A ⦂ `Setn l₁ → (Δ , A) ⊨ B ⦂ `Setn (ren wk l₂) → (∀ ρ → ρ ⊨ᶜ Δ → WD l₂ ρ) → Δ ⊨ former A B ⦂ `Setn (l₁ `⊔ l₂) sem-formerF {A = A} {B} {l₁} {l₂} F F-U former WD-former ⟦former⟧ Δ≈ SA SB wl₂ = sem (`Setn (UA.l₁ `⊔ l₂)) (≈-Setn (≈-⊔ (≈-sym UA.l≈) ≈-refl)) okF where module UA = IsU (asU SA) module UB = IsU (asU SB) okF : ∀ ρ → _ → _ okF ρ h with UA.okU ρ h ... | ⟨ wA , ⟨ wL₁ , mA ⟩ ⟩ = ⟨ WD-former ⟨ wA , (λ {x} x∈ → proj₁ (UB.okU _ (⊨ᶜ-ext h wA x∈))) ⟩ , ⟨ ⟨ wL₁ , wl₂ ρ h ⟩ , subst (_∈ U (fin (⟦ UA.l₁ ⟧ ρ ⊔ ⟦ l₂ ⟧ ρ))) (sym ⟦former⟧) (F-U (U-⊆ (fin≤ (m≤m⊔n _ _)) mA) (λ {x} x∈ → cod x x∈)) ⟩ ⟩ where cod : ∀ x → x ∈ ⟦ A ⟧ ρ → ⟦ B ⟧ (ρ ▹ x) ∈ U (fin (⟦ UA.l₁ ⟧ ρ ⊔ ⟦ l₂ ⟧ ρ)) cod x x∈ with UB.okU (ρ ▹ x) (⊨ᶜ-ext h wA x∈) ... | ⟨ _ , ⟨ wL₂ , mB ⟩ ⟩ = U-⊆ (fin≤ (m≤n⊔m _ _)) (subst (λ k → _ ∈ U (fin k)) (trans (≈-sem (≈-sym UB.l≈) wL₂ (WD-wk l₂ (wl₂ ρ h))) (wk-⟦⟧ l₂ ρ x)) mB) -- Large type formers (∀ and ∃ in Setω). sem-formerW : ∀ {n} {Γ Δ : Context n} {A : Term n} {B : Term (suc n)} {k₁ k₂ : ℕ} (F : V → (V → V) → V) (F-U : ∀ {β A G} → A ∈ U β → (∀ {x} → x ∈ A → G x ∈ U β) → F A G ∈ U β) (former : Term n → Term (suc n) → Term n) (WD-former : ∀ {ρ} → WD A ρ × (∀ {x} → x ∈ ⟦ A ⟧ ρ → WD B (ρ ▹ x)) → WD (former A B) ρ) (⟦former⟧ : ∀ {ρ} → ⟦ former A B ⟧ ρ ≡ F (⟦ A ⟧ ρ) (λ x → ⟦ B ⟧ (ρ ▹ x))) → Δ ≃ᶜ Γ → Δ ⊨ A ⦂ `Setω k₁ → (Δ , A) ⊨ B ⦂ `Setω k₂ → Δ ⊨ former A B ⦂ `Setω (k₁ ⊔ k₂) sem-formerW {A = A} {B} {k₁} {k₂} F F-U former WD-former ⟦former⟧ Δ≈ SA SB = sem _ ≈-refl okF where okF : ∀ ρ → _ → _ okF ρ h with asUω SA ρ h ... | ⟨ wA , mA ⟩ = ⟨ WD-former ⟨ wA , (λ {x} x∈ → proj₁ (asUω SB _ (⊨ᶜ-ext h wA x∈))) ⟩ , ⟨ tt , subst (_∈ U (ω+ (k₁ ⊔ k₂))) (sym ⟦former⟧) (F-U (U-⊆ (ω≤ (m≤m⊔n _ _)) mA) (λ {x} x∈ → U-⊆ (ω≤ (m≤n⊔m _ _)) (proj₂ (asUω SB _ (⊨ᶜ-ext h wA x∈))))) ⟩ ⟩ -- Level-dependent type formers: codomain in some Set, result in Setω k₁. sem-formerD : ∀ {n} {Γ Δ : Context n} {A : Term n} {B : Term (suc n)} {k₁ : ℕ} {l₂ : Lvl (suc n)} (F : V → (V → V) → V) (F-U : ∀ {β A G} → A ∈ U β → (∀ {x} → x ∈ A → G x ∈ U β) → F A G ∈ U β) (former : Term n → Term (suc n) → Term n) (WD-former : ∀ {ρ} → WD A ρ × (∀ {x} → x ∈ ⟦ A ⟧ ρ → WD B (ρ ▹ x)) → WD (former A B) ρ) (⟦former⟧ : ∀ {ρ} → ⟦ former A B ⟧ ρ ≡ F (⟦ A ⟧ ρ) (λ x → ⟦ B ⟧ (ρ ▹ x))) → Δ ≃ᶜ Γ → Δ ⊨ A ⦂ `Setω k₁ → (Δ , A) ⊨ B ⦂ `Setn l₂ → Δ ⊨ former A B ⦂ `Setω k₁ sem-formerD {A = A} {B} {k₁} F F-U former WD-former ⟦former⟧ Δ≈ SA SB = sem _ ≈-refl okF where module UB = IsU (asU SB) okF : ∀ ρ → _ → _ okF ρ h with asUω SA ρ h ... | ⟨ wA , mA ⟩ = ⟨ WD-former ⟨ wA , (λ {x} x∈ → proj₁ (UB.okU _ (⊨ᶜ-ext h wA x∈))) ⟩ , ⟨ tt , subst (_∈ U (ω+ k₁)) (sym ⟦former⟧) (F-U mA (λ {x} x∈ → U-⊆ finω (proj₂ (proj₂ (UB.okU _ (⊨ᶜ-ext h wA x∈)))))) ⟩ ⟩ sound Δ≈ (⊢-` x refl) = sem _ (at Δ≈ x) (λ ρ h → ⟨ tt , get h x ⟩) sound {Δ = Δ} Δ≈ (⊢-λ {e = b} {t₁ = A} d₁ d₂) = sem (∀[x⦂ A ] W SB) (≈-∀ ≈-refl (W≈ SB)) okλ where SA = sound Δ≈ d₁ SB = sound (ext≃ Δ≈ ≈-refl) d₂ okλ : ∀ ρ → _ → _ okλ ρ h with ok SA ρ h ... | ⟨ wA , _ ⟩ = ⟨ ⟨ wA , (λ {x} x∈ → proj₁ (ok SB _ (⊨ᶜ-ext h wA x∈))) ⟩ , ⟨ ⟨ wA , (λ {x} x∈ → proj₁ (proj₂ (ok SB _ (⊨ᶜ-ext h wA x∈)))) ⟩ , lam-∈ (λ {x} x∈ → proj₂ (proj₂ (ok SB _ (⊨ᶜ-ext h wA x∈)))) ⟩ ⟩ sound Δ≈ (⊢-· {e₁ = f} {e₂ = a} d₁ d₂) = sem (Π.B₁ [ a ]) (≈-sub (0↦ a) (≈-sym Π.B≈)) okA where module Π = IsΠ (asΠ (sound Δ≈ d₁)) Sa = sound Δ≈ d₂ okA : ∀ ρ → _ → _ okA ρ h with Π.okΠ ρ h | ok Sa ρ h ... | ⟨ wf , ⟨ wA , ⟨ wB , mf ⟩ ⟩ ⟩ | ⟨ wa , ⟨ wWa , ma ⟩ ⟩ = ⟨ ⟨ wf , ⟨ wa , subst (_ ∈_) (sym (Pi-dom mf)) a∈ ⟩ ⟩ , ⟨ WD-[] Π.B₁ wa (wB a∈) , subst (_ ∈_) (sym ([]-⟦⟧ Π.B₁ a ρ)) (app-∈ mf a∈) ⟩ ⟩ where a∈ = subst (_ ∈_) (≈-sem (≈-trans (W≈ Sa) Π.A≈) wWa wA) ma sound Δ≈ (⊢-∀ d₁ d₂ dl) = sem-formerF Pi Pi-U ∀[x⦂_]_ (λ w → w) refl Δ≈ (sound Δ≈ d₁) (sound (ext≃ Δ≈ ≈-refl) d₂) (soundₗ Δ≈ dl) sound Δ≈ (⊢-∀ω d₁ d₂) = sem-formerW Pi Pi-U ∀[x⦂_]_ (λ w → w) refl Δ≈ (sound Δ≈ d₁) (sound (ext≃ Δ≈ ≈-refl) d₂) sound Δ≈ (⊢-∀-dep d₁ d₂) = sem-formerD Pi Pi-U ∀[x⦂_]_ (λ w → w) refl Δ≈ (sound Δ≈ d₁) (sound (ext≃ Δ≈ ≈-refl) d₂) sound Δ≈ (⊢-≈ t≈t' d) with sound Δ≈ d ... | sem W W≈ okW = sem W (≈-trans W≈ t≈t') okW sound Δ≈ (⊢-∃ d₁ d₂ dl) = sem-formerF Sig Sig-U ∃[x⦂_]_ (λ w → w) refl Δ≈ (sound Δ≈ d₁) (sound (ext≃ Δ≈ ≈-refl) d₂) (soundₗ Δ≈ dl) sound Δ≈ (⊢-∃ω d₁ d₂) = sem-formerW Sig Sig-U ∃[x⦂_]_ (λ w → w) refl Δ≈ (sound Δ≈ d₁) (sound (ext≃ Δ≈ ≈-refl) d₂) sound Δ≈ (⊢-∃-dep d₁ d₂) = sem-formerD Sig Sig-U ∃[x⦂_]_ (λ w → w) refl Δ≈ (sound Δ≈ d₁) (sound (ext≃ Δ≈ ≈-refl) d₂) sound Δ≈ (⊢-, {e₁ = a} {e₂ = b} {t₂ = C} d₁ d₂ d₃) = sem (∃[x⦂ W Sa ] C) (≈-∃ (W≈ Sa) ≈-refl) okP where Sa = sound Δ≈ d₁ Sb = sound Δ≈ d₂ SC = sound (ext≃ Δ≈ (W≈ Sa)) d₃ okP : ∀ ρ → _ → _ okP ρ h with ok Sa ρ h | ok Sb ρ h ... | ⟨ wa , ⟨ wWa , ma ⟩ ⟩ | ⟨ wb , ⟨ wWb , mb ⟩ ⟩ = ⟨ ⟨ wa , wb ⟩ , ⟨ ⟨ wWa , (λ {x} x∈ → proj₁ (ok SC _ (⊨ᶜ-ext h wWa x∈))) ⟩ , pair-∈ ma (subst (_ ∈_) (trans (≈-sem (W≈ Sb) wWb wC[a]) ([]-⟦⟧ C a ρ)) mb) ⟩ ⟩ where wC[a] = WD-[] C wa (proj₁ (ok SC _ (⊨ᶜ-ext h wWa ma))) sound Δ≈ (⊢-proj₁ d) = sem SΣ.A₁ (≈-sym SΣ.A≈) okP where module SΣ = IsΣ (asΣ (sound Δ≈ d)) okP : ∀ ρ → _ → _ okP ρ h with SΣ.okΣ ρ h ... | ⟨ wp , ⟨ wA , ⟨ _ , m ⟩ ⟩ ⟩ = ⟨ wp , ⟨ wA , fst-∈ m ⟩ ⟩ sound Δ≈ (⊢-proj₂ {e = p} d) = sem (SΣ.B₁ [ `proj₁ p ]) (≈-sub (0↦ _) (≈-sym SΣ.B≈)) okP where module SΣ = IsΣ (asΣ (sound Δ≈ d)) okP : ∀ ρ → _ → _ okP ρ h with SΣ.okΣ ρ h ... | ⟨ wp , ⟨ wA , ⟨ wB , m ⟩ ⟩ ⟩ = ⟨ wp , ⟨ WD-[] SΣ.B₁ wp (wB (fst-∈ m)) , subst (_ ∈_) (sym ([]-⟦⟧ SΣ.B₁ (`proj₁ p) ρ)) (snd-∈ m) ⟩ ⟩ sound Δ≈ (⊢-≡ dt d₁ d₂) = sem (`Setn UT.l₁) (≈-Setn (≈-sym UT.l≈)) okE where module UT = IsU (asU (sound Δ≈ dt)) okE : ∀ ρ → _ → _ okE ρ h = ⟨ ⟨ proj₁ (ok (sound Δ≈ d₁) ρ h) , proj₁ (ok (sound Δ≈ d₂) ρ h) ⟩ , ⟨ proj₁ (proj₂ (UT.okU ρ h)) , U-⊆ (fin≤ z≤n) Id-U ⟩ ⟩ sound Δ≈ (⊢-refl {e = e} d) = sem (e `≡ e) ≈-refl okR where okR : ∀ ρ → _ → _ okR ρ h = let we = proj₁ (ok (sound Δ≈ d) ρ h) in ⟨ tt , ⟨ ⟨ we , we ⟩ , Id-intro ⟩ ⟩ sound Δ≈ (⊢-subst {e₁ = e₁} {e₂} {u₁} {u₂} {t = T} dt du₁ du₂ de₁ de₂) = sem (T [ u₂ ]) ≈-refl okS where Su₁ = sound Δ≈ du₁ Su₂ = sound Δ≈ du₂ ST = sound (ext≃ Δ≈ (W≈ Su₂)) dt module E = IsId (asId (sound Δ≈ de₁)) Se₂ = sound Δ≈ de₂ okS : ∀ ρ → _ → _ okS ρ h with ok Su₁ ρ h | ok Su₂ ρ h | E.okId ρ h | ok Se₂ ρ h ... | ⟨ wu₁ , ⟨ wW₁ , m₁ ⟩ ⟩ | ⟨ wu₂ , ⟨ wW₂ , m₂ ⟩ ⟩ | ⟨ we₁ , ⟨ wa , ⟨ wb , me₁ ⟩ ⟩ ⟩ | ⟨ we₂ , ⟨ wWe , me₂ ⟩ ⟩ = ⟨ ⟨ we₁ , we₂ ⟩ , ⟨ WD-[] T wu₂ wT₂ , subst (_ ∈_) (trans (≈-sem (W≈ Se₂) wWe (WD-[] T wu₁ wT₁)) (trans ([]-⟦⟧ T u₁ ρ) (trans (cong (λ v → ⟦ T ⟧ (ρ ▹ v)) u₁≡u₂) (sym ([]-⟦⟧ T u₂ ρ))))) me₂ ⟩ ⟩ where u₁≡u₂ : ⟦ u₁ ⟧ ρ ≡ ⟦ u₂ ⟧ ρ u₁≡u₂ = trans (≈-sem E.a≈ wu₁ wa) (trans (Id-elim me₁) (sym (≈-sem E.b≈ wu₂ wb))) m₁' = subst (_ ∈_) (≈-sem (≈-trans (W≈ Su₁) (≈-sym (W≈ Su₂))) wW₁ wW₂) m₁ wT₁ = proj₁ (ok ST _ (⊨ᶜ-ext h wW₂ m₁')) wT₂ = proj₁ (ok ST _ (⊨ᶜ-ext h wW₂ m₂)) sound Δ≈ (⊢-Setn {l = l} dl) = sem (`Setn (`lsuc l)) ≈-refl okU' where okU' : ∀ ρ → _ → _ okU' ρ h = let wl = soundₗ Δ≈ dl ρ h in ⟨ wl , ⟨ wl , U-∈ (fin< (n<1+n _)) ⟩ ⟩ sound Δ≈ ⊢-Setω = sem _ ≈-refl (λ ρ h → ⟨ tt , ⟨ tt , U-∈ (ω< (n<1+n _)) ⟩ ⟩) sound Δ≈ (⊢-lvl dl) = sem `Level ≈-refl (λ ρ h → ⟨ soundₗ Δ≈ dl ρ h , ⟨ tt , fromℕ-∈ ⟩ ⟩) sound Δ≈ ⊢-Level = sem `Set ≈-refl (λ ρ h → ⟨ tt , ⟨ tt , ω-U ⟩ ⟩) sound Δ≈ (⊢-Set