Inductive bool_expr : Set :=
| Zero : bool_expr
| One : bool_expr
| Var : BDDvar -> bool_expr
| Neg : bool_expr -> bool_expr
| Or : bool_expr -> bool_expr -> bool_expr
| ANd : bool_expr -> bool_expr -> bool_expr
| Impl : bool_expr -> bool_expr -> bool_expr
| Iff : bool_expr -> bool_expr -> bool_expr.
Fixpoint bool_fun_of_bool_expr (be : bool_expr) : bool_fun :=
match be with
| Zero => bool_fun_zero
| One => bool_fun_one
| Var x => bool_fun_var x
| Neg be' => bool_fun_neg (bool_fun_of_bool_expr be')
| Or be1 be2 =>
bool_fun_or (bool_fun_of_bool_expr be1) (bool_fun_of_bool_expr be2)
| ANd be1 be2 =>
bool_fun_and (bool_fun_of_bool_expr be1) (bool_fun_of_bool_expr be2)
| Impl be1 be2 =>
bool_fun_impl (bool_fun_of_bool_expr be1) (bool_fun_of_bool_expr be2)
| Iff be1 be2 =>
bool_fun_iff (bool_fun_of_bool_expr be1) (bool_fun_of_bool_expr be2)
end.
Fixpoint BDDof_bool_expr (cfg : BDDconfig) (negm : BDDneg_memo)
(orm : BDDor_memo) (be : bool_expr) {struct be} :
BDDconfig * (ad * (BDDneg_memo * BDDor_memo)) :=
match be with
| Zero => (cfg, (BDDzero, (negm, orm)))
| One => (cfg, (BDDone, (negm, orm)))
| Var x =>
match BDDvar_make cfg x with
| (cfg', node) => (cfg', (node, (negm, orm)))
end
| Neg be' =>
match BDDof_bool_expr cfg negm orm be' with
| (cfg', (node, (negm', orm'))) =>
match BDDneg cfg' negm' node with
| (cfg'', (node', negm'')) => (cfg'', (node', (negm'', orm')))
end
end
| Or be1 be2 =>
match BDDof_bool_expr cfg negm orm be1 with
| (cfg', (node1, (negm', orm'))) =>
match BDDof_bool_expr cfg' negm' orm' be2 with
| (cfg'', (node2, (negm'', orm''))) =>
match BDDor cfg'' orm'' node1 node2 with
| (cfg''', (node, orm''')) =>
(cfg''', (node, (negm'', orm''')))
end
end
end
| ANd be1 be2 =>
match BDDof_bool_expr cfg negm orm be1 with
| (cfg', (node1, (negm', orm'))) =>
match BDDof_bool_expr cfg' negm' orm' be2 with
| (cfg'', (node2, (negm'', orm''))) =>
BDDand cfg'' negm'' orm'' node1 node2
end
end
| Impl be1 be2 =>
match BDDof_bool_expr cfg negm orm be1 with
| (cfg', (node1, (negm', orm'))) =>
match BDDof_bool_expr cfg' negm' orm' be2 with
| (cfg'', (node2, (negm'', orm''))) =>
BDDimpl cfg'' negm'' orm'' node1 node2
end
end
| Iff be1 be2 =>
match BDDof_bool_expr cfg negm orm be1 with
| (cfg', (node1, (negm', orm'))) =>
match BDDof_bool_expr cfg' negm' orm' be2 with
| (cfg'', (node2, (negm'', orm''))) =>
BDDiff cfg'' negm'' orm'' node1 node2
end
end
end.

(* Specifications: *)
Lemma BDDof_bool_expr_correct :
forall (be : bool_expr) (cfg : BDDconfig) (negm : BDDneg_memo)
(orm : BDDor_memo),
BDDconfig_OK cfg ->
BDDneg_memo_OK_2 cfg negm ->
BDDor_memo_OK cfg orm ->
BDDconfig_OK (fst (BDDof_bool_expr cfg negm orm be)) /\
config_node_OK (fst (BDDof_bool_expr cfg negm orm be))
(fst (snd (BDDof_bool_expr cfg negm orm be))) /\
BDDneg_memo_OK_2 (fst (BDDof_bool_expr cfg negm orm be))
(fst (snd (snd (BDDof_bool_expr cfg negm orm be)))) /\
BDDor_memo_OK (fst (BDDof_bool_expr cfg negm orm be))
(snd (snd (snd (BDDof_bool_expr cfg negm orm be)))) /\
nodes_preserved cfg (fst (BDDof_bool_expr cfg negm orm be)) /\
bool_fun_eq
(bool_fun_of_BDD (fst (BDDof_bool_expr cfg negm orm be))
(fst (snd (BDDof_bool_expr cfg negm orm be))))
(bool_fun_of_bool_expr be).