(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(** modulo Modulo Arithmetic.  @author Olga Caprotti and Martijn Oostdijk @version $Revision$ *)
(** (Mod a b n) means (a = b (mod n)) *)
Definition Mod (a b : Z) (n : nat) :=
exists q : Z, a = (b + Z_of_nat n * q)%Z.

(* Specifications: *)
Lemma modpq_modp : forall (a b : Z) (p q : nat), Mod a b (p * q) -> Mod a b p.
Lemma mod_refl : forall (a : Z) (n : nat), Mod a a n.
Lemma mod_sym : forall (a b : Z) (n : nat), Mod a b n -> Mod b a n.
Lemma mod_trans :
forall (a b c : Z) (n : nat), Mod a b n -> Mod b c n -> Mod a c n.
Lemma eqmod : forall x y : Z, x = y -> forall n : nat, Mod x y n.
Lemma mod_plus_compat :
forall (a b c d : Z) (n : nat),
Mod a b n -> Mod c d n -> Mod (a + c) (b + d) n.
Lemma mod_mult_compat :
forall (a b c d : Z) (n : nat),
Mod a b n -> Mod c d n -> Mod (a * c) (b * d) n.
Lemma mod_sqr_compat :
forall (a b : Z) (n : nat), Mod a b n -> Mod (a * a) (b * b) n.
Lemma mod_exp_compat :
forall (a b : Z) (n : nat),
Mod a b n -> forall m : nat, Mod (Exp a m) (Exp b m) n.
Lemma moda0_exp_compat :
forall (a : Z) (n : nat),
n > 0 -> Mod a 0 n -> forall m : nat, m > 0 -> Mod (Exp a m) 0 n.
Lemma mod_opp_compat :
forall (a b : Z) (n : nat), Mod a b n -> Mod (- a) (- b) n.
Lemma mod_minus_compat :
forall (a b c d : Z) (n : nat),
Mod a b n -> Mod c d n -> Mod (a - c) (b - d) n.
Lemma mod_nx_0_n : forall (n : nat) (x : Z), Mod (Z_of_nat n * x) 0 n.
Lemma moddivmin :
forall (a b : Z) (n : nat), Mod a b n <-> Divides n (Zabs_nat (a - b)).
Lemma moddec : forall (a b : Z) (n : nat), Mod a b n \/ ~ Mod a b n.
Lemma mod_0not1 : forall n : nat, n > 1 -> ~ Mod 0 1 n.
Lemma mod_exp1 :
forall (a : Z) (n : nat), Mod a 1 n -> forall m : nat, Mod (Exp a m) 1 n.
Lemma mod_repr_non_0 :
forall (n : nat) (x : Z), (0 < x < Z_of_nat n)%Z -> ~ Mod x 0 n.
Lemma mod_repr_eq :
forall (p : nat) (x y : Z),
0 < p ->
(0 < x < Z_of_nat p)%Z -> (0 < y < Z_of_nat p)%Z -> Mod x y p -> x = y.