Section extended_euclid_algorithm.
Variable a b : Z.
(** The specification of Euclid's algorithm is the existence of [u], [v] and [d] such that [ua+vb=d] and [(gcd a b d)]. *)
Inductive Euclid : Set :=
Euclid_intro :
forall u v d : Z, (u * a + v * b)%Z = d -> gcd a b d -> Euclid.
(** The recursive part of Euclid's algorithm uses well-founded recursion of non-negative integers. It maintains 6 integers [u1,u2,u3,v1,v2,v3] such that the following invariant holds: [u1*a+u2*b=u3] and [v1*a+v2*b=v3] and [gcd(u2,v3)=gcd(a,b)]. *)
(** We get Euclid's algorithm by applying [euclid_rec] on [1,0,a,0,1,b] when [b>=0] and [1,0,a,0,-1,-b] when [b<0]. *)
End extended_euclid_algorithm.
(** * Bezout's coefficients *)
Inductive Bezout (a b d : Z) : Prop :=
Bezout_intro : forall u v : Z, (u * a + v * b)%Z = d -> Bezout a b d.
(** Existence of Bezout's coefficients for the [gcd] of [a] and [b] *)
(** gcd of [ca] and [cb] is [c gcd(a,b)]. *)

Lemma gcd_mult : forall a b c d : Z, gcd a b d -> gcd (c * a) (c * b) (c * d).