Skip to content
Posts

cat ~/posts/mathematics-logic-sets-proofs.mdx

2026.10.19

20 min read

––– views

ibsanju

Logic, Sets and Proofs: How Mathematicians Think

Statements, sets, functions and the main proof methods (direct, contrapositive, contradiction and induction), with worked examples and practice questions.

Series · Part 2 of 5

Mathematics from Scratch

  1. [01]Mathematics from Scratch: Basic to Advanced, Explained Simply
  2. [02]Logic, Sets and Proofs: How Mathematicians Think (you are here)
  3. [03]Linear Algebra and Differential Equations, Explained Simply
  4. [04]Real Analysis: Calculus With the Proofs
  5. [05]Abstract Algebra, and a Map of What Comes After

Part 1 was mostly about getting answers: fractions, algebra, calculus, matrices. University mathematics asks a different question. Not "what is the answer?" but "how do you know it is true for every case, and not only the ones you tried?"

That needs a small amount of vocabulary (logic, sets, functions) and four proof methods. This post covers both. Everything later in the series, linear algebra, analysis and abstract algebra, is written in this language.

How to use this post

The layout is the same as part 1: the idea, how to do it, worked examples, the usual mistake, then practice. Proofs are learned by writing them, so work every example on paper before reading the steps, and attempt every practice question before opening the answer.

1. Statements and logic

A statement is a sentence that is either true or false. "7 is prime" is a statement. "Close the door" and "what time is it?" are not. A sentence with a variable, such as "x > 3", becomes a statement once you choose x.

The pieces

  1. and: true only when both parts are true.
  2. or: true when at least one part is true. Mathematicians use the inclusive "or", so "2 is even or 2 is prime" is true.
  3. not: flips true and false.
  4. if P then Q, written P ⇒ Q: the one that causes trouble. It is false in exactly one case: P true and Q false.
PQIf P then Q
truetruetrue
truefalsefalse
falsetruetrue
falsefalsetrue

Think of it as a promise. "If you pass, I will buy you lunch" is broken only if you pass and I do not buy lunch. If you fail, the promise says nothing, so it cannot be broken. That is why a false P makes the whole statement true. Mathematicians call this "vacuously true".

Three relatives of "if P then Q"

  1. The converse swaps the parts: if Q then P. It is not equivalent.
  2. The contrapositive swaps and negates: if not Q then not P. It is equivalent.
  3. The negation is "P and not Q". To show an "if" statement is false, find one case where P holds and Q fails. That case is a counterexample.

Example 1: "If n is divisible by 4, then n is even."

  • True. Anything divisible by 4 is 2 times something.
  • Converse: "If n is even, then n is divisible by 4." False. Take n = 2.
  • Contrapositive: "If n is odd, then n is not divisible by 4." True, and it says the same as the original.

Quantifiers. ∀ means "for all" and ∃ means "there exists". To negate a statement that starts with one, swap the quantifier and negate the rest.

Example 2: negate "every prime number is odd".

  • Swap "every" for "some" and negate the rest: "some prime number is not odd".
  • That is true: 2 is the counterexample.

The usual mistake: treating the converse as if it were the original. "If it rains the ground is wet" does not give "if the ground is wet it rained". A sprinkler also does it.

Check yourself

Which statement says the same thing as: If it rains, the match is cancelled?

Practice

Write the converse and the contrapositive of: If a number is divisible by 6, it is divisible by 3. Say which of the three statements are true. Then negate: every dog in the shelter is friendly. Then decide: is 'if 2 + 2 = 5, then the moon is made of cheese' true or false?

Show the steps and the answer
  1. Original: true, since 6 = 2 × 3. Converse: if a number is divisible by 3, it is divisible by 6. False: 9 is divisible by 3 but not by 6. Contrapositive: if a number is not divisible by 3, it is not divisible by 6. True.
  2. At least one dog in the shelter is not friendly.
  3. True. The first part, 2 + 2 = 5, is false, so the promise cannot be broken.

Answers: converse false, contrapositive true; some dog is not friendly; true.

2. Sets

A set is a collection of distinct things. Order does not matter and repeats do not count, so {1, 2, 2, 3} and {3, 1, 2} are the same set.

The notation

  1. x ∈ A means x is an element of A. x ∉ A means it is not.
  2. A ⊆ B means every element of A is also in B (A is a subset of B).
  3. ∅ is the empty set, with no elements. It is a subset of every set.
  4. A ∪ B (union) is everything in A or B or both. A ∩ B (intersection) is everything in both.
  5. A \ B (difference) is everything in A that is not in B.
  6. The size of A, written |A|, is the number of elements.
  7. Set-builder notation describes a set by a rule: {x ∈ ℤ : x is even} reads "the integers x such that x is even".

