Graph-Based Algorithms for Boolean Function Manipulation
Graph-Based Algorithms for Boolean Function Manipulation
Abstract-In this paper we present a lnew data structure for A variety of methods have been developed for representing
representing Boolean functions and an associated set of manipu- and manipulating Boolean functions. Those based on classical
lation algorithms. Functions are represented by directed, acyclic representations such as truth tables, Karnaugh maps, or
graphs in a manner similar to the repre$enJation:s introduced by
Lee [11 and Akers 121, but with further restrictions on the canonical sum-of-products form [4] are quite impractical-
ordering of decision variables in the graph. Although a function every function of n arguments has a represdnitation of size 2"
requires, in the worst case, a graph of size exponential in the or more. More practical approaches utilize representations that,
number of arguments, many of the functions encountered in at least for many functions, are not of exponential size.
typical applications have a more reasonable representation. Our Example representations include as a reduced sum of products
algorithms have time complexity proportional to the sizes of the
graphs being operated on, and hence are quite efficient as long as [4] (or equivalently as sets of prime cubes [5]) and factored
the graphs do not grow too large. We present experimental results into unate functions [6]. These representations suffer from
from applying these algorithms to problems in logic design several drawbacks. First, certain common functions still
verification that demonstrate the practicality of our approach. require representations of exponential size. For example, the
even and odd parity functions serve as worst case examples in
Index Terms-Boolean functions, binary decision diagrams,
logic design verification, symbolic manipulation. all of these representations. Second, while a certain function
may have a reasonable representation, performing a simple
operation such as complementation could yield a function with
I. INTRODUCTION an exponential representation. Finally, none of these represen-
D OGLEAN Algebra forms a cornerstone of computer tations are canonicalforms, i.e., a given function may have
science and digital system design. Many problems in many different representations. Consequently, testing for
digital logic design and testing, artificial intelligence, and equivalence or satisfiability can be quite difficult.
combinatorics can be expressed as a sequence of operations on Due to these characteristics, most programs that process a
Boolean functions. Such applications would benefit from sequence of operations on Boolean functions have rather
efficient algorithms for representing and manipulating Bool- erratic behavior. They proceed at a reasonable pace, but then
ean functions symbolically. Unfortunately, many of the tasks suddenly "blow up," either running out of storage or failing
one would like to perform with Boolean functions, such as to complete an operation in a reasonable amount of time.
testing whether there exists any assignment of input variables In this paper we present a new class of algorithms for
such that a given Boolean expression evaluates to 1 (satisfiabil- manipulating Boolean functions represented as directed acy-
ity), or two Boolean expressions denote the same function clic graphs. Our representation resembles the binary decision
(equivalence) require solutions to NP-complete or co NP- diagram notation introduced by Lee [1] and further popular-
complete problems [3]. Consequently, all known approaches ized by Akers [2]. However, we place further restrictions on
to performing these operations require, in the worst case, an the ordering of decision variables in the, vertices. These
amount of computer time that grows exponentially with the restrictions enable the development of algofithms for manipu-
size of the problem. This makes it difficult to compare the lating the represehitations in a more efficieni manner.
relative efficiencies of different approaches to representing Our representation has several advantages over previous
and manipulating Boolean functions. In the worst case, all approaches to Boolean function manipulation. First, most
known approaches perform as poorly as the naive approach of commonly encountered functions have a reasonable represen-
representing functions by their truth tables and defining all of tation. Por example, all symmetric functions (including even
the desired operations in terms of their effect on truth table and odd parity) are represented by graphs where the number of
entries. In practice, by utilizing more clever representations vertices grows at most as the square of the number of
and manipulation algorithms, we can often avoid these arguments. Second, the performance of a program based on
exponential computations. our algorithms when processing a sequence of operations
degrades slowly, if at all. That is, the time complexity of any
Manuscript received Ndvember 28, 1984; revised June 11, 1985. This work single operation
is bounded by the product of the graph, sizes
was supported in part by the Defense Advanced Research Projects Agency for the functions being operated on. For example, comple-
under Orders 3771 and 3597. menting a function requires time proportional to the size of the
The author is with the Department of Computer Science, Carnegie-Mellon function graph, while combining two functions with a binary
University, Pittsburgh, PA 15213.
IEEE tog Number 8609399. operation (of which intersection, subtraction, and testing for
implication are special cases) requires, at most, time propor- experimental investigations into the practicality of our meth-
tional to the product of the two graph sizes. Finally, our ods. We conclude by suggesting further refinements of our
representation in terms of reduced graphs is a canonical form, methods.
i.e., every function has a unique representation. Hence,
testing for equivalence simply involves testing whether the two A. Notation
graphs match exactly, while testing for satisfiability simply We assume the functions to be represented all have the same
involves comparing the graph to that of the constant function n arguments, written xl, * xn. In expressing a system such
0. as a combinational logic network or a Boolean expression as a
Unfortunately, our approach does have its own set of Boolean function, we must choose some ordering of the inputs
undesirable characteristics. At the start of processing, we must or atomic variables, and this ordering must be the same for all
choose some ordering of the system inputs as arguments to all functions to be represented.
of the functions to be represented. For some functions, the size The function resulting when some argument xi of function f
of the graph representing the function is highly sensitive to this is replaced by a constant b is called a restriction of f
ordering. The problem of computing an ordering that mini- (sometimes termed a cofactor [10]) and is denoted fii=b*
mizes the size of the graph is itself a co NP-complete problem. That is, for any arguments xl, * xn,
Our experience, however, has been that a human with some
understanding of the problem domain can generally choose an fjlxi=b(X1, -, x") =(XI,* , xi_-,. b, xi+ ,***, xn).
appropriate ordering without great difficulty. It seems quite Using this notation, the Shannon expansion [11] of a function
likely that using a small set of heuristics, the program itself around variable xi is given by
could select an adequate ordering most of the time. More
seriously, there are some functions that can be represented by f=xi * flxi=I+i * flxi=o. (1)
Boolean expressions or logic circuits of reasonable size but for Similarly, the function resulting when some argument xi of
all input orderings the representation as a function graph is too function f is replaced by function g is called a composition of
large to be practical. For example, we prove in the Appendix f and g, and is denoted f x=g. That is, for any arguments xi,
that the furnctions describing the outputs of an integer
multiplier have graphs that grow exponentially in the word
size regardless of the input ordering. With the exception of f lxi=g(xl, Xn)
integer multiplication, our experience has been that such =f(XI, * * Xi- 1, g(Xli * *
..
Xn)9 Xi+l *
...
Xn)
functions seldom arise in digital logic design applications. For
other classes of problems, particularly in combinatorics, Some functions may not depend on all arguments. The
our methods seem practical only under restricted conditions. dependence set of a function f, denoted If, contains those
A variety of graphical representations of discrete functions arguments on which the function depends, i.e.,
have been presented and studied extensively. A survey of the
literature on the subject by Moret [7] cites over 100 refer- If= {i1f1xi=0#ffXi=11
ences, but none of these describe a sufficient set of algorithms The function which for all values of the arguments yields 1
to implement a Boolean function manipulation program. (respectively 0) is denoted 1 (respectively 0). These two
Fortune, Hopcroft, and Schmidt [8] studied the properties of Boolean functions have dependence sets equal to the empty
graphs obeying similar restrictions to ours, showing that two set.
graphs could be tested for functional equivalence in polyno- A Boolean function can also be viewed as denoting some
mial time and that some functions require much larger graphs subset of Boolean n space, namely those argument values for
under these restrictions than under milder restrictions. Payne which the function evaluates to 1. The satisfying set of a
[9] describes techniques similar to ours for reducing the size of function f, denoted Sf, is defined as
the graph representing a function. Our algorithms for combin-
ing two functions with a binary operation, and for composing Sf {(X1,*I , Xn)if(xl , X")=1}
two functions are new, however, and these capabilities are
central to a symbolic manipulation program. II. REPRESENTATION
The next section of this paper contains a formal presentation In this section we define our graphical representation of a
of function graphs. We define the graphs, the functions they Boolean function and prove that it is a canonical form.
represent, and a class of "reduced" graphs. Then we prove a Definition 1: A function graph is a rooted, directed graph
key property of reduced function graphs: that they form a with vertex set V containing two types of vertices. A
canonical representation of Boolean functions. In the follow- nonterminal vertex v has as attributes an argument index
ing section we depart from this formal presentation to give index(v) E I 1, * n } and two children low(v), high(v) e
some examples and to discuss issues regarding the V. A terminal vertex v has as attribute a value value(v) E { 0,
efficiency of our representation. Following this, we develop a 1 }.
set of algorithms for manipulating Boolean functions using our Furthermore, for any nonterminal vertex v, if low(v) is also
representation. These algorithms utilize many of the classical nonterminal, then we must have index(v) < index(low(v)).
techniques for graph algorithms, and we assume the reader has Similarly, if high(v) is nonterminal, then we must have
some familiarity with these techniques. We then present some index(v) < index(high(u)).
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 679
Due to the ordering restriction in our definition, function Definition 5: A function graph G is reduced if it contains
graphs form a proper subset of conventional binary decision no vertex v with low(v) = high(v), nor does it contain distinct
diagrams. Note that this restriction also implies that a function vertices v and v' such that the subgraphs rooted by v and v' are
graph must be acyclic because the nonterminal vertices along isomorphic.
any path must have strictly increasing index values. The following lemma follows directly from the definition of
We define the correspondence between function graphs and reduced function graphs.
Boolean functions as follows. Lemma 2: For every vertex v in a reduced function graph,
Definition 2: A function graph G having root vertex v the subgraph rooted by v is itself a reduced function graph.
denotes a function f, defined recursively as The following theorem proves a key property of reduced
1) If v is a terminal vertex: function graphs, namely that they form a canonical representa-
a) If value(v) = 1, thenffv = 1. tion for Boolean functions, i.e., every function is represented
b) If value(v) = 0, thenfv = 0. by a unique reduced function graph. In contrast to other
2) If v is a nonterminal vertex with index(v) = i, then f, canonical representations of Boolean functions, such as
is the function canonical sum-of-products form, however, many "interest-
ing" Boolean functions are represented by function graphs of
fv (XI 9 Xn) = i * flow(v)(Xi 9
..
* Xn) size polynomial in the number of arguments.
Theorem 1: For any Boolean function f, there is a unique
+ Xi * fhigh (,)(XI X Xn) - (up to isomorphism) reduced function graph denoting f and
any other function graph denoting f contains more vertices.
In other words, we can view a set of argument values xl, Proof: The proof of this theorem is conceptually
* * , xn as describing a path in the graph starting from the root, straightforward. However, we must take care not to presup-
where if some vertex v along the path has index(v) = i, then pose anything about the possible representations of a function.
the path continues to the low child if x, = 0 and to the high The proof proceeds by induction on the size of If.
child if xi = 1. The value of the function for these arguments For IIf 0, f must be one of the two constant functions 0
equals the value of the terminal vertex at the end of the path. or 1. Let G be a reduced function graph denoting the function
Note that the path defined by a set of argument values is 0. This graph can contain no terminal vertices having value 1,
unique. Furthermore, every vertex in the graph is contained in or else there would be some set of argument values for which
at least one path, i.e., no part of the graph is "unreachable." the function evaluates to 1, since all vertices in a function
Two function graphs are considered isomorphic if they graph are reachable by some -path corresponding to a set of
match in both their structure and their attributes, more argument values. Now suppose G contains at least one
precisely: nonterminal vertex. Then since the graph is acyclic, there
Definition 3: Function graphs G and G' are isomorphic if must be a nonterminal vertex u where both low(v) and high(v)
there exists a one-to-one function a from the vertices of G onto are terminal vertices, and it follows that value(low(v)) =
the vertices of G' such that for any vertex v if a(v) = v', then value(high(v)) = 0. Either these 2 vertices are distinct, in
either both v and v' are terminal vertices with value(v) = which case they constitute isomorphic subgraphs, or they are
value(v'), or both v and v' are nonterminal vertices with identical, in which case v has low(v) = high(u). In either case,
index(v) = index(v'), a(low(v)) = low(u'), and o(high(v)) G would not be a reduced function graph. Hence, the only
= high(v'). reduced function graph denoting the function 0 consists of a
Note that since a function graph contains only 1 root and the single terminal vertex with value 0. Similarly, the only
children of any nonterminal vertex are distinguished, the reduced function graph denoting 1 consists of a single terminal
isomorphic mapping a between graphs G and G' is quite vertex with value 1.
constrained: the root in G must map to the root in G', the Next suppose that the statement of the theorem holds for any
root's low child in G must map to the root's low child in G', function g having IIg < k, and that IIf = k where k > 0.
and so on all the way down to the terminal vertices. Hence, Let i be the minimum value in If, i.e., the least argument on
testing two function graphs for isomorphism is quite simple. which the functionf depends. Define the functions fo andfi as
Definition 4: For any vertex v in a function graph G, the f ,== o andlxi =1, respectively. Bothfo and fi have dependence
subgraph rooted by v is defined as the graph consisting of v sets of size less than k and hence are represented by unique
and all of its descendants. reduced function graphs. Let G and G' be reduced function
Lemma 1: If G is isomorphic to G' by mapping a, then for graphs for f. We will show that these two graphs are
any vertex v in G, the subgraph rooted by v is isomorphic to isomorphic, consisting of a root vertex with index i and with
the subgraph rooted by a(v). low and high subgraphs denoting the functions fo and fi. Let v
The proof of this lemma is straightforward, since the and u' be nonterminal vertices in the two graphs such that
restriction of a to v and its descendants forms the isomorphic index(v) = index(v') = i. The subgraphs rooted by u and v'
mapping. both denote f, since f is independent of the arguments xl, -
A function graph can be reduced in size without changing xi_1. The subgraphs rooted by vertices low(v) and low(v')
the denoted function by eliminating redundant vertices and both denote the function fo and hence by induction must be
duplicate subgraphs. The resulting graph will be our primary isomorphic according to some mapping ao. Similarly, the
data structure for representing a Boolean function. subgraphs rooted by vertices high(v) and high(v') both denote
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
680 IEEE TRANSACTIONS ON COMPUTERS, VOL. C-35, NO. 8, AUGUST 1986
the function fi and hence must be isomorphic according to Argument x i Odd Parity
some mapping a,.
We claim that the subgraphs rooted by v and v' must be 0 1
isomorphic according to the mapping a defined as 0 1
(v U =v
v(u) = o(u) u in subgraph rooted by low(v)
cri(u) u in subgraph rooted by high(v).
X1'X2 X4
To prove this, we must show that the function a is well
00
defined, and that it is an isomorphic mapping. Observe that if *
*
0
.
.
and the subgraph rooted by high(v), then the subgraphs rooted
by a0(u) and al(u) must be isomorphic to the one rooted by u
and hence to each other. Since G' contains no isomorphic
subgraphs, this can only hold if oo(u) = a,(u), and hence there
is no conflict in the above definition of a. By similar
reasoning, we can see that a must be one-to-one-if there were
distinct vertices ul and u2 in G having a(ul) = C(u2), then the Fig. 1. Example function graphs.
subgraphs rooted by these two vertices would be isomorphic to
the subgraph rooted by a(ul) and hence to each other implying index i and having as low child a terminal vertex with value 0
that G is not reduced. Finally, the properties that a is onto and and as high child a terminal vertex with value 1. We present
is an isomorphic mapping follows directly from its definition this graph mainly to point out that an input variable can be
and from the fact that both ao and a, obey these properties. viewed as a Boolean function, and hence can be operated on by
By similar reasoning, we can see that graph G contains the manipulation algorithms described in this paper.
exactly one vertex with index(v) = i because if some other The odd parity function of n variables is denoted by a graph
such vertex existed, the subgraphs rooted by it and by v would containing 2n + 1 vertices. This compares favorably to its
be isomorphic. We claim in fact that v must be the root. representation in reduced sum-of-products form (requiring 2n
Suppose instead that there is some vertex u with index(v) = j terms). This graph resembles the familiar parity ladder contact
< i, but such that there is no other vertex w having j < network first described by Shannon [11]. In fact, we can adapt
index(w) < i. The function f does not depend on the xj and his construction of a contact network to implement an arbitrary
hence the subgraphs rooted by low(u) and high(u) both denote symmetric function to show that any symmetric function of n
f, but this implies that low(u) = high(u) = u, i.e., G is not arguments is denoted by a reduced function graph having
reduced. Similarly, vertex v' must be the root of G', and O(n2) vertices.
hence the two graphs are isomorphic. As a third example, the graph denoting the function x, x2 +
Finally, we can prove that of all the graphs denoting a x4 contains 5 vertices as shown. This example illustrates
particular function, only the reduced graph has a minimum several key properties of reduced function graphs. First,
number of vertices. Suppose G is not a reduced graph. Then observe that there is no vertex having index 3 because the
we can form a smaller graph denoting the same function as function is independent of x3. More generally, a reduced
follows. If G contains a vertex v with low(v) = high(u), then function graph for a function f contains only vertices having
eliminate this vertex, and for any vertex having v as child, indexes in If. There are no inefficiencies caused by consider-
make low(v) -be the child instead. If G contains distinct ing all of the functions to have the same n arguments. This
vertices v and u' such that the subgraphs rooted by v and v' are would not be the case if we represented functions by their truth
isomorphic, then eliminate vertex v' and for any vertex having tables. Second, observe that even for this simple function,
v' as a child, make v be the child instead. E several of the subgraphs are shared by different branches. This
sharing yields efficiency not only in the size of the function
III. PROPERTIES representation, but also in the performance of our al-
In this section we explore the efficiency of our representa- gorithms-once some operation has been performed on a
tion by means of several examples. Fig. 1 shows several subgraph, the result can be utilized by all places sharing this
examples of reduced function graphs. In this figure, a subgraph.
nonterminal vertex is represented by a circle containing the
index with the two children indicated by branches labeled 0 B. Ordering Dependence
(low) and 1 (high). A terminal vertex is represented by a Fig. 2 shows an extreme case of how the ordering of the
square containing the value. arguments can affect the size of the graph denoting a function.
The functions x1ix2 + x3-x4 + x5 x6and xl x4 + x2 x5 +
A. Example Functions x3 x6 differ from each other only by a permutation of their
The function which yields the value of the ith argument is arguments, yet one is denoted by a function graph with 8
denoted by a graph with a single nonterminal vertex having vertices while the other requires 16 vertices. Generalizing this
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 681
X 1X2 + X3'X4 + 5 6 x .x
1 4
+ x .x
2 5
+ x *x
3 6 number of vertices grows exponentially with the number of
arguments.
To view this from a different perspective, consider the
family of functions:
fbl, * -,bn (Xn + I
I , X2n) =bl Xn+l1 + +bn X2n -
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
682 IEEE TRANSACTIONS ON COMPUTERS, VOL. C-35, NO. 8, AUGUST 1986
A. Data Structures already been visited by comparing the two marks. As a vertex
We will express our algorithms in a pseudo-Pascal notation. is visited, we could perform some operation such as to
Each vertex in a function graph is represented by a record increment a counter and then set the id field to the value of the
declared as follows: counter (thereby assigning a unique identifier to each vertex).
type vertex = record Each vertex is visited exactly once, and assuming the
low, high: vertex; operation at each vertex requires constant time, the complexity
index: 1..n + 1; of the algorithm is °(1 G I), i.e., proportional to the number of
val: (0,1,X); vertices in the graph. Upon termination, the vertices again all
id: integer; have the same mark value.
mark: boolean; B. Reduction
end;
The reduction algorithm transforms an arbitrary function
Both nonterminal and terminal vertices are represented by graph into a reduced graph denoting the same function. It
the same type of record, but the field values for a vertex v closely follows an algorithm presented in Example 3.2 of Aho
depend on the vertex type as given in the following table. et al. [13] for testing whether two trees are isomorphic.
Field Terminal Nonterminal Proceeding from the terminal vertices up to the root, a unique
low null low(v) integer identifier is assigned to each unique subgraph root.
high null high(v) That is, for each vertex v it assigns a label id(v) such that for
index n + 1 index(v) any two vertices u and v, id(u) = id(v) if and only if fu = f,
val value(v) x (in the terminology of Definition 2). Given this labeling, the
algorithm constructs a graph with one vertex for each unique
The id and mark fields contain auxiliary information used label.
by the algorithms. The id field contains a integer identifier By working from the terminal vertices up to the root, a
which is unique to that vertex in the graph. It does not matter procedure can label the vertices by the following inductive
how the identifiers are ordered among the vertices, only that method. First, two terminal vertices should have the same
they range from 1 up to the number of vertices and that they all label if and only if they have the same value attributes. Now
be different. The mark field is used to mark which vertices assume all terminal vertices and all nonterminal vertices with
have been visited during a traversal of the graph. The index greater than i have been labeled. As we proceed with the
procedure Traverse shown in Fig. 3 illustrates a general labeling of vertices with index i, a vertex v should have id(v)
method used by many of our algorithms for traversing a graph equal to that of some vertex that has already been labeled if
and performing some operation on the vertices. This proce- and only if one of two conditions is satisfied. First, if
dure is called at the top level with the root vertex as argument id(low(v)) = id(high(v)), then vertex v is redundant, and we
and with the mark fields of the vertices being either all true or should set id(v) = id(low(v)). Second, if there is some labeled
all false. It then systematically visits every vertex in the graph vertex u with index(u) = i having id(low(v)) = id(low(u)),
by recursively visiting the subgraphs rooted by the two and id(high(v)) = id(high(u)), then the reduced subgraphs
children. As it visits a vertex, it complements the value of the rooted by these two vertices will be isomorphic, and we should
mark field, so that it can later determine whether a child has set id(v) = id(u).
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 683
are collected into lists according to their indexes. This can be o0 \ Key Label
done by a procedure similar to Traverse where as a vertex is (1,3)
2 2
(3.3) (1)
~~~~~~~(
2
1,2) 3
o/ 1 v X1 (3 33)33
visited, it is added to the appropriate list. Then we process o ( 1,3) 4
(3.3) 3
these lists working from the one containing the terminal (1,2) / j
1.2)
2
(4.3) 5
vertices up to the one containing the root. For each vertex on a 1 0 0 1
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
684 IEEE TRANSACTIONS ON COMPUTERS, VOL. C-35, NO. 8, AUGUST 1986
the branching points of the two arguments graphs. First, let us avoids the potentially numerous recursive calls required to
explain the basic idea of the algorithm. Then we will describe construct the subgraph rooted by u.
two refinements to improve the efficiency. The control Second, suppose the algorithm is applied to two vertices
structure of the algorithm is based on the following recursion, where one, say ul, is a terminal vertex, and for this particular
derived from the Shannon expansion (1) operator, value(vl) is a "controlling" value, i.e., either
value(uv)(op)a = 1 for all a, or value(vl)(op)a = 0 for all a.
fi(op)f2=Xi * (fljXi=o(oP)f2jXi=o)+Xi * (flx,=1KoP)f21x,= 1)- For example, 1 is a controlling value for either argument of
OR, while 0 is a controlling value for either argument of AND.
To apply the operator to functions represented by graphs with In this case, there is no need to evaluate further. We simply
roots vI and v2, we must consider several cases. First, suppose create a terminal vertex having the appropriate value. While
both vu and v2 are terminal vertices. Then the result graph this refinement does not improve the worst case complexity of
consists of a terminal vertex having a value of value(vl) (op) the algorithm, it certainly helps in many cases. In practice we
value(u2). Otherwise, suppose at least one of the two is a have found this case occurs around 10 percent of the time.
nonterminal vertex. If index(vl) = index(v2) = i, we create a A sketch of the code is shown in Fig. 6. For simplicity and
vertex u having index i, and apply the algorithm recursively on to optimize,,the worst case performance, the table is imple-
low(vj) and low(v2) to generate the subgraph whose root mented as a two-dimensional array indexed 'by the unique
becomes low(u), and on high(vl) and high(V2) to generate the identifiers of the two vertices. In practice;, this table will be
subgraph whose root becomes high(u). Suppose, on the other very sparse, and hence it is more efficient to use a hash table.
hand, that index(v1) = i, but either V2 is a terminal vertex or To detect whether one of the two vertices contains a
index(v2) > i. Then the function represented by the graph controllitig value for the operator, we evaluate the expression
with root v2 is independent of xi, i.e., v l.value (op) v2.value using a three-valued algebra where X
(the value at any nonterminal vertex) represents "DON'T
CARE. that is,if b (op) 1 = b (op) 0 = a, then b (op) X = a,
f2Axi= 0 =f2Ixi= f
=2-- otherwise b (op) X = X. This evaluation technique is used in
many logic simulators [14]. Before the final graph is returned,
Hence, we create a vertex u having index i, but recursively we apply the procedure Reduce to transform it into a reduced
appily the algorithm on low(vi) and V2 to generate the subgraph graph and to assign unique identifiers td the vertices.
whose root becomes low(u), and on high(vl) and v2 to To analyze the time complexity of this algorithm when
generate the subgraph whose root becomes high(u). A similar called on graphs with IGI and IG21 vertices, respectively,
situation holds When the roles of the two vertices in the observe that the procedure Apply-step only generates recur-
previbus case are reversed. In general the graph produced by sive calls the first time it is invoked on a given pair of vertices,
this process will not be reduced, and we apply the reduction hence the total number of recursive calls to this procedure
algorithm to it before returning. cannot exceed 2* GI G21 . Within a single call, all opera-
-
If we were to implement the technique described in the tions (including looking for an entry in the table) require
previous paragraph directly we would obtain an algorithm of constant time. Furthermore, the initialization of the table
exponential (in n) time complexity because every call for requires at time proportional to its size, i.e., °(I G1 G21).
which one of the arguments is a nonterminal vertex generates Hence, the total complexity of the algorithm is O(j Gi G21).
two recursive calls. This complexity can be reduced by two In the worst case, the algorithm may actually require this much
refinetients. time because the reduced graph for the function fl(op)f2 can
First, the algorithm need not evaluate a given pair of contain O(1 GI G2j) vertices. For example, choose any
subgraphs more than once. Instead, we can maintain a table positive integers m and n and define the functions fi and f2 as
containing entries of the form (Vu b2, u) indicating that the
result of applying the algorithm to subgraphs with roots v1 and fl(XI** X2n+2m)=XI Xn+m+I+ +Xn X2n+m
v2 was a subgraph with root u. Th6n before applying the
algorithm to a pair of vertices, we first chbbk whether the table f2(xCI * X2n +2m) =Xn+ I X`2n +m+ I
contains an entry for these two vertices. If so, we can + * **+Xn+m * X2n+2m,
immediately return the result. Othetwise, we proceed as
described in the previous paragraph and add a new entry to the These functions are represented by graphs containing 2 f + I and
table. This refinement alone drops the time complexity to 2 m +1 vertices, respectively, as we saw in Section III. If we
0(1 G1 G2j), as we will shdw latef. This refinement shows computef = fi + f2, the resulting functibn is
how we can exploit the sharingof ubhgraphs in the data
structures to gain efficiency in the algorithms. If the two
f(Xls s X2n+2m)=XI Xn+mpI+ +Xn+m X2n+2m
argument graphs each contain many, shared subgraphs, we Which is represented by a graph with 2fn+m+l = 0.5
obtain a high "hit rate" for our table. In practice we have 'I1 * IG21 vertices. Hence the worst case efficiency of the
found hit rates to range between 40 and 50 per&ent. Note that algorithm is limited by the size of the result graph, and we
with a 50 percent hit rate, we obtain a speed improvement far cannot expect any algorithm to achieve better performance
better than the factor of 2 one might first expect. Finding an than ours under these conditions. Empirically, we have never
entry (v1, V2, u) in the table counts as only one "hit," but observed this worst case occurring except when the result
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 685
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
686 IEEE TRANSACTIONS ON COMPUTERS, VOL. C-35, NO. 8, AUGUST 1986
simpler and more efficient way by a more syntactic technique. which again is optimal. However, this is generally not a wise
That is suppose functions fi and f2 are represented by graphs thing to do-many functions that are represented by small
G1 and G2, respectively. We can compose the functions by graphs have very large satisfying sets. For example, the
replacing each vertex v in graph G1 having index i by a copy of function 1 is represented by a graph with one vertex, yet all 2n
G2, replacing each branch to a terminal vertex in G2 by a possible combinations of argument values are in -its satisfying
branch to low(v) or high(v) depending on the value of the set. Hence, care must be exercised in invoking this algorithm.
terminal vertex. We can do this however, only if the resulting If we wish to find an'element of the satisfying set obeying
graph would not violate our index ordering restriction. That is, some property, it can be very inefficient to enumerate all
there can be no indexes j E Ifi, k E If2, such that i < j k elements of the satisfying set and then pick out an element with
or i > j 2 k. Assuming both Gl and G2 are reduced, the the desired characteristics. Instead, we should specify this
graph resulting from these replacements is also reduced, and property in terms of a Boolean function, compute the Boolean
we can even avoid applying the reduction algorithm. While product of this function and the original function, and then use
this technique applies only under restricted conditions, we the procedure Satisfy-one to select an element. Finally, we
have found it a worthwhile optimization. can compute the size of the' satisfying set by an algorithm of
time proportional to the size of the graph (assuming integer
F. Satisfy operations of sufficient precision can be performed in constant
There are many questions one could ask about the satisfying time). In'general, it is much faster to apply this algorithm than
set Sf for a function, including the number of elements, a to enumerate all elements of the satisfying set and count them.
listing of the elements, or perhaps just a single element. As can The procedure Satisfy-one shown in Fig. 9 is called with
be seen from Table I, these operations are performed by the root of the graph and an array x initialized to some
algorithms of widely varying complexity. A single element arbitrary pattern of O's and 1's. It returns'the value false if the
can be found in time proportional to n, the number of function function is unsatisfiable (Sf = and the value true if it is. In
arguments, assuming the graph is reduced. Considering that the latter case, the entries in the array are set to a set of values
the value of an element in Sf is specified by a bit sequence of denoting some element in the satisfying set. This procedure
length n, this algorithm is optimal. We can list all elements of utilizes a classic depth-first search with backtracking scheme
Sf in time proportional to n times the number of elements, to find a terminal vertex in the graph having value 1. This
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 687
As with the previous algorithm, this procedure will work for We have implemented the algorithms described in this paper
any function graph, but it could require time exponential in n and have applied them to problems in logic design verification,
for an unreduced graph regardless of the size of the satisfying test pattern generation, and combinatorics. On the whole, our
set (consider a complete binary tree with all terminal vertices experience has been quite favorable. By analyzing the problem
having value 0). For a reduced graph, however, we are domain, we can generally develop strategies for choosing a
guaranteed that the search will only fail when the procedure is good ordering of the inputs. Furthermore, it is not necessary to
called on a terminal vertex with value 0, and in this case the find the optimal ordering. Many orderings will produce
recursive call to the other child will succeed. Hence, at least acceptable results. Functions rarely require graphs of size
half of the recursive calls to Satisfy-all generate at least one exponential in the number of inputs, as long as a reasonable
new argument value to some element in the satisfying set, and ordering of the inputs has been chosen. In addition, the
the overall complexity is O(n* IS 1). algorithms are quite fast, remaining practical for graphs with
Finally, to compute the size of the satisfying set, we assign a as many as 20 000 vertices.
value c,, to each vertex in the graph according to the
v For this paper, we consider the problem of verifying that the
following recursive formula: implementation of a logic function (in terms of a combina-
1) If v is a terminal vertex: av, value(v).
= tional logic gate network) satisfies its specification (in terms of
2) If v is a nonterminal vertex Boolean expressions.) As examples we use a family of
arithmetic logic unit (ALU) designs constructed from 74181
g =
ctlow(,) 2 hindexghow(0)-vndex(u) + gh(v) . 2index(high(v)) index(v) and 74182 TTL integrated circuits [15]. The '181 implements
-
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
688 IEEE TRANSACTIONS ON COMPUTERS, VOL. C-35, NO. 8, AUGUST 1986
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 689
logical operations on words of data, as long as we choose an structure. With such a structure, we could enhance the
ordering in which the successive bits of the input words are performance of the Apply procedure by maintaining a table
interleaved. Our representation seems especially efficient containing entries of the form (vl, V2, (op), u) indicating that
when compared to other representations of Boolean functions. the result of applying operation (op) to graphs with roots v1
For example, a truth table representation would be totally and V2 was a graph with root u. In this way we would exploit
impractical for ALU's with word sizes greater than 8 bits. A the information generated by previous invocations of Apply as
reduced sum-of-products representation of the most significant well as by the current one. These savings in overall storage
bit in the sum of two n-bit numbers requires about 2n+2 requirements and algorithm efficiencies would be offset
product terms, and hence a reduced sum-of-products represen- somewhat by a more difficult memory management problem,
tation of this circuit would be equally impractical. however.
Akers also saves storage by representing functions in
VI. CONCLUSION decomposed form. That is, we can represent the function
We have shown that by taking a well-known graphical flxi=g in terms of f and g (which may themselves be
representation of Boolean functions and imposing a restriction represented in decomposed form). Unfortunately, a given
on the vertex labels, the minimum-size graph representing a function can be decomposed in many different ways, and
function becomes a canonical form. Furthermore, given any hence this technique would not lead to a canonical form.
graph representing a function, we can reduce it to a canonical However, as noted in Section IV-E, there are certain instances
form graph in nearly linear time. Thus our reduction algorithm in which functions f and g can be composed in a straightfor-
not only minimizes the amount of storage required to represent a ward way by simply replacing each vertex representing the
function and the time required to perform symbolic operations composition variable xi with the graph for g. For such
on the function, it also makes such tasks as testing for decompositions, functions could be stored in decomposed
equivalence, satisfiability, or tautology very simple. We have form and expanded into canonical form dynamically as
found this property valuable in many applications. operations are performed on them. In some instances, the
We have presented a set of algorithms for performing a storage savings could be considerable. For example the graph
variety of operations on Boolean functions represented by our for the function
data structure. Each of these algorithms obeys an important Xi * X2n + X2 * X2n- 1I+ ***+ Xn Xn + I
closure property-if the argument graphs satisfy our ordering
restrictions, so does the result graph. By combining concepts requires a total of 2 n+1 vertices. This function can be
from Boolean algebra with techniques from graph algorithms, decomposed as a series of functions where f, = xn x, , l:
we achieve "a high degree of efficiency. That is, the perform-
fi =(Xi X2n -i+ 1+ XZ+1) lxi+l1=fi+l1
ance is limited more by the sizes of the data structures rather
than by the algorithms that operate on them. for n > i 2 1, and fi equals the desired function. Each of
Akers [17] has devised a variety of coding techniques to these functions can be represented by graphs with 6 vertices. It
reduce the size of the binary decision diagrams representing is unclear, however, how often such decompositions occur,
the output functions of a system. For example, he can how easy they ate to find, and how they would affect the
represent the functions for all 8 outputs of the 74181 ALU efficiency of the algorithms.
slice by a total of 35 vertices, whereas our representation APPENDIX
requires 918. Several of these techniques could be applied to
our representation without violating the properties required by THE COMPLEXITY OF INTEGER MULTIPLICATION
our algorithms. We will discuss two such refinements briefly. In this appendix, we prove that the functions representing
Most digital systems contain multiple outputs. In our the outputs of an integer multiplier provide a difficult case for
current implementation we represent each output function by a our representation, i.e., the graph sizes grow exponentially in
separate graph, even though these function may be closely the word size regardless of the ordering of the input variables.
related and therefore have graphs containing isomorphic Given that there are (2n)! possible orderings of the input
subgraphs. Alternatively, we could represent a set of functions variables, we could not hope to derive this result experimen-
by a single graph with multiple roots (one for each function.) tally, and hence we must provide a detailed proof.
Our -reduction algorithm could be applied to such graphs to Our proof is based on principles similar to those used in
eliminate any duplicate subgraphs and to guarantee that the proving area-time lower bounds on multiplier circuits [18],
subgraph consisting of a root and all of its descendants is a [19]. However, we must show not just that a large amount of
canonical representation of the corresponding function. For information must be transferred from the set of inputs to the
example, we could represent the n + 1 functions for the set of outputs in performing multiplication, but that certain
addition of two n-bit numbers by a single graph containing 9n individual outputs require high information transfer.
- 1 vertices (assuming the inputs are ordered most significant Consider a multiplier with inputs al, , an and bl, ** , bn
bits first), whereas representing them by separate graphs corresponding to the binary encoding of integers a and b with
requires a total of 3n2 + 6n + 2 vertices. Taking this idea to a, and b, being the least significant bits. This circuit has 2n
an extreme, we could manage our entire set of graphs as a outputs corresponding to the binary encoding of the product
single shared data structure, using an extension of the a- b, described by functions muli(a,, * * , a,, bi, * * *, b,) for
reduction algorithm to merge a newly created graph into this 1 c i c 2n. For a permutation ir of { 1, * * *, 2n }, let G(i, ir)
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
690 IEEE TRANSACTIONS ON COMPUTERS, VOL. C-35, NO. 8, AUGUST 1986
j=l
F= {r(j)Il.j1n, ir(j)>n} For some value of i, qi must be at least as large as the average
L= {I7r(j)In+1.j.2n, ir(j).n}. value of the qj's:
That is, F represents those indexes of b (with n added to them) 1 n2 n
D
occurring in the first half while L represents those indexes of a 2n-1 4 8
occurring in the second. In either case, the sets F and L will
each contain at least n/2 elements. We will consider the This theorem shows that for any ordering, some multiplier
elements of F to be data inputs and those of L to be control. output will have a graph of exponential size. This leaves open
Since multiplication is commutative, we are free to choose the possibility that for each output, there could be some
which argument is considered the control input and which is ordering giving a polynomial size graph for this output. We
considered the data in our proof. conjecture, however, that this is not the case, namely that for
For 1 c i c 2n - 1 define the set Fi as certain outputs (e.g., output n), the graph for this function is
of exponential size regardless of the ordering. A proof of this
Fi= {ij3i E F, k E L(j+k=i+n +1)} conjecture would require something stronger than our simple
and let qi = IFiI. That is, for output i, Fi represents those shifter argument. Such a proof would also lead to an
indexes of the data input occurring in the first half of the- input interesting area-time lower bound on circuits computing single
sequence such that the corresponding bits of the control input bits in the product of two binary numbers.
occur in the second half.
Now consider the set of sequences REFERENCES
[1] C. Y. Lee, "Representation of switching circuits by binary-decision
Si {XI, x,jx=0
XnI if r(j) E Fi}. programs," Bell. Syst. Tech. J., vol. 38, pp. 985-999, July 1959.
[2] S. B. Akers, "Binary decision diagrams," IEEE Trans. Comput.,
This set contains 2qi possible values for the first n inputs. We vol. C-27, pp. 509-516, June 1978.
claim that G(i, ir) must contain a unique vertex for each [3] M. R. Garey and D. S. Johnson, Computers and Intractibility: A
Guide to the Theory of NP-Completeness. New York: Freeman,
element of Si. If this were not the case, then we could choose 1979.
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.
BRYANT: GRAPH-BASED ALGORITHMS 691
[4] F. J. Hill and G. R. Peterson, Introduction to Switching Theory and [17] S. B. Akers, "Functional testing with binary decision diagrams," in
Logical Design. New York: Wiley, 1974. Proc. 8th Ann. IEEE Conf. Fault-Tolerant Comput., 1978, pp. 75-
[5] J. P. Roth, Computer Logic, Testing, and Verification. Rockville, 82.
MD: Computer Science Press, 1980. [18] R. P. Brent and H. T. Kung, "The area-time complexity of binary
[6] R. Brayton et al., "Fast recursive Boolean function manipulation," in multiplication," J. Ass. Comput. Mach., vol. 28, pp. 521-534, July
Proc. Int. Symp. Circuits and Syst., IEEE, Rome, Italy, May 1982, pp. 1981.
58-62. [19] H. Abelson and P. Andreae, "Information transfer and area-time trade-
[7] B. M. E. Moret, "Decision trees and diagrams," Ass. Comput. offs for VLSI multiplication," Commun. Ass. Comput. Mach., vol.
Mach., Comput. Surv., vol. 14, pp. 593-623, Dec. 1982. 23, pp. 20-23, Jan. 1980.
[8] S. Fortune, 1. Hopcroft, and E. M. Schmidt, "The complexity of
equivalence and containment for free single variable program
schemes," in Automata, Languages and Programming, Lecture
Notes in Computer Science, Vol. 62, Goos, Hartmannis, Ausiello,
and Boehm, Eds. Berlin: Springer-Verlag, 1978, pp. 227-240.
[9] R. W. Payne, "Reticulation and other methods of reducing the size of
printed diagnostic keys," J. Gen. Microbiol., vol. 98, pp. 595-597,
1977. Randal E. Bryant (S'78-M'81) received the B.S.
[10] R. Brayton et al., Logic Minimization Algorithms for VLSI Synthe- degree in applied mathematics from the University
sis. Hingham, MA: Kluwer, 1984. of Michigan, Ann Arbor, in 1973, and the S.M.,
[11] C. E. Shannon, "A symbolic analysis of relay and switching circuits," E.E., and Ph.D. degrees in electrical engineering
Trans. AiEE, vol. 57, pp. 713-723, 1938. and computer science from the Massachusetts Insti-
[12] C. S. Wallace, "A suggestion for a fast multiplier," IEEE Trans. tute of Technology, Cambridge, in 1977, 1978, and
Electron. Comput., vol. EC-13, pp. 14-17, Jan. 1964. 1981, respectively.
[13] A. V. Aho, J. E. Hopcroft, and J. D. Ullman, The Design and From June, 1981 to August, 1984 he was an
Analysis of Computer Algorithms. Reading, MA: Addison-Wes- Assistant Professor of Computer Science at the
ley, 1974. California Institute of Technology, Pasadena. Since
[14] J. S. Jephson, R. P. McQuarrie, and R. E. Vogelsberg, "A three-level September, 1984 he has been an Assistant Professor
design verification system," IBM Syst. J., vol. 8, no. 3, pp. 178-188, of Computer Science and of Electrical and Computer Engineering at
1969. Carnegie-Mellon University, Pittsburgh, PA. His research and teaching
[15] TTL Data Book, Texas Instruments, Dallas, TX, 1976. interests include VLSI design, verification, and testing, as well as algorithms
[16] M. Rowan- Robinson, Cosmology. London: Oxford University and computer architecture.
Press, 1977. Dr. Bryant is a member of the Association for Computing Machinery.
Authorized licensed use limited to: SOUTHWEST JIAOTONG UNIVERSITY. Downloaded on November 15,2024 at 09:55:20 UTC from IEEE Xplore. Restrictions apply.