(* 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                                                     *)


(******** Copied variables upto bdd5_2.v *)

Require Import Bool.
Require Import Sumbool.
Require Import Arith.
Require Import ZArith NArith Nnat Ndec Ndigits.
From IntMap Require Import Allmaps.
Definition BDDzero := N0.
Definition BDDone := Npos 1.

  Definition BDDvar := ad.

  Definition BDDcompare (x y : BDDvar) :=
    match x, y with
    | N0, N0 => Datatypes.Eq
    | N0, Npos _ => Datatypes.Lt
    | Npos _, N0 => Datatypes.Gt
    | Npos p1, Npos p2 => Pcompare p1 p2 Datatypes.Eq
    end.

Definition BDDvar_eq := Neqb.

  Definition ad_S (a : ad) :=
    match a with
    | N0 => Npos 1
    | Npos p => Npos (Psucc p)
    end.

  Lemma ad_S_is_S : forall a : ad, nat_of_N (ad_S a) = S (nat_of_N a).
  Proof.
(* Goal: forall a : BDDvar, @eq comparison (BDDcompare a (ad_S a)) Lt *)
    simple induction a. reflexivity.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    simpl in |- *. unfold nat_of_P in |- *. intro p. exact (Pmult_nat_succ_morphism p 1).
  Qed.

Lemma lt_pred : forall x y : nat, x < y -> x <> 0 -> pred x < pred y.
Proof.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  simple induction x.  intros y H H0.  absurd (0 = 0).  assumption.  reflexivity.  intros n H y H0 H1.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  apply lt_pred.  assumption.
Qed.

Lemma O_N0 : forall x : ad, nat_of_N x = 0 -> x = N0.
Proof.
(* Goal: forall (x : ad) (_ : @eq nat (N.to_nat x) O), @eq ad x N0 *)
  cut (0 = nat_of_N N0).  intro H.  rewrite H.  intros x H0.  replace x with (N_of_nat (nat_of_N x)).
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  replace N0 with (N_of_nat (nat_of_N N0)).  rewrite H0.  reflexivity.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  rewrite (N_of_nat_of_N N0).  reflexivity.  rewrite (N_of_nat_of_N x).
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  reflexivity.  reflexivity.
Qed.
Lemma INFERIEUR_neq_O :
 forall x y : ad, BDDcompare x y = Datatypes.Lt -> y <> N0.
Proof.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  double induction x y.  simpl in |- *.  intro; discriminate.  unfold not in |- *; intros.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  discriminate.  simpl in |- *.  intros; discriminate.  unfold not in |- *; intros.  discriminate.
Qed.

 Lemma BDDcompare_trans :
  forall x y z : BDDvar,
  BDDcompare x y = Datatypes.Lt ->
  BDDcompare y z = Datatypes.Lt -> BDDcompare x z = Datatypes.Lt.
  Proof.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    double induction x y.  simpl in |- *.  intros z H H0.  discriminate H.  simpl in |- *.  intro p.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    simple induction z.  intros H H0.  discriminate H0.  trivial.  simpl in |- *.  intros p z H H0.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    discriminate H.  intro p.  intro p0.  simple induction z.  simpl in |- *.  trivial.  intro p1.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    simpl in |- *.  intros H H0.  cut (nat_of_P p0 < nat_of_P p).
(* Goal: forall _ : lt (Pos.to_nat p0) (Pos.to_nat p), @eq comparison (Pos.compare_cont Eq p0 p1) Lt *)
(* Goal: lt (Pos.to_nat p0) (Pos.to_nat p) *)
    cut (nat_of_P p < nat_of_P p1).  intros H1 H2.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Lt *)
    apply nat_of_P_lt_Lt_compare_complement_morphism.  apply lt_trans with (m := nat_of_P p).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    assumption.  assumption.  apply nat_of_P_lt_Lt_compare_morphism.  assumption.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply nat_of_P_lt_Lt_compare_morphism.  assumption.
  Qed.

  Lemma ad_S_le_then_le :
   forall x y : ad, Nleb (ad_S x) y = true -> Nleb x y = true.
  Proof.
(* Goal: forall (x y : BDDvar) (_ : @eq comparison (BDDcompare x y) Lt), or (@eq comparison (BDDcompare (ad_S x) y) Lt) (@eq N (ad_S x) y) *)
    intros x y H.  cut (Nleb x (ad_S x) = true).  intro H0.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply Nleb_trans with (b := ad_S x).  assumption.  assumption.  unfold Nleb in |- *.
