Vous êtes sur la page 1sur 31

Algorithm-Tokuron

(1st part, lecture-4)


Shin-ichi Minato
Division of Computer Science,
Graduate School of Information Science and Technology,
Hokkaido University

Review of the last lecture


Simplification/minimization of SOPs
Simplification, minimization, and irredundant SOP
Correspondence of Karnaugh map and SOP.
minterm, implicant, prime implicant, and essential P.I.

Minimization (Quine-McClusky method)


Algorithm and complexity

Practical simplification methods


MINI, Espresso
Benchmark set for evaluation

Irredundant SOP (Morreales method)


Algorithm
Acceleration using BDDs
2012.05.01

Algorithm-tokuron

Todays topic

BDD

Basic data structure


Shannons expansion, Binary tree and BDD, reduction rules.

Properties of BDDs

Comparison with truth-tables and SOP forms.


Uniqueness, compactness, fast logic operations.
BDDs for typical Boolean functions.
Impact of variable ordering to BDD size

Algorithms for BDD construction


BDD construction for a given Boolean expression.
Binary logic operation algorithms.
Finding satisfiable/minimal solutions, truth-table density.

Improvement of BDDs
Shared BDDs for multiple functions.
Negative edge.
2012.05.01

Algorithm-tokuron

BDDBinary Decision Diagram)

b
c

c
1

c
0

Binary Decision Tree


BDD

2012.05.01

c
1

c
1

Reduced Ordered BDD


BDD

Algorithm-tokuron

b
1

Unordered BDD

BDD
4

Nodesand edgesin BDDs

Decision node
Terminal node
0-edge0-
1-edge1-
Sub-graph

Shannons expansion

0
0
1

F
0

(Booles expansion)

F(v, X) = ~v F(0, X) + v F(1, X)


F0
2012.05.01

Algorithm-tokuron

F1
5

ROBDD (Reduced Ordered BDD)


In general, BDD is not unique for a Boolean function.
Ordered BDD
A fixed total order relation is defined for the variables.
On each path from the root node to a terminal node,
any pair of variables follows the total order relation.

Reduced BDD
A BDD form where the two reduction rules are applied as much
as possible.

ROBDD has the most important properties.


In this lecture, we may use BDD for discussing ROBDD.
2012.05.01

Algorithm-tokuron

BDD reduction rules


(a)

(a) Eliminate all redundant nodes.


(b) Share all equivalent nodes.

(jump)

Reduced BDD.
(b)
x

(share)

f0

f1

f0

f1

2012.05.01

(cf.)
When using the rule (b) only,
we can obtain
a quasi-reduced BDD.
BDD
Algorithm-tokuron

Example of BDD reduction


Final BDD form is anyway unique.
A unique (canonical) form for a Boolean function.
However, different variable orders may produce different forms.
(occasionally same but in general different.)

2012.05.01

c
0

b
c

c
0

Algorithm-tokuron

1
8

Properties of BDDs
Canonical form for a Boolean functions.
Easy to equivalence checking

Compact for many practical Boolean functions.


Linear size for n-bit parity functions and n-bit full-adder func.
More than 100 inputs can be handled for good cases.

Binary logic operations between two BDDs can be


performed in almost linear time.
NOT operation is also easily done.

BDDs cannot be compact in some Boolean functions.


Exponential size for n-bit multiplier functions.

BDDs becomes large if variable ordering is poor.


NP complete problem to get an optimal variable order.
(Some heuristic methods have been developed, however.)
2012.05.01

Algorithm-tokuron

Size of BDDs
n

22
n

Total number of n input Boolean functions:


To distinguish all the functions, at least 2 bit needed.
Also for BDDs, the worst case of BDD size is:
O(2n/n) nodes.
O(n) bit for each node, so O(2n) bit in total.

However, for many practical Boolean functions,


the number of BDD nodes are within a polynomial of n.

2012.05.01

Algorithm-tokuron

10

n-input AND, OR, EXOR functions

x2

x2

x3

x3

x1

x1

x1

x4

x4

AND

OR

x2

x2

x3

