(** We implement the extended version of Euclid's algorithm, i.e. the one computing Bezout's coefficients as it computes the [gcd]. We follow the algorithm given in Knuth's "Art of Computer Programming", vol 2, page 325. *)
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)]. *)

Lemma euclid_rec :
forall v3 : Z,
(0 <= v3)%Z ->
forall u1 u2 u3 v1 v2 : Z,
(u1 * a + u2 * b)%Z = u3 ->
(v1 * a + v2 * b)%Z = v3 ->
(forall d : Z, gcd u3 v3 d -> gcd a b d) -> Euclid.