(* Goal: @eq bool (Nat.leb (N.to_nat y) (N.to_nat (ad_S y))) true *)
    apply leb_correct.  rewrite (ad_S_is_S x).  apply le_S.  apply le_n.
  Qed.

  Lemma le_then_le_S :
   forall x y : ad, Nleb x y = true -> Nleb x (ad_S y) = true.
  Proof.
(* Goal: forall (x y : BDDvar) (_ : @eq comparison (BDDcompare x y) Lt), or (@eq comparison (BDDcompare (ad_S x) y) Lt) (@eq N (ad_S x) y) *)
    intros x y H.  cut (Nleb y (ad_S y) = true).  intro H0.  apply Nleb_trans with (b := y).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    assumption.  assumption.  unfold Nleb in |- *.  apply leb_correct.  rewrite (ad_S_is_S y).
(* Goal: le (N.to_nat y) (S (N.to_nat y)) *)
    apply le_S.  apply le_n.
  Qed.

  Lemma ad_S_le_then_neq :
   forall x y : ad, Nleb (ad_S x) y = true -> Neqb x y = false.
  Proof.
(* Goal: forall (x y : BDDvar) (_ : @eq comparison (BDDcompare x y) Lt), or (@eq comparison (BDDcompare (ad_S x) y) Lt) (@eq N (ad_S x) y) *)
    intros x y H.  cut (Neqb x y = true \/ Neqb x y = false).  intro H0.  elim H0.
(* Goal: forall _ : @eq positive p0 p, @eq BDDvar (Npos p0) (Npos p) *)
(* Goal: @eq positive p0 p *)
    clear H0.  intro H0.  cut (x = y).  intro H1.  rewrite H1 in H.  unfold Nleb in H.
(* Goal: @eq bool (N.eqb x y) false *)
(* Goal: @eq ad x y *)
(* Goal: forall _ : @eq bool (N.eqb x y) false, @eq bool (N.eqb x y) false *)
(* Goal: or (@eq bool (N.eqb x y) true) (@eq bool (N.eqb x y) false) *)
    rewrite (ad_S_is_S y) in H.
(* Goal: lt (Pos.to_nat p) (Pos.to_nat (Pos.succ p)) *)
(* Goal: @eq nat (Pos.to_nat (Pos.succ p)) (Init.Nat.add (S O) (Pos.to_nat p)) *)
    cut (leb (S (nat_of_N y)) (nat_of_N y) = false).  rewrite H.  intro H2.
(* Goal: forall _ : lt (N.to_nat y) (S (N.to_nat y)), @eq bool (Nat.leb (S (N.to_nat y)) (N.to_nat y)) false *)
(* Goal: lt (N.to_nat y) (S (N.to_nat y)) *)
(* Goal: @eq ad x y *)
(* Goal: forall _ : @eq bool (N.eqb x y) false, @eq bool (N.eqb x y) false *)
(* Goal: or (@eq bool (N.eqb x y) true) (@eq bool (N.eqb x y) false) *)
    discriminate H2.  cut (nat_of_N y < S (nat_of_N y)).  intro H2.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply leb_correct_conv.  assumption.  unfold lt in |- *.  trivial.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply Neqb_complete.  assumption.  trivial. elim (Neqb x y). auto. auto.
  Qed.

  Lemma BDDcompare_succ :
   forall a : BDDvar, BDDcompare a (ad_S a) = Datatypes.Lt.
  Proof.
(* Goal: forall a : BDDvar, @eq comparison (BDDcompare a (ad_S a)) Lt *)
    simple induction a.  simpl in |- *.  trivial.  simpl in |- *.  intro p.
(* Goal: forall (_ : @ex nat (fun h : nat => @eq nat (Pos.to_nat p) (S h))) (_ : lt (Pos.to_nat p) O), @eq comparison Gt Lt *)
(* Goal: @ex nat (fun h : nat => @eq nat (Pos.to_nat p) (S h)) *)
(* Goal: forall (p p0 : positive) (_ : lt (N.to_nat (Npos p0)) (N.to_nat (Npos p))), @eq comparison (BDDcompare (Npos p0) (Npos p)) Lt *)
    cut (nat_of_P p < nat_of_P (Psucc p)).  intro H.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply nat_of_P_lt_Lt_compare_complement_morphism.  assumption.
