{-# OPTIONS --allow-unsolved-metas #-}

{-

'(agda-input-user-translations
   (quote
    (("i" "βŠƒ") ("e" "⊒") ("t" "⊩")
     ("f" "𝑓") ("f2" "𝑓²") ("f3" "𝑓³") ("fn" "𝑓ⁿ")
     ("v" "𝑣") ("v2" "𝑣²") ("v3" "𝑣³") ("vn" "𝑣ⁿ")
     ("l" "πœ†") ("l2" "πœ†Β²") ("l3" "πœ†Β³") ("ln" "πœ†βΏ")
     ("o" "∘") ("o2" "∘²") ("o3" "∘³") ("on" "∘ⁿ")
     ("p" "𝑝") ("p2" "𝑝²") ("p3" "𝑝³") ("pn" "𝑝ⁿ")
     ("1" "πœ‹β‚€") ("12" "πœ‹β‚€Β²") ("13" "πœ‹β‚€Β³") ("1n" "πœ‹β‚€βΏ")
     ("2" "πœ‹β‚") ("22" "πœ‹β‚Β²") ("23" "πœ‹β‚Β³") ("2n" "πœ‹β‚βΏ")
     ("u" "⇑") ("u2" "⇑²") ("u3" "⇑³") ("un" "⇑ⁿ")
     ("d" "⇓") ("d2" "⇓²") ("d3" "⇓³") ("dn" "⇓ⁿ"))))

-}

module A201602.Try4 where

open import Data.Fin using (Fin; zero; suc; toβ„•)
open import Data.Nat using (β„•; zero; suc; _+_)
open import Data.Product using (Ξ£; _Γ—_; _,_)


data Vec (X : Set) : β„• β†’ Set where
  βˆ…   : Vec X zero
  _,_ : βˆ€{n} β†’ Vec X n β†’ X β†’ Vec X (suc n)

data _∈_ {X : Set} : βˆ€{n} β†’ X β†’ Vec X n β†’ Set where
  Z  : βˆ€{n x} {xs : Vec X n}
     β†’ x ∈ (xs , x)
  S_ : βˆ€{n x y} {xs : Vec X n}
     β†’ x ∈ xs
     β†’ x ∈ (xs , y)


infixl 4 _∘_ _∘²_ _∘³_
infixr 3 πœ†_ πœ†Β²_ πœ†Β³_
infixl 2 _∧_
infixr 1 _βŠƒ_
infixr 0 _βˆ™_⊒_ _⊩_ βŠͺ_
infixr 0 _βˆ™_⊒_∷_ _⊩_∷_ βŠͺ_∷_
infixr 0 _βˆ™_⊒_∷_∷_ _⊩_∷_∷_ βŠͺ_∷_∷_


data Ty : Set where
  βŠ₯   : Ty
  _βŠƒ_ : Ty β†’ Ty β†’ Ty
  _∧_ : Ty β†’ Ty β†’ Ty


Cx : β„• β†’ Set
Cx = Vec Ty


data _βˆ™_⊒_ {k n : β„•} (Ξ¦ : Cx k) (Ξ“ : Cx n) : Ty β†’ Set where
  𝑓_     : βˆ€{A}
         β†’ A ∈ Ξ¦
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A
  𝑣_     : βˆ€{A}
         β†’ A ∈ Ξ“
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A
  πœ†_     : βˆ€{A B}
         β†’ Ξ¦ βˆ™ Ξ“ , A ⊒ B
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A βŠƒ B
  _∘_    : βˆ€{A B}
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A βŠƒ B    β†’ Ξ¦ βˆ™ Ξ“ ⊒ A
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ B
  π‘βŸ¨_,_⟩ : βˆ€{A B}
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A        β†’ Ξ¦ βˆ™ Ξ“ ⊒ B
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B
  πœ‹β‚€_    : βˆ€{A B}
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A
  πœ‹β‚_    : βˆ€{A B}
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B
         β†’ Ξ¦ βˆ™ Ξ“ ⊒ B


_⊩_ : βˆ€{k} β†’ Cx k β†’ Ty β†’ Set
Ξ¦ ⊩ A = βˆ€{n} {Ξ“ : Cx n} β†’ Ξ¦ βˆ™ Ξ“ ⊒ A

βŠͺ_ : Ty β†’ Set
βŠͺ A = βˆ€{k} {Ξ¦ : Cx k} β†’ Ξ¦ ⊩ A


