Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)

Zgcd_alt : an alternate version of Z.gcd, based on Euclid's algorithm

Author: Pierre Letouzey
The alternate Zgcd_alt given here used to be the main Z.gcd function (see file Znumtheory), but this main Z.gcd is now based on a modern binary-efficient algorithm. This earlier version, based on Euclid's algorithm of iterated modulo, is kept here due to both its intrinsic interest and its use as reference point when proving gcd on Int31 numbers
Require Import ZArith_base.
Require Import ZArithRing.
Require Import Zdiv.
Require Import Znumtheory.
Require Import Omega.

Open Scope Z_scope.
In Coq, we need to control the number of iteration of modulo. For that, we use an explicit measure in nat, and we prove later that using 2*d is enough, where d is the number of binary digits of the first argument.
 Fixpoint Zgcdn (n:nat) : Z -> Z -> Z := fun a b =>
   match n with
     | O => 1 (* arbitrary, since n should be big enough *)
     | S n => match a with
	        | Z0 => Z.abs b
	        | Zpos _ => Zgcdn n (Z.modulo b a) a
	        | Zneg a => Zgcdn n (Z.modulo b (Zpos a)) (Zpos a)
  	      end
   end.

 Definition Zgcd_bound (a:Z) :=
   match a with
     | Z0 => S O
     | Zpos p => let n := Pos.size_nat p in (n+n)%nat
     | Zneg p => let n := Pos.size_nat p in (n+n)%nat
   end.

 Definition Zgcd_alt a b := Zgcdn (Zgcd_bound a) a b.
A first obvious fact : Z.gcd a b is positive.
 

forall (n : nat) (a b : Z), 0 <= Zgcdn n a b

forall (n : nat) (a b : Z), 0 <= Zgcdn n a b

forall a b : Z, 0 <= Zgcdn 0 a b
n:nat
IHn:forall a b : Z, 0 <= Zgcdn n a b
forall a b : Z, 0 <= Zgcdn (S n) a b
n:nat
IHn:forall a b : Z, 0 <= Zgcdn n a b

forall a b : Z, 0 <= Zgcdn (S n) a b
destruct a; simpl; intros; auto with zarith; auto. Qed.

forall a b : Z, 0 <= Zgcd_alt a b

forall a b : Z, 0 <= Zgcd_alt a b
intros; unfold Z.gcd; apply Zgcdn_pos; auto. Qed.
We now prove that Z.gcd is indeed a gcd.
 
1) We prove a weaker & easier bound.
 

forall (n : nat) (a b : Z), Z.abs a < Z.of_nat n -> Zis_gcd a b (Zgcdn n a b)

forall (n : nat) (a b : Z), Z.abs a < Z.of_nat n -> Zis_gcd a b (Zgcdn n a b)

forall a b : Z, Z.abs a < Z.of_nat 0 -> Zis_gcd a b (Zgcdn 0 a b)
n:nat
IHn:forall a b : Z, Z.abs a < Z.of_nat n -> Zis_gcd a b (Zgcdn n a b)
forall a b : Z, Z.abs a < Z.of_nat (S n) -> Zis_gcd a b (Zgcdn (S n) a b)
a, b:Z
H:Z.abs a < 0

Zis_gcd a b 1
n:nat
IHn:forall a b : Z, Z.abs a < Z.of_nat n -> Zis_gcd a b (Zgcdn n a b)
forall a b : Z, Z.abs a < Z.of_nat (S n) -> Zis_gcd a b (Zgcdn (S n) a b)
n:nat
IHn:forall a b : Z, Z.abs a < Z.of_nat n -> Zis_gcd a b (Zgcdn n a b)

forall a b : Z, Z.abs a < Z.of_nat (S n) -> Zis_gcd a b (Zgcdn (S n) a b)
n:nat
p:positive
b:Z
H:Z.pos p < Z.succ (Z.of_nat n)
q, r:Z
H0:b = Z.pos p * q + r
H1:0 <= r < Z.pos p
H2:Z.abs r < Z.of_nat n
IH:Zis_gcd r (Z.pos p) (Zgcdn n r (Z.pos p))

