Implication is the connective behind the most reasoning errors, both in proofs and in everyday life. Given a sentence of the form "if p then q", you can build three related sentences that seem to say the same thing, but only one of them is truly equivalent to the original. Telling them apart is a basic skill for anyone who writes code, specifications or arguments.
The four forms
Start from an implication p → q, for example: "if a user is an administrator, then they can delete files".
| Name | Form | Example |
|---|---|---|
| Implication (direct) | p → q | if admin, can delete |
| Converse | q → p | if can delete, is admin |
| Inverse | ¬p → ¬q | if not admin, cannot delete |
| Contrapositive | ¬q → ¬p | if cannot delete, is not admin |
There is only one rule to remember: an implication is equivalent to its contrapositive, and the converse is equivalent to the inverse. But the implication and its converse are not equivalent.
In the example, the fact that administrators can delete says nothing about who else can: perhaps the file's owner as well. So the converse can be false while the direct implication is true. The contrapositive always holds: if someone cannot delete, they cannot be an administrator, because otherwise they could.
Checking with a truth table
Compare the columns:
| p | q | p → q | q → p | ¬q → ¬p |
|---|---|---|---|---|
| T | T | T | T | T |
| T | F | F | T | F |
| F | T | T | F | T |
| F | F | T | T | T |
The column for p → q matches the one for ¬q → ¬p, while the one for q → p differs in the second and third rows. The table confirms what the example suggested.
Necessary and sufficient conditions
In the implication p → q:
- p is a sufficient condition for q: p being true is enough for q to be true.
- q is a necessary condition for p: without q, p cannot be true.
"Being divisible by 4 is sufficient for being even" corresponds to "divisible by 4 → even". "Being even is necessary for being divisible by 4" says exactly the same thing, read from the other side. When a condition is both necessary and sufficient we write p ↔ q and say "p if and only if q".
A common linguistic trap involves "only if". The sentence "p only if q" means p → q, not q → p. "You can log in only if you have the password" means that logging in implies having the password; it does not say that the password is enough (a second factor might also be required).
Typical reasoning errors
Two classic fallacies come precisely from confusing these forms.
Affirming the consequent
"If the server is under attack, traffic rises. Traffic has risen. Therefore the server is under attack." This reasoning is invalid: it uses the converse as if it were true. Traffic can rise because of an advertising campaign, an automatic update, or an article that went viral.
Denying the antecedent
"If the file is encrypted, it is protected. The file is not encrypted. Therefore it is not protected." This is wrong too: it uses the inverse. The file might be protected by operating system permissions or by physically isolated storage.
In both cases the conclusion may happen to be true, but it does not follow from the premises. In my work, when I analyse the signals of an incident, this distinction is essential: a clue that is consistent with a hypothesis does not prove it.
Implication in code
Programming languages usually have no implication operator, but it is easy to express using the equivalence p → q ≡ ¬p ∨ q:
# "if the order has shipped, it must have an address"
valid = (not order.shipped) or (order.address is not None)
This pattern is handy in integrity checks and assertions. Writing shipped and address is not None would be a mistake: it would make every order that has not yet shipped invalid.
The contrapositive is also useful when debugging. If we know that "if the configuration is correct, the service starts", and the service does not start, we can conclude with certainty that the configuration is not correct (provided the implication really holds, which has to be checked).
The contrapositive in proofs
Many proofs become simpler if you prove the contrapositive. Example: "if n² is even, then n is even". Proving it directly is awkward; the contrapositive is "if n is odd, then n² is odd". If n = 2k + 1, then n² = 4k² + 4k + 1 = 2(2k² + 2k) + 1, which is odd. Done: we have proved the original statement.
In short
- p → q is equivalent to the contrapositive ¬q → ¬p, not to the converse q → p.
- In p → q, p is sufficient for q and q is necessary for p; "p only if q" means p → q.
- Affirming the consequent and denying the antecedent are fallacies, even when the conclusion happens to be true.
- In code, implication is written as
not p or q. - Proving the contrapositive is often the shortest route.