Quine–McCluskey Solver

Minimise past the K-map limit with the full tabular method and Petrick’s step.

Names are A B C D, most significant first. Exact to 12 variables; the Espresso heuristic to 20, labelled as a heuristic.

Comma-separated indices between 0 and 15.

Optional. Don’t-cares join the merging but are never charted.

Show

Hiding a table recomputes nothing — the whole tabulation arrives in one result.

Start from a worked example

The function being minimised

  • Σm(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) over A B C D
  • ΠM(1, 14, 15)

Minimal forms

Minimal SOP — the walkthrough’s answer

A′ · D′ + A′ · C + B · C′ + A · B′

4 terms · 8 literals · verified exact1 of 6 equally minimal formsPermalink to this form

Nothing is forced — no term appears in all 6 of these covers, so no part of the answer is fixed.

Every minimum cover then makes each of these choices, independently:

  • one of A′ · D′, B′ · D′ or C′ · D′
  • one of A′ · C + B · C′ + A · B′ or B′ · C + A′ · B + A · C′

3 × 2 is the 6 answers above.

Any one of A′ · D′, B′ · D′ or C′ · D′ works here — they cover the same minterms at the same cost, so the choice is free.

Why you can trust the count

Two pipelines run over the same prime-implicant chart. The walkthrough uses essential primes, then minterm (“row”) dominance, then implicant (“column”) dominance, then Petrick’s method — the sequence a textbook shows, which reaches one correct answer.

The list of every minimum cover is produced by a second pipeline that uses essentials and minterm dominance only. Essential-prime extraction is safe for enumeration and minterm dominance is safe; implicant dominance is not — striking out a dominated prime discards every cover that used it, and some of those cost exactly the minimum.

So the walkthrough answers “what is an optimum?” and the list answers “what are all the optima?”. Both are shown because the textbook shows the first and the truth is the second.

Quine–McCluskey tabulation

exact — Quine–McCluskey

Table 1 — Combining rounds

A merge is only legal between adjacent 1-count buckets, only when the dash patterns already match, and only when the fixed bits differ in exactly one place.

Round 0 — minterms — tabulating the ON-set, with the don’t-cares available for merging
ImplicantTermMintermsStatus
zero ones — one implicant
0000A′ · B′ · C′ · D′0combined into the next round
one one — three implicants
0010A′ · B′ · C · D′2combined into the next round
0100A′ · B · C′ · D′4combined into the next round
1000A · B′ · C′ · D′8combined into the next round
two ones — six implicants
0011A′ · B′ · C · D3combined into the next round
0101A′ · B · C′ · D5combined into the next round
0110A′ · B · C · D′6combined into the next round
1001A · B′ · C′ · D9combined into the next round
1010A · B′ · C · D′10combined into the next round
1100A · B · C′ · D′12combined into the next round
three ones — three implicants
0111A′ · B · C · D7combined into the next round
1011A · B′ · C · D11combined into the next round
1101A · B · C′ · D13combined into the next round
Show the 21 merges of round 0
Merges performed in round 0
FromWithGivesTerm
0000001000-0A′ · B′ · D′
000001000-00A′ · C′ · D′
00001000-000B′ · C′ · D′
00100011001-A′ · B′ · C
001001100-10A′ · C · D′
00101010-010B′ · C · D′
01000101010-A′ · B · C′
0100011001-0A′ · B · D′
01001100-100B · C′ · D′
10001001100-A · B′ · C′
1000101010-0A · B′ · D′
100011001-00A · C′ · D′
001101110-11A′ · C · D
00111011-011B′ · C · D
0101011101-1A′ · B · D
01011101-101B · C′ · D
01100111011-A′ · B · C
1001101110-1A · B′ · D
100111011-01A · C′ · D
10101011101-A · B′ · C
11001101110-A · B · C′
Round 1 — pairs (2 minterms each) — tabulating the ON-set, with the don’t-cares available for merging
ImplicantTermMintermsStatus
zero ones — three implicants
00-0A′ · B′ · D′0, 2combined into the next round
0-00A′ · C′ · D′0, 4combined into the next round
-000B′ · C′ · D′0, 8combined into the next round
one one — nine implicants
001-A′ · B′ · C2, 3combined into the next round
0-10A′ · C · D′2, 6combined into the next round
-010B′ · C · D′2, 10combined into the next round
010-A′ · B · C′4, 5combined into the next round
01-0A′ · B · D′4, 6combined into the next round
-100B · C′ · D′4, 12combined into the next round
100-A · B′ · C′8, 9combined into the next round
10-0A · B′ · D′8, 10combined into the next round
1-00A · C′ · D′8, 12combined into the next round
two ones — nine implicants
0-11A′ · C · D3, 7combined into the next round
-011B′ · C · D3, 11combined into the next round
01-1A′ · B · D5, 7combined into the next round
-101B · C′ · D5, 13combined into the next round
011-A′ · B · C6, 7combined into the next round
10-1A · B′ · D9, 11combined into the next round
1-01A · C′ · D9, 13combined into the next round
101-A · B′ · C10, 11combined into the next round
110-A · B · C′12, 13combined into the next round
Show the 18 merges of round 1
Merges performed in round 1
FromWithGivesTerm
00-001-00--0A′ · D′
00-010-0-0-0B′ · D′
0-000-100--0A′ · D′
0-001-00--00C′ · D′
-000-010-0-0B′ · D′
-000-100--00C′ · D′
001-011-0-1-A′ · C
001-101--01-B′ · C
0-100-110-1-A′ · C
-010-011-01-B′ · C
010-011-01--A′ · B
010-110--10-B · C′
01-001-101--A′ · B
-100-101-10-B · C′
100-101-10--A · B′
100-110-1-0-A · C′
10-010-110--A · B′
1-001-011-0-A · C′
Round 2 — quads (4 minterms each) — tabulating the ON-set, with the don’t-cares available for merging
ImplicantTermMintermsStatus
zero ones — three implicants
0--0A′ · D′0, 2, 4, 6prime implicant
-0-0B′ · D′0, 2, 8, 10prime implicant
--00C′ · D′0, 4, 8, 12prime implicant
one one — six implicants
0-1-A′ · C2, 3, 6, 7prime implicant
-01-B′ · C2, 3, 10, 11prime implicant
01--A′ · B4, 5, 6, 7prime implicant
-10-B · C′4, 5, 12, 13prime implicant
10--A · B′8, 9, 10, 11prime implicant
1-0-A · C′8, 9, 12, 13prime implicant

Round 3 is empty — no two quads differ in exactly one position, so every quad is prime.

Table 2 — Prime-implicant chart

Prime-implicant chart — 9 prime implicants against 13 mintermsThis chart draws prime implicants as rows and minterms as columns — the transpose of most textbooks, where "row dominance" means dominance between minterms and "column dominance" means dominance between prime implicants. Each reduction step below prints the textbook name alongside the unambiguous one.Columns are ON-set minterms only. Don’t-cares are never charted: nothing requires them to be covered.
Prime implicantminterm 0minterm 2minterm 3minterm 4minterm 5minterm 6minterm 7minterm 8minterm 9minterm 10minterm 11minterm 12minterm 13
P10--0A′ · D′P1 covers minterm 0P1 covers minterm 2P1 covers minterm 4P1 covers minterm 6
P2-0-0B′ · D′P2 covers minterm 0P2 covers minterm 2P2 covers minterm 8P2 covers minterm 10
P3--00C′ · D′P3 covers minterm 0P3 covers minterm 4P3 covers minterm 8P3 covers minterm 12
P40-1-A′ · CP4 covers minterm 2P4 covers minterm 3P4 covers minterm 6P4 covers minterm 7
P5-01-B′ · CP5 covers minterm 2P5 covers minterm 3P5 covers minterm 10P5 covers minterm 11
P601--A′ · BP6 covers minterm 4P6 covers minterm 5P6 covers minterm 6P6 covers minterm 7
P7-10-B · C′P7 covers minterm 4P7 covers minterm 5P7 covers minterm 12P7 covers minterm 13
P810--A · B′P8 covers minterm 8P8 covers minterm 9P8 covers minterm 10P8 covers minterm 11
P91-0-A · C′P9 covers minterm 8P9 covers minterm 9P9 covers minterm 12P9 covers minterm 13

Table 3 — Chart reduction

Chart reduction — the textbook walkthroughThe P-labels in these sentences number the chart as it stood at that step; the legend beside each step maps them to their terms. Petrick’s product numbers the full chart independently.
StepPassMoveWhyCommittedStruck outMinterms struck
1Row dominanceminterm-dominanceEvery prime implicant that covers the remaining minterms already covers 2, 4, 6, 8, 10, 12, so those columns are struck out — covering the harder minterms covers them for free.2, 4, 6, 8, 10, 12
2Column dominanceimplicant-dominanceP2, P3 cover no minterm that a remaining prime implicant of no greater literal cost does not already cover, so they are struck out.P2 = B′ · D′P3 = C′ · D′
3Secondary essential prime implicantssecondary-essentialMinterm 0 is covered by only one remaining prime implicant, so P1 must be in every cover.P1 = A′ · D′0
4Petrick's methodpetrickThe remaining chart is cyclic: no prime implicant is essential and no row or column dominates another. Petrick's product (P1 + P2)·(P3 + P4)·(P1 + P3)·(P5 + P6)·(P2 + P5)·(P4 + P6) reduces to P1·P4·P5 + P2·P3·P6 + P1·P2·P4·P6 + P1·P3·P5·P6 + P2·P3·P4·P5; the cheapest term is taken.P4 = A′ · CP7 = B · C′P8 = A · B′3, 5, 7, 9, 11, 13
Warning:

This walkthrough reaches one correct answer, not all of them.

Step 2 used column dominance, which is safe when you only want an optimum and unsafe when you want every optimum: striking out a dominated prime discards every cover that used it, and some of those can be minimum-cost. P2 and P3 were struck out here, and they appear in four of this function’s six minimum covers. The complete list of equally minimal forms is produced by a second pipeline that uses essentials and row dominance only. Both are shown because the textbook shows the first and the truth is the second.

Essential-prime extraction is safe for enumeration, and row (minterm) dominance is safe. Column (implicant) dominance is not, and it is used only here in the walkthrough.

Table 4 — Petrick’s product

1. The product of sums — one factor per minterm still to be covered

(P4 + P5)·(P6 + P7)·(P4 + P6)·(P8 + P9)·(P5 + P8)·(P7 + P9)·(P1 + P2 + P3)

  • P1 = A′ · D′
  • P2 = B′ · D′
  • P3 = C′ · D′
  • P4 = A′ · C
  • P5 = B′ · C
  • P6 = A′ · B
  • P7 = B · C′
  • P8 = A · B′
  • P9 = A · C′

2. The fold, factor by factor

Absorption happens inside the loop: after each factor the antichain keeps only the ⊆-minimal products, so the expansion below never materialises.

Expanding the product and absorbing afterwards would have had to materialise 192 terms; folding one factor at a time, the largest antichain this fold ever held was 15.

Petrick’s fold — the antichain after each factor
Factor folded inProducts after foldingCount
minterm m3P4 + P52
minterm m5P4·P6 + P4·P7 + P5·P6 + P5·P74
minterm m7P4·P6 + P4·P7 + P5·P63
minterm m9P4·P6·P8 + P4·P6·P9 + P4·P7·P8 + P4·P7·P9 + P5·P6·P8 + P5·P6·P96
minterm m11P4·P6·P8 + P4·P7·P8 + P5·P6·P8 + P5·P6·P9 + P4·P5·P7·P95
minterm m13P4·P7·P8 + P5·P6·P9 + P4·P6·P8·P9 + P5·P6·P7·P8 + P4·P5·P7·P95
minterm m0P1·P4·P7·P8 + P2·P4·P7·P8 + P3·P4·P7·P8 + P1·P5·P6·P9 + P2·P5·P6·P9 + P3·P5·P6·P9 + P1·P4·P6·P8·P9 + P2·P4·P6·P8·P9 + P3·P4·P6·P8·P9 + P1·P5·P6·P7·P8 + P2·P5·P6·P7·P8 + P3·P5·P6·P7·P8 + P1·P4·P5·P7·P9 + P2·P4·P5·P7·P9 + P3·P4·P5·P7·P915

3. The sum of products after absorption

Every term here is an irredundant cover. The 6 highlighted terms use the fewest prime implicants.

P1·P4·P7·P8 (fewest prime implicants)P1·P5·P6·P9 (fewest prime implicants)P2·P4·P7·P8 (fewest prime implicants)P2·P5·P6·P9 (fewest prime implicants)P3·P4·P7·P8 (fewest prime implicants)P3·P5·P6·P9 (fewest prime implicants)P1·P4·P5·P7·P9P1·P4·P6·P8·P9P1·P5·P6·P7·P8P2·P4·P5·P7·P9P2·P4·P6·P8·P9P2·P5·P6·P7·P8P3·P4·P5·P7·P9P3·P4·P6·P8·P9P3·P5·P6·P7·P8

4. The selection — fewest terms first, fewest literals as the tie-break

Six terms have four prime implicants; none has fewer.

Among those six, all cost eight literals, so all six are minimum.

Notation and operator precedence used here

Products are written A · B, sums A + B, and a complement carries a prime: A′ · D′. In a cube pattern a - marks a position the implicant does not depend on, so 0--0 over A B C D is A′ · D′.

Bit order. The variable list is most-significant-bit first, so over A B C D minterm 9 is A=1, B=0, C=0, D=1. Reordering the variables renumbers every minterm.

Chart orientation. This page draws prime implicants as rows and minterms as columns. Most textbooks draw it the other way up, so their “row dominance” is dominance between minterms and their “column dominance” is dominance between prime implicants. Each reduction step is therefore named twice: once for what actually dominates, and once with the textbook label.

Precedence in the expression field. ( ) → NOT → AND (including juxtaposition) → XOR / XNOR → NAND / NOR → OR → IMPLIES → IFF, with the fully parenthesised reading echoed back.

The algorithm, in the order the tables show it

  1. Combine minterms that differ in exactly one bit, round after round, until nothing combines. What survives uncombined is prime.
  2. Chart the primes against the ON-set minterms.
  3. Take the primes that uniquely cover something — the essentials — and strike out what they cover.
  4. Reduce what is left by dominance.
  5. Solve whatever remains — the cyclic core— with Petrick's method.
  6. Among the irredundant covers that produces, take the cheapest.

A merge is legal only between adjacent 1-count buckets, only when the dash patterns already match, and only when the fixed bits differ in exactly one place. “Merging 0011 with 1100” is the standard first mistake, and the caption of the first table says so.

Why don’t-cares go into the merging but not into the chart

They may be used to build bigger primes, because you are free to read them as 1. They must not appear as chart columns, because nothing requires them to be covered. The corollary is a filter: a prime that covers no ON-set minterm is discarded before the chart is built, and this page shows the discards in a dimmed block rather than dropping them silently — including them in the chart is a known bug in the popular npm implementations.

Prime, essential, irredundant, minimum

A distinguishing cell makes a prime essential: it is a minterm that only that prime covers, and the chart rings it. An irredundant cover is one where no term can be deleted. A minimum cover is one no cover beats on cost. An irredundant cover can be strictly worse than the minimum, which is why the two words are not interchangeable.

Petrick’s method without the explosion

Expanding the product of k sums and absorbing afterwards materialises up to n₁·n₂·…·nk terms before anything cancels. Folding one factor at a time and keeping only the ⊆-minimal products applies absorption inside the loop, and Table 4 prints both numbers — the size the expansion would have reached against the largest antichain the fold actually held. Because every cost here is strictly positive, a minimum-cost cover is necessarily irredundant, so the antichain provably contains it; that is why the fold is sound for literal cost too and not only for term count.

Column dominance destroys alternative answers

This page opens on Σm(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) over A B C D: 9 prime implicants, none of them essential, and 6 minimum covers, provably the complete set — minimal SOP A′ · D′ + A′ · C + B · C′ + A · B′, minimal POS (A + B + C + D′) · (A′ + B′ + C′). Those numbers are computed by the engine at build time.

The published handout this function comes from reports two. It is not wrong; it answered a different question. Its reduction applies column dominance, which is safe when you want an optimum and unsafe when you want every optimum: striking out a dominated prime discards every cover that used it, and some of those cost exactly the minimum. So this page runs two pipelines — the textbook walkthrough for the tables, and essentials plus row dominance only for the list of covers — and labels which is which.

One more guard, and it is a silent-wrong-answer bug in several published implementations: a dominated prime may only be struck out when the dominating one costs no more. That condition is vacuous under term-count cost and mandatory under literal cost.

K-map or Quine–McCluskey?

They compute the same thing. The map is faster to read and stops at six variables; the tables scale, are mechanical, and are what an algorithm can execute. A group on a map is a prime implicant, and the largest legal rectangle is a maximal cube. The Karnaugh map solver draws the same functions this page tabulates.

Limits, stated plainly

Exact to 8 variables on the main thread and to 12 in a solve you can cancel; the Espresso heuristic to 20, badged near-minimal (Espresso heuristic) rather than exact, with the combining and chart tables replaced by a note saying why they do not exist on that path; refused above 20, with the reason in text. Worst-case prime count is Θ(3ⁿ/√n) and cover selection is NP-hard, which is why the thresholds exist. Equally minimal covers are enumerated to 200 and displayed to 200, and the badge says so when a cap is reached rather than printing a count nothing proved.

How this page is tested

The minimiser is checked exhaustively against brute force for every function of up to four variables and by randomised differential testing above that, matching on both cost and the number of distinct minimum covers. It independently reproduces three published reference results: Petrick's own example (2 covers), the Columbia handout's Example #2 (6 covers, against the handout's 2), and Σm(4, 5, 7, 8, 9, 11, 12, 14) (4 covers). Publishing the test regime is this page's alternative to the incumbents' disclaimers.

Worked examples

Sources

  • Quine, Willard V. “The Problem of Simplifying Truth Functions.” The American Mathematical Monthly 59, no. 8 (October 1952): 521–531. doi:10.2307/2308219.
  • Quine, Willard V. “A Way to Simplify Truth Functions.” The American Mathematical Monthly 62, no. 9 (November 1955): 627–631. doi:10.2307/2307285.
  • McCluskey, Edward J. “Minimization of Boolean Functions.” The Bell System Technical Journal 35, no. 6 (November 1956): 1417–1444. doi:10.1002/j.1538-7305.1956.tb03835.x.
  • Petrick, Stanley R. A Direct Determination of the Irredundant Forms of a Boolean Function from the Set of Prime Implicants. Technical Report AFCRC-TR-56-110. Bedford, MA: Air Force Cambridge Research Center, April 1956.
  • Chandra, Ashok K., and George Markowsky. “On the Number of Prime Implicants.” Discrete Mathematics 24, no. 1 (1978): 7–11. doi:10.1016/0012-365X(78)90168-1.
  • Brayton, Robert K., Gary D. Hachtel, Curtis T. McMullen, and Alberto L. Sangiovanni-Vincentelli. Logic Minimization Algorithms for VLSI Synthesis. Boston: Kluwer Academic, 1984 — Espresso, and the exact-mode objective this page adopts.
  • Rudell, Richard L., and Alberto L. Sangiovanni-Vincentelli. “Multiple-Valued Minimization for PLA Optimization.” IEEE Transactions on Computer-Aided Design 6, no. 5 (September 1987): 727–750. doi:10.1109/TCAD.1987.1270318.
  • Karnaugh, Maurice. “The Map Method for Synthesis of Combinational Logic Circuits.” Transactions of the AIEE, Part I 72, no. 5 (November 1953): 593–599. doi:10.1109/TCE.1953.6371932.