tI : βˆ€{A}
   β†’ βŠͺ A βŠƒ A
tI = πœ† 𝑣 Z

tK : βˆ€{A B}
   β†’ βŠͺ A βŠƒ B βŠƒ A
tK = πœ† πœ† 𝑣 S Z

tS : βˆ€{A B C}
   β†’ βŠͺ (A βŠƒ B βŠƒ C) βŠƒ (A βŠƒ B) βŠƒ A βŠƒ C
tS = πœ† πœ† πœ† (𝑣 S S Z ∘ 𝑣 Z) ∘ (𝑣 S Z ∘ 𝑣 Z)


data _βˆ™_⊒_∷_ {k n : β„•} (Ξ¦ : Cx k) (Ξ“ : Cx n) : (A : Ty) β†’ Ξ¦ βˆ™ Ξ“ ⊒ A β†’ Set where
  𝑓²_     : βˆ€{A x}
          β†’ A ∈ Ξ¦
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ 𝑓 x
  𝑣²_     : βˆ€{A}
          β†’ (x : A ∈ Ξ“)
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ 𝑣 x
  πœ†Β²_     : βˆ€{A B t}
          β†’ Ξ¦ βˆ™ Ξ“ , A ⊒ B ∷ t
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A βŠƒ B ∷ πœ† t
  _∘²_    : βˆ€{A B t s}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A βŠƒ B ∷ t    β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ s
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ B ∷ t ∘ s
  π‘Β²βŸ¨_,_⟩ : βˆ€{A B t s}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t        β†’ Ξ¦ βˆ™ Ξ“ ⊒ B ∷ s
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B ∷ π‘βŸ¨ t , s ⟩
  πœ‹β‚€Β²_    : βˆ€{A B t}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B ∷ t
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ πœ‹β‚€ t
  πœ‹β‚Β²_    : βˆ€{A B t}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B ∷ t
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ B ∷ πœ‹β‚ t
  !_      : βˆ€{A t}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t


_⊩_∷_ : βˆ€{k} (Ξ¦ : Cx k) (A : Ty) β†’ Ξ¦ ⊩ A β†’ Set
Ξ¦ ⊩ A ∷ t = βˆ€{n} {Ξ“ : Cx n} β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t

βŠͺ_∷_ : (A : Ty) β†’ βŠͺ A β†’ Set
βŠͺ A ∷ t = βˆ€{k} {Ξ¦ : Cx k} β†’ Ξ¦ ⊩ A ∷ t


tIΒ² : βˆ€{A}
    β†’ βŠͺ A βŠƒ A
      ∷ πœ† 𝑣 Z
tIΒ² = πœ†Β² (𝑣² Z)

tKΒ² : βˆ€{A B}
    β†’ βŠͺ A βŠƒ B βŠƒ A
      ∷ πœ† πœ† 𝑣 S Z
tKΒ² = πœ†Β² πœ†Β² 𝑣² S Z

tSΒ² : βˆ€{A B C}
    β†’ βŠͺ (A βŠƒ B βŠƒ C) βŠƒ (A βŠƒ B) βŠƒ A βŠƒ C
      ∷ πœ† πœ† πœ† (𝑣 S S Z ∘ 𝑣 Z) ∘ (𝑣 S Z ∘ 𝑣 Z)
tSΒ² = πœ†Β² πœ†Β² πœ†Β² (𝑣² S S Z ∘² 𝑣² Z) ∘² (𝑣² S Z ∘² 𝑣² Z)