(* Goal: forall (_ : @ex nat (fun h : nat => @eq nat (Pos.to_nat p) (S h))) (_ : lt (Pos.to_nat p) O), @eq comparison Gt Lt *)
(* Goal: @ex nat (fun h : nat => @eq nat (Pos.to_nat p) (S h)) *)
(* Goal: forall (p p0 : positive) (_ : lt (N.to_nat (Npos p0)) (N.to_nat (Npos p))), @eq comparison (BDDcompare (Npos p0) (Npos p)) Lt *)
    cut (nat_of_P (Psucc p) = 1 + nat_of_P p).  intro H.  rewrite H.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    simpl in |- *.  unfold lt in |- *.  trivial.  unfold nat_of_P in |- *.  apply Pmult_nat_succ_morphism.
  Qed.

  Lemma BDDcompare_lt :
   forall x y : BDDvar,
   BDDcompare x y = Datatypes.Lt -> nat_of_N x < nat_of_N y.
  Proof.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    double induction x y.  simpl in |- *.  intro H.  discriminate.  simpl in |- *.  intros p H.
(* Goal: forall _ : @eq positive p0 p, @eq BDDvar (Npos p0) (Npos p) *)
(* Goal: @eq positive p0 p *)
    cut (exists h : nat, nat_of_P p = S h).  intro H0.  inversion H0.  rewrite H1.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
    apply lt_O_Sn.  apply ZL4.  simpl in |- *.  intros p H.  discriminate.  simpl in |- *.  intros p p0 H.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply nat_of_P_lt_Lt_compare_morphism.  assumption.
  Qed.


Lemma BDDlt_compare :
 forall x y : BDDvar,
 nat_of_N x < nat_of_N y -> BDDcompare x y = Datatypes.Lt.
Proof.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  double induction x y.  simpl in |- *.  intro H.  absurd (0 < 0).  apply lt_n_O.  assumption.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  simpl in |- *.  reflexivity.  simpl in |- *.  intro p.  cut (exists h : nat, nat_of_P p = S h).  intro H.
(* Goal: forall _ : lt (Pos.to_nat p) O, @eq comparison Gt Lt *)
(* Goal: @ex nat (fun h : nat => @eq nat (Pos.to_nat p) (S h)) *)
(* Goal: forall (p p0 : positive) (_ : lt (N.to_nat (Npos p0)) (N.to_nat (Npos p))), @eq comparison (BDDcompare (Npos p0) (Npos p)) Lt *)
  inversion H.  rewrite H0.  intro H1.  absurd (S x0 < 0).  apply lt_n_O.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  assumption.  apply ZL4.  simpl in |- *.  intro p.  intros p0 H.  apply nat_of_P_lt_Lt_compare_complement_morphism.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  assumption.
Qed.

Lemma relation_sum :
 forall r : Datatypes.comparison,
 {r = Datatypes.Eq} + {r = Datatypes.Lt} + {r = Datatypes.Gt}.
Proof.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  intro r.  elim r.  left; left; reflexivity.  left; right; reflexivity.  right; reflexivity.
Qed.

Lemma BDD_EGAL_complete :
 forall x y : BDDvar, BDDcompare x y = Datatypes.Eq -> x = y.
Proof.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  double induction x y.  reflexivity.  simpl in |- *.  intros; discriminate.  simpl in |- *.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  intros; discriminate.  simpl in |- *.  intros p p0 H.  cut (p0 = p).  intro H0.  rewrite H0; reflexivity.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  apply Pcompare_Eq_eq.  assumption.
Qed.

  Lemma lt_trans_1 : forall x y z : nat, x < y -> y < S z -> x < z.
  Proof.
(* Goal: lt x z *)
    intros x y z H H0.  unfold lt in H0.  unfold lt in H.  unfold lt in |- *.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply le_trans with (m := y).  assumption.  apply le_S_n.  assumption.
  Qed.

Lemma BDDcompare_sup_inf :
 forall x y : BDDvar,
 BDDcompare x y = Datatypes.Gt -> BDDcompare y x = Datatypes.Lt.
Proof.
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  double induction x y.  simpl in |- *.  intro; discriminate.  simpl in |- *.  intro p.  intro; discriminate.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  simpl in |- *.  reflexivity.  unfold BDDcompare in |- *.  intros p p0 H.  apply ZC1.  assumption.
Qed.

  Lemma BDDcompare_1 :
   forall x y : BDDvar,
   BDDcompare x y = Datatypes.Lt ->
   BDDcompare (ad_S x) y = Datatypes.Lt \/ ad_S x = y.
  Proof.
