Digital Logic Toolkit — Quine–McCluskey solver
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.
Start from a worked example
- F(A,B,C) = Σm(0,1,2,5,6,7)intro6 prime implicants, 0 essential, 2 minimal covers
- F(A,B,C,D) = Σm(0,2,5,6,7,8,10,12,13,14,15)intro6 prime implicants, 2 essential, 4 minimal covers
- F(A,B,C,D) = Σm(4,8,10,11,12,15) + d(9,14)core4 prime implicants, 2 essential, 2 minimal covers
- F(A,B,C,D) = Σm(0,5,7,8,9,10,11,14,15)core5 prime implicants, 4 essential
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′
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′orC′ · D′ - one of
A′ · C + B · C′ + A · B′orB′ · 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.
| Form | Terms | Literals | Gate inputs | NAND-only gates |
|---|---|---|---|---|
| A′ · D′ + A′ · C + B · C′ + A · B′ | 4 | 8 | 12 | 13 |
| A′ · D′ + B′ · C + A′ · B + A · C′ | 4 | 8 | 12 | 13 |
| B′ · D′ + A′ · C + B · C′ + A · B′ | 4 | 8 | 12 | 13 |
| B′ · D′ + B′ · C + A′ · B + A · C′ | 4 | 8 | 12 | 13 |
| C′ · D′ + A′ · C + B · C′ + A · B′ | 4 | 8 | 12 | 13 |
| C′ · D′ + B′ · C + A′ · B + A · C′ | 4 | 8 | 12 | 13 |
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–McCluskeyTable 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.
| Implicant | Term | Minterms | Status |
|---|---|---|---|
| zero ones — one implicant | |||
| 0000 | A′ · B′ · C′ · D′ | 0 | combined into the next round |
| one one — three implicants | |||
| 0010 | A′ · B′ · C · D′ | 2 | combined into the next round |
| 0100 | A′ · B · C′ · D′ | 4 | combined into the next round |
| 1000 | A · B′ · C′ · D′ | 8 | combined into the next round |
| two ones — six implicants | |||
| 0011 | A′ · B′ · C · D | 3 | combined into the next round |
| 0101 | A′ · B · C′ · D | 5 | combined into the next round |
| 0110 | A′ · B · C · D′ | 6 | combined into the next round |
| 1001 | A · B′ · C′ · D | 9 | combined into the next round |
| 1010 | A · B′ · C · D′ | 10 | combined into the next round |
| 1100 | A · B · C′ · D′ | 12 | combined into the next round |
| three ones — three implicants | |||
| 0111 | A′ · B · C · D | 7 | combined into the next round |
| 1011 | A · B′ · C · D | 11 | combined into the next round |
| 1101 | A · B · C′ · D | 13 | combined into the next round |
Show the 21 merges of round 0
| From | With | Gives | Term |
|---|---|---|---|
| 0000 | 0010 | 00-0 | A′ · B′ · D′ |
| 0000 | 0100 | 0-00 | A′ · C′ · D′ |
| 0000 | 1000 | -000 | B′ · C′ · D′ |
| 0010 | 0011 | 001- | A′ · B′ · C |
| 0010 | 0110 | 0-10 | A′ · C · D′ |
| 0010 | 1010 | -010 | B′ · C · D′ |
| 0100 | 0101 | 010- | A′ · B · C′ |
| 0100 | 0110 | 01-0 | A′ · B · D′ |
| 0100 | 1100 | -100 | B · C′ · D′ |
| 1000 | 1001 | 100- | A · B′ · C′ |
| 1000 | 1010 | 10-0 | A · B′ · D′ |
| 1000 | 1100 | 1-00 | A · C′ · D′ |
| 0011 | 0111 | 0-11 | A′ · C · D |
| 0011 | 1011 | -011 | B′ · C · D |
| 0101 | 0111 | 01-1 | A′ · B · D |
| 0101 | 1101 | -101 | B · C′ · D |
| 0110 | 0111 | 011- | A′ · B · C |
| 1001 | 1011 | 10-1 | A · B′ · D |
| 1001 | 1101 | 1-01 | A · C′ · D |
| 1010 | 1011 | 101- | A · B′ · C |
| 1100 | 1101 | 110- | A · B · C′ |
| Implicant | Term | Minterms | Status |
|---|---|---|---|
| zero ones — three implicants | |||
| 00-0 | A′ · B′ · D′ | 0, 2 | combined into the next round |
| 0-00 | A′ · C′ · D′ | 0, 4 | combined into the next round |
| -000 | B′ · C′ · D′ | 0, 8 | combined into the next round |
| one one — nine implicants | |||
| 001- | A′ · B′ · C | 2, 3 | combined into the next round |
| 0-10 | A′ · C · D′ | 2, 6 | combined into the next round |
| -010 | B′ · C · D′ | 2, 10 | combined into the next round |
| 010- | A′ · B · C′ | 4, 5 | combined into the next round |
| 01-0 | A′ · B · D′ | 4, 6 | combined into the next round |
| -100 | B · C′ · D′ | 4, 12 | combined into the next round |
| 100- | A · B′ · C′ | 8, 9 | combined into the next round |
| 10-0 | A · B′ · D′ | 8, 10 | combined into the next round |
| 1-00 | A · C′ · D′ | 8, 12 | combined into the next round |
| two ones — nine implicants | |||
| 0-11 | A′ · C · D | 3, 7 | combined into the next round |
| -011 | B′ · C · D | 3, 11 | combined into the next round |
| 01-1 | A′ · B · D | 5, 7 | combined into the next round |
| -101 | B · C′ · D | 5, 13 | combined into the next round |
| 011- | A′ · B · C | 6, 7 | combined into the next round |
| 10-1 | A · B′ · D | 9, 11 | combined into the next round |
| 1-01 | A · C′ · D | 9, 13 | combined into the next round |
| 101- | A · B′ · C | 10, 11 | combined into the next round |
| 110- | A · B · C′ | 12, 13 | combined into the next round |
Show the 18 merges of round 1
| From | With | Gives | Term |
|---|---|---|---|
| 00-0 | 01-0 | 0--0 | A′ · D′ |
| 00-0 | 10-0 | -0-0 | B′ · D′ |
| 0-00 | 0-10 | 0--0 | A′ · D′ |
| 0-00 | 1-00 | --00 | C′ · D′ |
| -000 | -010 | -0-0 | B′ · D′ |
| -000 | -100 | --00 | C′ · D′ |
| 001- | 011- | 0-1- | A′ · C |
| 001- | 101- | -01- | B′ · C |
| 0-10 | 0-11 | 0-1- | A′ · C |
| -010 | -011 | -01- | B′ · C |
| 010- | 011- | 01-- | A′ · B |
| 010- | 110- | -10- | B · C′ |
| 01-0 | 01-1 | 01-- | A′ · B |
| -100 | -101 | -10- | B · C′ |
| 100- | 101- | 10-- | A · B′ |
| 100- | 110- | 1-0- | A · C′ |
| 10-0 | 10-1 | 10-- | A · B′ |
| 1-00 | 1-01 | 1-0- | A · C′ |
| Implicant | Term | Minterms | Status |
|---|---|---|---|
| zero ones — three implicants | |||
| 0--0 | A′ · D′ | 0, 2, 4, 6 | prime implicant |
| -0-0 | B′ · D′ | 0, 2, 8, 10 | prime implicant |
| --00 | C′ · D′ | 0, 4, 8, 12 | prime implicant |
| one one — six implicants | |||
| 0-1- | A′ · C | 2, 3, 6, 7 | prime implicant |
| -01- | B′ · C | 2, 3, 10, 11 | prime implicant |
| 01-- | A′ · B | 4, 5, 6, 7 | prime implicant |
| -10- | B · C′ | 4, 5, 12, 13 | prime implicant |
| 10-- | A · B′ | 8, 9, 10, 11 | prime implicant |
| 1-0- | A · C′ | 8, 9, 12, 13 | prime 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 | minterm 0 | minterm 2 | minterm 3 | minterm 4 | minterm 5 | minterm 6 | minterm 7 | minterm 8 | minterm 9 | minterm 10 | minterm 11 | minterm 12 | minterm 13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| P10--0A′ · D′ | P1 covers minterm 0 | P1 covers minterm 2 | P1 covers minterm 4 | P1 covers minterm 6 | |||||||||
| P2-0-0B′ · D′ | P2 covers minterm 0 | P2 covers minterm 2 | P2 covers minterm 8 | P2 covers minterm 10 | |||||||||
| P3--00C′ · D′ | P3 covers minterm 0 | P3 covers minterm 4 | P3 covers minterm 8 | P3 covers minterm 12 | |||||||||
| P40-1-A′ · C | P4 covers minterm 2 | P4 covers minterm 3 | P4 covers minterm 6 | P4 covers minterm 7 | |||||||||
| P5-01-B′ · C | P5 covers minterm 2 | P5 covers minterm 3 | P5 covers minterm 10 | P5 covers minterm 11 | |||||||||
| P601--A′ · B | P6 covers minterm 4 | P6 covers minterm 5 | P6 covers minterm 6 | P6 covers minterm 7 | |||||||||
| P7-10-B · C′ | P7 covers minterm 4 | P7 covers minterm 5 | P7 covers minterm 12 | P7 covers minterm 13 | |||||||||
| P810--A · B′ | P8 covers minterm 8 | P8 covers minterm 9 | P8 covers minterm 10 | P8 covers minterm 11 | |||||||||
| P91-0-A · C′ | P9 covers minterm 8 | P9 covers minterm 9 | P9 covers minterm 12 | P9 covers minterm 13 |
Table 3 — Chart reduction
| Step | Pass | Move | Why | Committed | Struck out | Minterms struck |
|---|---|---|---|---|---|---|
| 1 | Row dominanceminterm-dominance | Every 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 | |||
| 2 | Column dominanceimplicant-dominance | P2, 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′ | — | ||
| 3 | Secondary essential prime implicantssecondary-essential | Minterm 0 is covered by only one remaining prime implicant, so P1 must be in every cover. | P1 = A′ · D′ | 0 | ||
| 4 | Petrick's methodpetrick | The 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 |
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.
| Factor folded in | Products after folding | Count |
|---|---|---|
| minterm m3 | P4 + P5 | 2 |
| minterm m5 | P4·P6 + P4·P7 + P5·P6 + P5·P7 | 4 |
| minterm m7 | P4·P6 + P4·P7 + P5·P6 | 3 |
| minterm m9 | P4·P6·P8 + P4·P6·P9 + P4·P7·P8 + P4·P7·P9 + P5·P6·P8 + P5·P6·P9 | 6 |
| minterm m11 | P4·P6·P8 + P4·P7·P8 + P5·P6·P8 + P5·P6·P9 + P4·P5·P7·P9 | 5 |
| minterm m13 | P4·P7·P8 + P5·P6·P9 + P4·P6·P8·P9 + P5·P6·P7·P8 + P4·P5·P7·P9 | 5 |
| minterm m0 | P1·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·P9 | 15 |
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
- Combine minterms that differ in exactly one bit, round after round, until nothing combines. What survives uncombined is prime.
- Chart the primes against the ON-set minterms.
- Take the primes that uniquely cover something — the essentials — and strike out what they cover.
- Reduce what is left by dominance.
- Solve whatever remains — the cyclic core— with Petrick's method.
- 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
Worked examples
- F(A,B,C) = Σm(0,1,2,5,6,7)intro6 prime implicants, 0 essential, 2 minimal covers
- F(A,B,C,D) = Σm(0,2,5,6,7,8,10,12,13,14,15)intro6 prime implicants, 2 essential, 4 minimal covers
- F(A,B,C,D) = Σm(4,8,10,11,12,15) + d(9,14)core4 prime implicants, 2 essential, 2 minimal covers
- F(A,B,C,D) = Σm(0,5,7,8,9,10,11,14,15)core5 prime implicants, 4 essential
- F(A,B,C,D) = Σm(2,3,7,9,11,13)core5 prime implicants, 3 essential, 2 minimal covers
- F(A,B,C,D) = Σm(0,1,3,7,8,9,11,15)exam3 prime implicants, 2 essential
- F(A,B,C,D,E) = Σm(0,1,4,5,16,17,21,25,29)exam4 prime implicants, 3 essential
- F(A,B,C,D,E,F) = Σm(0,2,8,10,16,18,24,26,32,34,40,42,48,50,56,58)edge case1 prime implicants, 1 essential
Related
- Karnaugh map solver — the same minimisation, drawn
- Boolean algebra simplifier — the named-law path to this answer
- SOP and POS canonical forms — minterms, maxterms, and the OFF-set this page tabulates for POS
- Truth table generator — where the minterm list comes from
- The adjacency law — the law each merge applies
- Logic gate diagram builder — build the minimised circuit
- Universal gates — gate counts for each of the alternative covers
- De Morgan's laws — how each OFF-set cube becomes a sum term
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.