~-lsuc-inj : lsuc l ~ lsuc l' → l ~ l' in LevelEqualityDecision: shift is injective and readback is injective on well-formed normal forms. TODO records the analysis of the optional η rule for the coercions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016LG5WunTkTJFuvdzgET3Af
61 lines
2.9 KiB
Agda
61 lines
2.9 KiB
Agda
module univTypes.SubjectReduction.LevelEqualityDecision where
|
||
|
||
open import Data.List using (List; []; _∷_; map)
|
||
open import Data.List.Properties using (∷-injective)
|
||
open import Data.Nat using (ℕ; suc)
|
||
open import Data.Nat.Properties using (suc-injective)
|
||
open import Data.Product using (_×_; _,_; map₂)
|
||
open import Data.Product.Properties using (,-injective)
|
||
open import Relation.Binary.PropositionalEquality using (_≡_; refl; trans; sym; cong)
|
||
open import Relation.Nullary using (Dec; yes; no)
|
||
|
||
open import univTypes.SubjectReduction.Specification hiding (_,_)
|
||
open import univTypes.SubjectReduction.LevelNormalForm using (nf; LNF; shift; flatten; readback)
|
||
open import univTypes.SubjectReduction.LevelNormalForm.Order using (_≟_)
|
||
open import univTypes.SubjectReduction.LevelNormalForm.Completeness using (complete) public
|
||
open import univTypes.SubjectReduction.LevelNormalForm.Completeness
|
||
using (flatten-readback; wf-shift; wf-flatten; nf-readback)
|
||
open import univTypes.SubjectReduction.LevelNormalForm.Soundness using (sound) public
|
||
|
||
-- Level equality is decided by the normaliser:
|
||
-- sound : e ~ nf e
|
||
-- complete : e ~ e' → nf e ≡ nf e'
|
||
|
||
nf-≡→~ : ∀ {s n} {e e' : Tm s n} → nf e ≡ nf e' → e ~ e'
|
||
nf-≡→~ {e = e} {e'} p = ~-trans (sound e) (~-trans (≡→~ p) (~-sym (sound e')))
|
||
where
|
||
≡→~ : ∀ {s n} {e e' : Tm s n} → e ≡ e' → e ~ e'
|
||
≡→~ refl = ~-refl
|
||
|
||
infix 4 _~?_
|
||
_~?_ : ∀ {s n} (e e' : Tm s n) → Dec (e ~ e')
|
||
e ~? e' with nf e ≟ nf e'
|
||
... | yes p = yes (nf-≡→~ p)
|
||
... | no ¬p = no λ q → ¬p (complete q)
|
||
|
||
-- Injectivity of `lsuc ------------------------------------------------------------
|
||
|
||
-- Not a consequence of the one-layer structure of ~ (LevelEqualityProperties),
|
||
-- since `lsuc takes part in the level equations; it goes through the
|
||
-- normaliser instead: readback is injective on well-formed normal forms
|
||
-- (flatten-readback), and shift is injective.
|
||
|
||
private
|
||
shiftₑ-inj : ∀ {n} {xs ys : List (Term n × ℕ)} → map (map₂ suc) xs ≡ map (map₂ suc) ys → xs ≡ ys
|
||
shiftₑ-inj {xs = []} {[]} refl = refl
|
||
shiftₑ-inj {xs = (a , k) ∷ xs} {(b , j) ∷ ys} p
|
||
with ∷-injective p
|
||
... | q , ps with ,-injective q
|
||
... | refl , r rewrite suc-injective r = cong ((a , j) ∷_) (shiftₑ-inj ps)
|
||
|
||
shift-inj : ∀ {n} {L M : LNF n} → shift L ≡ shift M → L ≡ M
|
||
shift-inj {L = c , xs} {d , ys} p with ,-injective p
|
||
... | q , ps rewrite suc-injective q = cong (d ,_) (shiftₑ-inj ps)
|
||
|
||
~-lsuc-inj : ∀ {n} {l l' : Lvl n} → `lsuc l ~ `lsuc l' → l ~ l'
|
||
~-lsuc-inj {l = l} {l'} p = nf-≡→~ (trans (nf-readback l) (trans (cong readback flat) (sym (nf-readback l'))))
|
||
where
|
||
flat : flatten l ≡ flatten l'
|
||
flat = shift-inj (trans (sym (flatten-readback (wf-shift (wf-flatten l))))
|
||
(trans (cong flatten (complete p)) (flatten-readback (wf-shift (wf-flatten l')))))
|