Zis_gcd (Z.pos p) (Z.pos p * q + r) (Zgcdn n r (Z.pos p))
n:nat
p:positive
b:Z
H:Z.pos p < Z.succ (Z.of_nat n)
q, r:Z
H0:b = Z.pos p * q + r
H1:0 <= r < Z.pos p
H2:Z.abs r < Z.of_nat n
IH:Zis_gcd r (Z.pos p) (Zgcdn n r (Z.pos p))
Zis_gcd (Z.neg p) (Z.pos p * q + r) (Zgcdn n r (Z.pos p))
n:nat
p:positive
b:Z
H:Z.pos p < Z.succ (Z.of_nat n)
q, r:Z
H0:b = Z.pos p * q + r
H1:0 <= r < Z.pos p
H2:Z.abs r < Z.of_nat n
IH:Zis_gcd r (Z.pos p) (Zgcdn n r (Z.pos p))

Zis_gcd (Z.neg p) (Z.pos p * q + r) (Zgcdn n r (Z.pos p))
n:nat
p:positive
b:Z
H:Z.pos p < Z.succ (Z.of_nat n)
q, r:Z
H0:b = Z.pos p * q + r
H1:0 <= r < Z.pos p
H2:Z.abs r < Z.of_nat n
IH:Zis_gcd r (Z.pos p) (Zgcdn n r (Z.pos p))

Zis_gcd (- Z.neg p) (Z.pos p * q + r) (Zgcdn n r (Z.pos p))
apply Zis_gcd_for_euclid2; auto. Qed.
2) For Euclid's algorithm, the worst-case situation corresponds to Fibonacci numbers. Let's define them:
 Fixpoint fibonacci (n:nat) : Z :=
   match n with
     | O => 1
     | S O => 1
     | S (S n as p) => fibonacci p + fibonacci n
   end.

 

forall n : nat, 0 <= fibonacci n

forall n : nat, 0 <= fibonacci n

forall N n : nat, (n < N)%nat -> 0 <= fibonacci n

forall n : nat, (n < 0)%nat -> 0 <= fibonacci n
N:nat
IHN:forall n : nat, (n < N)%nat -> 0 <= fibonacci n
forall n : nat, (n < S N)%nat -> 0 <= fibonacci n
N:nat
IHN:forall n : nat, (n < N)%nat -> 0 <= fibonacci n

forall n : nat, (n < S N)%nat -> 0 <= fibonacci n
N:nat
IHN:forall n0 : nat, (n0 < N)%nat -> 0 <= fibonacci n0
n:nat
H:(n < S N)%nat

0 <= fibonacci n
N:nat
IHN:forall n : nat, (n < N)%nat -> 0 <= fibonacci n
H:(0 < S N)%nat

0 <= fibonacci 0
N:nat
IHN:forall n0 : nat, (n0 < N)%nat -> 0 <= fibonacci n0
n:nat
H:(S n < S N)%nat
0 <= fibonacci (S n)
N:nat
IHN:forall n0 : nat, (n0 < N)%nat -> 0 <= fibonacci n0
n:nat
H:(S n < S N)%nat

0 <= fibonacci (S n)
N:nat
IHN:forall n : nat, (n < N)%nat -> 0 <= fibonacci n
H:(1 < S N)%nat

0 <= fibonacci 1
N:nat
IHN:forall n0 : nat, (n0 < N)%nat -> 0 <= fibonacci n0
n:nat
H:(S (S n) < S N)%nat
0 <= fibonacci (S (S n))
N:nat
IHN:forall n0 : nat, (n0 < N)%nat -> 0 <= fibonacci n0
n:nat
H:(S (S n) < S N)%nat

