Skip to content

Commit

Permalink
restored implementation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
backtracking committed Feb 28, 2022
1 parent c326d41 commit c02ea95
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/bdd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ let get_max_var () = max_var
type bdd = { tag: int; node : view }
and view = Zero | One | Node of variable * bdd (*low*) * bdd (*high*)

(* Notes:
- Variables are ordered as integers, i.e. variable indices increase
as we descend in the BDD.
- A node is created using function `mk` below. *)

type t = bdd (* export *)

let view b = b.node
Expand Down Expand Up @@ -282,6 +287,10 @@ let high b = match b.node with
| Zero | One -> invalid_arg "Bdd.low"
| Node (_, _, h) -> h

(* Note: `mk` ensures that BDDs are reduced and maximally shared.
But it *does not* ensure that BDDs are ordered. This is ensured by
the various functions below. See for instance the code of `gapply`
and the way it compares variables before proceeding recursively. *)
let mk v ~low ~high =
if low == high then low else hashcons_node v low high

Expand Down Expand Up @@ -415,7 +424,6 @@ let mk_imp = gapply Op_imp
let mk_iff = gapply (Op_any (fun b1 b2 -> b1 == b2))



(** {2 quantifier elimination} *)

let rec quantifier_elim cache op filter b =
Expand Down Expand Up @@ -451,18 +459,16 @@ let rec extract_known_values cache b =
with Not_found ->
let res = match b.node with
| Zero | One -> BddVarMap.empty
| Node(v,{node=Zero;_},h) ->
| Node(v, {node=Zero;_}, h) ->
(* if v then h else 0 --> v /\ h *)
BddVarMap.add v true (extract_known_values cache h)
| Node(v,l,{node=Zero;_}) ->
| Node(v, l, {node=Zero;_}) ->
(* if v then 0 else l --> !v /\ l *)
BddVarMap.add v false (extract_known_values cache l)
| Node(_,l,h) ->
| Node(_, l, h) ->
let m1 = extract_known_values cache l in
let m2 = extract_known_values cache h in
let merge_bool _ b1 b2 =
if b1=b2 then Some b1 else None
in
let merge_bool _ b1 b2 = if b1 = b2 then Some b1 else None in
BddVarMap.union merge_bool m1 m2
in
H1.add cache b res;
Expand All @@ -472,13 +478,6 @@ let extract_known_values b =
let cache = H1.create cache_default_size in
extract_known_values cache b








let apply f = gapply (Op_any f)

let constrain b1 b2 =
Expand Down

0 comments on commit c02ea95

Please sign in to comment.