Example 1: A = {1, 2, 3, 4} and B = {3, 4, 5}

  • A ∪ B = {1, 2, 3, 4, 5}.
  • A ∩ B = {3, 4}.
  • A \ B = {1, 2}.
  • Size check: |A ∪ B| = |A| + |B| − |A ∩ B| = 4 + 3 − 2 = 5. Adding the sizes counts the shared elements twice, so subtract them once.

Example 2: a class of 30. 18 play football, 12 play chess, 5 play both. How many play neither?

  1. Players of at least one sport: 18 + 12 − 5 = 25.
  2. Neither: 30 − 25 = 5.

Example 3: how many subsets does {a, b, c} have?

  • For each element, choose in or out: 2 × 2 × 2 = 8.
  • They are ∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c} and {a, b, c}.
  • In general a set with n elements has 2ⁿ subsets.

The usual mistake: mixing up ∈ and ⊆. The number 2 is in {1, 2, 3}, so 2 ∈ {1, 2, 3}. The set {2} is a subset of it, so {2} ⊆ {1, 2, 3}. Also, ∅ (nothing) and {∅} (a set holding one thing, the empty set) are different.

Check yourself

In a group of 40 people, 25 drink tea, 20 drink coffee and 8 drink neither. How many drink both?

Practice

For A = {2, 4, 6, 8} and B = {4, 8, 12}, find the union, the intersection and A \ B. Then: how many subsets does a 5-element set have, and how many of them have exactly 2 elements?

Show the steps and the answer
  1. Union: {2, 4, 6, 8, 12}. Intersection: {4, 8}. A \ B: {2, 6}.
  2. All subsets: 2⁵ = 32.
  3. Subsets with exactly 2 elements: choose 2 of 5, which is 5 × 4 ÷ 2 = 10 (the counting section of part 1).

Answers: as listed; 32; 10.

3. Functions, stated carefully

A function f from a set X to a set Y gives each input in X exactly one output in Y. X is the domain and Y is the codomain. The range is the set of outputs actually reached, which can be smaller than the codomain.

Two properties decide whether a function can be undone:

  1. Injective (one-to-one): different inputs always give different outputs.
  2. Surjective (onto): every element of the codomain is hit by some input.
  3. Bijective: both. Each output comes from exactly one input, so the function has an inverse.

Example 1: f(x) = x² from the reals to the reals.

  • Not injective: f(2) = f(−2) = 4.
  • Not surjective: no real x gives −1.
  • On the graph from part 1, a horizontal line hits it twice (not injective) or not at all (not surjective).

Example 2: f(x) = 2x + 1 from the integers to the integers.

  • Injective: if 2a + 1 = 2b + 1 then a = b.
  • Not surjective: the output is always odd, so 4 is never hit.

Example 3: f(x) = x³ from the reals to the reals.

  • Injective and surjective, so bijective. The inverse is the cube root.

The usual mistake: forgetting that the codomain is part of the question. The same rule x² is surjective if you change the codomain to the non-negative reals. "Is it onto?" has no answer until you say onto what.

Check yourself

Take f(x) = x² with the real numbers as both domain and codomain. Which is true?

Practice

Classify each as injective, surjective, both or neither, and say why. (a) f(x) = 3x − 2 from the reals to the reals. (b) f(x) = |x| from the reals to the reals. (c) f(n) = n + 1 from the positive integers 1, 2, 3, ... to the positive integers.

Show the steps and the answer
  1. (a) Both. 3a − 2 = 3b − 2 gives a = b. Any y is hit by x = (y + 2) ÷ 3. The inverse is (y + 2) ÷ 3.
  2. (b) Neither. |3| = |−3|, and no input gives −1.
  3. (c) Injective, but not surjective. The output 1 is never reached, because n + 1 is at least 2.

Answers: (a) both; (b) neither; (c) injective only.

4. What a proof is, and the direct proof

A proof is a chain of steps. Each step follows from a definition, an earlier proven fact, or the step before it, and the chain ends at the claim. A proof covers every case at once, which testing examples cannot do.

Here is why examples are not enough. The expression n² + n + 41 gives a prime number for every n from 0 to 39. At n = 40 it gives 40² + 40 + 41 = 1681, which is 41 × 41. Forty successes, then a failure. Nothing short of a proof settles a claim about all n.

The direct proof, step by step

  1. Write down what you are given, using definitions. An even number is 2k for some integer k. An odd number is 2k + 1.
  2. Write down what you must reach, also as a definition.
  3. Calculate from the first to the second, one justified step at a time.
  4. Use a fresh letter each time you say "some integer".

