Heuristic Minimization of Two Level Circuits Sungho Kang Yonsei University
Outline Local Search Checking for Equivalence and Tautology Choosing the Right Direction Identifying Essential Implicants
Local Search Local search algorithms The algorithms that start from an initial solution and try to find a better one by applying successive modifications One property of the solution of a local search algorithm is local optimality A solution is locally optimal if its neighborhood does not contain any solution of lower cost In order to guarantee local optimality, it is sufficient to use the following stopping criterion Stop when there is no cheaper solution in the neighborhood of the current solution
Local Search Applied to Logic Minimization Starting point is a cover for a multi-output function and the cost is the number of cubes with the number of literals as a tie-breaker The neighborhood is defined as the set of covers that are obtained from the original cover by adding or removing exactly one literal to one of the cubes A new cover obtained is a feasible point if it is equivalent to the original one i.e. if it represents the same function The solutions with more cubes than the initial cover are not part of the search space
Local Search Applied to Logic Minimization x y z f 1 - x y z f - 1 change 000 1 into 0-0 1 Expanding input parts and removing the cube from the cover
Local Search Applied to Logic Minimization Expand output part and remove the cube x y z f g - 1 x y z f g - 1 x y z f g - 1 x y z f g 1 - x y z f g 1 -
Simple Local Search Algorithm F = EXPAND(F,D); F = IRREDUNDANT(F,D); do { cost = |F|; F = REDUCE(F,D); } while (|F| < cost); F = MAKE_SPARSE(F,D);
MAKE_SPARSE Example x y z f g 1 - Local Search x y z f g 1 - All cubes are maximally expanded in their input and output parts The input term xz of f is redundant MAKE_SPRSE eliminates it x y z f g 1 -
Checking for Equivalence Equivalence and Tautology Two problems One is the choice of the best move when many are possible The other is checking a move for validity When a cube is expanded new minterms are added to it Check that none of these minterms belong to the OFF-set When a cube is reduced minterms are removed from it Make sure that these minterms are either covered by some other cubes or belong to the DC-set
Checking for Equivalence Equivalence and Tautology The expansion or reduction is valid if and only if ci* ( F-{ci} ) D F={cj} is the current cover for ON-set and D is the cover for DC-set ci is the cube of F that is being added or reduced ci* is the cube that contains the newly added or removed minterms check the validity of the expansion of 000 1 to 0-0 1 ci is 000 1 and ci* is 010 1 must check the containment of 010 1 in x y z f 1 - x y z ( F-{ci} ) D 1 -
Checking for Tautology Equivalence and Tautology A possible simplistic approach is to examine all the minterms of ci* for containment in ( F-{ci} ) D This is simple but there could be too many minterms to examine Improvement Initially check for single cube containment of ci* If that fails, we break ci* into halves and check the two halves separately If both are contained, we are done If only one is contained, the other is split again, and so on If eventually we find no minterms that are not contained, the containment test has succeeded
Checking for Tautology Equivalence and Tautology The cofactor of a function f(x1, x2, …, xn) with respect to literal x1, written fx1, is f(1, x2, …, xn) The cofactor of a function f(x1, x2, …, xn) with respect to literal x1’, written fx1’, is f(0, x2, …, xn) The cofactor of a function f(x1, x2, …, xn) with respect to cube c is the successive cofactoring of f with respect to all the literals in c A function that is identically 1 is called a tautology For a function f and a cube c c f fc 1 (c f → cc fc 1 fc fc 1)
Checking for Tautology Equivalence and Tautology Advantages of [ ( F-{ci} ) D ] ci* Cofactoring may greatly simplify the function by reducing the number of variables and cubes Tautology The cofactor is taken by selecting the rows such that The first and the third input columns are not 0 The first output column is a 1
Checking for Tautology Equivalence and Tautology General rule Eliminate the rows that disagree with the input part of ci* A disagreement means that the row has a 1 in an input column where ci* has a 0 or vice versa Eliminate the rows that do not have at least a 1 in an output column where ci* has a one
Unate Functions Equivalence and Tautology A function f(x1, x2, …, xn) is monotonically increasing in variable x1 if and only if f(0, x2, …, xn ) f(1, x2, …, xn) A function f(x1, x2, …, xn) is monotonically decreasing in variable x1 if and only if f(0, x2, …, xn ) f(1, x2, …, xn) If neither of the two above is true, f is non monotonic in x1 A function f(x1, x2, …, xn) is unate in variable x1 if and only if it is either monotonic increasing or monotonic decreasing in x1 It is unate if it is unate in all of its variables
Unate Functions Equivalence and Tautology A cover f is monotonically increasing in variable x1 if and only if x1 never appears complemented in the terms of f It is monotonically decreasing in variable x1 if and only if x1 never appears uncomplemented in the terms of f If neither of the two above is true, f is non monotonic in x1 If function ia unate in variable x1 then there exists a cover of f unate in x1 If a cover in F is unate in x1 then the function F represents is also unate in x1 A unate cover F is a tautology if and only if it contains the constant term 1
Unate Functions Non-unate cover xyz f yz fx yz fx’ Equivalence and Tautology Non-unate cover xyz f yz fx yz fx’ 1-1 1 after splitting -1 1 0- 1 11- 1 1- 1 -0 1 00- 1 0-0 1 It is sufficient to examine one of them to see that the function is not a tautology
Unate Functions Equivalence and Tautology It is sufficient to test the negative cofactor for tautology to get the answer for the complete functions If a function is negative unate in a variable, it is sufficient to test the positive cofactor for tautology wxyz f - 1- 1 1 0 -10 1 010- 1 All minterms with w=1 and x=0 cause f to be 0 After simplification, no row is left The fucntion is not tautologous
Speed-up for Tautology Checking Equivalence and Tautology A row of all - in the input part If such a row is found, the function is tautologous in all the outputs that have a 1 in that row This condition is always sufficient and is also necessary for unate functions An input column of all 1s or all 0s If such a column is found, the function is not a tautology If the number of inputs is less than 8, the truth table is generated and the tautology question is answered by inspection The rationale is that if the number of inputs is small enough, generating the truth table is faster than recurring If the vertex count of the cover is insufficient, the function is not a tautology The vertex count of the cover is the sum of the vertex counts of the cubes
Speed-up for Tautology Checking Equivalence and Tautology Partitioning a search problem is normally very advantageous If a cover F can be written as F = G + H where G and H have disjoint support (no variables in common), then F is tautologous if and only if either G and H are tautologous Let x1, …xk be the variables on which G depends and xk+1, … xn be the variables on which H depends If G(x1*, …xk*)=0 and H(xk+1*, … xn*)=0, then F(x1*, …xk*, xk+1*, … xn*)=0
Speed-up for Tautology Checking Equivalence and Tautology Finding a bipartition The set of columns of the first block C1, is initialized to empty One then picks a cube of the cover All the columns where the cube is 0 or 1 are added to C1 Then all the cubes that intersect any of the column in C1 are selected and their columns added to C1 The process is repeated until no addition to C1 is possible There are two possible outcomes C1 includes all the columns of the cover There is no bipartition At least one column is left over The leftover columns and rows identify the second block of the partition
Speed-up for Tautology Checking Equivalence and Tautology Partitioning example 12345 1 1-1- - 2 -1--0 3 0--0- 4 -- 01- 5 ---- 1 C1={1,3,4} and C2={2,5} Neither subproblem is tautologous
Tautology Checks : Example Equivalence and Tautology Not a tautology wxyz f cover is unate in w and x - - 1 - 1 1 - - 1 1 cofactor wrt to w’ and x yz f - 0 - 0 1 1- 1 - 0 0 - 1
Tautology Checks : Example Equivalence and Tautology A multiple output cover is tautologous if all the outputs are tautologous wxyz fg cover is unate in w and x 1- 01 01 - 110 10 cofactor yz fg 1110 11 -0 10 - - - 0 10 -1 11 - - - 1 11 can drop y g is not a tautology Not a tautology
Choosing the Right Direction The choice of one direction over another may influence the quality of the solution Having an explicit representation of the OFF-set of the function helps
Recursive Complementation Right Direction For a Boolean function f f’ = xf’x +x’f’x’ Proof Let g = xf’x +x’f’x’ ( f = xfx +x’fx’ ) f + g = x(fx + f’x) + x’(fx’ + f’x’) = x + x’ = 1 fg = (xfx +x’fx’)(xf’x +x’f’x’) = 0
Recursive Complementation Example Right Direction Positive cofactor wrt x Positive cofactor wrt x f’xy’ = 0 x y z f 1 - y z fx - 1 z fxy 1 z f’xy 1 z fxy’ - 1 z f’xy’ y z f’x’ - 1 y z fx’ - 1 y z f’x 1 x y z f’ 1 -
Recursive Complementation Right Direction For f monotonic increasing in x f’ = fx’ +x’ fx’’ For f monotonic decreasing in x f’ = x fx’ + fx’’
Recursive Complementation Right Direction Example wxyz If we select w, a row of all dashes will appear in fw 11 - - Complement of the tautology is trivial to compute 1 - - - - 1 - 1 fw’ = 0 - 11 - compute fw’’ cofactoring f xyz - 111 1- 1 11- 111 fw’’ = x’+G’ xyz final result 0- - wxyz -00 00 - - 0 - 00
Using the OFF-set in the Expansion Right Direction Build a blocking matrix, that has a row for each cube in the OFF-set and a column for each variable A row of the blocking matrix tells us that it is OK to expand the cube, as long as at least one of the directions corresponding to one of its ones is not expanded It is not difficult to see that finding a maximum expansion corresponds to finding a minimum subset of the columns of the blocking matrix that covers all the rows
Identifying Essential Primes Let F be a cover composed of prime implicants Let e be one of the primes in F and let G be the cover composed of the remaining primes Then e is an essential prime if and only if it is not covered by the union of ; 1. The consensus terms of e and each term of G 2. The intersections of e and each term of G
Identifying Essential Primes Consider y’z’+xy’+xz and test y’z’ This prime intersects xy’ (the intersection is xy’z’) It also has a consensus term with xz (xy’) To see whether y’z’ is essential, check y’z’ xy’ + xy’z’ Since xy’z’ xy’, need to check y’z’ xy’ The answer is no; hence y’z’ is essential If we consider xy’, need to check whether xy’ is covered by xy’z’ + xy’z The answer is positive and xy’ is not essential
Identifying Essential Primes Consider f = x’z’+x’y+xz The cover is not a complete sum Therefore it is not immediate to see whether a given prime is essential Suppose we want to test x’y Its intersection with x’z’ is x’yz’, while its consensus term with xz is yz Hence we test x’y x’yz’ + yz Cofactoring the right hand side, we get z’+x, which is clearly a tautology Hence x’y is not essential