Generalized Cofactor Definition 1 Let f, g be completely specified functions. The generalized cofactor of f with respect to g is the incompletely specified function: co( f , g ) ( f g , g , f g ) Definition 2 Let = (f, d, r) and g be given. Then co(, g ) ( f g , d g , r g ) 1 Relation with Shannon Cofactor • Let g=xi . Shannon cofactor is f xi f ( x1 ,, ( xi 1), , xn ) • Generalized cofactor with respect to g=xi is co( f , x ) ( f x , x , f x ) i i i i • Note that f xi f xi f xi xi f xi In fact fxi is the unique cover of co(f, xi ) independent of the variable xi . 2 Shannon Cofactor on f abc ab c a b c a bc off Don’t care a co( f , a) ( f a, a , f a) f a bc b c 3 Shannon Cofactor (Cont.) co( f , a) ( f a, a , f a) f f a fa So fa a f a fa f a 4 Properties of Generalized Cofactor co(f,g) Shannon Cofactor x fx x fx f f x y f xy f g y f y g y f f x x Generalized Cofactor f g co( f , g ) g co( f , g ) co(co( f , g ), h) co( f , gh) co( f g , h) co( f , h) co( g , h) co( f , g ) co( f , g ) We will get back to use of generalized cofactor later 5 Quine-McCluskey Summary Q-M: 1. Generate cover of all primes G p1 p2 p3n / n 2. Make G irredundant (in optimum way) Note: Q-M is exact i.e. it gives an exact minimum Heuristic Methods: 1. 2. 3. Generate (somehow) a cover of using some of the primes G pi pi pi 1 2 k Make G irredundant (maybe not optimumly) Keep best result - try again (i.e. go to 1) 6 ESPRESSO - Heuristic Two-Level Minimization ESPRESSO() { (F,D,R) DECODE() F EXPAND(F,R) F IRREDUNDANT(F,D) E ESSENTIAL_PRIMES(F,D) F F-E; D D E do{ do{ F REDUCE(F,D) F EXPAND(F,R) F IRREDUNDANT(F,D) } }while fewer terms in F //LASTGASP G REDUCE_GASP(F,D) G EXPAND(G,R) F IRREDUNDANT(F G,D) //LASTGASP }while G F F E; D D-E LOWER_OUTPUT(F,D) RAISE_INPUTS(F,R) error (Fon F) or (F Fold D) return (F,error) 7 ESPRESSO Illustrated REDUCE Local minimum EXPAND IRREDUNDAN T Local minimum 8 IRREDUNDANT Problem: Given a cover of cubes {ci}, find a minimum subset {cik} that is also a cover, i.e. f cik f d Idea 1: We are going to create a function g(y) and a new set of variables yi, one for each cube ci. A minterm in the yspace will indicate a subset of the cubes {ci}. Example 1: y=011010 = {c2,c3,c5} 9 IRREDUNDANT Idea 2: Create g(y) so that it is the function such that: g(y) = 1 c yik 1 ik is a cover i.e. if g(yk) = 1 if and only if {ci | yki =1} is a cover. Note: g(y) is positive unate (monotone increasing) in all its variables. 10 Example Example 2: f bc a c a b b c g ( y1 , y2 , y3 , y4 ) y1 y4 ( y2 y3 ) 1 2 3 4 Note: We are after a minimum subset of cubes. Thus we want: the largest prime of g (least literals). Consider g : it is monotone decreasing in y, e.g. g ( y1 , y2 , y3 , y4 ) y1 y4 y2 y3 11 Example Create a Boolean matrix for g: f bc a c a b b c g ( y1 , y2 , y3 , y4 ) y1 y4 y2 y3 • Recall a minimal column cover of B is a prime of g (g) • We want a minimum cover of B Example 3: {1,2,4} y1 y2 y4 (cubes 1,2,4) bc,a c,b c 12 Deriving g(y) Modify tautology algorithm: F = cover of =(f,d,r) D = cover of d Pick a cube ci F. (Note: ci F Fci 1) Do the following for each cube ci F : A FCi B D Ci 13 Deriving g(y) 1. All leaves must be tautologies 2. G’ means how can we make it not the tautology. We must exactly delete all rows of all 2’s that are not part of D 3. Each row came from some row of A/B 4. Each row of A is associated with some cube of F. 5. Each cube of B associated with some cube of D ( we don’t need to know which, and we can’t delete its rows). 6. Rows that must be deleted are written as a cube, e.g. y1y2y7 delete rows 1,3,7 of F. 14 Deriving g(y) Example 4: Suppose unate leaf is in subspace x1x’2x3 : Thus we write down: y10 y18 (actually, yi must be one of y10 , y18). Thus, F is not a cover if we leave out cubes c10 , c18. Note: If row of all 2’s in don’t cares, then there is no way not to have tautology at that leaf. Unate leaf Row of all 2’s in don’t cares 15 Deriving g(y) g ( y) gi ( y) g j ( y) gi ( y) y10 y18 gi ( y) ci F D g j ( y) cj x1 x2 x3 16 Summary Convert g(y) into a Boolean matrix B (note that g(y) is unate). Then find a minimum cover of B. For example, if y1y3y18 is a minimum cover, then the set of cubes: {c1 , c3 , c18 } is a minimum sub cover of { ci | i=1,…,k}. (Recall that a minimal cover of B is a prime of g(y), and g(y) gives all possible sub-covers of F). Note: We are just doing tautology in constructing g(y) , so unate reduction works: A B T C , Other efficiencies ? A 1 17 Back to Q-M All primes B= Minterms of f 1011010 B g ( y) y1 y3 y4 y6 We want a maximum prime of g(y). Note: A row of B says if we leave out primes {p1 , p3 , p4 , p6 } we cease to have a cover. So basically, the only difference between Q-M and IRREDUNDANT is that for the latter, we just constructed a g(y) where we did not consider all primes, but only those in some cover: F = {c1 , c3 ,…, ck } 18 EXPAND F EXPAND(F,R) Problem: Take a cube c and make it prime by removing literals. a). Greedy way: (uses D and not R) remove literal l i from c (results in c c ) test if c f d (same as (f d)c 1) repeat, removing valid literals in order found. 19 EXPAND F EXPAND(F,R) b). Better way: (uses R and not D) Want to see all possible ways to remove maximal subset of literals. Idea: Create a function g(y) such that g(y)=1 iff literals: {li | yi 0} can be removed. or {li | yi 1} is a subset of literals such that if kept in c, will still make c~ f d , i.e. c~ r 20 Main Idea of EXPAND Outline: 1. Expand one cube, ci , at a time 2. Build “blocking” matrix B = B ci 3. See which other cubes cj can be feasibly covered using B. 4. Choose expansion (literals to be removed) to cover most other cj . Note: g (y ) is monotone increasing B g (y ) is easily built if we have R , a cover of r . We do not need all of R . (reduced offset) 21 Reduced offset on off Don’t care r a b ab ac Make r unate by adding (1,1,1) to offset. Then Rblack a b g ( y ). This is simpler and easier to deal with. (See paper A. Malik et. al.) 22 Blocking Matrix B (for cube C) Given R = {ri }, a cover of r. [ = (f,d,r) ] l j C and l j ri Bij 1 l j C and l j ri What does row i of B say? It says that if literals j | Bij 1 are removed from c, then c ri , i.e. Bij 1 is one reason why c is orthogonal to offset cube ri . Thus B g ( y ) y1 y3 y10 gives all ways that literals of c can be removed to get c~ f d c~ r 23 EXPAND example c abd ri abde y1 y2 y3 a, b, d y1 1 keep a Suppose g(y)=1, If y1 = 1, we keep literal y2 1 keep b a in cube c. y3 1 keep c Bi 101 y1 y3 gi(y) Bi means do not keep literals 1 and 3 of c. (implies that ~ is not an implicant). If literals 1, 3 are subsequent c ~ b . But c~ r : removed we get c c i b a bde a bde so obviously b is not an implicant. 24 EXPAND continued Thus all minimal column covers ( g(y) ) of B are the minimal subsets of literals of c that must be kept to ensure that c f d ( i.e. c ri ) Thus each minimal column cover is a prime p that covers c, i.e. p c. p1 p2 c p3 pi c 25 End of lecture 4 26 Expanding ci F = { ci }, = (f,d,r) f F f+d Q: Why do we want to expand ci ? A: To cover some other cj ‘s. ci p cj Q: Can we cover cj ? A: If and only if (SCC = “smallest cube containing” also called “supercube” ) equivalent to: SCC ci c j f d SCC ci c j ri equivalent to: literals ”conflicting” between ci, cj can be removed and still have an implicant 27 Expanding ci Can check SCC(ci, cj) with blocking matrix: ci = 12012 cj = 12120 implies that literals 3 and 4 must be removed for to cover cj . Check if column 3, 4 of B can be removed without causing a row of all 0’s. ci p c~i cj 28 Covering function The objective of EXPAND is to expand ci to cover as many cubes cj as possible. The blocking function g(y)=1 whenever the subset of literals {li | yi 1} ~ f d. (Note that c~ yields a cube c l j). ( y j 1) We now build the covering function,h , such that: h(y) = 1 ~ c covers another cube c F. whenever the cube c j i Note: h(y) is easy to build. Thus a minterm m g(y) h(y) is such that it gives c~ f d ( g(m) =1 ) and covers at least one cube (h(m) =1). In fact every cube c~m cl is covered. We seek m which results in the most cubes covered. 29 Covering function Thus define h(y) by a set of cubes where dk = kth cube is: d k if SCC[ci ck ] f d else j dk yj 2 1 if ckj cij i.e. 0 1 1 0 2 otherwise (Thus each dk gives minimal expansion to cover ck ) Thus dk if cube ck can be feasibly covered by expanding cube ci. dk says which literals we have leave out to minimally cover ck . Thus h(y) is defined by h(y) = d1 + d2 +… + d|F|-1 (one for each cube of F, except ci. It is monotone decreasing). 30 Covering function We want m g(y)h(y) contained in a maximum number of dk ‘s. In the Espresso, we build a Boolean covering matrix C (note that h(y) is unate negative) representing h(y) and solve this problem with greedy heuristics. Note: 010110 B g ( y) ~ but C h ( y) h( y) C 101011 100101 110110 B 101010 101001 31 Covering function 010110 C 101011 100101 110110 B 101010 101001 Want set of columns such that if eliminated from B and C results in no empty rows of B and a maximum of empty rows in C. Note: ~does not a 1 in C can be interpreted as a reason why c cover cj . 32 Endgame What do we do if h(y) 0 ? Some things to try: • generate largest prime covering ci • cover most care points of another cube ck • coordinate two or more cube expansions, i.e. try to cover another cube by a combination of several other cube expansions So far we have not come up with a really satisfactory endgame. This could be important in many hard problems, since it is often the case that h(y) 0 . 33 REDUCE Problem: Given a cover F and c F, find the smallest cube c c such that F\{ c } + { c } is still a cover. c is called the maximally reduced cube of c. REDUCE is order dependent on off Don’t care BAD GOOD 34 REDUCE Example Example 5: F ac bc b c a c Two orders: BAD GOOD abc bc abc ac 2. REDUCE F bc, bc , ac, ac abc ac abc ac 1. REDUCE F ac, bc, bc , ac REDUCE is order dependent ! 35 REDUCE Algorithm REDUCE F , D { F ORDER( F) for (1 j F ) do { c j MAX_REDUCE( c, F, D) F (F {c j }) \ {c j } } return F } 36 REDUCE Main Idea: Make a prime not a prime but still maintain cover: {c1 ,…, ci,…, ck} {c1 ,…,ci,ci+1 ,…,ck } i 1 k But f c j ci c j f d j 0 j i 1 • Get out of a local minimum (prime and irredundant is local minimum) • Then have nonprimes, so can expand again in different directions. (Since EXPAND is “smart”, it may know best direction) 37 REDUCE F = {c1 ,c2, …,ck} F (i) = (F + D) \ { ci } = {c1 ,c2,…,ci-1,ci+1,…, ck} • Reduced cube: c i = smallest cube containing (ci F(i) ) • Note that ci F(i) is the set of points uniquely covered by ci (and not by any other cj or D). • Thus, ci is the smallest cube containing the minterms of ci which are not in F(i). 38 REDUCE C1 C1 C2 on C2 off Don’t care F (i ) SCC c F (i ) c SCC F (i ) c i SCC ci i i ci ci ci SCCC Fci (i ) • SCC == “supercube” • SCCC = “smallest cube containing complement” 39 Efficient Algorithm for SCCC Unate Recursive Paradigm: • select most binate variable • cofactor • until unate leaf x1 x1 x2 x3 x2 x3 unate What is SCCC (unate cover) ? • Note that for a cube c with at least 2 literals, SCCC(c) is the universe: 12222 cube cube 01222 20222 So SCCC(cube) = 22222 40 SCCC SCCC (U) = Claim: if unate cover has row of – all 2’s except one 0, then complement is in x i , i.e. i = 1 – all 2’s except one 1, complement is in x i, i.e. i = 0 otherwise in both subspaces, i.e. i = 2 Finally SCCC c1 c2 ck SCC c1c2 SCC c1 ck SCC ck Implies that only need to look at 1-literal cubes. 41 SCCC Example Example1: f a bc d f a (b c )d a d Note: 0101 and 0001 are both inf . So SCCC could not have literal b or b in it. Example2: 2 0 U (unate ) 2 2 2 2 1 1 2 2 1 2 2 2 2 1 0 2 2 0 Note that columns 1 and 5 are essential: they must be in every minimal cover. So U = x1x5(...). Hence SCCC(U) = x1x5 42 SCCC Example Proof. (sketch): U x1 x5 x2 ( x3 x4 ) U x1 x5 ( x2 x3 x4 ) 1 0 2 2 1 U (unate) 1 2 0 0 1 12221 The marked columns contain both 0’s and 1’s. But every prime ofU contains literals x1 , x5 minterms of U 1 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 1 43 SCCC Thus γ SCCC(unate) if row of all 2's x j if column j has a row singleton with a 0 in it γ j x j if column j has a row singleton with a 1 in it 2 otherwise Thus unate leaf is easy ! 44 Merging We need to produce SCCC f SCC xi c1 xi c2 xi xi l j i l1l 2 lk c2 c1 (l j c1 ) (l j c2 ) If c1 c2 , then points in both xi andxj, so ( SCC(xic1 +xic2) )i = 2 If ljc1 , or ljc2 , then both xj andxj points exit, hence i =2. Also if ljc1 and ljc2 , then i =2. 45 ESPRESSO() { (F,D,R) DECODE() F EXPAND(F,R) F IRREDUNDAN T(F, D) E ESSENTIAL_ PRIMES(F, D) F F - E; D D E do{ do{ F REDUCE(F,D) F EXPAND(F,R) F IRREDUNDAN T(F, D) }while fewer terms in F //LASTGASP G REDUCE_GASP(F,D) G EXPAND(G,R) F IRREDUNDANT(F G,D) //LASTGASP }while G F F E; D D-E LOWER_OUTPUT(F,D) RAISE_INPUTS(F,R) error (Fon F) or (F Fold D) 46 return(F,error) ESPRESSO - Heuristic Two-Level Minimization } LASTGASP Reduce is order dependent: Expand can’t do anything with the reduction produced by REDUCE 2. Maximal Reduce: c i SCCC ci M F ( i ) ci REDUCE 2 REDUCE 1 GOOD BAD SCCC F (i )ci i i.e. we reduce all cubes as if each were the first one. Note: {c1M ,c2M ,...} is not a cover. 47 LASTGASP Now expand use EXPAND, but try to cover only cjM‘s. (Note here we call EXPAND(G,R), where G = {c1M ,c2M ,…, ckM} ) If a covering is possible, take the resulting prime: f d pi c i c j and add to F: ~ F F { pi } Since F is a cover, so is F . Now make F irredundant (using M M IRREDUNDANT). What about “supergasp” ? Main Idea: Generally, think of ways to throw in a few more primes and then use IRREDUNDANT. If generate all primes, then just Quine-McCluskey 48 Goldberg Variation Property of LASTGASP: Let Fi = maximal reduction of Fi F. LASTGASP searches for maximally reduced cubes Fi and Fk such that Fik supercube( Fi, Fk) is an implicant of . It then produces a new prime (which is not in F) which covers supercube( Fi, Fk). However, this does not guarantee that the size of F decreases by at least one on the next IRREDUNDANT. EXAMPLE: 100 F F 110 F 1 122 221 2 D 010 001 011 F12 212 prime 49 Goldberg Theorem Theorem 1: Let Aik = (f Fi Fk ) - { F\ {Fi,Fk} } = ( Fi Fk ) - { D+F\ {Fi,Fk} } (i.e. Aik is the set of ON-set minterms covered by Fi Fk and not intersected with any other cube from F.) Then both Fi and Fk can be replaced by a prime Pik supercube( Fi, Fk) if and only if: Pik Aik Thus for a reduction by at least one in the size of the cover, we need a prime with the property Pik supercube( Fi, Fk) Aik An algorithm based on this was proposed by E. Goldberg of the Byelorussion Academy of Sciences, Institue of Engineering Cybernetics in Minsk, FSU (now at Cadence Berkeley Labs). He reported it was less expensive than SUPER_GASP and more effective than LASTGASP. 50