Files
Julius FischerandClaude Opus 5.5 d83c61261d
Typecheck / agda (push) Successful in 1m52s
Annotate λ with its domain: `λ[x⦂ A ] e
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
2026-11-22 21:12:06 +01:00

329 lines
18 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.Decidability.SN.Strong where
open import Data.Empty using (⊥-elim)
open import Data.Nat using (ℕ; suc)
open import Data.Product using (Σ; _×_) renaming (_,_ to ⟨_,_⟩)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import univTypes.Specification
open import univTypes.Metatheory.Confluence.Conversion using (↪-sub)
open import univTypes.Metatheory.Confluence.Parallel using (↪ₚ→↪*; ↪ₚσ-[]; ↪ₚ-refl; ↪→↪ₚ)
open import univTypes.Decidability.Statement
using (StrongNormalisation; StrongNormalisationₗ) renaming (SN to SNᵃ; sn to accᵃ)
import univTypes.Decidability.SN.Inductive as I
open import univTypes.Decidability.SN.Properties using (Spine; ↪-Spine; SNe→Spine)
open import univTypes.Decidability.Fundamental using (sn-wt; sn-wtₗ)
-- Strong normalisation in the classical sense: every reduction sequence from
-- a well-typed term (or well-formed level) is finite. The inductive SN of
-- the fundamental theorem is sound for accessibility (cf. van Raamsdonk,
-- Severi; Abel et al., POPLMark Reloaded): every rule preserves
-- accessibility, the hard case being weak head expansion (back).
-- Accessibility --------------------------------------------------------------------
SNᵃ-↪ : ∀ {s n} {e e' : Tm s n} → SNᵃ e → e ↪ e' → SNᵃ e'
SNᵃ-↪ (accᵃ h) r = h r
infix 4 _↪⁺_
data _↪⁺_ {s n} : Tm s n → Tm s n → Set where
one : ∀ {e e'} → e ↪ e' → e ↪⁺ e'
more : ∀ {e e' e''} → e ↪ e' → e' ↪⁺ e'' → e ↪⁺ e''
↪⁺-map : ∀ {s s' m n} (f : Tm s m → Tm s' n) → (∀ {a b} → a ↪ b → f a ↪ f b)
→ ∀ {a b} → a ↪⁺ b → f a ↪⁺ f b
↪⁺-map f ξ (one r) = one (ξ r)
↪⁺-map f ξ (more r rs) = more (ξ r) (↪⁺-map f ξ rs)
↪*-map : ∀ {s s' m n} (f : Tm s m → Tm s' n) → (∀ {a b} → a ↪ b → f a ↪ f b)
→ ∀ {a b} → a ↪* b → f a ↪* f b
↪*-map f ξ ↪*-refl = ↪*-refl
↪*-map f ξ (↪*-step r rs) = ↪*-step (ξ r) (↪*-map f ξ rs)
-- Accessibility for one or more steps.
data Acc⁺ {s n} (e : Tm s n) : Set where
acc⁺ : (∀ {e'} → e ↪⁺ e' → Acc⁺ e') → Acc⁺ e
SNᵃ→Acc⁺ : ∀ {s n} {e : Tm s n} → SNᵃ e → Acc⁺ e
SNᵃ→Acc⁺ (accᵃ h) = acc⁺ λ { (one r) → SNᵃ→Acc⁺ (h r) ; (more r rs) → down (SNᵃ→Acc⁺ (h r)) rs }
where
down : ∀ {s n} {e e' : Tm s n} → Acc⁺ e → e ↪⁺ e' → Acc⁺ e'
down (acc⁺ h) rs = h rs
Acc⁺→SNᵃ : ∀ {s n} {e : Tm s n} → Acc⁺ e → SNᵃ e
Acc⁺→SNᵃ (acc⁺ h) = accᵃ λ r → Acc⁺→SNᵃ (h (one r))
Acc⁺-↪* : ∀ {s n} {e e' : Tm s n} → Acc⁺ e → e ↪* e' → Acc⁺ e'
Acc⁺-↪* a ↪*-refl = a
Acc⁺-↪* (acc⁺ h) (↪*-step r rs) = h (plus r rs)
where
plus : ∀ {s n} {e e' e'' : Tm s n} → e ↪ e' → e' ↪* e'' → e ↪⁺ e''
plus r ↪*-refl = one r
plus r (↪*-step r' rs') = more r (plus r' rs')
-- Introduction forms ---------------------------------------------------------------
accλ : ∀ {n} {a : Term n} {b : Term (suc n)} → SNᵃ a → SNᵃ b → SNᵃ (`λ[x⦂ a ] b)
accλ sa@(accᵃ ha) sb@(accᵃ hb) = accᵃ λ { (ξ-λ₁ r) → accλ (ha r) sb ; (ξ-λ r) → accλ sa (hb r) }
acc∀ : ∀ {n} {a : Term n} {b : Term (suc n)} → SNᵃ a → SNᵃ b → SNᵃ (∀[x⦂ a ] b)
acc∀ sa@(accᵃ ha) sb@(accᵃ hb) = accᵃ λ { (ξ-∀₁ r) → acc∀ (ha r) sb ; (ξ-∀₂ r) → acc∀ sa (hb r) }
acc∃ : ∀ {n} {a : Term n} {b : Term (suc n)} → SNᵃ a → SNᵃ b → SNᵃ (∃[x⦂ a ] b)
acc∃ sa@(accᵃ ha) sb@(accᵃ hb) = accᵃ λ { (ξ-∃₁ r) → acc∃ (ha r) sb ; (ξ-∃₂ r) → acc∃ sa (hb r) }
acc, : ∀ {n} {a b : Term n} → SNᵃ a → SNᵃ b → SNᵃ (a `, b)
acc, sa@(accᵃ ha) sb@(accᵃ hb) = accᵃ λ { (ξ-,₁ r) → acc, (ha r) sb ; (ξ-,₂ r) → acc, sa (hb r) }
acc≡ : ∀ {n} {a b : Term n} → SNᵃ a → SNᵃ b → SNᵃ (a `≡ b)
acc≡ sa@(accᵃ ha) sb@(accᵃ hb) = accᵃ λ { (ξ-≡₁ r) → acc≡ (ha r) sb ; (ξ-≡₂ r) → acc≡ sa (hb r) }
acc⊔ : ∀ {n} {a b : Lvl n} → SNᵃ a → SNᵃ b → SNᵃ (a `⊔ b)
acc⊔ sa@(accᵃ ha) sb@(accᵃ hb) = accᵃ λ { (ξ-⊔₁ r) → acc⊔ (ha r) sb ; (ξ-⊔₂ r) → acc⊔ sa (hb r) }
accSetn : ∀ {n} {l : Lvl n} → SNᵃ l → SNᵃ (`Setn l)
accSetn (accᵃ h) = accᵃ λ { (ξ-Setn r) → accSetn (h r) }
acclvl : ∀ {n} {l : Lvl n} → SNᵃ l → SNᵃ (`lvl l)
acclvl (accᵃ h) = accᵃ λ { (ξ-lvl r) → acclvl (h r) }
acclsuc : ∀ {n} {l : Lvl n} → SNᵃ l → SNᵃ (`lsuc l)
acclsuc (accᵃ h) = accᵃ λ { (ξ-lsuc r) → acclsuc (h r) }
accsuc : ∀ {n} {k : Term n} → SNᵃ k → SNᵃ (`suc k)
accsuc (accᵃ h) = accᵃ λ { (ξ-suc r) → accsuc (h r) }
-- Neutral terms ----------------------------------------------------------------------
-- A spine never reduces at its root, so only its parts reduce.
acc-app : ∀ {n} {f a : Term n} → Spine f → SNᵃ f → SNᵃ a → SNᵃ (f · a)
acc-app' : ∀ {n} {f a e : Term n} → Spine f → SNᵃ f → SNᵃ a → f · a ↪ e → SNᵃ e
acc-app sp sf sa = accᵃ (acc-app' sp sf sa)
acc-app' () _ _ β-λ
acc-app' sp (accᵃ hf) sa (ξ-·₁ r) = acc-app (↪-Spine sp r) (hf r) sa
acc-app' sp sf (accᵃ ha) (ξ-·₂ r) = acc-app sp sf (ha r)
acc-proj₁ : ∀ {n} {e : Term n} → Spine e → SNᵃ e → SNᵃ (`proj₁ e)
acc-proj₁' : ∀ {n} {e e' : Term n} → Spine e → SNᵃ e → `proj₁ e ↪ e' → SNᵃ e'
acc-proj₁ sp se = accᵃ (acc-proj₁' sp se)
acc-proj₁' () _ β-proj₁
acc-proj₁' sp (accᵃ h) (ξ-proj₁ r) = acc-proj₁ (↪-Spine sp r) (h r)
acc-proj₂ : ∀ {n} {e : Term n} → Spine e → SNᵃ e → SNᵃ (`proj₂ e)
acc-proj₂' : ∀ {n} {e e' : Term n} → Spine e → SNᵃ e → `proj₂ e ↪ e' → SNᵃ e'
acc-proj₂ sp se = accᵃ (acc-proj₂' sp se)
acc-proj₂' () _ β-proj₂
acc-proj₂' sp (accᵃ h) (ξ-proj₂ r) = acc-proj₂ (↪-Spine sp r) (h r)
acc-subst : ∀ {n} {t : Term (suc n)} {e₁ e₂ : Term n}
→ SNᵃ t → Spine e₁ → SNᵃ e₁ → SNᵃ e₂ → SNᵃ (`subst t e₁ e₂)
acc-subst' : ∀ {n} {t : Term (suc n)} {e₁ e₂ e : Term n}
→ SNᵃ t → Spine e₁ → SNᵃ e₁ → SNᵃ e₂ → `subst t e₁ e₂ ↪ e → SNᵃ e
acc-subst st sp s₁ s₂ = accᵃ (acc-subst' st sp s₁ s₂)
acc-subst' _ () _ _ β-subst
acc-subst' (accᵃ h) sp s₁ s₂ (ξ-subst₁ r) = acc-subst (h r) sp s₁ s₂
acc-subst' st sp (accᵃ h) s₂ (ξ-subst₂ r) = acc-subst st (↪-Spine sp r) (h r) s₂
acc-subst' st sp s₁ (accᵃ h) (ξ-subst₃ r) = acc-subst st sp s₁ (h r)
acc-latom : ∀ {n} {e : Term n} → Spine e → SNᵃ e → SNᵃ (`latom e)
acc-latom' : ∀ {n} {e : Term n} {l : Lvl n} → Spine e → SNᵃ e → `latom e ↪ l → SNᵃ l
acc-latom sp se = accᵃ (acc-latom' sp se)
acc-latom' () _ β-latom
acc-latom' sp (accᵃ h) (ξ-latom r) = acc-latom (↪-Spine sp r) (h r)
acc-natrec : ∀ {n} {P z s t : Term n}
→ SNᵃ P → SNᵃ z → SNᵃ s → Spine t → SNᵃ t → SNᵃ (`natrec P z s t)
acc-natrec' : ∀ {n} {P z s t e : Term n}
→ SNᵃ P → SNᵃ z → SNᵃ s → Spine t → SNᵃ t → `natrec P z s t ↪ e → SNᵃ e
acc-natrec sP sz ss sp st = accᵃ (acc-natrec' sP sz ss sp st)
acc-natrec' _ _ _ () _ β-natrec-zero
acc-natrec' _ _ _ () _ β-natrec-suc
acc-natrec' (accᵃ h) sz ss sp st (ξ-natrec₁ r) = acc-natrec (h r) sz ss sp st
acc-natrec' sP (accᵃ h) ss sp st (ξ-natrec₂ r) = acc-natrec sP (h r) ss sp st
acc-natrec' sP sz (accᵃ h) sp st (ξ-natrec₃ r) = acc-natrec sP sz (h r) sp st
acc-natrec' sP sz ss sp (accᵃ h) (ξ-natrec₄ r) = acc-natrec sP sz ss (↪-Spine sp r) (h r)
-- Weak head expansion ------------------------------------------------------------------
-- The part of a term that a weak head step discards.
data Packed : Set where
pack : ∀ {s n} → Tm s n → Packed
-- Weak head reduction, indexed by the discarded part (`tt when nothing is
-- discarded).
infix 4 _↦_⟨_⟩
data _↦_⟨_⟩ : ∀ {s n} → Tm s n → Tm s n → Packed → Set where
-- β discards the domain annotation and the argument, packed as a pair.
↦β : ∀ {n} {A : Term n} {b : Term (suc n)} {a : Term n} → (`λ[x⦂ A ] b) · a ↦ b [ a ] ⟨ pack (A `, a) ⟩
↦π₁ : ∀ {n} {a b : Term n} → `proj₁ (a `, b) ↦ a ⟨ pack b ⟩
↦π₂ : ∀ {n} {a b : Term n} → `proj₂ (a `, b) ↦ b ⟨ pack a ⟩
↦subst : ∀ {n} {t : Term (suc n)} {e : Term n} → `subst t `refl e ↦ e ⟨ pack t ⟩
↦latom : ∀ {n} {l : Lvl n} → `latom (`lvl l) ↦ l ⟨ pack (`tt {n}) ⟩
↦· : ∀ {n} {f f' c : Term n} {d} → f ↦ f' ⟨ d ⟩ → f · c ↦ f' · c ⟨ d ⟩
↦proj₁ : ∀ {n} {e e' : Term n} {d} → e ↦ e' ⟨ d ⟩ → `proj₁ e ↦ `proj₁ e' ⟨ d ⟩
↦proj₂ : ∀ {n} {e e' : Term n} {d} → e ↦ e' ⟨ d ⟩ → `proj₂ e ↦ `proj₂ e' ⟨ d ⟩
↦substc : ∀ {n} {t : Term (suc n)} {e₁ e₁' e₂ : Term n} {d}
→ e₁ ↦ e₁' ⟨ d ⟩ → `subst t e₁ e₂ ↦ `subst t e₁' e₂ ⟨ d ⟩
↦latomc : ∀ {n} {e e' : Term n} {d} → e ↦ e' ⟨ d ⟩ → `latom e ↦ `latom e' ⟨ d ⟩
-- natrec P z s zero discards P and s, packed as a pair.
↦natrec-zero : ∀ {n} {P z s : Term n} → `natrec P z s `zero ↦ z ⟨ pack (P `, s) ⟩
↦natrec-suc : ∀ {n} {P z s k : Term n}
→ `natrec P z s (`suc k) ↦ s · k · `natrec P z s k ⟨ pack (`tt {n}) ⟩
↦natrec : ∀ {n} {P z s e e' : Term n} {d}
→ e ↦ e' ⟨ d ⟩ → `natrec P z s e ↦ `natrec P z s e' ⟨ d ⟩
-- How another step relates to a weak head step: it is the head step, or it
-- commutes with it, either making the contractum take at least one step or
-- reducing only the discarded part.
data Comm {s n s' n'} (e' : Tm s n) (t : Tm s' n') (e₁ : Tm s n) : Set where
head : e₁ ≡ e' → Comm e' t e₁
same : ∀ {e₁'} → e₁ ↦ e₁' ⟨ pack t ⟩ → e' ↪⁺ e₁' → Comm e' t e₁
side : ∀ {t' : Tm s' n'} {e₁'} → t ↪ t' → e₁ ↦ e₁' ⟨ pack t' ⟩ → e' ↪* e₁' → Comm e' t e₁
comm : ∀ {s n s' n'} {e e' e₁ : Tm s n} {t : Tm s' n'} → e ↦ e' ⟨ pack t ⟩ → e ↪ e₁ → Comm e' t e₁
comm ↦β β-λ = head refl
comm ↦β (ξ-·₁ (ξ-λ r)) = same ↦β (one (↪-sub (0↦ _) r))
comm ↦β (ξ-·₁ (ξ-λ₁ r)) = side (ξ-,₁ r) ↦β ↪*-refl
comm (↦β {b = b}) (ξ-·₂ r) = side (ξ-,₂ r) ↦β (↪ₚ→↪* (↪ₚσ-[] {e₁ = b} ↪ₚ-refl (↪→↪ₚ r)))
comm ↦π₁ β-proj₁ = head refl
comm ↦π₁ (ξ-proj₁ (ξ-,₁ r)) = same ↦π₁ (one r)
comm ↦π₁ (ξ-proj₁ (ξ-,₂ r)) = side r ↦π₁ ↪*-refl
comm ↦π₂ β-proj₂ = head refl
comm ↦π₂ (ξ-proj₂ (ξ-,₁ r)) = side r ↦π₂ ↪*-refl
comm ↦π₂ (ξ-proj₂ (ξ-,₂ r)) = same ↦π₂ (one r)
comm ↦subst β-subst = head refl
comm ↦subst (ξ-subst₁ r) = side r ↦subst ↪*-refl
comm ↦subst (ξ-subst₂ ())
comm ↦subst (ξ-subst₃ r) = same ↦subst (one r)
comm ↦latom β-latom = head refl
comm ↦latom (ξ-latom (ξ-lvl r)) = same ↦latom (one r)
comm (↦· ()) β-λ
comm (↦· r₀) (ξ-·₁ st) with comm r₀ st
... | head refl = head refl
... | same r₁ p = same (↦· r₁) (↪⁺-map (_· _) ξ-·₁ p)
... | side st' r₁ p = side st' (↦· r₁) (↪*-map (_· _) ξ-·₁ p)
comm (↦· r₀) (ξ-·₂ st) = same (↦· r₀) (one (ξ-·₂ st))
comm (↦proj₁ ()) β-proj₁
comm (↦proj₁ r₀) (ξ-proj₁ st) with comm r₀ st
... | head refl = head refl
... | same r₁ p = same (↦proj₁ r₁) (↪⁺-map `proj₁ ξ-proj₁ p)
... | side st' r₁ p = side st' (↦proj₁ r₁) (↪*-map `proj₁ ξ-proj₁ p)
comm (↦proj₂ ()) β-proj₂
comm (↦proj₂ r₀) (ξ-proj₂ st) with comm r₀ st
... | head refl = head refl
... | same r₁ p = same (↦proj₂ r₁) (↪⁺-map `proj₂ ξ-proj₂ p)
... | side st' r₁ p = side st' (↦proj₂ r₁) (↪*-map `proj₂ ξ-proj₂ p)
comm (↦substc ()) β-subst
comm (↦substc r₀) (ξ-subst₁ st) = same (↦substc r₀) (one (ξ-subst₁ st))
comm (↦substc r₀) (ξ-subst₂ st) with comm r₀ st
... | head refl = head refl
... | same r₁ p = same (↦substc r₁) (↪⁺-map (λ x → `subst _ x _) ξ-subst₂ p)
... | side st' r₁ p = side st' (↦substc r₁) (↪*-map (λ x → `subst _ x _) ξ-subst₂ p)
comm (↦substc r₀) (ξ-subst₃ st) = same (↦substc r₀) (one (ξ-subst₃ st))
comm (↦latomc ()) β-latom
comm (↦latomc r₀) (ξ-latom st) with comm r₀ st
... | head refl = head refl
... | same r₁ p = same (↦latomc r₁) (↪⁺-map `latom ξ-latom p)
... | side st' r₁ p = side st' (↦latomc r₁) (↪*-map `latom ξ-latom p)
comm ↦natrec-zero β-natrec-zero = head refl
comm ↦natrec-zero (ξ-natrec₁ r) = side (ξ-,₁ r) ↦natrec-zero ↪*-refl
comm ↦natrec-zero (ξ-natrec₂ r) = same ↦natrec-zero (one r)
comm ↦natrec-zero (ξ-natrec₃ r) = side (ξ-,₂ r) ↦natrec-zero ↪*-refl
comm ↦natrec-zero (ξ-natrec₄ ())
comm ↦natrec-suc β-natrec-suc = head refl
comm ↦natrec-suc (ξ-natrec₁ r) = same ↦natrec-suc (one (ξ-·₂ (ξ-natrec₁ r)))
comm ↦natrec-suc (ξ-natrec₂ r) = same ↦natrec-suc (one (ξ-·₂ (ξ-natrec₂ r)))
comm ↦natrec-suc (ξ-natrec₃ r) =
same ↦natrec-suc (more (ξ-·₁ (ξ-·₁ r)) (one (ξ-·₂ (ξ-natrec₃ r))))
comm ↦natrec-suc (ξ-natrec₄ (ξ-suc r)) =
same ↦natrec-suc (more (ξ-·₁ (ξ-·₂ r)) (one (ξ-·₂ (ξ-natrec₄ r))))
comm (↦natrec ()) β-natrec-zero
comm (↦natrec ()) β-natrec-suc
comm (↦natrec r₀) (ξ-natrec₁ st) = same (↦natrec r₀) (one (ξ-natrec₁ st))
comm (↦natrec r₀) (ξ-natrec₂ st) = same (↦natrec r₀) (one (ξ-natrec₂ st))
comm (↦natrec r₀) (ξ-natrec₃ st) = same (↦natrec r₀) (one (ξ-natrec₃ st))
comm (↦natrec r₀) (ξ-natrec₄ st) with comm r₀ st
... | head refl = head refl
... | same r₁ p = same (↦natrec r₁) (↪⁺-map (`natrec _ _ _) ξ-natrec₄ p)
... | side st' r₁ p = side st' (↦natrec r₁) (↪*-map (`natrec _ _ _) ξ-natrec₄ p)
-- Backward closure: lexicographic in the discarded part and the contractum.
back : ∀ {s n s' n'} {e e' : Tm s n} {t : Tm s' n'} → e ↦ e' ⟨ pack t ⟩ → SNᵃ t → Acc⁺ e' → SNᵃ e
back' : ∀ {s n s' n'} {e e' e₁ : Tm s n} {t : Tm s' n'}
→ e ↦ e' ⟨ pack t ⟩ → SNᵃ t → Acc⁺ e' → e ↪ e₁ → SNᵃ e₁
back r sd a' = accᵃ (back' r sd a')
back' r sd a' st with comm r st
back' r sd a' st | head refl = Acc⁺→SNᵃ a'
back' r sd (acc⁺ h) st | same r₁ p = back r₁ sd (h p)
back' r (accᵃ hd) a' st | side st' r₁ p = back r₁ (hd st') (Acc⁺-↪* a' p)
-- Soundness of inductive SN ---------------------------------------------------------------
SNᵖ : Packed → Set
SNᵖ (pack t) = SNᵃ t
sound : ∀ {s n} {e : Tm s n} → I.SN e → SNᵃ e
soundₑ : ∀ {n} {e : Term n} → I.SNe e → SNᵃ e
toᵃ : ∀ {s n} {e e' : Tm s n} → e I.⇒ e' → Σ Packed λ d → (e ↦ e' ⟨ d ⟩) × SNᵖ d
sound (I.sn-λ s₁ s₂) = accλ (sound s₁) (sound s₂)
sound (I.sn-∀ s₁ s₂) = acc∀ (sound s₁) (sound s₂)
sound (I.sn-∃ s₁ s₂) = acc∃ (sound s₁) (sound s₂)
sound (I.sn-, s₁ s₂) = acc, (sound s₁) (sound s₂)
sound (I.sn-≡ s₁ s₂) = acc≡ (sound s₁) (sound s₂)
sound I.sn-refl = accᵃ λ ()
sound I.sn-tt = accᵃ λ ()
sound I.sn-Unit = accᵃ λ ()
sound I.sn-Level = accᵃ λ ()
sound I.sn-Setω = accᵃ λ ()
sound (I.sn-Setn s) = accSetn (sound s)
sound (I.sn-lvl s) = acclvl (sound s)
sound I.sn-lzero = accᵃ λ ()
sound (I.sn-lsuc s) = acclsuc (sound s)
sound (I.sn-⊔ s₁ s₂) = acc⊔ (sound s₁) (sound s₂)
sound I.sn-ℕ = accᵃ λ ()
sound I.sn-zero = accᵃ λ ()
sound (I.sn-suc s) = accsuc (sound s)
sound (I.sn-latom s) = acc-latom (SNe→Spine s) (soundₑ s)
sound (I.sn-ne s) = soundₑ s
sound (I.sn-⇒ r s) with toᵃ r
... | ⟨ pack t , ⟨ r' , sd ⟩ ⟩ = back r' sd (SNᵃ→Acc⁺ (sound s))
soundₑ I.ne-` = accᵃ λ ()
soundₑ (I.ne-· s₁ s₂) = acc-app (SNe→Spine s₁) (soundₑ s₁) (sound s₂)
soundₑ (I.ne-proj₁ s) = acc-proj₁ (SNe→Spine s) (soundₑ s)
soundₑ (I.ne-proj₂ s) = acc-proj₂ (SNe→Spine s) (soundₑ s)
soundₑ (I.ne-subst s₁ s₂ s₃) = acc-subst (sound s₁) (SNe→Spine s₂) (soundₑ s₂) (sound s₃)
soundₑ (I.ne-natrec s₁ s₂ s₃ s₄) =
acc-natrec (sound s₁) (sound s₂) (sound s₃) (SNe→Spine s₄) (soundₑ s₄)
toᵃ (I.⇒β s₁ s₂) = ⟨ pack _ , ⟨ ↦β , acc, (sound s₁) (sound s₂) ⟩ ⟩
toᵃ (I.⇒π₁ s) = ⟨ pack _ , ⟨ ↦π₁ , sound s ⟩ ⟩
toᵃ (I.⇒π₂ s) = ⟨ pack _ , ⟨ ↦π₂ , sound s ⟩ ⟩
toᵃ (I.⇒subst-refl s) = ⟨ pack _ , ⟨ ↦subst , sound s ⟩ ⟩
toᵃ I.⇒latom = ⟨ pack `tt , ⟨ ↦latom , accᵃ (λ ()) ⟩ ⟩
toᵃ (I.⇒· r) with toᵃ r
... | ⟨ d , ⟨ r' , sd ⟩ ⟩ = ⟨ d , ⟨ ↦· r' , sd ⟩ ⟩
toᵃ (I.⇒proj₁ r) with toᵃ r
... | ⟨ d , ⟨ r' , sd ⟩ ⟩ = ⟨ d , ⟨ ↦proj₁ r' , sd ⟩ ⟩
toᵃ (I.⇒proj₂ r) with toᵃ r
... | ⟨ d , ⟨ r' , sd ⟩ ⟩ = ⟨ d , ⟨ ↦proj₂ r' , sd ⟩ ⟩
toᵃ (I.⇒subst r) with toᵃ r
... | ⟨ d , ⟨ r' , sd ⟩ ⟩ = ⟨ d , ⟨ ↦substc r' , sd ⟩ ⟩
toᵃ (I.⇒latom-cong r) with toᵃ r
... | ⟨ d , ⟨ r' , sd ⟩ ⟩ = ⟨ d , ⟨ ↦latomc r' , sd ⟩ ⟩
toᵃ (I.⇒natrec-zero s₁ s₂) = ⟨ pack _ , ⟨ ↦natrec-zero , acc, (sound s₁) (sound s₂) ⟩ ⟩
toᵃ I.⇒natrec-suc = ⟨ pack `tt , ⟨ ↦natrec-suc , accᵃ (λ ()) ⟩ ⟩
toᵃ (I.⇒natrec r) with toᵃ r
... | ⟨ d , ⟨ r' , sd ⟩ ⟩ = ⟨ d , ⟨ ↦natrec r' , sd ⟩ ⟩
-- Strong normalisation of well-typed terms and well-formed levels.
strong-normalisation : StrongNormalisation
strong-normalisation ⊢Γ ⊢e = sound (sn-wt ⊢Γ ⊢e)
strong-normalisationₗ : StrongNormalisationₗ
strong-normalisationₗ ⊢Γ ⊢l = sound (sn-wtₗ ⊢Γ ⊢l)