(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(****************************************************************************)
(*                 The Calculus of Inductive Constructions                  *)
(*                                                                          *)
(*                                Projet Coq                                *)
(*                                                                          *)
(*                     INRIA                        ENS-CNRS                *)
(*              Rocquencourt                        Lyon                    *)
(*                                                                          *)
(*                                Coq V5.10                                 *)
(*                              Nov 25th 1994                               *)
(*                                                                          *)
(****************************************************************************)
(*                                 Zmult.v                                  *)
(****************************************************************************)
Require Export Lci.
Require Export misc.
Require Export Arith.
Require Export Nat_complements.
Require Export groups.
Require Export rings.
Require Export Zbase.
Require Export Z_succ_pred.
Require Export Zadd.
(* Multiplication on Z, (Z, +, *, 0, 1) is a unitary commutative ring *)
(*Recursive Definition multZ : Z -> Z -> Z := OZ      y  => OZ | (pos O)      y  => y | (pos (S n1)) y  => (addZ (multZ (pos n1) y) y) | (neg O)      y  => (oppZ y) | (neg (S n1)) y  => (addZ (multZ (neg n1) y) (oppZ y)). *)
Fixpoint multpos (x2 : Z) (n : nat) {struct n} : Z :=
match n with
| O => x2
| S n0 => addZ (multpos x2 n0) x2
end.
Fixpoint multneg (x2 : Z) (n : nat) {struct n} : Z :=
match n with
| O => oppZ x2
| S n0 => addZ (multneg x2 n0) (oppZ x2)
end.
Definition multZ (x1 x2 : Z) :=
match x1 with
| OZ => OZ
| pos n => multpos x2 n
| neg n => multneg x2 n
end.
Proof multZ_eq3.
Proof multZ_eq5.
intros; elim x.
(* OZ *)
simpl in |- *; reflexivity.
(* pos n *)
intros; simpl in |- *; reflexivity.
(* neg n *)
intros; elim n.
(* neg O *)
simpl in |- *; symmetry  in |- *.
elim (addZ_opposite y I); intros. elim H0; intros; elim H2; intros; exact H4.
(* neg (S n0) *)
intros; unfold succZ in |- *; rewrite (tech_mult_negZ n0 y).
elim (addZ_associativity (multZ (neg n0) y) (oppZ y) y).
elim (addZ_opposite y I); intros. elim H1; intros; elim H3; intros. rewrite H5.
symmetry  in |- *; exact (add_OZ (multZ (neg n0) y)).
Qed.
intros; elim x.
(* OZ *)
reflexivity.
(* pos n *)
simple induction n.
(* pos O *)
symmetry  in |- *; exact (add_IZ_succZ y).
(* pos (S y0) *)
intros y0 H; do 2 rewrite (tech_mult_posZ y0).
rewrite H; elim (addZ_commutativity (pos y0) (multZ (pos y0) y)).
elim (addZ_associativity (pos y0) (multZ (pos y0) y) (succZ y)).
elim (addZ_commutativity (addZ (multZ (pos y0) y) (succZ y)) (pos y0)).
rewrite (succ_addZ_r (multZ (pos y0) y) y).
rewrite (succ_addZ_l (addZ (multZ (pos y0) y) y) (pos y0)).
elim (succ_addZ_r (addZ (multZ (pos y0) y) y) (pos y0)).
reflexivity.
(* neg n *)
simple induction n.
(* neg O *)
simpl in |- *; rewrite (add_mIZ_predZ (oppZ y)); exact (opp_succZ y).
(* neg (S y0) *)
intros y0 H; do 2 rewrite (tech_mult_negZ y0).
elim H; elim (addZ_commutativity (oppZ y) (multZ (neg y0) y)).
elim (addZ_associativity (oppZ y) (multZ (neg y0) y) (neg (S y0))).
elim (addZ_commutativity (addZ (multZ (neg y0) y) (neg (S y0))) (oppZ y)).
rewrite (opp_succZ y).
rewrite (pred_addZ_r (multZ (neg y0) (succZ y)) (oppZ y)).
rewrite H; elim (pred_addZ_l (addZ (multZ (neg y0) y) (neg y0)) (oppZ y)).
elim (pred_addZ_r (multZ (neg y0) y) (neg y0)); unfold predZ in |- *;
reflexivity.
Qed.

(*****************)
Lemma mult_predZ_r :
forall x y : Z, multZ x (predZ y) = addZ (multZ x y) (oppZ x).