package bdd

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module type Bdd.BDDSource

Binary Decision Diagrams (BDDs)

Number of variables

Sourceval get_max_var : unit -> int

Returns the number of variables max_var. Default value is 0, which means that bdds cannot be created until the module is initialized using set_max_var.

The abstract type of BDD nodes

Sourcetype t

View

Sourcetype view =
  1. | Zero
  2. | One
  3. | Node of variable * t * t
Sourceval view : t -> view

Displays a bdd as a tree.

Accessors

Sourceval var : t -> variable

The root variable of a bdd. Convention: Zero and One have variable max_var+1

Sourceval low : t -> t
Sourceval high : t -> t

The low and high parts of a bdd, respectively. low and high raise Invalid_argument on Zero and One.

Constructors

Sourceval zero : t
Sourceval one : t
Sourceval make : variable -> low:t -> high:t -> t

Builds a bdd node. Raises Invalid_argument is the variable is out of 1..max_var.

Sourceval mk_var : variable -> t

Builds the bdd reduced to a single variable.

Sourceval mk_not : t -> t
Sourceval mk_and : t -> t -> t
Sourceval mk_or : t -> t -> t
Sourceval mk_imp : t -> t -> t
Sourceval mk_iff : t -> t -> t

Builds bdds for negation, conjunction, disjunction, implication, and logical equivalence.

Quantifier elimination

Sourceval mk_exist : (variable -> bool) -> t -> t
Sourceval mk_forall : (variable -> bool) -> t -> t

mk_exists f b (resp. mk_forall f b) quantifies bdd b over all variables v for which f v holds. For example: mk_exists x. x /\ y produces y, mk_exists x. x \/ y produces one, mk_forall x. x /\ y produces zero and mk_forall x. x \/ y produces y. See test/quant_elim.ml.

Sourceval extract_known_values : t -> bool BddVarMap.t

extract_known_values b returns a map indexed by variables, associated to Boolean values. In that map, a variable v is associated to true (resp. false) if bdd b entails v to have this value, that is b -> v=true (resp b -> v=false) is a tautology.

Generic binary operator constructor

Sourceval apply : (bool -> bool -> bool) -> t -> t -> t

Applies the given Boolean function to two bdds. Caveat: Do not use this function to compute the usual Boolean operations (conjunction, disjunction, etc.). Use instead the operations above (mk_and, etc.), which are more efficient.

Sourceval constrain : t -> t -> t

constrain f g is the generalized cofactor, sometimes written f ↓ g. It is defined for any function g <> false so that f = (g /\ (f ↓ g)) \/ (~g /\ (f ↓ ~g)). Setting g to a variable x gives the classical Shannon cofactors: f = (x /\ (f ↓ x)) \/ (~x /\ (f ↓ ~x)). For f' = constrain f g, f' xs = f xs if g xs, the graph of f' is often simper than that of f, but not always. Note also that (∃xs, (α ↓ β)(xs)) = (∃xs, (α /\ β)(xs)), but constrain is, in general, less costly to calculate than mk_and. See, e.g., Raymond 2008, "Synchronous program verification with Lustre/Lesar", §7.9.

Sourceval restriction : t -> t -> t

For f' = restriction f g, f' xs = f xs if g xs, and the graph of f' is a subset of that of f. I.e., f' is a smaller version of f for input vectors in the "care set" g. See, e.g., Raymond 2008, "Synchronous program verification with Lustre/Lesar", §7.9.

Sourceval restrict : t -> variable -> bool -> t

restrict t v b is the bdd for t[b/v], that is, t where variable v is assigned the truth value b.

Sourceval build : formula -> t

Builds a bdd from a propositional formula f. Raises Invalid_argument if f contains a variable out of 1..max_var.

Sourceval as_formula : t -> formula

Builds a propositional formula from the given BDD. The returned formula is only build using if-then-else (Fite) and variables (Fvar).

Sourceval as_compact_formula : t -> formula

Builds a ``compact'' formula from the given BDD. The returned formula is only built using conjunctions, disjunctions, variables, negations of variables, and if-then-else where the if condition is a variable.

Satisfiability

Sourceval is_sat : t -> bool

Checks if a bdd is satisfiable i.e. different from zero

Sourceval tautology : t -> bool

Checks if a bdd is a tautology i.e. equal to one

Sourceval equivalent : t -> t -> bool

Checks if a bdd is equivalent to another bdd

Sourceval entails : t -> t -> bool

entails b1 b2 checks that b1 entails b2, in other words b1 implies b2

Sourceval count_sat_int : t -> int
Sourceval count_sat : t -> Int64.t

Counts the number of different ways to satisfy a bdd.

Sourceval any_sat : t -> (variable * bool) list

Returns one truth assignment which satisfies a bdd, if any. The result is chosen deterministically. Raises Not_found if the bdd is zero

Sourceval random_sat : t -> (variable * bool) list

Returns one truth assignment which satisfies a bdd, if any. The result is chosen randomly. Raises Not_found if the bdd is zero

Sourceval all_sat : t -> (variable * bool) list list

Returns all truth assignments which satisfy a bdd b.

Pretty printer

Sourceval print_var : Format.formatter -> variable -> unit
Sourceval print : Format.formatter -> t -> unit

Prints as compound if-then-else expressions

Sourceval print_compact : Format.formatter -> t -> unit

Prints as Boolean expressions, with fallback to if-then-else expressions when nothing is more compact

Sourceval cnf_size : t -> int

Returns the number of clauses when the bdd is printed in conjunctive normal form. This is the number of lines when the bdd is printed with function print_dimacs below, each line having up to max_var literals.

Sourceval print_dimacs : Format.formatter -> t -> unit

Prints a bdd in conjunctive normal form using the DIMACS format.

Warning: The output may be exponential in the size of the bdd. The number of clauses (that is, the number of lines printed) is given by cnf_size.

Sourceval print_dot : Format.formatter -> t -> unit

Prints a DOT output of a given bdd.

Sourceval to_dot : t -> string
  • deprecated

    Use print_dot instead.

Sourceval print_to_dot : t -> file:string -> unit
  • deprecated

    Use print_dot instead.

Sourceval display : t -> unit

Renders a given bdd using DOT and runs the shell command "dot -Tps <file> | gv -"

Stats

Sourceval nb_nodes : t -> int

Returns the number of internal nodes of the bdd (i.e. nodes Zero and One are not counted). This is proportional to the space used internally by the bdd (7 words per node).

Sourceval stats : unit -> (int * int * int * int * int * int) array

Returns statistics on the internal nodes tables (one for each variable). The numbers are, in order: table length, number of entries, sum of bucket lengths, smallest bucket length, median bucket length, biggest bucket length.

OCaml

Innovation. Community. Security.