BL2.ru

Truth Table Generator: Build a Table from a Formula

Enter a logical formula and the calculator builds its truth table step by step, with a separate column for every subformula, and finds the canonical DNF and CNF. At the bottom there is a helper for task 2 of the Russian EGE exam: it finds which variable belongs to which column of a table fragment.

Type symbols as in a textbook or with the keyboard. NOT: ¬, !, ~, not. AND: ∧, &, *, and. OR: ∨, +, or. Implication: →, ->, =>. Equivalence: ≡, ↔, ==, <->. XOR: ⊕, ^, xor. Constants 0 and 1. Priority: NOT, AND, XOR, OR, implication, equivalence. Up to 6 variables.
Calculate

What a truth table is

A truth table lists every combination of values of the variables of a logical formula and the value of the formula for each. For n variables there are 2n rows: two variables give 4 rows, three give 8, four give 16. Values are written as 0 (false) and 1 (true), and the combinations are listed as binary numbers in ascending order: 000, 001, 010 and so on.

Logical operations

OperationNotationEquals 1 when
Negation (NOT)¬AA = 0
Conjunction (AND)A ∧ Bboth are 1
Disjunction (OR)A ∨ Bat least one is 1
ImplicationA → Balways, except A = 1 and B = 0
EquivalenceA ≡ Bthe values are equal
Exclusive ORA ⊕ Bthe values differ

To remember implication: truth never implies falsehood, so 1 → 0 = 0 and every other case gives 1. Useful identities: A → B = ¬A ∨ B, A ≡ B = (A → B) ∧ (B → A), A ⊕ B = ¬(A ≡ B).

Operator priority

Negation goes first, then AND, XOR, OR, implication and finally equivalence. Equal operations run left to right, but implication runs right to left: A → B → C means A → (B → C). When in doubt, add brackets: the calculator shows the formula in a normal form with the minimum of brackets.

Building a table by hand

  1. List the variables and count the rows: 2n.
  2. Split the formula into steps by priority and make a column for each.
  3. Fill the variable columns by binary counting: the last variable alternates 0 and 1, the previous one goes 00 11, and so on.
  4. Compute the columns from left to right using the ready ones.
  5. The last column is the value of the formula.

Canonical DNF and CNF

Any formula can be written in a standard form read off its truth table. For the DNF take the rows with F = 1: from each build the AND of all variables (negating those equal to 0) and join them with OR. For the CNF take the rows with F = 0: from each build the OR of all variables (negating those equal to 1) and join them with AND. These forms are unique for a given function, so they can be used to check whether two formulas are equivalent.

EGE informatics task 2

The task gives a formula and a table fragment in which it is unknown which column belongs to which variable. It is solved by trying rows: for example, if a row with F = 0 is given for an implication A → B, then A = 1 and B = 0, which pins down the column with a one and the column with a zero. Look at the most restrictive rows, where the function takes its rare value (1 for AND, 0 for OR and implication). The helper above tries all column orders and shows the fitting ones. It works when the number of columns equals the number of variables.

Common mistakes

  • Mixing up A → B and B → A: they are not equivalent.
  • Evaluating A → B → C left to right although implication goes right to left.
  • Forgetting that without brackets AND binds tighter than OR: A ∨ B ∧ C is A ∨ (B ∧ C).
  • Writing = instead of equivalence: formulas use ≡ or ↔.
  • Changing the variable order midway and losing track of the row numbers.

FAQ

How do I build a truth table from a formula?
List the variables, create 2 to the power n rows with a binary enumeration of values, add a column for each subformula in order of operator priority and evaluate row by row. The calculator does this automatically and shows the steps.
What are the canonical DNF and CNF and how do I get them?
The DNF is built from the rows where the function equals 1: for each, write the AND of all variables and join them with OR. The CNF is built from the rows where the function equals 0: for each, write the OR of all variables with inverted negations and join them with AND.
What does implication equal and in which order is it evaluated?
A → B is 0 only when A = 1 and B = 0, otherwise it is 1. It is equivalent to ¬A ∨ B. A chain A → B → C is evaluated from right to left, as A → (B → C).
Which operator notations does the calculator understand?
Textbook symbols ¬ ∧ ∨ → ≡ ↔ ⊕ and keyboard variants: not, !, ~, and, &, *, or, +, ->, =>, ==, <->, xor, ^. You can use the constants 0 and 1, variable names of several letters and brackets of any depth.
How do I solve EGE informatics task 2 with a truth table?
First build the table and see at which sets the function takes the value given in the fragment. Then match the fragment columns to the variables so that every row fits. To check, enter the formula and the fragment rows in the helper on this page: it tries all column orders.