Search

Search papers and lessons

Propositional Logic

Level 1 · 10 min read

Propositional logic treats statements as simply true or false and combines them with words like and, or and not, so any argument built this way can be checked by listing every case.

On this page

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 p→qp \to q, which says that whenever it rains, I take an umbrella. We want to know when this statement is true.

  1. 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.
  2. 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).
  3. Apply the rule for "if ... then". The statement p→qp \to q 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.
  4. Write the results in a column. The column for p→qp \to q reads T, F, T, T, in the order of the four cases above. Check: only the second row has F.
  5. 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

Definition: Proposition

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: ¬p\neg p is true exactly when p is false.
  • And: p∧qp \land q is true exactly when both p and q are true.
  • Or: p∨qp \lor q is true when at least one of p and q is true. In logic, "or" includes the case where both are true.
  • If ... then: p→qp \to q is false exactly when p is true and q is false.
  • If and only if: p↔qp \leftrightarrow q 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 2n2^n rows. The table below uses p and q, so it has four rows.

pq¬p\neg pp∧qp \land qp∨qp \lor qp→qp \to q
TTFTTT
TFFFTF
FTTFTT
FFTFFT

Each column after the first two is built from the rule above, one connective at a time.

Step 4 in symbols: tautologies and equivalence

Definition: Tautology

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 A≡BA \equiv B. For example, the formula ¬(p∧q)\neg(p \land q) and the formula ¬p∨¬q\neg p \lor \neg q have the same values in all four rows, so they are equivalent. That is one form of De Morgan's law.

Worked examples

Example
Example 1: one row at a time (tiny)

Let p be true and q be false. Find the value of p∧¬qp \land \neg q.

  1. Compute ¬q\neg q. Since q is false, ¬q\neg q is true.
  2. Compute p∧¬qp \land \neg q. Both p and ¬q\neg q are true, so the and is true.
  3. Result: true.

Interpretation: the statement "it is raining and I do not take an umbrella" is true in this case.

Example
Example 2: an implication and its contrapositive (standard)

Show that p→qp \to q is equivalent to ¬q→¬p\neg q \to \neg p. This form is called the Contrapositive.

  1. Row (T, T): p→qp \to q is T. Its contrapositive: ¬q\neg q is F and ¬p\neg p is F, so ¬q→¬p\neg q \to \neg p is T (a false premise makes "if" true).
  2. Row (T, F): p→qp \to q is F. Contrapositive: ¬q\neg q is T and ¬p\neg p is F, so ¬q→¬p\neg q \to \neg p is F.
  3. Row (F, T): p→qp \to q is T. Contrapositive: ¬q\neg q is F, so ¬q→¬p\neg q \to \neg p is T.
  4. Row (F, F): p→qp \to q is T. Contrapositive: ¬q\neg q is T and ¬p\neg p is T, so ¬q→¬p\neg q \to \neg p is T.
  5. 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.

Example
Example 3: a door rule (realistic)

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

b∧(c∨a)∧¬lb \land (c \lor a) \land \neg l
  1. Set the values b = T, c = F, a = T, l = F.
  2. Compute c∨ac \lor a. c is F and a is T, so the or is T.
  3. Compute b∧(c∨a)b \land (c \lor a). b is T and the bracket is T, so the value is T.
  4. Compute ¬l\neg l. l is F, so ¬l\neg l is T.
  5. 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 bb 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 p→qp \to q 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 p→qp \to q and ¬q→¬p\neg q \to \neg p.
  • 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 p∧qp \land q 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 p→qp \to q false?Show answer

A table with three letters has 23=82^3 = 8 rows. The statement p→qp \to q 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 p→qp \to q 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 (password∨token)∧¬suspended(\text{password} \lor \text{token}) \land \neg\text{suspended}. The password is correct, so the or is true, but the account is suspended, so ¬suspended\neg\text{suspended} is false, and the and is false.

Sources

Propositional Logic — explained simply · ungoon.me