x3

x4

x4

EXOR (parity)

Number of BDD nodes is linear for n: O(n)


Swapping 0- and 1-terminal nodes gives NAND/NOR/XNOR.
2012.05.01

Algorithm-tokuron

11

n-bit binary-coded arithmetic addition


BDD for the 3-bit adder function.
(Variable order: a2, b2, a1, b1, a0, b0, c0 )

S2

S1
S0

Increasing n, BDD grows vertically but the width is bounded.


BDD size: O(n) nodes.
Subtraction function is also O(n) nodes.
Equality/inequality function is also O(n) nodes.
2012.05.01

Algorithm-tokuron

12

n-input data selector


Boolean function selecting
one data from n data inputs.
[log2n] control input specifies
which data input is selected.
BDD size: O(n) nodes.

2012.05.01

Algorithm-tokuron

13

Symmetric function
example of 9-input
symmetric function.

Symmetric functions:
Exchanging variable order
has no effect to outputs.
Output value only depends
on the number of 1 in the
n-inputs.

Each level of the BDD


shows the number of 1
in the upper k-inputs.
BDD width is up to n.
Total BDD size: O(n2) nodes.

2012.05.01

Algorithm-tokuron

14

Effect of variable ordering (1)


BDD size may greatly depend on the variable order.
x1 x2 + x3 x4 + x5 x6 + x7 x8

x1 x5 + x2 x6 + x3 x7 + x4 x8

O(2n)

O(n)
2012.05.01

Algorithm-tokuron

15

Effect of variable ordering (2)


8-input data selector
Control inputs higher than data inputs.

Data inputs higher than control inputs.

O(n)
2012.05.01

O(2n)
Algorithm-tokuron

16

Effect of variable ordering (3)


55-bit multiplier
(5th output function)

Binary-coded multiplier
is a weak point.
Proved that O(2n) nodes
needed in any variable
ordering.
Division function also
becomes an
exponential size.
Patterns of variable ordering.
(a) Easy for any order.
(b) Easy/hard may change
depending on the order.
(c) Hard for any order.

2012.05.01

Algorithm-tokuron

17

BDD construction algorithm


a

a
b

b
c

c
1

reduction
(compress)

0
0

F = a b + ~c

direct construction

b
1

Reduction from binary decision tree to BDD


always requires exponential time and space.
we use the algorithm [Bryant1986] for directly
constructing BDDs from given Boolean expressions.
2012.05.01

Algorithm-tokuron

18

BDD construction from Boolean expressions


a
Any BDD can be generated by
repeating binary logic operations
between two BDDs.

ab
a
0

a
0

AND

a b + ~c

b
0

OR

~c

NOT

2012.05.01

b
1

0
Algorithm-tokuron

19

Binary logic operation algorithm


H = (F [op] G)
v
0

H(v=0) = (F(v=0) [op] G(v=0))

H(v=1) = (F(v=1) [op] G(v=1))

Recursive expansion assigning 0/1 into top variable v.


Eventually trivial operation appears and result obtained.
(in OR operation) F+1=1, F+0=F, F+F=F

Unifying all results of sub-operations into one BDD.


2012.05.01

Algorithm-tokuron

20

Execution of binary logic operation


F+G
F
a

N1

N3

N2

0
0

N4
c
1

b
1

N6
0

N5
c
1

2012.05.01

b=0
1

N7
d

d
1

1 1

d
0

1 0

N1+N3

a=0

N8

N4+N3

N4+N5
c=0
c=1

a=1

b=1 b=0

N4+N8

N2+N3

N4+N5

b=1
N6+N8

N6+N8 0 +N7 N6+N8 0 +N8


d=0
d=1
N7
N8
0+1 1+0
1

Algorithm-tokuron

21

Computation time for binary logic operation


We denote |F| as the number of nodes in BDD F,
then, in the worst case |H| = |F||G| for H = F [op] G.
This means that BDD construction for n-input
Boolean expression requires O(2n) time.
However, using techniques such as hash tables, we may
execute in O( |F| + |G| + |H| ) time for many practical cases.
There are cases where |F|, |G| are very large but |H| is very small.
Opposite cases are also possible.

If BDD size is relatively small, logic operation becomes


very fast, even for a large n.
if BDD grows exponentially large (e.g. multiplier),
almost no advantage of using BDDs.
2012.05.01

Algorithm-tokuron

22

NOT operation algorithm


F
a

~F
1

a
0

0
0

c
1

b
1

1
0

2012.05.01

c
1

Just copying the BDD, and


swapping 0- and 1-terminal
nodes.
Linear time for BDD size.
Using negative edges
(explain later), we can
execute in a constant time.

Algorithm-tokuron

23

Finding satisfiable/minimal solutions


If a BDD is already reduced,
satisfiability checking can be done immediately.
If satisfiable, a solution (0/1 assignment into each input)
can be found easily.
Choosing decisions not connecting to the 0-terminal node,
then eventually we must reach the 1-terminal node.
Linear time for the number of inputs. (less than BDD size)

If the cost of assigning 1 to each input is defined,


we can search the minimal-cost satisfiable solutions.
Linear time for BDD size.

Truth-table density (ratio of 1 in the table) and


probability of satisfiability can be computed efficiently.
Linear time for BDD size.
2012.05.01

Algorithm-tokuron

24

Improvements of BDDs

Various improvement techniques for efficient BDD


manipulation have been developed.
The two techniques are important for practical use.
1. Shared BDDs for multiple functions.
2. Negative edges.
These two techniques are implemented in
most of BDD manipulation programs.

2012.05.01

Algorithm-tokuron

25

Shared BDDBDD
Use a uniform variable order.
All BDDs are shared into a
multi-rooted graph.

a b + ~c
ab

ab

~c

2012.05.01

a b + ~c
~c

Algorithm-tokuron

1
26

Logic operation in shared BDDs


a

ab

AND

b
c

OR
NOT

~c

c
2012.05.01

a b + ~c

Shared BDD
manipulator

b
c

0Algorithm-tokuron1

Shared BDD grows


when executing
logic operations.
Equivalence
checking can be
done just by
comparing pointers.
(constant time)
27

Negative edge

~F

a
0

0
0

1
0

c
1

b
1

Attaching a mark of NOT


F ~F
operation into an edge to
a BDD, then compliment
a
BDDs can be shared into
0
one BDD.
NOT operation can be
c
done in a constant time.
1

0
0

2012.05.01

Constraints in using
negative edges to keep
uniqueness of BDDs.

x
1

Just switch on/off of the


edge at the root node.

Algorithm-tokuron

Dont use 1-terninal node.


0-edges never be negative.
28

BDD package
BDD manipulation programs have been developed
actively in 1990s.
Some of them are public domain software as BDD package.

In many cases, implemented as a C or C++ library.


We call a library function with pointers to BDDs as
function parameters, then new BDD is constructed in the
memory, and a pointer to the new BDD is returned.
User designs the main program to call BDD operations, and
then compile the program with the BDD package.

Detailed implementation techniques of BDD package


will be shown in the next lecture.
2012.05.01

Algorithm-tokuron

29

Summary

BDD

Basic data structure


Shannons expansion, Binary tree and BDD, reduction rules.

Properties of BDDs

Comparison with truth-tables and SOP forms.


Uniqueness, compactness, fast logic operations.
BDDs for typical Boolean functions.
Impact of variable ordering to BDD size

Algorithms for BDD construction


BDD construction for a given Boolean expression.
Binary logic operation algorithms.
Finding satisfiable/minimal solutions, truth-table density.

Improvement of BDDs
Shared BDDs for multiple functions.
Negative edge.
2012.05.01

Algorithm-tokuron

30

Exercises
1. Draw a structure of BDD
for an Achilless heel function:
F = x1 x2 x3 + x4 x5 x6 + x7 x8 x9 + + x3n-2 x3n-1 x3n

2. For the above function, if the worst variable


order is used, how is the BDD size?

2012.05.01

Algorithm-tokuron

31

Vous aimerez peut-être aussi