Sunteți pe pagina 1din 43

Multi-Level Logic-2

Andreas Kuehlmann

Modified for ELEN 500/COEN 200


Samiha Mourad

Check: Devedas (7), Hachtel (10, 11) DeMicheli (8)

Factorization
Given a SOP, how do we generate a good factored form Division operation: is central in many operations find a good divisor apply the actual division results in quotient and remainder Applications: factoring substitution extraction

Division
Definition: An operation OP is called division if, given two SOP expressions F and G, it generates expressions H and R such that F = GH + R. G is called the divisor H is called the quotient ? 0 R is called the remainder Definition: If GH is an algebraic product, then OP is called an algebraic division (denoted F // G) otherwise GH is a Boolean product and OP is called a Boolean division (denoted F G).

Division ( f = gh+r )
Example: f = ad + ae + bcd + j g1 = a + bc g2 = a + b Algebraic division: f // a = d + e, r = bcd + j >>> f // (bc) = d, r = ad + ae + j >>> Also, algebraic division is not unique) f // a = d or f // a = e, f // g1= d, r1 = ae + j Boolean division: f g2 = (a + c)d, r2 = ae + j i.e. f = (a+b)(a+c)d + ae + j

GH R f = a(d+e) + bcd+j f = bcd + ad+ae+j f = ad f = ae f = g1 d + ae+bcd+j + ad+bcd+j + ae+j

f = (a+c)d g2 +ae+j.

Division
Definition: G is an algebraic factor of F if there exists an algebraic expression H such that F = GH (using algebraic multiplication). Definition: G is an Boolean factor of F if there exists an expression H such that F = GH (using Boolean multiplication). Example: f = ac + ad + bc + bd (a+b) is an algebraic factor of f since f = (a+b)(c+d) f = ~ab + ac + bc (a+b) is a Boolean factor of f since f = (a+b)(~a+c)
5

Why Use Algebraic Methods?


need spectrum of operations algebraic methods provide fast algorithms treat logic function like a polynomial efficient data structures fast methods for manipulation of polynomials available loss of optimality, but results quite good can iterate and interleave with Boolean operations in specific instances slight extensions available to include Boolean methods

Weak Division
Weak division is a specific example of algebraic division. DEFINITION: Given two algebraic expressions F and G, a division is called weak division if it is algebraic and R has as few cubes as possible. The quotient H resulting from weak division is denoted by F/G. THEOREM: Given expressions F and G, H and R generated by weak division are unique.

Algorithm WEAK_DIV
F=GH + R Let F = f1, f2, f3, fn G = g1, g2, g3, gm Where fi, gi are the cubes of F and G respectively Define H = F//G = hi for i=1 to m then F=G F//G + R Example 1 F= abc + abd + de G= ab + e h1 = c + d h2 = d F//G = c+d d = d F = (ab+e) d + abc

Example of WEAK_DIV
Example 2: F = ace + ade + bc + bd + be +ab + ab >> F=GH + R G = ae + b = ae, b hae = c + d hb = c + d + e +a +a H = F//G = (c+d+e+a+a) (c+d) = c+d R = be + ab + ab F = (ae + b)(c + d) + be + ab + ab

Efficiency Issues
We use filters to prevent trying a division. G is not an algebraic divisor of F if G contains a literal not in F. G has more terms than F. For any literal, its count in G exceeds that in F. F is in the transitive fanin of G. that is, if F is an input to G

10

Division - What do we divide with?


Weak_Div provides a methods to divide an expression for a given divisor How do we find a good divisor? Restrict to algebraic divisors Generalize to Boolean divisors Problem: Given a set of functions { Fi }, find common weak (algebraic) divisors.

11

Kernels and Kernel Intersections


DEFINITION: An expression is cube-free if no cube divides the expression evenly (i.e. R ?0, there is no literal that is common to all the cubes). ab + c is cube-free ab + ac and abc are not cube-free Note: a cube-free expression must have more than one cube. DEFINITION: The primary divisors of an expression F are the set of expressions D(F) = {F/c | c is a cube}.

12

Kernels and Kernel Intersections


DEFINITION: The kernels of an expression F are the set of expressions K(F) = {G | G D(F) and G is cube-free}. In other words, the kernels of an expression F are the cube-free primary divisors of F. f = abc + abde = ab(c+de): a, b and c+de are divisors tof f D(f) = {a,b,c+de) neither a nor b are kernels since they contain a cube, but c+de is a kernel of f DEFINITION: A cube c used to obtain the kernel K = F/c is called a co-kernel of K. C(F) is used to denote the set of co-kernels of F.

13

Example
Example: x = adf + aef + bdf + bef + cdf + cef + g = (a + b + c)(d + e)f + g kernels a+b+c d+e (a+b+c)(d+e)f+g co-kernels df, ef af, bf, cf 1

14

Fundamental Theorem
THEOREM: If two expressions F and G have the property that kF K(F), kG K(G) | kG kF | 1 (kG and kF have at most one term in common), then F and G have no common algebraic multiple divisors (i.e. with more than one cube). Important: If we kernel all functions and there are no nontrivial intersections, then the only common algebraic divisors left are single cube divisors.

15

The Level of a Kernel


Definition: A kernel is of level 0 (K0) if it contains no kernels except itself. A kernel is of level n (Kn) if it contains at least one kernel of level (n-1), but no kernels (except itself) of level n or greater K0(F) K1(F) K2(F) ... Kn(F) K(F). level-n kernels = Kn(F) \ Kn-1(F) Kn(F) is the set of kernels of level k or less.

Example: F = (a + b(c + d))(e + g) k1 = a + b(c + d) K1 K0 ==> level-1 k2 = c + d K0 k3 = e + g K0


16

Kerneling Algorithm (informal)


To find KERNEL(j, G) 1. Consider c the largest cube factor of G. 2. Then G/c is CUBE_FREE. 3. Select a literal of G and divide G by it. 4. The resulting Q is a kernel if it is cube-free. If it is not cube-free, then make it cube-free by selecting the largest cube factor. 5. However this kernel might contain another kernel. 6. Repeat the above procedure on the resulting function until no kernel is found.

17

Kerneling Algorithm (formal)


Algorithm KERNEL(j, G) { R= if(CUBE_FREE(G)) R = {G} for(i=j+1,...,n) { if(l i appears only in one term or none) continue if(k i, l k all cubes of G/l (l i) continue R = R KERNEL(i,MAKE_CUBE_FREE(G/l i) } return R } MAKE_CUBE_FREE(F) removes algebraic cube factor from F

18

Kerneling Algorithm
KERNEL(0, F) returns all the kernels of F. Notes:

The test (k i, l l k all cubes of G/li ) is a major efficiency factor. It also guarantees that no co-kernel is tried more than once. Can be used to generate all co-kernels. The algorithm is applicable to cube-free expressions thus either the function G is cube-free or is made so by dividing it by its largest cube factor.

19

Kerneling Illustrated Example 1


F=abcd + abce + abef there six literals The largest cube l1 = ab, then form F/l1 =cd + ce + ef
We try the literals one by one in lexicographic order, a, b, c, d, e, and f. a and b are not in F/ l1 . The largest cube dividing F/ l1 by c is d+e. The largest cube dividing F/ l1 by e is c+f. Notice the division by d and f is not cube-free. And the kernels are cd+ce+ef, d+e, c+f

F= ab (cd + cd + ef) not a kernel, not cube free ab c d+e Level 0 d c not a kernel
F/ ab = (cd+ce+ef) Kernel level 1

e c+f Level 0 e

f
not a kernel

20

Kerneling Illustrated Example 2

F = abcd + abce + adfg + aefg + adbe + acdef + beg


For the other literals Please see next slide a b c d e d c e e
(bc + fg)(d + e) + de(b + cf)=a{b[c(d+e)+de]+f[g(d+e)+cde]}

d f

d+e c+d c+e

b+ef b+df
c(d+e) + de= d(c+e) + ce = ...

g f b+cf ce+g cd+g d+e Level 0 Level 1 d(b+ef)+be= Level 2 e(b+df)+bd=


...
21

Kerneling Illustrated

F = abcd + abce + adfg + aefg + adbe + acdef + beg

b c a(d+e) (a)

(acd+ace+ade+eg)

ca(bc+bd+def) g (a) d
a(b(c+e)+f(g+ce))

da(c+e) (a)

e a(c+d)+g (a)

(a)

Level 0 Level 1 Level 2 (a) Means the same as obtained using the literal a.
22

Kerneling Illustrated

F = abcd + abce + adfg + aefg + adbe + acdef + beg

e f a(cd+g) (a) g

(abc+afg+adb+acdf+bg)

(af+b)

a(dg+eg+cde)= a{g(d+e)+cde}= a{d(g+e) +eg}

(a)

(a)
g (adf+aef+be)=

Level 0 gaf(d+e)+be= Level 1 g(af+b)+adf Level 2 (a) & (e) (a) Means the same as obtained using the literal a.

23

Kerneling Illustrated

co-kernels 1 a ab abc abd abe ac acd

kernels (level) a((bc + fg)(d + e) + de(b + cf))) + beg(3) (bc + fg)(d + e) + de(b + cf)(2) c(d+e) + de(1) d + e(0) c + e(0) c + d(0) b(d + e) + def(1) b + ef(0)

Note: f/bc = ad + ae = a(d + e)


24

Applications - Factoring
Algorithm FACTOR(F) { if(F has no factor) return F // e.g. if |F|=1, or F is an OR of single literals // or of no literal appears more than once D = CHOOSE_DIVISOR(F) (Q,R) = DIVIDE(F,D) return FACTOR(Q)FACTOR(D) + FACTOR(R) // recur } different heuristics can be applied for CHOOSE_DIVISOR different DIVIDE routines may be applied (e.g. also Boolean divide)

25

Example and Problems of Factor


Example: F = abc + abd + ae + af + g D=c+d Q = ab P = ab(c + d) + ae + af + g O = ab(c + d) + a(e + f) + g
Notation: F = the original function, D = the divisor, Q = the quotient, P = the partial factored form, O = the final factored form by FACTOR. Restrict to algebraic operations only.

O is not optimal since not maximally factored. Can be further factored to a(b(c + d) + e + f) + g The problem occurs when quotient Q is a single cube, and some of the literals of Q also appear in the remainder R.

26

Solving this Problem


Solving this problem: Check if the quotient Q is not a single cube, then done, else, Pick a literal l 1 in Q which occurs most frequently in cubes of F. Divide F by l 1 to obtain a new divisor D1. Now, F has a new partial factored form (l 1 )(D1) + (R1) and literal l 1 does not appear in R1. Note: The new divisor D1 contains the original D as a divisor because l 1 is a literal of Q. When recursively factoring D1, D can be discovered again.

27

Second Problem with FACTOR


Example: F = ace + ade + bce + bde + cf + df D=a+b Q = ce + de P = (ce + de)(a + b) + (c + d) f O = e(c + d)(a + b) + (c + d)f
Notation: F = the original function, D = the divisor, Q = the quotient, P = the partial factored form, O = the final factored form by FACTOR.

O is not maximally factored because (c + d) is common to both products e(c + d)(a + b) and remainder (c + d)f. The final factored form should have been: (c+d)(e(a + b) + f)

28

Second Problem with FACTOR


Solving the problem: Essentially, we reverse D and Q!! Make Q cube-free to get Q1 Obtain a new divisor D1 by dividing F by Q1 If D1 is cube-free, the partial factored form is F = (Q1)(D1) + R1, and can recursively factor Q1, D1, and R1 If D1 is not cube-free, let D1 = cD2 and D3 = Q1D2. We have the partial factoring F = cD3 + R1. Now recursively factor D3 and R1.

29

Improving the Divisor


Various kinds of factoring can be obtained by choosing different forms of DIVISOR and DIVIDE. CHOOSE_DIVISOR: LITERAL - chooses most frequent literal QUICK_DIVISOR - chooses the first level-0 kernel BEST_DIVISOR - chooses the best kernel DIVIDE: Algebraic Division Boolean Division

30

Factoring Algorithms
x = ac + ad + ae + ag + bc + bd +be + bf + ce + cf + df + dg LITERAL_FACTOR: x = a(c + d + e + g) + b(c + d + e + f) + c(e + f) + d(f + g) QUICK_FACTOR: x = g(a + d) + (a + b)(c + d + e) + c(e + f) + f(b + d) GOOD_FACTOR: (c + d + e)(a + b) + f(b + c + d) + g(a + d) + ce

31

Extraction
To identify cube-free expressions that occur in several functions Kernel Extraction: 1. Find all kernels of all functions 2. Choose kernel intersection with best value i.e. Ki Kj is not a cube. 3. Create new node with this as function v = Ki Kj 4. Algebraically substitute new node everywhere 5. Repeat 1,2,3,4 until best value threshold

New Node v = Ki Kj
32

Example-Extraction
f1 = ab(c(d + e) + f + g) + h (8) f2 = ai(c(d + e) + f + j) + k(8) (only level-0 kernels used in this example) 1. Extraction: K0(f1) = K0(f2) = {d + e} K0(f1) K0(f2) = {d + e} l = d + e(2) f1 = ab(cl + f + g) + h(7) f2 = ai(cl + f + j) + k(7) 2. Extraction: m = cl + f(3) K0(f1) = {cl + f + g}; K0(f2) = {cl + f + j) K0(f1) K0(f2) = cl + f f1 = ab(m + g) + h(5) f2 = ai(m + j) + k(5)

The values in parentheses are the number of the literals in the expressions there is a saving of 16-13 = 3

No kernel intersections anymore!! 3. Cube extraction: n = am f1 = b(n + ag) + h f2 = i(n + aj) + k

33

Rectangle Covering
Alternative method for the identification of common divisors We can use the kernels to determine a set of divisors for algebraic factoring, decomposition and extraction The problem can be reduced to combinatorial optimization:
Rectangle Covering

Build co-kernel cube matrix M = R C, also called a rectangle (R,C) it is expressed as in a matrix form rows correspond to co-kernels of individual functions columns correspond to individual cubes of kernel mij = cubes of functions mij = 0 if cube not there
34

Rectangle Covering
Properties of Rectangles: A rectangle (R1,C1) contains a rectangle (R2, C2) if: R2 R1 and C2 C1 identify sub-matrix M = R C, where R R, C C, and mij 0 A rectangle (R,C) is said to be prime if it is not strictly contained in another rectangle A co-rectangle of a rectangle (R,C) is the pair (R,C) where C is the set of columns not in C A Set of rectangles (Rk, Ck) form a rectangle cover of a matrix M if mij =1 implies that imRk and jCk form for some k. Each 1 in M must be covered by at least one rectangle from the cover. The covering need not be disjoint and hence a 1 in B can be covered by more than one rectangle. Rectangle covering: Dotted Red is a rectangle not prime Solid Red is a prime rectangle Blue is not a rectangle Brown rectangle is prime

1 2 3 4 5 1 1 1 1 0 * 2 1 * 1 0 * 3 0 1 1 0 1 4 1 0 1 1 1

1 2 3 4 5 1 1 1 1 0 * 2 1 * 1 0 * 3 0 1 1 0 1 4 1 0 1 1 1
35

Rectangle Kernels
Consider the algebraic expression: g= abe + acd + bcd that can be represented by the matrix A Rectangle of a matrix is a subset of rows and columns when all entries are 1. Solid Red is a prime rectangle It is a divisor (co-kernel) of g: cd Dotted Red is the co-rectangle Co-kernel: prime rectangle with number of rows >= 2 G= cd (a + b) + abe

a abe 1 acd 1 bcd 0

b 1 0 1

c 0 1 1

d e 0 1 1 0 1 0

Rectangle covering:

36

Rectangle Covering
Properties of Rectangles: A rectangle (R1,C1) contains a rectangle (R2, C2) if: R2 R1 and C2 C1 A rectangle (R,C) is said to be prime if it is not strictly contained in another rectangle A corectangle of a rectangle (R,C) is the pair (R,C) where C is the set of columns not in C A Set of rectangles (Rk, Ck) form a rectangle cover of a matrix M if mij =1 implies that imRk and jCk form for some k. Each 1 in M must be covered by at least one rectangle from the cover. The covering need not be disjoint and hence a 1 in B can be covered by more than one rectangle. Rectangle covering: identify sub-matrix M = R C, where R R, C C, and mij 0 construct divisor d corresponding to M as new node extract d from all functions

37

Kernel Intersection (example)


F = af + bf + ag + cg + ade + bde + cde G = af + bf + ace + bce H = ade + cde Total number of literals=33 The leftmost column list the functions. The second column represents all co-kernels of the functions. F The upper row represents all F cubes of the kernels. The entries in M represents the cubes of F the 3 functions

a a b de f c g a b ce f de ace af ade ade af ag

ce

de ade bde

f af bf

g ag

bde bf

cde cde cg ace bce af bf cg

Kernels/Co-kernels: F: (de+f+g)/a (de + f)/b (a+b+c/de (a + b)/f (de+g)/c (a+c)/g G: (ce+f)/{a,b} (a+b)/{f,ce} H: (a+c)/de

M = F F G G

G The two boxes identify the largest G rectangle

bce bf cde
38

ab as common to F and G

Kernel Intersections (example)


extract new expression X
X=a+b F = fX + ag + cg + deX + cde G = fX + ceX H =ade + cde Number of lit. =25 update M
F F F F F F F G G G H X a b de deX c g X f f X fX fX ceX cde fX * * ade c ce de * * cde cde cg deX fX * * * * cg ga f * * g ag * * a b

and recompute Kernels/Co-kernels: F: (de + f)/X (X+c)/de

(de+g)/c (a+c)/g G: (ce+f)/{X} H: (a+c)/de The largest rectangle is formed by the two rows 5 and 11 and the two columns a and c. Again we can find that a and c are common to F and H. Hence extract Y = a+ c X = a + b and Y=a + c F = fX + Yg + deX + cde G = fX + ceX H = Yde Number of lit. =22

ce ceX de

39

Kernel Intersections (example)


X = a + b and Y=a + c F = fX + Yg + deX + cde G = fX + ceX H = Yde and recompute Kernels/Cokernels: F: (de + f)/X (X+c)/de G: (ce+f)/{X} H: Final gain= 33 22= 11
X F F F F F F F G G G H a b de deX c g X f f X ce de fX fX ceX ceX * fX * * * * deX fX * * * * cde cde * * c ce de * * f * * * * g a b *

40

Value of a Sub-Matrix
Number of literals before - Number of literals after

V ( R ', C ') =

iR , jC

vij wir wcj


iR ' jC

vij : Number of literals of cube mij wir : (Number of literals of the cube associated with row i ) + 1 wcj : Number of literals of the cube associated with column j
a b c ce de f g ag

For the example V = 20 - 10 - 2 = 8 Go now to slide

F F F F M =F F G G G G H

a b de f c g a b ce f de ace af ade bce bf cde ade bde cde af bf

ade af bde bf

cde ag cg ace bce af bf

cg

41

Value of a Sub-Matrix
Number of literals before - Number of literals after The rectangle consists of rows 3,4, 9 and 10 and columns 1 and 2 There are 8 cubes in the rectangle. Four of the cubes consists of 3 literals and the other four of 2 literals Then the total number of literals in these cubes is 20 Each of the columns of the rectangle consists of 1 literal (a and b) then the total is 2 The co-kernels associated with the rectangle are four: two consisting of 2 literals and the other two of 1 literal, In all there are 6 cubes. Add one to each number - this results in 10 Thus extracting X results in a saving of V = 20 - 10 - 2 = 8 literals. Now calculate how much saving is obtained from Y.

a F F F F M =F F G G G G H a b de f c g a b ce f de ace af ade

ce

de

g ag

ade af bde bf ade bde cde af bf cde ag cg ace bce bce bf cde af bf

cg

42

Pseudo-Boolean Division
Rectangle covering was originally formulated for algebraic operations, it may also be used for Boolean operations with slight modification. Idea: consider entries in covering matrix that are dont cares and recall that a+ a= a. overlap of rectangles (a+a = a) product that cancel each other out (a.a = 0)

a
Example: F = ab + ac + ab + ac + bc + bc

Result: X = a + b + c F = ax + bx + cx Gain= 12 6 3 = 3 or Gain= Before (12) After (9) = 3

F F M =F F F F

a b c a ' * a 'b a 'c b ' ab ' * b ' c c ' ac ' bc ' *

a' b' c' * ab ' ac ' a ' b * bc ' a 'c b 'c *

43

S-ar putea să vă placă și