Tools

K-Map Solver

Enter a function as minterms, as a Boolean expression or by clicking a truth table. The map shows the groups, and the page gives the minimal sum of products and product of sums, the prime implicants and the essential ones, with each group explained step by step.

The tool

How it works

From a function to a map

A Karnaugh map is a truth table folded into a grid so that neighbouring cells differ in exactly one variable. The rows and columns are labelled in Gray code (00, 01, 11, 10) for that reason. The map also wraps around: the left edge touches the right edge, and the top touches the bottom.

Variable A is the most significant bit of a cell number, so with three variables cell 5 is 101: A=1, B=0, C=1. Five variables are shown as two four-variable maps, one for A=0 and one for A=1, and cells in the same place on the two maps are neighbours.

How the groups are found

The solver uses the Quine-McCluskey method, which does by table what you do by eye. It writes each cell in binary and joins two cells that differ in one bit, replacing that bit with a dash. It repeats on the new groups until none can join. A group that cannot join any further is a prime implicant. Don't cares are allowed inside groups to make them bigger, but they never have to be covered.

A prime implicant is essential if it is the only one holding some cell. Those must be in the answer. The remaining cells are covered with the fewest extra groups, and when two choices tie the fewest literals decides. If still tied, one of the equally good answers is shown; there can be more than one minimal answer.

Sum of products and product of sums

Grouping the 1s gives a sum of products (SOP): each group is an AND term, and the terms are ORed. Grouping the 0s gives a product of sums (POS): each group of 0s is written as an OR term with its literals flipped, and the terms are ANDed. Both describe the same function.

Expressions are read with NOT first, then AND, then XOR, then OR. Write A B, A*B or AB for AND, A + B for OR, A' or NOT A for NOT, and use brackets when in doubt. NAND, NOR and XNOR are read left to right, so bracket them when you chain more than two.

Questions

Why are the K-map rows and columns in Gray code?

So that cells next to each other differ in only one variable. Two such cells can be joined into a group, and the variable that differs drops out of the term. In ordinary binary order, 01 and 10 are next to each other but differ in two bits, which would break the rule.

Why must a group have 1, 2, 4, 8 or 16 cells?

Each time two equal groups join, one variable drops out, so group sizes double: a group of 2^k cells removes k variables. A group of 3 or 5 cannot remove a whole number of variables, so it is never a single term.

What is a don't care and how is it used?

A don't care (X) is an input that never happens, or one whose output does not matter. The solver may treat it as a 1 when that makes a group bigger, and ignore it otherwise. It never forces an extra group.

What is the difference between SOP and POS?

SOP groups the 1s of the function and ORs product terms, like AB' + C. POS groups the 0s and ANDs sum terms, like (A + B')(C). Both equal the same function. NAND-only circuits suit SOP and NOR-only circuits suit POS.

What is an essential prime implicant?

A prime implicant is a group that cannot be made any bigger. It is essential if it is the only group that holds some 1, so the answer cannot leave it out. The solver always starts with the essential ones.

Learn the idea behind it

The tool is easier to use once you know what it is doing. These courses and lessons teach it from the start: the Digital Logic course, the Computer Architecture course and the Computer Networks course.

  • Karnaugh maps (Digital Logic)Simplify a function by eye: arrange its truth table so that neighbours differ in one variable, then circle groups of 1s.
  • Minterms, maxterms and canonical forms (Digital Logic)Turn any truth table into a formula: a sum of minterms (SOP) from its 1s, or a product of maxterms (POS) from its 0s.
  • Boolean algebra (Digital Logic)The laws of Boolean algebra, De Morgan's laws, simplifying expressions by hand, and proving any identity with a truth table.
  • Designing a combinational circuit (Digital Logic)From a problem in words to a circuit: inputs and outputs, a truth table, a Karnaugh map, the gates, and the circuit's delay.

More tools