0 <= fibonacci (S (S n))
N:nat
IHN:forall n0 : nat, (n0 < N)%nat -> 0 <= fibonacci n0
n:nat
H:(S (S n) < S N)%nat

0 <= fibonacci (S n) + fibonacci n
generalize (IHN n) (IHN (S n)); omega. Qed.

forall n m : nat, (n <= m)%nat -> fibonacci n <= fibonacci m

forall n m : nat, (n <= m)%nat -> fibonacci n <= fibonacci m
n:nat

fibonacci n <= fibonacci n
n, m:nat
H:(n <= m)%nat
IHle:fibonacci n <= fibonacci m
fibonacci n <= fibonacci (S m)
n, m:nat
H:(n <= m)%nat
IHle:fibonacci n <= fibonacci m

fibonacci n <= fibonacci (S m)
n, m:nat
H:(n <= m)%nat
IHle:fibonacci n <= fibonacci m

fibonacci m <= fibonacci (S m)
m:nat

fibonacci m <= fibonacci (S m)

fibonacci 0 <= fibonacci 1
m:nat
fibonacci (S m) <= fibonacci (S (S m))
m:nat

fibonacci (S m) <= fibonacci (S (S m))
m:nat

fibonacci (S m) <= fibonacci (S m) + fibonacci m
generalize (fibonacci_pos m); omega. Qed.
3) We prove that fibonacci numbers are indeed worst-case: for a given number n, if we reach a conclusion about gcd(a,b) in exactly n+1 loops, then fibonacci (n+1)<=a fibonacci(n+2)<=b
 

forall (n : nat) (a b : Z), 0 < a < b -> Zis_gcd a b (Zgcdn (S n) a b) -> Zgcdn n a b <> Zgcdn (S n) a b -> fibonacci (S n) <= a /\ fibonacci (S (S n)) <= b

forall (n : nat) (a b : Z), 0 < a < b -> Zis_gcd a b (Zgcdn (S n) a b) -> Zgcdn n a b <> Zgcdn (S n) a b -> fibonacci (S n) <= a /\ fibonacci (S (S n)) <= b

forall a b : Z, 0 < a < b -> Zis_gcd a b (Zgcdn 1 a b) -> Zgcdn 0 a b <> Zgcdn 1 a b -> fibonacci 1 <= a /\ fibonacci 2 <= b
n:nat
IHn:forall a b : Z, 0 < a < b -> Zis_gcd a b (Zgcdn (S n) a b) -> Zgcdn n a b <> Zgcdn (S n) a b -> fibonacci (S n) <= a /\ fibonacci (S (S n)) <= b
forall a b : Z, 0 < a < b -> Zis_gcd a b (Zgcdn (S (S n)) a b) -> Zgcdn (S n) a b <> Zgcdn (S (S n)) a b -> fibonacci (S (S n)) <= a /\ fibonacci (S (S (S n))) <= b
n:nat
IHn:forall a b : Z, 0 < a < b -> Zis_gcd a b (Zgcdn (S n) a b) -> Zgcdn n a b <> Zgcdn (S n) a b -> fibonacci (S n) <= a /\ fibonacci (S (S n)) <= b

forall a b : Z, 0 < a < b -> Zis_gcd a b (Zgcdn (S (S n)) a b) -> Zgcdn (S n) a b <> Zgcdn (S (S n)) a b -> fibonacci (S (S n)) <= a /\ fibonacci (S (S (S n))) <= b
n:nat
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn (S n) a0 b0) -> Zgcdn n a0 b0 <> Zgcdn (S n) a0 b0 -> fibonacci (S n) <= a0 /\ fibonacci (S (S n)) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b

Zis_gcd (Z.pos a) b (Zgcdn (S (S n)) (Z.pos a) b) -> Zgcdn (S n) (Z.pos a) b <> Zgcdn (S (S n)) (Z.pos a) b -> fibonacci (S (S n)) <= Z.pos a /\ fibonacci (S (S (S n))) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b

