Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. \data UoM
  2. | unit
  3. | m | kg | s | A | K | mol | cd
  4. | mul UoM UoM
  5. | inv UoM
  6. | comm (x y : UoM) (i : I) \elim i {
  7. | left => mul x y
  8. | right => mul y x
  9. }
  10. | inv-inv (x : UoM) (i : I) \elim i {
  11. | left => inv (inv x)
  12. | right => x
  13. }
  14. | inv-mul (x : UoM) (i : I) \elim i {
  15. | left => mul x (inv x)
  16. | right => unit
  17. }
  18. | unit-left (x : UoM) (i : I) \elim i {
  19. | left => mul unit x
  20. | right => x
  21. }
  22. | assoc (x y z : UoM) (i : I) \elim i {
  23. | left => mul x (mul y z)
  24. | right => mul (mul x y) z
  25. }
  26. \where {
  27. \func div (x y : UoM) : UoM => mul x (inv y)
  28. \func sqr (x : UoM) : UoM => mul x x
  29. }
  30.  
  31. \record MyNat (unit : UoM) (val : Nat)
  32. \where {
  33. \func mk {u : UoM} (x : Nat) : MyNat u => \new MyNat u x
  34.  
  35. \func \infixl 6 + {u : UoM} (x y : MyNat u) : MyNat u
  36. => mk (Nat.+ x.val y.val)
  37.  
  38. \func \infixl 7 * {u v : UoM} (x : MyNat u) (y : MyNat v) : MyNat (UoM.mul u v)
  39. => mk (Nat.* x.val y.val)
  40.  
  41. \func \infixl 7 / {u v : UoM} (x : MyNat u) (y : MyNat v) : MyNat (UoM.div u v)
  42. => mk (Nat.div x.val y.val)
  43. }
  44.  
  45. -- examples
  46. \open MyNat
  47.  
  48. \func test1 : MyNat UoM.m => mk 5
  49. \func test2 : MyNat UoM.s => mk 2
  50.  
  51. \func test3 : MyNat (UoM.div UoM.m UoM.s) => test1 / test2
  52. -- \func test4 : MyNat {?} => test1 + test2 -- ???
  53.  
  54. \func N => UoM.mul UoM.kg (UoM.div UoM.m (UoM.sqr UoM.s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement