Advertisement
Nolrai

Linear_Lean

Apr 4th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. import standard
  2. import data.bag
  3. import data.nat data.list.perm algebra.binary
  4. open nat quot list subtype binary function eq.ops
  5. open [decl] perm
  6.  
  7. namespace linear
  8. open nat fin
  9.  
  10. namespace Enums
  11.  
  12. inductive sign : Type :=
  13. | Pos
  14. | Neg
  15.  
  16. notation `#+` := sign.Pos
  17. notation `#-` := sign.Neg
  18.  
  19. inductive join : Type :=
  20. | Add
  21. | Mul
  22.  
  23. notation `%+` := join.Add
  24. notation `%*` := join.Mul
  25.  
  26. inductive conj : Type :=
  27. | Con
  28. | Dis
  29.  
  30. notation `@&` := conj.Con
  31. notation `@$` := conj.Dis
  32.  
  33. prefix `~` := has_neg.neg
  34.  
  35. definition sign_has_neg [instance]
  36. : has_neg sign :=
  37. begin
  38. constructor 1, intro x, induction x, right, left
  39. end
  40.  
  41. end Enums
  42. open Enums
  43.  
  44. record opclass :=
  45. mkJC :: (join : join) (conj : conj)
  46.  
  47. attribute opclass.join [coercion]
  48. attribute opclass.conj [coercion]
  49.  
  50. namespace opclass
  51. open Enums
  52.  
  53. protected definition f
  54. : Enums.conj -> Enums.sign
  55. | @& := #+
  56. | @$ := #-
  57.  
  58. definition sign [coercion]
  59. : opclass -> Enums.sign :=
  60. take a : opclass,
  61. match a with
  62. | (mkJC %* b) := opclass.f b
  63. | (mkJC %+ b) := ~ (opclass.f b)
  64. end
  65.  
  66. definition mkCS
  67. : Enums.conj -> Enums.sign -> opclass
  68. | @& #+ := mkJC %* @&
  69. | @& #- := mkJC %+ @&
  70. | @$ #+ := mkJC %+ @$
  71. | @$ #- := mkJC %* @$
  72.  
  73. definition mkJS
  74. : Enums.join -> Enums.sign -> opclass
  75. | %+ #+ := mkJC %+ @$
  76. | %+ #- := mkJC %+ @&
  77. | %* #+ := mkJC %* @&
  78. | %* #- := mkJC %* @$
  79.  
  80. lemma mkJC_id
  81. : forall x : linear.opclass
  82. , x = mkJC x x
  83. :=
  84. begin
  85. intro x
  86. , cases x
  87. , all_goals (apply rfl),
  88. end
  89.  
  90. lemma mkJS_id
  91. : forall x : linear.opclass
  92. , x = mkJS x x
  93. :=
  94. begin
  95. intro x
  96. , cases x with J S
  97. : cases J
  98. : cases S
  99. : esimp
  100. end
  101.  
  102. lemma mkCS_id
  103. : forall x : linear.opclass
  104. , x = mkCS x x
  105. :=
  106. begin
  107. intro x
  108. , cases x with J C
  109. : cases J
  110. : cases C
  111. : unfold mkCS
  112. end
  113.  
  114. end opclass
  115.  
  116. inductive MALL (A : Type) : Type :=
  117. | Var : bool -> A -> MALL A
  118. | Null : opclass ->
  119. MALL A
  120. | Bi : opclass ->
  121. MALL A -> MALL A -> MALL A
  122.  
  123. open MALL
  124.  
  125. abbreviation MALL.top {A : Type} :=
  126. Null A (opclass.mkJS %+ #-)
  127. abbreviation MALL.bottom [A : Type] :=
  128. Null A (opclass.mkJS %* #-)
  129. abbreviation MALL.one [A : Type] :=
  130. Null A (opclass.mkJS %* #+)
  131. abbreviation MALL.zero (A : Type) :=
  132. Null A (opclass.mkJS %+ #+)
  133.  
  134. definition MALL.has_zero [instance] {A : Type}
  135. : has_zero (MALL A) :=
  136. has_zero.mk (MALL.zero A)
  137.  
  138. definition MALL.has_one [instance] {A : Type}
  139. : has_one (MALL A) :=
  140. has_one.mk MALL.one
  141.  
  142. postfix `^^`:70 := Dual
  143.  
  144. open MALL
  145.  
  146. infix `*&`:50 :=
  147. Bi (opclass.mkJC %* @&)
  148. infix `*$`:50 :=
  149. Bi (opclass.mkJC %* @$)
  150. infix `+&`:50 :=
  151. Bi (opclass.mkJC %+ @&)
  152. infix `+$`:50 :=
  153. Bi (opclass.mkJC %+ @$)
  154.  
  155. definition two {A} : MALL A := one +$ one
  156.  
  157. structure seq A :=
  158. (hypo : bag (MALL A)) (concl : bag (MALL A))
  159.  
  160. infix `!-`:50 := seq.mk
  161.  
  162. local notation `[[` a ]]` := bag.of_list [a]
  163.  
  164. local notation bag' `-:` item := bag.insert item bag'
  165. local notation item `:-` bag := bag.insert item bag'
  166. local notation bag' `++` bag'' := bag.append bag' bag''
  167.  
  168. section P
  169.  
  170. parameter {A}
  171. variables D D' G G D1 D2 G1 G2 : bag (MALL A)
  172. variables B B1 B2 : MALL A
  173.  
  174. inductive P : seq A -> Type :=
  175. | init :
  176. P ([[B]] !- [[B]])
  177. | cut :
  178. P (D !- (B :- G)) ->
  179. P ((D' -: B) !- G') ->
  180. P ((D ++ D') !- (G ++ G'))
  181. | negL :
  182. P (D !- (B :- G)) ->
  183. P ((D -: B^^) !- G)
  184. | negR :
  185. P ((D -: B) !- G)) ->
  186. P (D !- (B^^ :- G))
  187. | oneL :
  188. P (D !- G) ->
  189. P ((D -: one) !- G)
  190. | oneR :
  191. P (bag.empty !- [[ one ]])
  192. | tensorL :
  193. P ((D ++ [[ B1 , B2 ]]) !- G) ->
  194. P ((D -: ( B1 *& B2 )) !- G)
  195. | tensorR :
  196. P (D1 !- (B1 :- G1)) ->
  197. P (D2 !- (B2 :- G2)) ->
  198. P ((D1 ++ D2) !- ((B1 *& B2) :- (G1 ++ G2)))
  199. | parL :
  200. P ((D1 -: B1) !- G1) ->
  201. P ((D2 -: B2) !- G2) ->
  202. P
  203.  
  204. end P
  205.  
  206. end linear
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement