{-# OPTIONS --allow-unsolved-metas #-}
module A201602.Try12 where
open import Data.Nat using (β; zero; suc; _+_)
open import Data.Product using (Ξ£) renaming (_,_ to β¨_,_β©)
infixl 5 _β_ _βΒ²_
infixr 4 π_,_ πΒ²_,_
infixr 3 _βΆ_
infixr 3 _β_
infixl 3 _,_
infixl 2 _β§_
infixr 1 _β_
infixr 1 _ββ_
infixr 0 _β’_β·_
infixr 0 β©_ β©_β·_ β©_β·_β·_
Var : Set
Var = β
mutual
data Ty : Set where
β₯ : Ty
_β_ : Ty β Ty β Ty
_β§_ : Ty β Ty β Ty
_βΆ_ : Tm β Ty β Ty
data Tm : Set where
π£_ : Var β Tm
π[_]_,_ : β β Var β Tm β Tm
_β[_]_ : Tm β β β Tm β Tm
π[_]β¨_,_β© : β β Tm β Tm β Tm
πβ[_]_ : β β Tm β Tm
πβ[_]_ : β β Tm β Tm
!_ : Tm β Tm
β[_]_ : β β Tm β Tm
β[_]_ : β β Tm β Tm
β€ : Ty
β€ = β₯ β β₯
Β¬_ : Ty β Ty
Β¬ A = A β β₯
_ββ_ : Ty β Ty β Ty
A ββ B = A β B β§ B β A
π_,_ : Var β Tm β Tm
π x , t = π[ 1 ] x , t
πΒ²_,_ : Var β Tm β Tm
πΒ² xβ , tβ = π[ 2 ] xβ , tβ
_β_ : Tm β Tm β Tm
t β s = t β[ 1 ] s
_βΒ²_ : Tm β Tm β Tm
tβ βΒ² sβ = tβ β[ 2 ] sβ
πβ¨_,_β© : Tm β Tm β Tm
πβ¨ t , s β© = π[ 1 ]β¨ t , s β©
πΒ²β¨_,_β© : Tm β Tm β Tm
πΒ²β¨ tβ , sβ β© = π[ 2 ]β¨ tβ , sβ β©
πβ_ : Tm β Tm
πβ t = πβ[ 1 ] t
πβΒ²_ : Tm β Tm
πβΒ² tβ = πβ[ 2 ] tβ
πβ_ : Tm β Tm
πβ t = πβ[ 1 ] t
πβΒ²_ : Tm β Tm
πβΒ² tβ = πβ[ 2 ] tβ
β_ : Tm β Tm
β t = β[ 1 ] t
βΒ²_ : Tm β Tm
βΒ² tβ = β[ 2 ] tβ
β_ : Tm β Tm
β t = β[ 1 ] t
βΒ²_ : Tm β Tm
βΒ² tβ = β[ 2 ] tβ
data Vec (X : Set) : β β Set where
β
: Vec X zero
_β_ : β{n} β X β Vec X n β Vec X (suc n)
_β_ : β{n m} {X : Set} β Vec X n β Vec X m β Vec X (n + m)
β
β ys = ys
(x β xs) β ys = x β xs β ys
foldr : β{n} {X : Set} (Y : β β Set) β (β{k} β X β Y k β Y (suc k)) β Y zero β Vec X n β Y n
foldr Y f yβ β
= yβ
foldr Y f yβ (x β xs) = f x (foldr Y f yβ xs)
ixMap : β{n} {X Y : Set} β (β β X β Y) β Vec X n β Vec Y n
ixMap {zero} f β
= β
ixMap {suc n} f (x β xs) = f (suc n) x β ixMap f xs
ixZipWith : β{n} {X Y Z : Set} β (β β X β Y β Z) β Vec X n β Vec Y n β Vec Z n
ixZipWith {zero} f β
β
= β
ixZipWith {suc n} f (x β xs) (y β ys) = f (suc n) x y β ixZipWith f xs ys
map : β{n} {X Y : Set} β (X β Y) β Vec X n β Vec Y n
map f = ixMap (Ξ» _ x β f x)
zipWith : β{n} {X Y Z : Set} β (X β Y β Z) β Vec X n β Vec Y n β Vec Z n
zipWith f = ixZipWith (Ξ» _ x y β f x y)
Vars : β β Set
Vars = Vec Var
Tms : β β Set
Tms = Vec Tm
π£βΏ_ : β{n} β Vars n β Tms n
π£βΏ_ = map π£_
πβΏ_,_ : β{n} β Vars n β Tms n β Tms n
πβΏ_,_ = ixZipWith π[_]_,_
_ββΏ_ : β{n} β Tms n β Tms n β Tms n
_ββΏ_ = ixZipWith (Ξ» n t s β t β[ n ] s)
πβΏβ¨_,_β© : β{n} β Tms n β Tms n β Tms n
πβΏβ¨_,_β© = ixZipWith π[_]β¨_,_β©
πββΏ_ : β{n} β Tms n β Tms n
πββΏ_ = ixMap πβ[_]_
πββΏ_ : β{n} β Tms n β Tms n
πββΏ_ = ixMap πβ[_]_
ββΏ_ : β{n} β Tms n β Tms n
ββΏ_ = ixMap β[_]_
ββΏ_ : β{n} β Tms n β Tms n
ββΏ_ = ixMap β[_]_
record Hyp : Set where
constructor H[_]_β·_
field
n : β
ts : Tms n
A : Ty
data Cx : β β Set where
β
: Cx zero
_,_ : β{m} β Cx m β Hyp β Cx (suc m)
data _β_ : β{m} β Hyp β Cx m β Set where
Z : β{m} {Ξ : Cx m} {h : Hyp} β h β (Ξ , h)
S_ : β{m} {Ξ : Cx m} {h hβ² : Hyp} β h β Ξ β h β (Ξ , hβ²)
data _β’_β·_ {m : β} (Ξ : Cx m) : β{n} β Tms n β Ty β Set where
Mπ£_ : β{n A} {ts : Tms n} β (H[ n ] ts β· A) β Ξ
β Ξ β’ ts β· A
Mπ : β{n A B} {xs : Vars n} {ts : Tms n} β Ξ , H[ n ] π£βΏ xs β· A β’ ts β· B
β Ξ β’ πβΏ xs , ts β· A β B
Mβ : β{n A B} {ts ss : Tms n} β Ξ β’ ts β· A β B β Ξ β’ ss β· A
β Ξ β’ ts ββΏ ss β· B
Mπ : β{n A B} {ts ss : Tms n} β Ξ β’ ts β· A β Ξ β’ ss β· B
β Ξ β’ πβΏβ¨ ts , ss β© β· A β§ B
Mπβ : β{n A B} {ts : Tms n} β Ξ β’ ts β· A β§ B
β Ξ β’ πββΏ ts β· A
Mπβ : β{n A B} {ts : Tms n} β Ξ β’ ts β· A β§ B
β Ξ β’ πββΏ ts β· B
Mβ : β{n A u} {ts : Tms n} β Ξ β’ ts β· u βΆ A
β Ξ β’ ββΏ ts β· ! u βΆ u βΆ A
Mβ : β{n A u} {ts : Tms n} β Ξ β’ ts β· u βΆ A
β Ξ β’ ββΏ ts β· A
Mβ» : β{n A u} {ts : Tms n} β Ξ β’ ts β· u βΆ A
β Ξ β’ ts β (u β β
) β· A
MβΊ : β{n A u} {ts : Tms n} β Ξ β’ ts β (u β β
) β· A
β Ξ β’ ts β· u βΆ A
β©_ : Ty β Set
β© A = β{m} {Ξ : Cx m} β Ξ β’ β
β· A
β©_β·_ : Tm β Ty β Set
β© t β· A = β{m} {Ξ : Cx m} β Ξ β’ t β β
β· A
β©_β·_β·_ : Tm β Tm β Ty β Set
β© tβ β· t β· A = β{m} {Ξ : Cx m} β Ξ β’ tβ β t β β
β· A
eIβ° : β{A}
β β© A β A
eIβ° = Mπ (Mπ£ Z)
eIΒΉ : β{A x}
β β© π x , π£ x
β· A β A
eIΒΉ = Mπ (Mπ£ Z)
eIΒ² : β{A x u}
β β© πΒ² u , π£ u
β· π x , π£ x
β· A β A
eIΒ² = Mπ (Mπ£ Z)
eKβ° : β{A B}
β β© A β B β A
eKβ° = Mπ (Mπ (Mπ£ S Z))
eKΒΉ : β{A B x y}
β β© π x , π y , π£ x
β· A β B β A
eKΒΉ = Mπ (Mπ (Mπ£ S Z))
eKΒ² : β{A B x y u v}
β β© πΒ² u , πΒ² v , π£ u
β· π x , π y , π£ x
β· A β B β A
eKΒ² = Mπ (Mπ (Mπ£ S Z))
eSβ° : β{A B C}
β β© (A β B β C) β (A β B) β A β C
eSβ° = Mπ (Mπ (Mπ (Mβ (Mβ (Mπ£ S S Z)
(Mπ£ Z))
(Mβ (Mπ£ S Z)
(Mπ£ Z)))))
eSΒΉ : β{A B C f g x}
β β© π f , π g , π x , (π£ f β π£ x) β (π£ g β π£ x)
β· (A β B β C) β (A β B) β A β C
eSΒΉ = Mπ (Mπ (Mπ (Mβ (Mβ (Mπ£ S S Z)
(Mπ£ Z))
(Mβ (Mπ£ S Z)
(Mπ£ Z)))))
eSΒ² : β{A B C f g x p q u}
β β© πΒ² p , πΒ² q , πΒ² u , (π£ p βΒ² π£ u) βΒ² (π£ q βΒ² π£ u)
β· π f , π g , π x , (π£ f β π£ x) β (π£ g β π£ x)
β· (A β B β C) β (A β B) β A β C
eSΒ² = Mπ (Mπ (Mπ (Mβ (Mβ (Mπ£ S S Z)
(Mπ£ Z))
(Mβ (Mπ£ S Z)
(Mπ£ Z)))))
e11 : β{A x y}
β β© π y , β π£ y
β· x βΆ A β A
e11 = Mπ (Mβ (Mπ£ Z))
e12 : β{A x y}
β β© π y , β π£ y
β· x βΆ A β ! x βΆ x βΆ A
e12 = Mπ (Mβ (Mπ£ Z))
e13 : β{A B x y u v}
β β© πΒ² u , πΒ² v , πΒ²β¨ π£ u , π£ v β©
β· π x , π y , πβ¨ π£ x , π£ y β©
β· A β B β A β§ B
e13 = Mπ (Mπ (Mπ (Mπ£ S Z)
(Mπ£ Z)))
e14 : β{A B x y u v}
β β© π u , π v , β πΒ²β¨ π£ u , π£ vΒ β©
β· x βΆ A β y βΆ B β ! πβ¨ x , y β© βΆ πβ¨ x , y β© βΆ (A β§ B)
e14 = Mπ (Mπ (Mβ (MβΊ (Mπ (Mβ» (Mπ£ S Z))
(Mβ» (Mπ£ Z))))))
t0 : β{A B x y u v}
β β© π u , π v , πΒ²β¨ π£ u , π£ v β©
β· x βΆ A β y βΆ B β πβ¨ x , y β© βΆ (A β§ B)
t0 = Mπ (Mπ (MβΊ (Mπ (Mβ» (Mπ£ S Z))
(Mβ» (Mπ£ Z)))))
t1 : β{A B x y u}
β β© π u , πΒ²β¨ πβ π£ u , πβ π£ u β©
β· x βΆ A β§ y βΆ B β πβ¨ x , y β© βΆ (A β§ B)
t1 = Mπ (MβΊ (Mπ (Mβ» (Mπβ (Mπ£ Z)))
(Mβ» (Mπβ (Mπ£ Z)))))
t2 : β{A B x y u}
β β© π u , β πΒ²β¨ πβ π£ u , πβ π£ u β©
β· x βΆ A β§ y βΆ B β ! πβ¨ x , y β© βΆ πβ¨ x , y β© βΆ (A β§ B)
t2 = Mπ (Mβ (MβΊ (Mπ (Mβ» (Mπβ (Mπ£ Z)))
(Mβ» (Mπβ (Mπ£ Z))))))
axK : β{A B f x p u}
β β© π p , π u , π£ p βΒ² π£ u
β· f βΆ (A β B) β x βΆ A β (f β x) βΆ B
axK = Mπ (Mπ (MβΊ (Mβ (Mβ» (Mπ£ S Z))
(Mβ» (Mπ£ Z)))))
axT : β{A x u}
β β© π u , β π£ u
β· x βΆ A β A
axT = e11
ax4 : β{A x u}
β β© π u , β π£ u
β· x βΆ A β ! x βΆ x βΆ A
ax4 = e12
e2 : β{A xβ xβ xβ}
β β© πΒ² xβ , βΒ² βΒ² π£ xβ
β· π xβ , β β π£ xβ
β· xβ βΆ A β xβ βΆ A
e2 = Mπ (Mβ (Mβ (Mπ£ Z)))
e2β² : β{A xβ xβ xβ}
β β© πΒ² xβ , π£ xβ
β· π xβ , π£ xβ
β· xβ βΆ A β xβ βΆ A
e2β² = Mπ (Mπ£ Z)
_β’_ : β{m} (Ξ : Cx m) (h : Hyp) β Set
Ξ β’ (H[ n ] ts β· A) = Ξ β’ ts β· A
data _β²_ : β{m mβ²} β Cx m β Cx mβ² β Set where
base : β
β² β
keep : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β² Ξβ² β (Ξ , h) β² (Ξβ² , h)
drop : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β² Ξβ² β Ξ β² (Ξβ² , h)
β
β²Ξ : β{m} {Ξ : Cx m} β β
β² Ξ
β
β²Ξ {Ξ = β
} = base
β
β²Ξ {Ξ = Ξ , h} = drop β
β²Ξ
Ξβ²Ξ : β{m} {Ξ : Cx m} β Ξ β² Ξ
Ξβ²Ξ {Ξ = β
} = base
Ξβ²Ξ {Ξ = Ξ , h} = keep Ξβ²Ξ
wkβ : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β² Ξβ² β h β Ξ β h β Ξβ²
wkβ base ()
wkβ (keep p) Z = Z
wkβ (keep p) (S i) = S wkβ p i
wkβ (drop p) i = S wkβ p i
wkβ’ : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β² Ξβ² β Ξ β’ h β Ξβ² β’ h
wkβ’ p (Mπ£ i) = Mπ£ (wkβ p i)
wkβ’ p (Mπ d) = Mπ (wkβ’ (keep p) d)
wkβ’ p (Mβ d dβ²) = Mβ (wkβ’ p d) (wkβ’ p dβ²)
wkβ’ p (Mπ d dβ²) = Mπ (wkβ’ p d) (wkβ’ p dβ²)
wkβ’ p (Mπβ d) = Mπβ (wkβ’ p d)
wkβ’ p (Mπβ d) = Mπβ (wkβ’ p d)
wkβ’ p (Mβ d) = Mβ (wkβ’ p d)
wkβ’ p (Mβ d) = Mβ (wkβ’ p d)
wkβ’ p (Mβ» d) = Mβ» (wkβ’ p d)
wkβ’ p (MβΊ d) = MβΊ (wkβ’ p d)
data _β³_ : β{m mβ²} β Cx m β Cx mβ² β Set where
base : β
β³ β
once : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β³ Ξβ² β (Ξ , h) β³ (Ξβ² , h)
more : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β³ Ξβ² β (Ξ , h , h) β³ (Ξβ² , h)
cnβ : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β³ Ξβ² β h β Ξ β h β Ξβ²
cnβ base ()
cnβ (once p) Z = Z
cnβ (once p) (S i) = S cnβ p i
cnβ (more p) Z = Z
cnβ (more p) (S i) = cnβ (once p) i
cnβ’ : β{m mβ² h} {Ξ : Cx m} {Ξβ² : Cx mβ²} β Ξ β³ Ξβ² β Ξ β’ h β Ξβ² β’ h
cnβ’ p (Mπ£ i) = Mπ£ (cnβ p i)
cnβ’ p (Mπ d) = Mπ (cnβ’ (once p) d)
cnβ’ p (Mβ d dβ²) = Mβ (cnβ’ p d) (cnβ’ p dβ²)
cnβ’ p (Mπ d dβ²) = Mπ (cnβ’ p d) (cnβ’ p dβ²)
cnβ’ p (Mπβ d) = Mπβ (cnβ’ p d)
cnβ’ p (Mπβ d) = Mπβ (cnβ’ p d)
cnβ’ p (Mβ d) = Mβ (cnβ’ p d)
cnβ’ p (Mβ d) = Mβ (cnβ’ p d)
cnβ’ p (Mβ» d) = Mβ» (cnβ’ p d)
cnβ’ p (MβΊ d) = MβΊ (cnβ’ p d)
data _β_ : β{m} β Cx m β Cx m β Set where
base : β
β β
just : β{m h} {Ξ Ξβ² : Cx m} β Ξ β Ξβ² β (Ξ , h) β (Ξβ² , h)
same : β{m h hβ²} {Ξ Ξβ² : Cx m} β Ξ β Ξβ² β (Ξ , h , hβ²) β (Ξβ² , h , hβ²)
diff : β{m h hβ²} {Ξ Ξβ² : Cx m} β Ξ β Ξβ² β (Ξ , hβ² , h) β (Ξβ² , h , hβ²)
exβ : β{m h} {Ξ Ξβ² : Cx m} β Ξ β Ξβ² β h β Ξ β h β Ξβ²
exβ base ()
exβ (just p) Z = Z
exβ (just p) (S i) = S exβ p i
exβ (same p) Z = Z
exβ (same p) (S Z) = S Z
exβ (same p) (S (S i)) = S (S exβ p i)
exβ (diff p) Z = S Z
exβ (diff p) (S Z) = Z
exβ (diff p) (S (S i)) = S (S exβ p i)
exβ’ : β{m h} {Ξ Ξβ² : Cx m} β Ξ β Ξβ² β Ξ β’ h β Ξβ² β’ h
exβ’ p (Mπ£ i) = Mπ£ (exβ p i)
exβ’ p (Mπ d) = Mπ (exβ’ (just p) d)
exβ’ p (Mβ d dβ²) = Mβ (exβ’ p d) (exβ’ p dβ²)
exβ’ p (Mπ d dβ²) = Mπ (exβ’ p d) (exβ’ p dβ²)
exβ’ p (Mπβ d) = Mπβ (exβ’ p d)
exβ’ p (Mπβ d) = Mπβ (exβ’ p d)
exβ’ p (Mβ d) = Mβ (exβ’ p d)
exβ’ p (Mβ d) = Mβ (exβ’ p d)
exβ’ p (Mβ» d) = Mβ» (exβ’ p d)
exβ’ p (MβΊ d) = MβΊ (exβ’ p d)
postulate fresh : Var
toVec : β{m} β Cx m β Vec Hyp m
toVec β
= β
toVec (Ξ , h) = h β toVec Ξ
fromVec : β{m} β Vec Hyp m β Cx m
fromVec β
= β
fromVec (h β hs) = fromVec hs , h
prefixHyp : Tm β Hyp β Hyp
prefixHyp t (H[ n ] ts β· A) = H[ suc n ] (t β ts) β· A
prefixHyps : β{m} β Tms m β Cx m β Cx m
prefixHyps ts Ξ = fromVec (zipWith prefixHyp ts (toVec Ξ))
inβ : β{m h} {vs : Vars m} {Ξ : Cx m}
β h β Ξ β Ξ£ Var (Ξ» x β prefixHyp (π£ x) h β Ξ)
inβ {vs = β
} ()
inβ {vs = x β vs} Z = {!β¨ x , Z β©!}
inβ {vs = x β vs} (S i) = {!!}
inβ’ : β{m h} {vs : Vars m} {Ξ : Cx m}
β Ξ β’ h β Ξ£ (Vars m β Tm) (Ξ» t β prefixHyps (map π£_ vs) Ξ β’ prefixHyp (t vs) h)
inβ’ d = {!!}
nec : β{h} β β
β’ h β Ξ£ Tm (Ξ» t β β
β’ prefixHyp t h)
nec d = let β¨ s , c β© = inβ’ d in β¨ s β
, c β©