Zis_gcd (Z.pos a) b (Zgcdn (S m) (Z.pos a) b) -> Zgcdn m (Z.pos a) b <> Zgcdn (S m) (Z.pos a) b -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b

Zis_gcd (Z.pos a) b (Zgcdn (S m) (Z.pos a) b) -> Zgcdn (S n) (Z.pos a) b <> Zgcdn (S m) (Z.pos a) b -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b

Zis_gcd (Z.pos a) b (Zgcdn m (b mod Z.pos a) (Z.pos a)) -> Zgcdn n (b mod Z.pos a) (Z.pos a) <> Zgcdn m (b mod Z.pos a) (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b

(let (q, r) := Z.div_eucl b (Z.pos a) in b = Z.pos a * q + r /\ 0 <= r < Z.pos a) -> Zis_gcd (Z.pos a) b (Zgcdn m (let (_, r) := Z.div_eucl b (Z.pos a) in r) (Z.pos a)) -> Zgcdn n (let (_, r) := Z.div_eucl b (Z.pos a) in r) (Z.pos a) <> Zgcdn m (let (_, r) := Z.div_eucl b (Z.pos a) in r) (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z

b = Z.pos a * q + r /\ 0 <= r < Z.pos a -> Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 <= r
Hr':r < Z.pos a

Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a

Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 = r
Hr':r < Z.pos a
Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a

Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a

Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S m) + fibonacci m <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)

fibonacci (S m) <= Z.pos a /\ fibonacci (S m) + fibonacci m <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)

Zis_gcd r (Z.pos a) (Zgcdn m r (Z.pos a))
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a
fibonacci (S m) <= Z.pos a /\ fibonacci (S m) + fibonacci m <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)

Zis_gcd r (Z.pos a) (Zgcdn m r (Z.pos a))
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
EQ':r = Z.pos a * - q + b

Zis_gcd r (Z.pos a) (Zgcdn m r (Z.pos a))
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
EQ':r = Z.pos a * - q + b

Zis_gcd (Z.pos a * - q + b) (Z.pos a) (Zgcdn m r (Z.pos a))
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
EQ':r = Z.pos a * - q + b

Zis_gcd (Z.pos a) (Z.pos a * - q + b) (Zgcdn m r (Z.pos a))
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
EQ':r = Z.pos a * - q + b

Zis_gcd b (Z.pos a) (Zgcdn m r (Z.pos a))
apply Zis_gcd_sym; auto.
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

fibonacci (S m) <= Z.pos a /\ fibonacci (S m) + fibonacci m <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

fibonacci (S m) + fibonacci m <= b
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

fibonacci (S m) + fibonacci m <= Z.pos a * q + r
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

fibonacci (S m) <= Z.pos a * q
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

fibonacci (S m) <= Z.pos a * 1
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a
Z.pos a * 1 <= Z.pos a * q
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

Z.pos a * 1 <= Z.pos a * q
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

1 <= q
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

Z.succ 0 <= q
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

0 < q
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
p:positive
r:Z
EQ:b = Z.pos a * Z.neg p + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a

0 < Z.neg p
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
p:positive
r:Z
EQ:b = Z.pos a * Z.neg p + r
Hr:0 < r
Hr':r < Z.pos a
H:Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a))
H0:Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a)
H1:fibonacci m <= r
H2:fibonacci (S m) <= Z.pos a
H3:Z.pos a * Z.neg p < 0

0 < Z.neg p
omega.
n, m:nat
Heqm:m = S n
IHn:forall a0 b0 : Z, 0 < a0 < b0 -> Zis_gcd a0 b0 (Zgcdn m a0 b0) -> Zgcdn n a0 b0 <> Zgcdn m a0 b0 -> fibonacci m <= a0 /\ fibonacci (S m) <= b0
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
EQ:b = Z.pos a * q + r
Hr:0 = r
Hr':r < Z.pos a

Zis_gcd (Z.pos a) b (Zgcdn m r (Z.pos a)) -> Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q, r:Z
Hr:0 = r