data _βˆ™_⊒_∷_∷_ {k n : β„•} (Ξ¦ : Cx k) (Ξ“ : Cx n) : (A : Ty) β†’ (t : Ξ¦ βˆ™ Ξ“ ⊒ A) β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t β†’ Set where
  𝑓³_      : βˆ€{A x}
          β†’ A ∈ Ξ¦
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ 𝑓 x ∷ 𝑓² x
  𝑣³_     : βˆ€{A}
          β†’ (x : A ∈ Ξ“)
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ 𝑣 x ∷ 𝑣² x
  πœ†Β³_     : βˆ€{A B t tβ‚‚}
          β†’ Ξ¦ βˆ™ Ξ“ , A ⊒ B ∷ t ∷ tβ‚‚
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A βŠƒ B ∷ πœ† t ∷ πœ†Β² tβ‚‚
  _∘³_    : βˆ€{A B t tβ‚‚ s sβ‚‚}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A βŠƒ B ∷ t ∷ tβ‚‚   β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ s ∷ sβ‚‚
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ B ∷ t ∘ s ∷ tβ‚‚ ∘² sβ‚‚
  π‘Β³βŸ¨_,_⟩ : βˆ€{A B t tβ‚‚ s sβ‚‚}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t ∷ tβ‚‚       β†’ Ξ¦ βˆ™ Ξ“ ⊒ B ∷ s ∷ sβ‚‚
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B ∷ π‘βŸ¨ t , s ⟩ ∷ π‘Β²βŸ¨ tβ‚‚ , sβ‚‚ ⟩
  πœ‹β‚€Β³_    : βˆ€{A B t tβ‚‚}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B ∷ t ∷ tβ‚‚
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ πœ‹β‚€ t ∷ πœ‹β‚€Β² tβ‚‚
  πœ‹β‚Β³_    : βˆ€{A B t tβ‚‚}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∧ B ∷ t ∷ tβ‚‚
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ B ∷ πœ‹β‚ t ∷ πœ‹β‚Β² tβ‚‚
  !_      : βˆ€{A t tβ‚‚}
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t ∷ tβ‚‚
          β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t ∷ tβ‚‚


⇑_ : βˆ€{k n} {Ξ¦ : Cx k} {Ξ“ : Cx n} {A : Ty} {u : Ξ¦ βˆ™ Ξ“ ⊒ A}
   β†’ (x : Ξ¦ βˆ™ Ξ“ ⊒ A ∷ u)
   β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ u ∷ (! x)
⇑_ = {!!}

⇓_ : βˆ€{k n} {Ξ¦ : Cx k} {Ξ“ : Cx n} {A : Ty} {u : Ξ¦ βˆ™ Ξ“ ⊒ A}
   β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ u
   β†’ Ξ¦ βˆ™ Ξ“ ⊒ A
⇓_ {u = u} = Ξ» _ β†’ u


_⊩_∷_∷_ : βˆ€{k} (Ξ¦ : Cx k) (A : Ty) (t : Ξ¦ ⊩ A) β†’ Ξ¦ ⊩ A ∷ t β†’ Set
Ξ¦ ⊩ A ∷ t ∷ tβ‚‚ = βˆ€{n} {Ξ“ : Cx n} β†’ Ξ¦ βˆ™ Ξ“ ⊒ A ∷ t ∷ tβ‚‚

βŠͺ_∷_∷_ : (A : Ty) (t : βŠͺ A) β†’ βŠͺ A ∷ t β†’ Set
βŠͺ A ∷ t ∷ tβ‚‚ = βˆ€{k} {Ξ¦ : Cx k} β†’ Ξ¦ ⊩ A ∷ t ∷ tβ‚‚


tIΒ³ : βˆ€{A} β†’ βŠͺ A βŠƒ A
    ∷ πœ† 𝑣 Z
    ∷ πœ†Β² 𝑣² Z
tIΒ³ = πœ†Β³ 𝑣³ Z

tKΒ³ : βˆ€{A B} β†’ βŠͺ A βŠƒ B βŠƒ A
    ∷ πœ† πœ† 𝑣 S Z
    ∷ πœ†Β² πœ†Β² 𝑣² S Z
tKΒ³ = πœ†Β³ πœ†Β³ 𝑣³ S Z

tSΒ³ : βˆ€{A B C} β†’ βŠͺ (A βŠƒ B βŠƒ C) βŠƒ (A βŠƒ B) βŠƒ A βŠƒ C
    ∷ πœ† πœ† πœ† (𝑣 S S Z ∘ 𝑣 Z) ∘ (𝑣 S Z ∘ 𝑣 Z)
    ∷ πœ†Β² πœ†Β² πœ†Β² (𝑣² S S Z ∘² 𝑣² Z) ∘² (𝑣² S Z ∘² 𝑣² Z)
tSΒ³ = πœ†Β³ πœ†Β³ πœ†Β³ (𝑣³ S S Z ∘³ 𝑣³ Z) ∘³ (𝑣³ S Z ∘³ 𝑣³ Z)


-- tt : βˆ€{A x}
--    β†’ βˆ… , x ⊩ A βŠƒ A
--            ∷ ?
--            ∷ πœ† ⇑ 𝑣 Z
-- tt = {!!}