Computer science

Truth Table Generator

Type a Boolean expression in the notation you use in class (A·B + C', !A & B, p → q…) and get the truth table and canonical forms.

Examples:

How to type your expression

Variables are single letters (A, B, C… or p, q, r). The generator accepts the most common notations from digital electronics, logic and programming:

OperationYou can typeExample
NOTA' !A ~A ¬A(A+B)'
ANDA·B A*B A&B A∧B ABAB'C
ORA+B A|B A∨BA + BC
XORA^B A⊕BA ⊕ B ⊕ C
ImplicationA->B A=>B A→Bp → q
Equivalence (XNOR)A<->B A↔B A≡Bp ↔ q

Operator precedence, from highest to lowest: NOT, AND, XOR, OR, implication and equivalence. Writing two variables side by side means AND (AB = A·B). When in doubt, use parentheses.

How a truth table is built

With n variables there are 2n possible combinations. They are listed in binary order (000, 001, 010…) and the expression is evaluated for each row. Intermediate columns make it harder to slip up: negations first, then products, then sums.

Example · F = A·B + C'

With 3 variables there are 8 rows. A·B is 1 only in rows 6 and 7 (A = B = 1) and C' is 1 when C = 0, that is, in rows 0, 2, 4 and 6. Adding them: F = Σm(0, 2, 4, 6, 7) and therefore F = ΠM(1, 3, 5).

Minterms, maxterms and canonical forms

A minterm is a product containing every variable (complemented or not) that is 1 in exactly one row. Adding the minterms of the rows where the function is 1 gives the canonical sum of products (SOP). A maxterm is the sum that is 0 in exactly one row; multiplying the maxterms of the rows where the output is 0 gives the canonical product of sums (POS). Both describe the same function, but they are rarely the shortest: to simplify them use the Karnaugh map solver.

Watch the convention: in a minterm a variable appears uncomplemented if it is 1 in that row; in a maxterm it is the other way round, complemented if it is 1.

Frequently asked questions

How do I check whether two expressions are equivalent?

Type (expression 1) ↔ (expression 2). If every row is 1 (a tautology), they are equivalent. Try the De Morgan example.

What are a tautology and a contradiction?

A tautology is 1 for every input combination; a contradiction is always 0. If it is neither, the expression is called contingent.

Why is A → B true when A is 0?

An implication is only false when the premise is true and the conclusion is false. If the premise is false the implication is not broken, so it counts as true. It is equivalent to A' + B.

How many variables can I use?

Up to 10, which gives 1,024 rows. For 2 to 4 variables you can jump straight to the Karnaugh map to get the minimal expression.

More computer science tools