open import Definition.Typed.Restrictions
open import Graded.Modality
module Definition.Conversion.Conversion
{a} {M : Set a}
{š : Modality M}
(R : Type-restrictions š)
(open Type-restrictions R)
⦠no-equality-reflection : No-equality-reflection ā¦
where
open import Definition.Untyped M
open import Definition.Untyped.Neutral M type-variant
open import Definition.Typed R
open import Definition.Typed.EqRelInstance R
open import Definition.Typed.EqualityRelation.Instance R
open import Definition.Typed.Properties R
open import Definition.Typed.Stability R
open import Definition.Typed.Substitution R
open import Definition.Typed.Syntactic R
open import Definition.Conversion R
open import Definition.Conversion.Soundness R
open import Definition.Conversion.Stability R
open import Definition.Typed.Consequences.Injectivity R
open import Definition.Typed.Consequences.Equality R
open import Definition.Typed.Consequences.Reduction R
open import Tools.Function
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
private
variable
n : Nat
Ī Ī : Con Term n
A B t u : Term _
mutual
convConvāTermā² :
⢠Π┠Πā
Π⢠A ā” B ā
Π⢠t [convā] u ā· A ā
Π⢠t [convā] u ā· B
convConvāTermā² Īā”Ī Aā”B ([ā]ā Bā tā² uā² (D , _) d dā² t<>u) =
let _ , ā¢B = syntacticEq Aā”B
Bā² , whnfBā² , Dā² = whNorm ā¢B
Bāā”Bā² = trans (sym (subset* D)) (trans Aā”B (subset* Dā²))
in [ā]ā Bā² tā² uā² (stabilityRedā Īā”Ī (Dā² , whnfBā²))
(stabilityRedāTerm Īā”Ī (convāā· d Bāā”Bā²))
(stabilityRedāTerm Īā”Ī (convāā· dā² Bāā”Bā²))
(convConvāTermā² Īā”Ī Bāā”Bā² whnfBā² t<>u)
convConvāTermā² :
⢠Π┠Πā
Π⢠A ā” B ā
Whnf B ā
Π⢠t [convā] u ā· A ā
Π⢠t [convā] u ā· B
convConvāTermā² Īā”Ī Aā”B whnfB (ā-ins x) rewrite āā”A Aā”B whnfB =
ā-ins (stability~ā Īā”Ī x)
convConvāTermā² Īā”Ī Aā”B whnfB (Empty-ins x) rewrite Emptyā”A Aā”B whnfB =
Empty-ins (stability~ā Īā”Ī x)
convConvāTermā² Īā”Ī Aā”B B-whnf (UnitŹ·-ins ok t~u)
rewrite Unitā”A Aā”B B-whnf =
UnitŹ·-ins ok (stability~ā Īā”Ī t~u)
convConvāTermā² Īā”Ī Aā”B whnfB (Σʷ-ins x xā xā) with Ī£ā”A Aā”B whnfB
... | _ , _ , PE.refl =
Σʷ-ins (stabilityTerm Īā”Ī (conv x Aā”B))
(stabilityTerm Īā”Ī (conv xā Aā”B))
(stability~ā Īā”Ī xā)
convConvāTermā² Īā”Ī Aā”B whnfB (ne-ins t u x xā) =
ne-ins (stabilityTerm Īā”Ī (conv t Aā”B)) (stabilityTerm Īā”Ī (conv u Aā”B))
(neā”A x Aā”B whnfB) (stability~ā Īā”Ī xā)
convConvāTermā² Īā”Ī Aā”B whnfB (univ x xā xā) rewrite Uā”A Aā”B whnfB =
univ (stabilityTerm Īā”Ī x) (stabilityTerm Īā”Ī xā) (stabilityConvā Īā”Ī xā)
convConvāTermā² Īā”Ī Aā”B whnfB (zero-refl x) rewrite āā”A Aā”B whnfB =
let _ , ā¢Ī , _ = contextConvSubst Īā”Ī
in zero-refl ā¢Ī
convConvāTermā² Īā”Ī Aā”B whnfB (starŹ·-refl _ ok no-Ī·)
rewrite Unitā”A Aā”B whnfB =
let _ , ā¢Ī , _ = contextConvSubst Īā”Ī
in starŹ·-refl ā¢Ī ok no-Ī·
convConvāTermā² Īā”Ī Aā”B whnfB (suc-cong x) rewrite āā”A Aā”B whnfB =
suc-cong (stabilityConvāTerm Īā”Ī x)
convConvāTermā² Īā”Ī Aā”B whnfB (prod-cong xā xā xā ok)
with Ī£ā”A Aā”B whnfB
... | Fā² , Gā² , PE.refl with ΠΣ-injectivity-no-equality-reflection Aā”B
... | Fā”Fā² , Gā”Gā² , _ , _ =
let _ , ā¢Gā² = syntacticEq Gā”Gā²
_ , ā¢t , _ = syntacticEqTerm (soundnessConvāTerm xā)
Gtā”Gā²t = substTypeEq Gā”Gā² (refl ā¢t)
in prod-cong (stability (Īā”Ī ā Fā”Fā²) ā¢Gā²)
(convConvāTermā² Īā”Ī Fā”Fā² xā) (convConvāTermā² Īā”Ī Gtā”Gā²t xā) ok
convConvāTermā² Īā”Ī Aā”B whnfB (Ī·-eq xā xā y yā xā) with Ī ā”A Aā”B whnfB
convConvāTermā² Īā”Ī Aā”B whnfB (Ī·-eq xā xā y yā xā) | _ , _ , PE.refl =
case ΠΣ-injectivity-no-equality-reflection Aā”B of Ī» {
(Fā”Fā² , Gā”Gā² , _ , _) ā
Ī·-eq (stabilityTerm Īā”Ī (conv xā Aā”B))
(stabilityTerm Īā”Ī (conv xā Aā”B))
y yā
(convConvāTermā² (Īā”Ī ā Fā”Fā²) Gā”Gā² xā) }
convConvāTermā² Īā”Ī Aā”B whnfB (Ī£-Ī· ā¢p ā¢r pProd rProd fstConv sndConv)
with Ī£ā”A Aā”B whnfB
... | F , G , PE.refl with ΠΣ-injectivity-no-equality-reflection Aā”B
... | Fā” , Gā” , _ , _ =
let ā¢G = projā (syntacticEq Gā”)
ā¢fst = fstā±¼ ā¢G ā¢p
in Ī£-Ī· (stabilityTerm Īā”Ī (conv ā¢p Aā”B))
(stabilityTerm Īā”Ī (conv ā¢r Aā”B))
pProd
rProd
(convConvāTermā² Īā”Ī Fā” fstConv)
(convConvāTermā² Īā”Ī (substTypeEq Gā” (refl ā¢fst)) sndConv)
convConvāTermā² Īā”Ī Aā”B whnfB (Ī·-unit [t] [u] tUnit uUnit ok)
rewrite Unitā”A Aā”B whnfB =
let [t] = stabilityTerm Īā”Ī [t]
[u] = stabilityTerm Īā”Ī [u]
in Ī·-unit [t] [u] tUnit uUnit ok
convConvāTermā² Īā”Ī Id-A-t-uā”B B-whnf (Id-ins ā¢vā vā~vā) =
case Idā”Whnf Id-A-t-uā”B B-whnf of Ī» {
(_ , _ , _ , PE.refl) ā
Id-ins (stabilityTerm Īā”Ī (conv ā¢vā Id-A-t-uā”B))
(stability~ā Īā”Ī vā~vā) }
convConvāTermā² Īā”Ī Id-A-t-uā”B B-whnf (rfl-refl tā”u) =
case Idā”Whnf Id-A-t-uā”B B-whnf of Ī» {
(_ , _ , _ , PE.refl) ā
case Id-injectivity Id-A-t-uā”B of Ī» {
(Aā”Aā² , tā”tā² , uā”uā²) ā
rfl-refl
(stabilityEqTerm Īā”Ī $
conv (trans (symā² tā”tā²) (trans tā”u uā”uā²)) Aā”Aā²) }}
convConvāTerm :
Π⢠A ā” B ā
Π⢠t [convā] u ā· A ā
Π⢠t [convā] u ā· B
convConvāTerm Aā”B = convConvāTermā² (reflConEq (wfEq Aā”B)) Aā”B
opaque
convConvāTerm :
Π⢠A ā” B ā
Whnf B ā
Π⢠t [convā] u ā· A ā
Π⢠t [convā] u ā· B
convConvāTerm Aā”B = convConvāTermā² (reflConEq (wfEq Aā”B)) Aā”B