TL;DR
Propositional logic is the study of statements that are either true or false, and of how they combine. Words such as "and", "or", "not" and "if ... then" become symbols that take true or false values and return a true or false value. Because each statement has only two values, you can check any combined statement by listing every case, which gives a truth table.
Builds on: nothing beyond everyday reasoning · Leads to: First-Order Logic, Mathematical Induction
Where it's used
Computer circuits. A chip is built from logic gates that implement "and", "or" and "not" on signals that are either on or off. Designers write the behaviour as a logical formula and check it before building the circuit.
Software conditions. An if statement tests a logical condition, such as "the user is logged in and the cart is not empty". Testing and verifying such code often means checking that conditions are equivalent or that one implies another.
Formal verification. SAT solvers that check hardware and software for bugs turn the question into a propositional formula and search for an assignment of true and false that breaks the property. A tool that returns "no such assignment exists" has proven the property for that formula.
How it works
Take two simple statements. Let p mean "it is raining" and q mean "I take an umbrella". Consider the combined statement "if p then q", written , which says that whenever it rains, I take an umbrella. We want to know when this statement is true.
- Each statement has one of two values. Write T for true and F for false. In one case it is raining (p is T), and in another it is not (p is F). Similarly for q.
- List the four cases. There are two statements with two values each, so there are 2 times 2 = 4 combinations: (T, T), (T, F), (F, T) and (F, F).
- Apply the rule for "if ... then". The statement is false in exactly one case: when p is true and q is false. It rains and I do not take an umbrella, so the promise is broken. In the other three cases it is true.
- Write the results in a column. The column for reads T, F, T, T, in the order of the four cases above. Check: only the second row has F.
- Read off the meaning. Because the statement is true in three cases out of four, it is not the same as "I always take an umbrella". It only says what happens when it rains. Dry days, where p is false, make it true whatever I do.
flowchart LR A["Statements p and q each take T or F"] --> B["List all combinations"] B --> C["Apply the rule for each connective"] C --> D["Read the final column: true or false in each case"]
The math
A proposition is a statement that is either true or false, and never both. Letters such as p, q and r stand for propositions.
Step 2 in symbols: the connectives
The main connectives are listed here with their symbols and their rule in words. They play the role that union and intersection play for sets.
- Not: is true exactly when p is false.
- And: is true exactly when both p and q are true.
- Or: is true when at least one of p and q is true. In logic, "or" includes the case where both are true.
- If ... then: is false exactly when p is true and q is false.
- If and only if: is true exactly when p and q have the same value.
Step 3 in symbols: the truth table
For a formula with n letters there are rows. The table below uses p and q, so it has four rows.
| p | q | ||||
|---|---|---|---|---|---|
| T | T | F | T | T | T |
| T | F | F | F | T | F |
| F | T | T | F | T | T |
| F | F | T | F | F | T |
Each column after the first two is built from the rule above, one connective at a time.
Step 4 in symbols: tautologies and equivalence
A tautology is a formula that is true in every row of its truth table. A contradiction is one that is false in every row.
Two formulas are equivalent when they have the same column of values. We write . For example, the formula and the formula have the same values in all four rows, so they are equivalent. That is one form of De Morgan's law.
Worked examples
Let p be true and q be false. Find the value of .
- Compute . Since q is false, is true.
- Compute . Both p and are true, so the and is true.
- Result: true.
Interpretation: the statement "it is raining and I do not take an umbrella" is true in this case.
Show that is equivalent to . This form is called the Contrapositive.
- Row (T, T): is T. Its contrapositive: is F and is F, so is T (a false premise makes "if" true).
- Row (T, F): is F. Contrapositive: is T and is F, so is F.
- Row (F, T): is T. Contrapositive: is F, so is T.
- Row (F, F): is T. Contrapositive: is T and is T, so is T.
- The two columns read T, F, T, T in both cases, so they match in every row.
Interpretation: "if it rains I take an umbrella" says the same thing as "if I did not take an umbrella, it did not rain". This is often a useful way to prove a claim.
A door opens when all of the following hold: the badge is valid, and either the PIN is correct or an admin has overridden the lock, and the door is not locked. Let b mean the badge is valid, c the PIN is correct, a the override is on, and l the door is locked. The rule is
- Set the values b = T, c = F, a = T, l = F.
- Compute . c is F and a is T, so the or is T.
- Compute . b is T and the bracket is T, so the value is T.
- Compute . l is F, so is T.
- Combine the two parts. T and T is T, so the door opens.
Try it: set b = F, c = T, a = T, l = F. Does the door open?
Answer: No. The badge is not valid, so the first part is F, and the and of the three parts is F whatever the other values are.
Common mistakes and tradeoffs
It is tempting to think that "if p then q" means "if q then p". In fact the converse is a different statement. "If it rains, I take an umbrella" does not tell you that taking an umbrella means rain.
It is tempting to think that "or" means "one or the other but not both". In fact in logic "or" includes the case where both are true. The exclusive version is written differently when it is needed.
It is tempting to think that an "if" statement is false when its first part is false. In fact is true whenever p is false. This is a convention, and it is why the dry-day case in the walkthrough makes the statement true.
When to use it: for exact reasoning about yes-or-no conditions, for circuit design, and for checking conditions in code. When not to use it: when statements talk about "all" or "some" objects, which needs First-Order Logic, or when statements are only partly true. Alternatives: first-order logic adds quantifiers, and probabilistic logics handle degrees of belief.
History
Logic as a study of valid argument goes back to Aristotle, but the part about combining whole statements was developed by the Stoic school. The Stoic logician Chrysippus, in the 3rd century BC, worked out rules for statements joined by "and", "or" and "if".
George Boole's The Mathematical Analysis of Logic in 1847 treated logical reasoning as algebra on the values 0 and 1, which is now called Boolean algebra. Gottlob Frege's Begriffsschrift in 1879 gave a precise formal notation for these connectives. Truth tables, as used today, were popularised by Wittgenstein's Tractatus in 1921.
In 1937 Claude Shannon showed in his master's thesis that Boolean algebra could describe switching circuits. That link is why propositional logic is the foundation of modern digital design.
Recap
- A proposition is a statement that is either true or false.
- The connectives not, and, or, if ... then, and if and only if combine propositions by fixed rules.
- A truth table lists every combination of values, so any formula with a small number of letters can be checked completely.
- Two formulas are equivalent when their columns match, for example and .
- A tautology is true in every row.
Next, read First-Order Logic to add "for all" and "there exists", and Mathematical Induction to see logic used in proofs about all natural numbers.
Check yourself
QuestionRecall: when is true?Show answer
Only when both p and q are true. If either one is false, the and is false.
QuestionCompute: how many rows does a truth table need for a formula with three letters p, q and r, and and in how many of those 8 rows is false?Show answer
A table with three letters has rows. The statement depends only on p and q, so it is false in one of the four (p, q) combinations, and each of those combinations appears twice, once with r true and once with r false. So it is false in 2 of the 8 rows.
QuestionWhy: why is true when p is false?Show answer
The rule for "if ... then" only makes a promise when its first part holds. When p is false, the promise is not tested, so the statement cannot be broken. The convention keeps the table consistent with ordinary reasoning in proofs.
QuestionApplied: a login rule says access is allowed if the password is correct or the user has a token, and the account is not suspended. A user has a correct password but the account is suspended. Is access allowed?Show answer
No. The rule is . The password is correct, so the or is true, but the account is suspended, so is false, and the and is false.
Sources
- Wikipedia, Propositional calculus
- Wikipedia, Truth table