Zgcdn n r (Z.pos a) <> Zgcdn m r (Z.pos a) -> fibonacci (S m) <= Z.pos a /\ fibonacci (S (S m)) <= b
n, m:nat
Heqm:m = S n
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q:Z

Zgcdn n 0 (Z.pos a) <> Zgcdn (S n) 0 (Z.pos a) -> fibonacci (S n) + fibonacci n <= Z.pos a /\ fibonacci (S n) + fibonacci n + fibonacci (S n) <= b
m:nat
Heqm:m = 1%nat
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q:Z

Zgcdn 0 0 (Z.pos a) <> Zgcdn 1 0 (Z.pos a) -> fibonacci 1 + fibonacci 0 <= Z.pos a /\ fibonacci 1 + fibonacci 0 + fibonacci 1 <= b
n, m:nat
Heqm:m = S (S n)
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q:Z
Zgcdn (S n) 0 (Z.pos a) <> Zgcdn (S (S n)) 0 (Z.pos a) -> fibonacci (S (S n)) + fibonacci (S n) <= Z.pos a /\ fibonacci (S (S n)) + fibonacci (S n) + fibonacci (S (S n)) <= b
m:nat
Heqm:m = 1%nat
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q:Z

Zgcdn 0 0 (Z.pos a) <> Zgcdn 1 0 (Z.pos a) -> fibonacci 1 + fibonacci 0 <= Z.pos a /\ fibonacci 1 + fibonacci 0 + fibonacci 1 <= b
m:nat
Heqm:m = 1%nat
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q:Z

1 <> Z.pos a -> 2 <= Z.pos a /\ 3 <= b
omega.
n, m:nat
Heqm:m = S (S n)
a:positive
b:Z
Ha:0 < Z.pos a
Ha':Z.pos a < b
q:Z

Zgcdn (S n) 0 (Z.pos a) <> Zgcdn (S (S n)) 0 (Z.pos a) -> fibonacci (S (S n)) + fibonacci (S n) <= Z.pos a /\ fibonacci (S (S n)) + fibonacci (S n) + fibonacci (S (S n)) <= b
now destruct 1. Qed.
3b) We reformulate the previous result in a more positive way.
 

forall (n : nat) (a b : Z), 0 < a < b -> a < fibonacci (S n) -> Zis_gcd a b (Zgcdn n a b)

forall (n : nat) (a b : Z), 0 < a < b -> a < fibonacci (S n) -> Zis_gcd a b (Zgcdn n a b)
n:nat
p:positive

forall b : Z, 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
n:nat
p:positive

(forall (k n0 : nat) (b : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b (Zgcdn n0 (Z.pos p) b)) -> forall b : Z, 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
n:nat
p:positive
forall (k n0 : nat) (b : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b (Zgcdn n0 (Z.pos p) b)
n:nat
p:positive

forall (k n0 : nat) (b : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b (Zgcdn n0 (Z.pos p) b)
p:positive

forall (n : nat) (b : Z), 0%nat = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)

Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:(Pos.to_nat p < n)%nat

Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:(Pos.to_nat p < n)%nat

Z.abs (Z.pos p) < Z.of_nat n
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:(Pos.to_nat p < n)%nat

Z.pos p < Z.of_nat n
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:(Pos.to_nat p < n)%nat

Z.of_nat (S (Pos.to_nat p)) <= Z.of_nat n -> Z.pos p < Z.of_nat n
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:(Pos.to_nat p < n)%nat

Z.succ (Z.of_nat (Pos.to_nat p)) <= Z.of_nat n -> Z.pos p < Z.of_nat n
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
n:nat
b:Z
H:0%nat = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:(Pos.to_nat p < n)%nat

Z.succ (Z.pos p) <= Z.of_nat n -> Z.pos p < Z.of_nat n
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n : nat) (b : Z), k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)

