Truth Table to Expression Generator

Click the output column into the shape you need and the tool reads the formula back off it: the canonical DNF (sum of products), the canonical CNF (product of sums), and the shortest equivalent form. Everything runs in your browser, and the table you build travels in the link.

Variables: p, q
pqOutput

Click on the output values to toggle between true (⊤) and false (⊥)

Generated Expression

Disjunctive Normal Form (Sum of Products)
(p ∧ ¬q) ∨ (¬p ∧ q)

How to convert a truth table into a Boolean expression

Every truth table is the truth table of some formula, and two of those formulas can be read straight off it - no algebra and no guesswork:

  1. Write out all 2ⁿ rows for your n variables and mark the ones where the output is ⊤.
  2. For each ⊤ row write a minterm: every variable conjoined, negated where the row makes it false. Disjoin the minterms and you have the DNF.
  3. For each ⊥ row write a maxterm: every variable disjoined, negated where the row makes it true. Conjoin the maxterms and you have the CNF.
  4. Both formulas have exactly the table you started from, so either is a correct answer. Minimize afterwards if you want the shortest one.

Minterm

A conjunction of every variable, each negated or not, that is true in exactly one row of the table. The DNF is the disjunction of the minterms of the rows where the output is ⊤, which is why it has one term per ⊤ row.

Maxterm

A disjunction of every variable, each negated or not, that is false in exactly one row of the table. The CNF is the conjunction of the maxterms of the rows where the output is ⊥, which is why it has one term per ⊥ row.

Worked example: exclusive or

The table above is the one the tool opens with: p and q, true in exactly the two rows where the inputs differ.

  • Two rows are ⊤, so the DNF has two minterms: (p ∧ ¬q) ∨ (¬p ∧ q)
  • The other two rows are ⊥, so the CNF has two maxterms: (p ∨ q) ∧ (¬p ∨ ¬q)

Neither can be shortened - exclusive or genuinely needs both terms - which is worth seeing once: the canonical form is not always the long way round. A table like "at most one of p, q, r" is where the minimal form pulls well ahead.

Understanding Boolean Synthesis

Disjunctive Normal Form (DNF)

DNF represents a formula as an OR of ANDs (sum of products). For each row where the output is true, we create a minterm that ANDs together all variables, negating those that are false. These minterms are then ORed together to form the complete expression.

Conjunctive Normal Form (CNF)

CNF represents a formula as an AND of ORs (product of sums). For each row where the output is false, we create a maxterm that ORs together all variables, negating those that are true. These maxterms are then ANDed together to form the complete expression.

DNF and CNF compared

AspectDisjunctive Normal Form (Sum of Products)Conjunctive Normal Form (Product of Sums)
Built fromThe rows where the output is ⊤, one minterm eachThe rows where the output is ⊥, one maxterm each
ShapeA disjunction of conjunctions: an OR of ANDsA conjunction of disjunctions: an AND of ORs
Reach for it whenYou want to enumerate the cases that make the formula true, or lay out an AND-OR circuitYou want the constraints that all have to hold at once, or the clause form a SAT solver expects

How big does the table get?

A function of n variables has 2ⁿ rows, so the table doubles with every variable you add: 4 rows for two variables, 8 for three, 16 for four and 32 for five, which is where this tool stops. The DNF takes one term per ⊤ row and the CNF one per ⊥ row, so between them they account for every row exactly once - and one of the two is always the shorter starting point.

Applications of Truth Table Synthesis

Converting truth tables to logical expressions is a fundamental technique in computer science and digital electronics. This tool helps with:

  • Digital circuit design - Create Boolean equations for logic gates from desired input-output behavior
  • Software development - Generate conditional logic from specification tables
  • Academic studies - Learn and practice Boolean algebra and propositional logic
  • Logic optimization - Compare DNF and CNF forms to find simpler equivalent expressions

Frequently Asked Questions

Find answers to common questions about using the Logic Calculator

What does the truth table to expression tool do?

It runs the calculator backwards. You set the output column of a truth table by clicking each row, and it produces a formula with exactly that truth table, in disjunctive normal form (an OR of ANDs) or conjunctive normal form (an AND of ORs).

What is the difference between DNF and CNF?

DNF is a sum of products: one conjunction for each row where the output is true, all ORed together. CNF is a product of sums: one disjunction for each row where the output is false, all ANDed together. Both describe the same function, so the one to prefer is whichever is shorter for your table — a mostly-false column gives a short DNF, a mostly-true one a short CNF.

How many variables can the synthesis tool take?

Up to five, which is a table of 32 rows. Each variable you add doubles the rows, and beyond five the table stops being something anyone can set by hand.

Why is the generated expression so long?

A normal form is built row by row, one full-width term for every row it has to cover, so its length follows the truth table rather than the idea behind it. It is correct by construction rather than compact. To shorten it, open it in the calculator, which lists equivalent forms including a minimized DNF.

Can I get a simplified version of a formula?

Yes. Enter it in the calculator and look at the equivalent forms below the truth table. They include forms derived by rewriting with the algebraic laws, and the DNF and CNF read back off the truth table together with a minimized DNF.

See all questions