Definition BDDneg (cfg : BDDconfig) (memo : BDDneg_memo) 
  (node : ad) :=
  match BDDneg_1_1 cfg memo node (S (nat_of_N (var cfg node))) with
  | ((cfg', node'), memo') => (cfg', (node', memo'))
  end.Definition BDDor (cfg : BDDconfig) (memo : BDDor_memo) 
  (node1 node2 : ad) :=
  BDDor_1_1 cfg memo node1 node2
    (S (max (nat_of_N (var cfg node1)) (nat_of_N (var cfg node2)))).Definition BDDand (cfg : BDDconfig) (negm : BDDneg_memo) 
  (orm : BDDor_memo) (node1 node2 : ad) :=
  match BDDneg cfg negm node1 with
  | (cfg', (node1', negm')) =>
      match BDDneg cfg' negm' node2 with
      | (cfg'', (node2', negm'')) =>
          match BDDor cfg'' orm node1' node2' with
          | (cfg''', (node, orm')) =>
              match BDDneg cfg''' negm'' node with
              | (cfg'''', (node', negm''')) =>
                  (cfg'''', (node', (negm''', orm')))
              end
          end
      end
  end.

(* Specifications: *)
Lemma nodes_preserved_orm_OK : forall (cfg cfg' : BDDconfig) (orm : BDDor_memo), BDDconfig_OK cfg -> BDDconfig_OK cfg' -> nodes_preserved cfg cfg' -> BDDor_memo_OK cfg orm -> BDDor_memo_OK cfg' orm.
Lemma nodes_preserved_negm_OK : forall (cfg cfg' : BDDconfig) (negm : BDDneg_memo), BDDconfig_OK cfg -> BDDconfig_OK cfg' -> nodes_preserved cfg cfg' -> BDDneg_memo_OK_2 cfg negm -> BDDneg_memo_OK_2 cfg' negm.
Lemma BDDneg_keeps_config_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> BDDconfig_OK (fst (BDDneg cfg negm node)).
Lemma BDDneg_node_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> config_node_OK (fst (BDDneg cfg negm node)) (fst (snd (BDDneg cfg negm node))).
Lemma BDDneg_preserves_nodes : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> nodes_preserved cfg (fst (BDDneg cfg negm node)).
Lemma BDDneg_keeps_neg_memo_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> BDDneg_memo_OK_2 (fst (BDDneg cfg negm node)) (snd (snd (BDDneg cfg negm node))).
Lemma BDDneg_keeps_or_memo_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> BDDor_memo_OK cfg orm -> BDDor_memo_OK (fst (BDDneg cfg negm node)) orm.
Lemma BDDneg_keeps_node_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> forall node' : ad, config_node_OK cfg node' -> config_node_OK (fst (BDDneg cfg negm node)) node'.
Lemma BDDneg_preserves_bool_fun : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> forall node' : ad, config_node_OK cfg node' -> bool_fun_eq (bool_fun_of_BDD (fst (BDDneg cfg negm node)) node') (bool_fun_of_BDD cfg node').
Lemma BDDneg_is_neg : forall (cfg : BDDconfig) (negm : BDDneg_memo) (node : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> config_node_OK cfg node -> bool_fun_eq (bool_fun_of_BDD (fst (BDDneg cfg negm node)) (fst (snd (BDDneg cfg negm node)))) (bool_fun_neg (bool_fun_of_BDD cfg node)).
Lemma BDDor_keeps_config_OK : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> BDDconfig_OK (fst (BDDor cfg orm node1 node2)).
Lemma BDDor_node_OK : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> config_node_OK (fst (BDDor cfg orm node1 node2)) (fst (snd (BDDor cfg orm node1 node2))).
Lemma BDDor_keeps_or_memo_OK : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> BDDor_memo_OK (fst (BDDor cfg orm node1 node2)) (snd (snd (BDDor cfg orm node1 node2))).
Lemma BDDor_preserves_nodes : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> nodes_preserved cfg (fst (BDDor cfg orm node1 node2)).
Lemma BDDor_keeps_node_OK : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> forall node : ad, config_node_OK cfg node -> config_node_OK (fst (BDDor cfg orm node1 node2)) node.
Lemma BDDor_preserves_bool_fun : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> forall node : ad, config_node_OK cfg node -> bool_fun_eq (bool_fun_of_BDD (fst (BDDor cfg orm node1 node2)) node) (bool_fun_of_BDD cfg node).
Lemma BDDor_keeps_neg_memo_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> BDDneg_memo_OK_2 cfg negm -> BDDneg_memo_OK_2 (fst (BDDor cfg orm node1 node2)) negm.
Lemma BDDor_is_or : forall (cfg : BDDconfig) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> bool_fun_eq (bool_fun_of_BDD (fst (BDDor cfg orm node1 node2)) (fst (snd (BDDor cfg orm node1 node2)))) (bool_fun_or (bool_fun_of_BDD cfg node1) (bool_fun_of_BDD cfg node2)).
Lemma BDDand_keeps_config_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> BDDconfig_OK (fst (BDDand cfg negm orm node1 node2)).
Lemma BDDand_node_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> config_node_OK (fst (BDDand cfg negm orm node1 node2)) (fst (snd (BDDand cfg negm orm node1 node2))).
Lemma BDDand_preserves_nodes : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> nodes_preserved cfg (fst (BDDand cfg negm orm node1 node2)).
Lemma BDDand_keeps_node_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> forall node : ad, config_node_OK cfg node -> config_node_OK (fst (BDDand cfg negm orm node1 node2)) node.
Lemma BDDand_preserves_bool_fun : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> forall node : ad, config_node_OK cfg node -> bool_fun_eq (bool_fun_of_BDD (fst (BDDand cfg negm orm node1 node2)) node) (bool_fun_of_BDD cfg node).
Lemma BDDand_keeps_neg_memo_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> BDDneg_memo_OK_2 (fst (BDDand cfg negm orm node1 node2)) (fst (snd (snd (BDDand cfg negm orm node1 node2)))).
Lemma BDDand_keeps_or_memo_OK : forall (cfg : BDDconfig) (negm : BDDneg_memo) (orm : BDDor_memo) (node1 node2 : ad), BDDconfig_OK cfg -> BDDneg_memo_OK_2 cfg negm -> BDDor_memo_OK cfg orm -> config_node_OK cfg node1 -> config_node_OK cfg node2 -> BDDor_memo_OK (fst (BDDand cfg negm orm node1 node2)) (snd (snd (snd (BDDand cfg negm orm node1 node2)))).