Example 1: the sum of two even numbers is even.

  • Let the numbers be 2a and 2b, where a and b are integers.
  • Their sum is 2a + 2b = 2(a + b).
  • a + b is an integer, so the sum is 2 times an integer. It is even.

Example 2: the product of two odd numbers is odd.

  • Let the numbers be 2a + 1 and 2b + 1.
  • Multiply: (2a + 1)(2b + 1) = 4ab + 2a + 2b + 1 = 2(2ab + a + b) + 1.
  • 2ab + a + b is an integer, so the product has the form 2k + 1. It is odd.

Example 3: n² + n is even for every integer n.

  • Factor: n² + n = n(n + 1).
  • Of two consecutive integers, one is even.
  • So the product has an even factor, which makes it even.

The usual mistake: reusing one letter for two different numbers. Writing the two evens as 2k and 2k is a proof about equal numbers only. Use 2a and 2b.

Practice

Prove that the sum of two odd numbers is even. Then prove that if n is divisible by 6, then n² is divisible by 12. Then prove that the sum of three consecutive integers is divisible by 3.

Show the steps and the answer
  1. Let the numbers be 2a + 1 and 2b + 1. The sum is 2a + 2b + 2 = 2(a + b + 1), which is even.
  2. Write n = 6k. Then n² = 36k² = 12 × 3k², and 3k² is an integer, so 12 divides n².
  3. Let the integers be n, n + 1 and n + 2. The sum is 3n + 3 = 3(n + 1), a multiple of 3.

5. Contrapositive and contradiction

Two more methods, both built on the logic in section 1.

Proof by contrapositive. To prove "if P then Q", prove the equivalent "if not Q then not P". Use it when "not Q" is easier to work with than P.

Example 1: if n² is even, then n is even.

  • Contrapositive: if n is odd, then n² is odd.
  • Let n = 2k + 1. Then n² = 4k² + 4k + 1 = 2(2k² + 2k) + 1, which is odd.
  • That proves the contrapositive, so the original is true.

Proof by contradiction. To prove a claim, assume it is false and follow the consequences until something impossible appears. Then the assumption must have been wrong.

Example 2: √2 is irrational.

  1. Suppose √2 = a ÷ b, a fraction in lowest terms (a and b share no common factor).
  2. Square both sides: 2 = a² ÷ b², so a² = 2b².
  3. So a² is even, and by Example 1, a is even. Write a = 2c.
  4. Then 4c² = 2b², so b² = 2c². So b² is even, and b is even.
  5. Now a and b are both even, so they share the factor 2. That contradicts "lowest terms".
  6. The assumption fails, so √2 cannot be written as a fraction.

Example 3: there are infinitely many primes.

  1. Suppose the list of all primes is finite: p₁, p₂, ..., pₙ.
  2. Let N = p₁ × p₂ × ... × pₙ + 1.
  3. Dividing N by any pᵢ leaves remainder 1, so no prime on the list divides N.
  4. But every number above 1 has a prime factor. That factor is a prime not on the list, which contradicts step 1.

N itself need not be prime. With the first six primes, 2 × 3 × 5 × 7 × 11 × 13 + 1 = 30031 = 59 × 509. The proof only needs a prime factor of N outside the list, and 59 is one.

The usual mistake: calling something a proof by contradiction without reaching a contradiction. Finishing with "this seems unlikely" is not enough. You must arrive at a statement that is false, such as "a and b share no factor and also share the factor 2".

Check yourself

You want to prove: if n² is odd, then n is odd. Using the contrapositive, which statement do you prove?

Practice

Prove by contrapositive: if 3n + 2 is odd, then n is odd. Then prove by contradiction: the sum of a rational number and an irrational number is irrational.

Show the steps and the answer
  1. Contrapositive: if n is even, then 3n + 2 is even. Let n = 2k. Then 3n + 2 = 6k + 2 = 2(3k + 1), which is even.
  2. Let r be rational and s irrational. Suppose r + s = q is rational. Then s = q − r. A difference of two rationals is rational, so s is rational. That contradicts s being irrational. So r + s is irrational.

6. Induction

Induction proves a statement for every whole number n = 1, 2, 3, ... with two checks, like a row of dominoes. If the first falls, and each falling domino knocks over the next, they all fall.

How to do it

  1. State the claim P(n) for a general n.
  2. Base case: check P(1) directly.
  3. Induction step: assume P(k) is true for some k (the induction hypothesis). Prove that P(k + 1) is true, and use the assumption somewhere in the proof.
  4. Conclude that P(n) holds for all n.

