Definition BDDiff (cfg : BDDconfig) (negm : BDDneg_memo) 
  (orm : BDDor_memo) (node1 node2 : ad) :=
  match BDDimpl cfg negm orm node1 node2 with
  | (cfg', (node1', (negm', orm'))) =>
      match BDDimpl cfg' negm' orm' node2 node1 with
      | (cfg'', (node2', (negm'', orm''))) =>
          BDDand cfg'' negm'' orm'' node1' node2'
      end
  end.

(* Specifications: *)
Lemma BDDiff_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 (BDDiff cfg negm orm node1 node2)).
Lemma BDDiff_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 (BDDiff cfg negm orm node1 node2)) (fst (snd (BDDiff cfg negm orm node1 node2))).
Lemma BDDiff_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 (BDDiff cfg negm orm node1 node2)).
Lemma BDDiff_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 (BDDiff cfg negm orm node1 node2)) (fst (snd (snd (BDDiff cfg negm orm node1 node2)))).
Lemma BDDiff_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 (BDDiff cfg negm orm node1 node2)) (snd (snd (snd (BDDiff cfg negm orm node1 node2)))).