open import Definition.Typed.Restrictions
open import Graded.Modality
module Definition.Typed.Consequences.Consistency
{a} {M : Set a}
{š : Modality M}
(R : Type-restrictions š)
where
open Modality š
open Type-restrictions R
open import Graded.Mode.Instances.Trivial š
open import Definition.Untyped M
open import Definition.Untyped.Identity š as Id
open import Definition.Untyped.Properties M
open import Definition.Typed R
open import Definition.Typed.Consequences.Canonicity R
open import Definition.Typed.Decidable.Internal trivial R
import Definition.Typed.Decidable.Internal.Context trivial R as IC
import Definition.Typed.Decidable.Internal.Term trivial R as I
open import Definition.Typed.EqRelInstance R
open import Definition.Typed.Inversion R
open import Definition.Typed.Properties R
open import Definition.Typed.Stability R
open import Definition.Typed.Substitution R
open import Definition.Typed.Weakening.Definition R
open import Definition.Typed.Well-formed R
open import Definition.LogicalRelation.Hidden R
open import Definition.LogicalRelation.Substitution.Introductions R
open import Definition.LogicalRelation.Fundamental.Reducibility R
open import Tools.Bool
open import Tools.Empty
open import Tools.Fin
open import Tools.Function
import Tools.List as L
open import Tools.Maybe
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
open import Tools.Reasoning.PropositionalEquality
open import Tools.Relation
open import Tools.Vec as V using (ε)
open Id.Internal trivial R
private
variable
m n : Nat
ā āā² : DCon (Term 0) m
Ī Ī : Con Term n
Ī : Cons m n
Ļ : Subst _ _
t u : Term n
p q : M
opaque
subst-Consistent :
ā Ā» Ī ā¢Ė¢Ź· Ļ ā· Ī ā Consistent (ā Ā» Ī) ā Consistent (ā Ā» Ī)
subst-Consistent ā¢Ļ consistent _ ā¢t = consistent _ (subst-⢠ā¢t ā¢Ļ)
opaque
inhabited-consistent : ā Ā» ε ā¢Ė¢Ź· Ļ ā· Ī ā Consistent (ā Ā» Ī)
inhabited-consistent = flip subst-Consistent (Ī» _ ā ¬Empty)
opaque
zeroā¢suc :
⦠ok : No-equality-reflection or-empty (Ī .vars) ⦠ā
¬ Π⢠zero ā” suc t ā· ā
zeroā¢suc {Ī} {t} =
Π⢠zero ā” suc t ā· ā ā⨠reducible-ā©ā”ā· ā©
(ā Ī» l ā Ī ā©āØ l ā© zero ā” suc t ā· ā) ā⨠ā©zeroā”sucā·āā .projā āā projā ā©
ā„ ā”
opaque
zeroā¢one :
⦠ok : No-equality-reflection or-empty (Ī .vars) ⦠ā
¬ Π⢠zero ā” suc zero ā· ā
zeroā¢one = zeroā¢suc
opaque
zeroā”one :
Equality-reflection ā
Ā» ā ā
ā Ī» (Ī : Con Term 1) ā ā Ā» Π⢠zero ā” suc zero ā· ā
zeroā”one ok Ā»ā =
ε ā Id ā zero (suc zero) ,
equality-reflectionā² ok (varā (IdⱼⲠ(zeroā±¼ (ε Ā»ā)) (sucā±¼ (zeroā±¼ (ε Ā»ā)))))
opaque
¬-Id-ā-zero-suc : ¬ ā Ā» ε ⢠u ā· Id ā zero (suc t)
¬-Id-ā-zero-suc {ā} {u} {t} zeroā”suc = ¬Empty ā¢v
where
c : I.Constants
c = Ī» where
.I.gs ā 0
.I.ss ā 0
.I.bms ā 0
.I.ms ā 2
.I.meta-con-size ā 0 V.ā· 0 V.ⷠε
.I.meta-con-term-kind ā tm V.ā· tm V.ⷠε
.I.base-dcon-size ā _
.I.base-con-allowed ā true
.I.base-con-size ā 0
xt xu : I.Term c 0
xt = I.varįµ x0
xu = I.varįµ x1
γ : I.Contexts c
γ .I.grades = ε
γ .I.strengths = ε
γ .I.binder-modes = ε
γ .I.constraintsā° = I.emptyį¶ā°
γ .I.constraints⺠= L.[]
γ .I.ābaseā = ā Ā» ε
γ .I.metas .I.equalities = L.[]
γ .I.metas .I.bindings = λ where
(I.var! x0) ā I.base , I.term t I.ā
(I.var! x1) ā I.base , I.term u (I.Id I.ā I.zero (I.suc xt))
(I.var! not-x2)
v : I.Term c 0
v =
substįµ¢ I.š I.Uā (I.var x0) I.ā I.Empty
(congįµ¢ I.š I.ā I.zero (I.suc xt) I.Uā
(I.natrec I.š I.š I.š I.Uā I.ā I.Empty (I.var x0)) xu)
I.zero
ā¢t : ā Ā» ε ⢠t ā· ā
ā¢t =
inversion-suc (inversion-Id (wf-⢠zeroā”suc) .projā .projā) .projā
ā¢v : ā Ā» ε ⢠I.ā v ā γ ā· Empty
ā¢v = check-type-and-term-sound
γ
(I.base nothing I.Ā» I.base)
v
I.Empty
12
PE.refl
(Ī» where
.IC.constraints-wf ā L.[]
.IC.metas-wf .IC.equalities-wf ā L.[]
.IC.metas-wf .IC.bindings-wf ā Ī» where
(I.var! x0) ā ā¢t
(I.var! x1) ā zeroā”suc
(I.var not-x2 _ _))
(wf zeroā”suc)
opaque
Consistent-glassifyāConsistent :
Consistent (glassify ā Ā» Ī) ā
Consistent (ā Ā» Ī)
Consistent-glassifyāConsistent consistent _ =
consistent _ āā glassify-ā¢
opaque
unfolding inlineįµ
Consistent-inline-ConāConsistent :
Consistent (ε Ā» inline-Conįµ ā Ī) ā
Consistent (ā Ā» Ī)
Consistent-inline-ConāConsistent consistent _ =
consistent _ āā ā¢inlineįµ
opaque
Consistent-āāConsistent :
Ā» āā² ā ā ā
Consistent (āā² Ā» Ī) ā
Consistent (ā Ā» Ī)
Consistent-āāConsistent āā²āā consistent _ =
consistent _ āā defn-wk āā²āā
opaque
unfolding Trans ones inlineįµ
consistency-is-not-preserved :
Opacity-allowed ā
āā Ī» m n (ā : DCon (Term 0) m) (Ī : Con Term n) ā
ā »⢠ΠĆ
Consistent (ā Ā» Ī) Ć
¬ Consistent (glassify ā Ā» Ī) Ć
¬ Consistent (ε Ā» inline-Conįµ ā Ī) Ć
āā Ī» mā² (āā² : DCon (Term 0) mā²) ā
Ā» āā² ā ā à ¬ Consistent (āā² Ā» Ī)
consistency-is-not-preserved ok =
_ , _ , Opaque[ Empty ā· Uā ] , ε ā defn 0 , ā ā¢0 , consistent ,
(Ī» hyp ā hyp _ inconsistentā) ,
(Ī» hyp ā hyp _ inconsistentā) ,
_ , _ , āā ,
(Ī» hyp ā hyp _ inconsistentā)
where
ā¢Īµ : Opaque[ Empty ā· Uā ] »⢠ε
ā¢Īµ = ε (Ā»Opaque ok (Emptyā±¼ εε))
ā¢0ā·U : Opaque[ Empty ā· Uā ] Ā» ε ⢠defn 0 ā· Uā
ā¢0ā·U = defn ā¢Īµ here PE.refl
ā¢0 : Opaque[ Empty ā· Uā ] Ā» ε ⢠defn 0
ā¢0 = univ ā¢0ā·U
ā¢0ā² : glassify Opaque[ Empty ā· Uā ] Ā» ε ⢠defn 0
ā¢0ā² = glassify-⢠ā¢0
inconsistentā :
glassify Opaque[ Empty ā· Uā ] Ā» ε ā defn 0 ⢠var x0 ā· Empty
inconsistentā =
conv (varā ā¢0ā²) (univ (Ī“-red (ā ā¢0ā²) here PE.refl PE.refl))
inconsistentā :
ε Ā» inline-Conįµ Opaque[ Empty ā· Uā ] (ε ā defn 0) ⢠var x0 ā· Empty
inconsistentā =
varā (ā¢Empty εε)
āā :
Ā» Opaque[ Empty ā· Uā ]
ā⨠opa (ε ¹) ā©[ rfl ā· Id (Uā) (defn 0) Empty ] ā
Opaque[ Empty ā· Uā ]
āā =
stepįµā ok (IdⱼⲠā¢0ā·U (Emptyā±¼ ā¢Īµ))
(rflⱼⲠ(Ī“-red (glassify-⢠ā¢Īµ) here PE.refl PE.refl))
ā¢0ā³ :
Opaque[ Empty ā· Uā ] ā⨠opa ones ā©[ rfl ā· Id Uā (defn 0) Empty ] Ā»
ε ⢠defn 0
ā¢0ā³ = defn-wk āā ā¢0
inconsistentā :
Opaque[ Empty ā· Uā ] ā⨠opa ones ā©[ rfl ā· Id Uā (defn 0) Empty ] Ā»
ε ā defn 0 ā¢
subst š Uā (var x0) (defn 0) Empty (defn 1) (var x0) ā· Empty
inconsistentā =
ā¢subst (univ (varā (ā¢Uā (ā ā¢0ā³)))) (defn (ā ā¢0ā³) here PE.refl)
(varā ā¢0ā³)
consistent : Consistent (Opaque[ Empty ā· Uā ] Ā» ε ā defn 0)
consistent t =
let ā¢Īµ = ε āįµ[ āā±¼ εε ] in
Opaque[ Empty ā· Uā ] Ā» ε ā defn 0 ⢠t ā· Empty ā⨠definition-irrelevant-ā¢ā· ok (āā±¼ εε) ā©
Opaque[ ā ā· Uā ] Ā» ε ā defn 0 ⢠t ā· Empty ā⨠glassify-⢠ā©
glassify Opaque[ ā ā· Uā ] Ā» ε ā defn 0 ⢠t ā· Empty ā⨠inhabited-consistent {Ļ = sgSubst _}
(āā¢Ė¢Ź·ā·ā (ā¢Ė¢Ź·ā·Īµā .projā ā¢Īµ)
(conv (zeroā±¼ ā¢Īµ) (univ (symā² (Ī“-red ā¢Īµ here PE.refl PE.refl))))) _ ā©
ā„ ā”
opaque
¬ConsistentāConsistent-glassify :
Opacity-allowed ā
¬ (ā {m n} {ā : DCon (Term 0) m} {Ī : Con Term n} ā
ā »⢠Πā
Consistent (ā Ā» Ī) ā
Consistent (glassify ā Ā» Ī))
¬ConsistentāConsistent-glassify ok hyp =
let _ , _ , _ , _ , ā¢Ī , cons , not-cons , _ =
consistency-is-not-preserved ok
in
not-cons (hyp ā¢Ī cons)
opaque
¬ConsistentāConsistent-inline-Con :
Opacity-allowed ā
¬ (ā {m n} {ā : DCon (Term 0) m} {Ī : Con Term n} ā
ā »⢠Πā
Consistent (ā Ā» Ī) ā
Consistent (ε Ā» inline-Conįµ ā Ī))
¬ConsistentāConsistent-inline-Con ok hyp =
let _ , _ , _ , _ , ā¢Ī , cons , _ , not-cons , _ =
consistency-is-not-preserved ok
in
not-cons (hyp ā¢Ī cons)
opaque
¬ConsistentāConsistent-ā :
Opacity-allowed ā
¬ (ā {m mā² n} {ā : DCon (Term 0) m} {āā² : DCon (Term 0) mā²}
{Ī : Con Term n} ā
ā »⢠Πā Ā» āā² ā ā ā
Consistent (ā Ā» Ī) ā
Consistent (āā² Ā» Ī))
¬ConsistentāConsistent-ā ok hyp =
let _ , _ , _ , _ , ā¢Ī , cons , _ , _ , _ , _ , āā²āā , not-cons =
consistency-is-not-preserved ok
in
not-cons (hyp ā¢Ī āā²āā cons)
opaque
Consistentįµ : Cons m n ā Set a
Consistentįµ (ā Ā» Ī) = Consistent (glassify ā Ā» Ī)
opaque
unfolding Consistentįµ
ConsistentįµāConsistent :
Consistentįµ Ī ā Consistent Ī
ConsistentįµāConsistent = Consistent-glassifyāConsistent
opaque
unfolding Consistentįµ
¬ConsistentāConsistentįµ :
Opacity-allowed ā
¬ (ā {m n} {Ī : Cons m n} ā
⢠Πā Consistent Ī ā Consistentįµ Ī)
¬ConsistentāConsistentįµ ok hyp =
¬ConsistentāConsistent-glassify ok hyp
opaque
unfolding Consistentįµ
subst-Consistentįµ :
ā Ā» Ī ā¢Ė¢Ź· Ļ ā· Ī ā Consistentįµ (ā Ā» Ī) ā
Consistentįµ (ā Ā» Ī)
subst-Consistentįµ = subst-Consistent āā glassify-ā¢Ė¢Ź·ā·
opaque
unfolding Consistentįµ
ā¢Ė¢Ź·ā·āConsistentįµ :
ā Ā» ε ā¢Ė¢Ź· Ļ ā· Ī ā Consistentįµ (ā Ā» Ī)
ā¢Ė¢Ź·ā·āConsistentįµ =
flip subst-Consistentįµ (Ī» _ ā ¬Empty)
opaque
Consistentįµ-ε : Ā» ā ā Consistentįµ (ā Ā» ε)
Consistentįµ-ε =
ā¢Ė¢Ź·ā·āConsistentįµ āā ā¢Ė¢Ź·ā·-idSubst āā ε
opaque
unfolding Consistentįµ
Consistentįµ-glassifyāConsistentįµ :
Consistentįµ (glassify ā Ā» Ī) ā
Consistentįµ (ā Ā» Ī)
Consistentįµ-glassifyāConsistentįµ {ā} {Ī} =
Ī -cong-ā Ī» t ā
(glassify (glassify ā) Ā» Π⢠t ā· Empty ā”⨠PE.congā _ā¢_ā·_ (PE.cong (_Ā» _) (glassify-idem _)) PE.refl PE.refl ā©ā
glassify ā Ā» Π⢠t ā· Empty ā”ā)
ā-cong-ā idā
opaque
unfolding Consistentįµ inlineįµ
Consistentįµ-inline-ConāConsistentįµ :
(glassify ā »⢠Πā Consistentįµ (ε Ā» inline-Conįµ ā Ī)) ā
Consistentįµ (ā Ā» Ī)
Consistentįµ-inline-ConāConsistentįµ =
(Ī» consistent _ ā¢t ā
consistent (wf ā¢t) _ $
PE.substā _ā¢_ā·_
(PE.cong (_Ā»_ _) inline-Conįµ-glassify) PE.refl PE.refl $
ā¢inlineįµ ā¢t) ,
(Ī» consistent ā¢Ī _ ā
consistent _ āā
stability
(PE.substā _Ā»ā¢_ā”_
(glassify-idem _) inline-Conįµ-glassify PE.refl $
ā¢inline-Conįµā” ā¢Ī) āā
defn-wk (Ā»āε (defn-wf ā¢Ī)))
opaque
unfolding Consistentįµ
Consistentįµ-āāConsistentįµ :
(ā {n} {āā² : DCon (Term 0) n} ā
glassify ā »⢠Πā Ā» glassify āā² ā glassify ā ā
Consistentįµ (āā² Ā» Ī)) ā
Consistentįµ (ā Ā» Ī)
Consistentįµ-āāConsistentįµ =
(Ī» consistent _ ā¢t ā
consistent (wf ā¢t) idā _ ā¢t) ,
(Ī» consistent ā¢Ī āā²āā _ ā¢t ā
consistent _ $
PE.substā _ā¢_ā·_
(PE.cong (_Ā» _) $ glassify-idem _) PE.refl PE.refl $
inhabited-under-glassified-context (ā¢Empty ā¢Ī) āā²āā ā¢t .projā)
opaque
All-extensions-consistent : Cons m n ā Set a
All-extensions-consistent (ā Ā» Ī) =
ā {k} {āā² : DCon (Term 0) k} ā Ā» āā² ā ā ā Consistent (āā² Ā» Ī)
opaque
unfolding All-extensions-consistent Consistentįµ
All-extensions-consistentāConsistentįµ :
āā Ī -allowed or-empty (Ī .vars) ā
⢠Πā
All-extensions-consistent Ī ā Consistentįµ Ī
All-extensions-consistentāConsistentįµ ok ā¢Ī =
(Ī» consistent _ ā¢t ā
let _ , _ , _ , āā²āā , ā¢u =
inhabited-under-extension ok (ā¢Empty ā¢Ī) ā¢t
in
consistent āā²āā _ ā¢u) ,
(Ī» consistent āā²āā _ ā¢t ā
consistent _ $
inhabited-under-glassified-context (ā¢Empty ā¢Ī) āā²āā ā¢t .projā)
opaque
unfolding All-extensions-consistent
All-extensions-consistentāConsistent :
All-extensions-consistent Ī ā Consistent Ī
All-extensions-consistentāConsistent = _$ idā
opaque
unfolding All-extensions-consistent
¬ConsistentāAll-extensions-consistent :
Opacity-allowed ā
¬ (ā {m n} {Ī : Cons m n} ā
⢠Πā Consistent Ī ā All-extensions-consistent Ī)
¬ConsistentāAll-extensions-consistent ok hyp =
let _ , _ , _ , _ , ā¢Ī , cons , _ , _ , _ , _ , āā²āā , not-cons =
consistency-is-not-preserved ok
in
not-cons (hyp ā¢Ī cons āā²āā)
opaque
unfolding All-extensions-consistent
subst-All-extensions-consistent :
ā Ā» Ī ā¢Ė¢Ź· Ļ ā· Ī ā All-extensions-consistent (ā Ā» Ī) ā
All-extensions-consistent (ā Ā» Ī)
subst-All-extensions-consistent ā¢Ļ consistent āā²āā =
subst-Consistent (defn-wkSubstŹ· āā²āā ā¢Ļ) (consistent āā²āā)
opaque
unfolding All-extensions-consistent
ā¢Ė¢Ź·ā·āAll-extensions-consistent :
ā Ā» ε ā¢Ė¢Ź· Ļ ā· Ī ā All-extensions-consistent (ā Ā» Ī)
ā¢Ė¢Ź·ā·āAll-extensions-consistent =
flip subst-All-extensions-consistent (Ī» _ _ ā ¬Empty)
opaque
All-extensions-consistent-ε : Ā» ā ā All-extensions-consistent (ā Ā» ε)
All-extensions-consistent-ε =
ā¢Ė¢Ź·ā·āAll-extensions-consistent āā ā¢Ė¢Ź·ā·-idSubst āā ε