Skip to content
DoingCamp CS

Make it comfy

Lesson style

Quick mode shows the key picture, a summary and the practice. Good for a refresher.

Theme
Font

Both fonts are designed to be easy to read. Some readers with dyslexia prefer Lexend.

Text size
Spacing
Animations

Lesson 3 of 16 · about 14 min

If–then

"If p then q" is the most important sentence in mathematics, and the most misunderstood. You'll learn exactly when an implication is true, why its converse is a different claim, and why its contrapositive is the same one.

🧭 What you need first: Propositions and connectives

The story

A parent promises: “If you finish your homework, then we’ll go for ice cream.” When has the parent broken the promise?

  • Homework done, ice cream: promise kept.
  • Homework done, no ice cream: promise broken.
  • Homework not done, no ice cream: promise kept. Nothing was promised for this case.
  • Homework not done, ice cream anyway: still kept! The promise only said what happens if the homework gets done. A generous parent didn’t break anything.

That’s the whole meaning of “if pp then qq”: the only way to break it is pp happening without qq. Mathematicians use exactly this meaning, and once it clicks, a lot of proofs become much easier to read.

Another way: a vending machine guarantee

“If you insert $2, you get a drink.” The machine is only lying if you put in $2 and got nothing. If you put in nothing, it made no promise, so whatever happens, the guarantee stands.

Play with it

Explore the arrow

Look at the table for p -> q. Find the single false row. Then compare it with q -> p (the converse) and not q -> not p (the contrapositive). Which one has exactly the same column as p -> q?

pqresult
TTT
TFF
FTT
FFT

🟡 True in 3 of 4 rows: satisfiable, but not always true.

Name it

The real words

  • Implication (p→qp \to q): pp is the hypothesis, qq is the conclusion. It’s false only when pp is true and qq is false.
    • When pp is false, p→qp \to q is vacuously true. “If pigs fly, I’m the queen” is technically true.
    • Many ways to say it: ”pp implies qq”, ”qq if pp”, ”pp only if qq”, ”pp is sufficient for qq”, ”qq is necessary for pp”.
  • Converse and contrapositive of p→qp \to q:
    • Converse: q→pq \to p. Not the same! “If it’s a dog, it’s a mammal” is true; “if it’s a mammal, it’s a dog” isn’t.
    • Contrapositive: ¬q→¬p\lnot q \to \lnot p. Always the same as p→qp \to q. “If it’s not a mammal, it’s not a dog.” Lesson 9 turns this into a proof technique.
    • Inverse: ¬p→¬q\lnot p \to \lnot q. Same as the converse, so also not the original claim.
  • If and only if (↔\leftrightarrow): p↔qp \leftrightarrow q is true when pp and qq match. It means p→qp \to q and q→pq \to p. Mathematicians write “iff”. Proving an iff takes two proofs, one for each direction.
  • In code, p→qp \to q is (not p) or q.
Build it

Rewrite the arrow

🎯 Write a formula that means the same as p → q, using only not, and, or.

pqgoalyours
TTTT✅
TFFF✅
FTTF❌
FFTF❌

Without using: ->, <->

Challenge

The four-card puzzle

Four cards each have a letter on one side and a number on the other. You see: A, K, 4, 7. Rule: 'If a card has a vowel on one side, it has an even number on the other.' Which cards must you turn over to check the rule?

Remember it

Which statement means exactly the same as 'If it's a cat, then it's a mammal'?

Got it?

Finish the lesson to color it in on your map and collect its concept cards.

Did this lesson click?