forall (n : nat) (b : Z), S k = (S (Pos.to_nat p) - n)%nat -> 0 < Z.pos p < b -> Z.pos p < fibonacci (S n) -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)

Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b

Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b

Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
H3:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)
Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b

k = (S (Pos.to_nat p) - S n)%nat
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
Z.pos p < fibonacci (S (S n))
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
H3:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)
Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b

Z.pos p < fibonacci (S (S n))
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
H3:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)
Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b

Z.pos p < fibonacci (S n) + fibonacci n
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
H3:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)
Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
H3:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)

Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
p:positive
k:nat
IHk:forall (n0 : nat) (b0 : Z), k = (S (Pos.to_nat p) - n0)%nat -> 0 < Z.pos p < b0 -> Z.pos p < fibonacci (S n0) -> Zis_gcd (Z.pos p) b0 (Zgcdn n0 (Z.pos p) b0)
n:nat
b:Z
H:S k = (S (Pos.to_nat p) - n)%nat
H0:0 < Z.pos p < b
H1:Z.pos p < fibonacci (S n)
H2:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b) -> Zgcdn n (Z.pos p) b <> Zgcdn (S n) (Z.pos p) b -> fibonacci (S n) <= Z.pos p /\ fibonacci (S (S n)) <= b
H3:Zis_gcd (Z.pos p) b (Zgcdn (S n) (Z.pos p) b)

Zgcdn (S n) (Z.pos p) b = Zgcdn n (Z.pos p) b
generalize (H2 H3); clear H2 H3; omega. Qed.
4) The proposed bound leads to a fibonacci number that is big enough.
 

forall a : Z, 0 < a -> a < fibonacci (Zgcd_bound a)

forall a : Z, 0 < a -> a < fibonacci (Zgcd_bound a)
p:positive

0 < Z.pos p -> Z.pos p < fibonacci (Zgcd_bound (Z.pos p))
p:positive

Z.pos p < fibonacci (Zgcd_bound (Z.pos p))
p:positive
n:=(Pos.size_nat p + Pos.size_nat p)%nat:nat
IHp:Z.pos p < fibonacci n
H:n <> 0%nat

Z.pos p~1 < match n with | 0%nat => 1 | S n0 => fibonacci n + fibonacci n0 end + fibonacci n
p:positive
n:=(Pos.size_nat p + Pos.size_nat p)%nat:nat
IHp:Z.pos p < fibonacci n
H:n <> 0%nat
Z.pos p~0 < match n with | 0%nat => 1 | S n0 => fibonacci n + fibonacci n0 end + fibonacci n
p:positive
m:nat
IHp:Z.pos p < fibonacci (S m)
H:S m <> 0%nat

Z.pos p~1 < fibonacci (S m) + fibonacci m + fibonacci (S m)
p:positive
n:=(Pos.size_nat p + Pos.size_nat p)%nat:nat
IHp:Z.pos p < fibonacci n
H:n <> 0%nat
Z.pos p~0 < match n with | 0%nat => 1 | S n0 => fibonacci n + fibonacci n0 end + fibonacci n
p:positive
n:=(Pos.size_nat p + Pos.size_nat p)%nat:nat
IHp:Z.pos p < fibonacci n
H:n <> 0%nat

Z.pos p~0 < match n with | 0%nat => 1 | S n0 => fibonacci n + fibonacci n0 end + fibonacci n
p:positive
m:nat
IHp:Z.pos p < fibonacci (S m)
H:S m <> 0%nat

Z.pos p~0 < fibonacci (S m) + fibonacci m + fibonacci (S m)
generalize (fibonacci_pos m); rewrite Pos2Z.inj_xO; omega. Qed. (* 5) the end: we glue everything together and take care of situations not corresponding to [0<a<b]. *)
a:Z

Zgcd_bound (- a) = Zgcd_bound a
a:Z

Zgcd_bound (- a) = Zgcd_bound a
now destruct a. Qed.
n:nat
a, b:Z

