unfold ltof.
unfold f.
intros.
case (lt_eq_lt_dec (fst x) (snd x));intro.
case s;intro.
destruct (fst x).
right;exists (0,1);simpl;rewrite <- minus_n_O;rewrite plus_comm;simpl;apply gcd_zero.
elim (H (S n,snd x-S n));try (intro;simpl).
elim a;intro y;intro.
left;exists ((fst y)+(snd y),(snd y)).
simpl;apply bezout_aux1;try (auto with arith).
elim b;intro y;intro.
right;exists ((fst y)+(snd y),(snd y)).
simpl;apply bezout_aux2;try (auto with arith).
simpl;omega.
rewrite e;left;exists (1,0);simpl;rewrite <- minus_n_O;rewrite plus_comm;simpl;apply gcd_refl.
destruct (snd x).
left;exists (1,0);simpl;rewrite <- minus_n_O;rewrite plus_comm;simpl;apply gcd_sym;apply gcd_zero.
elim (H (S n,fst x-S n));try (intro;simpl).
elim a;intro y;intro.
right;exists ((snd y),(fst y)+(snd y));apply gcd_sym.
simpl;apply bezout_aux1;try (auto with arith).
elim b;intro y;intro.
left;exists ((snd y),(fst y)+(snd y));apply gcd_sym.
simpl;apply bezout_aux2;try (auto with arith).
simpl;omega.
Qed.

(** Bezout' theorem *)
Theorem bezout_exists : forall (a b:nat),{u:nat & {v:nat | (is_gcd (a*u-b*v) a b)}}+{u:nat & {v:nat | (is_gcd (b*v-a*u) a b)}}.
intros.