(* 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                                                     *)
Require Export MiscRsa.
(******************************************************************************)
Inductive divides : nat -> nat -> Prop :=
dividesDef : forall a b q : nat, b = q * a -> divides a b.
intros a; apply dividesDef with (q := 1); auto with arith.
Qed.
intros x y; case x; case y; auto.
left; apply dividesDef with (q := 0); auto.
intros n; right; red in |- *; intros H'; inversion_clear H'.
rewrite (mult_comm q 0) in H; discriminate.
intros n; left; apply dividesDef with (q := 0); auto.
intros x' y'; case (divides_dec' (S x') (S y')); auto.
intros H'; left; apply div_divides; auto.
intros H'; right; red in |- *; intros H'0; case H'; auto.
inversion H'0.
exists q; auto.
apply is_div_def; auto with arith.
rewrite H; auto with arith.
Qed.
intros a b; case b.
intros H'; case H'; auto.
intros n H' H'0; inversion_clear H'0.
rewrite H; generalize H; case q; simpl in |- *; auto with arith; intros;
discriminate.
Qed.
intros a b H'1 H'2; red in |- *; intros H'3; absurd (a <= b); auto with arith.
apply divides_le; auto.
apply sym_not_eq; auto with arith.
Qed.
(********************************************************************)
Inductive prime : nat -> Prop :=
primeDef :
forall a : nat,
a <> 1 -> (forall b : nat, divides b a -> b <> 1 -> a = b) -> prime a.
Hint Resolve div_ref all_divides_O SO_divides_all not_prime_O not_prime_1.
(**********************************************************************)
Inductive is_gcd (a b c : nat) : Prop :=
is_gcd_intro :
divides c a ->
divides c b ->
(forall d : nat, divides d a -> divides d b -> divides d c) ->
is_gcd a b c.
intros a b c H; inversion_clear H; intros.
apply is_gcd_intro; auto.
Qed.
intros a.
apply is_gcd_intro; auto.
Qed.

Lemma is_gcd_Or : forall a : nat, is_gcd 0 a a.