Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 68 ยท Logic

Implication and Biconditional

Understand if-then statements, why a false hypothesis makes them vacuously true, and how converse, inverse, contrapositive and iff relate, with Python checks.

"If it rains, then the ground is wet." Statements of this shape drive every theorem, every specification and every if in your code. They are called conditionals or implications, and they are the most misunderstood connective in logic. The surprise is that an implication can be true even when its premise is false, and the confusion that follows causes real bugs in reasoning, from flawed test cases to misread requirements.

In this lesson you will learn the truth table of the implication, how to build the converse, inverse and contrapositive, what "if and only if" means, and which mistakes to avoid. Everything is tested in Python as we go. The previous lesson, Propositional Logic, covers the basic connectives used here.

The implication p โ†’ q

An implication has two parts: the hypothesis (or premise) p and the conclusion q. We write p โ†’ q and read it "if p, then q" or "p implies q".

Think of it as a promise: "If you pass the exam, I will buy you ice cream." When is the promise broken? Only when you pass the exam and do not get ice cream. In every other case the promise was not violated.

p q p โ†’ q
T T T
T F F
F T T
F F T

The implication is false in exactly one row: true hypothesis, false conclusion. In Python there is no arrow operator, but the table matches (not p) or q.

Python Implication as a function

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the two rows where p is false. Both give True. We say the implication is vacuously true: no promise was tested, so none was broken.

Vacuous truth

"Every unicorn in this room is purple" is true if the room contains no unicorns. A universal statement over an empty set is vacuously true, for the same reason that an implication with a false hypothesis is true. You saw the programming version in Mathematical Notation and Python: all() of an empty list is True.

Vacuous truth is not a trick; it is what makes proofs and definitions work smoothly. A statement such as "every element of the empty set is positive" has to be true, otherwise theorems about all sets would need a special case for the empty set.

Many ways to say p โ†’ q

English offers many phrasings for the same implication:

  • if p, then q
  • p implies q
  • q if p
  • p only if q
  • p is sufficient for q
  • q is necessary for p
  • q whenever p

The tricky ones are "only if" and "necessary". "You can vote only if you are 18" means vote โ†’ 18, not the other way around. "Being 18 is necessary to vote" says the same thing.

Reading p implies q

Sufficient p is enough to guarantee q.
Necessary q must hold whenever p does.
Only if p only if q means p implies q.

The arrow points from the hypothesis to the conclusion, never back.

1 / 2

Converse, inverse and contrapositive

From an implication p โ†’ q you can build three relatives:

Name Form Example (p: it rains, q: ground is wet)
Converse q โ†’ p If the ground is wet, then it rained
Inverse ยฌp โ†’ ยฌq If it does not rain, the ground is not wet
Contrapositive ยฌq โ†’ ยฌp If the ground is not wet, then it did not rain

The key facts:

  1. The contrapositive is logically equivalent to the original. They are true in exactly the same situations. If it did rain, the ground must be wet, so a dry ground proves no rain fell.
  2. The converse and inverse are equivalent to each other, but not to the original. A sprinkler can make the ground wet without rain.

Because the contrapositive says the same thing as the original, it is a powerful proof tool; see Contradiction and Contrapositive. Let us confirm all of this by brute force.

Python Which relatives are equivalent?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output shows True for the first and last comparison and False for the two in the middle. Only the contrapositive can replace the original statement.

The biconditional p โ†” q

Sometimes the implication goes both ways: "A triangle is equilateral if and only if all its angles are equal." We write p โ†” q and read it "p if and only if q", often abbreviated iff. It is true exactly when p and q have the same truth value.

p q p โ†” q
T T T
T F F
F T F
F F T

The biconditional is the same as "p โ†’ q and q โ†’ p". In Python, it is p == q for booleans, because two booleans are equal exactly when they agree. Notice that it is also the negation of XOR.

Python The biconditional two ways

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The final line tests a true biconditional on 101 integers. It is evidence only, since the claim concerns all integers, but it fits what a proof shows.

Common mistakes

  1. Affirming the converse. From "if it rains, the ground is wet" and "the ground is wet", you cannot conclude it rained. Many arguments, and many bug reports ("the error appears when the cache is cold, so a cold cache is the cause") make exactly this error.
  2. Denying the hypothesis. From "if it rains, the ground is wet" and "it did not rain", you cannot conclude the ground is dry.
  3. Thinking a false hypothesis makes the implication false. It makes it vacuously true.
  4. Mixing up "only if" and "if". "p only if q" is p โ†’ q. "p if q" is q โ†’ p.
  5. Negating an implication wrongly. The negation of p โ†’ q is p โˆง ยฌq (the promise was made and then broken), not p โ†’ ยฌq.

The valid patterns are modus ponens (from p and p โ†’ q, conclude q) and modus tollens (from ยฌq and p โ†’ q, conclude ยฌp). A quick way to check that the negation rule is right:

Python Negating an implication

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In every row the second and third columns agree, while the fourth column (the common wrong answer) differs in rows where p is false.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. When is the implication p โ†’ q false?

    An implication fails only when the hypothesis is true and the conclusion is false. With a false hypothesis it is vacuously true.
  2. 2. Which statement is logically equivalent to 'if it is a square, then it is a rectangle'?

    That is the contrapositive (not q implies not p), which always has the same truth value as the original. The first is the converse and the third is the inverse.
  3. 3. 'You may park here only if you have a permit' means:

    'p only if q' translates to p โ†’ q. Here p is 'park' and q is 'have a permit', so a parked car implies a permit.
  4. 4. What is the negation of p โ†’ q?

    The implication is false exactly when p is true and q is false, so its negation is p โˆง ยฌq.
  5. 5. Which is true for any propositions p and q?

    The biconditional is true exactly when both sides have equal truth values. An implication is not equal to its converse, and it is vacuously true when p is false.

Summary

  • p โ†’ q is false only when p is true and q is false; otherwise it is true, and a false hypothesis gives vacuous truth.
  • In Python, implies(p, q) is (not p) or q, and the biconditional is p == q.
  • The contrapositive ยฌq โ†’ ยฌp is equivalent to p โ†’ q; the converse and inverse are equivalent to each other but not to the original.
  • "Only if" and "necessary" point from the hypothesis to the conclusion; read them carefully.
  • The negation of p โ†’ q is p โˆง ยฌq; do not affirm the converse or deny the hypothesis.

Next: Truth Tables, a systematic way to check any compound statement.