Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Prelude.Algebra
  2. import Prelude.Basics
  3. import Prelude.Bool
  4. import Prelude.Cast
  5. import Prelude.Interfaces
  6. import Prelude.Uninhabited
  7.  
  8. --Task 1
  9. -- Refl {y = x} : x = x
  10. --a)
  11. total eqSym: x = y -> y = x
  12. eqSym Refl = Refl
  13. --b)
  14. total eqTran: x = y -> y = z -> x = z
  15. eqTran Refl Refl = Refl
  16. --c)
  17. total eqCong: {P: a -> b} -> x = y -> P x = P y
  18. eqCong Refl = Refl
  19.  
  20. --Task 2
  21.  
  22. --a)
  23. total plusZero: (x: Nat) -> x = x + Z
  24. plusZero Z = Refl
  25. plusZero (S x) = rewrite (plusZero x) in Refl
  26.  
  27. --b)
  28. total onePlus: (x: Nat) -> S x = x + 1
  29. onePlus Z = Refl
  30. onePlus (S k) = rewrite (onePlus k) in Refl
  31. --c)
  32. total plusOne: (x: Nat) -> S x = 1 + x
  33. plusOne n = Refl
  34.  
  35. --f!!!)
  36. total plusSucRightSuc : (x : Nat) -> (y : Nat) -> S (x + y) = x + (S y)
  37. plusSucRightSuc Z y = Refl
  38. plusSucRightSuc (S x) y = rewrite (plusSucRightSuc x y) in Refl
  39.  
  40. --d)
  41. total plusSucTwice: (x: Nat) -> (S x) + (S x) = S (S (x + x))
  42. plusSucTwice x = rewrite (plusSucRightSuc x x) in Refl
  43.  
  44.  
  45. --e)
  46. total plusLeftSuccRightSucc: (x: Nat) -> (y: Nat) -> (S x) + (S y) = S (S (x + y))
  47. plusLeftSuccRightSucc x y = rewrite (plusSucRightSuc x y) in Refl
  48.  
  49. --g)
  50. total plusCom: (x: Nat) -> (y: Nat) -> x + y = y + x
  51. plusCom Z y = plusZero y
  52. plusCom (S x) y =
  53.                 rewrite (plusCom x y) in
  54.                 rewrite (plusSucRightSuc y x) in Refl
  55.  
  56. --h)
  57. total plusAssoc: (x: Nat) -> (y: Nat) -> (z: Nat) -> x + (y + z) = (x + y) + z
  58. plusAssoc Z y z = Refl
  59. plusAssoc (S x) y z = rewrite (plusAssoc x y z) in Refl
  60.  
  61.  
  62.  
  63. --3
  64.  
  65. as : a -> a=a
  66. as x = Refl
  67.  
  68.  
  69. --a
  70.  
  71. total mulZero : (x:Nat) -> Z = x * Z
  72. mulZero Z = Refl
  73. mulZero (S x) = rewrite (mulZero x) in Refl
  74.  
  75. --b
  76.  
  77. total zeroMul : (x:Nat) -> Z = Z * x
  78. zeroMul x = Refl  
  79.  
  80. --c
  81.  
  82. total oneMul : (x:Nat) -> x = 1 * x
  83. oneMul Z = Refl
  84. oneMul (S x) = rewrite (plusZero x) in Refl
  85.  
  86.  
  87. --d
  88. total mulOne : (x:Nat) -> x = x * 1
  89. mulOne Z = Refl
  90. mulOne (S x) = rewrite (mulOne x) in Refl
  91.  
  92. --e
  93.  
  94. total mulRighSuc : (x: Nat) -> (y: Nat) -> x * (S y) = x + x * y
  95. mulRighSuc Z y = Refl
  96. mulRighSuc (S x) y =
  97.     rewrite mulRighSuc x y in
  98.     rewrite plusAssoc y x (x * y) in
  99.     rewrite plusCom y x in
  100.     rewrite eqSym (plusAssoc x y (x * y)) in
  101.             Refl
  102.  
  103.  
  104.  
  105. total mulCom : (x: Nat) -> (y: Nat) -> x * y = y * x
  106. mulCom Z y = mulZero y
  107. mulCom (S x) y =
  108.     rewrite mulCom x y in
  109.     rewrite eqSym (mulRighSuc y x) in
  110.         Refl
  111.  
  112.  
  113.  
  114. --f
  115. total mulPlusDis2 : (x: Nat) -> (y: Nat) -> (z: Nat) -> (x + y) * z = x * z + y * z
  116. mulPlusDis2 Z x y = Refl
  117. mulPlusDis2 (S x) y z =
  118.     rewrite mulPlusDis2 x y z in
  119.     rewrite plusAssoc z (x * z) (y * z) in
  120.     Refl
  121.  
  122. total mulAssoc : (x: Nat) -> (y: Nat) -> (z: Nat) -> x * (y * z) = (x * y) * z
  123. mulAssoc Z y z = Refl
  124. mulAssoc (S x) y z =
  125.     rewrite mulAssoc x y z in
  126.     rewrite eqSym (mulPlusDis2 y (x * y) z) in Refl
  127.  
  128. --g
  129.  
  130. total mulPlusDis : (x: Nat) -> (y: Nat) -> (z: Nat) -> x * (y + z) = x * y + x * z
  131. mulPlusDis Z y z = Refl
  132.  
  133. mulPlusDis (S x) y z =
  134.     rewrite (mulPlusDis x y z) in
  135.     rewrite plusAssoc (plus y (mult x y)) z (mult x z) in
  136.     rewrite eqSym (plusAssoc y (mult x y) z) in
  137.     rewrite plusCom (mult x y) z in
  138.     rewrite plusAssoc y z (mult x y) in
  139.     rewrite plusAssoc (plus y z) (mult x y) (mult x z) in
  140.             Refl
  141.  
  142.  
  143. qasd : LTE 0 4
  144. qasd = LTEZero
  145.  
  146. -- Task 4
  147. --a
  148. t1 : LTE 3 5
  149. t1  = (LTESucc (LTESucc  (LTESucc  LTEZero {right = 2} )))
  150.  
  151. --b
  152. total grLte : LTE x y -> LTE x (S y)
  153. grLte LTEZero = LTEZero
  154. grLte (LTESucc x) = LTESucc ( grLte x)
  155.  
  156. --c
  157. total grLten : (n : Nat) -> LTE x y -> LTE (x + n) (y + n)
  158. grLten {x = x1} {y = y1} Z x =
  159.     rewrite eqSym (plusZero x1) in
  160.     rewrite eqSym (plusZero y1) in x
  161. grLten {x = x1} {y = y1} (S k) a  =
  162.     rewrite eqSym(plusSucRightSuc x1 k) in
  163.     rewrite eqSym(plusSucRightSuc y1 k) in  LTESucc (grLten k a)
  164.  
  165. --Task 5
  166.  
  167. GRT : Nat -> Nat -> Type
  168. GRT left right = LTE (S right) left
  169.  
  170. total tr : (x : Nat) -> (y :Nat) -> Either (LTE x y) (GRT x y)
  171. tr Z y = Left LTEZero
  172. tr (S k) Z = Right (LTESucc LTEZero)
  173. tr (S a) (S b) = case tr a b of
  174.                     Left x => Left (LTESucc x)
  175.                     Right x => Right (LTESucc x)
  176.  
  177. --task 6
  178. total sub : Nat -> Nat -> Nat
  179. sub Z y = Z
  180. sub (S x) Z = S x
  181. sub (S x) (S y) = sub x y
  182. subS : (x:Nat) -> (y : Nat) -> sub (S x) (S y) = sub x y
  183. subS x y = Refl
  184.  
  185. subS2 : (x:Nat)  -> sub x Z = x
  186. subS2 Z = Refl
  187. subS2 (S k) = Refl
  188.  
  189. subS3 : (x : Nat) -> (y : Nat) -> sub x y = sub (S x) (S y)
  190. subS3 x y  = Refl
  191.  
  192.  
  193. --a
  194.  
  195. total subP1 : LTE x y -> sub x y = Z
  196. subP1 LTEZero = Refl
  197. subP1 (LTESucc x) = rewrite (subP1 x) in Refl  
  198.  
  199. --b
  200. subP2 : sub x y = Z -> LTE x y
  201. subP2 {x = Z} {y = y1} a = LTEZero
  202. {-
  203. subP2 {x = (S x1)} {y = (S y1)} a = LTESucc ( ?r)    
  204.  
  205.  
  206. --c
  207. subP3 : LTE y x -> y + (sub x y) = x
  208. subP3 {x = x1} LTEZero = rewrite  (subS2 x1) in Refl
  209. --subP3 {x = x1} {y = y1} (LTESucc a) =
  210. -}
  211. main: IO()
  212. main = putStr "Hello"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement