(* *)
(**************************************************************************)
-set "baseuri" "cic:/matita/Z/".
+set "baseuri" "cic:/matita/Z/z".
-include "nat/nat.ma".
-include "datatypes/bool.ma".
+include "nat/compare.ma".
+include "nat/minus.ma".
+include "higher_order_defs/functions.ma".
inductive Z : Set \def
OZ : Z
[ O \Rightarrow OZ
| (S n)\Rightarrow neg n].
-definition absZ \def
+definition abs \def
\lambda z.
match z with
[ OZ \Rightarrow O
| (pos n) \Rightarrow n
| (neg n) \Rightarrow n].
-definition OZ_testb \def
+definition OZ_test \def
\lambda z.
match z with
[ OZ \Rightarrow true
| (pos n) \Rightarrow false
| (neg n) \Rightarrow false].
-theorem OZ_discr :
-\forall z. if_then_else (OZ_testb z) (eq Z z OZ) (Not (eq Z z OZ)).
-intros.elim z.simplify.reflexivity.
+theorem OZ_test_to_Prop :\forall z:Z.
+match OZ_test z with
+[true \Rightarrow z=OZ
+|false \Rightarrow \lnot (z=OZ)].
+intros.elim z.
+simplify.reflexivity.
simplify.intros.
-cut match neg e1 with
+cut match neg n with
[ OZ \Rightarrow True
| (pos n) \Rightarrow False
| (neg n) \Rightarrow False].
apply Hcut.rewrite > H.simplify.exact I.
simplify.intros.
-cut match pos e2 with
+cut match pos n with
[ OZ \Rightarrow True
| (pos n) \Rightarrow False
| (neg n) \Rightarrow False].
| (S p) \Rightarrow pos p]
| (neg n) \Rightarrow neg (S n)].
-theorem Zpred_succ: \forall z:Z. eq Z (Zpred (Zsucc z)) z.
+theorem Zpred_Zsucc: \forall z:Z. Zpred (Zsucc z) = z.
intros.elim z.reflexivity.
-elim e1.reflexivity.
+elim n.reflexivity.
reflexivity.
reflexivity.
qed.
-theorem Zsucc_pred: \forall z:Z. eq Z (Zsucc (Zpred z)) z.
+theorem Zsucc_Zpred: \forall z:Z. Zsucc (Zpred z) = z.
intros.elim z.reflexivity.
reflexivity.
-elim e2.reflexivity.
+elim n.reflexivity.
reflexivity.
qed.
-let rec Zplus x y : Z \def
+definition Zplus :Z \to Z \to Z \def
+\lambda x,y.
match x with
[ OZ \Rightarrow y
| (pos m) \Rightarrow
| EQ \Rightarrow OZ
| GT \Rightarrow (neg (pred (minus m n)))]
| (neg n) \Rightarrow (neg (S (plus m n)))]].
+
+(*CSC: the URI must disappear: there is a bug now *)
+interpretation "integer plus" 'plus x y = (cic:/matita/Z/z/Zplus.con x y).
-theorem Zplus_z_O: \forall z:Z. eq Z (Zplus z OZ) z.
+theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
intro.elim z.
simplify.reflexivity.
simplify.reflexivity.
simplify.reflexivity.
qed.
-theorem sym_Zplus : \forall x,y:Z. eq Z (Zplus x y) (Zplus y x).
-intros.elim x.simplify.rewrite > Zplus_z_O.reflexivity.
+(* theorem symmetric_Zplus: symmetric Z Zplus. *)
+
+theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
+intros.elim x.rewrite > Zplus_z_OZ.reflexivity.
elim y.simplify.reflexivity.
simplify.
rewrite < sym_plus.reflexivity.
simplify.
-rewrite > nat_compare_invert.
+rewrite > nat_compare_n_m_m_n.
simplify.elim nat_compare ? ?.simplify.reflexivity.
simplify. reflexivity.
simplify. reflexivity.
elim y.simplify.reflexivity.
-simplify.rewrite > nat_compare_invert.
+simplify.rewrite > nat_compare_n_m_m_n.
simplify.elim nat_compare ? ?.simplify.reflexivity.
simplify. reflexivity.
simplify. reflexivity.
-simplify.elim (sym_plus ? ?).reflexivity.
+simplify.rewrite < sym_plus.reflexivity.
qed.
-theorem Zpred_neg : \forall z:Z. eq Z (Zpred z) (Zplus (neg O) z).
+theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
intros.elim z.
simplify.reflexivity.
simplify.reflexivity.
-elim e2.simplify.reflexivity.
+elim n.simplify.reflexivity.
simplify.reflexivity.
qed.
-theorem Zsucc_pos : \forall z:Z. eq Z (Zsucc z) (Zplus (pos O) z).
+theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
intros.elim z.
simplify.reflexivity.
-elim e1.simplify.reflexivity.
+elim n.simplify.reflexivity.
simplify.reflexivity.
simplify.reflexivity.
qed.
-theorem Zplus_succ_pred_pp :
-\forall n,m. eq Z (Zplus (pos n) (pos m)) (Zplus (Zsucc (pos n)) (Zpred (pos m))).
+theorem Zplus_pos_pos:
+\forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
intros.
elim n.elim m.
simplify.reflexivity.
rewrite < plus_n_Sm.reflexivity.
qed.
-theorem Zplus_succ_pred_pn :
-\forall n,m. eq Z (Zplus (pos n) (neg m)) (Zplus (Zsucc (pos n)) (Zpred (neg m))).
+theorem Zplus_pos_neg:
+\forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
intros.reflexivity.
qed.
-theorem Zplus_succ_pred_np :
-\forall n,m. eq Z (Zplus (neg n) (pos m)) (Zplus (Zsucc (neg n)) (Zpred (pos m))).
+theorem Zplus_neg_pos :
+\forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
intros.
elim n.elim m.
simplify.reflexivity.
simplify.reflexivity.
qed.
-theorem Zplus_succ_pred_nn:
-\forall n,m. eq Z (Zplus (neg n) (neg m)) (Zplus (Zsucc (neg n)) (Zpred (neg m))).
+theorem Zplus_neg_neg:
+\forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
intros.
elim n.elim m.
simplify.reflexivity.
simplify.rewrite > plus_n_Sm.reflexivity.
qed.
-theorem Zplus_succ_pred:
-\forall x,y. eq Z (Zplus x y) (Zplus (Zsucc x) (Zpred y)).
+theorem Zplus_Zsucc_Zpred:
+\forall x,y. x+y = (Zsucc x)+(Zpred y).
intros.
elim x. elim y.
simplify.reflexivity.
simplify.reflexivity.
-rewrite < Zsucc_pos.rewrite > Zsucc_pred.reflexivity.
+rewrite < Zsucc_Zplus_pos_O.
+rewrite > Zsucc_Zpred.reflexivity.
elim y.rewrite < sym_Zplus.rewrite < sym_Zplus (Zpred OZ).
-rewrite < Zpred_neg.rewrite > Zpred_succ.
+rewrite < Zpred_Zplus_neg_O.
+rewrite > Zpred_Zsucc.
simplify.reflexivity.
-rewrite < Zplus_succ_pred_nn.reflexivity.
-apply Zplus_succ_pred_np.
+rewrite < Zplus_neg_neg.reflexivity.
+apply Zplus_neg_pos.
elim y.simplify.reflexivity.
-apply Zplus_succ_pred_pn.
-apply Zplus_succ_pred_pp.
+apply Zplus_pos_neg.
+apply Zplus_pos_pos.
qed.
-theorem Zsucc_plus_pp :
-\forall n,m. eq Z (Zplus (Zsucc (pos n)) (pos m)) (Zsucc (Zplus (pos n) (pos m))).
+theorem Zplus_Zsucc_pos_pos :
+\forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
intros.reflexivity.
qed.
-theorem Zsucc_plus_pn :
-\forall n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m))).
+theorem Zplus_Zsucc_pos_neg:
+\forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
intros.
-apply nat_double_ind
-(\lambda n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m)))).intro.
+apply nat_elim2
+(\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m)))).intro.
intros.elim n1.
simplify. reflexivity.
-elim e1.simplify. reflexivity.
+elim n2.simplify. reflexivity.
simplify. reflexivity.
intros. elim n1.
simplify. reflexivity.
simplify.reflexivity.
intros.
-rewrite < (Zplus_succ_pred_pn ? m1).
+rewrite < (Zplus_pos_neg ? m1).
elim H.reflexivity.
qed.
-theorem Zsucc_plus_nn :
-\forall n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m))).
+theorem Zplus_Zsucc_neg_neg :
+\forall n,m. (Zsucc (neg n))+(neg m) = Zsucc ((neg n)+(neg m)).
intros.
-apply nat_double_ind
-(\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m)))).intro.
+apply nat_elim2
+(\lambda n,m. ((Zsucc (neg n))+(neg m)) = Zsucc ((neg n)+(neg m))).intro.
intros.elim n1.
simplify. reflexivity.
-elim e1.simplify. reflexivity.
+elim n2.simplify. reflexivity.
simplify. reflexivity.
intros. elim n1.
simplify. reflexivity.
simplify.reflexivity.
intros.
-rewrite < (Zplus_succ_pred_nn ? m1).
+rewrite < (Zplus_neg_neg ? m1).
reflexivity.
qed.
-theorem Zsucc_plus_np :
-\forall n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m))).
+theorem Zplus_Zsucc_neg_pos:
+\forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
intros.
-apply nat_double_ind
-(\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m)))).
+apply nat_elim2
+(\lambda n,m. (Zsucc (neg n))+(pos m) = Zsucc ((neg n)+(pos m))).
intros.elim n1.
simplify. reflexivity.
-elim e1.simplify. reflexivity.
+elim n2.simplify. reflexivity.
simplify. reflexivity.
intros. elim n1.
simplify. reflexivity.
simplify.reflexivity.
intros.
rewrite < H.
-rewrite < (Zplus_succ_pred_np ? (S m1)).
+rewrite < (Zplus_neg_pos ? (S m1)).
reflexivity.
qed.
-
-theorem Zsucc_plus : \forall x,y:Z. eq Z (Zplus (Zsucc x) y) (Zsucc (Zplus x y)).
+theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
intros.elim x.elim y.
simplify. reflexivity.
-rewrite < Zsucc_pos.reflexivity.
+rewrite < Zsucc_Zplus_pos_O.reflexivity.
simplify.reflexivity.
elim y.rewrite < sym_Zplus.rewrite < sym_Zplus OZ.simplify.reflexivity.
-apply Zsucc_plus_nn.
-apply Zsucc_plus_np.
+apply Zplus_Zsucc_neg_neg.
+apply Zplus_Zsucc_neg_pos.
elim y.
rewrite < sym_Zplus OZ.reflexivity.
-apply Zsucc_plus_pn.
-apply Zsucc_plus_pp.
+apply Zplus_Zsucc_pos_neg.
+apply Zplus_Zsucc_pos_pos.
qed.
-theorem Zpred_plus : \forall x,y:Z. eq Z (Zplus (Zpred x) y) (Zpred (Zplus x y)).
+theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
intros.
-cut eq Z (Zpred (Zplus x y)) (Zpred (Zplus (Zsucc (Zpred x)) y)).
+cut Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y).
rewrite > Hcut.
-rewrite > Zsucc_plus.
-rewrite > Zpred_succ.
+rewrite > Zplus_Zsucc.
+rewrite > Zpred_Zsucc.
reflexivity.
-rewrite > Zsucc_pred.
+rewrite > Zsucc_Zpred.
reflexivity.
qed.
-theorem assoc_Zplus :
-\forall x,y,z:Z. eq Z (Zplus x (Zplus y z)) (Zplus (Zplus x y) z).
+
+theorem associative_Zplus: associative Z Zplus.
+change with \forall x,y,z:Z. (x + y) + z = x + (y + z).
+(* simplify. *)
intros.elim x.simplify.reflexivity.
-elim e1.rewrite < (Zpred_neg (Zplus y z)).
-rewrite < (Zpred_neg y).
-rewrite < Zpred_plus.
+elim n.rewrite < (Zpred_Zplus_neg_O (y+z)).
+rewrite < (Zpred_Zplus_neg_O y).
+rewrite < Zplus_Zpred.
reflexivity.
-rewrite > Zpred_plus (neg e).
-rewrite > Zpred_plus (neg e).
-rewrite > Zpred_plus (Zplus (neg e) y).
-apply f_equal.assumption.
-elim e2.rewrite < Zsucc_pos.
-rewrite < Zsucc_pos.
-rewrite > Zsucc_plus.
+rewrite > Zplus_Zpred (neg n1).
+rewrite > Zplus_Zpred (neg n1).
+rewrite > Zplus_Zpred ((neg n1)+y).
+apply eq_f.assumption.
+elim n.rewrite < Zsucc_Zplus_pos_O.
+rewrite < Zsucc_Zplus_pos_O.
+rewrite > Zplus_Zsucc.
reflexivity.
-rewrite > Zsucc_plus (pos e1).
-rewrite > Zsucc_plus (pos e1).
-rewrite > Zsucc_plus (Zplus (pos e1) y).
-apply f_equal.assumption.
+rewrite > Zplus_Zsucc (pos n1).
+rewrite > Zplus_Zsucc (pos n1).
+rewrite > Zplus_Zsucc ((pos n1)+y).
+apply eq_f.assumption.
+qed.
+
+variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
+\def associative_Zplus.
+
+(* Zopp *)
+definition Zopp : Z \to Z \def
+\lambda x:Z. match x with
+[ OZ \Rightarrow OZ
+| (pos n) \Rightarrow (neg n)
+| (neg n) \Rightarrow (pos n) ].
+
+(*CSC: the URI must disappear: there is a bug now *)
+interpretation "integer unary minus" 'uminus x = (cic:/matita/Z/z/Zopp.con x).
+
+theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
+intro.elim x.
+apply refl_eq.
+simplify.
+rewrite > nat_compare_n_n.
+simplify.apply refl_eq.
+simplify.
+rewrite > nat_compare_n_n.
+simplify.apply refl_eq.
qed.
+