(* An interpretation of BDDvar's *)
Definition var_binding := BDDvar -> bool.(* A boolean function. However not all boolean functions represent a logical
   formula. *)
Definition bool_fun := var_binding -> bool.(* Evaluation of a boolean function given a binding of variables *)
Definition bool_fun_eval (bf : bool_fun) (vb : var_binding) := bf vb.(* The boolean functions representing ZERO and ONE *)
Definition bool_fun_zero (vb : var_binding) := false.Definition bool_fun_one (vb : var_binding) := true.Fixpoint bool_fun_of_BDD_1 (cfg : BDDconfig) (node : ad) 
 (bound : nat) {struct bound} : bool_fun :=
  match MapGet _ (fst cfg) node with
  | None => if Neqb node BDDzero then bool_fun_zero else bool_fun_one
  | Some (x, (l, r)) =>
      match bound with
      | O => (* Error *)  bool_fun_zero
      | S bound' =>
          let bfl := bool_fun_of_BDD_1 cfg l bound' in
          let bfr := bool_fun_of_BDD_1 cfg r bound' in
          fun vb : var_binding => if vb x then bfr vb else bfl vb
      end
  end.

(* Specifications: *)
Lemma bool_fun_of_BDD_1_semantics : forall cfg : BDDconfig, BDDconfig_OK cfg -> forall bound : nat, bool_fun_of_BDD_1 cfg BDDzero bound = bool_fun_zero /\ bool_fun_of_BDD_1 cfg BDDone bound = bool_fun_one /\ (forall node : ad, is_internal_node cfg node -> nat_of_N (var cfg node) < bound -> forall vb : var_binding, (vb (var cfg node) = true -> bool_fun_eval (bool_fun_of_BDD_1 cfg node bound) vb = bool_fun_eval (bool_fun_of_BDD_1 cfg (high cfg node) (pred bound)) vb) /\ (vb (var cfg node) = false -> bool_fun_eval (bool_fun_of_BDD_1 cfg node bound) vb = bool_fun_eval (bool_fun_of_BDD_1 cfg (low cfg node) (pred bound)) vb)).
Lemma bool_fun_of_BDD_1_semantics_1 : forall cfg : BDDconfig, BDDconfig_OK cfg -> forall bound : nat, bool_fun_of_BDD_1 cfg BDDzero bound = bool_fun_zero /\ bool_fun_of_BDD_1 cfg BDDone bound = bool_fun_one /\ (forall node : ad, is_internal_node cfg node -> nat_of_N (var cfg node) < bound -> bool_fun_of_BDD_1 cfg node bound = (fun vb : var_binding => if vb (var cfg node) then bool_fun_of_BDD_1 cfg (high cfg node) (pred bound) vb else bool_fun_of_BDD_1 cfg (low cfg node) (pred bound) vb)).
Lemma bool_fun_of_BDD_1_semantics_2 : forall (cfg : BDDconfig) (node : ad) (bound1 bound2 : nat), MapGet _ (fst cfg) node = None -> bool_fun_of_BDD_1 cfg node bound1 = bool_fun_of_BDD_1 cfg node bound2.
Lemma bool_fun_of_BDD_1_change_bound : forall cfg : BDDconfig, BDDconfig_OK cfg -> forall (bound : nat) (node : ad), nat_of_N (var cfg node) < bound -> bool_fun_of_BDD_1 cfg node bound = bool_fun_of_BDD_1 cfg node (S (nat_of_N (var cfg node))).