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



(*s Decision procedure for arithmetic formulas by looking 
    for negative cycles in  a graph *)

Require Import NArith.
Require Import Ndigits.
Require Import Ndec.
From IntMap Require Import Allmaps.
Require Import Arith.
Require Import ZArith.
Require Import Bool.
Require Import Sumbool.
Require Import List.
Require Import Wf_nat.

Unset Standard Proposition Elimination Names.

Section ConstraintGraphs.

(*s Axiomatisation of the domain of interpretation [D] *)

  Variable D : Set.  

  Variable Dz : D.
  Variable Dplus : D -> D -> D.
  Variable Dneg : D -> D.
  Variable Dle : D -> D -> bool.

  Variable Dplus_d_z : forall d : D, Dplus d Dz = d.
  Variable Dplus_z_d : forall d : D, Dplus Dz d = d.
  Variable
    Dplus_assoc :
      forall d d' d'' : D, Dplus (Dplus d d') d'' = Dplus d (Dplus d' d'').

  Variable Dplus_neg : forall d : D, Dplus d (Dneg d) = Dz.

  Variable Dle_refl : forall d : D, Dle d d = true.
  Variable
    Dle_antisym :
      forall d d' : D, Dle d d' = true -> Dle d' d = true -> d = d'.
  Variable
    Dle_trans :
      forall d d' d'' : D,
      Dle d d' = true -> Dle d' d'' = true -> Dle d d'' = true.
  Variable Dle_total : forall d d' : D, {Dle d d' = true} + {Dle d' d = true}.

  Variable
    Dle_plus_mono :
      forall d d' d'' d''' : D,
      Dle d d' = true ->
      Dle d'' d''' = true -> Dle (Dplus d d'') (Dplus d' d''') = true.

(*s Properties of [Dle] *)

Lemma Dle_true_permut :
 forall d d' : D, Dle d d' = true -> {Dle d' d = false} + {d = d'}.