Zgcdn n (- a) b = Zgcdn n a b
n:nat
a, b:Z

Zgcdn n (- a) b = Zgcdn n a b
n:nat
a, b:Z
IHn:Zgcdn n (- a) b = Zgcdn n a b

match - a with | 0 => Z.abs b | Z.pos _ => Zgcdn n (b mod - a) (- a) | Z.neg a0 => Zgcdn n (b mod Z.pos a0) (Z.pos a0) end = match a with | 0 => Z.abs b | Z.pos _ => Zgcdn n (b mod a) a | Z.neg a0 => Zgcdn n (b mod Z.pos a0) (Z.pos a0) end
destruct a; simpl; auto. Qed.
n:nat
a:positive
b:Z

(Zgcd_bound (Z.pos a) <= n)%nat -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z

(Zgcd_bound (Z.pos a) <= n)%nat -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
H:(Zgcd_bound (Z.pos a) <= n)%nat

Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
H:(Zgcd_bound (Z.pos a) <= n)%nat

(0 < Z.pos a -> Z.pos a < fibonacci (Zgcd_bound (Z.pos a))) -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
H:(Pos.size_nat a + Pos.size_nat a <= n)%nat

(0 < Z.pos a -> Z.pos a < fibonacci (Pos.size_nat a + Pos.size_nat a)) -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
m:nat
Heqm:m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(m <= n)%nat

(0 < Z.pos a -> Z.pos a < fibonacci m) -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
m:nat
Heqm:m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(m <= n)%nat

(1 < m)%nat
n:nat
a:positive
b:Z
m:nat
Heqm:m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(m <= n)%nat
H0:(1 < m)%nat
(0 < Z.pos a -> Z.pos a < fibonacci m) -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
m:nat
Heqm:m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(m <= n)%nat

(1 < m)%nat
rewrite Heqm; destruct a; simpl; rewrite 1?plus_comm; auto with arith.
n:nat
a:positive
b:Z
m:nat
Heqm:m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(m <= n)%nat
H0:(1 < m)%nat

(0 < Z.pos a -> Z.pos a < fibonacci m) -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= n)%nat
H0:(1 < S m)%nat

(0 < Z.pos a -> Z.pos a < fibonacci (S m)) -> Zis_gcd (Z.pos a) b (Zgcdn n (Z.pos a) b)
n:nat
a:positive
b:Z
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat

(0 < Z.pos a -> Z.pos a < fibonacci (S m)) -> Zis_gcd (Z.pos a) b (Zgcdn (S n) (Z.pos a) b)
n:nat
a:positive
b:Z
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat

(0 < Z.pos a -> Z.pos a < fibonacci (S m)) -> Zis_gcd (Z.pos a) b (Zgcdn n (b mod Z.pos a) (Z.pos a))
n:nat
a:positive
b:Z
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat

(0 < Z.pos a -> Z.pos a < fibonacci (S m)) -> Zis_gcd (Z.pos a) b (Zgcdn n (let (_, r) := Z.div_eucl b (Z.pos a) in r) (Z.pos a))
n:nat
a:positive
b:Z
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat

(let (q, r) := Z.div_eucl b (Z.pos a) in b = Z.pos a * q + r /\ 0 <= r < Z.pos a) -> (0 < Z.pos a -> Z.pos a < fibonacci (S m)) -> Zis_gcd (Z.pos a) b (Zgcdn n (let (_, r) := Z.div_eucl b (Z.pos a) in r) (Z.pos a))
n:nat
a:positive
b:Z
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z

