ObsEq2.agda 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. module ObsEq2 where
  2. data Nat : Set where
  3. zero : Nat
  4. suc : Nat -> Nat
  5. data Fin : Nat -> Set where
  6. fz : {n : Nat} -> Fin (suc n)
  7. fs : {n : Nat} -> Fin n -> Fin (suc n)
  8. infixr 40 _::_ _,_
  9. data List (X : Set) : Set where
  10. ε : List X
  11. _::_ : X -> List X -> List X
  12. record One : Set where
  13. Π : (S : Set)(T : S -> Set) -> Set
  14. Π S T = (x : S) -> T x
  15. data Σ (S : Set)(T : S -> Set) : Set where
  16. _,_ : (s : S) -> T s -> Σ S T
  17. split : {S : Set}{T : S -> Set}{P : Σ S T -> Set}
  18. (p : (s : S)(t : T s) -> P (s , t)) ->
  19. (x : Σ S T) -> P x
  20. split p (s , t) = p s t
  21. fst : {S : Set}{T : S -> Set}(x : Σ S T) -> S
  22. fst = split \s t -> s
  23. snd : {S : Set}{T : S -> Set}(x : Σ S T) -> T (fst x)
  24. snd = split \s t -> t
  25. mutual
  26. data ∗ : Set where
  27. /Π/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
  28. /Σ/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
  29. /Fin/ : Nat -> ∗
  30. /D/ : (I : ∗)(A : [ I ] -> ∗)(R : (i : [ I ]) -> [ A i ] -> List [ I ])
  31. -> [ I ] -> ∗
  32. [_] : ∗ -> Set
  33. [ /Π/ S T ] = Π [ S ] \s -> [ T s ]
  34. [ /Σ/ S T ] = Σ [ S ] \s -> [ T s ]
  35. [ /Fin/ n ] = Fin n
  36. [ /D/ I A R i ] = Σ [ A i ] \a -> [ Kids I (/D/ I A R) (R i a) ]
  37. Kids : (I : ∗)(P : [ I ] -> ∗) -> List [ I ] -> ∗
  38. Kids I P ε = /Fin/ (suc zero)
  39. Kids I P (i :: is) = /Σ/ (P i) \_ -> Kids I P is
  40. /0/ : ∗
  41. /0/ = /Fin/ zero
  42. /1/ : ∗
  43. /1/ = /Fin/ (suc zero)
  44. /2/ : ∗
  45. /2/ = /Fin/ (suc (suc zero))
  46. Branches : {n : Nat}(P : Fin n -> Set) -> Set
  47. Branches {zero} P = One
  48. Branches {suc n} P = Σ (P fz) \_ -> Branches {n} \x -> P (fs x)
  49. case : {n : Nat}{P : Fin n -> Set} -> Branches P -> (x : Fin n) -> P x
  50. case pps fz = fst pps
  51. case pps (fs x) = case (snd pps) x
  52. infixr 40 _⟶_
  53. infixr 60 _×_
  54. _⟶_ : ∗ -> ∗ -> ∗
  55. S ⟶ T = /Π/ S \_ -> T
  56. _×_ : ∗ -> ∗ -> ∗
  57. S × T = /Σ/ S \_ -> T
  58. NatR : [ /1/ ] -> [ /2/ ] -> List [ /1/ ]
  59. NatR _ fz = ε
  60. NatR _ (fs fz) = fz :: ε
  61. NatR _ (fs (fs ()))
  62. /Nat/ : ∗
  63. /Nat/ = /D/ /1/ (\_ -> /2/) NatR fz
  64. /zero/ : [ /Nat/ ]
  65. /zero/ = fz , fz
  66. /suc/ : [ /Nat/ ⟶ /Nat/ ]
  67. /suc/ n = fs fz , n , fz
  68. Hyps : (I : ∗)(K : [ I ] -> ∗)
  69. (P : (i : [ I ]) -> [ K i ] -> ∗)
  70. (is : List [ I ]) -> [ Kids I K is ] -> ∗
  71. Hyps I K P ε _ = /1/
  72. Hyps I K P (i :: is) (k , ks) = /Σ/ (P i k) \_ -> Hyps I K P is ks
  73. recs : (I : ∗)(K : [ I ] -> ∗)
  74. (P : (i : [ I ]) -> [ K i ] -> ∗)
  75. (e : (i : [ I ])(k : [ K i ]) -> [ P i k ])
  76. (is : List [ I ])(ks : [ Kids I K is ]) -> [ Hyps I K P is ks ]
  77. recs I K P e ε _ = fz
  78. recs I K P e (i :: is) (k , ks) = ( e i k , recs I K P e is ks )
  79. elim : (I : ∗)(A : [ I ] -> ∗)(R : (i : [ I ]) -> [ A i ] -> List [ I ])
  80. (P : (i : [ I ]) -> [ /D/ I A R i ] -> ∗) ->
  81. [( (/Π/ I \i -> /Π/ (A i) \a ->
  82. /Π/ (Kids I (/D/ I A R) (R i a)) \ks ->
  83. Hyps I (/D/ I A R) P (R i a) ks ⟶ P i (a , ks)) ⟶
  84. /Π/ I \i -> /Π/ (/D/ I A R i) \x -> P i x )]
  85. elim I A R P p i (a , ks) =
  86. p i a ks (recs I (/D/ I A R) P (elim I A R P p) (R i a) ks)
  87. natElim : (P : [ /Nat/ ] -> ∗) ->
  88. [( P /zero/ ⟶
  89. (/Π/ /Nat/ \n -> P n ⟶ P (/suc/ n)) ⟶
  90. /Π/ /Nat/ P )]
  91. natElim P pz ps = elim /1/ (\_ -> /2/) NatR (case (P , _))
  92. (case ( case (case ((\_ -> pz ) , _ )
  93. , (split \n -> case (split (\h _ -> ps n h) , _ )) , _ ) , _ ))
  94. fz
  95. plus : [ /Nat/ ⟶ /Nat/ ⟶ /Nat/ ]
  96. plus x y = natElim (\_ -> /Nat/) y (\_ -> /suc/) x
  97. {-
  98. elim /1/ (\_ -> /2/) NatR (\_ _ -> /Nat/)
  99. (\_ -> case
  100. ((\_ _ -> y )
  101. , split (\_ _ -> split (\n _ -> /suc/ n ) ) , _ ) )
  102. fz x
  103. -}
  104. mutual
  105. _⇔_ : ∗ -> ∗ -> ∗
  106. /Π/ S0 T0 ⇔ /Π/ S1 T1 =
  107. (S1 ⇔ S0) ×
  108. /Π/ S1 \s1 -> /Π/ S0 \s0 -> (S1 > s1 ≅ S0 > s0) ⟶ (T0 s0 ⇔ T1 s1)
  109. /Σ/ S0 T0 ⇔ /Σ/ S1 T1 =
  110. (S0 ⇔ S1) ×
  111. /Π/ S0 \s0 -> /Π/ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⟶ (T0 s0 ⇔ T1 s1)
  112. /Fin/ _ ⇔ /Π/ _ _ = /0/
  113. /Fin/ _ ⇔ /Σ/ _ _ = /0/
  114. /Fin/ _ ⇔ /D/ _ _ _ _ = /0/
  115. /Π/ _ _ ⇔ /Fin/ _ = /0/
  116. /Σ/ _ _ ⇔ /Fin/ _ = /0/
  117. /D/ _ _ _ _ ⇔ /Fin/ _ = /0/
  118. /Fin/ zero ⇔ /Fin/ zero = /1/
  119. /Fin/ (suc m) ⇔ /Fin/ (suc n) = /Fin/ m ⇔ /Fin/ n
  120. /D/ I0 A0 R0 i0 ⇔ /D/ I1 A1 R1 i1 =
  121. (I0 ⇔ I1) ×
  122. (/Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶ (A0 i0 ⇔ A1 i1)) ×
  123. (/Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶
  124. /Π/ (A0 i0) \a0 -> /Π/ (A1 i1) \a1 -> (A0 i0 > a0 ≅ A1 i1 > a1) ⟶
  125. Eqs I0 (R0 i0 a0) I1 (R1 i1 a1)) ×
  126. (I0 > i0 ≅ I1 > i1)
  127. _ ⇔ _ = /0/
  128. Eqs : (I0 : ∗) -> List [ I0 ] -> (I1 : ∗) -> List [ I1 ] -> ∗
  129. Eqs _ ε _ ε = /1/
  130. Eqs I0 (i0 :: is0) I1 (i1 :: is1) = (I0 > i0 ≅ I1 > i1) × Eqs I0 is0 I1 is1
  131. Eqs _ _ _ _ = /0/
  132. _>_≅_>_ : (S : ∗) -> [ S ] -> (T : ∗) -> [ T ] -> ∗
  133. /Π/ S0 T0 > f0 ≅ /Π/ S1 T1 > f1 =
  134. /Π/ S0 \s0 -> /Π/ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⟶
  135. (T0 s0 > f0 s0 ≅ T1 s1 > f1 s1)
  136. /Σ/ S0 T0 > p0 ≅ /Σ/ S1 T1 > p1 =
  137. let s0 : [ S0 ] ; s0 = fst p0
  138. s1 : [ S1 ] ; s1 = fst p1
  139. in (S0 > s0 ≅ S1 > s1) × (T0 s0 > snd p0 ≅ T1 s1 > snd p1)
  140. /Fin/ (suc n0) > fz ≅ /Fin/ (suc n1) > fz = /1/
  141. /Fin/ (suc n0) > fs x0 ≅ /Fin/ (suc n1) > fs x1 =
  142. /Fin/ n0 > x0 ≅ /Fin/ n1 > x1
  143. /D/ I0 A0 R0 i0 > (a0 , ks0) ≅ /D/ I1 A1 R1 i1 > (a1 , ks1) =
  144. (A0 i0 > a0 ≅ A1 i1 > a1) ×
  145. (Kids I0 (/D/ I0 A0 R0) (R0 i0 a0) > ks0 ≅
  146. Kids I1 (/D/ I1 A1 R1) (R1 i1 a1) > ks1)
  147. _ > _ ≅ _ > _ = /0/
  148. Resp : (S : ∗)(P : [ S ] -> ∗)
  149. {s0 s1 : [ S ]} -> [ (S > s0 ≅ S > s1) ⟶ (P s0 ⇔ P s1) ]
  150. Resp = {! !}
  151. [_>_] : (S : ∗)(s : [ S ]) -> [ S > s ≅ S > s ]
  152. [_>_] = {! !}
  153. KidsResp : (I0 : ∗)(I1 : ∗) -> [ I0 ⇔ I1 ] ->
  154. (P0 : [ I0 ] -> ∗)(P1 : [ I1 ] -> ∗) ->
  155. [( /Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶
  156. (P0 i0 ⇔ P1 i1) )] ->
  157. (is0 : List [ I0 ])(is1 : List [ I1 ]) ->
  158. [ Eqs I0 is0 I1 is1 ] ->
  159. [ Kids I0 P0 is0 ⇔ Kids I1 P1 is1 ]
  160. KidsResp = {! !}
  161. mutual
  162. _>_<_!_ : (S : ∗) -> [ S ] -> (T : ∗) -> [ S ⇔ T ] -> [ T ]
  163. /Π/ S0 T0 > f0 < /Π/ S1 T1 ! Q =
  164. let S1S0 : [ S1 ⇔ S0 ]
  165. S1S0 = fst Q
  166. T0T1 : [( /Π/ S1 \s1 -> /Π/ S0 \s0 -> (S1 > s1 ≅ S0 > s0) ⟶
  167. (T0 s0 ⇔ T1 s1) )]
  168. T0T1 = snd Q
  169. in \s1 ->
  170. let s0 : [ S0 ]
  171. s0 = S1 > s1 < S0 ! S1S0
  172. s1s0 : [( S1 > s1 ≅ S0 > s0 )]
  173. s1s0 = [| S1 > s1 < S0 ! S1S0 |]
  174. in T0 s0 > f0 s0 < T1 s1 ! T0T1 s1 s0 s1s0
  175. /Σ/ S0 T0 > p0 < /Σ/ S1 T1 ! Q =
  176. let S0S1 : [ S0 ⇔ S1 ]
  177. S0S1 = fst Q
  178. T0T1 : [( /Π/ S0 \s0 -> /Π/ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⟶
  179. (T0 s0 ⇔ T1 s1) )]
  180. T0T1 = snd Q
  181. s0 : [ S0 ]
  182. s0 = fst p0
  183. s1 : [ S1 ]
  184. s1 = S0 > s0 < S1 ! S0S1
  185. s0s1 : [ S0 > s0 ≅ S1 > s1 ]
  186. s0s1 = [| S0 > s0 < S1 ! S0S1 |]
  187. t0 : [ T0 s0 ]
  188. t0 = snd p0
  189. t1 : [ T1 s1 ]
  190. t1 = T0 s0 > t0 < T1 s1 ! T0T1 s0 s1 s0s1
  191. in s1 , t1
  192. /Fin/ (suc n0) > fz < /Fin/ (suc n1) ! Q = fz
  193. /Fin/ (suc n0) > fs x < /Fin/ (suc n1) ! Q = fs (/Fin/ n0 > x < /Fin/ n1 ! Q)
  194. /D/ I0 A0 R0 i0 > (a0 , ks0) < /D/ I1 A1 R1 i1 ! Q =
  195. let I01 : [ I0 ⇔ I1 ] ; I01 = fst Q
  196. A01 : [( /Π/ I0 \i0 -> /Π/ I1 \i1 ->
  197. (I0 > i0 ≅ I1 > i1) ⟶ (A0 i0 ⇔ A1 i1) )]
  198. A01 = fst (snd Q)
  199. R01 : [( /Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶
  200. /Π/ (A0 i0) \a0 -> /Π/ (A1 i1) \a1 ->
  201. (A0 i0 > a0 ≅ A1 i1 > a1) ⟶
  202. Eqs I0 (R0 i0 a0) I1 (R1 i1 a1) )]
  203. R01 = fst (snd (snd Q))
  204. i01 : [ I0 > i0 ≅ I1 > i1 ] ; i01 = snd (snd (snd Q))
  205. in (/Σ/ (A0 i0) \a0 -> Kids I0 (/D/ I0 A0 R0) (R0 i0 a0)) > (a0 , ks0) <
  206. (/Σ/ (A1 i1) \a1 -> Kids I1 (/D/ I1 A1 R1) (R1 i1 a1)) !
  207. A01 i0 i1 i01 ,
  208. \x0 x1 x01 ->
  209. KidsResp I0 I1 I01
  210. (/D/ I0 A0 R0) (/D/ I1 A1 R1) (\j0 j1 j01 -> I01 , A01 , R01 , j01 )
  211. (R0 i0 x0) (R1 i1 x1) (R01 i0 i1 i01 x0 x1 x01)
  212. /Π/ _ _ > _ < /Σ/ _ _ ! ()
  213. /Π/ _ _ > _ < /Fin/ _ ! ()
  214. /Π/ _ _ > _ < /D/ _ _ _ _ ! ()
  215. /Σ/ _ _ > _ < /Π/ _ _ ! ()
  216. /Σ/ _ _ > _ < /Fin/ _ ! ()
  217. /Σ/ _ _ > _ < /D/ _ _ _ _ ! ()
  218. /D/ _ _ _ _ > _ < /Π/ _ _ ! ()
  219. /D/ _ _ _ _ > _ < /Σ/ _ _ ! ()
  220. /D/ _ _ _ _ > _ < /Fin/ _ ! ()
  221. /Fin/ _ > _ < /Π/ _ _ ! ()
  222. /Fin/ _ > _ < /Σ/ _ _ ! ()
  223. /Fin/ zero > () < /Fin/ zero ! _
  224. /Fin/ zero > _ < /Fin/ (suc n) ! ()
  225. /Fin/ (suc n) > _ < /Fin/ zero ! ()
  226. /Fin/ _ > _ < /D/ _ _ _ _ ! ()
  227. [|_>_<_!_|] : (S : ∗)(s : [ S ])(T : ∗)(q : [ S ⇔ T ]) ->
  228. [ S > s ≅ T > (S > s < T ! q) ]
  229. [| S > s < T ! q |] = {! !}
  230. ext : (S : ∗)(T : [ S ] -> ∗)(f g : [ /Π/ S T ]) ->
  231. [( /Π/ S \x -> T x > f x ≅ T x > g x )] ->
  232. [ /Π/ S T > f ≅ /Π/ S T > g ]
  233. ext S T f g h s0 s1 s01 =
  234. (T s0 > f s0 ≅ T s0 > g s0) > h s0 < (T s0 > f s0 ≅ T s1 > g s1) !
  235. Resp S (\s1 -> T s0 > f s0 ≅ T s1 > g s1) s01
  236. plusZeroLemma : [ (/Nat/ ⟶ /Nat/) > (\x -> plus x /zero/) ≅
  237. (/Nat/ ⟶ /Nat/) > (\x -> plus /zero/ x) ]
  238. plusZeroLemma = ext /Nat/ (\_ -> /Nat/)
  239. (\x -> plus x /zero/) (\x -> plus /zero/ x) (natElim (\x ->
  240. /Nat/ > plus x /zero/ ≅ /Nat/ > plus /zero/ x) (fz , fz)
  241. (\n h -> [ (/Nat/ ⟶ /Nat/) > /suc/ ] (plus n /zero/) n h ))