ObsEq.agda 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. module ObsEq where
  2. data Zero : Set where
  3. record One : Set where
  4. data Two : Set where
  5. tt : Two
  6. ff : Two
  7. Π : (S : Set)(T : S -> Set) -> Set
  8. Π S T = (x : S) -> T x
  9. record Σ (S : Set)(T : S -> Set) : Set where
  10. field
  11. fst : S
  12. snd : T fst
  13. _,_ : {S : Set}{T : S -> Set}(s : S) -> T s -> Σ S T
  14. s , t = record {fst = s; snd = t}
  15. open module Σ' {S : Set}{T : S -> Set} = Σ {S} {T}
  16. data W (S : Set)(T : S -> Set) : Set where
  17. _<|_ : (s : S) -> (T s -> W S T) -> W S T
  18. mutual
  19. data ∗ : Set where
  20. /0/ : ∗
  21. /1/ : ∗
  22. /2/ : ∗
  23. /Π/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
  24. /Σ/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
  25. /W/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
  26. [_] : ∗ -> Set
  27. [ /0/ ] = Zero
  28. [ /1/ ] = One
  29. [ /2/ ] = Two
  30. [ /Π/ S T ] = Π [ S ] \s -> [ T s ]
  31. [ /Σ/ S T ] = Σ [ S ] \s -> [ T s ]
  32. [ /W/ S T ] = W [ S ] \s -> [ T s ]
  33. infixr 40 _⟶_
  34. _⟶_ : ∗ -> ∗ -> ∗
  35. S ⟶ T = /Π/ S \_ -> T
  36. {-
  37. _Ψ_ : Zero -> (S : ∗) -> [ S ]
  38. () Ψ S -- magic as there's no such thing
  39. -}
  40. _Ψ : Zero -> {S : Set} -> S
  41. () Ψ
  42. Case : Two -> ∗ -> ∗ -> ∗
  43. Case tt St Sf = St
  44. Case ff St Sf = Sf
  45. case : (P : Two -> ∗)(b : Two) -> [ P tt ] -> [ P ff ] -> [ P b ]
  46. case P tt ptt pff = ptt
  47. case P ff ptt pff = pff
  48. rec : {S : Set}{T : S -> Set}(P : W S T -> ∗)(x : W S T) ->
  49. ((s : S)(f : T s -> W S T) ->
  50. ((t : T s) -> [ P (f t) ]) -> [ P (s <| f) ]) ->
  51. [ P x ]
  52. rec P (s <| f) p = p s f \t -> rec P (f t) p
  53. /Nat/ : ∗
  54. /Nat/ = /W/ /2/ \b -> Case b /0/ /1/
  55. zero : [ /Nat/ ]
  56. zero = tt <| \z -> z Ψ
  57. suc : [ /Nat/ ⟶ /Nat/ ]
  58. suc n = ff <| \_ -> n
  59. {-
  60. elimNatSet : (P : [ /Nat/ ] -> Set) ->
  61. P zero ->
  62. ((k : [ /Nat/ ]) -> P k -> P (suc k)) ->
  63. (n : [ /Nat/ ]) -> P n
  64. elimNatSet P pz ps (tt <| g) = {! !}
  65. elimNatSet P pz ps (ff <| g) = {! !}
  66. -}
  67. infixr 60 _∧_
  68. data † : Set where
  69. ⊥ : †
  70. TT : †
  71. _∧_ : † -> † -> †
  72. ∏ : (S : ∗) -> ([ S ] -> †) -> †
  73. |- : † -> ∗
  74. |- ⊥ = /0/
  75. |- TT = /1/
  76. |- (P ∧ Q) = /Σ/ (|- P) \_ -> |- Q
  77. |- (∏ S P) = /Π/ S \s -> |- (P s)
  78. Prf : † -> Set
  79. Prf P = [ |- P ]
  80. infixr 40 _⇒_
  81. _⇒_ : † -> † -> †
  82. P ⇒ Q = ∏ (|- P) \_ -> Q
  83. infix 80 _⇔_
  84. mutual
  85. _⇔_ : ∗ -> ∗ -> †
  86. /0/ ⇔ /0/ = TT
  87. /1/ ⇔ /1/ = TT
  88. /2/ ⇔ /2/ = TT
  89. /Π/ S0 T0 ⇔ /Π/ S1 T1 =
  90. S1 ⇔ S0 ∧
  91. ∏ S1 \s1 -> ∏ S0 \s0 -> (S1 > s1 ≅ S0 > s0) ⇒ (T0 s0 ⇔ T1 s1)
  92. /Σ/ S0 T0 ⇔ /Σ/ S1 T1 =
  93. S0 ⇔ S1 ∧
  94. ∏ S0 \s0 -> ∏ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⇒ (T0 s0 ⇔ T1 s1)
  95. /W/ S0 T0 ⇔ /W/ S1 T1 =
  96. S0 ⇔ S1 ∧
  97. ∏ S0 \s0 -> ∏ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⇒ (T1 s1 ⇔ T0 s0)
  98. _ ⇔ _ = ⊥
  99. _>_≅_>_ : (S : ∗) -> [ S ] -> (T : ∗) -> [ T ] -> †
  100. /0/ > _ ≅ /0/ > _ = TT
  101. /1/ > _ ≅ /1/ > _ = TT
  102. /2/ > tt ≅ /2/ > tt = TT
  103. /2/ > ff ≅ /2/ > ff = TT
  104. /Π/ S0 T0 > f0 ≅ /Π/ S1 T1 > f1 =
  105. ∏ S0 \s0 -> ∏ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⇒
  106. (T0 s0 > f0 s0 ≅ T1 s1 > f1 s1)
  107. /Σ/ S0 T0 > p0 ≅ /Σ/ S1 T1 > p1 =
  108. (S0 > fst p0 ≅ S1 > fst p1) ∧
  109. (T0 (fst p0) > snd p0 ≅ T1 (fst p1) > snd p1)
  110. /W/ S0 T0 > (s0 <| f0) ≅ /W/ S1 T1 > (s1 <| f1) =
  111. (S0 > s0 ≅ S1 > s1) ∧
  112. ∏ (T0 s0) \t0 -> ∏ (T1 s1) \t1 ->
  113. (T0 s0 > t0 ≅ T1 s1 > t1) ⇒
  114. (/W/ S0 T0 > f0 t0 ≅ /W/ S1 T1 > f1 t1)
  115. _ > _ ≅ _ > _ = ⊥
  116. mutual
  117. _>_<_!_ : (S : ∗) -> [ S ] -> (T : ∗) -> Prf (S ⇔ T) -> [ T ]
  118. /0/ > z < /0/ ! _ = z
  119. /1/ > u < /1/ ! _ = u
  120. /2/ > b < /2/ ! _ = b
  121. /Π/ S0 T0 > f0 < /Π/ S1 T1 ! Q =
  122. let S1S0 : Prf (S1 ⇔ S0)
  123. S1S0 = fst Q
  124. T0T1 : Prf (∏ S1 \s1 -> ∏ S0 \s0 -> (S1 > s1 ≅ S0 > s0) ⇒
  125. (T0 s0 ⇔ T1 s1))
  126. T0T1 = snd Q
  127. in \s1 ->
  128. let s0 : [ S0 ]
  129. s0 = S1 > s1 < S0 ! S1S0
  130. s1s0 : Prf (S1 > s1 ≅ S0 > s0)
  131. s1s0 = [| S1 > s1 < S0 ! S1S0 |]
  132. in T0 s0 > f0 s0 < T1 s1 ! T0T1 s1 s0 s1s0
  133. /Σ/ S0 T0 > p0 < /Σ/ S1 T1 ! Q =
  134. let S0S1 : Prf (S0 ⇔ S1)
  135. S0S1 = fst Q
  136. T0T1 : Prf (∏ S0 \s0 -> ∏ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⇒
  137. (T0 s0 ⇔ T1 s1))
  138. T0T1 = snd Q
  139. s0 : [ S0 ]
  140. s0 = fst p0
  141. s1 : [ S1 ]
  142. s1 = S0 > s0 < S1 ! S0S1
  143. s0s1 : Prf (S0 > s0 ≅ S1 > s1)
  144. s0s1 = [| S0 > s0 < S1 ! S0S1 |]
  145. t0 : [ T0 s0 ]
  146. t0 = snd p0
  147. t1 : [ T1 s1 ]
  148. t1 = T0 s0 > t0 < T1 s1 ! T0T1 s0 s1 s0s1
  149. in s1 , t1
  150. /W/ S0 T0 > (s0 <| f0) < /W/ S1 T1 ! Q =
  151. let S0S1 : Prf (S0 ⇔ S1)
  152. S0S1 = fst Q
  153. T1T0 : Prf (∏ S0 \s0 -> ∏ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⇒
  154. (T1 s1 ⇔ T0 s0))
  155. T1T0 = snd Q
  156. s1 : [ S1 ]
  157. s1 = S0 > s0 < S1 ! S0S1
  158. s0s1 : Prf (S0 > s0 ≅ S1 > s1)
  159. s0s1 = [| S0 > s0 < S1 ! S0S1 |]
  160. in s1 <| \t1 ->
  161. let t0 : [ T0 s0 ]
  162. t0 = T1 s1 > t1 < T0 s0 ! T1T0 s0 s1 s0s1
  163. in /W/ S0 T0 > f0 t0 < /W/ S1 T1 ! Q
  164. /0/ > _ < /1/ ! ()
  165. /0/ > _ < /2/ ! ()
  166. /0/ > _ < /Π/ _ _ ! ()
  167. /0/ > _ < /Σ/ _ _ ! ()
  168. /0/ > _ < /W/ _ _ ! ()
  169. /1/ > _ < /0/ ! ()
  170. /1/ > _ < /2/ ! ()
  171. /1/ > _ < /Π/ _ _ ! ()
  172. /1/ > _ < /Σ/ _ _ ! ()
  173. /1/ > _ < /W/ _ _ ! ()
  174. /2/ > _ < /0/ ! ()
  175. /2/ > _ < /1/ ! ()
  176. /2/ > _ < /Π/ _ _ ! ()
  177. /2/ > _ < /Σ/ _ _ ! ()
  178. /2/ > _ < /W/ _ _ ! ()
  179. /Π/ _ _ > _ < /0/ ! ()
  180. /Π/ _ _ > _ < /1/ ! ()
  181. /Π/ _ _ > _ < /2/ ! ()
  182. /Π/ _ _ > _ < /Σ/ _ _ ! ()
  183. /Π/ _ _ > _ < /W/ _ _ ! ()
  184. /Σ/ _ _ > _ < /0/ ! ()
  185. /Σ/ _ _ > _ < /1/ ! ()
  186. /Σ/ _ _ > _ < /2/ ! ()
  187. /Σ/ _ _ > _ < /Π/ _ _ ! ()
  188. /Σ/ _ _ > _ < /W/ _ _ ! ()
  189. /W/ _ _ > _ < /0/ ! ()
  190. /W/ _ _ > _ < /1/ ! ()
  191. /W/ _ _ > _ < /2/ ! ()
  192. /W/ _ _ > _ < /Π/ _ _ ! ()
  193. /W/ _ _ > _ < /Σ/ _ _ ! ()
  194. [|_>_<_!_|] : (S : ∗)(s : [ S ])(T : ∗)(q : Prf (S ⇔ T)) ->
  195. Prf (S > s ≅ T > (S > s < T ! q))
  196. [| S > s < T ! q |] = {! !}
  197. Resp : (S : ∗)(P : [ S ] -> ∗)
  198. {s0 s1 : [ S ]} -> Prf ((S > s0 ≅ S > s1) ⇒ (P s0 ⇔ P s1))
  199. Resp = {! !}
  200. [|_>_|] : (S : ∗)(s : [ S ]) -> Prf (S > s ≅ S > s)
  201. [| S > s |] = {! !}
  202. Sym : (S0 S1 : ∗) -> Prf ((S0 ⇔ S1) ⇒ (S1 ⇔ S0))
  203. Sym = {! !}
  204. sym : (S0 : ∗)(s0 : [ S0 ])(S1 : ∗)(s1 : [ S1 ]) ->
  205. Prf ((S0 > s0 ≅ S1 > s1) ⇒ (S1 > s1 ≅ S0 > s0))
  206. sym = {! !}
  207. elimNat∗ : (P : [ /Nat/ ] -> ∗) ->
  208. [( P zero ⟶ (/Π/ /Nat/ \k -> P k ⟶ P (suc k)) ⟶
  209. /Π/ /Nat/ \n -> P n )]
  210. {-
  211. elimNat∗ P pz ps (tt <| g) = P zero > pz < P (tt <| g) !
  212. Resp /Nat/ P (_ , \z0 -> z0 Ψ)
  213. elimNat∗ P pz ps (ff <| g) =
  214. let n = g _
  215. in P (suc n) > ps n (elimNat∗ P pz ps n) < P (ff <| g) !
  216. Resp /Nat/ P
  217. (_ , \u0 u1 u0u1 -> [| (/1/ ⟶ /Nat/) > g |] _ u1 _)
  218. -}
  219. elimNat∗ P pz ps n = rec P n
  220. \b -> case (\ b -> /Π/ ((Case b /0/ /1/) ⟶ /Nat/) \g ->
  221. (/Π/ (Case b /0/ /1/) \t -> P (g t)) ⟶
  222. P (b <| g)) b
  223. (\g _ -> P zero > pz < P (tt <| g) ! Resp /Nat/ P (_ , \z0 -> z0 Ψ))
  224. (\g h ->
  225. let n = g _
  226. in P (suc n) > ps n (h _) < P (ff <| g) !
  227. Resp /Nat/ P
  228. (_ , \u0 u1 u0u1 -> [| (/1/ ⟶ /Nat/) > g |] _ u1 _))
  229. plus : [ /Nat/ ⟶ /Nat/ ⟶ /Nat/ ]
  230. plus x y = elimNat∗ (\_ -> /Nat/) y (\_ -> suc) x
  231. irr : (P0 P1 : †) -> Prf ((|- P0 ⇔ |- P1) ⇒
  232. ∏ (|- P0) \p0 -> ∏ (|- P1) \p1 -> |- P0 > p0 ≅ |- P1 > p1)
  233. irr ⊥ ⊥ _ _ _ = _
  234. irr TT TT _ _ _ = _
  235. irr (P0 ∧ Q0) (P1 ∧ Q1) PQ01 pq0 pq1 =
  236. let p01 : Prf (|- P0 > fst pq0 ≅ |- P1 > fst pq1)
  237. p01 = irr P0 P1 (fst PQ01) (fst pq0) (fst pq1)
  238. in p01 , irr Q0 Q1 (snd PQ01 (fst pq0) (fst pq1) p01) (snd pq0) (snd pq1)
  239. irr (∏ S0 P0) (∏ S1 P1) SP01 f0 f1 = \s0 s1 s0s1 ->
  240. irr (P0 s0) (P1 s1) (snd SP01 s1 s0 (sym S0 s0 S1 s1 s0s1)) (f0 s0) (f1 s1)
  241. irr ⊥ TT () _ _
  242. irr ⊥ (_ ∧ _) () _ _
  243. irr ⊥ (∏ _ _) () _ _
  244. irr TT ⊥ () _ _
  245. irr TT (_ ∧ _) () _ _
  246. irr TT (∏ _ _) () _ _
  247. irr (_ ∧ _) TT () _ _
  248. irr (_ ∧ _) ⊥ () _ _
  249. irr (_ ∧ _) (∏ _ _) () _ _
  250. irr (∏ _ _) TT () _ _
  251. irr (∏ _ _) ⊥ () _ _
  252. irr (∏ _ _) (_ ∧ _) () _ _
  253. {---------------------------------------------------------------------------
  254. The News from Nottingham (with subtitles)
  255. Conor McBride
  256. joint work with
  257. Thorsten Altenkirch, Wouter Swierstra, Peter Hancock,
  258. Nicolas Oury, James Chapman and Peter Morris
  259. ---------------------------------------------------------------------------}