Jump to content

Quine–McCluskey algorithm

From Wikipedia, the free encyclopedia

Hasse diagram of the search graph of the algorithm for 3 variables. Given e.g. the subset of the bottom-level nodes (light green), the algorithm computes a minimal set of nodes (here: , dark green) that covers exactly .

The Quine–McCluskey algorithm (QMC), also known as the method of prime implicants, is a method used for minimization of Boolean functions that was developed by Willard V. Quine in 1952[1][2] and extended by Edward J. McCluskey in 1956.[3] As a general principle this approach had already been demonstrated by the logician Hugh McColl in 1878,[4][5][6] was proved by Archie Blake in 1937,[7][8][9][6] and was rediscovered by Edward W. Samson and Burton E. Mills in 1954[10][6] and by Raymond J. Nelson in 1955.[11][6] Also in 1955, Paul W. Abrahams and John G. Nordahl[12] as well as Albert A. Mullin and Wayne G. Kellner[13][14][15][16] proposed a decimal variant of the method.[17][14][15][16][18][19][20][21]

The Quine–McCluskey algorithm is functionally identical to Karnaugh mapping, but the tabular form makes it more efficient for use in computer algorithms, and it also gives a deterministic way to check that the minimal form of a Boolean F has been reached. It is sometimes referred to as the tabulation method.

The Quine-McCluskey algorithm works as follows:

  1. Finding all prime implicants of the function.
  2. Use those prime implicants in a prime implicant chart to find the essential prime implicants of the function, as well as other prime implicants that are necessary to cover the function.

Complexity

[edit]

Although more practical than Karnaugh mapping when dealing with more than four variables, the Quine–McCluskey algorithm also has a limited range of use since the problem it solves is NP-complete.[22][23][24] The running time of the Quine–McCluskey algorithm grows exponentially with the number of variables. For a function of n variables the number of prime implicants can be as large as ,[25] e.g. for 32 variables there may be over 534 × 1012 prime implicants. Functions with a large number of variables have to be minimized with potentially non-optimal heuristic methods, of which the Espresso heuristic logic minimizer was the de facto standard in 1995.[needs update][26] For one natural class of functions , the precise complexity of finding all prime implicants is better-understood: Milan Mossé, Harry Sha, and Li-Yang Tan discovered a near-optimal algorithm for finding all prime implicants of a formula in conjunctive normal form.[27]

Step two of the algorithm amounts to solving the set cover problem;[28] NP-hard instances of this problem may occur in this algorithm step.[29][30]

Example

[edit]

Input

[edit]

In this example, the input is a Boolean function in four variables, which evaluates to on the values and , evaluates to an unknown value on and , and to everywhere else (where these integers are interpreted in their binary form for input to for succinctness of notation). The inputs that evaluate to are called 'minterms'. We encode all of this information by writing

This expression says that the output function f will be 1 for the minterms and (denoted by the 'm' term) and that we don't care about the output for and combinations (denoted by the 'd' term). The summation symbol denotes the logical sum (logical OR, or disjunction) of all the terms being summed over.

Step 1: finding prime implicants

[edit]

