Truth Table Generator
Enter a propositional expression using p, q, r, s and the operators ! (not), & (and), | (or), -> (implies), <-> or = (iff), ^ (xor). The calculator parses the formula, evaluates it on every truth assignment and reports whether it is a tautology, contradiction or contingency.
Exhaustion as a method
Propositional logic has a property nothing else on this site shares: it is finitely checkable. A formula over a handful of variables has only so many possible assignments of true and false, and evaluating all of them settles every question about it exhaustively.
That is what a truth table is. This generator builds one for any formula over up to four variables, evaluates every row, and classifies the result.
Elsewhere, checking a claim at many points is evidence. Here it is proof: four variables give sixteen assignments, and there is no seventeenth case hiding anywhere. A formula true in every row is true under every possible interpretation, which is what makes it a tautology rather than merely a well-supported guess.
The classification line states which of the three outcomes applies. That single word usually answers the question a formula was written to settle — whether two statements are equivalent, whether an argument form is valid, whether a condition can ever be met.
How to use this calculator
- Type the formula Using p, q, r and s as the variables, with the logical operators between them. Brackets group as usual, and spaces are ignored.
- Keep to four variables The table doubles in height with each one, so four is the practical limit at sixteen rows. More is rejected rather than truncated.
- Read the rows Each shows one assignment of truth values and the formula's value under it. The variables are listed alphabetically regardless of the order they appear in the formula.
- Read the classification Always true, always false, or neither. It summarises the whole column in one word.
How the table is built
The formula is tokenised and converted into a form where operators follow their operands, which removes the brackets entirely and fixes the order of evaluation once and for all. That conversion is what makes precedence unambiguous, so negation binds tighter than conjunction, which binds tighter than implication.
The distinct variables are then collected and sorted alphabetically. That sorting is why the columns appear in a standard order even when the formula mentions them in another — a formula in r and p produces a table headed p then r.
Rows are generated by counting in binary. With three variables the numbers zero to seven have three binary digits each, and reading those digits as truth values produces all eight assignments exactly once, in the conventional order with the first variable changing slowest.
The formula is evaluated once per row on a stack, and two running flags track whether anything has been false and whether anything has been true. Those two flags decide the classification at the end without needing a second pass over the table.
What each input means
- expr Formula — form field “Logical expression”
- A propositional expression over p, q, r and s. At least one variable is required and at most four are allowed.
- p, q, r, s Variables
- The atomic propositions. Only those actually appearing in the formula become columns, and they are sorted alphabetically.
- rows Row count
- Two raised to the number of variables: two rows for one variable, four for two, eight for three, sixteen for four.
Worked examples
Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.
A tautology
A proposition or its negation — the law of excluded middle, which cannot fail.
Inputs Logical expression = p | !p
- Expression p | !p
- Variables p
- Header p | p | !p
- Row F | T
- Row T | T
- Classification Tautology — always true.
Result Tautology — always true.
Both rows come out true, so the formula is classified as a tautology. With one variable the table has only two rows, and checking both is a complete proof rather than a sample.
A tautology is true regardless of what the variables mean. That is exactly what makes such formulas useful as logical laws rather than as claims about anything in particular.
A contradiction
A proposition and its negation together, which no assignment can satisfy.
Inputs Logical expression = p & !p
- Expression p & !p
- Variables p
- Header p | p & !p
- Row F | F
- Row T | F
- Classification Contradiction — always false.
Result Contradiction — always false.
Both rows are false, giving the opposite classification. This formula is the negation of the previous one, and negating a tautology always produces a contradiction.
A contradiction is unsatisfiable: no interpretation makes it true. Finding that a set of conditions reduces to one is how an inconsistent specification gets caught.
Testing an equivalence
An implication set against its contrapositive, joined by the biconditional operator.
Inputs Logical expression = (p -> q) = (!q -> !p)
- Expression (p -> q) = (!q -> !p)
- Variables p, q
- Header p | q | (p -> q) = (!q -> !p)
- Row F | F | T
- Row F | T | T
- Row T | F | T
- Row T | T | T
- Classification Tautology — always true.
Result Tautology — always true.
The whole formula is a tautology, which is precisely the statement that the two sides are logically equivalent. Wrapping two formulas in a biconditional and checking for a tautology is the standard way to test equivalence.
That the contrapositive is equivalent to the original is one of the most useful facts in logic, and here it is established exhaustively across all four rows rather than argued.
Reading the result
The three classifications
A tautology is true in every row and holds regardless of interpretation. A contradiction is false in every row and can never be satisfied. A contingency is neither, meaning its truth depends on the facts — which is what most ordinary statements are.
Testing equivalence and validity
Two formulas are equivalent exactly when joining them with a biconditional gives a tautology. An argument is valid exactly when the implication from its combined premises to its conclusion is a tautology.
Implication is not causation
An implication is false only when its antecedent is true and its consequent false. It is therefore true whenever the antecedent is false, which surprises people meeting the truth table for the first time and is nonetheless the standard convention.
When you would use this
Checking a logical simplification
Rewriting a condition into a simpler form is only safe if the two are equivalent. Joining them with a biconditional and confirming a tautology verifies that exhaustively.
Testing whether an argument form is valid
Building the implication from the conjunction of the premises to the conclusion and checking for a tautology is the definition of validity, carried out mechanically.
Assumptions and limitations
What this calculator assumes
- The formula uses only p, q, r and s as variables, and at least one of them.
- Operators follow standard precedence, with negation binding most tightly.
- Rows are generated in the conventional binary order, with the first variable changing most slowly.
- Every assignment is evaluated, so the classification is exhaustive rather than sampled.
Where it stops being the right tool
- At most four variables, since the table doubles in height with each addition.
- Propositional logic only: no quantifiers, predicates or variables ranging over objects.
- No simplification or normal form is produced — the table is the output.
- A satisfying assignment is not called out separately; it has to be read from the rows.
Common mistakes
Misreading a false antecedent as making the implication false
Why it happens. In ordinary speech, saying that one thing implies another suggests a connection between them. The logical operator has no such requirement and is true whenever the antecedent fails.
How to avoid it. Read the rows. An implication is false in exactly one case — true antecedent, false consequent — and true in the other three.
Relying on precedence instead of brackets
Why it happens. A formula written without brackets still parses, and the grouping the parser chooses may not be the one intended — especially between conjunction and implication.
How to avoid it. Bracket anything ambiguous. It costs nothing and removes the possibility of testing a different formula from the one you meant.
Reading a contingency as a failure
Why it happens. The other two classifications sound like verdicts, so being told a formula is sometimes true reads as an inconclusive result.
How to avoid it. It is a definite answer: the formula's truth depends on the variables. Most meaningful statements are contingencies, and only logical laws are tautologies.
Frequently asked questions
What operators can I use?
Negation, conjunction, disjunction, implication, the biconditional and exclusive or, each accepted in both an ASCII form and its conventional symbol. Brackets group as usual and spaces are ignored.
How many variables are supported?
Up to four — p, q, r and s. The table doubles in height with each variable added, so four gives sixteen rows. A formula mentioning more is rejected rather than partially evaluated.
What is the difference between a tautology, a contradiction and a contingency?
A tautology is true in every row, a contradiction false in every row, and a contingency is true in some and false in others. Because every assignment is checked, the classification is proved rather than estimated.
How do I test whether two formulas are equivalent?
Join them with the biconditional operator and check the result. Equivalence means agreeing on every assignment, which is exactly the condition that the combined formula is a tautology.