b = Z.pos a * q + r /\ 0 <= r < Z.pos a -> (0 < Z.pos a -> Z.pos a < fibonacci (S m)) -> Zis_gcd (Z.pos a) b (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 <= r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

Zis_gcd (Z.pos a) (Z.pos a * q + r) (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 <= r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

Zis_gcd r (Z.pos a) (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 < r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

Zis_gcd r (Z.pos a) (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 = r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)
Zis_gcd r (Z.pos a) (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 < r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

Zis_gcd r (Z.pos a) (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 < r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

r < fibonacci (S n)
apply Z.lt_le_trans with (fibonacci (S m)); [ omega | apply fibonacci_incr; auto].
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q, r:Z
H1:0 = r
H2:r < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

Zis_gcd r (Z.pos a) (Zgcdn n r (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S m = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S m <= S n)%nat
H0:(1 < S m)%nat
q:Z
H2:0 < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S m)

Zis_gcd 0 (Z.pos a) (Zgcdn n 0 (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S (S m) = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S (S m) <= S n)%nat
H0:(1 < S (S m))%nat
q:Z
H2:0 < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S (S m))

Zis_gcd 0 (Z.pos a) (Zgcdn n 0 (Z.pos a))
n:nat
a:positive
m:nat
Heqm:S (S m) = (Pos.size_nat a + Pos.size_nat a)%nat
H:(S (S m) <= S (S n))%nat
H0:(1 < S (S m))%nat
q:Z
H2:0 < Z.pos a
H3:0 < Z.pos a -> Z.pos a < fibonacci (S (S m))

Zis_gcd 0 (Z.pos a) (Zgcdn (S n) 0 (Z.pos a))
simpl; apply Zis_gcd_sym; apply Zis_gcd_0. Qed.
n:nat
a, b:Z

(Zgcd_bound a <= n)%nat -> Zis_gcd a b (Zgcdn n a b)
n:nat
a, b:Z

(Zgcd_bound a <= n)%nat -> Zis_gcd a b (Zgcdn n a b)
n:nat
b:Z

(Zgcd_bound 0 <= n)%nat -> Zis_gcd 0 b (Zgcdn n 0 b)
n:nat
p:positive
b:Z
(Zgcd_bound (Z.pos p) <= n)%nat -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
n:nat
p:positive
b:Z
(Zgcd_bound (Z.neg p) <= n)%nat -> Zis_gcd (Z.neg p) b (Zgcdn n (Z.neg p) b)
n:nat
b:Z

(Zgcd_bound 0 <= n)%nat -> Zis_gcd 0 b (Zgcdn n 0 b)
n:nat
b:Z
H:(1 <= n)%nat

Zis_gcd 0 b (Zgcdn n 0 b)
n:nat
b:Z
H:(1 <= S n)%nat

Zis_gcd 0 b (Zgcdn (S n) 0 b)
simpl; generalize (Zis_gcd_0_abs b); intuition.
n:nat
p:positive
b:Z

(Zgcd_bound (Z.pos p) <= n)%nat -> Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
apply Zgcdn_is_gcd_pos.
n:nat
p:positive
b:Z

(Zgcd_bound (Z.neg p) <= n)%nat -> Zis_gcd (Z.neg p) b (Zgcdn n (Z.neg p) b)
n:nat
p:positive
b:Z

(Zgcd_bound (- Z.neg p) <= n)%nat -> Zis_gcd (Z.neg p) b (Zgcdn n (- Z.neg p) b)
n:nat
p:positive
b:Z
H:(Zgcd_bound (- Z.neg p) <= n)%nat

Zis_gcd (Z.neg p) b (Zgcdn n (- Z.neg p) b)
n:nat
p:positive
b:Z
H:(Zgcd_bound (- Z.neg p) <= n)%nat

Zis_gcd (- Z.neg p) b (Zgcdn n (- Z.neg p) b)
n:nat
p:positive
b:Z
H:(Zgcd_bound (- Z.neg p) <= n)%nat

Zis_gcd (Z.pos p) b (Zgcdn n (Z.pos p) b)
now apply Zgcdn_is_gcd_pos. Qed.

forall a b : Z, Zis_gcd a b (Zgcd_alt a b)

forall a b : Z, Zis_gcd a b (Zgcd_alt a b)
unfold Zgcd_alt; intros; apply Zgcdn_is_gcd; auto. Qed.