First, we write the function as a table (where 'x' stands for don't care):

A B C D f
m0 0 0 0 0 0
m1 0 0 0 1 0
m2 0 0 1 0 0
m3 0 0 1 1 0
m4 0 1 0 0 1
m5 0 1 0 1 0
m6 0 1 1 0 0
m7 0 1 1 1 0
m8 1 0 0 0 1
m9 1 0 0 1 x
m10 1 0 1 0 1
m11 1 0 1 1 1
m12 1 1 0 0 1
m13 1 1 0 1 0
m14 1 1 1 0 x
m15 1 1 1 1 1

One can easily form the canonical sum of products expression from this table, simply by summing the minterms (leaving out don't-care terms) where the function evaluates to one:

fA,B,C,D = A'BC'D' + AB'C'D' + AB'CD' + AB'CD + ABC'D' + ABCD.

which is not minimal. So to optimize, all minterms that evaluate to one are first placed in a minterm table. Don't-care terms are also added into this table (names in parentheses), so they can be combined with minterms:

Number
of 1s
Minterm Binary
Representation
1 m4 0100
m8 1000
2 (m9) 1001
m10 1010
m12 1100
3 m11 1011
(m14) 1110
4 m15 1111

At this point, one can start combining minterms with other minterms in adjacent groups. If two terms differ by only a single digit, that digit can be replaced with a dash indicating that the digit doesn't matter. Terms that can't be combined any more are marked with an asterisk (*). For instance 1000 and 1001 can be combined to give 100-, indicating that both minterms imply the first digit is 1 and the next two are 0.

Number
of 1s
Minterm 0-Cube Size 2 Implicants
1 m4 0100 m(4,12) -100 *
m8 1000 m(8,9) 100-
m(8,10) 10-0
m(8,12) 1-00
2 m9 1001 m(9,11) 10-1
m10 1010 m(10,11) 101-
m(10,14) 1-10
m12 1100 m(12,14) 11-0
3 m11 1011 m(11,15) 1-11
m14 1110 m(14,15) 111-
4 m15 1111

When going from Size 2 to Size 4, treat - as a third bit value. Match up the -'s first. The terms represent products and to combine two product terms they must have the same variables. One of the variables should be complemented in one term and uncomplemented in the other. The remaining variables present should agree. So to match two terms the -'s must align and all but one of the other digits must be the same. For instance, -110 and -100 can be combined to give -1-0, as can -110 and -010 to give --10, but -110 and 011- cannot since the -'s do not align. -110 corresponds to BCD' while 011- corresponds to A'BC, and BCD' + A'BC is not equivalent to a product term.

Number
of 1s
Minterm 0-Cube Size 2 Implicants Size 4 Implicants
1 m4 0100 m(4,12) -100 *
m8 1000 m(8,9) 100- m(8,9,10,11) 10-- *
m(8,10) 10-0 m(8,10,12,14) 1--0 *
m(8,12) 1-00
2 m9 1001 m(9,11) 10-1
m10 1010 m(10,11) 101- m(10,11,14,15) 1-1- *
m(10,14) 1-10
m12 1100 m(12,14) 11-0
3 m11 1011 m(11,15) 1-11
m14 1110 m(14,15) 111-
4 m15 1111

Note: In this example, none of the terms in the size 4 implicants table can be combined any further. In general this process should be continued (sizes 8, 16 etc.) until no more terms can be combined.

Step 2: prime implicant chart

[edit]

None of the terms can be combined any further than this, so at this point we construct an essential prime implicant table. Along the side goes the prime implicants that have just been generated (these are the ones that have been marked with a "*" in the previous step), and along the top go the minterms specified earlier. The don't care terms are not placed on top—they are omitted from this section because they are not necessary inputs.

4 8 10 11 12 15 A B C D
m(4,12) # ✓ ✓ 1 0 0
m(8,9,10,11) ✓ ✓ ✓ 1 0
m(8,10,12,14) ✓ ✓ ✓ 1 0
m(10,11,14,15) # ✓ ✓ ✓ 1 1

To find the essential prime implicants, we look for columns with only one "✓". If a column has only one "✓", this means that the minterm can only be covered by one prime implicant. This prime implicant is essential.

For example: in the first column, with minterm 4, there is only one "✓". This means that m(4,12) is essential (hence marked by #). Minterm 15 also has only one "✓", so m(10,11,14,15) is also essential. Now all columns with one "✓" are covered. The rows with minterm m(4,12) and m(10,11,14,15) can now be removed, together with all the columns they cover.

The second prime implicant can be 'covered' by the third and fourth, and the third prime implicant can be 'covered' by the second and first, and neither is thus essential. If a prime implicant is essential then, as would be expected, it is necessary to include it in the minimized boolean equation. In some cases, the essential prime implicants do not cover all minterms, in which case additional procedures for chart reduction can be employed. The simplest "additional procedure" is trial and error, but a more systematic way is Petrick's method. In the current example, the essential prime implicants do not handle all of the minterms, so, in this case, the essential implicants can be combined with one of the two non-essential ones to yield one equation:

fA,B,C,D = BC'D' + AB' + AC[31]

or

fA,B,C,D = BC'D' + AD' + AC

Both of those final equations are functionally equivalent to the original, verbose equation:

fA,B,C,D = A'BC'D' + AB'C'D' + AB'C'D + AB'CD' + AB'CD + ABC'D' + ABCD' + ABCD.

Algorithm

[edit]

Step 1: Finding the prime implicants

[edit]

The pseudocode below recursively computes the prime implicants given the list of minterms of a boolean function. It does this by trying to merge all possible minterms and filtering out minterms that have been merged until no more merges of the minterms can be performed and hence, the prime implicants of the function have been found.

// Computes the prime implicants from a list of minterms. 
// each minterm is of the form "1001", "1010", etc. 
function getPrimeImplicants(list minterms) is 
    primeImplicants ← empty list
    merges ← new boolean array of length equal to the number of minterms, each set to false
    numberOfmerges ← 0 
    mergedMinterm, minterm1, minterm2 ← empty strings 

    for i = 0 to length(minterms) do
        for c = i + 1 to length(minterms) do
            minterm1 ← minterms[i]
            minterm2 ← minterms[c]
            // Checking that two minterms can be merged
            if CheckDashesAlign(minterm1, minterm2) && CheckMintermDifference(minterm1, minterm2) then
                mergedMinterm ← MergeMinterms(minterm1, minterm2) 
                if primeImplicants Does Not Contain mergedMinterm then
                    primeImplicants.Add(mergedMinterm) 
                numberOfMerges ← numberOfMerges + 1
                merges[i] ← true
                merges[c] ← true

    // Filtering all minterms that have not been merged as they are prime implicants. Also removing duplicates
    for j = 0 to length(minterms) do
        if merges[j] == false && primeImplicants Does Not Contain minterms[j] then
            primeImplicants.Add(minterms[j]) 

    // if no merges have taken place then all of the prime implicants have been found so return, otherwise 
    // keep merging the minterms. 
    if numberOfmerges == 0 then
        return primeImplicants
    else 
        return getPrimeImplicants(primeImplicants)

In this example the CheckDashesAlign and CheckMintermDifference functions perform the necessary checks for determining whether two minterms can be merged. The function MergeMinterms merges the minterms and adds the dashes where necessary.

function MergeMinterms(minterm1, minterm2) is
    mergedMinterm ← empty string
    for i = 0 to length(minterm1) do 
        //If the bits vary then replace it with a dash, otherwise the bit remains in the merged minterm.
        if minterm[i] != minterm2[i] then
            mergedMinterm ← mergedMinterm + '-'
        else
            mergedMinterm ← mergedMinter + minterm1[i] 
    return mergedMinterm

function CheckDashesAlign(minterm1, minterm2) is
    for i = 0 to length(minterm1) do 
        // If one minterm has dashes and the other does not then the minterms cannot be merged. 
        if minterm1[i] != '-' && minterm2[i] == '-' then
            return false 
    return true

function CheckMintermDifference(minterm1, minterm2) is 
    // minterm1 and minterm2 are strings representing all of the currently found prime implicants and merged 
    // minterms. Examples include '01--' and '10-0'
    m1, m2  integer representation of minterm1 and minterm2 with the dashes removed, these are replaced with 0
    // ^ here is a bitwise XOR
    res ← m1 ^ m2
    return res != 0 && (res & res - 1) == 0

Step 2: Prime implicant chart

[edit]

The pseudocode below can be split into two sections:

  1. Creating the prime implicant chart using the prime implicants
  2. Reading the prime implicant chart to find the essential prime implicants.

Creating the prime implicant chart

[edit]

The prime implicant chart can be represented by a dictionary where each key is a prime implicant and the corrresponding value is an empty string that will store a binary string once this step is complete. Each bit in the binary string is used to represent the ticks within the prime implicant chart. The prime implicant chart can be created using the following steps:

  1. Iterate through each key (prime implicant of the dictionary).
  2. Replace each dash in the prime implicant with the \d character code. This creates a regular expression that can be checked against each of the minterms, looking for matches.
  3. Iterate through each minterm, comparing the regular expression with the binary representation of the minterm, if there is a match append a "1" to the corresponding string in the dictionary. Otherwise append a "0".
  4. Repeat for all prime implicants to create the completed prime implicant chart.

When written in pseudocode, the algorithm described above is:

function CreatePrimeImplicantChart(list primeImplicants, list minterms) 
    primeImplicantChart ← new dictionary with key of type string and value of type string
    // Creating the empty chart with the prime implicants as the key and empty strings as the value. 
    for i = 0 to length(primeImplicants) do
        // Adding a new prime implicant to the chart. 
        primeImplicantChart.Add(primeImplicants[i], "")
    
    for i = 0 to length(primeImplicantChart.Keys) do
        primeImplicant ← primeImplicantChart.Keys[i]
        // Convert the "-" to "\d" which can be used to find the row of ticks above.
        regularExpression ← ConvertToRegularExpression(primeImplicant)
        for j = 0 to length(minterms) do
            // If there is a match between the regular expression and the minterm than append a 1 otherwise 0. 
            if regularExpression.matches(primeImplicant) then
                primeImplicantChart[primeImplicant] += "1"
            else 
                primeImplicantChart[primeImplicant] += "0"

    // The prime implicant chart is complete so return the completed chart. 
    return primeImplicantChart

The utility function, ConvertToRegularExpression, is used to convert the prime implicant into the regular expression to check for matches between the implicant and the minterms.

function ConvertToRegularExpression(string primeImplicant)
    regularExpression ← new string 
    for i = 0 to length(primeImplicant) do
        if primeImplicant[i] == "-" then
            // Add the literal character "\d". 
            regularExpression += @"\d"; 
    return regularExpression

Finding the essential prime implicants

[edit]

Using the function, CreatePrimeImplicantChart, defined above, we can find the essential prime implicants by simply iterating column by column of the values in the dictionary, and where a single "1" is found then an essential prime implicant has been found.

See also

[edit]

References

[edit]
  1. ^ Quine, Willard Van Orman (October 1952). "The Problem of Simplifying Truth Functions". The American Mathematical Monthly. 59 (8): 521–531. doi:10.2307/2308219. JSTOR 2308219.
  2. ^ Quine, Willard Van Orman (November 1955). "A Way to Simplify Truth Functions". The American Mathematical Monthly. 62 (9): 627–631. doi:10.2307/2307285. hdl:10338.dmlcz/142789. JSTOR 2307285.
  3. ^ McCluskey, Edward Joseph Jr. (November 1956). "Minimization of Boolean Functions". Bell System Technical Journal. 35 (6): 1417–1444. doi:10.1002/j.1538-7305.1956.tb03835.x. hdl:10338.dmlcz/102933. Retrieved 2014-08-24.
  4. ^ McColl, Hugh (1878-11-14). "The Calculus of Equivalent Statements (Third Paper)". Proceedings of the London Mathematical Society. s1-10 (1): 16–28. doi:10.1112/plms/s1-10.1.16.
  5. ^ Ladd, Christine (1883). "On the algebra of logic". In Peirce, Charles Sanders (ed.). Studies in Logic. Boston, USA: Little, Brown & Company. pp. 17–71. p. 23: [...] If the reduction [of an expression to simplest form] is not evident, it may be facilitated by taking the negative of the expression, reducing it, and then restoring it to the positive form. [...]
  6. ^ a b c d Brown, Frank Markham (November 2010) [2010-10-27]. "McColl and Minimization". History and Philosophy of Logic. 31 (4). Taylor & Francis: 337–348. doi:10.1080/01445340.2010.517387. ISSN 1464-5149. S2CID 216590641. Archived from the original on 2020-04-15. Retrieved 2020-04-15.
  7. ^ Blake, Archie (1938) [1937]. Canonical Expressions in Boolean Algebra (Dissertation) (Lithographed ed.). Chicago, Illinois, USA: University of Chicago Libraries. p. 36. p. 36: [...] this method was known to Peirce and his students [...] It is mentioned at several places in Studies in Logic, by members of the Johns Hopkins University, 1883 [...] (ii+60 pages)
  8. ^ Blake, Archie (November 1932). "Canonical expressions in Boolean algebra". Bulletin of the American Mathematical Society. Abstracts of Papers: 805.
  9. ^ Blake, Archie (June 1938). "Corrections to Canonical Expressions in Boolean Algebra". The Journal of Symbolic Logic. 3 (2). Association for Symbolic Logic: 112–113. doi:10.2307/2267595. ISSN 0022-4812. JSTOR 2267595. S2CID 5810863.
  10. ^ Samson, Edward Walter; Mills, Burton E. (April 1954). Circuit Minimization: Algebra and Algorithms for New Boolean Canonical Expressions. Bedford, Massachusetts, USA: Air Force Cambridge Research Center. Technical Report AFCRC TR 54-21.
  11. ^ Nelson, Raymond J. (June 1955). "Simplest Normal Truth Functions". The Journal of Symbolic Logic. 20 (2). Association for Symbolic Logic: 105–108. doi:10.2307/2266893. JSTOR 2266893. S2CID 32920372. (4 pages)
  12. ^ "Welcome to the memorial page for John "Jack" G Nordahl June 14, 1933 ~ November 20, 2017 (age 84)". Jellison Funeral Home and Cremation Services. Archived from the original on 2020-05-05. Retrieved 2020-05-05.
  13. ^ Mullin, Albert Alkins; Kellner, Wayne G. (1958). Written at University of Illinois, Urbana, USA and Electrical Engineering Department, Massachusetts Institute of Technology, Massachusetts, USA. "A Residue Test for Boolean Functions" (PDF). Transactions of the Illinois State Academy of Science (Teaching memorandum). 51 (3–4). Springfield, Illinois, USA: 14–19. S2CID 125171479. Archived (PDF) from the original on 2020-05-05. Retrieved 2020-05-05. [1] (6 pages) (NB. In his book, Caldwell dates this to November 1955 as a teaching memorandum. Since Mullin dates their work to 1958 in another work and Abrahams/Nordahl's class memorandum is also dated November 1955, this could be a copy error.)
  14. ^ a b Caldwell, Samuel Hawks (1958-12-01) [February 1958]. "5.8. Operations Using Decimal Symbols". Written at Watertown, Massachusetts, USA. Switching Circuits and Logical Design. 5th printing September 1963 (1st ed.). New York, USA: John Wiley & Sons Inc. pp. 162–169. ISBN 0-47112969-0. LCCN 58-7896. p. 166: [...] It is a pleasure to record that this treatment is based on the work of two students during the period they were studying Switching Circuits at the Massachusetts Institute of Technology. They discussed the method independently and then collaborated in preparing a class memorandum: P. W. Abraham and J. G. Nordahl [...] (xviii+686 pages) (NB. For the first major treatise of the decimal method in this book, it is sometimes misleadingly known as "Caldwell's decimal tabulation".)
  15. ^ a b Mullin, Albert Alkins (1960-03-15) [1959-09-19]. Written at University of Illinois, Urbana, USA. Fisher, Harvey I.; Ekblaw, George E.; Green, F. O.; Jones, Reece; Kruidenier, Francis; McGregor, John; Silva, Paul; Thompson, Milton (eds.). "Two Applications of Elementary Number Theory" (PDF). Transactions of the Illinois State Academy of Science. 52 (3–4). Springfield, Illinois, USA: 102–103. Archived (PDF) from the original on 2020-05-05. Retrieved 2020-05-05. [2][3][4] (2 pages)
  16. ^ a b McCluskey, Edward Joseph Jr. (June 1960). "Albert A. Mullin and Wayne G. Kellner. A residue test for Boolean functions. Transactions of the Illinois State Academy of Science, vol. 51 nos. 3 and 4, (1958), pp. 14–19". The Journal of Symbolic Logic (Review). 25 (2): 185. doi:10.2307/2964263. JSTOR 2964263. S2CID 123530443. p. 185: [...] The results of this paper are presented in the more readily available book by S. H. Caldwell [...]. In this book, the author gives credit to Mullin and Kellner for development of the manipulations with the decimal numbers. (1 page)
  17. ^ Abrahams, Paul William; Nordahl, John "Jack" G. (November 1955). The Modified Quine–McCluskey Reduction Procedure (Class memorandum). Electrical Engineering Department, Massachusetts Institute of Technology, Massachusetts, USA.{{cite book}}: CS1 maint: location missing publisher (link) (4 pages) (NB. Some sources list the authors as "P. W. Abraham" and "I. G. Nordahl", the title is also cited as "Modified McCluskey–Quine Reduction Procedure".)
  18. ^ Fielder, Daniel C. (December 1966). "Classroom Reduction of Boolean Functions". IEEE Transactions on Education. 9 (4). IEEE: 202–205. Bibcode:1966ITEdu...9..202F. doi:10.1109/TE.1966.4321989. eISSN 1557-9638. ISSN 0018-9359.
  19. ^ Kämmerer, Wilhelm [in German] (May 1969). "I.12. Theorie: Minimierung Boolescher Funktionen". Written at Jena, Germany. In Frühauf, Hans [in German]; Kämmerer, Wilhelm; Schröder, Kurz; Winkler, Helmut (eds.). Digitale Automaten – Theorie, Struktur, Technik, Programmieren. Elektronisches Rechnen und Regeln (in German). Vol. 5 (1 ed.). Berlin, Germany: Akademie-Verlag GmbH. pp. 98, 103–104. License no. 202-100/416/69. Order no. 4666 ES 20 K 3. p. 98: [...] 1955 wurde das Verfahren auf die bequemere dezimale Schreibweise umgestellt (P. W. Abraham und I. G. Nordahl in [Caldwell]). [...] (NB. A second edition 1973 exists as well.)
  20. ^ Holdsworth, Brian; Woods, Clive (2002). "3.17 Decimal approach to Quine–McCluskey simplification of Boolean algebra". Digital Logic Design (4 ed.). Newnes Books / Elsevier Science. pp. 65–67. ISBN 0-7506-4588-2. Retrieved 2020-04-19.{{cite book}}: CS1 maint: ignored ISBN errors (link) (519 pages) [5]
  21. ^ Majumder, Alak; Chowdhury, Barnali; Mondal, Abir J.; Jain, Kunj (2015-01-30) [2015-01-09]. Investigation on Quine McCluskey Method: A Decimal Manipulation Based Novel Approach for the Minimization of Boolean Function. 2015 International Conference on Electronic Design, Computer Networks & Automated Verification (EDCAV), Shillong, India (Conference paper). Department of Electronics & Communication, Engineering National Institute of Technology, Arunachal Pradesh Yupia, India. pp. 18–22. doi:10.1109/EDCAV.2015.7060531. Archived from the original on 2020-05-08. Retrieved 2020-05-08. [6] (NB. This work does not cite the prior art on decimal methods.) (5 pages)
  22. ^ Masek, William J. (1979). Some NP-complete set covering problems. unpublished.
  23. ^ Czort, Sebastian Lukas Arne (1999). The complexity of minimizing disjunctive normal form formulas (Master's thesis). University of Aarhus.
  24. ^ Umans, Christopher; Villa, Tiziano; Sangiovanni-Vincentelli, Alberto Luigi (2006-06-05). "Complexity of two-level logic minimization". IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems. 25 (7): 1230–1246. doi:10.1109/TCAD.2005.855944. S2CID 10187481.
  25. ^ Chandra, Ashok K.; Markowsky, George (1978). "On the number of prime implicants". Discrete Mathematics. 24 (1): 7–11. doi:10.1016/0012-365X(78)90168-1.
  26. ^ Nelson, Victor P.; Nagle, H. Troy; Carroll, Bill D.; Irwin, J. David (1995). Digital Logic Circuit Analysis and Design (2 ed.). Prentice Hall. p. 234. ISBN 978-0-13463894-2. Retrieved 2014-08-26.
  27. ^ Mossé, Milan; Sha, Harry; Tan, Li-Yang (2022). "A Generalization of the Satisfiability Coding Lemma and Its Applications". DROPS-IDN/V2/Document/10.4230/LIPIcs.SAT.2022.9. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.SAT.2022.9.
  28. ^ Feldman, Vitaly (2009). "Hardness of Approximate Two-Level Logic Minimization and PAC Learning with Membership Queries". Journal of Computer and System Sciences. 75: 13–25 [13–14]. doi:10.1016/j.jcss.2008.07.007.
  29. ^ Gimpel, James F. (1965). "A Method for Producing a Boolean Function Having an Arbitrary Prescribed Prime Implicant Table". IEEE Transactions on Computers. 14: 485–488. doi:10.1109/PGEC.1965.264175.
  30. ^ Paul, Wolfgang Jakob [in German] (1974). "Boolesche Minimalpolynome und Überdeckungsprobleme". Acta Informatica (in German). 4 (4): 321–336. doi:10.1007/BF00289615. S2CID 35973949.
  31. ^ Logic Friday program

Further reading

[edit]
[edit]