(* Goal: forall (d d' : D) (_ : @eq bool (Dle d d') true), sumbool (@eq bool (Dle d' d) false) (@eq D d d') *)
  intros; case (sumbool_of_bool (Dle d' d)); intro; auto.
  Qed.

(*s Definition of the minimum function *)

Definition Dmin (d d' : D) := if Dle d d' then d else d'.

Lemma Dle_true_Dmin : forall d d' : D, Dle d d' = true -> Dmin d d' = d.
(* Goal: forall (d d' : D) (_ : @eq bool (Dle d d') true), @eq D (Dmin d d') d *)
  unfold Dmin in |- *; intros d d' H; rewrite H; trivial.
  Qed.

Lemma Dle_inv_Dmin : forall d d' : D, Dle d' d = true -> Dmin d d' = d'.
(* Goal: forall (d d' : D) (_ : @eq bool (Dle d' d) true), @eq D (Dmin d d') d' *)
  unfold Dmin in |- *; intros d d' H.
(* Goal: @eq D (if Dle d d' then d else d') d' *)
  case (sumbool_of_bool (Dle d d')); intro H'; rewrite H'; auto.
  Qed.

Hint Resolve Dle_true_Dmin Dle_inv_Dmin.

Lemma Dmin_idempotent : forall d : D, Dmin d d = d.
  Proof.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    auto.
  Qed.

Lemma Dmin_comm : forall d d' : D, Dmin d d' = Dmin d' d.
  Proof.
(* Goal: forall d d' : D, @eq D (Dmin d d') (Dmin d' d) *)
    intros d d'; case (Dle_total d d'); intro H. 
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
(* Goal: @eq D d' (Dmin d d') *)
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H); trivial.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
(* Goal: @eq D d' (Dmin d d') *)
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H); trivial.
  Qed.

Lemma Dmin_assoc :
 forall d d' d'' : D, Dmin (Dmin d d') d'' = Dmin d (Dmin d' d'').
  Proof.
(* Goal: forall d d' d'' : D, @eq D (Dplus d'' (Dmin d d')) (Dmin (Dplus d'' d) (Dplus d'' d')) *)
    intros d d' d''; case (Dle_total d d'); intro H.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    case (Dle_total d' d''); intro H'.
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H').
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite (Dle_true_Dmin d d''); eauto.
(* Goal: @eq D (Dmin d d'') (Dmin d (Dmin d' d'')) *)
(* Goal: @eq D (Dmin (Dmin d d') d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H'); trivial.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H).
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    case (Dle_total d' d''); intro H'.
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H').
(* Goal: @eq D d' (Dmin d d') *)
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H); trivial.
(* Goal: @eq D (Dmin d' d'') (Dmin d (Dmin d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H').
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite (Dle_inv_Dmin d d''); eauto.
Qed.

Lemma Dmin_le_1 : forall d d' : D, Dle (Dmin d d') d = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. case (Dle_total d d'); intro H.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite Dle_true_Dmin with (1 := H); auto.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite Dle_inv_Dmin with (1 := H); auto.
  Qed.

Lemma Dmin_le_2 : forall d d' : D, Dle (Dmin d d') d' = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite (Dmin_comm d d'). apply Dmin_le_1.
  Qed.

Lemma Dmin_le_3 :
 forall d d' d'' : D, Dle d (Dmin d' d'') = true -> Dle d d' = true.
  Proof.
(* Goal: forall (d d' d'' : D) (_ : @eq bool (Dle d (Dmin d' d'')) true), @eq bool (Dle d d') true *)
    intros d d' d''; elim (Dle_total d' d''); intro H0.
(* Goal: forall _ : @eq bool (Dle d (Dmin d' d'')) true, @eq bool (Dle d d') true *)
(* Goal: forall _ : @eq bool (Dle d (Dmin d' d'')) true, @eq bool (Dle d d') true *)
    rewrite Dle_true_Dmin with (1 := H0); trivial.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite Dle_inv_Dmin with (1 := H0); eauto.
  Qed.

Lemma Dmin_le_4 :
 forall d d' d'' : D, Dle d (Dmin d' d'') = true -> Dle d d'' = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite (Dmin_comm d' d'') in H. exact (Dmin_le_3 _ _ _ H).
  Qed.

Lemma Dmin_le_5 :
 forall d d' d'' : D,
 Dle d d' = true -> Dle d d'' = true -> Dle d (Dmin d' d'') = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. unfold Dmin in |- *. case (Dle d' d''); assumption.
  Qed.

(*s Properties of [Dneg] *)

Lemma Dneg_Dz : Dneg Dz = Dz.
  Proof.
(* Goal: @eq D (Dneg Dz) Dz *)
    rewrite <- (Dplus_z_d (Dneg Dz)). apply Dplus_neg.
  Qed.

Lemma Dneg_neg : forall d : D, Dneg (Dneg d) = d.
  Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. rewrite <- (Dplus_z_d (Dneg (Dneg d))). rewrite <- (Dplus_neg d).
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    rewrite Dplus_assoc. rewrite Dplus_neg. apply Dplus_d_z.
  Qed.

Lemma Dplus_neg_2 : forall d : D, Dplus (Dneg d) d = Dz.
  Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. cut (Dplus (Dneg d) (Dneg (Dneg d)) = Dz). rewrite Dneg_neg. trivial.
(* Goal: @eq D (Dplus d (Dneg d)) Dz *)
    apply Dplus_neg.
  Qed.

(*s Properties of [Dplus] *)

Lemma Dplus_reg_l :
 forall d d' d'' : D,
 Dle (Dplus d'' d) (Dplus d'' d') = true -> Dle d d' = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite <- (Dplus_z_d d). rewrite <- (Dplus_z_d d'). rewrite <- (Dplus_neg_2 d'').
(* Goal: @eq bool (Dle (Dplus (Dplus (Dneg d'') d'') d) (Dplus (Dplus (Dneg d'') d'') d')) true *)
    rewrite (Dplus_assoc (Dneg d'') d'' d). rewrite (Dplus_assoc (Dneg d'') d'' d').
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    apply Dle_plus_mono. apply Dle_refl.
(* Goal: CGeval rho f *)
    assumption.
  Qed.

Lemma Dplus_reg_r :
 forall d d' d'' : D,
 Dle (Dplus d d'') (Dplus d' d'') = true -> Dle d d' = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite <- (Dplus_d_z d). rewrite <- (Dplus_d_z d'). rewrite <- (Dplus_neg d'').
(* Goal: @eq bool (Dle (Dplus d (Dplus d'' (Dneg d''))) (Dplus d' (Dplus d'' (Dneg d'')))) true *)
    rewrite <- (Dplus_assoc d d'' (Dneg d'')). rewrite <- (Dplus_assoc d' d'' (Dneg d'')).
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    apply Dle_plus_mono. assumption.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    apply Dle_refl.
  Qed.

Lemma Dmin_plus_l :
 forall d d' d'' : D,
 Dplus (Dmin d d') d'' = Dmin (Dplus d d'') (Dplus d' d'').
  Proof.
(* Goal: forall d d' d'' : D, @eq D (Dplus d'' (Dmin d d')) (Dmin (Dplus d'' d) (Dplus d'' d')) *)
    intros d d' d''; case (Dle_total d d'); intro H.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite (Dle_true_Dmin (Dplus d d'')); auto.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H).
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite (Dle_inv_Dmin (Dplus d d'')); auto.
  Qed.

Lemma Dmin_plus_r :
 forall d d' d'' : D,
 Dplus d'' (Dmin d d') = Dmin (Dplus d'' d) (Dplus d'' d').
  Proof.
(* Goal: forall d d' d'' : D, @eq D (Dplus d'' (Dmin d d')) (Dmin (Dplus d'' d) (Dplus d'' d')) *)
   intros d d' d''; case (Dle_total d d'); intro H.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite (Dle_true_Dmin (Dplus d'' d)); auto.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H).
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite (Dle_inv_Dmin (Dplus d'' d)); auto.
  Qed.

Lemma Dle_neg : forall d : D, Dle Dz d = true -> Dle (Dneg d) Dz = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. cut (Dle (Dplus Dz (Dneg d)) (Dplus d (Dneg d)) = true). intro.
(* Goal: CGeval rho f *)
    rewrite (Dplus_z_d (Dneg d)) in H0. rewrite (Dplus_neg d) in H0. assumption.
(* Goal: @eq bool (Dle (Dplus d (Dneg d')) (Dplus d' (Dneg d'))) true *)
    exact (Dle_plus_mono _ _ _ _ H (Dle_refl _)).
  Qed.

Lemma Dle_neg_2 : forall d : D, Dle d Dz = true -> Dle Dz (Dneg d) = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. cut (Dle (Dplus d (Dneg d)) (Dplus Dz (Dneg d)) = true). intro.
(* Goal: CGeval rho f *)
    rewrite (Dplus_neg d) in H0. rewrite (Dplus_z_d (Dneg d)) in H0. assumption.
(* Goal: @eq bool (Dle (Dplus d (Dneg d')) (Dplus d' (Dneg d'))) true *)
    exact (Dle_plus_mono _ _ _ _ H (Dle_refl _)).
  Qed.
 
Lemma Dnotle_not_eq : forall d d' : D, Dle d d' = false -> d <> d'.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
  red in |- *; intros.
(* Goal: False *)
  apply diff_true_false.
(* Goal: False *)
  rewrite H0 in H.  
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
  rewrite (Dle_refl d') in H; trivial.
  Qed.

Hint Immediate Dnotle_not_eq.

Lemma Dnotle_not_eq_sym : forall d d' : D, Dle d d' = false -> d' <> d.
  Proof.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    intros; apply sym_not_eq; auto.
  Qed.

Hint Immediate Dnotle_not_eq_sym.

(*s Equality on [D] is decidable *)

Lemma D_dec : forall d d' : D, {d = d'} + {d <> d'}.
  Proof.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    intros d d'; case (sumbool_of_bool (Dle d d')); intro H; auto. 
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    case (sumbool_of_bool (Dle d' d)); intro H0; auto.
  Qed.

Lemma Dnotle_3_cases :
 forall d d' : D, {Dle d d' = false} + {d = d'} + {Dle d' d = false}.
  Proof.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
   intros d d'; case (sumbool_of_bool (Dle d d')); intro H; auto. 
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    case (sumbool_of_bool (Dle d' d)); intro H0; auto.
  Qed.

Lemma Dle_noteq_notle :
 forall d d' : D, Dle d' d = true -> d <> d' -> Dle d d' = false.
  Proof.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    intros d d'; case (sumbool_of_bool (Dle d d')); intro H; auto. 
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    intros; absurd (d = d'); auto.
  Qed.

Lemma Dnotle_not_refl : forall d : D, Dle d d <> false.
  Proof.
(* Goal: forall d : D, not (@eq bool (Dle d d) false) *)
    red in |- *; intro; rewrite (Dle_refl d).
(* Goal: forall _ : @eq bool true false, False *)
    exact diff_true_false.
  Qed.


Lemma Dnotle_elim :
 forall d d' : D, Dle d' d = false -> Dle d d' = true /\ d <> d'.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
  intros.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
  case (Dle_total d d'); intro H'; auto.
(* Goal: and (@eq bool (Dle d d') true) (not (@eq D d d')) *)
  case diff_true_false.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
  rewrite <- H'; trivial.
Qed.  

Lemma Dnotle_trans :
 forall d d' d'' : D,
 Dle d d' = false -> Dle d' d'' = false -> Dle d d'' = false.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
   intros.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
   case Dnotle_elim with (1 := H); intros.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
   case Dnotle_elim with (1 := H0); intros.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
   apply Dle_noteq_notle; eauto.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
   red in |- *; intros.
(* Goal: False *)
   apply diff_false_true.
(* Goal: @eq bool (Ddle (CG_edge cg2 x0 y0) (@Some D d0)) true *)
   rewrite <- H0.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
   rewrite <- H5; trivial.
   Qed.

Lemma Dnotle_le_1 : forall d d' : D, Dle d d' = false -> Dle d' d = true.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intros; case Dnotle_elim with (1 := H); trivial.
  Qed.

Lemma Dmin_le_distr_l :
 forall d d' d'' : D, Dle (Dmin d d') d'' = Dle d d'' || Dle d' d''.
  Proof.
(* Goal: @eq bool (Dle (Dmin d d') d) true *)
    intros; case (Dle_total d d'); intro H.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_true_Dmin with (1 := H).
    pattern (Dle d d'') in |- *; apply bool_eq_ind; intro H'; simpl in |- *;
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
     trivial.
    pattern (Dle d' d'') in |- *; apply bool_eq_ind; intro H''; simpl in |- *;
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
     trivial.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite <- H'; eauto.
(* Goal: @eq bool (Dle (Dmin d d') d'') (orb (Dle d d'') (Dle d' d'')) *)
    rewrite Dle_inv_Dmin with (1 := H).
    pattern (Dle d d'') in |- *; apply bool_eq_ind; intro H'; simpl in |- *;
(* Goal: forall d : D, @eq D (Dmin d d) d *)
     eauto.
    Qed.

Lemma Dmin_choice : forall d d' : D, {Dmin d d' = d} + {Dmin d d' = d'}.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold Dmin in |- *. intros. elim (sumbool_of_bool (Dle d d')). intro H. left. rewrite H. reflexivity.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H. right. rewrite H. reflexivity.
  Qed.

Lemma Dnotle_noteq : forall d d' : D, Dle d d' = false -> d <> d'.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold not in |- *. intros. rewrite H0 in H. rewrite (Dle_refl d') in H. discriminate H.
  Qed.

Lemma Dneg_plus :
 forall d d' : D, Dneg (Dplus d d') = Dplus (Dneg d') (Dneg d).
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. cut (Dplus (Dplus d d') (Dplus (Dneg d') (Dneg d)) = Dz). intro.
(* Goal: @eq D (Dneg (Dplus d d')) (Dplus (Dneg d') (Dneg d)) *)
(* Goal: @eq D (Dplus (Dplus d d') (Dplus (Dneg d') (Dneg d))) Dz *)
    rewrite <- (Dplus_d_z (Dneg (Dplus d d'))). rewrite <- H. rewrite <- Dplus_assoc.
(* Goal: @eq bool (negb false) true *)
    rewrite Dplus_neg_2. rewrite Dplus_z_d. reflexivity.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    rewrite Dplus_assoc. rewrite <- (Dplus_assoc d' (Dneg d') (Dneg d)). rewrite Dplus_neg.
(* Goal: @eq D (Dplus d (Dneg d)) Dz *)
    rewrite Dplus_z_d. apply Dplus_neg.
  Qed.

Lemma Dneg_le :
 forall d d' : D, Dle d d' = true -> Dle (Dneg d') (Dneg d) = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply Dplus_reg_l with (d'' := d'). rewrite Dplus_neg. rewrite <- (Dneg_neg d').
(* Goal: @eq bool (Dle (rho a) (Dplus (rho a) (Dplus (Dplus (Dneg Done) (Dneg d)) d))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    rewrite <- Dneg_plus. apply Dle_neg_2. rewrite <- (Dplus_neg d').
(* Goal: @eq bool (Dle (Dplus d (Dneg d')) (Dplus d' (Dneg d'))) true *)
    exact (Dle_plus_mono _ _ _ _ H (Dle_refl _)).
  Qed.

Lemma Dnotle_plus_mono_1 :
 forall d d' d'' d''' : D,
 Dle d' d = true ->
 Dle d'' d''' = false -> Dle (Dplus d d'') (Dplus d' d''') = false.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply Dle_noteq_notle. apply Dle_plus_mono. assumption.
(* Goal: CGeval rho f *)
    apply Dnotle_le_1. assumption.
(* Goal: not (CGSeval rho (CGSnot (CGFormSimplify f))) *)
    unfold not in |- *. intro H1.
    cut
     (Dle (Dplus (Dneg d) (Dplus d d'')) (Dplus (Dneg d') (Dplus d' d''')) =
      true).
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg Done)) (Dplus (Dneg d) d))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    rewrite <- (Dplus_assoc (Dneg d) d d''). rewrite Dplus_neg_2. rewrite Dplus_z_d.
(* Goal: @eq bool (Dle (rho a0) (Dplus (rho a) (Dplus (Dneg Done) (Dneg d)))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    rewrite <- Dplus_assoc. rewrite Dplus_neg_2. rewrite Dplus_z_d. rewrite H0.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    intro H2. discriminate H2.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    apply Dle_plus_mono. apply Dneg_le. assumption.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    rewrite H1. apply Dle_refl.
  Qed.

Lemma Dnotle_plus_mono :
 forall d d' d'' d''' : D,
 Dle d d' = false ->
 Dle d'' d''' = false -> Dle (Dplus d d'') (Dplus d' d''') = false.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply Dnotle_plus_mono_1; try assumption. apply Dnotle_le_1; assumption.
  Qed.

(*s Extending D with an element None representing infinity *)

Definition Ddmin (dd dd' : option D) :=
  match dd, dd' with
  | None, _ => dd'
  | _, None => dd
  | Some d, Some d' => Some (Dmin d d')
  end.

Lemma Ddmin_idempotent : forall dd : option D, Ddmin dd dd = dd.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction dd; trivial.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. simpl in |- *. rewrite Dmin_idempotent. reflexivity.
  Qed.

Lemma Ddmin_comm : forall dd dd' : option D, Ddmin dd dd' = Ddmin dd' dd.
  Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    simple induction dd. Focus 2. intro. case dd'; reflexivity.
(* Goal: @eq bool (negb false) true *)
    intro d. simple induction dd'. Focus 2. reflexivity.
(* Goal: @eq bool (negb false) true *)
    intro d'. simpl in |- *. rewrite Dmin_comm. reflexivity.
  Qed.

Lemma Ddmin_assoc :
 forall dd dd' dd'' : option D,
 Ddmin (Ddmin dd dd') dd'' = Ddmin dd (Ddmin dd' dd'').
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. case dd. simpl in |- *. case dd'. simpl in |- *. case dd''.
(* Goal: forall d d0 d1 : D, @eq (option D) (@Some D (Dmin (Dmin d1 d0) d)) (@Some D (Dmin d1 (Dmin d0 d))) *)
(* Goal: forall d d0 : D, @eq (option D) (@Some D (Dmin d0 d)) (@Some D (Dmin d0 d)) *)
(* Goal: forall d : D, @eq (option D) (Ddmin (@Some D d) dd'') match Ddmin (@None D) dd'' with | Some d' => @Some D (Dmin d d') | None => @Some D d end *)
(* Goal: @eq (option D) (Ddmin (Ddmin (@None D) dd') dd'') (Ddmin (@None D) (Ddmin dd' dd'')) *)
    intros; rewrite Dmin_assoc. 
(* Goal: @eq bool (negb false) true *)
    reflexivity.
(* Goal: @eq bool (negb false) true *)
    intros; reflexivity.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. simpl in |- *. case dd''; reflexivity.
(* Goal: @eq bool (negb false) true *)
    simpl in *; reflexivity.
  Qed.

(*s The order [Dle] extended to $D_{\infty}$ *)
Definition Ddle (dd dd' : option D) :=
  match dd, dd' with
  | _, None => true
  | None, _ => false
  | Some d, Some d' => Dle d d'
  end.

Lemma Ddle_refl : forall dd : option D, Ddle dd dd = true.
  Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. case dd; try reflexivity.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. exact (Dle_refl d).
  Qed.

Lemma Ddle_antisym :
 forall dd dd' : option D,
 Ddle dd dd' = true -> Ddle dd' dd = true -> dd = dd'.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intros dd dd'. case dd. Focus 2. case dd'. Focus 2. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. discriminate H.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    case dd'. Focus 2. intros. discriminate H0.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite (Dle_antisym _ _ H0 H). reflexivity.
  Qed.

Lemma Ddle_trans :
 forall dd dd' dd'' : option D,
 Ddle dd dd' = true -> Ddle dd' dd'' = true -> Ddle dd dd'' = true.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intros dd dd' dd''. case dd''. Focus 2. case dd; trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intro d''. case dd'. Focus 2. intros. discriminate H0.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro d'. case dd. Focus 2. intro. discriminate H.
    intros d H H0. exact (Dle_trans _ _ _ H H0).
  Qed.

Lemma Ddle_d_none : forall dd : option D, Ddle dd None = true.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction dd; trivial.
  Qed.

Lemma Ddmin_le_1 : forall dd dd' : option D, Ddle (Ddmin dd dd') dd = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. case dd. Focus 2. case dd'; reflexivity.
    intro d. case dd'. Focus 2. apply Ddle_refl.
    exact (Dmin_le_1 d).
  Qed.

Lemma Ddmin_le_2 : forall dd dd' : option D, Ddle (Ddmin dd dd') dd' = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite (Ddmin_comm dd dd'). apply Ddmin_le_1.
  Qed.

Lemma Ddmin_le_3 :
 forall dd dd' dd'' : option D,
 Ddle dd (Ddmin dd' dd'') = true -> Ddle dd dd' = true.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intros dd dd' dd''. case dd'. Focus 2. case dd; trivial.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro d'. case dd. Focus 2. case dd''. Focus 2. intro. discriminate H.
(* Goal: False *)
    intros d'' H. discriminate H.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d. case dd''. Focus 2. trivial.
    exact (Dmin_le_3 d d').
  Qed.

Lemma Ddmin_le_4 :
 forall dd dd' dd'' : option D,
 Ddle dd (Ddmin dd' dd'') = true -> Ddle dd dd'' = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite (Ddmin_comm dd' dd'') in H. exact (Ddmin_le_3 _ _ _ H).
  Qed.

Lemma Ddmin_le_distr_l :
 forall dd dd' dd'' : option D,
 Ddle (Ddmin dd dd') dd'' = Ddle dd dd'' || Ddle dd' dd''.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction dd. Focus 2. simple induction dd'. Focus 2. simple induction dd''; trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d. simple induction dd''; trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d. simple induction dd'. Focus 2. simple induction dd''; trivial.
(* Goal: @eq bool (negb false) true *)
    simpl in |- *. intro d'. rewrite orb_b_false. reflexivity.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d'. simple induction dd''; trivial. simpl in |- *. exact (Dmin_le_distr_l d d').
  Qed.

Lemma Ddmin_choice :
 forall dd dd' : option D, {Ddmin dd dd' = dd} + {Ddmin dd dd' = dd'}.
  Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    simple induction dd. Focus 2. intro. right. simpl in |- *. case dd'; reflexivity.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro d. simple induction dd'. Focus 2. left. reflexivity.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro d'. simpl in |- *. elim (Dmin_choice d d'). intro H. left. rewrite H. reflexivity.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H. right. rewrite H. reflexivity.
  Qed.

(*s Operation [Ddplus] on $D_{\infty}$ *)

Definition Ddplus (dd : option D) (d' : D) :=
  match dd with
  | Some d => Some (Dplus d d')
  | _ => dd
  end.

Lemma Ddmin_plus_l :
 forall (dd dd' : option D) (d'' : D),
 Ddplus (Ddmin dd dd') d'' = Ddmin (Ddplus dd d'') (Ddplus dd' d'').
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction dd. Focus 2. simple induction dd'. Focus 2. trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d. simple induction dd'. Focus 2. trivial.
(* Goal: @eq bool (negb false) true *)
    intros d' d''. simpl in |- *. rewrite Dmin_plus_l. reflexivity.
  Qed.

Lemma Ddle_plus_mono :
 forall (dd dd' : option D) (d d' : D),
 Ddle dd dd' = true ->
 Dle d d' = true -> Ddle (Ddplus dd d) (Ddplus dd' d') = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simple induction dd. Focus 2. simple induction dd'. Focus 2. intros. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d0. simple induction dd'. Focus 2. trivial.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    simpl in |- *. exact (Dle_plus_mono d0).
  Qed.

Lemma Ddplus_reg_r :
 forall (dd dd' : option D) (d'' : D),
 Ddle (Ddplus dd d'') (Ddplus dd' d'') = true -> Ddle dd dd' = true.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction dd. Focus 2. simple induction dd'. Focus 2. trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simpl in |- *. trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intro d. simple induction dd'. Focus 2. trivial.
    intros d' d'' H. exact (Dplus_reg_r d d' d'' H).
  Qed.

(*s Introducing graphs of objects in [D] *)

Definition CGraph1 := Map (Map D).

Definition CGraph := option CGraph1.

Section CGDist.

    Variable cg : CGraph1.

Definition CG_edge (x y : ad) :=
  match MapGet _ cg x with
  | Some edges =>
      match MapGet _ edges y with
      | Some d => Some d
      | _ => None
      end
  | _ => None
  end.

(*s Let $\rho$ be an interpretation of adresses as elements in [D], 
    the graph [cg] is satisfied by $\rho$ if for any edge 
    from $x$ to $y$ indexed by $d$, we have $\rho(x) \leq \rho(y)+d$
   A graph is consistent if there exists an interpretation which satisfies it.
*)

Definition CGsat (rho : ad -> D) :=
  forall (x y : ad) (d : D),
  CG_edge x y = Some d -> Dle (rho x) (Dplus (rho y) d) = true.


Definition CGconsistent := sig CGsat. 

(* [CG_path last d l] if there exists a path starting from [last] with successive 
   vertexes $l=[x0;...;xn]$ $(xn=last)$ and [d] is the sum of the weights on the 
   edges *)

Inductive CG_path (last : ad) : D -> list ad -> Set :=
  | CG_p1 : forall x : ad, x = last -> CG_path last Dz (x :: nil)
  | CG_p2 :
      forall (x y : ad) (l : list ad) (d : D),
      CG_path last d (y :: l) ->
      forall d' : D,
      CG_edge x y = Some d' -> CG_path last (Dplus d d') (x :: y :: l).

(* If $\rho$ satisfies the graph and there is a path from [last] to [x] of 
   weight d then $\rho(x) \leq \rho(last)+d$
*)

Definition first (l : list ad) : ad :=
  match l with
  | nil => N0
  | x :: _ => x
  end.

Lemma CG_path_head :
 forall (l : list ad) (last : ad) (d : D),
 CG_path last d l ->
 forall rho : ad -> D,
 CGsat rho -> Dle (rho (first l)) (Dplus (rho last) d) = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros; elim H; simpl in |- *; intros.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite e; rewrite Dplus_d_z; auto.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    apply Dle_trans with (Dplus (rho y) d'); auto.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
    rewrite <- Dplus_assoc; auto.
    Qed.

Lemma CG_path_correct :
 forall (l : list ad) (x last : ad) (d : D),
 CG_path last d (x :: l) ->
 forall rho : ad -> D, CGsat rho -> Dle (rho x) (Dplus (rho last) d) = true.
    Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    intros; apply (CG_path_head (x :: l) last d); trivial.
    Qed.

(*s If there is a circuit [(cons x l)] with negative weight [d], then [cg] is inconsistent: *)

Theorem CG_circuit_correct :
 forall (x : ad) (d : D) (l : list ad),
 CG_path x d (x :: l) -> Dle Dz d = false -> CGconsistent -> False.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold CGconsistent in H1. elim H1. intros rho H2.
(* Goal: False *)
      cut (Dle (Dplus (rho x) Dz) (Dplus (rho x) d) = true). intro H3.
(* Goal: @eq bool (Dle d (Dplus d (Dneg Done))) false *)
(* Goal: @eq bool (Dle Dz (Dneg Done)) true *)
(* Goal: forall _ : @eq bool (Dle d (Dplus d (Dneg Done))) false, @eq bool (Dle d (Dplus d (Dneg Done))) false *)
      rewrite (Dplus_reg_l _ _ _ H3) in H0. discriminate H0.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg Done)) Dz)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      rewrite Dplus_d_z. exact (CG_path_correct l x x d H rho H2).
    Qed.

Section CGConsistent.

      Variable P : CGconsistent.

(*s Assuming that [cg] is consistent, we can build a distance d(x,y) as follows:
      	 d(x,y) is the length of the shortest path from x to y (or +infty if none). *)

Lemma CG_circuits_non_negative_weight :
 forall (x : ad) (d : D) (l : list ad),
 CG_path x d (x :: l) -> Dle Dz d = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (sumbool_of_bool (Dle Dz d)). trivial.
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intro H0. elim (CG_circuit_correct x d l H H0 P).
      Qed.

End CGConsistent.

(*s We assume that any cycle has a positive weight *)

Section CGNoBadCycles.

      Variable
        no_bad_cycles :
          forall (x : ad) (d : D) (l : list ad),
          CG_path x d (x :: l) -> Dle Dz d = true.

(*s The edges are in the domain of the graph *)

Lemma CG_edge_in_cg_1 :
 forall (x y : ad) (d : D),
 CG_edge x y = Some d -> in_FSet x (MapDom _ cg) = true.
      Proof.
(* Goal: forall (x y : ad) (d : D) (_ : @eq (option D) (CG_edge (M0 (Map D)) x y) (@Some D d)), @eq bool (Dle Dz (Dplus Dz d)) true *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
      	unfold CG_edge in |- *. intros x y d. 
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	elim (option_sum _ (MapGet (Map D) cg x)). intro H.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	elim H. intros edges H0. rewrite H0. intros. 
(* Goal: @eq bool (in_FSet x (MapDom (Map D) cg)) true *)
(* Goal: forall (_ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D))) (_ : @eq (option D) match MapGet (Map D) cg x with | Some edges => match MapGet D edges y with | Some d => @Some D d | None => @None D end | None => @None D end (@Some D d)), @eq bool (in_FSet x (MapDom (Map D) cg)) true *)
	exact (MapDom_semantics_1 _ cg x edges H0).
(* Goal: @eq bool (Dle d (Dplus d (Dneg Done))) false *)
(* Goal: @eq bool (Dle Dz (Dneg Done)) true *)
(* Goal: forall _ : @eq bool (Dle d (Dplus d (Dneg Done))) false, @eq bool (Dle d (Dplus d (Dneg Done))) false *)
	intros H H0. rewrite H in H0. discriminate H0.
      Qed.


(*s The elements of a path are in the domain of the graph extended with 
    the last element *)
Lemma CG_path_in_cg_1 :
 forall (l : list ad) (last : ad) (d : D),
 CG_path last d l -> MapSubset _ _ (Elems l) (MapPut _ (MapDom _ cg) last tt).
      Proof.
      
(* Goal: forall (l : list ad) (last : ad) (d : D) (_ : CG_path last d l), MapSubset unit unit (Elems l) (MapPut unit (MapDom (Map D) cg) last tt) *)
      	simple induction 1.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
        unfold MapSubset in |- *; unfold Elems in |- *; simpl in |- *; intros.
(* Goal: @eq bool (in_dom unit a (MapPut unit (MapDom (Map D) cg) last tt)) true *)
(* Goal: forall (x y : ad) (l : list ad) (d : D) (_ : CG_path last d (@cons ad y l)) (_ : MapSubset unit unit (Elems (@cons ad y l)) (MapPut unit (MapDom (Map D) cg) last tt)) (d' : D) (_ : @eq (option D) (CG_edge x y) (@Some D d')), MapSubset unit unit (Elems (@cons ad x (@cons ad y l))) (MapPut unit (MapDom (Map D) cg) last tt) *)
        rewrite in_dom_put.
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
(* Goal: forall (x y : ad) (l : list ad) (d : D) (_ : CG_path last d (@cons ad y l)) (_ : MapSubset unit unit (Elems (@cons ad y l)) (MapPut unit (MapDom (Map D) cg) last tt)) (d' : D) (_ : @eq (option D) (CG_edge x y) (@Some D d')), MapSubset unit unit (Elems (@cons ad x (@cons ad y l))) (MapPut unit (MapDom (Map D) cg) last tt) *)
        rewrite in_dom_M1 in H0.
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
(* Goal: forall (x y : ad) (l : list ad) (d : D) (_ : CG_path last d (@cons ad y l)) (_ : MapSubset unit unit (Elems (@cons ad y l)) (MapPut unit (MapDom (Map D) cg) last tt)) (d' : D) (_ : @eq (option D) (CG_edge x y) (@Some D d')), MapSubset unit unit (Elems (@cons ad x (@cons ad y l))) (MapPut unit (MapDom (Map D) cg) last tt) *)
        rewrite <- e.
(* Goal: @eq bool (orb (N.eqb a x) (in_dom unit a (MapDom (Map D) cg))) true *)
(* Goal: forall (x y : ad) (l : list ad) (d : D) (_ : CG_path last d (@cons ad y l)) (_ : MapSubset unit unit (Elems (@cons ad y l)) (MapPut unit (MapDom (Map D) cg) last tt)) (d' : D) (_ : @eq (option D) (CG_edge x y) (@Some D d')), MapSubset unit unit (Elems (@cons ad x (@cons ad y l))) (MapPut unit (MapDom (Map D) cg) last tt) *)
        rewrite (Neqb_comm a x).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        rewrite H0; simpl in |- *; trivial.
(* Goal: MapSubset unit unit (M0 unit) (MapDom (Map D) cg) *)
(* Goal: le (MapCard (Map D) cg) (Init.Nat.add (Init.Nat.add n0 (MapCard (Map D) cg)) (MapCard unit (M0 unit))) *)
        unfold MapSubset in |- *.
(* Goal: @eq bool (in_dom unit a (MapPut unit (MapDom (Map D) cg) last tt)) true *)
(* Goal: forall (x y : ad) (l : list ad) (d : D) (_ : CG_path last d (@cons ad y l)) (_ : MapSubset unit unit (Elems (@cons ad y l)) (MapPut unit (MapDom (Map D) cg) last tt)) (d' : D) (_ : @eq (option D) (CG_edge x y) (@Some D d')), MapSubset unit unit (Elems (@cons ad x (@cons ad y l))) (MapPut unit (MapDom (Map D) cg) last tt) *)
        intros; rewrite in_dom_put.
        change (in_dom unit a (MapPut unit (Elems (y :: l0)) x tt) = true)
         in H1.
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
        rewrite in_dom_put in H1.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
        case orb_prop with (1 := H1); intro.
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
      	rewrite (Neqb_complete _ _ H2).
(* Goal: @eq bool (orb (N.eqb x last) (in_dom unit x (MapDom (Map D) cg))) true *)
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
        change (Neqb x last || in_FSet x (MapDom (Map D) cg) = true) in |- *.
(* Goal: @eq bool (orb (N.eqb x last) (in_FSet x (MapDom (Map D) cg))) true *)
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
	rewrite CG_edge_in_cg_1 with (1 := e); auto with bool.
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
        set (H3 := H0 a H2) in *.
(* Goal: @eq bool (orb (N.eqb a last) (in_dom unit a (MapDom (Map D) cg))) true *)
	rewrite in_dom_put in H3.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	trivial.
Qed.

Lemma CG_path_last :
 forall (l : list ad) (last : ad) (d : D),
 CG_path last d l -> {l' : list ad | l = l' ++ last :: nil}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction 1; intros. 
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        exists (nil (A:=ad)); simpl in |- *; rewrite e; trivial.
(* Goal: @sig (list ad) (fun l' : list ad => @eq (list ad) (@cons ad x (@cons ad y l0)) (@app ad l' (@cons ad last (@nil ad)))) *)
	case H0; intros l' H1.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
        exists (x :: l'); simpl in |- *.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        rewrite H1; auto.
      Qed.

(*s The length of a path without repetition is less than the
   cardinal of the map representing the graph *)

Lemma ad_simple_path_bounded_card :
 forall (l : list ad) (last x : ad) (d : D),
 CG_path last d (x :: l) ->
 ad_list_stutters (x :: l) = false -> length (x :: l) <= S (MapCard _ cg).
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. apply le_trans with (m := MapCard _ (MapPut _ (MapDom _ cg) last tt)).
(* Goal: le (@length ad (@cons ad x l)) (MapCard unit (MapPut unit (MapDom (Map D) cg) last tt)) *)
(* Goal: le (MapCard unit (MapPut unit (MapDom (Map D) cg) last tt)) (S (MapCard (Map D) cg)) *)
      	rewrite (ad_list_not_stutters_card (x :: l) H0). apply MapSubset_Card_le.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      	apply CG_path_in_cg_1 with (1 := H); trivial.
(* Goal: le (MapCard unit (MapPut unit (MapDom (Map D) cg) last tt)) (S (MapCard (Map D) cg)) *)
	rewrite (MapCard_Dom _ cg). apply MapCard_Put_ub.
      Qed.

Lemma CG_path_app_1 :
 forall (l1 l2 : list ad) (last x : ad) (d1 d2 : D),
 CG_path last d2 (x :: l2) ->
 CG_path x d1 l1 -> CG_path last (Dplus d2 d1) (l1 ++ l2).
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
        intros.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
        elim H0; intros.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        simpl in |- *; rewrite Dplus_d_z; rewrite e; trivial.
(* Goal: @eq bool (Dle (rho a0) (Dplus (rho a) (Dplus (Dneg Done) (Dneg d)))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
        rewrite <- Dplus_assoc.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        simpl in |- *; constructor; auto.
      Qed.

Lemma CG_path_app_2 :
 forall (l1 l2 : list ad) (last x : ad) (d : D),
 CG_path last d (l1 ++ x :: l2) -> {d2 : D &  CG_path last d2 (x :: l2)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction l1. simpl in |- *. intros. split with d. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	simpl in |- *. simple induction l. intros. simpl in H0. inversion H0. split with d0. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. simpl in H1. inversion H1. exact (H0 l2 last x d0 H5).
      Qed.

Lemma CG_path_app_3 :
 forall (l1 l2 : list ad) (last x : ad) (d : D),
 CG_path last d (l1 ++ x :: l2) -> {d1 : D &  CG_path x d1 (l1 ++ x :: nil)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction l1. simpl in |- *. intros. split with Dz. apply CG_p1. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	simple induction l. simpl in |- *. intros. inversion H0. split with d'. rewrite <- (Dplus_z_d d').
(* Goal: @eq bool (negb false) true *)
      	apply CG_p2. apply CG_p1. reflexivity.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	simpl in |- *. intros. inversion H1. elim (H0 _ _ _ _ H5). intros d1 H9. split with (Dplus d1 d').
(* Goal: CGeval rho f *)
      	apply CG_p2. assumption.
(* Goal: CGeval rho f *)
	assumption.
      Qed.

Lemma CG_path_weight_and_last_unique :
 forall (l : list ad) (last last' : ad) (d d' : D),
 CG_path last d l -> CG_path last' d' l -> d = d' /\ last = last'.
      Proof.
(* Goal: forall (l : list ad) (last last' : ad) (d d' : D) (_ : CG_path last d l) (_ : CG_path last' d' l), and (@eq D d d') (@eq ad last last') *)
        intros l last last' d d' H; generalize d'.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	elim H; intros. 
(* Goal: CG_path cg1 last d0 (@cons ad a (@cons ad a0 l1)) *)
	inversion H0. 
(* Goal: forall d : D, @eq D (Dmin d d) d *)
	split; trivial. transitivity x; auto.
(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else @None D) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) O) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix O) (@Some D d)) true *)
(* Goal: forall (n : nat) (_ : forall (x y : ad) (l : list ad) (d : D) (_ : le (@length ad l) n) (_ : CG_path cg y d (@cons ad x l)) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x l))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix n) (@Some D d)) true) (x y : ad) (l : list ad) (d : D) (_ : le (@length ad l) (S n)) (_ : CG_path cg y d (@cons ad x l)) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x l))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n)) (@Some D d)) true *)
        inversion H1.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        case H0 with (1 := H5); split; intros; trivial.
(* Goal: le (S (Init.Nat.add (@length ad l1) (S O))) (@length ad l) *)
(* Goal: le (@length ad l) (S n0) *)
(* Goal: @eq bool (Dle d1 d1) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
        rewrite H8.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        replace d'0 with d'2; auto.
(* Goal: @eq D d'2 d'0 *)
        cut (Some d'2 = Some d'0).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        intro E; injection E; trivial.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        transitivity (CG_edge x y); auto.
      Qed.

    Inductive and_sp (A : Set) (B : Prop) : Set :=
        conj_sp : A -> B -> and_sp A B.

(*s Given a path, one may find a shortest path withour repetition *)

Lemma ad_path_then_simple_path :
 forall (l : list ad) (last : ad) (d : D),
 CG_path last d l ->
 {sl : list ad & 
 {d0 : D & 
 and_sp (CG_path last d0 (first l :: sl))
   (ad_list_stutters (first l :: sl) = false /\ Dle d0 d = true)}}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction 1; unfold first in |- *; intros.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        exists (nil (A:=ad)); exists Dz; split; auto.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        constructor; auto.
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        case H0; clear H0; intros sl (d1, (H1, (H2, H3))).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
        elim (sumbool_of_bool (ad_in_list x (y :: sl))); intro.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
        case (ad_in_list_forms_circuit x (y :: sl) a); intros.
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        case s; clear a s; intros l2 H4.
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        case (CG_path_app_2 x0 l2 last x d1).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        rewrite <- H4; trivial.
(* Goal: forall (x0 : D) (_ : CG_path last x0 (@cons ad x l2)), @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        intros d2 H5; exists l2; exists d2.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        split; trivial.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
        split.
(* Goal: @eq bool (ad_list_stutters (@cons ad x l2)) false *)
(* Goal: @eq bool (Dle d2 (Dplus d0 d')) true *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        apply (ad_list_stutters_app_conv_r x0).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	rewrite <- H4; trivial.
(* Goal: @eq bool (Dle d2 (Dplus d0 d')) true *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        apply Dle_trans with (Dplus d1 d').
(* Goal: @eq bool (Dle d2 (Dplus d1 d')) true *)
(* Goal: @eq bool (Dle (Dplus d1 d') (Dplus d0 d')) true *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
	case (CG_path_app_3 (x :: x0) l2 last x (Dplus d1 d')).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        simpl in |- *; rewrite <- H4; constructor; trivial.
(* Goal: forall (x1 : D) (_ : CG_path x x1 (@app ad (@cons ad x x0) (@cons ad x (@nil ad)))), @eq bool (Dle d2 (Dplus d1 d')) true *)
(* Goal: @eq bool (Dle (Dplus d1 d') (Dplus d0 d')) true *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        intros d3 H6.
(* Goal: @eq bool (Dle d2 (Dplus d1 d')) true *)
(* Goal: @eq bool (Dle (Dplus d1 d') (Dplus d0 d')) true *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        replace (Dplus d1 d') with (Dplus d2 d3).
(* Goal: @eq bool (Dle d2 (Dplus d2 d3)) true *)
(* Goal: @eq D (Dplus d2 d3) (Dplus d1 d') *)
(* Goal: @eq bool (Dle (Dplus d1 d') (Dplus d0 d')) true *)
(* Goal: @sigT (list ad) (fun sl : list ad => @sigT D (fun d1 : D => and_sp (CG_path last d1 (@cons ad x sl)) (and (@eq bool (ad_list_stutters (@cons ad x sl)) false) (@eq bool (Dle d1 (Dplus d0 d')) true)))) *)
        apply Dle_trans with (Dplus d2 Dz).
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        rewrite Dplus_d_z; auto.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        apply Dle_plus_mono; trivial.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        apply (no_bad_cycles x d3 (x0 ++ x :: nil)); auto.
        case
         (CG_path_weight_and_last_unique (((x :: x0) ++ x :: nil) ++ l2) last
(* Goal: forall d : D, @eq D (Dmin d d) d *)
            last (Dplus d2 d3) (Dplus d1 d')); auto.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        apply CG_path_app_1 with x; trivial.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        replace (((x :: x0) ++ x :: nil) ++ l2) with (x :: y :: sl); auto.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        constructor; auto.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        rewrite H4; rewrite <- ass_app; simpl in |- *; trivial.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        apply Dle_plus_mono; trivial.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
	exists (y :: sl); exists (Dplus d1 d'); repeat split; auto.
(* Goal: forall d : D, @eq D (Dmin d d) d *)
        constructor; auto.
        change (ad_in_list x (y :: sl) || ad_list_stutters (y :: sl) = false)
         in |- *.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
        apply orb_false_intro; trivial.
      Qed.

Lemma CG_path_app_4 :
 forall (l1 l2 : list ad) (last x : ad) (d : D),
 CG_path last d (l1 ++ x :: l2) ->
 {d1 : D & 
 {d2 : D & 
 and_sp (CG_path x d1 (l1 ++ x :: nil) * CG_path last d2 (x :: l2))
   (d = Dplus d2 d1)}}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (CG_path_app_2 l1 l2 last x d). intros d1 H0.
(* Goal: @sigT D (fun d1 : D => @sigT D (fun d2 : D => and_sp (prod (CG_path x d1 (@app ad l1 (@cons ad x (@nil ad)))) (CG_path last d2 (@cons ad x l2))) (@eq D d (Dplus d2 d1)))) *)
(* Goal: CG_path last d (@app ad l1 (@cons ad x l2)) *)
      	elim (CG_path_app_3 l1 l2 last x d). intros d2 H1. split with d2. split with d1.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
      	split. exact (H1, H0).
(* Goal: @eq D d (Dplus d1 d2) *)
(* Goal: CG_path last d (@app ad l1 (@cons ad x l2)) *)
(* Goal: CG_path last d (@app ad l1 (@cons ad x l2)) *)
	cut (l1 ++ x :: l2 = (l1 ++ x :: nil) ++ l2). 
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
	intro. rewrite H2 in H.
      	elim
        (CG_path_weight_and_last_unique _ _ _ _ _ H
           (CG_path_app_1 (l1 ++ x :: nil) l2 last x d2 d1 H0 H1)).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      	trivial.
(* Goal: @eq (list ad) (@app ad l1 (@cons ad x l2)) (@app ad (@app ad l1 (@cons ad x (@nil ad))) l2) *)
(* Goal: CG_path last d (@app ad l1 (@cons ad x l2)) *)
(* Goal: CG_path last d (@app ad l1 (@cons ad x l2)) *)
	exact (ass_app l1 (x :: nil) l2).
(* Goal: CGeval rho f *)
	assumption.
(* Goal: CGeval rho f *)
	assumption.
      Qed.

(*s [(ad_simple_path_naive_search x y prefix n)] is true when 
    there esists a path [x::l] from [y] to [x] of length less than 
    [n] with edges not in prefix
*)

Fixpoint ad_simple_path_naive_search (x y : ad) (l : list ad) 
 (n : nat) {struct n} : bool :=
  Neqb x y
  || match n with
     | O => false
     | S n' =>
         match MapGet _ cg x with
         | None => false
         | Some edges =>
             let l' := x :: l in (* builds reverse path *)
             match
               MapSweep D
                 (fun (z : ad) (d : D) =>
                  if ad_in_list z l'
                  then false
                  else ad_simple_path_naive_search z y l' n') edges
             with
             | None => false
             | Some _ => true
             end
         end
     end.

Lemma ad_simple_path_naive_search_correct_1 :
 forall (n : nat) (x y : ad) (l : list ad) (d : D),
 length l <= n ->
 CG_path y d (x :: l) ->
 forall prefix : list ad,
 ad_list_stutters (rev prefix ++ x :: l) = false ->
 ad_simple_path_naive_search x y prefix n = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction n. intros x y l. case l. intros. inversion H0. 
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
        rewrite H4. simpl in |- *.
(* Goal: @eq bool (negb false) true *)
      	rewrite (Neqb_correct y). reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. elim (le_Sn_O _ H).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros n0 H x y l. case l. intros. inversion H1. rewrite H5. simpl in |- *.
(* Goal: @eq bool (negb false) true *)
      	rewrite (Neqb_correct y). reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. simpl in |- *. elim (sumbool_of_bool (Neqb x y)). intro H3. rewrite H3. reflexivity.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
	intro H3. rewrite H3. simpl in |- *. elim (option_sum _ (MapGet _ cg x)). intro H4. elim H4.
(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
      	clear H4. intros edges H4. rewrite H4. inversion_clear H1. unfold CG_edge in H6.
(* Goal: @eq bool match MapGet (Map D) cg x with | Some edges => match MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges with | Some p => true | None => false end | None => false end true *)
      	rewrite H4 in H6. elim (option_sum _ (MapGet D edges a)). intro H7. elim H7. clear H7.
(* Goal: forall (x0 : D) (_ : @eq (option D) (MapGet D edges a) (@Some D x0)), @eq bool match MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges with | Some p0 => true | None => false end true *)
(* Goal: forall _ : @eq (option D) (MapGet D edges a) (@None D), @eq bool match MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges with | Some p => true | None => false end true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool match MapGet (Map D) cg x with | Some edges => match MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges with | Some p => true | None => false end | None => false end true *)
      	intros d'' H7. rewrite H7 in H6.
      	cut
        ((if ad_in_list a (x :: prefix)
          then false
          else ad_simple_path_naive_search a y (x :: prefix) n0) = true).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	intro. elim
  (MapSweep_semantics_4 D
     (fun (z : ad) (_ : D) =>
      if Neqb z x || ad_in_list z prefix
      then false
      else ad_simple_path_naive_search z y (x :: prefix) n0) edges a d'' H7
     H1).
(* Goal: @eq bool (negb false) true *)
      	intros a' H8. elim H8. intros d1 H9. rewrite H9. reflexivity.
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
	rewrite (ad_list_app_rev prefix (a :: l0) x) in H2.
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      	rewrite <- (ad_in_list_rev (x :: prefix) a).
(* Goal: @eq bool (Ddle (if ad_in_list a (@rev ad (@cons ad x prefix)) then @None D else Ddplus (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      	rewrite (ad_list_stutters_prev_conv_l _ _ _ H2).
(* Goal: @eq bool (ad_simple_path_naive_search a y (@cons ad x prefix) n0) true *)
(* Goal: forall _ : @eq (option D) (MapGet D edges a) (@None D), @eq bool match MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges with | Some p => true | None => false end true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool match MapGet (Map D) cg x with | Some edges => match MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges with | Some p => true | None => false end | None => false end true *)
      	exact (H a y l0 d0 (le_S_n _ _ H0) H5 (x :: prefix) H2).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H7. rewrite H7 in H6. discriminate H6.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
	intro H4. inversion_clear H1. unfold CG_edge in H6. rewrite H4 in H6. discriminate H6.
      Qed.

Lemma ad_simple_path_naive_search_correct :
 forall (n : nat) (x y : ad) (l : list ad) (d : D),
 length l <= n ->
 CG_path y d (x :: l) ->
 ad_list_stutters (x :: l) = false ->
 ad_simple_path_naive_search x y nil n = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. exact (ad_simple_path_naive_search_correct_1 n x y l d H H0 nil H1).
      Qed.

Lemma ad_simple_path_naive_search_complete_1 :
 forall (n : nat) (x y : ad) (prefix : list ad) (d' : D),
 CG_path x d' (rev (x :: prefix)) ->
 ad_list_stutters (x :: prefix) = false ->
 ad_simple_path_naive_search x y prefix n = true ->
 {d : D & 
 {l : list ad & 
 and_sp (CG_path y d (rev (x :: prefix) ++ l))
   (ad_list_stutters (rev (x :: prefix) ++ l) = false)}}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction n. intros. split with d'. split with (nil (A:=ad)). simpl in H1.
(* Goal: and_sp (CG_path y d' (@app ad (@rev ad (@cons ad x prefix)) (@nil ad))) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) (@nil ad))) false) *)
(* Goal: forall (n : nat) (_ : forall (x y : ad) (prefix : list ad) (d' : D) (_ : CG_path x d' (@rev ad (@cons ad x prefix))) (_ : @eq bool (ad_list_stutters (@cons ad x prefix)) false) (_ : @eq bool (ad_simple_path_naive_search x y prefix n) true), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false)))) (x y : ad) (prefix : list ad) (d' : D) (_ : CG_path x d' (@rev ad (@cons ad x prefix))) (_ : @eq bool (ad_list_stutters (@cons ad x prefix)) false) (_ : @eq bool (ad_simple_path_naive_search x y prefix (S n)) true), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
      	rewrite (orb_b_false (Neqb x y)) in H1. rewrite <- (Neqb_complete _ _ H1).
(* Goal: CGeval rho f *)
      	rewrite <- app_nil_end. split. assumption.
(* Goal: CGeval rho f *)
	rewrite ad_list_stutters_rev. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. simpl in H2. elim (orb_true_elim _ _ H2). intro H3.
(* Goal: @sig D (fun d' : D => @eq (option D) (CG_edge cg x0 y) (@Some D d')) *)
(* Goal: forall _ : @eq bool (N.eqb a y) false, @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
      	rewrite <- (Neqb_complete _ _ H3). split with d'. split with (nil (A:=ad)).
(* Goal: CGeval rho f *)
      	rewrite <- app_nil_end. split. assumption.
(* Goal: CGeval rho f *)
	rewrite ad_list_stutters_rev. assumption.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	intro H3. clear H2. elim (option_sum _ (MapGet _ cg x)). intro H4. elim H4.
(* Goal: forall (x0 : Map D) (_ : @eq (option (Map D)) (MapGet (Map D) cg x) (@Some (Map D) x0)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
      	intros edges H5. rewrite H5 in H3.
      	elim
        (option_sum _
           (MapSweep D
              (fun (z : ad) (_ : D) =>
               if Neqb z x || ad_in_list z prefix
               then false
               else ad_simple_path_naive_search z y (x :: prefix) n0) edges)).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      	intro H2. elim H2. intro r. elim r. intros x0 d0 H6.
      	cut
        ((if ad_in_list x0 (x :: prefix)
          then false
          else ad_simple_path_naive_search x0 y (x :: prefix) n0) = true).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	intro. elim (sumbool_of_bool (ad_in_list x0 (x :: prefix))). intro H8.
(* Goal: @eq (option D) (CG_edge cg1 a a0) (@Some D d') *)
      	rewrite H8 in H7. discriminate H7.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGFormSimplify c))), CGeval rho c0 *)
(* Goal: forall (_ : CGeval rho (CG_of_CGS (CGFormSimplify c0))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H8. rewrite H8 in H7. clear H2 H3. elim (H x0 y (x :: prefix) (Dplus d0 d')).
(* Goal: forall (x : D) (_ : @sigT D (fun d2 : D => and_sp (prod (CG_path cg2 y0 x (@app ad (@cons ad x0 l0) (@cons ad y0 (@nil ad)))) (CG_path cg2 x0 d2 (@cons ad y0 (@app ad l1 (@cons ad y0 l2))))) (@eq D d0 (Dplus d2 x)))), @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
      	intros d1 H9. elim H9. intros l H10. elim H10. intros H11 H12.
(* Goal: @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
(* Goal: CG_path x0 (Dplus d0 d') (@rev ad (@cons ad x0 (@cons ad x prefix))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x0 (@cons ad x prefix))) false *)
(* Goal: @eq bool (ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: @eq bool (if ad_in_list x0 (@cons ad x prefix) then false else ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: forall _ : @eq (option (prod ad D)) (MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges) (@None (prod ad D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
      	rewrite <- (ad_list_app_rev (x :: prefix) l x0) in H11.
(* Goal: @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
(* Goal: CG_path x0 (Dplus d0 d') (@rev ad (@cons ad x0 (@cons ad x prefix))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x0 (@cons ad x prefix))) false *)
(* Goal: @eq bool (ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: @eq bool (if ad_in_list x0 (@cons ad x prefix) then false else ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: forall _ : @eq (option (prod ad D)) (MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges) (@None (prod ad D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
      	rewrite <- (ad_list_app_rev (x :: prefix) l x0) in H12. split with d1.
(* Goal: CGeval rho f *)
      	split with (x0 :: l). split. assumption.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: CG_path x0 (Dplus d0 d') (@rev ad (@cons ad x0 (@cons ad x prefix))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x0 (@cons ad x prefix))) false *)
(* Goal: @eq bool (ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: @eq bool (if ad_in_list x0 (@cons ad x prefix) then false else ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: forall _ : @eq (option (prod ad D)) (MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges) (@None (prod ad D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
	change (CG_path x0 (Dplus d0 d') (rev (x :: prefix) ++ x0 :: nil)) in |- *.
(* Goal: CG_path cg x Dz (@cons ad x (@nil ad)) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
      	apply CG_path_app_1 with (x := x). rewrite <- (Dplus_z_d d0). apply CG_p2. apply CG_p1.
(* Goal: @eq bool (negb false) true *)
      	reflexivity.
(* Goal: forall (x y : ad) (d : D) (_ : @eq (option D) (CG_edge (M0 (Map D)) x y) (@Some D d)), @eq bool (Dle Dz (Dplus Dz d)) true *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
	unfold CG_edge in |- *. rewrite H5. rewrite (MapSweep_semantics_2 _ _ edges x0 d0 H6).
(* Goal: @eq bool (negb false) true *)
      	reflexivity.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: @eq bool (negb false) true *)
	simpl in |- *. simpl in H1. rewrite H1. simpl in H8. rewrite H8. reflexivity.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: @eq bool (if ad_in_list x0 (@cons ad x prefix) then false else ad_simple_path_naive_search x0 y (@cons ad x prefix) n0) true *)
(* Goal: forall _ : @eq (option (prod ad D)) (MapSweep D (fun (z : ad) (_ : D) => if orb (N.eqb z x) (ad_in_list z prefix) then false else ad_simple_path_naive_search z y (@cons ad x prefix) n0) edges) (@None (prod ad D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
	exact (MapSweep_semantics_1 _ _ _ x0 d0 H6).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	intro H2. rewrite H2 in H3. discriminate H3.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
	intro H4. rewrite H4 in H3. discriminate H3.
      Qed.

Lemma ad_simple_path_naive_search_complete :
 forall (n : nat) (x y : ad),
 ad_simple_path_naive_search x y nil n = true ->
 {d : D & 
 {l : list ad & 
 and_sp (CG_path y d (x :: l)) (ad_list_stutters (x :: l) = false)}}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. exact
  (ad_simple_path_naive_search_complete_1 n x y nil Dz
     (CG_p1 x x (refl_equal _)) (refl_equal false) H).
      Qed.

(*s Definition of simple paths : paths without repetition *)

Definition CG_simple_path (last : ad) (d : D) (l : list ad) :=
  and_sp (CG_path last d l) (ad_list_stutters l = false).

(*s Between two vertexes, there exists a simple path or there exists no path *)
Lemma ad_simple_path_dec :
 forall x y : ad,
 {l : list ad &  {d : D &  CG_simple_path y d (x :: l)}} +
 {(forall (l : list ad) (d : D), CG_simple_path y d (x :: l) -> False)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (sumbool_of_bool (ad_simple_path_naive_search x y nil (MapCard _ cg))).
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      	intro H. left. elim (ad_simple_path_naive_search_complete _ _ _ H). intros d H0.
(* Goal: @sig D (fun d : D => @eq (option D) (CG_edge cg x y) (@Some D d)) *)
      	elim H0. intros l H1. split with l. split with d. exact H1.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H. right. intros l d H0. unfold CG_simple_path in H0. elim H0. intros H1 H2.
      	rewrite
        (ad_simple_path_naive_search_correct _ x y l d
           (le_S_n _ _ (ad_simple_path_bounded_card _ _ _ _ H1 H2)) H1 H2)
         in H.
(* Goal: False *)
      	discriminate H.
      Qed.

(*s Computing the minimum of edges in a Map *)

Definition all_min (f : ad -> D -> option D) := MapFold _ _ None Ddmin f.

Lemma all_min_le_1 :
 forall (f : ad -> D -> option D) (m : Map D) (a : ad) (d : D),
 MapGet _ m a = Some d -> Ddle (all_min f m) (f a d) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (option_sum _ (f a d)). intro H0. elim H0. intros d' H1. rewrite H1.
(* Goal: @eq bool (Ddle (all_min f m) (@Some D d')) true *)
(* Goal: forall _ : @eq (option D) (f a d) (@None D), @eq bool (Ddle (all_min f m) (f a d)) true *)
      	unfold all_min in |- *. cut
  ((fun (a : option D) (b : D) => Ddle a (Some b))
     (MapFold D (option D) None Ddmin f m) d' =
   MapFold D bool false orb
     (fun (a : ad) (y : D) =>
      (fun (a0 : option D) (b : D) => Ddle a0 (Some b)) (f a y) d') m).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	intro. rewrite H2. rewrite MapFold_orb.
      	elim
        (MapSweep_semantics_4 D
           (fun (a : ad) (y : D) => Ddle (f a y) (Some d')) m a d H).
(* Goal: @eq bool (negb false) true *)
      	intros a' H3. elim H3. intros d'' H4. rewrite H4. reflexivity.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	rewrite H1. simpl in |- *. apply Dle_refl.
	exact
  (MapFold_distr_r D _ None Ddmin bool false orb D
     (fun (a : option D) (b : D) => Ddle a (Some b))
     (fun c : D => refl_equal false)
     (fun (a b : option D) (c : D) => Ddmin_le_distr_l a b (Some c)) f m d').
(* Goal: @eq bool (negb false) true *)
	intro H0. rewrite H0. case (all_min f m); reflexivity.
      Qed.

Lemma all_min_le_2_1 :
 forall (f : ad -> D -> option D) (m : Map D) (pf : ad -> ad) (d : D),
 MapFold1 _ _ None Ddmin f pf m = Some d ->
 {a : ad &  {d' : D | MapGet _ m a = Some d' /\ f (pf a) d' = Some d}}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
        simple induction m. intros. discriminate H.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
	intros a y pf d H. simpl in H. split with a. split with y. split. apply M1_semantics_1.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. simpl in H1.
      	elim
        (Ddmin_choice
           (MapFold1 D (option D) None Ddmin f
              (fun a0 : ad => pf (Ndouble a0)) m0)
           (MapFold1 D (option D) None Ddmin f
              (fun a0 : ad => pf (Ndouble_plus_one a0)) m1)).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      	intro H2. rewrite H2 in H1. elim (H (fun a0 : ad => pf (Ndouble a0)) d H1). intros a0 H3.
(* Goal: @sig D (fun d' : D => @eq (option D) (CG_edge cg x0 y) (@Some D d')) *)
(* Goal: forall _ : @eq bool (N.eqb a y) false, @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
      	elim H3. intros d' H4. split with (Ndouble a0). split with d'. split.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      	rewrite MapGet_M2_bit_0_0. rewrite Ndouble_div2. elim H4; trivial.
(* Goal: @eq bool (N.odd (N.double a0)) false *)
(* Goal: @eq (option D) (f (pf (N.double a0)) d') (@Some D d) *)
(* Goal: forall _ : @eq (option D) (Ddmin (MapFold1 D (option D) (@None D) Ddmin f (fun a0 : ad => pf (N.double a0)) m0) (MapFold1 D (option D) (@None D) Ddmin f (fun a0 : ad => pf (N.succ_double a0)) m1)) (MapFold1 D (option D) (@None D) Ddmin f (fun a0 : ad => pf (N.succ_double a0)) m1), @sigT ad (fun a : ad => @sig D (fun d' : D => and (@eq (option D) (MapGet D (M2 D m0 m1) a) (@Some D d')) (@eq (option D) (f (pf a) d') (@Some D d)))) *)
	apply Ndouble_bit0.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	elim H4; trivial.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	intro H2. rewrite H2 in H1. elim (H0 (fun a0 : ad => pf (Ndouble_plus_one a0)) d H1).
(* Goal: @sig D (fun d' : D => @eq (option D) (CG_edge cg x0 y) (@Some D d')) *)
(* Goal: forall _ : @eq bool (N.eqb a y) false, @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
      	intros a0 H3. elim H3. intros d' H4. split with (Ndouble_plus_one a0). split with d'.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      	split. rewrite MapGet_M2_bit_0_1. rewrite Ndouble_plus_one_div2. elim H4; trivial.
(* Goal: @eq bool (N.odd (N.succ_double a0)) true *)
(* Goal: @eq (option D) (f (pf (N.succ_double a0)) d') (@Some D d) *)
	apply Ndouble_plus_one_bit0.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	elim H4; trivial.
      Qed.

Lemma all_min_le_2 :
 forall (f : ad -> D -> option D) (m : Map D) (d : D),
 all_min f m = Some d ->
 {a : ad &  {d' : D | MapGet _ m a = Some d' /\ f a d' = Some d}}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. exact (all_min_le_2_1 f m (fun a : ad => a) d H).
      Qed.

Lemma all_min_le_3 :
 forall (f g : ad -> D -> option D) (m : Map D),
 (forall (a : ad) (d : D),
  MapGet _ m a = Some d -> Ddle (f a d) (g a d) = true) ->
 Ddle (all_min f m) (all_min g m) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (option_sum _ (all_min g m)). intro H0. elim H0. intros d H1.
(* Goal: or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      	elim (all_min_le_2 g m d H1). intros a H2. elim H2. intros d' H3. elim H3. intros H4 H5.
(* Goal: CGeval rho f *)
      	apply Ddle_trans with (f a d'). apply all_min_le_1. assumption.
(* Goal: CGeval rho f *)
	rewrite H1. rewrite <- H5. apply H. assumption.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intro H0. rewrite H0. apply Ddle_d_none.
      Qed.

(*s [(ad_simple_path_dist_1 x y l n)] computes the minimum weight of a path 
    from [x] to [y] of maximal length [n] which does not contain vertexes 
    from [l] *)

Fixpoint ad_simple_path_dist_1 (x y : ad) (l : list ad) 
 (n : nat) {struct n} : option D :=
  if Neqb x y
  then Some Dz
  else
   match n with
   | O => None
   | S n' =>
       match MapGet _ cg x with
       | None => None
       | Some edges =>
           let l' := x :: l in (* builds reverse path *)
           all_min
             (fun (z : ad) (d : D) =>
              if ad_in_list z l'
              then None
              else Ddplus (ad_simple_path_dist_1 z y l' n') d) edges
       end
   end.

Lemma ad_simple_path_dist_1_correct_1 :
 forall (n : nat) (x y : ad) (l : list ad) (d : D),
 length l <= n ->
 CG_path y d (x :: l) ->
 forall prefix : list ad,
 ad_list_stutters (rev prefix ++ x :: l) = false ->
 Ddle (ad_simple_path_dist_1 x y prefix n) (Some d) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction n. intros x y l. case l. intros. inversion H0. 
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
        rewrite H4. simpl in |- *.
(* Goal: @eq bool (Ddle (@Some D d) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
      	rewrite (Neqb_correct y). rewrite H3. apply Ddle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. elim (le_Sn_O _ H).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros n0 H x y l. case l. intros. inversion H1. 
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
        rewrite H5. simpl in |- *.
(* Goal: @eq bool (Ddle (@Some D d) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
      	rewrite (Neqb_correct y). rewrite H4. apply Ddle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. simpl in |- *. elim (sumbool_of_bool (Neqb x y)). intro H3. rewrite H3.
(* Goal: @eq bool (Ddle (@Some D Dz) (@Some D d)) true *)
(* Goal: forall _ : @eq bool (N.eqb x y) false, @eq bool (Ddle (if N.eqb x y then @Some D Dz else match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
      	rewrite (Neqb_complete _ _ H3) in H1. exact (no_bad_cycles _ _ _ H1).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	intro H3. rewrite H3. elim (option_sum _ (MapGet _ cg x)). intro H4. elim H4.
(* Goal: @eq bool (Ddle (@Some D Dz) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
      	intros edges H5. rewrite H5. inversion_clear H1.
      	apply
        Ddle_trans
         with
           (dd' := match ad_in_list a (x :: prefix) with
                   | true => None
                   | false =>
                       Ddplus (ad_simple_path_dist_1 a y (x :: prefix) n0) d'
                   end).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	cut (MapGet _ edges a = Some d'). intro.
      	exact
        (all_min_le_1
           (fun (z : ad) (d : D) =>
            match Neqb z x || ad_in_list z prefix with
            | true => None
            | false => Ddplus (ad_simple_path_dist_1 z y (x :: prefix) n0) d
            end) edges a d' H1).
(* Goal: @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
	unfold CG_edge in H7. rewrite H5 in H7. elim (option_sum _ (MapGet D edges a)). intro H8.
(* Goal: @eq bool (negb false) true *)
      	elim H8. intros d1 H9. rewrite H9 in H7. rewrite H9. inversion_clear H7. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGFormSimplify c))), CGeval rho c0 *)
(* Goal: forall (_ : CGeval rho (CG_of_CGS (CGFormSimplify c0))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H8. rewrite H8 in H7. discriminate H7.
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
	rewrite (ad_list_app_rev prefix (a :: l0) x) in H2.
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      	rewrite <- (ad_in_list_rev (x :: prefix) a).
(* Goal: @eq bool (Ddle (if ad_in_list a (@rev ad (@cons ad x prefix)) then @None D else Ddplus (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      	rewrite (ad_list_stutters_prev_conv_l _ _ _ H2).
      	apply
        (Ddle_plus_mono (ad_simple_path_dist_1 a y (x :: prefix) n0)
           (Some d0) d' d').
(* Goal: @eq bool (Ddle (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) (@Some D d0)) true *)
(* Goal: @eq bool (Dle d' d') true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      	exact (H a y l0 d0 (le_S_n _ _ H0) H6 (x :: prefix) H2).
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	apply Dle_refl.
(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else @None D) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) O) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix O) (@Some D d)) true *)
(* Goal: forall (n : nat) (_ : forall (x y : ad) (l : list ad) (d : D) (_ : le (@length ad l) n) (_ : CG_path cg y d (@cons ad x l)) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x l))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix n) (@Some D d)) true) (x y : ad) (l : list ad) (d : D) (_ : le (@length ad l) (S n)) (_ : CG_path cg y d (@cons ad x l)) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x l))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n)) (@Some D d)) true *)
	intro H4. inversion H1. unfold CG_edge in H10. 
(* Goal: @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D (Dplus d0 d'))) true *)
        rewrite H4 in H10. discriminate H10.
      Qed.

Lemma ad_simple_path_dist_1_correct_2 :
 forall (n : nat) (x y : ad) (l : list ad) (d : D),
 length l <= n ->
 CG_path y d (x :: l) ->
 ad_list_stutters (x :: l) = false ->
 Ddle (ad_simple_path_dist_1 x y nil n) (Some d) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. exact (ad_simple_path_dist_1_correct_1 n x y l d H H0 nil H1).
      Qed.

(*s [(ad_simple_path_dist x y)] computes the minimum path from x to y *)
Definition ad_simple_path_dist (x y : ad) :=
  ad_simple_path_dist_1 x y nil (MapCard _ cg).

Lemma ad_simple_path_dist_correct_1 :
 forall (x y : ad) (l : list ad) (d : D),
 CG_path y d (x :: l) ->
 ad_list_stutters (x :: l) = false ->
 Ddle (ad_simple_path_dist x y) (Some d) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. unfold ad_simple_path_dist in |- *.
(* Goal: CGeval rho f *)
      	apply ad_simple_path_dist_1_correct_2 with (l := l); try assumption.
(* Goal: le (@length ad l) (MapCard (Map D) cg) *)
      	exact (le_S_n _ _ (ad_simple_path_bounded_card l y x d H H0)).
      Qed.

Lemma ad_simple_path_dist_correct :
 forall (x y : ad) (l : list ad) (d : D),
 CG_path y d (x :: l) -> Ddle (ad_simple_path_dist x y) (Some d) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim ad_path_then_simple_path with (1 := H). 
(* Goal: forall (x0 : list ad) (_ : @sigT D (fun d0 : D => and_sp (CG_path y d0 (@cons ad (first (@cons ad x l)) x0)) (and (@eq bool (ad_list_stutters (@cons ad (first (@cons ad x l)) x0)) false) (@eq bool (Dle d0 d) true)))), @eq bool (Ddle (ad_simple_path_dist x y) (@Some D d)) true *)
        intros l0 H0.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	elim H0. intros d0 H1. elim H1. intros H2 H3. elim H3. intros H4 H5.
(* Goal: @eq bool (Ddle (ad_simple_path_dist x y) (@Some D d)) true *)
      	apply Ddle_trans with (dd' := Some d0).
(* Goal: @eq bool (Ddle (ad_simple_path_dist x y) (@Some D d0)) true *)
(* Goal: @eq bool (Ddle (@Some D d0) (@Some D d)) true *)
      	exact (ad_simple_path_dist_correct_1 x y l0 d0 H2 H4).
(* Goal: @eq bool (Dle (rho a) (Dplus (rho a0) d)) true *)
(* Goal: CGSeval_l rho l *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
	exact H5.
      Qed.

Lemma ad_simple_path_dist_1_complete_1 :
 forall (n : nat) (x y : ad) (prefix : list ad) (d' : D),
 CG_path x d' (rev (x :: prefix)) ->
 ad_list_stutters (x :: prefix) = false ->
 forall d0 : D,
 ad_simple_path_dist_1 x y prefix n = Some d0 ->
 {l : list ad & 
 and_sp (CG_path y (Dplus d0 d') (rev (x :: prefix) ++ l))
   (ad_list_stutters (rev (x :: prefix) ++ l) = false /\ length l <= n)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	simple induction n. intros. split with (nil (A:=ad)). split. unfold ad_simple_path_dist_1 in H1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      	elim (sumbool_of_bool (Neqb x y)). intro H2. rewrite H2 in H1. inversion H1.
(* Goal: @eq bool (Dle (Dplus Dz Done) (Dplus (Dneg d) d')) true *)
      	rewrite <- H4. rewrite Dplus_z_d. rewrite <- app_nil_end.
(* Goal: CGeval rho f *)
      	rewrite <- (Neqb_complete _ _ H2). assumption.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	intro H2. rewrite H2 in H1. discriminate H1.
(* Goal: CGeval rho f *)
	split. rewrite <- app_nil_end. rewrite ad_list_stutters_rev. assumption.
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: CGsat (M0 (Map D)) rho *)
(* Goal: CGSeval_l rho (@cons CGSForm fs (@nil CGSForm)) *)
	apply le_n.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. simpl in H2. elim (sumbool_of_bool (Neqb x y)). intro H3. rewrite H3 in H2.
(* Goal: @eq bool (Dle (Dplus Dz Done) (Dplus (Dneg d) d')) true *)
      	inversion H2. split with (nil (A:=ad)). split. rewrite <- H5. rewrite Dplus_z_d.
(* Goal: CGeval rho f *)
      	rewrite <- app_nil_end. rewrite <- (Neqb_complete _ _ H3). assumption.
(* Goal: CGeval rho f *)
	split. rewrite <- app_nil_end. rewrite ad_list_stutters_rev. assumption.
(* Goal: le O (@length ad l2) *)
(* Goal: le (Init.Nat.add (@length ad l1) (@length ad l2)) (Init.Nat.add (@length ad l0) (Init.Nat.add (@length ad l1) (@length ad l2))) *)
(* Goal: le (@length ad l) (S n0) *)
(* Goal: @eq bool (Dle d1 d1) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
	apply le_O_n.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	intro H3. rewrite H3 in H2. elim (option_sum _ (MapGet _ cg x)). intro H4. elim H4.
(* Goal: forall (x0 : Map D) (_ : @eq (option (Map D)) (MapGet (Map D) cg x) (@Some (Map D) x0)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
      	intros edges H5. rewrite H5 in H2. elim (all_min_le_2 _ edges d0 H2). intros a H6.
(* Goal: @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
      	elim H6. intros d1 H7. elim H7. intros H8 H9. clear H2 H6 H7.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	cut (ad_in_list a (x :: prefix) = false). intro.
(* Goal: and (CGSeval rho (CGSor c c0)) (CGSeval_l rho l) *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: lt (FlSize (@cons CGSForm c0 l)) n *)
(* Goal: @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
      	elim (option_sum _ (ad_simple_path_dist_1 a y (x :: prefix) n0)). intro H6. elim H6.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	intros d2 H7. clear H6. rewrite H7 in H9. cut (Dplus d2 d1 = d0). intro.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	cut (CG_path a (Dplus d1 d') (rev (a :: x :: prefix))). intro.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	cut (ad_list_stutters (a :: x :: prefix) = false). intro.
(* Goal: @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad a (@cons ad x prefix))) false *)
(* Goal: CG_path a (Dplus d1 d') (@rev ad (@cons ad a (@cons ad x prefix))) *)
(* Goal: @eq D (Dplus d2 d1) d0 *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) (@None D), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
      	elim (H a y (x :: prefix) _ H10 H11 d2 H7). intros l0 H12. elim H12. intros H13 H14.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
      	elim H14. intros H15 H16. split with (a :: l0). split. rewrite ad_list_app_rev.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	rewrite <- H6. rewrite Dplus_assoc. assumption.
(* Goal: CGeval rho f *)
	split. rewrite ad_list_app_rev. assumption.
(* Goal: le (@length ad (@cons ad a l0)) (S n0) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad a (@cons ad x prefix))) false *)
(* Goal: CG_path a (Dplus d1 d') (@rev ad (@cons ad a (@cons ad x prefix))) *)
(* Goal: @eq D (Dplus d2 d1) d0 *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) (@None D), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
	exact (le_n_S _ _ H16).
(* Goal: @eq bool (negb false) true *)
	simpl in |- *. simpl in H2. rewrite H2. simpl in H1. rewrite H1. reflexivity.
(* Goal: CG_path a (Dplus d1 d') (@rev ad (@cons ad a (@cons ad x prefix))) *)
(* Goal: @eq D (Dplus d2 d1) d0 *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) (@None D), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
	apply (CG_path_app_1 (rev (x :: prefix)) (a :: nil) a x).
(* Goal: @eq bool (negb false) true *)
      	rewrite <- (Dplus_z_d d1). apply CG_p2. apply CG_p1. reflexivity.
(* Goal: @eq bool (negb false) true *)
	unfold CG_edge in |- *. rewrite H5. rewrite H8. reflexivity.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: @eq D (Dplus d2 d1) d0 *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) (@None D), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
	elim (sumbool_of_bool (Neqb a x || ad_in_list a prefix)). intro H10.
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq bool (ad_in_list a (@cons ad x prefix)) false, @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
      	rewrite H10 in H9. discriminate H9.
(* Goal: @eq bool (negb false) true *)
	intro H10. rewrite H10 in H9. simpl in H9. inversion H9. reflexivity.
(* Goal: forall _ : not (CGeval rho c), or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H6. rewrite H6 in H9. generalize H9.
(* Goal: @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D (Dplus d0 d'))) true *)
      	case (Neqb a x || ad_in_list a prefix); intro H10; discriminate H10.
(* Goal: forall _ : @eq bool (ad_in_list a (@cons ad x prefix)) true, @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq bool (ad_in_list a (@cons ad x prefix)) false, @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
	elim (sumbool_of_bool (ad_in_list a (x :: prefix))). intro H10. simpl in H10.
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq bool (ad_in_list a (@cons ad x prefix)) false, @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
      	rewrite H10 in H9. discriminate H9.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	trivial.
(* Goal: @eq bool (orb (ad_in_list x0 l'0) false) false *)
(* Goal: forall _ : @eq bool (ad_in_list x0 l'0) false, @eq bool (orb (ad_in_list x0 l'0) false) false *)
(* Goal: CG_path cg2 x d1 (@app ad l0 (@cons ad x (@nil ad))) *)
(* Goal: CG_path cg1 x0 d3 (@cons ad y l1) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
	intro H4. rewrite H4 in H2. discriminate H2.
      Qed.

Lemma ad_simple_path_dist_1_complete :
 forall (n : nat) (x y : ad) (d : D),
 ad_simple_path_dist_1 x y nil n = Some d ->
 {l : list ad & 
 and_sp (CG_path y d (x :: l)) (ad_list_stutters (x :: l) = false)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim
  (ad_simple_path_dist_1_complete_1 n x y nil Dz (CG_p1 x x (refl_equal _))
     (refl_equal _) d H).
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
      	intros l H0. split with l. elim H0. intros H1 H2. elim H2. intros H3 H4. split.
(* Goal: CGeval rho f *)
      	rewrite (Dplus_d_z d) in H1. assumption.
(* Goal: CG_path cg y d (@cons ad x l) *)
(* Goal: @eq bool (ad_list_stutters (@app ad (@rev ad (@nil ad)) (@cons ad x l))) false *)
(* Goal: CG_path cg x Dz (@rev ad (@cons ad x (@nil ad))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
	exact H3.
      Qed.

Lemma ad_simple_path_dist_complete :
 forall (x y : ad) (d : D),
 ad_simple_path_dist x y = Some d ->
 {l : list ad & 
 and_sp (CG_path y d (x :: l)) (ad_list_stutters (x :: l) = false)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. exact (ad_simple_path_dist_1_complete (MapCard _ cg) x y d H).
      Qed.

Lemma ad_simple_path_dist_complete_2 :
 forall (x y : ad) (d : D),
 ad_simple_path_dist x y = Some d -> {l : list ad &  CG_path y d (x :: l)}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (ad_simple_path_dist_complete x y d H). intros l H0. split with l.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      	elim H0; trivial.
      Qed.

Lemma ad_simple_path_dist_complete_3 :
 forall (x y : ad) (dd : option D),
 (forall (l : list ad) (d : D),
  CG_path y d (x :: l) -> Ddle dd (Some d) = true) ->
 Ddle dd (ad_simple_path_dist x y) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros x y dd. case dd. Focus 2. intros. elim (option_sum _ (ad_simple_path_dist x y)). intro H0.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
      	elim H0. intros d H1. elim (ad_simple_path_dist_complete_2 x y d H1). intros l H2.
(* Goal: @eq bool (negb false) true *)
      	simpl in H. rewrite <- (H l d H2). rewrite H1. reflexivity.
(* Goal: @eq bool (negb false) true *)
	intro H0. rewrite H0. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. elim (option_sum _ (ad_simple_path_dist x y)). intro H0. elim H0. intros d0 H1.
(* Goal: @eq (option D) (ad_1_path_dist x y) (ad_1_path_dist_1 x y (M0 unit) n) *)
(* Goal: @ex nat (fun m : nat => @eq nat n (Init.Nat.add m (MapCard (Map D) cg))) *)
      	rewrite H1. elim (ad_simple_path_dist_complete_2 x y d0 H1). intros l H2.
      	exact (H l d0 H2).
(* Goal: @eq bool (negb false) true *)
	intro H0. rewrite H0. reflexivity.
      Qed.

Lemma ad_simple_path_dist_d_1 :
 forall x : ad, ad_simple_path_dist x x = Some Dz.
      Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	unfold ad_simple_path_dist in |- *. elim (MapCard _ cg); simpl in |- *. intro.
(* Goal: @eq bool (negb false) true *)
      	rewrite (Neqb_correct x). reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. rewrite (Neqb_correct x). reflexivity.
      Qed.

Lemma ad_simple_path_dist_d_2 :
 forall (x y z : ad) (d d' : D),
 ad_simple_path_dist x y = Some d ->
 ad_simple_path_dist y z = Some d' ->
 Ddle (ad_simple_path_dist x z) (Some (Dplus d' d)) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (ad_simple_path_dist_complete_2 x y d H).
(* Goal: forall (x0 : list ad) (_ : CG_path y d (@cons ad x x0)), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
      	elim (ad_simple_path_dist_complete_2 y z d' H0). intros l1 H1 l2 H2.
(* Goal: @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
      	apply (ad_simple_path_dist_correct x z (l2 ++ l1)).
(* Goal: CG_path z (Dplus d' d) (@cons ad x (@app ad l2 l1)) *)
      	exact (CG_path_app_1 (x :: l2) l1 z y d d' H1 H2).
      Qed.

Lemma ad_simple_path_dist_d_3 :
 forall (x y z : ad) (d d' : D),
 Ddle (ad_simple_path_dist x y) (Some d) = true ->
 Ddle (ad_simple_path_dist y z) (Some d') = true ->
 Ddle (ad_simple_path_dist x z) (Some (Dplus d' d)) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. elim (option_sum _ (ad_simple_path_dist x y)). intro H1. elim H1. intros d0 H2.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      	elim (option_sum _ (ad_simple_path_dist y z)). intro H3. elim H3. intros d'0 H4.
(* Goal: @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist y z) (@None D), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist x y) (@None D), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
      	apply Ddle_trans with (dd' := Some (Dplus d'0 d0)).
(* Goal: @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d'0 d0))) true *)
(* Goal: @eq bool (Ddle (@Some D (Dplus d'0 d0)) (@Some D (Dplus d' d))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist y z) (@None D), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist x y) (@None D), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
      	exact (ad_simple_path_dist_d_2 x y z d0 d'0 H2 H4).
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
	rewrite H2 in H. simpl in H. rewrite H4 in H0. simpl in H0. simpl in |- *.
(* Goal: @eq bool (Dle (Dplus d'0 d0) (Dplus d' d)) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist y z) (@None D), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist x y) (@None D), @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d' d))) true *)
      	exact (Dle_plus_mono _ _ _ _ H0 H).
(* Goal: @eq bool (Dle d (Dplus d (Dneg Done))) false *)
(* Goal: @eq bool (Dle Dz (Dneg Done)) true *)
(* Goal: forall _ : @eq bool (Dle d (Dplus d (Dneg Done))) false, @eq bool (Dle d (Dplus d (Dneg Done))) false *)
	intro H3. rewrite H3 in H0. discriminate H0.
(* Goal: False *)
	intro H1. rewrite H1 in H. discriminate H.
      Qed.

(*s [(CG_leq x y)] is true when there is a path from [x] to [y] *)

Definition CG_leq (x y : ad) :=
  match ad_simple_path_dist x y with
  | Some _ => true
  | _ => false
  end.

Lemma CG_leq_refl : forall x : ad, CG_leq x x = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	unfold CG_leq in |- *. intros. rewrite (ad_simple_path_dist_d_1 x). reflexivity.
      Qed.

Lemma CG_leq_trans :
 forall x y z : ad,
 CG_leq x y = true -> CG_leq y z = true -> CG_leq x z = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	unfold CG_leq in |- *. intros. elim (option_sum _ (ad_simple_path_dist x y)). intro H1.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	elim H1. intros d1 H2. elim (option_sum _ (ad_simple_path_dist y z)). intro H3.
(* Goal: @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
      	elim H3. intros d2 H4. cut (Ddle (ad_simple_path_dist x z) (Some (Dplus d2 d1)) = true).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	intro. elim (option_sum _ (ad_simple_path_dist x z)). intro H6. elim H6. intros d3 H7.
(* Goal: @eq bool (negb false) true *)
      	rewrite H7. reflexivity.
(* Goal: forall _ : not (CGeval rho c), or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H6. rewrite H6 in H5. discriminate H5.
(* Goal: @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d2 d1))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist y z) (@None D), @eq bool match ad_simple_path_dist x z with | Some d => true | None => false end true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist x y) (@None D), @eq bool match ad_simple_path_dist x z with | Some d => true | None => false end true *)
	exact (ad_simple_path_dist_d_2 _ _ _ _ _ H2 H4).
(* Goal: @eq bool (Dle d (Dplus d (Dneg Done))) false *)
(* Goal: @eq bool (Dle Dz (Dneg Done)) true *)
(* Goal: forall _ : @eq bool (Dle d (Dplus d (Dneg Done))) false, @eq bool (Dle d (Dplus d (Dneg Done))) false *)
	intro H3. rewrite H3 in H0. discriminate H0.
(* Goal: False *)
	intro H1. rewrite H1 in H. discriminate H.
      Qed.

(*s [(CG_standard_rho root d0 others x)] computes [d0-d] when
     [root] and [x] are connected by a path of minimal 
     length [d] and [(others x)] when there are not connected 
*)

Definition CG_standard_rho (root : ad) (d0 : D) (others : ad -> D)
  (x : ad) :=
  match ad_simple_path_dist root x with
  | Some d => Dplus d0 (Dneg d)
  | None => others x (* dummy *)
  end.

Lemma CG_standard_rho_root :
 forall (root : ad) (d0 : D) (others : ad -> D),
 CG_standard_rho root d0 others root = d0.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	unfold CG_standard_rho in |- *. intros. rewrite (ad_simple_path_dist_d_1 root).
(* Goal: @eq D (Dplus anchor_value Dz) anchor_value *)
      	rewrite Dneg_Dz. apply Dplus_d_z.
      Qed.

(*s If there is a root such that all the nodes ae connected to 
    this root, then [CG_standard_rho] gives a correct valuation 
*)
Lemma CG_rooted_sat_1 :
 forall (root : ad) (d0 : D) (others : ad -> D),
 (forall x : ad, in_dom _ x cg = true -> CG_leq root x = true) ->
 CGsat (CG_standard_rho root d0 others).
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	unfold CG_standard_rho in |- *. intros. unfold CGsat in |- *. intros.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
      	elim (option_sum _ (ad_simple_path_dist root x)). intro H1. elim H1. intros d1 H2.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      	rewrite H2. cut (Ddle (ad_simple_path_dist root y) (Some (Dplus d d1)) = true). intro.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
      	elim (option_sum _ (ad_simple_path_dist root y)). intro H4. elim H4. intros d2 H5.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	rewrite H5. rewrite Dplus_assoc. apply Dle_plus_mono. apply Dle_refl.
(* Goal: @eq bool (Dle (rho y) (Dplus (rho y) (Dplus d (Dneg d)))) true *)
	apply Dplus_reg_l with (d'' := d2). rewrite <- Dplus_assoc. rewrite Dplus_neg.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	rewrite Dplus_z_d. apply Dplus_reg_r with (d'' := d1). rewrite Dplus_assoc.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg Done)) (Dplus (Dneg d) d))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	rewrite Dplus_neg_2. rewrite Dplus_d_z. rewrite H5 in H3. exact H3.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
	intro H4. rewrite H4 in H3. discriminate H3.
(* Goal: @eq bool (Ddle (ad_simple_path_dist root y) (@Some D (Dplus d d1))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist root x) (@None D), @eq bool (Dle match ad_simple_path_dist root x with | Some d => Dplus d0 (Dneg d) | None => others x end (Dplus match ad_simple_path_dist root y with | Some d => Dplus d0 (Dneg d) | None => others y end d)) true *)
	elim (ad_simple_path_dist_complete_2 root x d1 H2). intros l H3.
      	apply
        (ad_simple_path_dist_correct root y (l ++ y :: nil) (Dplus d d1)).
(* Goal: CG_path y (Dplus d d1) (@cons ad root (@app ad l (@cons ad y (@nil ad)))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist root x) (@None D), @eq bool (Dle match ad_simple_path_dist root x with | Some d => Dplus d0 (Dneg d) | None => others x end (Dplus match ad_simple_path_dist root y with | Some d => Dplus d0 (Dneg d) | None => others y end d)) true *)
      	change (CG_path y (Dplus d d1) ((root :: l) ++ y :: nil)) in |- *.
(* Goal: CG_path y d (@cons ad x (@cons ad y (@nil ad))) *)
(* Goal: CG_path x d1 (@cons ad root l) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist root x) (@None D), @eq bool (Dle match ad_simple_path_dist root x with | Some d => Dplus d0 (Dneg d) | None => others x end (Dplus match ad_simple_path_dist root y with | Some d => Dplus d0 (Dneg d) | None => others y end d)) true *)
      	apply CG_path_app_1 with (last := y) (x := x). rewrite <- (Dplus_z_d d). apply CG_p2.
(* Goal: @eq bool (negb false) true *)
      	apply CG_p1. reflexivity.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
	intro H1. cut (CG_leq root x = true). 
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
	unfold CG_leq in |- *. rewrite H1. intro. discriminate H2.
(* Goal: CGeval rho (CG_of_CGS c) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c0))), or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	apply H. rewrite MapDom_Dom. exact (CG_edge_in_cg_1 _ _ _ H0).
      Qed.

Lemma CG_rooted_sat :
 forall (root : ad) (d0 : D),
 (forall x : ad, in_dom _ x cg = true -> CG_leq root x = true) ->
 {rho : ad -> D | CGsat rho /\ rho root = d0}.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. split with (CG_standard_rho root d0 (fun x : ad => d0)). split.
(* Goal: CGsat (CG_standard_rho root d0 (fun _ : ad => d0)) *)
(* Goal: @eq D (CG_standard_rho root d0 (fun _ : ad => d0) root) d0 *)
      	exact (CG_rooted_sat_1 root d0 (fun x : ad => d0) H).
(* Goal: @eq D (CG_standard_rho root d0 (fun _ : ad => d0) root) d0 *)
	apply CG_standard_rho_root.
      Qed.

(*s The [CG_standard_rho] valuation is the minimal one *)
Lemma CG_standard_rho_minimal :
 forall (root : ad) (d0 : D) (others rho : ad -> D),
 CGsat rho ->
 Dle d0 (rho root) = true ->
 forall x : ad,
 CG_leq root x = true ->
 Dle (CG_standard_rho root d0 others x) (rho x) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	unfold CG_leq, CG_standard_rho in |- *. intros. elim (option_sum _ (ad_simple_path_dist root x)).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      	intro H2. elim H2. intros d H3. rewrite H3.
(* Goal: @eq bool (Dle (Dplus d0 (Dneg d)) (rho x)) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist root x) (@None D), @eq bool (Dle match ad_simple_path_dist root x with | Some d => Dplus d0 (Dneg d) | None => others x end (rho x)) true *)
      	elim (ad_simple_path_dist_complete_2 root x d H3). intros l H4.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	apply Dplus_reg_r with (d'' := d). rewrite Dplus_assoc. rewrite Dplus_neg_2.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg Done)) Dz)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	rewrite Dplus_d_z. apply Dle_trans with (d' := rho root). exact H0.
(* Goal: @eq bool (Dle (rho root) (Dplus (rho x) d)) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist root x) (@None D), @eq bool (Dle match ad_simple_path_dist root x with | Some d => Dplus d0 (Dneg d) | None => others x end (rho x)) true *)
	exact (CG_path_correct l root x d H4 rho H).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	intro H2. rewrite H2 in H1. discriminate H1.
      Qed.

Lemma CG_sat_add_1 :
 forall (x y : ad) (d : D) (rho : ad -> D),
 CGsat rho ->
 Dle (rho x) (Dplus (rho y) d) = true ->
 Ddle (Some (Dneg d)) (ad_simple_path_dist y x) = true.
      Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      	intros. apply ad_simple_path_dist_complete_3. intros. simpl in |- *.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg Done)) (Dplus (Dneg d) d))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      	apply Dplus_reg_r with (d'' := d). rewrite Dplus_neg_2. apply Dplus_reg_l with (d'' := rho x).
(* Goal: CGeval rho f *)
      	rewrite Dplus_d_z. apply Dle_trans with (d' := Dplus (rho y) d); try assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      	apply Dle_trans with (d' := Dplus (Dplus (rho x) d0) d). apply Dle_plus_mono.
(* Goal: @eq bool (Dle (rho y) (Dplus (rho x) d0)) true *)
(* Goal: @eq bool (Dle d d) true *)
(* Goal: @eq bool (Dle (Dplus (Dplus (rho x) d0) d) (Dplus (rho x) (Dplus d0 d))) true *)
      	exact (CG_path_correct l y x d0 H1 rho H).
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	apply Dle_refl.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
	rewrite Dplus_assoc. apply Dle_refl.
      Qed.

    End CGNoBadCycles.

(*s [(CG_add x y d)] adds the edge (x,y) of weight d to G, 
   in case an edge already exists, only the minimal one is kept
*)

Definition CG_add (x y : ad) (d : D) :=
  match MapGet _ cg x with
  | None => MapPut _ cg x (M1 _ y d)
  | Some edges =>
      match MapGet _ edges y with
      | None => MapPut _ cg x (MapPut _ edges y d)
      | Some d0 => MapPut _ cg x (MapPut _ edges y (Dmin d d0))
      end
  end.

End CGDist.

(*s Properties of [CG_add] *)
Section CGAdd.

    Variable cg1 : CGraph1.

    Variable x y : ad.
    Variable d : D.

Definition cg2 := CG_add cg1 x y d.

Lemma CG_add_edge_1 :
 forall x0 y0 : ad,
 CG_edge cg2 x0 y0 =
 (if Neqb x x0 && Neqb y y0
  then Ddmin (Some d) (CG_edge cg1 x0 y0)
  else CG_edge cg1 x0 y0).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	unfold cg2, CG_add in |- *. intros. elim (sumbool_of_bool (Neqb x x0 && Neqb y y0)).
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    	intro H. elim (andb_prop _ _ H). intros H0 H1. rewrite H.
(* Goal: @eq (option D) (CG_edge match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end | None => MapPut (Map D) cg1 x (M1 D y d) end x y0) (Ddmin (@Some D d) (CG_edge cg1 x y0)) *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq (option D) (CG_edge match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end | None => MapPut (Map D) cg1 x (M1 D y d) end x0 y0) (if andb (N.eqb x x0) (N.eqb y y0) then Ddmin (@Some D d) (CG_edge cg1 x0 y0) else CG_edge cg1 x0 y0) *)
    	rewrite <- (Neqb_complete _ _ H0). rewrite <- (Neqb_complete _ _ H1).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    	elim (option_sum _ (MapGet _ cg1 x)). intro H2. elim H2. intros edges H3. rewrite H3.
(* Goal: @eq bool (Ddle (@Some D Dz) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
    	elim (option_sum _ (MapGet D edges y)). intro H4. elim H4. intros d0 H5. rewrite H5.
(* Goal: forall (x y : ad) (d : D) (_ : @eq (option D) (CG_edge (M0 (Map D)) x y) (@Some D d)), @eq bool (Dle Dz (Dplus Dz d)) true *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
    	unfold CG_edge in |- *. rewrite (MapPut_semantics _ cg1 x (MapPut D edges y (Dmin d d0)) x).
(* Goal: @eq (option D) match (if N.eqb x x then @Some (Map D) (M1 D y d) else MapGet (Map D) cg1 x) with | Some edges => match MapGet D edges y with | Some d => @Some D d | None => @None D end | None => @None D end (Ddmin (@Some D d) match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d => @Some D d | None => @None D end | None => @None D end) *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq (option D) (CG_edge match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end | None => MapPut (Map D) cg1 x (M1 D y d) end x0 y0) (if andb (N.eqb x x0) (N.eqb y y0) then Ddmin (@Some D d) (CG_edge cg1 x0 y0) else CG_edge cg1 x0 y0) *)
    	rewrite (Neqb_correct x). rewrite (MapPut_semantics _ edges y (Dmin d d0) y).
(* Goal: @eq bool (negb false) true *)
    	rewrite (Neqb_correct y). rewrite H3. rewrite H5. reflexivity.
(* Goal: forall (x y : ad) (d : D) (_ : @eq (option D) (CG_edge (M0 (Map D)) x y) (@Some D d)), @eq bool (Dle Dz (Dplus Dz d)) true *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
	intro H4. rewrite H4. unfold CG_edge in |- *.
(* Goal: @eq (option D) match (if N.eqb x x then @Some (Map D) (M1 D y d) else MapGet (Map D) cg1 x) with | Some edges => match MapGet D edges y with | Some d => @Some D d | None => @None D end | None => @None D end (Ddmin (@Some D d) match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d => @Some D d | None => @None D end | None => @None D end) *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq (option D) (CG_edge match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end | None => MapPut (Map D) cg1 x (M1 D y d) end x0 y0) (if andb (N.eqb x x0) (N.eqb y y0) then Ddmin (@Some D d) (CG_edge cg1 x0 y0) else CG_edge cg1 x0 y0) *)
    	rewrite (MapPut_semantics _ cg1 x (MapPut D edges y d) x). rewrite (Neqb_correct x).
(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
    	rewrite H3. rewrite H4. rewrite (MapPut_semantics _ edges y d y).
(* Goal: @eq bool (negb false) true *)
    	rewrite (Neqb_correct y). reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	intro H2. rewrite H2. unfold CG_edge in |- *. rewrite (MapPut_semantics _ cg1 x (M1 D y d) x).
(* Goal: @eq bool (negb false) true *)
    	rewrite (Neqb_correct x). rewrite H2. rewrite (M1_semantics_1 _ y d). reflexivity.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H. rewrite H. elim (andb_false_elim _ _ H). intro H0.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    	elim (option_sum _ (MapGet _ cg1 x)). intro H1. elim H1. intros edges H2. rewrite H2.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    	elim (option_sum _ (MapGet _ edges y)). intro H3. elim H3. intros d0 H4. rewrite H4.
(* Goal: forall (x y : ad) (d : D) (_ : @eq (option D) (CG_edge (M0 (Map D)) x y) (@Some D d)), @eq bool (Dle Dz (Dplus Dz d)) true *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
    	unfold CG_edge in |- *. rewrite (MapPut_semantics _ cg1 x (MapPut D edges y (Dmin d d0)) x0).
(* Goal: @eq bool (negb false) true *)
    	rewrite H0. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	intro H3. rewrite H3. unfold CG_edge in |- *.
(* Goal: @eq bool (negb false) true *)
    	rewrite (MapPut_semantics _ cg1 x (MapPut D edges y d) x0). rewrite H0. reflexivity.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
	intro H1. rewrite H1. unfold CG_edge in |- *. rewrite (MapPut_semantics _ cg1 x (M1 D y d) x0).
(* Goal: @eq bool (negb false) true *)
    	rewrite H0. reflexivity.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
	intro H0. elim (option_sum _ (MapGet _ cg1 x)). intro H1. elim H1. intros edges H2.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    	rewrite H2. elim (option_sum _ (MapGet _ edges y)). intro H3. elim H3. intros d0 H4.
(* Goal: forall (x y : ad) (d : D) (_ : @eq (option D) (CG_edge (M0 (Map D)) x y) (@Some D d)), @eq bool (Dle Dz (Dplus Dz d)) true *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
    	rewrite H4. unfold CG_edge in |- *.
(* Goal: @eq (option D) match MapGet (Map D) (MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0))) x0 with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end match MapGet (Map D) cg1 x0 with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end *)
(* Goal: forall _ : @eq (option D) (MapGet D edges y) (@None D), @eq (option D) (CG_edge match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end x0 y0) (CG_edge cg1 x0 y0) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg1 x) (@None (Map D)), @eq (option D) (CG_edge match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end | None => MapPut (Map D) cg1 x (M1 D y d) end x0 y0) (CG_edge cg1 x0 y0) *)
    	rewrite (MapPut_semantics _ cg1 x (MapPut D edges y (Dmin d d0)) x0).
(* Goal: @eq bool (Ddle (@Some D Dz) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
    	elim (sumbool_of_bool (Neqb x x0)). intro H5. rewrite H5.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	rewrite (MapPut_semantics _ edges y (Dmin d d0) y0). rewrite H0.
(* Goal: @eq bool (negb false) true *)
    	rewrite <- (Neqb_complete _ _ H5). rewrite H2. reflexivity.
(* Goal: @eq bool (negb false) true *)
	intro H5. rewrite H5. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	intro H3. rewrite H3. unfold CG_edge in |- *.
(* Goal: @eq (option D) match MapGet (Map D) (MapPut (Map D) cg1 x (MapPut D edges y d)) x0 with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end match MapGet (Map D) cg1 x0 with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg1 x) (@None (Map D)), @eq (option D) (CG_edge match MapGet (Map D) cg1 x with | Some edges => match MapGet D edges y with | Some d0 => MapPut (Map D) cg1 x (MapPut D edges y (Dmin d d0)) | None => MapPut (Map D) cg1 x (MapPut D edges y d) end | None => MapPut (Map D) cg1 x (M1 D y d) end x0 y0) (CG_edge cg1 x0 y0) *)
    	rewrite (MapPut_semantics _ cg1 x (MapPut D edges y d) x0).
(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
    	elim (sumbool_of_bool (Neqb x x0)). intro H4. rewrite H4.
(* Goal: @eq nat (S m) (Init.Nat.add (S m') (MapCard (Map D) cg)) *)
    	rewrite <- (Neqb_complete _ _ H4). rewrite H2.
(* Goal: @eq bool (negb false) true *)
    	rewrite (MapPut_semantics _ edges y d y0). rewrite H0. reflexivity.
(* Goal: @eq bool (negb false) true *)
	intro H4. rewrite H4. reflexivity.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
	intro H1. rewrite H1. unfold CG_edge in |- *. rewrite (MapPut_semantics _ cg1 x (M1 D y d) x0).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    	elim (sumbool_of_bool (Neqb x x0)). intro H2. rewrite H2.
(* Goal: @eq (option D) (@None D) match MapGet (Map D) cg1 x0 with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end *)
(* Goal: forall _ : @eq bool (N.eqb x x0) false, @eq (option D) match (if N.eqb x x0 then @Some (Map D) (M1 D y d) else MapGet (Map D) cg1 x0) with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end match MapGet (Map D) cg1 x0 with | Some edges => match MapGet D edges y0 with | Some d => @Some D d | None => @None D end | None => @None D end *)
    	rewrite (M1_semantics_2 _ y y0 d H0). rewrite <- (Neqb_complete _ _ H2).
(* Goal: @eq bool (negb false) true *)
    	rewrite H1. reflexivity.
(* Goal: @eq bool (negb false) true *)
	intro H2. rewrite H2. reflexivity.
    Qed.

Lemma CG_add_edge_2 :
 forall x0 y0 : ad, Ddle (CG_edge cg2 x0 y0) (CG_edge cg1 x0 y0) = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	intros. rewrite (CG_add_edge_1 x0 y0).
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    	elim (sumbool_of_bool (Neqb x x0 && Neqb y y0)). intro H. rewrite H.
(* Goal: @eq bool (Ddle (Ddmin (@Some D d) (CG_edge cg1 x0 y0)) (CG_edge cg1 x0 y0)) true *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq bool (Ddle (if andb (N.eqb x x0) (N.eqb y y0) then Ddmin (@Some D d) (CG_edge cg1 x0 y0) else CG_edge cg1 x0 y0) (CG_edge cg1 x0 y0)) true *)
    	apply Ddmin_le_2.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H. rewrite H. apply Ddle_refl.
    Qed.

Lemma CG_add_1 :
 forall rho : ad -> D,
 CGsat cg1 rho -> Dle (rho x) (Dplus (rho y) d) = true -> CGsat cg2 rho.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	unfold CGsat in |- *. intros. rewrite (CG_add_edge_1 x0 y0) in H1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    	elim (sumbool_of_bool (Neqb x x0 && Neqb y y0)). intro H2.
(* Goal: sumbool (@eq ad a0 root) (@eq bool (in_dom (Map D) a0 cg) true) *)
    	elim (andb_prop _ _ H2). intros H3 H4. rewrite H2 in H1.
(* Goal: @eq bool (Dle (rho x0) (Dplus (rho y0) d0)) true *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq bool (Dle (rho x0) (Dplus (rho y0) d0)) true *)
    	rewrite <- (Neqb_complete _ _ H3). rewrite <- (Neqb_complete _ _ H4).
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
    	elim (option_sum _ (CG_edge cg1 x0 y0)). intro H5. elim H5. intros d1 H6.
(* Goal: @eq bool (Dle (rho x) (Dplus (rho y) d0)) true *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq bool (Dle (rho x0) (Dplus (rho y0) d0)) true *)
    	rewrite H6 in H1. simpl in H1. inversion H1. rewrite Dmin_plus_r. apply Dmin_le_5.
(* Goal: CGeval rho f *)
    	assumption.
(* Goal: CGeval rho f *)
	apply H. rewrite (Neqb_complete _ _ H3). rewrite (Neqb_complete _ _ H4). assumption.
(* Goal: CGeval rho f *)
	intro H5. rewrite H5 in H1. simpl in H1. inversion H1. rewrite <- H7. assumption.
(* Goal: CGeval rho f *)
	intro H2. rewrite H2 in H1. apply H. assumption.
    Qed.

Lemma CG_add_2 : forall rho : ad -> D, CGsat cg2 rho -> CGsat cg1 rho.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	unfold CGsat in |- *. intros. elim (option_sum _ (CG_edge cg2 x0 y0)). intro H1. elim H1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    	intros d1 H2. cut (Dle d1 d0 = true). intro H3.
(* Goal: CGeval rho f *)
    	apply Dle_trans with (d' := Dplus (rho y0) d1). apply H. assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	apply Dle_plus_mono. apply Dle_refl.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: @eq bool (Ddle (CG_edge cg2 x0 y0) (@Some D d0)) true *)
	change (Ddle (Some d1) (Some d0) = true) in |- *. rewrite <- H2. rewrite <- H0.
(* Goal: @eq bool (Ddle (CG_edge cg2 x0 y0) (CG_edge cg1 x0 y0)) true *)
    	apply CG_add_edge_2.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
	intro H1. cut (Ddle (None) (Some d0) = true). intro H2. discriminate H2.
(* Goal: @eq bool (Ddle (CG_edge cg2 x0 y0) (@Some D d0)) true *)
	rewrite <- H1. rewrite <- H0. apply CG_add_edge_2.
    Qed.

Lemma CG_add_3 :
 forall rho : ad -> D, CGsat cg2 rho -> Dle (rho x) (Dplus (rho y) d) = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	unfold CGsat in |- *. intros. elim (option_sum _ (CG_edge cg2 x y)). intro H0. elim H0.
(* Goal: CGeval rho f *)
    	intros d0 H1. apply Dle_trans with (d' := Dplus (rho y) d0). apply H. assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	apply Dle_plus_mono. apply Dle_refl.
	rewrite (CG_add_edge_1 x y) in H1. rewrite (Neqb_correct x) in H1.
(* Goal: @eq bool (Dle (rho x) (Dplus (rho y) d0)) true *)
(* Goal: forall _ : @eq bool (andb (N.eqb x x0) (N.eqb y y0)) false, @eq bool (Dle (rho x0) (Dplus (rho y0) d0)) true *)
    	rewrite (Neqb_correct y) in H1. simpl in H1. elim (option_sum _ (CG_edge cg1 x y)).
(* Goal: @eq bool (Dle (Dmin d' d) d') true *)
    	intro H2. elim H2. intros d1 H3. rewrite H3 in H1. inversion H1. apply Dmin_le_1.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	intro H2. rewrite H2 in H1. inversion H1. apply Dle_refl.
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intro H0. rewrite (CG_add_edge_1 x y) in H0. rewrite (Neqb_correct x) in H0.
(* Goal: @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => CGSeval rho fs) *)
(* Goal: CGconsistent (M0 (Map D)) *)
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: lt (FlSize (@cons CGSForm fs (@nil CGSForm))) (S (FSize fs)) *)
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
    	rewrite (Neqb_correct y) in H0. simpl in H0. generalize H0.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    	case (CG_edge cg1 x y); intro H1. Focus 2. discriminate H1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
	intro H2. discriminate H2.
    Qed.

(*s Every path in the new graph [cg2] either goes through the new edge from [x] to [y],
       or is a path in the old graph cg1: 
*)
Lemma CG_add_4_1 :
 forall (l : list ad) (x0 y0 : ad) (d0 : D),
 CG_path cg2 y0 d0 (x0 :: l) ->
 {l0 : list ad &  {l1 : list ad | x0 :: l = l0 ++ x :: y :: l1}} +
 CG_path cg1 y0 d0 (x0 :: l).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	simple induction l. intros. inversion H. right. rewrite H2.
(* Goal: CG_path cg x Dz (@cons ad x (@nil ad)) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
        rewrite <- H1. apply CG_p1.
(* Goal: @eq bool (negb false) true *)
    	reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. inversion H0. rewrite (CG_add_edge_1 x0 a) in H6.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    	elim (sumbool_of_bool (Neqb x x0 && Neqb y a)). intro H8. left.
(* Goal: @sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) (@cons ad a (@nil ad)) (@app ad l0 (@cons ad y0 (@nil ad))))) *)
    	split with (nil (A:=ad)). split with l0. elim (andb_prop _ _ H8). intros H9 H10.
(* Goal: @eq bool (negb false) true *)
    	rewrite (Neqb_complete _ _ H9). rewrite (Neqb_complete _ _ H10). reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGFormSimplify c))), CGeval rho c0 *)
(* Goal: forall (_ : CGeval rho (CG_of_CGS (CGFormSimplify c0))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H8. elim (H _ _ _ H4). intro H9. elim H9. intros l2 H10. elim H10. intros l3 H11.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    	left. split with (x0 :: l2). split with l3. rewrite H11. reflexivity.
(* Goal: CGeval rho f *)
	intro H9. right. apply CG_p2. assumption.
(* Goal: CGeval rho f *)
	rewrite H8 in H6. assumption.
    Qed.

Lemma CG_add_4_2 :
 forall (l : list ad) (last : ad) (d0 : D),
 CG_path cg2 last d0 l -> ad_in_list y l = false -> CG_path cg1 last d0 l.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction l. intros. inversion H.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros a l0. case l0. intros. inversion H0. rewrite <- H3. apply CG_p1. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. inversion H0. rewrite (CG_add_edge_1 a a0) in H7. elim (orb_false_elim _ _ H1).
(* Goal: forall (_ : @eq bool (N.eqb y a) false) (_ : @eq bool (orb (N.eqb y a0) ((fix ad_in_list (a : ad) (l : list ad) {struct l} : bool := match l with | nil => false | cons a' l' => orb (N.eqb a a') (ad_in_list a l') end) y l1)) false), CG_path cg1 last (Dplus d1 d') (@cons ad a (@cons ad a0 l1)) *)
    	intros H9 H10. elim (orb_false_elim _ _ H10). 
(* Goal: forall (_ : prod (CG_path cg2 y0 d1 (@app ad (@cons ad x0 l0) (@cons ad y0 (@nil ad)))) (CG_path cg2 x0 d2 (@cons ad y0 (@app ad l1 (@cons ad y0 l2))))) (_ : @eq D d0 (Dplus d2 d1)), @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
        intros H11 H12. rewrite H11 in H7.
(* Goal: CGeval rho f *)
    	rewrite (andb_b_false (Neqb x a)) in H7. apply CG_p2. apply H. assumption.
(* Goal: @eq bool (ad_in_list y (@cons ad a0 l1)) false *)
(* Goal: @eq (option D) (CG_edge cg1 a a0) (@Some D d') *)
	exact H10.
(* Goal: CGeval rho f *)
	assumption.
    Qed.

Lemma CG_add_4_3 :
 forall (x0 : ad) (d0 : D) (l : list ad),
 ad_list_stutters (y :: l) = false ->
 CG_path cg2 x0 d0 (y :: l) -> CG_path cg1 x0 d0 (y :: l).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	intros x0 d0 l. elim l. intros. inversion H0. 
(* Goal: CGeval rho f *)
        rewrite <- H2. apply CG_p1. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. inversion H1. apply CG_p2. apply CG_add_4_2. 
(* Goal: CGeval rho f *)
        assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	elim (orb_false_elim _ _ H0). trivial.
(* Goal: @eq (option D) (CG_edge cg1 y a) (@Some D d') *)
	rewrite (CG_add_edge_1 y a) in H7. 
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
        elim (orb_false_elim _ _ H0). intros.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	elim (orb_false_elim _ _ H8). intros. rewrite H10 in H7.
(* Goal: CGeval rho f *)
    	rewrite (andb_b_false (Neqb x y)) in H7. assumption.
    Qed.

Lemma CG_add_4_4 :
 forall (l : list ad) (last : ad) (d0 : D),
 CG_path cg2 last d0 l -> ad_in_list x l = false -> CG_path cg1 last d0 l.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	simple induction l. intros. inversion H.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros a l0. case l0. intros. inversion H0. rewrite <- H3. apply CG_p1. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. inversion H0. apply CG_p2. apply H. assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	elim (orb_false_elim _ _ H1). trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	rewrite (CG_add_edge_1 a a0) in H7. elim (orb_false_elim _ _ H1). intros.
(* Goal: @eq (option D) (CG_edge cg1 a a0) (@Some D d') *)
    	rewrite H8 in H7. exact H7.
    Qed.

Lemma CG_add_4_5 :
 forall (d0 : D) (l : list ad),
 ad_list_stutters (l ++ x :: nil) = false ->
 CG_path cg2 x d0 (l ++ x :: nil) -> CG_path cg1 x d0 (l ++ x :: nil).
    Proof.
(* Goal: forall (d0 : D) (l : list ad) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
    	intros d0 l. cut ({l0 : list ad &  {y0 : ad | l = l0 ++ y0 :: nil}} + {l = nil}).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    	intro. elim H. intro H0. elim H0. intros l0 H1. elim H1. intros y0 H2 H3 H4.
(* Goal: CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	rewrite H2 in H4. rewrite (app_ass l0 (y0 :: nil) (x :: nil)) in H4.
(* Goal: CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	simpl in H4. elim (CG_path_app_3 cg2 l0 (x :: nil) x y0 d0 H4). intros d1 H5.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	rewrite H2. rewrite (app_ass l0 (y0 :: nil) (x :: nil)). simpl in |- *.
(* Goal: CG_path cg1 x d0 (@app ad l0 (@cons ad y0 (@cons ad x (@nil ad)))) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	elim (CG_path_app_2 cg2 l0 (x :: nil) x y0 d0 H4). intros d2 H6.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    	cut (d0 = Dplus d2 d1). intro. rewrite H7.
    	change (CG_path cg1 x (Dplus d2 d1) (l0 ++ (y0 :: nil) ++ x :: nil))
      in |- *.
(* Goal: CG_path cg2 x (Dplus d2 d1) (@app ad l0 (@app ad (@cons ad y0 (@nil ad)) (@cons ad x (@nil ad)))) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	rewrite <- (app_ass l0 (y0 :: nil) (x :: nil)).
(* Goal: CG_path cg1 x (Dplus d2 d1) (@app ad (@app ad l0 (@cons ad y0 (@nil ad))) (@cons ad x (@nil ad))) *)
(* Goal: @eq D d0 (Dplus d2 d1) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	apply CG_path_app_1 with (last := x) (x := y0). inversion H6. 
(* Goal: CG_path cg1 y (Dplus Dz d'0) (@cons ad x (@cons ad y (@nil ad))) *)
(* Goal: forall _ : @eq (option D) (CG_edge cg1 x y) (@None D), @eq bool (Dle Dz (Dplus (Dplus d1 d3) d')) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
        inversion H11. apply CG_p2.
(* Goal: CGeval rho f *)
    	rewrite <- H15. apply CG_p1. assumption.
(* Goal: @eq bool (ad_in_list x (@app ad l0 (@cons ad y0 (@nil ad)))) false *)
(* Goal: @eq D d0 (Dplus d2 d1) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
	rewrite (CG_add_edge_1 y0 x) in H13. rewrite H2 in H3.
(* Goal: @eq (option D) (CG_edge cg1 y0 x) (@Some D d') *)
(* Goal: CG_path cg1 y0 d1 (@app ad l0 (@cons ad y0 (@nil ad))) *)
(* Goal: @eq D d0 (Dplus d2 d1) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	rewrite (app_ass l0 (y0 :: nil) (x :: nil)) in H3. simpl in H3.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	elim (orb_false_elim _ _ (ad_list_stutters_app_conv_r _ _ H3)). intros.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	elim (orb_false_elim _ _ H17). intros. 
(* Goal: @eq (option D) (CG_edge cg1 y0 x) (@Some D d') *)
(* Goal: CG_path cg1 y0 d1 (@app ad l0 (@cons ad y0 (@nil ad))) *)
(* Goal: @eq D d0 (Dplus d2 d1) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
        rewrite (Neqb_comm y0 x) in H19.
(* Goal: @eq (option D) (CG_edge cg1 y0 x) (@Some D d') *)
(* Goal: CG_path cg1 y0 d1 (@app ad l0 (@cons ad y0 (@nil ad))) *)
(* Goal: @eq D d0 (Dplus d2 d1) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	rewrite H19 in H13. 
(* Goal: CGeval rho f *)
        rewrite (andb_false_b (Neqb y x)) in H13. assumption.
(* Goal: CGeval rho f *)
	apply CG_add_4_4. assumption.
(* Goal: CGeval rho f *)
	rewrite H2 in H3. apply ad_list_stutters_prev_conv_l with (l' := nil (A:=ad)). assumption.
	elim
  (CG_path_weight_and_last_unique cg2 (l0 ++ y0 :: x :: nil) x x d0
     (Dplus d2 d1)).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    	trivial.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: CG_path cg2 x (Dplus d2 d1) (@app ad l0 (@cons ad y0 (@cons ad x (@nil ad)))) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
	change (CG_path cg2 x (Dplus d2 d1) (l0 ++ (y0 :: nil) ++ x :: nil)) in |- *.
(* Goal: CG_path cg2 x (Dplus d2 d1) (@app ad l0 (@app ad (@cons ad y0 (@nil ad)) (@cons ad x (@nil ad)))) *)
(* Goal: forall (_ : @eq (list ad) l (@nil ad)) (_ : @eq bool (ad_list_stutters (@app ad l (@cons ad x (@nil ad)))) false) (_ : CG_path cg2 x d0 (@app ad l (@cons ad x (@nil ad)))), CG_path cg1 x d0 (@app ad l (@cons ad x (@nil ad))) *)
(* Goal: sumor (@sigT (list ad) (fun l0 : list ad => @sig ad (fun y0 : ad => @eq (list ad) l (@app ad l0 (@cons ad y0 (@nil ad)))))) (@eq (list ad) l (@nil ad)) *)
    	rewrite <- (app_ass l0 (y0 :: nil) (x :: nil)).
(* Goal: CGeval rho f *)
    	apply CG_path_app_1 with (x := y0). assumption.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intro H0. rewrite H0. simpl in |- *. intros. inversion H2. 
(* Goal: CG_path cg x Dz (@cons ad x (@nil ad)) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
        rewrite <- H4. apply CG_p1.
(* Goal: CGeval rho f *)
    	assumption.
(* Goal: @eq bool (negb false) true *)
	elim l. right. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. elim H. intro H0. elim H0. intros l1 H1. elim H1. intros a0 H2. rewrite H2.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    	left. split with (a :: l1). split with a0. reflexivity.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
	intro H0. rewrite H0. left. split with (nil (A:=ad)). split with a. reflexivity.
    Qed.

(*s If there is no cycle of negative weight in the old graph [cg1], and the distance
   from [y] to [x] is $\geq -d$, then there is no simple cycle of negative weight in 
   the new graph  [cg2] either: *)

Lemma CG_add_4 :
 (forall (x0 : ad) (d0 : D) (l : list ad),
  CG_path cg1 x0 d0 (x0 :: l) -> Dle Dz d0 = true) ->
 Ddle (Some (Dneg d)) (ad_simple_path_dist cg1 y x) = true ->
 forall (x0 : ad) (d0 : D) (l : list ad),
 CG_path cg2 x0 d0 (x0 :: l) ->
 ad_list_stutters l = false -> Dle Dz d0 = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	intros. elim (CG_add_4_1 _ _ _ _ H1). intro H3. elim H3. intros l0 H4. elim H4.
(* Goal: sumbool (@eq ad a0 root) (@eq bool (in_dom (Map D) a0 cg) true) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg root) (@None (Map D)), sumbool (@eq ad a0 root) (@eq bool (in_dom (Map D) a0 cg) true) *)
    	intros l1 H5. rewrite H5 in H1.
(* Goal: @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	change (CG_path cg2 x0 d0 (l0 ++ (x :: nil) ++ y :: l1)) in H1.
(* Goal: and (CGSeval rho (CGSor c c0)) (CGSeval_l rho l) *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: lt (FlSize (@cons CGSForm c0 l)) n *)
(* Goal: @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
    	elim (CG_path_app_4 cg2 _ _ _ _ _ H1). intros d1 H6. elim H6. intros d2 H7.
(* Goal: @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	elim H7. intros H8 H9. elim H8. intros H10 H11. clear H3 H6 H7 H8. rewrite H9.
(* Goal: @eq bool (Dle Dz (Dplus d2 d1)) true *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	inversion_clear H11. rewrite (CG_add_edge_1 x y) in H6. rewrite (Neqb_correct x) in H6.
(* Goal: @eq bool (Dle Dz (Dplus (Dplus d3 d') d1)) true *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	rewrite (Neqb_correct y) in H6. simpl in H6. apply Dplus_reg_r with (d'' := Dneg d1).
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    	rewrite Dplus_assoc. rewrite Dplus_neg. rewrite Dplus_d_z. rewrite Dplus_z_d.
(* Goal: @eq bool (Dle (rho y) (Dplus (rho y) (Dplus d (Dneg d)))) true *)
    	apply Dplus_reg_l with (d'' := d1). rewrite Dplus_neg. rewrite <- Dplus_assoc.
(* Goal: @eq bool (Dle Dz (Dplus (Dplus d1 d3) d')) true *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	change (x0 :: l = l0 ++ (x :: nil) ++ y :: l1) in H5.
(* Goal: @eq bool (Dle Dz (Dplus (Dplus d1 d3) d')) true *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	rewrite (ass_app l0 (x :: nil) (y :: l1)) in H5.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    	cut {l'0 : list ad | l0 ++ x :: nil = x0 :: l'0}. intro H7. elim H7.
(* Goal: forall (x1 : list ad) (_ : @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 x1)), @eq bool (Dle Dz (Dplus (Dplus d1 d3) d')) true *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	intros l'0 H8. clear H4 H7. rewrite H8 in H5. simpl in H5. inversion H5. rewrite H8 in H10.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    	cut (CG_path cg1 x (Dplus d1 d3) (y :: l1 ++ l'0)). intro.
(* Goal: @eq bool (Dle Dz (Dplus (Dplus d1 d3) d')) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	elim (option_sum _ (CG_edge cg1 x y)). intro H11. elim H11. intros d'0 H12.
(* Goal: @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 a y (@cons ad x prefix) n0) (@None D), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
(* Goal: @eq bool (ad_in_list a (@cons ad x prefix)) false *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sigT (list ad) (fun l : list ad => and_sp (CG_path y (Dplus d0 d') (@app ad (@rev ad (@cons ad x prefix)) l)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false) (le (@length ad l) (S n0)))) *)
    	rewrite H12 in H6. inversion_clear H6. elim (Dmin_choice d d'0). intro H13. rewrite H13.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    	apply Dplus_reg_r with (d'' := Dneg d). rewrite Dplus_assoc. rewrite Dplus_neg.
(* Goal: @eq bool (Dle (Dplus Dz Done) (Dplus (Dneg d) d')) true *)
    	rewrite Dplus_d_z. rewrite Dplus_z_d.
(* Goal: @eq bool (Dle (Dneg d) (Dplus d1 d3)) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	change (Ddle (Some (Dneg d)) (Some (Dplus d1 d3)) = true) in |- *.
(* Goal: CGeval rho f *)
    	apply Ddle_trans with (dd' := ad_simple_path_dist cg1 y x). assumption.
(* Goal: @eq bool (Ddle (ad_simple_path_dist cg1 y x) (@Some D (Dplus d1 d3))) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
	exact (ad_simple_path_dist_correct cg1 H y x _ _ H4).
(* Goal: forall _ : @eq D (Dmin d d'0) d'0, @eq bool (Dle Dz (Dplus (Dplus d1 d3) (Dmin d d'0))) true *)
(* Goal: forall _ : @eq (option D) (CG_edge cg1 x y) (@None D), @eq bool (Dle Dz (Dplus (Dplus d1 d3) d')) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
	intro H13. rewrite H13. apply (H x (Dplus (Dplus d1 d3) d'0) (y :: l1 ++ l'0)).
(* Goal: CGeval rho f *)
    	apply (CG_path_app_1 cg1 (x :: y :: nil) (l1 ++ l'0) x y). assumption.
(* Goal: @eq bool (negb false) true *)
	rewrite <- (Dplus_z_d d'0). apply CG_p2. apply CG_p1. reflexivity.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
	intro H11. rewrite H11 in H6. inversion H6. rewrite <- H13.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    	apply Dplus_reg_r with (d'' := Dneg d). rewrite Dplus_assoc. rewrite Dplus_neg.
(* Goal: @eq bool (Dle (Dplus Dz Done) (Dplus (Dneg d) d')) true *)
    	rewrite Dplus_d_z. rewrite Dplus_z_d.
(* Goal: @eq bool (Dle (Dneg d) (Dplus d1 d3)) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	change (Ddle (Some (Dneg d)) (Some (Dplus d1 d3)) = true) in |- *.
(* Goal: CGeval rho f *)
    	apply Ddle_trans with (dd' := ad_simple_path_dist cg1 y x). assumption.
(* Goal: @eq bool (Ddle (ad_simple_path_dist cg1 y x) (@Some D (Dplus d1 d3))) true *)
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
	exact (ad_simple_path_dist_correct cg1 H y x _ _ H4).
(* Goal: CG_path cg1 x (Dplus d1 d3) (@cons ad y (@app ad l1 l'0)) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
	apply (CG_path_app_1 cg1 (y :: l1) l'0 x x0). rewrite <- H8. apply CG_add_4_5.
(* Goal: le (S (Init.Nat.add (@length ad l1) (S O))) (@length ad l) *)
(* Goal: le (@length ad l) (S n0) *)
(* Goal: @eq bool (Dle d1 d1) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	rewrite H8. elim (CG_path_last cg2 _ _ _ H3). intros l'1 H11. rewrite H7 in H2.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	simpl in |- *. rewrite (ad_list_stutters_app_conv_l _ _ H2). rewrite H11 in H2.
(* Goal: @eq bool (orb (ad_in_list x0 l'0) false) false *)
(* Goal: CG_path cg2 x d1 (@app ad l0 (@cons ad x (@nil ad))) *)
(* Goal: CG_path cg1 x0 d3 (@cons ad y l1) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	rewrite (ass_app l'0 l'1 (x0 :: nil)) in H2.
(* Goal: @eq bool (orb (ad_in_list x0 l'0) false) false *)
(* Goal: CG_path cg2 x d1 (@app ad l0 (@cons ad x (@nil ad))) *)
(* Goal: CG_path cg1 x0 d3 (@cons ad y l1) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	elim (sumbool_of_bool (ad_in_list x0 l'0)). intro H12.
    	rewrite (ad_list_stutters_prev_l _ nil _ (ad_in_list_l l'0 l'1 x0 H12))
       in H2.
(* Goal: @eq bool (orb (ad_in_list x0 l'0) false) false *)
(* Goal: forall _ : @eq bool (ad_in_list x0 l'0) false, @eq bool (orb (ad_in_list x0 l'0) false) false *)
(* Goal: CG_path cg2 x d1 (@app ad l0 (@cons ad x (@nil ad))) *)
(* Goal: CG_path cg1 x0 d3 (@cons ad y l1) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
    	discriminate H2.
(* Goal: @eq bool (negb false) true *)
	intro H12. rewrite H12. reflexivity.
(* Goal: CGeval rho f *)
	rewrite H8. assumption.
(* Goal: @eq bool (ad_list_stutters (@cons ad y l1)) false *)
(* Goal: CG_path cg2 x0 d3 (@cons ad y l1) *)
(* Goal: @sig (list ad) (fun l'0 : list ad => @eq (list ad) (@app ad l0 (@cons ad x (@nil ad))) (@cons ad x0 l'0)) *)
(* Goal: forall _ : CG_path cg1 x0 d0 (@cons ad x0 l), @eq bool (Dle Dz d0) true *)
	apply CG_add_4_3. rewrite H7 in H2. exact (ad_list_stutters_app_conv_r l'0 (y :: l1) H2).
(* Goal: CGeval rho f *)
	assumption.
(* Goal: @eq bool (negb false) true *)
	generalize H5. elim l0. simpl in |- *. intro H7. exists (nil (A:=ad)). inversion_clear H7. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. rewrite (app_ass (a :: l2) (x :: nil) (y :: l1)) in H8. simpl in H8.
(* Goal: @eq bool (negb false) true *)
    	exists (l2 ++ x :: nil). inversion_clear H8. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	intro H3. exact (H x0 d0 l H3).
    Qed.

Lemma CG_add_5_1 :
 forall n : nat,
 (forall (x0 : ad) (d0 : D) (l : list ad),
  CG_path cg1 x0 d0 (x0 :: l) -> Dle Dz d0 = true) ->
 Ddle (Some (Dneg d)) (ad_simple_path_dist cg1 y x) = true ->
 forall (x0 : ad) (d0 : D) (l : list ad),
 CG_path cg2 x0 d0 (x0 :: l) -> length l <= n -> Dle Dz d0 = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	simple induction n. simple induction l. intros. inversion H1. apply Dle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. elim (le_Sn_O _ H3).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	intros. elim (sumbool_of_bool (ad_list_stutters l)). intros H4.
(* Goal: and (CGSeval rho (CGSor c c0)) (CGSeval_l rho l) *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: lt (FlSize (@cons CGSForm c0 l)) n *)
(* Goal: @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
    	elim (ad_list_stutters_has_circuit l H4). intros y0 H5. elim H5. intros l0 H6. elim H6.
(* Goal: @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	intros l1 H7. elim H7. intros l2 H8. rewrite H8 in H2.
(* Goal: forall (x : D) (_ : @sigT D (fun d2 : D => and_sp (prod (CG_path cg2 y0 x (@app ad (@cons ad x0 l0) (@cons ad y0 (@nil ad)))) (CG_path cg2 x0 d2 (@cons ad y0 (@app ad l1 (@cons ad y0 l2))))) (@eq D d0 (Dplus d2 x)))), @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	elim (CG_path_app_4 cg2 (x0 :: l0) (l1 ++ y0 :: l2) x0 y0 d0 H2). intros d1 H9.
(* Goal: @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: forall _ : @eq (option D) (MapGet D edges a) (@None D), @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
    	elim H9. intros d2 H10. elim H10. intros H11 H12. elim H11. intros H13 H14.
(* Goal: @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	clear H5 H6 H7 H9 H10 H11. elim (CG_path_app_4 cg2 (y0 :: l1) l2 x0 y0 d2 H14).
(* Goal: @eq bool (Dle Dz d0) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	intros d3 H5. elim H5. intros d4 H6. elim H6. intros H7 H9. elim H7. intros H10 H11.
(* Goal: @eq bool (Ddle (if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges) (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d')) true *)
(* Goal: @eq bool (ad_in_list x prefix) false *)
(* Goal: @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
    	clear H5 H6 H7 H14. rewrite H12. rewrite H9. apply Dle_trans with (d' := Dplus d4 d1).
(* Goal: @eq bool (Dle Dz (Dplus d4 d1)) true *)
(* Goal: @eq bool (Dle (Dplus d4 d1) (Dplus (Dplus d4 d3) d1)) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	apply (H H0 H1 x0 (Dplus d4 d1) (l0 ++ y0 :: l2)).
(* Goal: CG_path cg2 x0 (Dplus d4 d1) (@cons ad x0 (@app ad l0 (@cons ad y0 l2))) *)
(* Goal: le (@length ad (@app ad l0 (@cons ad y0 l2))) n0 *)
(* Goal: @eq bool (Dle (Dplus d4 d1) (Dplus (Dplus d4 d3) d1)) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	cut (x0 :: l0 ++ y0 :: l2 = ((x0 :: l0) ++ y0 :: nil) ++ l2).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    	intro. rewrite H5. exact (CG_path_app_1 cg2 _ _ _ _ _ _ H11 H13).
(* Goal: @eq (list ad) (@cons ad x0 (@app ad l0 (@cons ad y0 l2))) (@app ad (@app ad (@cons ad x0 l0) (@cons ad y0 (@nil ad))) l2) *)
(* Goal: le (@length ad (@app ad l0 (@cons ad y0 l2))) n0 *)
(* Goal: @eq bool (Dle (Dplus d4 d1) (Dplus (Dplus d4 d3) d1)) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
	exact (ass_app (x0 :: l0) (y0 :: nil) l2).
(* Goal: le (S (Init.Nat.add (@length ad l1) (S O))) (Init.Nat.add (@length ad l0) (S (@length ad (@app ad l1 (@cons ad y0 l2))))) *)
(* Goal: le (@length ad l) (S n0) *)
(* Goal: @eq bool (Dle d1 d1) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
	rewrite ad_list_app_length. apply le_S_n. apply le_trans with (m := length l).
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	rewrite H8. rewrite ad_list_app_length. simpl in |- *. rewrite ad_list_app_length. simpl in |- *.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	rewrite <- plus_Snm_nSm. rewrite <- plus_Snm_nSm. rewrite <- plus_Snm_nSm. simpl in |- *.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	rewrite <- plus_Snm_nSm. simpl in |- *. apply le_n_S. apply le_n_S. apply plus_le_compat_l.
(* Goal: CGeval rho f *)
    	apply le_plus_r. assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	apply Dle_plus_mono. apply Dle_trans with (Dplus d4 Dz). rewrite Dplus_d_z. apply Dle_refl.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    	apply Dle_plus_mono. apply Dle_refl.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	apply (H H0 H1 y0 d3 (l1 ++ y0 :: nil) H10). rewrite ad_list_app_length. simpl in |- *.
(* Goal: le (S (Init.Nat.add (@length ad l1) (S O))) (@length ad l) *)
(* Goal: le (@length ad l) (S n0) *)
(* Goal: @eq bool (Dle d1 d1) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
    	apply le_S_n. apply le_trans with (m := length l). rewrite H8. rewrite ad_list_app_length.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	simpl in |- *. rewrite ad_list_app_length. simpl in |- *. rewrite <- plus_Snm_nSm. rewrite <- plus_Snm_nSm.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
    	rewrite <- plus_Snm_nSm. simpl in |- *. rewrite <- plus_Snm_nSm. simpl in |- *. apply le_n_S. apply le_n_S.
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: CGsat (M0 (Map D)) rho *)
(* Goal: CGSeval_l rho (@cons CGSForm fs (@nil CGSForm)) *)
    	apply le_trans with (m := length l1 + length l2). apply plus_le_compat. apply le_n.
(* Goal: CGeval rho f *)
    	apply le_O_n. apply le_plus_r. assumption.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
	apply Dle_refl.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
	intro H4. exact (CG_add_4 H0 H1 x0 d0 l H2 H4).
    Qed.

Lemma CG_add_5 :
 (forall (x0 : ad) (d0 : D) (l : list ad),
  CG_path cg1 x0 d0 (x0 :: l) -> Dle Dz d0 = true) ->
 Ddle (Some (Dneg d)) (ad_simple_path_dist cg1 y x) = true ->
 forall (x0 : ad) (d0 : D) (l : list ad),
 CG_path cg2 x0 d0 (x0 :: l) -> Dle Dz d0 = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    	intros. exact (CG_add_5_1 (length l) H H0 x0 d0 l H1 (le_n _)).
    Qed.

  End CGAdd.

(*s Properties of the range of the graph *)

Definition cg_range := DMerge D.

Lemma cg_range_1 :
 forall (cg : CGraph1) (x y : ad) (d : D),
 CG_edge cg x y = Some d -> in_dom D y (cg_range cg) = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold cg_range, CG_edge in |- *. intros. elim (option_sum _ (MapGet _ cg x)). intro H0. elim H0.
(* Goal: CGeval rho f *)
    intros edges H1. rewrite H1 in H. apply in_dom_DMerge_3 with (a := x) (m0 := edges). assumption.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    unfold in_dom in |- *. generalize H. case (MapGet D edges y). Focus 2. intro H2. discriminate H2.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    trivial.
(* Goal: False *)
    intro H0. rewrite H0 in H. discriminate H.
  Qed.

Lemma cg_range_2 :
 forall (cg : CGraph1) (y : ad),
 in_dom D y (cg_range cg) = true ->
 {x : ad &  {d : D | CG_edge cg x y = Some d}}.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. elim (in_dom_DMerge_2 _ cg y H). intros x H0. elim H0. intros edges H1. elim H1.
(* Goal: @sig D (fun d : D => @eq (option D) (CG_edge cg x y) (@Some D d)) *)
    intros H2 H3. split with x. elim (in_dom_some _ edges y H3). intros d H4. split with d.
(* Goal: @eq bool (negb false) true *)
    unfold CG_edge in |- *. rewrite H2. rewrite H4. reflexivity.
  Qed.

Lemma cg_range_4 :
 forall (cg : CGraph1) (x y : ad) (d : D) (a : ad),
 in_dom D a (cg_range (CG_add cg x y d)) =
 Neqb a y || in_dom D a (cg_range cg).
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. elim (sumbool_of_bool (in_dom D a (cg_range (CG_add cg x y d)))). intro H.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
    elim (cg_range_2 _ _ H). intros a0 H0. elim H0. intros d0 H1. clear H0.
    change (CG_edge (cg2 cg x y d) a0 a = Some d0) in H1.
(* Goal: forall _ : @eq bool (Dle d' d) true, @eq bool (Dle (Dplus (Dneg d) d') Dz) false *)
(* Goal: @eq bool (Dle d' d) true *)
(* Goal: forall _ : @eq bool (Dle (Dplus (Dneg d) d') Dz) false, @eq bool (Dle (Dplus (Dneg d) d') Dz) false *)
    rewrite (CG_add_edge_1 cg x y d a0 a) in H1. rewrite H.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    elim (sumbool_of_bool (Neqb x a0 && Neqb y a)). intro H2. elim (andb_prop _ _ H2).
(* Goal: @eq bool (negb false) true *)
    intros H3 H4. rewrite (Neqb_comm y a) in H4. rewrite H4. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    intro H2. rewrite H2 in H1. rewrite (cg_range_1 _ _ _ _ H1). apply sym_eq. apply orb_b_true.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H. rewrite H. elim (sumbool_of_bool (Neqb a y)). intro H0.
    rewrite (Neqb_complete _ _ H0) in H. cut {d0 : D | CG_edge (cg2 cg x y d) x y = Some d0}.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    intro H1. elim H1. intros d0 H2. unfold cg2 in H2. rewrite (cg_range_1 _ _ _ _ H2) in H.
(* Goal: False *)
    discriminate H.
(* Goal: @eq bool (Ddle (if N.eqb y y then @Some D Dz else match MapGet (Map D) cg y with | Some edges => if ad_in_list y prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z y) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad y prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
    rewrite (CG_add_edge_1 cg x y d x y). rewrite (Neqb_correct x). rewrite (Neqb_correct y).
(* Goal: @eq bool (negb false) true *)
    case (CG_edge cg x y). Focus 2. split with d. reflexivity.
(* Goal: @eq bool (negb false) true *)
    intro d0. split with (Dmin d d0). reflexivity.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    intro H0. rewrite H0. elim (sumbool_of_bool (in_dom D a (cg_range cg))). intro H1.
(* Goal: or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    elim (cg_range_2 _ _ H1). intros a0 H2. elim H2. intros d0 H3.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
    cut {d1 : D | CG_edge (cg2 cg x y d) a0 a = Some d1}. intro H4. elim H4. intros d1 H5.
(* Goal: False *)
    unfold cg2 in H5. rewrite (cg_range_1 _ _ _ _ H5) in H. discriminate H.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    rewrite (CG_add_edge_1 cg x y d a0 a). rewrite (Neqb_comm a y) in H0. rewrite H0.
(* Goal: CGeval rho f *)
    rewrite (andb_b_false (Neqb x a0)). split with d0. assumption.
(* Goal: @eq bool (negb false) true *)
    intro H1. rewrite H1. reflexivity.
  Qed.

Lemma cg_out_of_range_1 :
 forall (cg : CGraph1) (y : ad),
 in_dom D y (cg_range cg) = false -> forall x : ad, CG_edge cg x y = None.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. elim (option_sum _ (CG_edge cg x y)). intro H0. elim H0. intros d H1.
(* Goal: False *)
    rewrite (cg_range_1 cg x y d H1) in H. discriminate H.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    trivial.
  Qed.

Lemma cg_out_of_range_2 :
 forall (cg : CGraph1) (y : ad),
 in_dom D y (cg_range cg) = false ->
 forall x : ad, Neqb x y = false -> ad_simple_path_dist cg x y = None.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. elim (option_sum _ (ad_simple_path_dist cg x y)). intro H1. elim H1. intros d H2.
(* Goal: forall (x0 : list ad) (_ : CG_path cg y d (@cons ad x x0)), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
    elim (ad_simple_path_dist_complete_2 cg x y d H2). intros l H3.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
    cut {a : ad &  {d' : D | CG_edge cg a y = Some d'}}. intro H4. elim H4. intros a H5. elim H5.
(* Goal: @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
(* Goal: @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
    intros d' H6. rewrite (cg_out_of_range_1 cg y H a) in H6. discriminate H6.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    generalize x H0 d H3. elim l. intros. inversion H5. 
(* Goal: @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall (a : ad) (l : list ad) (_ : forall (x : ad) (_ : @eq bool (N.eqb x y) false) (d : D) (_ : CG_path cg y d (@cons ad x l)), @sigT ad (fun a0 : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a0 y) (@Some D d')))) (x : ad) (_ : @eq bool (N.eqb x y) false) (d : D) (_ : CG_path cg y d (@cons ad x (@cons ad a l))), @sigT ad (fun a0 : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a0 y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
    rewrite H8 in H4.
(* Goal: @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall (a : ad) (l : list ad) (_ : forall (x : ad) (_ : @eq bool (N.eqb x y) false) (d : D) (_ : CG_path cg y d (@cons ad x l)), @sigT ad (fun a0 : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a0 y) (@Some D d')))) (x : ad) (_ : @eq bool (N.eqb x y) false) (d : D) (_ : CG_path cg y d (@cons ad x (@cons ad a l))), @sigT ad (fun a0 : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a0 y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
    rewrite (Neqb_correct y) in H4. discriminate H4.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. inversion H6. elim (sumbool_of_bool (Neqb a y)). 
(* Goal: forall _ : @eq bool (N.eqb a y) false, @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
    intro H14. split with x0.
(* Goal: CGeval rho f *)
    split with d'. rewrite <- (Neqb_complete _ _ H14). assumption.
(* Goal: forall _ : @eq bool (N.eqb a y) false, @sigT ad (fun a : ad => @sig D (fun d' : D => @eq (option D) (CG_edge cg a y) (@Some D d'))) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist cg x y) (@None D), @eq (option D) (ad_simple_path_dist cg x y) (@None D) *)
    intro H14. exact (H4 a H14 _ H10).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    trivial.
  Qed.

Lemma cg_out_of_range_3 :
 forall (cg : CGraph1) (y : ad),
 in_dom D y (cg_range cg) = false ->
 forall x : ad, Neqb x y = false -> CG_leq cg x y = false.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. unfold CG_leq in |- *. rewrite (cg_out_of_range_2 cg y H x H0). reflexivity.
  Qed.

Lemma cg_add_out_of_range_1 :
 forall (cg : CGraph1) (x y : ad) (d : D),
 (forall (x0 : ad) (d0 : D) (l : list ad),
  CG_path cg x0 d0 (x0 :: l) -> Dle Dz d0 = true) ->
 in_dom D x (cg_range cg) = false ->
 Neqb y x = false ->
 forall (x0 : ad) (d0 : D) (l : list ad),
 CG_path (CG_add cg x y d) x0 d0 (x0 :: l) -> Dle Dz d0 = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply (CG_add_5 cg x y d H) with (x0 := x0) (l := l).
(* Goal: @eq bool (negb false) true *)
    rewrite (cg_out_of_range_2 cg x H0 y H1). reflexivity.
(* Goal: CGeval rho f *)
    assumption.
  Qed.


Lemma cg_add_dom_subset :
 forall (cg : CGraph1) (x y : ad) (d : D),
 MapSubset _ _ (MapDom _ cg) (MapDom _ (CG_add cg x y d)).
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CG_add in |- *. intros. elim (option_sum _ (MapGet _ cg x)). intro H. elim H. intros edges H0.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    rewrite H0. elim (option_sum _ (MapGet D edges y)). intro H1. elim H1. intros d0 H2.
(* Goal: @eq nat (S m) (Init.Nat.add (S m') (MapCard (Map D) cg)) *)
    rewrite H2. apply MapSubset_Dom_1. apply MapSubset_Put.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    intro H1. rewrite H1. apply MapSubset_Dom_1. apply MapSubset_Put.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H. rewrite H. apply MapSubset_Dom_1. apply MapSubset_Put.
  Qed.

(*s Adding a lis of adresses connected to [root] with weight $0$ *)

Fixpoint CG_add_root (root : ad) (cg : CGraph1) (l : list ad) {struct l} :
 CGraph1 :=
  match l with
  | nil => cg
  | x :: l' => CG_add_root root (CG_add cg root x Dz) l'
  end.

Lemma CG_add_root_out_of_range :
 forall (l : list ad) (cg : CGraph1) (root : ad),
 (forall (x0 : ad) (d0 : D) (l : list ad),
  CG_path cg x0 d0 (x0 :: l) -> Dle Dz d0 = true) ->
 MapSubset _ _ (Elems l) (MapDom _ cg) ->
 ad_in_list root l = false ->
 in_dom _ root (cg_range cg) = false ->
 forall (x0 : ad) (d0 : D) (l0 : list ad),
 CG_path (CG_add_root root cg l) x0 d0 (x0 :: l0) -> Dle Dz d0 = true.
    Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    	simple induction l. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	simpl in |- *. intros. apply (H (CG_add cg root a Dz) root) with (x0 := x0) (d0 := d0) (l1 := l1). intros.
    	apply
      (cg_add_out_of_range_1 cg root a Dz)
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
       with (x0 := x1) (d0 := d1) (l := l2). intros.
(* Goal: @eq bool (Dle Dz d2) true *)
(* Goal: @eq bool (in_dom D root (cg_range cg)) false *)
(* Goal: @eq bool (N.eqb a root) false *)
(* Goal: CG_path (CG_add cg root a Dz) x1 d1 (@cons ad x1 l2) *)
(* Goal: MapSubset unit unit (Elems l0) (MapDom (Map D) (CG_add cg root a Dz)) *)
(* Goal: @eq bool (ad_in_list root l0) false *)
(* Goal: @eq bool (in_dom D root (cg_range (CG_add cg root a Dz))) false *)
(* Goal: CG_path (CG_add_root root (CG_add cg root a Dz) l0) x0 d0 (@cons ad x0 l1) *)
    	exact (H0 _ _ _ H6).
(* Goal: CGeval rho f *)
	assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
	elim (orb_false_elim _ _ H2). intros. rewrite Neqb_comm. assumption.
(* Goal: CGeval rho f *)
	assumption.
(* Goal: MapSubset unit unit (Elems l0) (MapPut unit (Elems l0) a tt) *)
(* Goal: MapSubset unit unit (MapPut unit (Elems l0) a tt) (MapDom (Map D) (CG_add cg root a Dz)) *)
(* Goal: @eq bool (ad_in_list root l0) false *)
(* Goal: @eq bool (in_dom D root (cg_range (CG_add cg root a Dz))) false *)
(* Goal: CG_path (CG_add_root root (CG_add cg root a Dz) l0) x0 d0 (@cons ad x0 l1) *)
	apply MapSubset_trans with (m' := MapPut unit (Elems l0) a tt). apply MapSubset_Put.
(* Goal: CGeval rho f *)
	apply MapSubset_trans with (m' := MapDom _ cg). assumption.
(* Goal: MapSubset unit unit (MapDom (Map D) cg) (MapDom (Map D) (CG_add cg root a Dz)) *)
(* Goal: @eq bool (ad_in_list root l0) false *)
(* Goal: @eq bool (in_dom D root (cg_range (CG_add cg root a Dz))) false *)
(* Goal: CG_path (CG_add_root root (CG_add cg root a Dz) l0) x0 d0 (@cons ad x0 l1) *)
	apply cg_add_dom_subset.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
	elim (orb_false_elim _ _ H2). trivial.
(* Goal: @eq bool (Ddle (@Some D Dz) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
	rewrite cg_range_4. elim (orb_false_elim _ _ H2). intros H5 H6. rewrite H5. rewrite H3.
(* Goal: @eq bool (negb false) true *)
    	reflexivity.
(* Goal: CGeval rho f *)
	assumption.
    Qed.

Lemma CG_add_rooted_1 :
 forall (cg : CGraph1) (root a : ad) (d : D),
 CG_edge cg root a = None -> CG_edge (CG_add cg root a d) root a = Some d.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. change (CG_edge (cg2 cg root a d) root a = Some d) in |- *. rewrite CG_add_edge_1.
(* Goal: forall _ : @eq bool (Dle d' d) true, @eq bool (Dle (Dplus (Dneg d) d') Dz) false *)
(* Goal: @eq bool (Dle d' d) true *)
(* Goal: forall _ : @eq bool (Dle (Dplus (Dneg d) d') Dz) false, @eq bool (Dle (Dplus (Dneg d) d') Dz) false *)
    rewrite (Neqb_correct root). rewrite (Neqb_correct a). rewrite H. reflexivity.
  Qed.

Lemma CG_add_root_rooted_1 :
 forall (l : list ad) (cg : CGraph1) (root a : ad),
 ad_list_stutters l = false ->
 ad_in_list a l = false ->
 forall d : D,
 CG_edge cg root a = Some d ->
 CG_edge (CG_add_root root cg l) root a = Some d.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction l. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. elim (orb_false_elim _ _ H0). intros. elim (orb_false_elim _ _ H1).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply H. assumption.
(* Goal: CGeval rho f *)
    assumption.
(* Goal: @eq (option D) (CG_edge (cg2 cg root a d) x y) (@Some D d0) *)
    change (CG_edge (cg2 cg root a Dz) root a0 = Some d) in |- *. rewrite CG_add_edge_1.
(* Goal: CGeval rho f *)
    rewrite (Neqb_comm a a0). rewrite H5. rewrite (andb_b_false (Neqb root root)). assumption.
  Qed.

Lemma CG_add_root_rooted_2 :
 forall (l : list ad) (cg : CGraph1) (root : ad),
 ad_list_stutters l = false ->
 (forall a0 : ad, ad_in_list a0 l = true -> CG_edge cg root a0 = None) ->
 forall a : ad,
 ad_in_list a l = true -> CG_edge (CG_add_root root cg l) root a = Some Dz.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simple induction l. intros. discriminate H1.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. elim (orb_false_elim _ _ H0). intros. elim (sumbool_of_bool (Neqb a0 a)).
(* Goal: CGeval rho f *)
    intro H5. rewrite (Neqb_complete _ _ H5). apply CG_add_root_rooted_1. assumption.
(* Goal: CGeval rho f *)
    assumption.
(* Goal: @eq bool (negb false) true *)
    apply CG_add_rooted_1. apply H1. rewrite (Neqb_correct a). reflexivity.
(* Goal: CGeval rho f *)
    intro H5. rewrite H5 in H2. simpl in H2. apply H. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. change (CG_edge (cg2 cg root a Dz) root a1 = None) in |- *. rewrite CG_add_edge_1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    elim (sumbool_of_bool (Neqb a a1)). intro H7. rewrite (Neqb_complete _ _ H7) in H3.
(* Goal: @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
    rewrite H6 in H3. discriminate H3.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H7. rewrite H7. rewrite (andb_b_false (Neqb root root)).
(* Goal: @eq bool (orb (N.eqb a1 a) true) true *)
(* Goal: @eq bool (ad_in_list a0 l0) true *)
    apply H1. rewrite H6. apply orb_b_true.
(* Goal: CGeval rho f *)
    assumption.
  Qed.
 
Lemma CG_add_root_rooted_3 :
 forall (cg : CGraph1) (root : ad),
 in_dom _ root cg = false ->
 forall a : ad,
 in_dom _ a cg = true ->
 CG_edge (CG_add_root root cg (ad_list_of_dom _ cg)) root a = Some Dz.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply CG_add_root_rooted_2. apply ad_list_of_dom_not_stutters.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. unfold CG_edge in |- *. rewrite (in_dom_none _ _ _ H). reflexivity.
(* Goal: CGeval rho f *)
    rewrite ad_in_list_of_dom_in_dom. assumption.
  Qed.

Lemma CG_add_root_rooted_4 :
 forall (l : list ad) (cg : CGraph1) (root a : ad),
 in_dom _ a (CG_add_root root cg l) = true ->
 {a = root} + {in_dom _ a cg = true}.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simple induction l. intros. right. exact H.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. elim (H (CG_add cg root a Dz) root a0 H0). intro H1. left. assumption.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    intro H1. unfold in_dom, CG_add in H1. elim (option_sum _ (MapGet _ cg root)). intro H2.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
    elim H2. intros edges H3. rewrite H3 in H1. elim (option_sum _ (MapGet D edges a)). intro H4.
(* Goal: @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
    elim H4. intros d H5. rewrite H5 in H1.
    rewrite (MapPut_semantics _ cg root (MapPut D edges a (Dmin Dz d)) a0)
      in H1.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    elim (sumbool_of_bool (Neqb root a0)). intro H6. left. rewrite (Neqb_complete _ _ H6).
(* Goal: @eq bool (negb false) true *)
    reflexivity.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall _ : not (CGeval rho c), or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H6. rewrite H6 in H1. right. exact H1.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
    intro H4. rewrite H4 in H1.
(* Goal: sumbool (@eq ad a0 root) (@eq bool (in_dom (Map D) a0 cg) true) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg root) (@None (Map D)), sumbool (@eq ad a0 root) (@eq bool (in_dom (Map D) a0 cg) true) *)
    rewrite (MapPut_semantics _ cg root (MapPut D edges a Dz) a0) in H1.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    elim (sumbool_of_bool (Neqb root a0)). intro H5. left. rewrite (Neqb_complete _ _ H5).
(* Goal: @eq bool (negb false) true *)
    reflexivity.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall _ : not (CGeval rho c), or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H5. rewrite H5 in H1. right. exact H1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    intro H2. rewrite H2 in H1. rewrite (MapPut_semantics _ cg root (M1 D a Dz) a0) in H1.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    elim (sumbool_of_bool (Neqb root a0)). intro H3. left. rewrite (Neqb_complete _ _ H3).
(* Goal: @eq bool (negb false) true *)
    reflexivity.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall _ : not (CGeval rho c), or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H3. rewrite H3 in H1. right. exact H1.
  Qed.

Lemma CG_edge_dist_some_1 :
 forall (n : nat) (cg : CGraph1) (x y : ad) (d : D) (prefix : list ad),
 CG_edge cg x y = Some d ->
 ad_in_list y prefix = false ->
 {d' : D |
 Ddle (ad_simple_path_dist_1 cg x y prefix (S n)) (Some d') = true}.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CG_edge in |- *. intros. simpl in |- *. elim (sumbool_of_bool (Neqb x y)). intro H1. rewrite H1.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    split with Dz. simpl in |- *. apply Dle_refl.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    intro H1. rewrite H1. elim (option_sum _ (MapGet _ cg x)). intro H2. elim H2.
(* Goal: @eq bool match ad_simple_path_dist (CG_add_root root cg (ad_list_of_dom (Map D) cg)) root a with | Some d => true | None => false end true *)
    intros edges H3. rewrite H3 in H. rewrite H3. elim (option_sum _ (MapGet D edges y)).
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
    intro H4. elim H4. intros d0 H5. rewrite H5 in H. inversion H. split with (Dplus Dz d).
(* Goal: @eq bool (Ddle (all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 cg z y (@cons ad x prefix) n) d) edges) (@Some D (Dplus Dz d))) true *)
(* Goal: forall _ : @eq (option D) (MapGet D edges y) (@None D), @sig D (fun d' : D => @eq bool (Ddle (all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 cg z y (@cons ad x prefix) n) d) edges) (@Some D d')) true) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sig D (fun d' : D => @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_simple_path_dist_1 cg z y (@cons ad x prefix) n) d) edges | None => @None D end (@Some D d')) true) *)
    rewrite H7 in H5. apply
  Ddle_trans
   with
     (dd' := (fun (z : ad) (d0 : D) =>
              match Neqb z x || ad_in_list z prefix with
              | true => None
              | false =>
                  Ddplus (ad_simple_path_dist_1 cg z y (x :: prefix) n) d0
              end) y d).
    apply
     all_min_le_1
      with
        (f := fun (z : ad) (d0 : D) =>
              match Neqb z x || ad_in_list z prefix with
              | true => None
              | false =>
                  Ddplus (ad_simple_path_dist_1 cg z y (x :: prefix) n) d0
              end).
(* Goal: CGeval rho f *)
    assumption.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    rewrite (Neqb_comm y x). rewrite H1. rewrite H0. simpl in |- *. case n. simpl in |- *.
(* Goal: @eq bool (Ddle (@Some D d) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
    rewrite (Neqb_correct y). apply Ddle_refl.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    intro. simpl in |- *. rewrite (Neqb_correct y). apply Ddle_refl.
(* Goal: False *)
    intro H4. rewrite H4 in H. discriminate H.
(* Goal: False *)
    intro H2. rewrite H2 in H. discriminate H.
  Qed.

Lemma CG_edge_dist_some :
 forall (cg : CGraph1) (x y : ad) (d : D),
 CG_edge cg x y = Some d ->
 {d' : D | ad_simple_path_dist cg x y = Some d'}.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. elim (option_sum _ (ad_simple_path_dist cg x y)). trivial.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
    unfold ad_simple_path_dist in |- *. intro H0. elim (option_sum _ (MapGet _ cg x)). intro H1. elim H1.
(* Goal: forall (x0 : Map D) (_ : @eq (option (Map D)) (MapGet (Map D) cg x) (@Some (Map D) x0)), @sig D (fun d' : D => @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) (MapCard (Map D) cg)) (@Some D d')) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sig D (fun d' : D => @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) (MapCard (Map D) cg)) (@Some D d')) *)
    intros edges H2. elim (MapCard_is_not_O _ cg x edges H2). intros n H3.
(* Goal: forall (x0 : D) (_ : @eq bool (Ddle (ad_simple_path_dist_1 cg x y (@nil ad) (S n)) (@Some D x0)) true), @sig D (fun d' : D => @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) (MapCard (Map D) cg)) (@Some D d')) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sig D (fun d' : D => @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) (MapCard (Map D) cg)) (@Some D d')) *)
    elim (CG_edge_dist_some_1 n cg x y d nil H (refl_equal _)). intros d0 H4.
(* Goal: @sig D (fun d' : D => @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) (MapCard (Map D) cg)) (@Some D d')) *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @sig D (fun d' : D => @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) (MapCard (Map D) cg)) (@Some D d')) *)
    rewrite H3 in H0. rewrite H0 in H4. discriminate H4.
(* Goal: False *)
    intro H1. unfold CG_edge in H. rewrite H1 in H. discriminate H.
  Qed.

Lemma CG_add_root_rooted :
 forall (cg : CGraph1) (root : ad),
 (forall (x : ad) (d : D) (l : list ad),
  CG_path cg x d (x :: l) -> Dle Dz d = true) ->
 in_dom _ root cg = false ->
 forall a : ad,
 in_dom _ a (CG_add_root root cg (ad_list_of_dom _ cg)) = true ->
 CG_leq (CG_add_root root cg (ad_list_of_dom _ cg)) root a = true.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. elim (CG_add_root_rooted_4 _ _ _ _ H1). intro H2. rewrite H2. apply CG_leq_refl.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    intro H2. elim (CG_edge_dist_some _ root a Dz (CG_add_root_rooted_3 cg root H0 a H2)).
(* Goal: @eq bool (negb false) true *)
    intros d H3. unfold CG_leq in |- *. rewrite H3. reflexivity.
  Qed.

Lemma CG_add_sat :
 forall (cg : CGraph1) (root a : ad) (d : D) (rho : ad -> D),
 CGsat (cg2 cg root a d) rho -> CGsat cg rho.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CGsat in |- *. intros. elim (sumbool_of_bool (Neqb root x && Neqb a y)). intro H1.
(* Goal: CGeval rho (CG_of_CGS c) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c0))), or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    apply Dle_trans with (d' := Dplus (rho y) (Dmin d d0)). apply H. rewrite CG_add_edge_1.
(* Goal: @eq bool (negb false) true *)
    rewrite H1. rewrite H0. reflexivity.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
    apply Dle_plus_mono. apply Dle_refl.
(* Goal: @eq bool (Dle (Dmin d d0) d0) true *)
(* Goal: forall _ : @eq bool (andb (N.eqb root x) (N.eqb a y)) false, @eq bool (Dle (rho x) (Dplus (rho y) d0)) true *)
    apply Dmin_le_2.
(* Goal: CGeval rho f *)
    intro H1. apply H. rewrite CG_add_edge_1. rewrite H1. assumption.
  Qed.

Lemma CG_add_root_sat :
 forall (l : list ad) (cg : CGraph1) (root : ad) (rho : ad -> D),
 CGsat (CG_add_root root cg l) rho -> CGsat cg rho.
  Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
    simple induction l. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. apply (CG_add_sat cg root a Dz rho). unfold cg2 in |- *. exact (H _ _ _ H0).
  Qed.

Lemma CG_add_root_consistent :
 forall (l : list ad) (cg : CGraph1) (root : ad),
 CGconsistent (CG_add_root root cg l) -> CGconsistent cg.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CGconsistent in |- *. intros. elim H. intros rho H0. split with rho.
(* Goal: CGsat cg rho *)
    exact (CG_add_root_sat l cg root rho H0).
  Qed.

Lemma CG_circuit_complete_1 :
 forall cg : CGraph1,
 (forall (x : ad) (d : D) (l : list ad),
  CG_path cg x d (x :: l) -> Dle Dz d = true) ->
 forall root : ad,
 root = ad_alloc_opt unit (FSetUnion (MapDom _ cg) (MapDom _ (cg_range cg))) ->
 forall cg' : CGraph1,
 cg' = CG_add_root root cg (ad_list_of_dom _ cg) -> CGconsistent cg.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. apply (CG_add_root_consistent (ad_list_of_dom (Map D) cg) cg root). rewrite <- H1.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
    cut (in_dom _ root cg || in_dom _ root (cg_range cg) = false). intro H2.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    elim (orb_false_elim _ _ H2). intros. elim CG_rooted_sat with (cg := cg') (root := root) (d0 := Dz).
(* Goal: CGeval rho f *)
    intros rho H5. elim H5. unfold CGconsistent in |- *. intros H6 H7. split with rho. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    rewrite H1. intros.
    apply
     CG_add_root_out_of_range
      with
        (l := ad_list_of_dom (Map D) cg)
        (cg := cg)
        (root := root)
        (x0 := x)
        (d0 := d)
        (l0 := l).
(* Goal: CGeval rho f *)
    assumption.
(* Goal: MapSubset unit unit (Elems (ad_list_of_dom (Map D) cg)) (MapDom (Map D) cg) *)
(* Goal: @eq bool (ad_in_list root (ad_list_of_dom (Map D) cg)) false *)
(* Goal: @eq bool (in_dom D root (cg_range cg)) false *)
(* Goal: CG_path (CG_add_root root cg (ad_list_of_dom (Map D) cg)) x d (@cons ad x l) *)
(* Goal: forall (x : ad) (_ : @eq bool (in_dom (Map D) x cg') true), @eq bool (CG_leq cg' root x) true *)
(* Goal: @eq bool (orb (in_dom (Map D) root cg) (in_dom D root (cg_range cg))) false *)
    apply MapSubset_2_imp. unfold MapSubset_2 in |- *.
    apply
     eqmap_trans
      with
        (m' := MapDomRestrBy unit unit (MapDom (Map D) cg)
                 (MapDom (Map D) cg)).
(* Goal: eqmap unit (MapDomRestrBy unit unit (Elems (ad_list_of_dom (Map D) cg)) (MapDom (Map D) cg)) (MapDomRestrBy unit unit (MapDom (Map D) cg) (MapDom (Map D) cg)) *)
(* Goal: eqmap unit (MapDomRestrBy unit unit (MapDom (Map D) cg) (MapDom (Map D) cg)) (M0 unit) *)
(* Goal: @eq bool (ad_in_list root (ad_list_of_dom (Map D) cg)) false *)
(* Goal: @eq bool (in_dom D root (cg_range cg)) false *)
(* Goal: CG_path (CG_add_root root cg (ad_list_of_dom (Map D) cg)) x d (@cons ad x l) *)
(* Goal: forall (x : ad) (_ : @eq bool (in_dom (Map D) x cg') true), @eq bool (CG_leq cg' root x) true *)
(* Goal: @eq bool (orb (in_dom (Map D) root cg) (in_dom D root (cg_range cg))) false *)
    apply MapDomRestrBy_ext. apply Elems_of_list_of_dom.
(* Goal: eqmap unit (MapDom (Map D) cg) (MapDom (Map D) cg) *)
(* Goal: eqmap unit (MapDomRestrBy unit unit (MapDom (Map D) cg) (MapDom (Map D) cg)) (M0 unit) *)
(* Goal: @eq bool (ad_in_list root (ad_list_of_dom (Map D) cg)) false *)
(* Goal: @eq bool (in_dom D root (cg_range cg)) false *)
(* Goal: CG_path (CG_add_root root cg (ad_list_of_dom (Map D) cg)) x d (@cons ad x l) *)
(* Goal: forall (x : ad) (_ : @eq bool (in_dom (Map D) x cg') true), @eq bool (CG_leq cg' root x) true *)
(* Goal: @eq bool (orb (in_dom (Map D) root cg) (in_dom D root (cg_range cg))) false *)
    apply eqmap_refl.
(* Goal: eqmap unit (MapDomRestrBy unit unit (MapDom (Map D) cg) (MapDom (Map D) cg)) (M0 unit) *)
(* Goal: @eq bool (ad_in_list root (ad_list_of_dom (Map D) cg)) false *)
(* Goal: @eq bool (in_dom D root (cg_range cg)) false *)
(* Goal: CG_path (CG_add_root root cg (ad_list_of_dom (Map D) cg)) x d (@cons ad x l) *)
(* Goal: forall (x : ad) (_ : @eq bool (in_dom (Map D) x cg') true), @eq bool (CG_leq cg' root x) true *)
(* Goal: @eq bool (orb (in_dom (Map D) root cg) (in_dom D root (cg_range cg))) false *)
    apply MapDomRestrBy_m_m_1.
(* Goal: CGeval rho f *)
    rewrite ad_in_list_of_dom_in_dom. assumption.
(* Goal: CGeval rho f *)
    assumption.
(* Goal: CGeval rho f *)
    assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. rewrite H1. apply CG_add_root_rooted. assumption.
(* Goal: CGeval rho f *)
    assumption.
(* Goal: CGeval rho f *)
    rewrite <- H1. assumption.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    rewrite MapDom_Dom. rewrite MapDom_Dom. rewrite <- in_FSet_union. rewrite H0.
(* Goal: @eq bool (in_FSet (ad_alloc_opt unit (FSetUnion (MapDom (Map D) cg) (MapDom D (cg_range cg)))) (FSetUnion (MapDom (Map D) cg) (MapDom D (cg_range cg)))) false *)
    unfold in_FSet in |- *. apply ad_alloc_opt_allocates.
  Qed.

(*s If there is no circuit [(cons x l)] with negative weight [d], then [cg] is consistent: *)

Theorem CG_circuit_complete :
 forall cg : CGraph1,
 (forall (x : ad) (d : D) (l : list ad),
  CG_path cg x d (x :: l) -> Dle Dz d = true) -> CGconsistent cg.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. eapply CG_circuit_complete_1. assumption.
(* Goal: @eq bool (negb false) true *)
    reflexivity.
(* Goal: @eq bool (negb false) true *)
    reflexivity.
  Qed.

Lemma CG_translate_l :
 forall (cg : CGraph1) (rho : ad -> D) (d : D),
 CGsat cg rho -> CGsat cg (fun a : ad => Dplus d (rho a)).
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CGsat in |- *. intros. rewrite Dplus_assoc. apply Dle_plus_mono. apply Dle_refl.
(* Goal: CGeval rho f *)
    apply H. assumption.
  Qed.

(*s [(CGconsistent_anchored cg a d)] if there exists a valuation $\rho$ which 
     satisfies [cg] and such that $\rho(a)=d$
*)

Definition CGconsistent_anchored (cg : CGraph1) (a : ad) 
  (d0 : D) := {rho : ad -> D | CGsat cg rho /\ rho a = d0}.

Lemma CGconsistent_then_anchored :
 forall cg : CGraph1,
 CGconsistent cg -> forall (a : ad) (d0 : D), CGconsistent_anchored cg a d0.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CGconsistent, CGconsistent_anchored in |- *. intros. elim H. intros rho H0.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
    split with (fun a0 : ad => Dplus (Dplus d0 (Dneg (rho a))) (rho a0)). split.
(* Goal: CGeval rho f *)
    apply CG_translate_l. assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
    rewrite Dplus_assoc. rewrite Dplus_neg_2. apply Dplus_d_z.
  Qed.

Lemma CGanchored_then_consistent :
 forall (cg : CGraph1) (a : ad) (d0 : D),
 CGconsistent_anchored cg a d0 -> CGconsistent cg.
  Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold CGconsistent, CGconsistent_anchored in |- *. intros. elim H. intros rho H0. elim H0. intros.
(* Goal: CGeval rho f *)
    split with rho. assumption.
  Qed.

(*s Definition of [ad_0_path_dist_1] 
    a more efficient version of [ad_simple_path_dist]: *)

Section CGDist1.

    Variable cg : CGraph1.

Fixpoint ad_0_path_dist_1 (x y : ad) (l : list ad) 
 (n : nat) {struct n} : option D :=
  if Neqb x y
  then Some Dz
  else
   match n with
   | O => None
   | S n' =>
       match MapGet _ cg x with
       | None => None
       | Some edges =>
           if ad_in_list x l
           then None
           else
            let l' := x :: l in (* builds reverse path *)
            all_min
              (fun (z : ad) (d : D) =>
               if ad_in_list z l'
               then None
               else Ddplus (ad_0_path_dist_1 z y l' n') d) edges
       end
   end.

Definition ad_0_path_dist (x y : ad) :=
  ad_0_path_dist_1 x y nil (MapCard _ cg).

Lemma ad_0_path_dist_1_ge :
 forall (n : nat) (l : list ad) (x y : ad),
 Ddle (ad_simple_path_dist_1 cg x y l n) (ad_0_path_dist_1 x y l n) = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction n. simpl in |- *. intros. apply Ddle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. case (Neqb x y). apply Ddle_refl.
      case (MapGet _ cg x). Focus 2. apply Ddle_refl.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. case (ad_in_list x l). apply Ddle_d_none.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      apply all_min_le_3. intros. case (Neqb a x || ad_in_list a l). apply Ddle_refl.
(* Goal: CGeval rho (CG_of_CGS c) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c0))), or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      apply Ddle_plus_mono. apply H.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      apply Dle_refl.
    Qed.

Lemma ad_0_path_dist_1_correct_1 :
 (forall (x : ad) (d : D) (l : list ad),
  CG_path cg x d (x :: l) -> Dle Dz d = true) ->
 forall (n : nat) (x y : ad) (l : list ad) (d : D),
 length l <= n ->
 CG_path cg y d (x :: l) ->
 forall prefix : list ad,
 ad_list_stutters (rev prefix ++ x :: l) = false ->
 Ddle (ad_0_path_dist_1 x y prefix n) (Some d) = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction n. intros x y l. case l. intros. simpl in |- *. 
(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else @None D) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) O) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix O) (@Some D d)) true *)
(* Goal: forall (n : nat) (_ : forall (x y : ad) (l : list ad) (d : D) (_ : le (@length ad l) n) (_ : CG_path cg y d (@cons ad x l)) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x l))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix n) (@Some D d)) true) (x y : ad) (l : list ad) (d : D) (_ : le (@length ad l) (S n)) (_ : CG_path cg y d (@cons ad x l)) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x l))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n)) (@Some D d)) true *)
      inversion H1. rewrite H5.
(* Goal: @eq bool (Ddle (@Some D d) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
      rewrite (Neqb_correct y). apply Ddle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (le_Sn_O _ H0).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros n0 H0 x y l. case l. intros. inversion H2. 
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      rewrite H6. simpl in |- *.
(* Goal: @eq bool (Ddle (@Some D d) (@Some D d)) true *)
(* Goal: forall (a : ad) (l : list ad) (d : D) (_ : le (@length ad (@cons ad a l)) (S n0)) (_ : CG_path cg y d (@cons ad x (@cons ad a l))) (prefix : list ad) (_ : @eq bool (ad_list_stutters (@app ad (@rev ad prefix) (@cons ad x (@cons ad a l)))) false), @eq bool (Ddle (ad_0_path_dist_1 x y prefix (S n0)) (@Some D d)) true *)
      rewrite (Neqb_correct y). rewrite H5. apply Ddle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. simpl in |- *. elim (sumbool_of_bool (Neqb x y)). intro H4. rewrite H4.
(* Goal: @eq bool (Ddle (@Some D Dz) (@Some D d)) true *)
(* Goal: forall _ : @eq bool (N.eqb x y) false, @eq bool (Ddle (if N.eqb x y then @Some D Dz else match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
      rewrite (Neqb_complete _ _ H4) in H2. exact (H _ _ _ H2).

(* Goal: @eq bool (Ddle (if N.eqb x y then @Some D Dz else match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end) (@Some D d)) true *)
      intro H4. rewrite H4. elim (option_sum _ (MapGet _ cg x)). intro H5. elim H5.
(* Goal: @sigT D (fun d : D => @sigT (list ad) (fun l : list ad => and_sp (CG_path y d (@app ad (@rev ad (@cons ad x prefix)) l)) (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x prefix)) l)) false))) *)
      intros edges H6. rewrite H6. inversion_clear H2. apply
  Ddle_trans
   with
     (dd' := match ad_in_list a (x :: prefix) with
             | true => None
             | false => Ddplus (ad_0_path_dist_1 a y (x :: prefix) n0) d'
             end).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      cut (MapGet _ edges a = Some d'). intro. cut (ad_in_list x prefix = false). intro H9.
(* Goal: @eq bool (Ddle (if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges) (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d')) true *)
(* Goal: @eq bool (ad_in_list x prefix) false *)
(* Goal: @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      rewrite H9. exact
  (all_min_le_1
     (fun (z : ad) (d : D) =>
      match Neqb z x || ad_in_list z prefix with
      | true => None
      | false => Ddplus (ad_0_path_dist_1 z y (x :: prefix) n0) d
      end) edges a d' H2).
(* Goal: @eq bool (ad_in_list x prefix) false *)
(* Goal: @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      rewrite <- ad_in_list_rev. exact (ad_list_stutters_prev_conv_l _ _ _ H3).
(* Goal: @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      unfold CG_edge in H8. rewrite H6 in H8. elim (option_sum _ (MapGet D edges a)).
(* Goal: CGeval rho f *)
      intro H9. elim H9. intros d1 H10. rewrite H10 in H8. rewrite H10. assumption.
(* Goal: forall _ : @eq (option D) (MapGet D edges a) (@None D), @eq (option D) (MapGet D edges a) (@Some D d') *)
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      intro H9. rewrite H9 in H8. discriminate H8.
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      rewrite (ad_list_app_rev prefix (a :: l0) x) in H3.
(* Goal: @eq bool (Ddle (if ad_in_list a (@cons ad x prefix) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      rewrite <- (ad_in_list_rev (x :: prefix) a).
(* Goal: @eq bool (Ddle (if ad_in_list a (@rev ad (@cons ad x prefix)) then @None D else Ddplus (ad_0_path_dist_1 a y (@cons ad x prefix) n0) d') (@Some D (Dplus d0 d'))) true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      rewrite (ad_list_stutters_prev_conv_l _ _ _ H3).
      apply
       (Ddle_plus_mono (ad_0_path_dist_1 a y (x :: prefix) n0) 
          (Some d0) d' d').
(* Goal: @eq bool (Ddle (ad_0_path_dist_1 a y (@cons ad x prefix) n0) (@Some D d0)) true *)
(* Goal: @eq bool (Dle d' d') true *)
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      exact (H0 a y l0 d0 (le_S_n _ _ H1) H7 (x :: prefix) H3).
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      apply Dle_refl.
(* Goal: @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      intro H5. inversion H2.
(* Goal: @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D (Dplus d0 d'))) true *)
      unfold CG_edge in H11. rewrite H5 in H11. discriminate H11.
    Qed.

Lemma ad_0_path_dist_1_le :
 (forall (x : ad) (d : D) (l : list ad),
  CG_path cg x d (x :: l) -> Dle Dz d = true) ->
 forall (n : nat) (x y : ad),
 Ddle (ad_0_path_dist_1 x y nil n) (ad_simple_path_dist_1 cg x y nil n) =
 true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (option_sum _ (ad_simple_path_dist_1 cg x y nil n)). intro H0. elim H0.
(* Goal: @eq (option D) (ad_1_path_dist x y) (ad_1_path_dist_1 x y (M0 unit) n) *)
(* Goal: @ex nat (fun m : nat => @eq nat n (Init.Nat.add m (MapCard (Map D) cg))) *)
      intros d H1. rewrite H1.
(* Goal: forall (x0 : list ad) (_ : and_sp (CG_path cg y (Dplus d Dz) (@app ad (@rev ad (@cons ad x (@nil ad))) x0)) (and (@eq bool (ad_list_stutters (@app ad (@rev ad (@cons ad x (@nil ad))) x0)) false) (le (@length ad x0) n))), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (@Some D d)) true *)
(* Goal: CG_path cg x Dz (@rev ad (@cons ad x (@nil ad))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
      elim (ad_simple_path_dist_1_complete_1 cg n x y nil Dz) with (d0 := d). intros l H2.
(* Goal: or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      elim H2. intros H3 H4. apply (ad_0_path_dist_1_correct_1 H n x y l). exact (proj2 H4).
(* Goal: CG_path cg y d (@cons ad x l) *)
(* Goal: @eq bool (ad_list_stutters (@app ad (@rev ad (@nil ad)) (@cons ad x l))) false *)
(* Goal: CG_path cg x Dz (@rev ad (@cons ad x (@nil ad))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
      rewrite (Dplus_d_z d) in H3. exact H3.
(* Goal: @eq bool (ad_list_stutters (@app ad (@rev ad (@nil ad)) (@cons ad x l))) false *)
(* Goal: CG_path cg x Dz (@rev ad (@cons ad x (@nil ad))) *)
(* Goal: @eq bool (ad_list_stutters (@cons ad x (@nil ad))) false *)
(* Goal: @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@Some D d) *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist_1 cg x y (@nil ad) n) (@None D), @eq bool (Ddle (ad_0_path_dist_1 x y (@nil ad) n) (ad_simple_path_dist_1 cg x y (@nil ad) n)) true *)
      exact (proj1 H4).
(* Goal: @eq bool (negb false) true *)
      simpl in |- *. apply CG_p1. reflexivity.
(* Goal: @eq bool (negb false) true *)
      reflexivity.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro H0. rewrite H0. apply Ddle_d_none.
    Qed.

Lemma ad_0_path_dist_correct_1 :
 CGconsistent cg ->
 forall (x y : ad) (n : nat),
 ad_0_path_dist_1 x y nil n = ad_simple_path_dist_1 cg x y nil n.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. apply Ddle_antisym. apply ad_0_path_dist_1_le.
(* Goal: forall (x : ad) (d : D) (l : list ad) (_ : CG_path cg x d (@cons ad x l)), @eq bool (Dle Dz d) true *)
(* Goal: @eq bool (Ddle (ad_simple_path_dist_1 cg x y (@nil ad) n) (ad_0_path_dist_1 x y (@nil ad) n)) true *)
      exact (CG_circuits_non_negative_weight cg H).
(* Goal: @eq bool (Ddle (ad_simple_path_dist_1 cg x y (@nil ad) n) (ad_0_path_dist_1 x y (@nil ad) n)) true *)
      apply ad_0_path_dist_1_ge.
    Qed.

Lemma ad_0_path_dist_correct :
 CGconsistent cg ->
 forall x y : ad, ad_0_path_dist x y = ad_simple_path_dist cg x y.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. exact (ad_0_path_dist_correct_1 H x y (MapCard _ cg)).
    Qed.

(*s Uses a set [s] of already visited nodes *)

Fixpoint ad_1_path_dist_1 (x y : ad) (s : FSet) (n : nat) {struct n} :
 option D :=
  if Neqb x y
  then Some Dz
  else
   match n with
   | O => None
   | S n' =>
       match MapGet _ cg x with
       | None => None
       | Some edges =>
           match MapGet _ s x with
           | Some _ => None
           | None =>
               let s' := MapPut unit s x tt in
               all_min
                 (fun (z : ad) (d : D) =>
                  match MapGet _ s' z with
                  | Some _ => None
                  | None => Ddplus (ad_1_path_dist_1 z y s' n') d
                  end) edges
           end
       end
   end.

Definition ad_1_path_dist (x y : ad) :=
  ad_1_path_dist_1 x y (M0 unit) (MapCard _ cg).

Lemma ad_1_path_dist_correct_1 :
 forall (n : nat) (x y : ad) (l : list ad),
 ad_1_path_dist_1 x y (Elems l) n = ad_0_path_dist_1 x y l n.
    Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      simple induction n. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. case (Neqb x y). reflexivity.
(* Goal: @eq bool (negb false) true *)
      case (MapGet _ cg x). Focus 2. reflexivity.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. unfold all_min in |- *. elim (sumbool_of_bool (ad_in_list x l)). intro H0. rewrite H0.
      rewrite <- (ad_in_elems_in_list l x) in H0. elim (in_dom_some _ _ _ H0). intros t H1.
(* Goal: @eq bool (negb false) true *)
      rewrite H1. reflexivity.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro H0. rewrite H0. rewrite <- (ad_in_elems_in_list l x) in H0.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      rewrite (in_dom_none _ _ _ H0). apply MapFold_ext_f. intros.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      elim (sumbool_of_bool (ad_in_list a (x :: l))). intro H2.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      rewrite <- (ad_in_elems_in_list (x :: l) a) in H2. elim (in_dom_some _ _ _ H2). simpl in |- *.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      intro t. elim t. intro H3. rewrite H3. rewrite (ad_in_elems_in_list (x :: l) a) in H2.
(* Goal: @eq bool (negb false) true *)
      simpl in H2. rewrite H2. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      intro H2. cut (Neqb a x || ad_in_list a l = false). intro H3. rewrite H3.
(* Goal: lt (Init.Nat.add (FSize c0) (FlSize l)) n *)
(* Goal: @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
      rewrite <- (ad_in_elems_in_list (x :: l) a) in H2. simpl in H2.
(* Goal: @eq bool (negb false) true *)
      rewrite (in_dom_none _ _ _ H2). rewrite <- (H a y (x :: l)). reflexivity.
(* Goal: CGeval rho f *)
      assumption.
    Qed.

Lemma ad_1_path_dist_correct_2 :
 forall x y : ad, ad_1_path_dist x y = ad_0_path_dist x y.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. exact (ad_1_path_dist_correct_1 (MapCard _ cg) x y nil).
    Qed.

Lemma ad_1_path_dist_correct_3 :
 CGconsistent cg ->
 forall (n : nat) (x y : ad),
 ad_1_path_dist_1 x y (M0 unit) n = ad_simple_path_dist_1 cg x y nil n.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. rewrite <- (ad_0_path_dist_correct_1 H x y n).
(* Goal: @eq (option D) (ad_1_path_dist_1 x y (M0 unit) n) (ad_0_path_dist_1 x y (@nil ad) n) *)
      exact (ad_1_path_dist_correct_1 n x y nil).
    Qed.

Lemma ad_1_path_dist_correct :
 CGconsistent cg ->
 forall x y : ad, ad_1_path_dist x y = ad_simple_path_dist cg x y.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. rewrite ad_1_path_dist_correct_2. apply ad_0_path_dist_correct. assumption.
    Qed.

Lemma ad_1_path_dist_big_enough_1 :
 forall (n : nat) (s : FSet),
 MapSubset _ _ s (MapDom _ cg) ->
 MapCard _ cg <= n + MapCard _ s ->
 forall x y : ad, ad_1_path_dist_1 x y s n = ad_1_path_dist_1 x y s (S n).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction n. intros. simpl in |- *. case (Neqb x y). reflexivity.
(* Goal: forall _ : CGeval rho c0, sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall _ : not (CGeval rho c0), sumbool (forall _ : CGeval rho c, CGeval rho c0) (not (forall _ : CGeval rho c, CGeval rho c0)) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, sumbool (CGeval rho c) (not (CGeval rho c))) (rho : forall _ : ad, D), sumbool (CGeval rho (CGnot c)) (not (CGeval rho (CGnot c))) *)
      elim (sumbool_of_bool (in_dom _ x cg)). intro H1. elim (in_dom_some _ _ _ H1).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      intros edges H2. rewrite H2. elim (sumbool_of_bool (in_dom _ x s)). intro H3.
(* Goal: @eq bool (negb false) true *)
      elim (in_dom_some _ _ _ H3). intros t H4. rewrite H4. reflexivity.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      intro H3. simpl in H0. rewrite (MapCard_Dom _ cg) in H0. rewrite (MapDom_Dom _ s x) in H3.
      cut (MapGet _ (MapDom unit s) x = None). rewrite (MapSubset_card_eq _ _ _ _ H H0 x).
      rewrite (FSet_Dom (MapDom _ cg)).
      elim (in_dom_some _ _ _ (MapDom_semantics_1 _ cg x edges H2)). intros t H4 H5.
(* Goal: @eq bool match ad_simple_path_dist x z with | Some d => true | None => false end true *)
(* Goal: @eq bool (Ddle (ad_simple_path_dist x z) (@Some D (Dplus d2 d1))) true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist y z) (@None D), @eq bool match ad_simple_path_dist x z with | Some d => true | None => false end true *)
(* Goal: forall _ : @eq (option D) (ad_simple_path_dist x y) (@None D), @eq bool match ad_simple_path_dist x z with | Some d => true | None => false end true *)
      rewrite H4 in H5. discriminate H5.
      exact (in_dom_none _ _ _ H3).
(* Goal: @eq bool (negb false) true *)
      intro H1. rewrite (in_dom_none _ _ _ H1). reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. cut
  (forall m : nat,
   m = S n0 -> ad_1_path_dist_1 x y s (S n0) = ad_1_path_dist_1 x y s (S m)).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. exact (H2 (S n0) (refl_equal _)).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. simpl in |- *. case (Neqb x y). reflexivity.
(* Goal: @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      elim (option_sum _ (MapGet _ cg x)). intro H'. elim H'. intros edges H'0. rewrite H'0.
(* Goal: @eq bool (negb false) true *)
      elim (option_sum _ (MapGet _ s x)). intro H3. elim H3. intros t H4. rewrite H4. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro H3. rewrite H3. unfold all_min in |- *. apply MapFold_ext_f. intros.
(* Goal: forall _ : @eq (option (Map D)) (MapGet (Map D) cg x) (@None (Map D)), @eq bool (Ddle match MapGet (Map D) cg x with | Some edges => if ad_in_list x prefix then @None D else all_min (fun (z : ad) (d : D) => if orb (N.eqb z x) (ad_in_list z prefix) then @None D else Ddplus (ad_0_path_dist_1 z y (@cons ad x prefix) n0) d) edges | None => @None D end (@Some D d)) true *)
      rewrite (MapPut_semantics unit s x tt a). elim (sumbool_of_bool (Neqb x a)). intro H5.
(* Goal: @eq bool (negb false) true *)
      rewrite H5. reflexivity.
(* Goal: forall _ : @eq bool (Dle d' d) true, @eq bool (Dle (Dplus (Dneg d) d') Dz) false *)
(* Goal: @eq bool (Dle d' d) true *)
(* Goal: forall _ : @eq bool (Dle (Dplus (Dneg d) d') Dz) false, @eq bool (Dle (Dplus (Dneg d) d') Dz) false *)
      intro H5. rewrite H5. case (MapGet _ s a). Focus 2. rewrite H2. rewrite H. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold MapSubset in |- *. intros. elim (in_dom_some _ _ _ H6). intro.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      rewrite (MapPut_semantics unit s x tt a0). elim (sumbool_of_bool (Neqb x a0)). intro H7.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGFormSimplify c))), CGeval rho c0 *)
(* Goal: forall (_ : CGeval rho (CG_of_CGS (CGFormSimplify c0))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      rewrite H7. intro H8. rewrite <- (Neqb_complete _ _ H7). fold (in_FSet x (MapDom _ cg)) in |- *.
(* Goal: @eq bool (negb false) true *)
      rewrite <- (MapDom_Dom _ cg x). unfold in_dom in |- *. rewrite H'0. reflexivity.
(* Goal: @eq bool (negb false) true *)
      intro H7. rewrite H7. intro H8. apply (H0 a0). unfold in_dom in |- *. rewrite H8. reflexivity.
(* Goal: @eq bool (in_dom (Map D) a0 cg) true *)
      rewrite MapCard_Put_2_conv. rewrite <- plus_Snm_nSm. exact H1.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      trivial.
(* Goal: @eq bool (negb false) true *)
      intro H3. rewrite H3. reflexivity.
    Qed.

Lemma ad_1_path_dist_big_enough_2 :
 forall (n : nat) (x y : ad),
 ad_1_path_dist x y = ad_1_path_dist_1 x y (M0 unit) (n + MapCard _ cg).
    Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      simple induction n. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold plus in |- *. fold (n0 + MapCard _ cg) in |- *. rewrite <- ad_1_path_dist_big_enough_1.
(* Goal: CGeval rho (CG_of_CGS c) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c0))), or (CGeval rho (CG_of_CGS c)) (CGeval rho (CG_of_CGS c0)) *)
(* Goal: or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      apply H.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold MapSubset in |- *. intros. discriminate H0.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      simpl in |- *. rewrite <- plus_n_O. apply le_plus_r.
    Qed.

Lemma ad_1_path_dist_big_enough :
 forall n : nat,
 MapCard _ cg <= n ->
 forall x y : ad, ad_1_path_dist x y = ad_1_path_dist_1 x y (M0 unit) n.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. cut (exists m : nat, n = m + MapCard _ cg). intro H0. elim H0. intros m H1.
(* Goal: @eq (option D) (ad_1_path_dist x y) (ad_1_path_dist_1 x y (M0 unit) n) *)
(* Goal: @ex nat (fun m : nat => @eq nat n (Init.Nat.add m (MapCard (Map D) cg))) *)
      rewrite H1. apply ad_1_path_dist_big_enough_2.
(* Goal: @eq bool (negb false) true *)
      elim H. split with 0. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim H1. intros m' H2. split with (S m'). rewrite H2. reflexivity.
    Qed.

End CGDist1.

(*s Definition of concrete formulas : 
    [(CGleq x y d)] means $x\leq y+d$, [(CGeq x y d)] means $x=y+d$
 *)

Inductive CGForm : Set :=
  | CGleq : ad -> ad -> D -> CGForm
  | CGeq : ad -> ad -> D -> CGForm
  | CGand : CGForm -> CGForm -> CGForm
  | CGor : CGForm -> CGForm -> CGForm
  | CGimp : CGForm -> CGForm -> CGForm
  | CGnot : CGForm -> CGForm.

(*s Interpretation of concrete formulas as proposition *)

Fixpoint CGeval (rho : ad -> D) (f : CGForm) {struct f} : Prop :=
  match f with
  | CGleq x y d => Dle (rho x) (Dplus (rho y) d) = true
  | CGeq x y d => rho x = Dplus (rho y) d
  | CGand f0 f1 => CGeval rho f0 /\ CGeval rho f1
  | CGor f0 f1 => CGeval rho f0 \/ CGeval rho f1
  | CGimp f0 f1 => CGeval rho f0 -> CGeval rho f1
  | CGnot f0 => ~ CGeval rho f0
  end.

(*s Decidability of satisfaction *)

Lemma CGeval_dec :
 forall (f : CGForm) (rho : ad -> D), {CGeval rho f} + {~ CGeval rho f}.
  Proof.
(* Goal: forall (f : CGForm) (rho : forall _ : ad, D), iff (CGeval rho f) (CGSeval rho (CGFormSimplify f)) *)
    simple induction f. 
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. simpl in |- *. elim (sumbool_of_bool (Dle (rho a) (Dplus (rho a0) d))).
(* Goal: CGeval rho f *)
    intro H. left. assumption.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    intro H. right. unfold not in |- *. rewrite H. intro H0. discriminate H0.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. apply D_dec.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. elim (H rho). intro H1. elim (H0 rho). intro H2. left. split; assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
    unfold not in |- *. intro H2. right. intro. elim H3. intro. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    unfold not in |- *. intro H1. right. intro H2. elim H2. intros. apply (H1 H3).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. elim (H rho). intro H1. left. left. assumption.
(* Goal: CGeval rho f *)
    elim (H0 rho). intros H1 H2. left. right. assumption.
(* Goal: CGeval rho f *)
    unfold not in |- *. intros H1 H2. right. intro H3. elim H3; assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    simpl in |- *. intros. elim (H0 rho). intro H1. left. intro H2. assumption.
(* Goal: CGeval rho f *)
    elim (H rho). unfold not in |- *. intros H1 H2. right. intro H3. apply H2. apply H3. assumption.
(* Goal: or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
    unfold not in |- *. intros H1 H2. left. intro H3. elim (H1 H3).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
    intros. simpl in |- *. elim (H rho). intro H0. right. unfold not in |- *. intros. exact (H1 H0).
(* Goal: CGeval rho f *)
    intro H0. left. assumption.
  Qed.

(*s Simplified formulae: *)
Inductive CGSForm : Set :=
  | CGSleq : ad -> ad -> D -> CGSForm
  | CGSand : CGSForm -> CGSForm -> CGSForm
  | CGSor : CGSForm -> CGSForm -> CGSForm.

Fixpoint CG_of_CGS (fs : CGSForm) : CGForm :=
  match fs with
  | CGSleq x y d => CGleq x y d
  | CGSand fs0 fs1 => CGand (CG_of_CGS fs0) (CG_of_CGS fs1)
  | CGSor fs0 fs1 => CGor (CG_of_CGS fs0) (CG_of_CGS fs1)
  end.

Definition CGSeval (rho : ad -> D) (fs : CGSForm) :=
  CGeval rho (CG_of_CGS fs).

(*s Decision procedure for simplified formulae *)

Section CGSSolve.

    Variable anchor : ad.
    Variable anchor_value : D.

(*s Is $x\leq y+d$ consistent with [cg]? *)

Definition CG_test_ineq (cg : CGraph1) (n : nat) (x y : ad) 
  (d : D) := Ddle (Some (Dneg d)) (ad_1_path_dist_1 cg y x (M0 unit) n).

    Variable def_answer : bool.

(*s Invariants: [cg] is consistent, [|cg|<=n].
       [(CGS_solve_1 cg n fsl gas)]
       returns [true] iff [cg /\ fsl /\ anchor=anchor_value] is consistent,
       	 where [fsl] is understood as the conjunction of all the [fs] in [fsl];
         i.e. iff [cg /\ fsl] alone is consistent 
          (lemmas [CG_anchored_then_consistent] and [CG_consistent_then_anchored)].
       [gas] is intended to be [>=] the sum of sizes of all formulas in [fsl]. *)

Fixpoint CGS_solve_1 (cg : CGraph1) (n : nat) (fsl : list CGSForm)
 (gas : nat) {struct gas} : bool :=
  match gas with
  | O => def_answer
  | S gas' =>
      match fsl with
      | nil => true
      | fs :: fsl' =>
          match fs with
          | CGSleq x y d =>
              if CG_test_ineq cg n x y d
              then
               let cg' := CG_add cg x y d in CGS_solve_1 cg' (S n) fsl' gas'
              else false
          | CGSand fs0 fs1 => CGS_solve_1 cg n (fs0 :: fs1 :: fsl') gas'
          | CGSor fs0 fs1 =>
              if CGS_solve_1 cg n (fs0 :: fsl') gas'
              then true
              else CGS_solve_1 cg n (fs1 :: fsl') gas'
          end
      end
  end.

(*s Size of a set of formula and of a list of formula *)

Fixpoint FSize (f : CGSForm) : nat :=
  match f with
  | CGSand f0 f1 => S (FSize f0 + FSize f1)
  | CGSor f0 f1 => S (FSize f0 + FSize f1)
  | _ => 1
  end.

Fixpoint FlSize (fsl : list CGSForm) : nat :=
  match fsl with
  | nil => 0
  | fs :: fsl' => FSize fs + FlSize fsl'
  end.


Definition CGS_solve (fs : CGSForm) :=
  CGS_solve_1 (M0 _) 0 (fs :: nil) (S (FSize fs)).

(*s Interpretation of a list of formula as a conjonction *)

Fixpoint CGSeval_l (rho : ad -> D) (fsl : list CGSForm) {struct fsl} :
 Prop :=
  match fsl with
  | nil => True
  | fs :: fsl' => CGSeval rho fs /\ CGSeval_l rho fsl'
  end.

Lemma FSize_geq_1 : forall fs : CGSForm, {n : nat | FSize fs = S n}.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction fs. simpl in |- *. intros. split with 0. reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. simpl in |- *. split with (FSize c + FSize c0). reflexivity.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. simpl in |- *. split with (FSize c + FSize c0). reflexivity.
    Qed.

Lemma FlSize_is_O : forall fsl : list CGSForm, FlSize fsl = 0 -> fsl = nil.
    Proof.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      simple induction fsl. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. simpl in H0. elim (FSize_geq_1 a). intros n H1. rewrite H1 in H0. discriminate H0.
    Qed.

Lemma CG_add_card_le :
 forall (cg : CGraph1) (x y : ad) (d : D) (n : nat),
 MapCard _ cg <= n -> MapCard _ (CG_add cg x y d) <= S n.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold CG_add in |- *. case (MapGet _ cg x). Focus 2.
(* Goal: CGeval rho f *)
      apply (le_trans _ _ (S n) (MapCard_Put_ub _ cg x (M1 D y d))). apply le_n_S. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. case (MapGet _ m y). Focus 2.
(* Goal: le (S (Init.Nat.add (@length ad l1) O)) (S (Init.Nat.add (@length ad l0) (Init.Nat.add (@length ad l1) (@length ad l2)))) *)
(* Goal: le (@length ad l) (S n0) *)
(* Goal: @eq bool (Dle d1 d1) true *)
(* Goal: forall _ : @eq bool (ad_list_stutters l) false, @eq bool (Dle Dz d0) true *)
      apply (le_trans _ _ (S n) (MapCard_Put_ub _ cg x (MapPut D m y d))). apply le_n_S.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. apply
  (le_trans _ _ (S n) (MapCard_Put_ub _ cg x (MapPut D m y (Dmin d d0)))).
(* Goal: CGeval rho f *)
      apply le_n_S. assumption.
    Qed.

Lemma CGS_solve_1_correct :
 forall (gas : nat) (fsl : list CGSForm) (cg : CGraph1) (n : nat),
 CGconsistent cg ->
 MapCard _ cg <= n ->
 FlSize fsl < gas ->
 CGS_solve_1 cg n fsl gas = true ->
 {rho : ad -> D | CGSeval_l rho fsl /\ CGsat cg rho}.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction gas. intros. elim (lt_n_O _ H1).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros n H fsl. case fsl. intros. elim H0. intros rho H4. split with rho.
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
      split. exact I.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro fs. case fs. intros. elim (sumbool_of_bool (CG_test_ineq cg n0 a a0 d)). intro H4.
(* Goal: @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      rewrite H4 in H3. unfold CG_test_ineq in H4. elim (H l (CG_add cg a a0 d) (S n0)).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros rho H5. split with rho. elim H5. intros. split. simpl in |- *. split. unfold CGSeval in |- *.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      simpl in |- *. exact (CG_add_3 cg a a0 d rho H7).
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGsat cg rho *)
(* Goal: CGconsistent (CG_add cg a a0 d) *)
(* Goal: le (MapCard (Map D) (CG_add cg a a0 d)) (S n0) *)
(* Goal: lt (FlSize l) n *)
(* Goal: @eq bool (CGS_solve_1 (CG_add cg a a0 d) (S n0) l n) true *)
(* Goal: forall _ : @eq bool (CG_test_ineq cg n0 a a0 d) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      exact (CG_add_2 cg a a0 d rho H7).
(* Goal: CGconsistent (CG_add cg a a0 d) *)
(* Goal: le (MapCard (Map D) (CG_add cg a a0 d)) (S n0) *)
(* Goal: lt (FlSize l) n *)
(* Goal: @eq bool (CGS_solve_1 (CG_add cg a a0 d) (S n0) l n) true *)
(* Goal: forall _ : @eq bool (CG_test_ineq cg n0 a a0 d) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      apply CG_circuit_complete. 
(* Goal: forall (x : ad) (d0 : D) (l : list ad) (_ : CG_path (CG_add cg a a0 d) x d0 (@cons ad x l)), @eq bool (Dle Dz d0) true *)
(* Goal: le (MapCard (Map D) (CG_add cg a a0 d)) (S n0) *)
(* Goal: lt (FlSize l) n *)
(* Goal: @eq bool (CGS_solve_1 (CG_add cg a a0 d) (S n0) l n) true *)
(* Goal: forall _ : @eq bool (CG_test_ineq cg n0 a a0 d) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      rewrite <- (ad_1_path_dist_big_enough cg n0 H1 a0 a) in H4.
(* Goal: forall (x : ad) (d0 : D) (l : list ad) (_ : CG_path (CG_add cg a a0 d) x d0 (@cons ad x l)), @eq bool (Dle Dz d0) true *)
(* Goal: le (MapCard (Map D) (CG_add cg a a0 d)) (S n0) *)
(* Goal: lt (FlSize l) n *)
(* Goal: @eq bool (CGS_solve_1 (CG_add cg a a0 d) (S n0) l n) true *)
(* Goal: forall _ : @eq bool (CG_test_ineq cg n0 a a0 d) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      rewrite (ad_1_path_dist_correct cg H0 a0 a) in H4.
(* Goal: forall (x : ad) (d0 : D) (l : list ad) (_ : CG_path (CG_add cg a a0 d) x d0 (@cons ad x l)), @eq bool (Dle Dz d0) true *)
(* Goal: le (MapCard (Map D) (CG_add cg a a0 d)) (S n0) *)
(* Goal: lt (FlSize l) n *)
(* Goal: @eq bool (CGS_solve_1 (CG_add cg a a0 d) (S n0) l n) true *)
(* Goal: forall _ : @eq bool (CG_test_ineq cg n0 a a0 d) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      exact (CG_add_5 cg a a0 d (CG_circuits_non_negative_weight cg H0) H4).
(* Goal: CGeval rho f *)
      apply CG_add_card_le. assumption.
(* Goal: lt (FlSize l) n *)
(* Goal: @eq bool (CGS_solve_1 (CG_add cg a a0 d) (S n0) l n) true *)
(* Goal: forall _ : @eq bool (CG_test_ineq cg n0 a a0 d) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSleq a a0 d) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c (@cons CGSForm c0 l)) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSand c c0) l)) (CGsat cg rho)) *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : CGconsistent cg) (_ : le (MapCard (Map D) cg) n0) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true), @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      exact (lt_S_n _ _ H2).
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
      intro H4. rewrite H4 in H3. discriminate H3.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (H (c :: c0 :: l) cg n0 H0). simpl in |- *. intros rho H4. split with rho.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim H4. intros. split; try assumption. elim H5. intros. elim H8. intros.
(* Goal: CGeval rho f *)
      split; try assumption. exact (conj H7 H9).
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      simpl in |- *. simpl in H2. rewrite plus_assoc. apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (sumbool_of_bool (CGS_solve_1 cg n0 (c :: l) n)). intro H4.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim (H (c :: l) cg n0 H0 H1). intros rho H5. split with rho. elim H5. intros. simpl in |- *.
(* Goal: CGeval rho f *)
      split; try assumption. split; try assumption. unfold CGSeval in |- *. simpl in |- *. left. simpl in H6.
(* Goal: CGeval rho (CG_of_CGS c) *)
(* Goal: CGSeval_l rho l *)
(* Goal: lt (FlSize (@cons CGSForm c l)) n *)
(* Goal: @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c l) n) true *)
(* Goal: forall _ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c l) n) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      exact (proj1 H6).
(* Goal: CGSeval_l rho l *)
(* Goal: lt (FlSize (@cons CGSForm c l)) n *)
(* Goal: @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c l) n) true *)
(* Goal: forall _ : @eq bool (CGS_solve_1 cg n0 (@cons CGSForm c l) n) false, @sig (forall _ : ad, D) (fun rho : forall _ : ad, D => and (CGSeval_l rho (@cons CGSForm (CGSor c c0) l)) (CGsat cg rho)) *)
      exact (proj2 H6).
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      simpl in |- *. simpl in H2. apply le_lt_trans with (m := FSize c + FSize c0 + FlSize l).
(* Goal: le (Init.Nat.add (FSize c0) (FlSize l)) (Init.Nat.add (Init.Nat.add (FSize c) (FSize c0)) (FlSize l)) *)
(* Goal: lt (Init.Nat.add (Init.Nat.add (FSize c) (FSize c0)) (FlSize l)) n *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: CGsat cg rho *)
(* Goal: CGSeval_l rho (@cons CGSForm c0 l) *)
      apply plus_le_compat_r. apply le_plus_l.
(* Goal: CGeval rho f *)
      apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
      intro H4. rewrite H4 in H3. elim (H (c0 :: l) cg n0 H0). intros rho H5. elim H5.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. split with rho. split; try assumption. simpl in |- *. simpl in H6. elim H6. intros.
(* Goal: CGeval rho f *)
      split; try assumption. unfold CGSeval in |- *. simpl in |- *. right. assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      simpl in |- *. simpl in H2. apply le_lt_trans with (m := FSize c + FSize c0 + FlSize l).
(* Goal: le (FSize c0) (Init.Nat.add (FSize c) (FSize c0)) *)
(* Goal: lt (Init.Nat.add (Init.Nat.add (FSize c) (FSize c0)) (FlSize l)) n *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: CGsat cg rho *)
(* Goal: CGSeval_l rho (@cons CGSForm c0 l) *)
      apply plus_le_compat_r. apply le_plus_r.
(* Goal: CGeval rho f *)
      apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      assumption.
    Qed.

Lemma CGS_solve_correct :
 forall fs : CGSForm, CGS_solve fs = true -> {rho : ad -> D | CGSeval rho fs}.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (CGS_solve_1_correct (S (FSize fs)) (fs :: nil) (M0 _) 0). intros rho H0.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in H0. elim H0. intros. elim H1. intros. split with rho. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      split with (fun x : ad => Dz). unfold CGsat in |- *. unfold CG_edge in |- *. simpl in |- *. intros. discriminate H0.
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: CGsat (M0 (Map D)) rho *)
(* Goal: CGSeval_l rho (@cons CGSForm fs (@nil CGSForm)) *)
      apply le_n.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      simpl in |- *. rewrite <- plus_n_O. unfold lt in |- *. apply le_n.
(* Goal: @eq bool (CGS_solve_1 (M0 (Map D)) O (@cons CGSForm fs (@nil CGSForm)) (S (FSize fs))) true *)
      exact H.
    Qed.

Lemma CGS_translate_l :
 forall (fs : CGSForm) (rho : ad -> D) (d : D),
 CGSeval rho fs -> CGSeval (fun a : ad => Dplus d (rho a)) fs.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction fs. unfold CGSeval in |- *. simpl in |- *. intros. rewrite Dplus_assoc. apply Dle_plus_mono.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      apply Dle_refl.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CGSeval in |- *. simpl in |- *. intros. elim H1. intros. split. apply H. assumption.
(* Goal: CGeval rho f *)
      apply H0. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CGSeval in |- *. simpl in |- *. intros. elim H1. intro. left. apply H. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. right. apply H0. assumption.
    Qed.

Lemma CGS_solve_correct_anchored :
 forall fs : CGSForm,
 CGS_solve fs = true ->
 {rho : ad -> D | CGSeval rho fs /\ rho anchor = anchor_value}.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (CGS_solve_correct fs H). intros rho H0.
      split
       with
         (fun a : ad =>
(* Goal: and (CGeval rho f) (@eq D (rho anchor) anchor_value) *)
          Dplus (Dplus anchor_value (Dneg (rho anchor))) (rho a)). split.
(* Goal: CGeval rho f *)
      apply CGS_translate_l. assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      rewrite Dplus_assoc. rewrite Dplus_neg_2. apply Dplus_d_z.
    Qed.

Lemma CGS_solve_complete_1 :
 forall (gas : nat) (fsl : list CGSForm) (cg : CGraph1) (n : nat),
 FlSize fsl < gas ->
 MapCard _ cg <= n ->
 forall rho : ad -> D,
 CGsat cg rho -> CGSeval_l rho fsl -> CGS_solve_1 cg n fsl gas = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction gas. intros. elim (lt_n_O _ H).
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      intros n H fsl. case fsl. trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro fs. case fs. simpl in |- *. intros. unfold CG_test_ineq in |- *.
(* Goal: forall _ : CGconsistent cg, @eq bool (if Ddle (@Some D (Dneg d)) (ad_1_path_dist cg a0 a) then CGS_solve_1 (CG_add cg a a0 d) (S n0) l n else false) true *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
      rewrite <- (ad_1_path_dist_big_enough cg n0 H1 a0 a). cut (CGconsistent cg). intro H4.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      rewrite (ad_1_path_dist_correct cg H4 a0 a). elim H3. intros.
(* Goal: CGeval rho f *)
      rewrite (CG_sat_add_1 cg a a0 d rho H2 H5). apply H with (rho := rho). apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      apply CG_add_card_le. assumption.
(* Goal: CGeval rho f *)
      fold (cg2 cg a a0 d) in |- *. apply CG_add_1. assumption.
(* Goal: @eq bool (Dle (rho a) (Dplus (rho a0) d)) true *)
(* Goal: CGSeval_l rho l *)
(* Goal: CGconsistent cg *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSand c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSand c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSand c c0) l) (S n)) true *)
(* Goal: forall (c c0 : CGSForm) (l : list CGSForm) (cg : CGraph1) (n0 : nat) (_ : lt (FlSize (@cons CGSForm (CGSor c c0) l)) (S n)) (_ : le (MapCard (Map D) cg) n0) (rho : forall _ : ad, D) (_ : CGsat cg rho) (_ : CGSeval_l rho (@cons CGSForm (CGSor c c0) l)), @eq bool (CGS_solve_1 cg n0 (@cons CGSForm (CGSor c c0) l) (S n)) true *)
      exact H5.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      split with rho. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. apply H with (rho := rho). simpl in |- *. rewrite plus_assoc. apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim H3. intros. simpl in |- *. elim H4. intros. split; try assumption. split; assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. elim H3. intros. elim H4. intro. cut (CGS_solve_1 cg n0 (c :: l) n = true).
(* Goal: @eq bool (negb false) true *)
      intro H7. rewrite H7. reflexivity.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      apply H with (rho := rho). simpl in |- *.
(* Goal: lt (Init.Nat.add (FSize c0) (FlSize l)) n *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: CGsat cg rho *)
(* Goal: CGSeval_l rho (@cons CGSForm c0 l) *)
      apply le_lt_trans with (m := FSize c + FSize c0 + FlSize l). apply plus_le_compat_r.
(* Goal: le (FSize c) (Init.Nat.add (FSize c) (FSize c0)) *)
(* Goal: lt (Init.Nat.add (Init.Nat.add (FSize c) (FSize c0)) (FlSize l)) n *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: CGsat cg rho *)
(* Goal: CGSeval_l rho (@cons CGSForm c l) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS c0), @eq bool (if CGS_solve_1 cg n0 (@cons CGSForm c l) n then true else CGS_solve_1 cg n0 (@cons CGSForm c0 l) n) true *)
      apply le_plus_l.
(* Goal: CGeval rho f *)
      apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      split; assumption.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      intro H6. cut (CGS_solve_1 cg n0 (c0 :: l) n = true). intro H7.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      case (CGS_solve_1 cg n0 (c :: l) n); trivial.
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      apply H with (rho := rho). simpl in |- *.
(* Goal: lt (Init.Nat.add (FSize c0) (FlSize l)) n *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: CGsat cg rho *)
(* Goal: CGSeval_l rho (@cons CGSForm c0 l) *)
      apply le_lt_trans with (m := FSize c + FSize c0 + FlSize l). apply plus_le_compat_r.
(* Goal: le (FSize c0) (Init.Nat.add (FSize c) (FSize c0)) *)
(* Goal: lt (Init.Nat.add (Init.Nat.add (FSize c) (FSize c0)) (FlSize l)) n *)
(* Goal: le (MapCard (Map D) cg) n0 *)
(* Goal: CGsat cg rho *)
(* Goal: CGSeval_l rho (@cons CGSForm c0 l) *)
      apply le_plus_r.
(* Goal: CGeval rho f *)
      apply lt_S_n. assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      split; assumption.
    Qed.

Lemma CGS_solve_complete :
 forall (fs : CGSForm) (rho : ad -> D), CGSeval rho fs -> CGS_solve fs = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. apply
  (CGS_solve_complete_1 (S (FSize fs)) (fs :: nil) (M0 _) 0)
   with (rho := rho).
(* Goal: forall (f : CGForm) (anchor : ad) (anchor_value : D) (_ : forall (rho : forall _ : ad, D) (_ : @eq D (rho anchor) anchor_value), CGeval rho f), @eq bool (negb (CGS_solve false (CGFormSimplify (CGnot f)))) true *)
      simpl in |- *. rewrite <- plus_n_O. unfold lt in |- *. apply le_n.
(* Goal: le (MapCard (Map D) (M0 (Map D))) O *)
(* Goal: CGsat (M0 (Map D)) rho *)
(* Goal: CGSeval_l rho (@cons CGSForm fs (@nil CGSForm)) *)
      apply le_n.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CGsat in |- *. intros. unfold CG_edge in H0. discriminate H0.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      simpl in |- *. split; trivial.
    Qed.

Definition CGSeq (x y : ad) (d : D) :=
  CGSand (CGSleq x y d) (CGSleq y x (Dneg d)).

Lemma CGSeq_correct :
 forall (x y : ad) (d : D) (rho : ad -> D),
 CGSeval rho (CGSeq x y d) -> rho x = Dplus (rho y) d.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold CGSeq, CGSeval in H. simpl in H. elim H. intros. apply Dle_antisym. assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      apply Dplus_reg_r with (d'' := Dneg d). rewrite Dplus_assoc. rewrite Dplus_neg.
(* Goal: CGeval rho f *)
      rewrite Dplus_d_z. assumption.
    Qed.

Lemma CGSeq_complete :
 forall (x y : ad) (d : D) (rho : ad -> D),
 rho x = Dplus (rho y) d -> CGSeval rho (CGSeq x y d).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold CGSeq, CGSeval in |- *. simpl in |- *. rewrite H. split. apply Dle_refl.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      rewrite Dplus_assoc. rewrite Dplus_neg. rewrite Dplus_d_z. apply Dle_refl.
    Qed.

End CGSSolve.

Section CGWithOne.

    Variable Done : D.
    Variable Done_pos : Dle Done Dz = false.
    Variable
      Done_min_pos : forall d : D, Dle d Dz = false -> Dle Done d = true.

(*s Defining the negation of a formula :
	  $\neg x \leq y+d \Leftrightarrow x>y+d \Leftrightarrow x \geq y+d+1$
 *)
Fixpoint CGSnot (fs : CGSForm) : CGSForm :=
  match fs with
  | CGSleq x y d => CGSleq y x (Dneg (Dplus d Done))
  | CGSand f0 f1 => CGSor (CGSnot f0) (CGSnot f1)
  | CGSor f0 f1 => CGSand (CGSnot f0) (CGSnot f1)
  end.

Lemma Dmone_neg : Dle Dz (Dneg Done) = false.
    Proof.
(* Goal: forall _ : @eq D (rho a) (Dplus (rho a0) d), and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true) *)
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      elim (sumbool_of_bool (Dle Dz (Dneg Done))). intro H. 
(* Goal: @eq bool (Dle Dz (Dneg Done)) false *)
(* Goal: forall _ : @eq bool (Dle Dz (Dneg Done)) false, @eq bool (Dle Dz (Dneg Done)) false *)
      rewrite <- (Dneg_neg Done) in Done_pos.
(* Goal: @eq bool (Dle Dz (Dneg Done)) false *)
(* Goal: forall _ : @eq bool (Dle Dz (Dneg Done)) false, @eq bool (Dle Dz (Dneg Done)) false *)
      rewrite (Dle_neg _ H) in Done_pos. discriminate Done_pos.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      trivial.
    Qed.

Lemma Dminus_one_1 : forall d : D, Dle d (Dplus d (Dneg Done)) = false.
    Proof.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. elim (sumbool_of_bool (Dle d (Dplus d (Dneg Done)))). intro H.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      cut (Dle Dz (Dneg Done) = true). intro. rewrite Dmone_neg in H0. discriminate H0.
(* Goal: CGeval rho f *)
      apply Dplus_reg_l with (d'' := d). rewrite Dplus_d_z. assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      trivial.
    Qed.

Lemma Dle_lt_1 :
 forall d d' : D, Dle d' d = false -> Dle d (Dplus d' (Dneg Done)) = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. apply Dplus_reg_r with (d'' := Done). rewrite Dplus_assoc. rewrite Dplus_neg_2.
(* Goal: @eq bool (Dle (rho a0) (Dplus (rho a) (Dplus (Dneg Done) (Dneg d)))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      rewrite Dplus_d_z. apply Dplus_reg_l with (d'' := Dneg d). rewrite <- Dplus_assoc.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg Done)) (Dplus (Dneg d) d))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      rewrite Dplus_neg_2. rewrite Dplus_z_d. apply Done_min_pos.
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim (sumbool_of_bool (Dle (Dplus (Dneg d) d') Dz)). intro H0. cut (Dle d' d = true).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      rewrite H. intro. discriminate H1.
(* Goal: CGeval rho f *)
      apply Dplus_reg_l with (d'' := Dneg d). rewrite Dplus_neg_2. assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      trivial.
    Qed.

Lemma Dle_lt_2 :
 forall d d' : D, Dle d (Dplus d' (Dneg Done)) = true -> Dle d' d = false.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (sumbool_of_bool (Dle d' d)). intro H0. cut (Dle d (Dplus d (Dneg Done)) = true).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      rewrite Dminus_one_1. intro. discriminate H1.
(* Goal: CGeval rho f *)
      apply Dle_trans with (d' := Dplus d' (Dneg Done)). assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      apply Dle_plus_mono. assumption.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      apply Dle_refl.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      trivial.
    Qed.

Lemma CGSnot_correct :
 forall (fs : CGSForm) (rho : ad -> D),
 CGSeval rho fs -> ~ CGSeval rho (CGSnot fs).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold not in |- *. simple induction fs. simpl in |- *. unfold CGSeval in |- *. simpl in |- *. intros.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      cut (Dle (rho a) (Dplus (rho a) (Dneg Done)) = true). rewrite Dminus_one_1. intro.
(* Goal: False *)
(* Goal: @eq bool (Dle (rho a) (Dplus (rho a) (Dneg Done))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      discriminate H1.
(* Goal: @eq bool (Dle (rho a) (Dplus (rho a) (Dneg Done))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      rewrite <- (Dplus_d_z (Dneg Done)). rewrite <- (Dplus_neg_2 d).
(* Goal: @eq bool (Dle (rho a) (Dplus (rho a) (Dplus (Dplus (Dneg Done) (Dneg d)) d))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      rewrite <- (Dplus_assoc (Dneg Done)). rewrite <- Dneg_plus.
(* Goal: CGeval rho f *)
      apply Dle_trans with (d' := Dplus (rho a0) d). assumption.
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (rho a) (Dneg (Dplus d Done))) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      rewrite <- Dplus_assoc. apply Dle_plus_mono. assumption.
(* Goal: @eq bool (Dle d d) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSand c c0)) (_ : CGSeval rho (CGSnot (CGSand c c0))), False *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c) (_ : CGSeval rho (CGSnot c)), False) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : CGSeval rho c0) (_ : CGSeval rho (CGSnot c0)), False) (rho : forall _ : ad, D) (_ : CGSeval rho (CGSor c c0)) (_ : CGSeval rho (CGSnot (CGSor c c0))), False *)
      apply Dle_refl.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CGSeval in |- *. simpl in |- *. intros. elim H1. intros. elim H2. intro. exact (H rho H3 H5).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. exact (H0 rho H4 H5).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CGSeval in |- *. simpl in |- *. intros. elim H2. intros. elim H1. intro. exact (H rho H5 H3).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. exact (H0 rho H5 H4).
    Qed.

Lemma CGSnot_complete :
 forall (fs : CGSForm) (rho : ad -> D),
 ~ CGSeval rho (CGSnot fs) -> CGSeval rho fs.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold not, CGSeval in |- *. simple induction fs. simpl in |- *. intros.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      elim (sumbool_of_bool (Dle (rho a) (Dplus (rho a0) d))). trivial.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro H0. cut False. intro. elim H1.
(* Goal: @eq bool (Dle (rho a0) (Dplus (rho a) (Dplus (Dneg Done) (Dneg d)))) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      apply H. rewrite Dneg_plus. rewrite <- Dplus_assoc. apply Dplus_reg_r with (d'' := d).
(* Goal: @eq bool (Dle (Dplus (rho a0) d) (Dplus (Dplus (Dplus (rho a) (Dneg Done)) (Dneg d)) d)) true *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSand c c0))), False), CGeval rho (CG_of_CGS (CGSand c c0)) *)
(* Goal: forall (c : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c)), False), CGeval rho (CG_of_CGS c)) (c0 : CGSForm) (_ : forall (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot c0)), False), CGeval rho (CG_of_CGS c0)) (rho : forall _ : ad, D) (_ : forall _ : CGeval rho (CG_of_CGS (CGSnot (CGSor c c0))), False), CGeval rho (CG_of_CGS (CGSor c c0)) *)
      rewrite Dplus_assoc. rewrite Dplus_neg_2. rewrite Dplus_d_z. apply Dle_lt_1. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. split. apply H. intro. apply H1. left. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      apply H0. intro. apply H1. right. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros.
      cut
       (~ CGeval rho (CG_of_CGS (CGSnot c)) \/
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
        ~ CGeval rho (CG_of_CGS (CGSnot c0))). intro.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      elim H2. intro. left. apply H. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. right. apply H0. assumption.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot c))), or (not (CGeval rho (CG_of_CGS (CGSnot c)))) (not (CGeval rho (CG_of_CGS (CGSnot c0)))) *)
      elim (CGeval_dec (CG_of_CGS (CGSnot c)) rho). intro H2.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      elim (CGeval_dec (CG_of_CGS (CGSnot c0)) rho). intro H3. elim (H1 (conj H2 H3)).
(* Goal: CGeval rho f *)
      intro H3. right. assumption.
(* Goal: CGeval rho f *)
      intro H2. left. assumption.
    Qed.

(*s Interpreting formula as simplified formula *)

Fixpoint CGFormSimplify (f : CGForm) : CGSForm :=
  match f with
  | CGleq x y d => CGSleq x y d
  | CGeq x y d => CGSeq x y d
  | CGand f0 f1 => CGSand (CGFormSimplify f0) (CGFormSimplify f1)
  | CGor f0 f1 => CGSor (CGFormSimplify f0) (CGFormSimplify f1)
  | CGimp f0 f1 => CGSor (CGSnot (CGFormSimplify f0)) (CGFormSimplify f1)
  | CGnot f0 => CGSnot (CGFormSimplify f0)
  end.

Lemma CGFormSimplify_correct :
 forall (f : CGForm) (rho : ad -> D),
 CGeval rho f <-> CGSeval rho (CGFormSimplify f).
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simple induction f. intros. split; trivial.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold CGSeval in |- *. simpl in |- *. split. intro H. exact (CGSeq_complete a a0 d rho H).
(* Goal: forall _ : and (@eq bool (Dle (rho a) (Dplus (rho a0) d)) true) (@eq bool (Dle (rho a0) (Dplus (rho a) (Dneg d))) true), @eq D (rho a) (Dplus (rho a0) d) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGand c c0)) (CGSeval rho (CGFormSimplify (CGand c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGor c c0)) (CGSeval rho (CGFormSimplify (CGor c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (c0 : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c0) (CGSeval rho (CGFormSimplify c0))) (rho : forall _ : ad, D), iff (CGeval rho (CGimp c c0)) (CGSeval rho (CGFormSimplify (CGimp c c0))) *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      exact (CGSeq_correct a a0 d rho).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. unfold CGSeval in |- *. simpl in |- *. elim (H rho). intros. elim (H0 rho). intros.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      split. intro. elim H5. intros. split. apply H1. assumption.
(* Goal: CGeval rho f *)
      apply H3. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro. elim H5. intros. split. apply H2. assumption.
(* Goal: CGeval rho f *)
      apply H4. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. unfold CGSeval in |- *. elim (H rho). intros. elim (H0 rho). intros. simpl in |- *. split.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. elim H5. intro. left. apply H1. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. right. apply H3. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. elim H5. intro. left. apply H2. assumption.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. right. apply H4. assumption.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      simpl in |- *. intros. unfold CGSeval in |- *. simpl in |- *. elim (H rho). intros. elim (H0 rho). intros. split.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      intro. elim (CGeval_dec c rho). intro H6. right. apply H3. apply H5. assumption.
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      intro H6. left. elim (CGeval_dec (CG_of_CGS (CGSnot (CGFormSimplify c))) rho). trivial.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall (_ : or (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))) (CGeval rho (CG_of_CGS (CGFormSimplify c0)))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      intro H7. elim (H6 (H2 (CGSnot_complete _ _ H7))).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intro. elim H5. intros. elim (CGeval_dec (CG_of_CGS (CGFormSimplify c)) rho). intro H8.
(* Goal: CGeval rho c0 *)
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGFormSimplify c))), CGeval rho c0 *)
(* Goal: forall (_ : CGeval rho (CG_of_CGS (CGFormSimplify c0))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      elim (CGSnot_correct _ _ H8 H6).
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGFormSimplify c))), CGeval rho c0 *)
(* Goal: forall (_ : CGeval rho (CG_of_CGS (CGFormSimplify c0))) (_ : CGeval rho c), CGeval rho c0 *)
(* Goal: forall (c : CGForm) (_ : forall rho : forall _ : ad, D, iff (CGeval rho c) (CGSeval rho (CGFormSimplify c))) (rho : forall _ : ad, D), iff (CGeval rho (CGnot c)) (CGSeval rho (CGFormSimplify (CGnot c))) *)
      intro H8. elim (H8 (H1 H7)).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. apply H4. assumption. simpl in |- *. intros. unfold CGSeval in |- *. simpl in |- *. elim (H rho). intros.
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      split. intro. elim (CGeval_dec (CG_of_CGS (CGSnot (CGFormSimplify c))) rho). trivial.
(* Goal: forall _ : not (CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c)))), CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))) *)
(* Goal: forall _ : CGeval rho (CG_of_CGS (CGSnot (CGFormSimplify c))), not (CGeval rho c) *)
      intro H3. elim (H2 (H1 (CGSnot_complete _ _ H3))).
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold not in |- *. intros. elim (CGSnot_correct _ _ (H0 H3) H2).
    Qed.

(*s Formula are solved by looking at their simplified form *)

Definition CG_solve (f : CGForm) := CGS_solve false (CGFormSimplify f).

Theorem CG_solve_correct :
 forall f : CGForm, CG_solve f = true -> {rho : ad -> D | CGeval rho f}.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (CGS_solve_correct _ _ H). intros rho H0. split with rho.
(* Goal: CGeval rho f *)
      apply (proj2 (CGFormSimplify_correct f rho)). assumption.
    Qed.

Theorem CG_solve_correct_anchored :
 forall (anchor : ad) (anchor_value : D) (f : CGForm),
 CG_solve f = true ->
 {rho : ad -> D | CGeval rho f /\ rho anchor = anchor_value}.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. elim (CGS_solve_correct_anchored anchor anchor_value _ _ H). intros rho H0.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      split with rho. elim H0. intros. split. apply (proj2 (CGFormSimplify_correct f rho)).
(* Goal: CGeval rho f *)
      assumption.
(* Goal: CGeval rho f *)
      assumption.
    Qed.

Theorem CG_solve_complete :
 forall (f : CGForm) (rho : ad -> D), CGeval rho f -> CG_solve f = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      intros. unfold CG_solve in |- *. apply (CGS_solve_complete false) with (rho := rho).
(* Goal: CGeval rho f *)
      apply (proj1 (CGFormSimplify_correct f rho)). assumption.
    Qed.

(*s A formula is proved when its negation cannot be satisfied *)

Definition CG_prove (f : CGForm) := negb (CG_solve (CGnot f)).

Theorem CG_prove_correct :
 forall f : CGForm, CG_prove f = true -> forall rho : ad -> D, CGeval rho f.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CG_prove, CG_solve in |- *. simpl in |- *. intros. apply (proj2 (CGFormSimplify_correct f rho)).
(* Goal: forall _ : CGSeval rho (CGSnot (CGFormSimplify f)), False *)
      apply CGSnot_complete. unfold not in |- *. intro. rewrite (CGS_solve_complete false _ _ H0) in H.
(* Goal: False *)
      discriminate H.
    Qed.

Theorem CG_prove_complete :
 forall f : CGForm, (forall rho : ad -> D, CGeval rho f) -> CG_prove f = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CG_prove, CG_solve in |- *. simpl in |- *. intros.
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim (sumbool_of_bool (CGS_solve false (CGSnot (CGFormSimplify f)))). intro H0.
(* Goal: @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim (CGS_solve_correct false _ H0). intros rho H1.
      elim
       (CGSnot_correct _ _ (proj1 (CGFormSimplify_correct _ _) (H rho)) H1).
(* Goal: @eq bool (negb false) true *)
      intro H0. rewrite H0. reflexivity.
    Qed.

Theorem CG_prove_complete_anchored :
 forall (f : CGForm) (anchor : ad) (anchor_value : D),
 (forall rho : ad -> D, rho anchor = anchor_value -> CGeval rho f) ->
 CG_prove f = true.
    Proof.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      unfold CG_prove, CG_solve in |- *. simpl in |- *. intros.
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim (sumbool_of_bool (CGS_solve false (CGSnot (CGFormSimplify f)))). intro H0.
(* Goal: forall (x : forall _ : ad, D) (_ : and (CGSeval x (CGSnot (CGFormSimplify f))) (@eq D (x anchor) anchor_value)), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim (CGS_solve_correct_anchored anchor anchor_value false _ H0). intros rho H1.
(* Goal: forall (_ : CGSeval rho (CGSnot (CGFormSimplify f))) (_ : @eq D (rho anchor) anchor_value), @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
(* Goal: forall _ : @eq bool (CGS_solve false (CGSnot (CGFormSimplify f))) false, @eq bool (negb (CGS_solve false (CGSnot (CGFormSimplify f)))) true *)
      elim H1. intros.
      elim
       (CGSnot_correct _ _ (proj1 (CGFormSimplify_correct f rho) (H rho H3))
          H2).
(* Goal: @eq bool (negb false) true *)
      intro H0. rewrite H0. reflexivity.
    Qed.

  End CGWithOne.

End ConstraintGraphs.
