minato robdd lecture 2

Upload: mehedi-sarwar

Post on 01-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Minato ROBDD lecture 2

    1/31

     Algorithm-Tokuron(1st part, lecture-4)

    Shin-ichi Minato

    Division of Computer Science,Graduate School of Information Science and Technology,

    Hokkaido University

  • 8/9/2019 Minato ROBDD lecture 2

    2/31

  • 8/9/2019 Minato ROBDD lecture 2

    3/31

    2012.05.01 Algorithm-tokuron 3

    Today’s topic

    • Basic data structure

     – Shannon’s 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.

    BDD( 分決定グラフ) 

  • 8/9/2019 Minato ROBDD lecture 2

    4/31

    2012.05.01 Algorithm-tokuron 4

    BDD(Binary Decision Diagram)

    ( 分決定グラフ) 

     a

     b  b

     c  c  c  c

    0 0 01 1 1 1 1 0 1

     a

     b

     c

    10

    1

    0

    1

    0

    0 1

     a

     b c

    10

    1

    0

    10

     b1

     c

    0

    10

    Binary Decision Tree(真理値表と等価なBDD) 

    Reduced Ordered BDD(既約な順序付きBDD)  Unordered BDD(既約でも順序付き でもないBDD) 

  • 8/9/2019 Minato ROBDD lecture 2

    5/31

    2012.05.01 Algorithm-tokuron 5

    Nodes(節点)and edges(枝)in BDDs

    • Decision node(分岐節点) • Terminal node(終端節点) 

    • 0-edge(0-枝) 

    • 1-edge(1-枝) 

    • Sub-graph(部分グラフ) 

    0 1

     a b  c

    1

    0

     F0  F1

    v10

     F

    Shannon’s expansion(シャノンの展開) (Boole’s expansion)

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

  • 8/9/2019 Minato ROBDD lecture 2

    6/31

    2012.05.01 Algorithm-tokuron 6

    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.

  • 8/9/2019 Minato ROBDD lecture 2

    7/31

    2012.05.01 Algorithm-tokuron 7

    BDD reduction rules

    (a) Eliminate all redundant nodes.(b) Share all equivalent nodes.

     x

     f  f

    (jump)

     x

     f 0  f 1

     x  x

     f 0  f 1

    (share)

    Reduced BDD.

    (cf.)

    When using the rule (b) only,

    we can obtaina “ quasi-reduced” BDD.

    (準規約なBDD) 

    (a)

    (b)

  • 8/9/2019 Minato ROBDD lecture 2

    8/31

    2012.05.01 Algorithm-tokuron 8

    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.)

     a

     b  b

     c  c  c  c

    0 0 01 1 1 1 1

     a

     b  b

     c c

    01 1

     a

     b

     c

    01 1

  • 8/9/2019 Minato ROBDD lecture 2

    9/31

    2012.05.01 Algorithm-tokuron 9

    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 l inear t ime. – 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.)

  • 8/9/2019 Minato ROBDD lecture 2

    10/31

    2012.05.01 Algorithm-tokuron 10

    Size of BDDs

    • Total number of n input Boolean functions: 22 n

      To distinguish all the functions, at least 2

     n bit needed.

    • Also for BDDs, the worst case of BDD size is:

    O(2 n /  n) nodes. 

     –  O( n) bit for each node, so O(2 n) bit in total.

    • However, for many practical Boolean functions,

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

  • 8/9/2019 Minato ROBDD lecture 2

    11/31

    2012.05.01 Algorithm-tokuron 11

     n-input AND, OR, EXOR functions

     AND(論理積)  OR(論理和) EXOR (parity)

    (排他的論理和) 

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

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

    0 1

     x1

     x2

     x3

     x4

    10

     x1

     x2

     x3

     x4

    10

     x1

     x2

     x3

     x4

     x2

     x3

     x4

  • 8/9/2019 Minato ROBDD lecture 2

    12/31

    2012.05.01 Algorithm-tokuron 12

     n-bit binary-coded arithmetic addition

    • 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.

    S0

    S1

    S2 CBDD for the 3-bit adder function.

    (Variable order:  a2 , b2 , a1 , b1 , a0 , b0 , c0 )

  • 8/9/2019 Minato ROBDD lecture 2

    13/31

    2012.05.01 Algorithm-tokuron 13

     n-input data selector

    • Boolean function selecting

    one data from n data inputs.

    • [log2 n] control input specifies

    which data input is selected.

    • BDD size: O( n

    ) nodes.

  • 8/9/2019 Minato ROBDD lecture 2

    14/31

    2012.05.01 Algorithm-tokuron 14

    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 BDDshows the number of “1”

    in the upper k -inputs.

     – BDD width is up to n.

     – Total BDD size: O( n2) nodes.

    example of 9-inputsymmetric function.

  • 8/9/2019 Minato ROBDD lecture 2

    15/31

    2012.05.01 Algorithm-tokuron 15

    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( n) O(2 n)

    Eff t f i bl d i (2)

  • 8/9/2019 Minato ROBDD lecture 2

    16/31

    2012.05.01 Algorithm-tokuron 16

    Effect of variable ordering (2)

    • 8-input data selectorControl inputs higher than data inputs.

    O( n) O(2 n)

    Data inputs higher than control inputs.

  • 8/9/2019 Minato ROBDD lecture 2

    17/31

    2012.05.01 Algorithm-tokuron 17

    • Binary-coded multiplier

    is a weak point. – Proved that O(2 n) nodes

    needed in any variable

    ordering.

     – Division function also

    becomes an

    exponential size.

    5×5-bit multiplier(5th output function)

    (a)Easy for any order.

    (b)Easy/hard may changedepending on the order.

    (c) Hard for any order.

    Patterns of variable ordering.

    Effect of variable ordering (3)

  • 8/9/2019 Minato ROBDD lecture 2

    18/31

    2012.05.01 Algorithm-tokuron 18

    BDD construction algorithm

    • Reduction from “binary decision tree” to BDD

    always requires exponential time and space.

    we use the algorithm [Bryant1986] for directlyconstructing BDDs from given Boolean expressions. 

     a

    b  b

    c  c  c  c

    0 0 01 1 1 1 1 0 1

     a

     b

     c

    10

    1

    0

    1

    0

    reduction

    (compress)

     F = a b + ~cdirect construction

    BDD t ti f B l i

  • 8/9/2019 Minato ROBDD lecture 2

    19/31

    • Any BDD can be generated by

    repeating binary logic operations

    between two BDDs.

    2012.05.01 Algorithm-tokuron 19

    BDD construction from Boolean expressions

    0 1

     a

     b

     c

    10

    1

    0

    1

    0

    0 1

     a

     b

    10

    0

    1

    0 1

     a

    10

    0 1

     b10

    0 1

     c 10

    1 0

     c10

     a

     b

     c~c

     a b

     a b + ~c AND

    NOT

    OR

  • 8/9/2019 Minato ROBDD lecture 2

    20/31

    2012.05.01 Algorithm-tokuron 20

    Binary logic operation ( 項論理演算) algorithm

    • 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.

     H  = ( F [op] G)

    v10

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

  • 8/9/2019 Minato ROBDD lecture 2

    21/31

    2012.05.01 Algorithm-tokuron 21

    Execution of binary logic operation

    0 1

     a

     b

     c

    10

    1

    0

    1

    0

     d d 11

    00

    0 1

     b

     c1

    0

    1

    0

     d10

     F

    G N 1

     N 3 N 2

     N 4 N 5

     N 6 N 7  N 8

     N 1+ N 3

     N 2+ N 3 N 4+ N 3

     N 6+ N 8 N 4+ N 5 N 4+ N 8 N 4+ N 5

     F + G

     a=0  a=1

     b=0  b=1  b=0  b=1

    0 + N 7 N 6+ N 8 0 + N 8 N 6+ N 8

     c=0  c=1

    0 + 1  1 + 0 

     d =0  d =1

    1

     N 7  N 8

  • 8/9/2019 Minato ROBDD lecture 2

    22/31

    2012.05.01 Algorithm-tokuron 22

    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(2 n) 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.

  • 8/9/2019 Minato ROBDD lecture 2

    23/31

    2012.05.01 Algorithm-tokuron 23

    NOT operation algorithm

    • Just copying the BDD, and

    swapping 0- and 1-terminalnodes.

    • Linear time for BDD size.

    • Using “negative edges”

    (explain later), we can

    execute in a constant time.

    0 1

     a

     b

     c

    10

    1

    0

    1

    0

    10

     a

     b

     c

    10

    1

    0

    1

    0

     F ~F

    Finding satisfiable/minimal solutions

  • 8/9/2019 Minato ROBDD lecture 2

    24/31

    2012.05.01 Algorithm-tokuron 24

    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 t ime 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) andprobability of satisfiability can be computed efficiently. – Linear time for BDD size.

  • 8/9/2019 Minato ROBDD lecture 2

    25/31

    2012.05.01 Algorithm-tokuron 25

    Improvements of BDDs

    • Various improvement techniques for efficient BDDmanipulation 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.

    Sh d BDD BDD

  • 8/9/2019 Minato ROBDD lecture 2

    26/31

    2012.05.01 Algorithm-tokuron 26

    Shared BDD(複数BDDの 有化) 

    • Use a uniform variable order.

    • All BDDs are shared into a

    multi-rooted graph.

    0 1

     a

     b

     c

    10

    1

    0

    1

    0

    0 1

     a

     b

    10

    0

    1

    0 1

     a10

    0 1

     b10

    0 1

     c10

    1 0

     c10

     a  b  c ~c

     a b

     a b + ~c

    0 1

     a

     c c

     b b

     a a

     a  b c ~c

     a b  a b + ~c

    Logic operation in shared BDDs

  • 8/9/2019 Minato ROBDD lecture 2

    27/31

    2012.05.01 Algorithm-tokuron 27

    Logic operation in shared BDDs

    0 1

     a

     b

     a a

     b

     c c

     a

     b

     c ~c

     a b

     a b + ~c

     AND

    NOT

    OR

    Shared BDD

    manipulator

    • Shared BDD growswhen executinglogic operations.

    • Equivalencechecking can bedone just bycomparing pointers.(constant time)

    N ti d

  • 8/9/2019 Minato ROBDD lecture 2

    28/31

    2012.05.01 Algorithm-tokuron 28

    Negative edge(否定枝) 

    • Attaching a mark of NOT

    operation into an edge to

    a BDD, then complimentBDDs can be shared into

    one BDD.

    • NOT operation can be

    done in a constant time. 

     – Just switch on/off of the

    edge at the root node.

    • Constraints in using

    negative edges to keep

    uniqueness of BDDs. – Don’t use 1-terninal node.

     – 0-edges never be negative.

    1

     a

     b

     c

    10

    1

    0

    1

    0

    0

     a

     b

     c

    10

    1

    0

    1

    0

     F ~F

    1

    0

     a

     b

     c

    10

    0

    1

    0

     F ~F

    1 0 x  x

    10 10

    BDD package

  • 8/9/2019 Minato ROBDD lecture 2

    29/31

    2012.05.01 Algorithm-tokuron 29

    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.

    S

    BDD

  • 8/9/2019 Minato ROBDD lecture 2

    30/31

    2012.05.01 Algorithm-tokuron 30

    Summary

    • Basic data structure – Shannon’s 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.

    BDD( 分決定グラフ) 

  • 8/9/2019 Minato ROBDD lecture 2

    31/31

    2012.05.01 Algorithm-tokuron 31

    Exercises

    1. Draw a structure of BDDfor an Achilles’s heel function: 

     F = x1 x2 x3 + x4 x5 x6 + x7 x8 x9 + … + x3 n-2 x3 n-1 x3 n 

    2. For the above function, if the worst variableorder is used, how is the BDD size?