Example 1: 1 + 2 + ... + n = n(n + 1) ÷ 2.

  • Base case, n = 1: the left side is 1 and the right side is 1 × 2 ÷ 2 = 1. Equal.
  • Step: assume 1 + 2 + ... + k = k(k + 1) ÷ 2.
  • Then 1 + 2 + ... + k + (k + 1) = k(k + 1) ÷ 2 + (k + 1).
  • Factor out k + 1: (k + 1)(k ÷ 2 + 1) = (k + 1)(k + 2) ÷ 2.
  • That is the formula with n = k + 1, so the claim holds for all n.

Example 2: the sum of the first n odd numbers is n².

  • Base case: 1 = 1².
  • Step: assume 1 + 3 + ... + (2k − 1) = k². Add the next odd number, 2k + 1: k² + 2k + 1 = (k + 1)².
  • It matches n = k + 1, so the claim holds for all n.

Example 3: 2ⁿ > n for every n ≥ 1.

  • Base case: 2¹ = 2 > 1.
  • Step: assume 2ᵏ > k. Then 2^(k+1) = 2 × 2ᵏ > 2k.
  • And 2k ≥ k + 1 whenever k ≥ 1. So 2^(k+1) > k + 1.

The usual mistake: skipping the base case. Take the false claim "n = n + 1 for every n". The step works: if k = k + 1, add 1 to both sides to get k + 1 = k + 2. But there is no true first domino, so nothing falls. The base case is not a formality.

Check yourself

In an induction proof, what does the induction step prove?

Practice

Prove by induction that 1² + 2² + ... + n² = n(n + 1)(2n + 1) ÷ 6. Then prove that n³ + 2n is divisible by 3 for every n ≥ 1.

Show the steps and the answer
  1. Base case, n = 1: left side 1, right side 1 × 2 × 3 ÷ 6 = 1.
  2. Step: assume the formula for k. Add (k + 1)²: k(k + 1)(2k + 1) ÷ 6 + (k + 1)² = (k + 1)[k(2k + 1) + 6(k + 1)] ÷ 6 = (k + 1)(2k² + 7k + 6) ÷ 6.
  3. Since 2k² + 7k + 6 = (k + 2)(2k + 3), this is (k + 1)(k + 2)(2k + 3) ÷ 6, which is the formula for n = k + 1.
  4. For the second claim, the base case n = 1 gives 1 + 2 = 3, divisible by 3.
  5. Step: assume k³ + 2k is divisible by 3. Then (k + 1)³ + 2(k + 1) = k³ + 3k² + 3k + 1 + 2k + 2 = (k³ + 2k) + 3(k² + k + 1).
  6. The first bracket is divisible by 3 by assumption and the second is 3 times an integer, so the sum is divisible by 3.

Getting unstuck

When a proof will not start, try these in order:

  1. Rewrite every word in the claim as its definition. "Even" becomes 2k. "Rational" becomes a ÷ b.
  2. Try small cases (n = 1, 2, 3) and look for the pattern you can then prove.
  3. Work backwards from the conclusion and ask what would make it true.
  4. If direct steps stall, try the contrapositive, then contradiction.

George Pólya's How to Solve It, listed in part 1, is the classic book on this habit.

The mistakes in one table

MistakeWhy it failsFix
Checking examples and calling it a proofn² + n + 41 is prime for 40 values and then failsProve it for a general n
Using the converse"If P then Q" does not give "if Q then P"Prove the contrapositive instead
Reusing one letter for two numbers2k and 2k are the same numberUse 2a and 2b
Skipping the base case"n = n + 1" has a working step and no startAlways check the first case
Assuming what you must proveThe argument goes in a circleStart from the definitions
Confusing ∈ and ⊆An element is not a set of elements2 ∈ {1, 2}, {2} ⊆ {1, 2}

Where to go next

The next post in the series puts this to use in linear algebra and differential equations. If you want more practice with proofs first, two books written for exactly this stage are Daniel Velleman's How to Prove It and Ethan Bloch's Proofs and Fundamentals.

Sources and further reading

  • Daniel J. Velleman, How to Prove It: A Structured Approach.
  • Ethan D. Bloch, Proofs and Fundamentals: A First Course in Abstract Mathematics.
  • George Pólya, How to Solve It (1945).
  • The proof that √2 is irrational and the proof that there are infinitely many primes are classical results (the second is in Euclid's Elements). Both appear in most proof textbooks.

Enjoyed this? Leave a reaction

Share this article

Comments

Loading comments…

Leave a comment

Enjoying this post?

Don't miss out. Get an email whenever I post, no spam.

Subscribe Now