(* Goal: forall (x y : BDDvar) (_ : @eq comparison (BDDcompare x y) Lt), or (@eq comparison (BDDcompare (ad_S x) y) Lt) (@eq N (ad_S x) y) *)
    intros x y H.  elim (relation_sum (BDDcompare (ad_S x) y)).  intro y0.  elim y0; intro.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    right.  apply BDD_EGAL_complete.  assumption.  left; assumption.  intro y0.
(* Goal: or (@eq comparison (BDDcompare (ad_S x) y) Lt) (@eq N (ad_S x) y) *)
    absurd (nat_of_N x < nat_of_N x).  apply lt_irrefl.  apply lt_trans_1 with (y := nat_of_N y).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply BDDcompare_lt.  assumption.  rewrite <- (ad_S_is_S x).  apply BDDcompare_lt.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
    apply BDDcompare_sup_inf.  assumption.
  Qed.

Definition max (m n : nat) := if leb m n then n else m.

Lemma lt_max_1_2 :
 forall x1 y1 x2 y2 : nat, x1 < x2 -> y1 < y2 -> max x1 y1 < max x2 y2.
Proof.
(* Goal: forall (x1 y1 x2 y2 : nat) (_ : lt x1 x2) (_ : lt y1 x2), lt (max x1 y1) (max x2 y2) *)
  intros x1 y1 x2 y2 H H0.  unfold max in |- *.  elim (sumbool_of_bool (leb x2 y2)).  intro y.  rewrite y.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  elim (leb x1 y1).  assumption.  apply lt_le_trans with (m := x2).  assumption.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  apply leb_complete.  assumption.  intro y.  rewrite y.  elim (leb x1 y1).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  apply lt_trans with (m := y2).  assumption.  apply leb_complete_conv.  assumption.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  assumption.
Qed.

Lemma lt_max_2 :
 forall x1 y1 x2 y2 : nat, x1 < y2 -> y1 < y2 -> max x1 y1 < max x2 y2.
Proof.
(* Goal: forall (x1 y1 x2 y2 : nat) (_ : lt x1 x2) (_ : lt y1 x2), lt (max x1 y1) (max x2 y2) *)
  intros x1 y1 x2 y2 H H0.  unfold max in |- *.  elim (leb x1 y1).  elim (sumbool_of_bool (leb x2 y2)).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  intro y.  rewrite y.  assumption.  intro y.  rewrite y.  apply lt_trans with (m := y2).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  assumption.  apply leb_complete_conv.  assumption.  elim (sumbool_of_bool (leb x2 y2)).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  intro y.  rewrite y.  assumption.  intro y.  rewrite y.  apply lt_trans with (m := y2).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  assumption.  apply leb_complete_conv.  assumption.
Qed.

Lemma lt_max_12 :
 forall x1 y1 x2 y2 : nat, x1 < x2 -> y1 < x2 -> max x1 y1 < max x2 y2.
Proof.
(* Goal: forall (x1 y1 x2 y2 : nat) (_ : lt x1 x2) (_ : lt y1 x2), lt (max x1 y1) (max x2 y2) *)
  intros x1 y1 x2 y2 H H0.  unfold max in |- *.  elim (leb x1 y1).  elim (sumbool_of_bool (leb x2 y2)); intro y; rewrite y.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  apply lt_le_trans with (m := x2).  assumption.  apply leb_complete; assumption.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  assumption.  elim (sumbool_of_bool (leb x2 y2)).  intro y.  rewrite y.  apply lt_le_trans with (m := x2).
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  assumption.  apply leb_complete; assumption.  intro y; rewrite y.  assumption.
Qed.

Lemma BDDcompare_eq :
 forall x y : BDDvar, BDDcompare x y = Datatypes.Eq -> x = y.
Proof.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  double induction x y.  reflexivity.  simpl in |- *.  intros; discriminate.  simpl in |- *.
(* Goal: forall _ : @eq comparison (BDDcompare N0 N0) Eq, @eq BDDvar N0 N0 *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare N0 (Npos p)) Eq), @eq BDDvar N0 (Npos p) *)
(* Goal: forall (p : positive) (_ : @eq comparison (BDDcompare (Npos p) N0) Eq), @eq BDDvar (Npos p) N0 *)
(* Goal: forall (p p0 : positive) (_ : @eq comparison (BDDcompare (Npos p0) (Npos p)) Eq), @eq BDDvar (Npos p0) (Npos p) *)
  intros; discriminate.  simpl in |- *.  intros p p0 H.  cut (p0 = p).  intro H0.  rewrite H0; reflexivity.
(* Goal: @eq comparison (Pos.compare_cont Eq p0 p) Eq *)
  apply Pcompare_Eq_eq.  assumption.
Qed.
