Advertisement
Guest User

asd

a guest
Jul 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. Require Import Coq.omega.Omega.
  2.  
  3. (** an integer as a pair of nats *)
  4. Inductive integer : Type :=
  5. | pair : nat -> nat -> integer.
  6.  
  7. Notation "( x , y )" := (pair x y).
  8.  
  9. (** first component of the pair *)
  10. Definition fst (x: integer): nat :=
  11. match x with
  12. | (m, n) => m
  13. end.
  14.  
  15. (** second component of the pair *)
  16. Definition snd (x: integer): nat :=
  17. match x with
  18. | (m, n) => n
  19. end.
  20.  
  21. (** equality as an axiom *)
  22. Axiom Z_eq: forall (x y: integer), fst x + snd y = snd x + fst y <-> x = y.
  23.  
  24. (** addition *)
  25. Definition Z_plus (x: integer) (y: integer): integer :=
  26. match x with
  27. | (a1, a2) =>
  28. match y with
  29. | (b1, b2) => (a1 + b1, a2 + b2)
  30. end
  31. end.
  32.  
  33. Notation "z '+Z' w" := (Z_plus z w) (at level 50, left associativity) : type_scope.
  34.  
  35. (** subtraction *)
  36. Definition Z_minus (x: integer) (y: integer): integer :=
  37. match x with
  38. | (a1, a2) =>
  39. match y with
  40. | (b1, b2) => (a1 + b2, a2 + b1)
  41. end
  42. end.
  43.  
  44. Notation "z '-Z' w" := (Z_minus z w) (at level 50, left associativity) : type_scope.
  45.  
  46. (** negation of an integer: z |-> -z *)
  47. Definition Z_neg (x: integer): integer :=
  48. match x with
  49. | (a1, a2) => (a2, a1)
  50. end.
  51.  
  52. Notation "'-Z' w" := (Z_neg w) (at level 35, right associativity) : type_scope.
  53.  
  54. (** multiplication *)
  55. Definition Z_mult (x: integer) (y: integer): integer :=
  56. match x with
  57. | (a1, a2) =>
  58. match y with
  59. | (b1, b2) => (a1 * b1 + a2 * b2, a1 * b2 + a2 * b1)
  60. end
  61. end.
  62.  
  63. Notation "z '*Z' w" := (Z_mult z w) (at level 40, left associativity) : type_scope.
  64.  
  65. (** zero and one *)
  66. Definition Z0: integer := (0, 0).
  67. Definition Z1: integer := (1, 0).
  68.  
  69. (** plus_assoc *)
  70. Theorem Z_1: forall x y z: integer, (x +Z y) +Z z = x +Z (y +Z z).
  71. Proof. destruct x, y, z. simpl. rewrite <- Z_eq. simpl. omega. Qed.
  72.  
  73. (** plus_comm *)
  74. Theorem Z_2: forall x y: integer, x +Z y = y +Z x.
  75. Proof. destruct x, y. simpl. rewrite <- Z_eq. simpl. omega. Qed.
  76.  
  77. (** zero as an identity for plus *)
  78. Theorem Z_3: forall x: integer, x +Z Z0 = x.
  79. Proof. destruct x. simpl. rewrite <- Z_eq. simpl. omega. Qed.
  80.  
  81. (** inverse element for plus *)
  82. Theorem Z_4: forall x: integer, x +Z -Z x = Z0.
  83. Proof. destruct x. simpl. rewrite <- Z_eq. simpl. omega. Qed.
  84.  
  85. (** mult_assoc *)
  86. Theorem Z_5: forall x y z: integer, (x *Z y) *Z z = x *Z (y *Z z).
  87. Proof. Admitted.
  88.  
  89. (** mult_comm *)
  90. Theorem Z_6: forall x y: integer, x *Z y = y *Z x.
  91. Proof. Admitted.
  92.  
  93. (** one as an identity for mult *)
  94. Theorem Z_7: forall x: integer, x *Z Z1 = x.
  95. Proof. Admitted.
  96.  
  97. (** left distribution law *)
  98. Theorem Z_8: forall x y z: integer, x *Z (y +Z z) = x *Z y +Z x *Z z.
  99. Proof. Admitted.
  100.  
  101. (** Z is an integral domain *)
  102. Theorem Z_9: forall x y: integer, x *Z y = Z0 -> x = Z0 \/ y = Z0.
  103. Proof. Admitted.
  104.  
  105. (** natural order for Z *)
  106. Definition Z_leb (x y: integer) := (** x <= y iff *)
  107. match x with
  108. | (a1, a2) =>
  109. match y with
  110. | (b1, b2) => (a1 + b2 <= b1 + a2)
  111. end
  112. end.
  113.  
  114. Notation "z '<=Z' w" := (Z_leb z w) (at level 70, no associativity) : type_scope.
  115. Notation "z '<Z' w" := (~ Z_leb w z) (at level 70, no associativity) : type_scope.
  116. Notation "z '>=Z' w" := (Z_leb w z) (at level 70, no associativity) : type_scope.
  117. Notation "z '>Z' w" := (~ Z_leb z w) (at level 70, no associativity) : type_scope.
  118.  
  119. (** trichotomy *)
  120. Theorem Z_10: forall x y: integer,
  121. ( x <Z y /\ ~ x = y /\ ~ x >Z y) \/
  122. (~ x <Z y /\ x = y /\ ~ x >Z y) \/
  123. (~ x <Z y /\ ~ x = y /\ x >Z y).
  124. Proof. Admitted.
  125.  
  126. (** transitivity *)
  127. Theorem Z_11: forall x y z: integer, x <Z y /\ y <Z z -> x <Z z.
  128. Proof. Admitted.
  129.  
  130. (** addition preserves the order *)
  131. Theorem Z_12: forall x y z: integer, x <Z y -> x +Z z <Z y +Z z.
  132. Proof. Admitted.
  133.  
  134. (** mult by positive number preserves the order *)
  135. Theorem Z_13: forall x y z: integer, x <Z y /\ z >Z Z0 -> x *Z z <Z y *Z z.
  136. Proof. Admitted.
  137.  
  138. (** Z is not a trivial ring *)
  139. Theorem Z_14: Z0 <> Z1.
  140. Proof. unfold not. rewrite <- Z_eq. simpl. intros. inversion H. Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement