it university of copenhagen lecture 8: binary decision diagrams 1. classical boolean expression...
Post on 22-Dec-2015
213 Views
Preview:
TRANSCRIPT
IT University of Copenhagen
Lecture 8: Binary Decision Diagrams1. Classical Boolean expression representations2. If-then-else Normal Form (INF)3. Binary Decision Diagrams
IT University of Copenhagen
2
Today’s Program
• [13:00-13:55] Computation based representations– Boolean expressions and Boolean functions– Classical representations of Boolean expressions
• Truth tables• Two-level normal forms: CNF, DNF• Multi-level representations: circuits and formulas
• [14:05-15:00] Evaluation based representations– If-then-else normal form– Decision trees– Ordered Binary Decision Diagrams (OBDDs)– Reduced Ordered Binary Decision Diagrams
(ROBDDs or just BDDs)
2007 Rune M. Jensen
IT University of Copenhagen
4
Boolean Expressions• Boolean Expressions
t ::= x | 0 | 1 | t | t t | t t | t t | t t
• Literalsl ::= x | x
• Precedence, , , , (obs. two last swapped in HRA notes)
• Terminology– Boolean expression = Boolean formula, Propositional
formula, Sentence in propositional logic– Boolean variable = Propositional symbol/letter/variable
2007 Rune M. Jensen
IT University of Copenhagen
5
Boolean functions
• DefinitionAn n-variable function f : Bn B is called a Boolean function if it is induced by a Boolean expression E.
• B = {0,1}• E represents the Boolean function
2007 Rune M. Jensen
IT University of Copenhagen
6
• Order of arguments matterf(x,y) = x y f(y,x) = x y
• Several expressions may represent a function f(x,y) = x y = x y = (x y) (x x) = …
• Equalityf = g iff x . f(x) = g(x)
• Number of Boolean functions f : Bn B
Properties
2007 Rune M. Jensen
n22
IT University of Copenhagen
7
Desirable properties of a representation
• Compact• Equality check easy (true for canonical representations)
• Easy to evaluate the truth-value of an assignment• Boolean operations efficient• SAT check efficient• Tautology check efficient• Easy to implement
2007 Rune M. Jensen
IT University of Copenhagen
8
The curse of Boolean function representation
• Boolean functions in n variables… – How do we find a single compact representation for
all of them?
Ex. Boolean circuits : how many Boolean circuits of size g with n inputs and 1 output?
– Choice of gates: 16g
– Choice of connections: (2g+1)(n+g)
– Total: 16g (2g+1)(n+g)
n22
…
Out1
In1 In2 Inn
161 2
2007 Rune M. Jensen
IT University of Copenhagen
9
The curse of Boolean function representation
• Assume g = O(nk)• Thus the fraction of Boolean functions of n
variables with a polynomial circuit size in n is
nnO
n
kk nnOknO
for 02
)1)(2(162
))(()(
Curse of Boolean function representation:
This problem exists for all representations we know!
2007 Rune M. Jensen
IT University of Copenhagen
10
Truth tables
• Compact table size 2n
• Equality check easy canonical
• Easy to evaluate the truth-value of an assignment linear
• Boolean operations efficient linear
• SAT check efficient linear
• Tautology check efficient linear
• Easy to implement e.g., DBs2007 Rune M. Jensen
x y z xyz
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
IT University of Copenhagen
11
• One level normal forms
• Two level normal Forms
Two Level Normal Forms
2007 Rune M. Jensen
OP1
Lit LitLit …
OP1
…
OP2
Lit Lit Lit
OP2
Lit Lit Lit
OP2
Lit Lit Lit… …
…
IT University of Copenhagen
12
Two-level normal forms: DNF CNF
• -monomials : x1 x2 x3 x4
• -monomials : x1 x2 x3 x4
• ( ,)-polynomials: -product of -monomials disjunctive normal form (DNF):
• Ex: x y x y
• (, )-polynomials: -product of -monomials conjunctive normal form (CNF):
• Ex: (x y) (x y)2007 Rune M. Jensen
IT University of Copenhagen
13
Two-level normal forms: DNF CNF• Is there a DNF and CNF of every expression?
• Given a truth table representation of a Boolean formula, can we easily define a DNF and CNF of the formula?
x y z xyz0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
2007 Rune M. Jensen
IT University of Copenhagen
14
Two-level normal forms: DNF CNF
• Example DNF of xyz
x y z xyz0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
x y z
x y z
x y z
x y z
x y z
2007 Rune M. Jensen
IT University of Copenhagen
15
Two-level normal forms: DNF CNF
• Example CNF of xyz
x y z xyz0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
( x y z)
(x y z)
(x y z)
2007 Rune M. Jensen
IT University of Copenhagen
16
Two-level normal forms: DNF CNF
• Example CNF of xyz
x y z xyz0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
(x y z)
(x y z)
( x y z)
2007 Rune M. Jensen
IT University of Copenhagen
17
Two-level normal forms: DNF CNF
• The special version DNF and CNF representations produced from on and off-tuples are canonical and called cDNF and cCNF
• Are cDNF and cCNF minimum size DNF and CNF representations?
Every Boolean formula has a DNF and CNF representation
2007 Rune M. Jensen
IT University of Copenhagen
18
Two-level normal forms: DNF CNF
• Properties of DNF and CNF
• Problem: conversion between CNFs and DNFs is exponential
SAT Tautology
CNF NP complete Polynomial (exercise)
DNF Polynomial (exercise)
Co-NP complete
2007 Rune M. Jensen
IT University of Copenhagen
19
Two-level normal forms: DNF CNF
• Example– CNF
– Corresponding DNF
nn xxxxxx 1021
20
11
10
nn
nn
nn
nn
xxxx
xxxx
xxxx
xxxx
11
121
11
01
121
11
11
020
10
01
020
10
2007 Rune M. Jensen
IT University of Copenhagen
20
Two-level normal forms: DNF CNF • Compact Translating a formula to either CNF or DNF may cause an exponential
blow-up in expression size
• Equality check easy ”compact” CNF and DNF formulas are not canonical
• Easy to evaluate the truth-value of an assignment linear
• Boolean operations efficient disjunction e.g. efficient for DNF
• SAT check efficient Not for CNF
• Tautology check efficient Not for DNF
• Easy to implement programmable logic arrays (PLAs)2007 Rune M. Jensen
IT University of Copenhagen
21
Circuits
• Circuits are multi-level representations • CNF and DNF are special circuits with depth 3• Thus, circuits are not canonical
Out
x y z
2007 Rune M. Jensen
IT University of Copenhagen
22
Circuits
• Compact But still suffers from the curse of Booelan function representation.
• Equality check easy Not canonical
• Easy to evaluate the truth-value of an assignment linear
• Boolean operations efficient constant
• SAT check efficient (NP-Hard)
• Tautology check efficient Not canonical
• Easy to implement Integrated circuits2007 Rune M. Jensen
IT University of Copenhagen
23
Formulas
• Formulas are circuits where each node has out-degree 1
• Multiple use of intermediate functions is not allowed
((x y) (z y)) ((x y) (z x))
2007 Rune M. Jensen
IT University of Copenhagen
24
Formulas • Compact At least as large as a circuit
• Equality check easy Not canonical
• Easy to evaluate the truth-value of an assignment linear
• Boolean operations efficient constant
• SAT check efficient (Circuit-SAT ≤p Formula-SAT)
• Tautology check efficient Not canonical
• Easy to implement Simpler algorithmic handling than circuits2007 Rune M. Jensen
IT University of Copenhagen
25
Classical Representations• Observations
– There is a trade off between the size of a representation and the efficiency of operations and checks
– Truthtables: very large, but all checks and Boolean operations can be carried out efficiently
– Circuits: quite compact, but SAT and equality checks are very hard
• Next: Binary decision diagrams, probably the best known balance between size and efficiency!
2007 Rune M. Jensen
IT University of Copenhagen
27
Computation and Evaluation Based Representation
• Computation Process Representation– Representation gives a way to compute the
expression value– Truth-tables, DNF, CNF, circuits and formulas
• Evaluation Process Representation– Representation gives a way to classify the expression
value by means of tests– Decision trees
2007 Rune M. Jensen
IT University of Copenhagen
28
If-then-else operator
• The if-then-else Boolean operator is defined by xy1 , y0 = ( x y1 ) ( x y0 )
• We have
(xy1 , y0) [1/x] = ( 1 y1 ) ( 0 y0 ) = y1
(xy1 , y0) [0/x] = ( 0 y1 ) ( 1 y0 ) = y0
2007 Rune M. Jensen
IT University of Copenhagen
29
If-then-else operator• All operators can be expressed using
– only operators and the constants 0 and 1– tests on un-negated variables
• What are if-then-else expressions for– x, x– x y, x y– x y
2007 Rune M. Jensen
IT University of Copenhagen
30
INF normal form
• Proposition: any Boolean expression t is equivalent to an expression in INFProof:
t = x t[1/x], t[0/x] (Shannon expansion of t)
Apply the Shannon expansion recursively on t. The recursion must terminate in 0 or 1, since the number of variables is finite
An if-then-else Normal Form (INF) is a Boolean expression build entirely from the if-then-else operator and the constants 0 and 1 such that all test are performed only on variables
2007 Rune M. Jensen
IT University of Copenhagen
31
Example
• Example: t = (x1 y1) (x2 y2)
• Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t0
2007 Rune M. Jensen
IT University of Copenhagen
32
Example
• Example: t = (x1 y1) (x2 y2)
• Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t0
t0 = y1 t01, t00
t1 = y1 1, t10
2007 Rune M. Jensen
IT University of Copenhagen
33
Example• Example: t = (x1 y1) (x2 y2)
• Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t0
t0 = y1 t01, t00
t1 = y1 1, t10
t01 = x2 t011, 0
t00 = x2 t001, 0
t10 = x2 t101, 0
2007 Rune M. Jensen
IT University of Copenhagen
34
Example• Example: t = (x1 y1) (x2 y2) • Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t0
t0 = y1 t01, t00
t1 = y1 1, t10
t01 = x2 t011, 0
t00 = x2 t001, 0
t10 = x2 t101, 0 t011 = y2 1,0 t001 = y2 1,0 t101 = y2 1,0
2007 Rune M. Jensen
IT University of Copenhagen
35
Decision tree• Example: t = (x1 y1) (x2 y2) • Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t0
t0 = y1 t01, t00
t1 = y1 1, t10
t01 = x2 t011, 0
t00 = x2 t001, 0
t10 = x2 t101, 0 t011 = y2 1,0 t001 = y2 1,0 t101 = y2 1,0
1
x1
y1 y1
x2 x2 x2
y2 y2
t
t0 t1
t00t01 t10
t001 t011 t101
0 0 y2 0
0 0 0 1 1 12007 Rune M. Jensen
IT University of Copenhagen
36
Reduction I: substitute identical subtrees
• Example: t = (x1 y1) (x2 y2)
• Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t0
t0 = y1 t01, t01
t1 = y1 1, t01
t01 = x2 t011, 0
t011 = y2 1,0
x1
y1 y1
x2
y2
t
t0 t1
t01
t011
0 1
Result: an Ordered Binary Decision Diagram (OBDD)
2007 Rune M. Jensen
IT University of Copenhagen
37
Reduction II: remove redundant tests
• Example: t = (x1 y1) (x2 y2)
• Shannon expansion of t in order x1,y1,x2,y2
t = x1 t1, t01
t1 = y1 1, t01
t01 = x2 t011, 0
t011 = y2 1,0
x1
y1
x2
y2
t
t1
t01
t011
0 1
Result: a Reduced Ordered Binary Decision Diagram (ROBDD) [often called a BDD]
2007 Rune M. Jensen
IT University of Copenhagen
38
Reductions
x
Uniqueness requirement
Non-redundant tests requirement
x x
2007 Rune M. Jensen
IT University of Copenhagen
40
Another reduction examplex
z
y y
z z
0 1
Equal subtrees
Redundant test
2007 Rune M. Jensen
IT University of Copenhagen
41
Another reduction examplex
z
y y
z
0 1
Equal subtrees
2007 Rune M. Jensen
IT University of Copenhagen
43
Another reduction examplex
z
y y
0 1
Equal subtrees
2007 Rune M. Jensen
IT University of Copenhagen
44
Another reduction examplex
z
y
0 1
Redundant test
2007 Rune M. Jensen
IT University of Copenhagen
48
Canonicity of ROBDDs
• Canonicity Lemma: for any function f : Bn B there is exactly one ROBDD u with a variable ordering x1 < x2 < … < xn such that fu = f(x1,…,xn)
Proof (by induction on n)
2007 Rune M. Jensen
IT University of Copenhagen
49
Canonicity of ROBDDs
• The canonicity of ROBDDs simplifies– Equality check– Tautology check– Satisfiability checkWhy?
2007 Rune M. Jensen
IT University of Copenhagen
50
• What are the ROBDDs of– 1– 0– x y order x, y– (x y) z order x, y, z
Practice
2007 Rune M. Jensen
IT University of Copenhagen
51
Size of ROBDDs
• ROBDDs of many practically important Boolean functions are small – E.g., Adders have polynomial sized ROBDDs
• Have all functions polynomial ROBDD size? NO– ROBDDs do not escape the curse of Boolean function
representation– E.g., Multipliers have exponential ROBDD size
2007 Rune M. Jensen
IT University of Copenhagen
52
Size of ROBDDs• The set of nodes of a ROBDD of f is equal to the set of
different subfunctions of f (in an INF expansion)
• Example: 4 subfunctions = 4 nodes in the ROBDD
f(x,y,z) = y zf(0,y,z) = y zf(1,y,z) = y zf(0,0,z) = zf(0,1,z) = 1f(1,0,z) = zf(1,1,z) = 1
f(0,0,0) = 0f(0,0,1) = 1f(0,1,0) = 1f(0,1,1) = 1f(1,0,0) = 0f(1,0,1) = 1f(1,1,0) = 1f(1,1,1) = 1
z
y
0 1
y z
z
0 1
This property can be used to find upper bounds on the ROBDD size 2007 Rune M. Jensen
IT University of Copenhagen
53
Size Of ROBDDs
• The size of an ROBDD depends heavily on the variable ordering
• Example: t = (x1 y1) (x2 y2)
• Build ROBDD of t in order x1,x2,y1,y2
2007 Rune M. Jensen
top related