Skip to content

Proof Techniques | Computer Science

To prove P    QP \implies Q: assume PPDerive QQ by a chain of logical deductions.

Example. Prove: if nn is odd, then n2n^2 is odd.

Proof. Let n=2k+1n = 2k + 1. Then n2=(2k+1)2=4k2+4k+1=2(2k2+2k)+1n^2 = (2k+1)^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1Which is odd. \blacksquare

Worked Example. Prove: the sum of any two rational numbers is rational.

Solution

Let a=p/qa = p/q and b=r/sb = r/s where p,q,r,sZp, q, r, s \in \mathbb{Z} and q,s0q, s \neq 0. Then

a+b=pq+rs=ps+rqqsa + b = \frac{p}{q} + \frac{r}{s} = \frac{ps + rq}{qs}

Since ps+rqZps + rq \in \mathbb{Z} and qsZ0qs \in \mathbb{Z} \setminus \\{0\\}The sum a+ba + b is rational. \blacksquare

To prove P    QP \implies Q: prove ¬Q    ¬P\neg Q \implies \neg P instead.

Example. Prove: if n2n^2 is even, then nn is even.

Proof. Contrapositive: if nn is odd, then n2n^2 is odd. This was proved above. \blacksquare

Worked Example. Prove: if 3n+23n + 2 is odd, then nn is odd.

Solution

Contrapositive: if nn is even, then 3n+23n + 2 is even.

Let n=2kn = 2k. Then 3n+2=3(2k)+2=6k+2=2(3k+1)3n + 2 = 3(2k) + 2 = 6k + 2 = 2(3k + 1)Which is even. \blacksquare

To prove PP: assume ¬P\neg P and derive a contradiction.

Example (Euclid). There are infinitely many primes.

Proof. Suppose there are finitely many primes p1,p2,,pnp_1, p_2, \ldots, p_n. Consider N=p1p2pn+1N = p_1 p_2 \cdots p_n + 1. NN is not divisible by any pip_i (it leaves remainder 1). So NN is either prime itself or has a prime Factor not in the list. Either way, the list was incomplete. Contradiction. \blacksquare

Worked Example. Prove: 2\sqrt{2} is irrational.

Solution

Suppose 2=p/q\sqrt{2} = p/q in lowest terms, with p,qZ+p, q \in \mathbb{Z}^+ and gcd(p,q)=1\gcd(p, q) = 1. Then 2q2=p22q^2 = p^2 So p2p^2 is even, hence pp is even. Write p=2rp = 2r. Then 2q2=4r22q^2 = 4r^2 So q2=2r2q^2 = 2r^2Hence qq is even. But then both pp and qq are even, Contradicting gcd(p,q)=1\gcd(p, q) = 1. \blacksquare

Principle of Mathematical Induction. To prove P(n)P(n) for all nn0n \geq n_0:

  1. Base case: Prove P(n0)P(n_0).
  2. Inductive step: Prove P(k)    P(k+1)P(k) \implies P(k+1) for all kn0k \geq n_0.

Strong Induction. The inductive step assumes P(n0),P(n0+1),,P(k)P(n_0), P(n_0+1), \ldots, P(k) to prove P(k+1)P(k+1).

Example. Prove: i=1ni=n(n+1)/2\sum_{i=1}^{n} i = n(n+1)/2 for all n1n \geq 1.

Proof. Base case: n=1n = 1: 1=12/21 = 1 \cdot 2 / 2. True.

Inductive step: Assume i=1ki=k(k+1)/2\sum_{i=1}^{k} i = k(k+1)/2. Then

i=1k+1i=k(k+1)2+(k+1)=k(k+1)+2(k+1)2=(k+1)(k+2)2\sum_{i=1}^{k+1} i = \frac{k(k+1)}{2} + (k+1) = \frac{k(k+1) + 2(k+1)}{2} = \frac{(k+1)(k+2)}{2}

\blacksquare

Worked Example. Prove by strong induction: every integer n2n \geq 2 can be factored into primes.

Solution

Base case: n=2n = 2 is prime, so it is a (trivial) product of primes.

Inductive step: Assume every integer in 2,3,,k\\{2, 3, \ldots, k\\} factors into primes, where k2k \geq 2. Consider n=k+1n = k + 1.

If k+1k + 1 is prime, it is already a product of primes (itself).

If k+1k + 1 is composite, then k+1=abk + 1 = ab where 2abk2 \leq a \leq b \leq k. By the strong induction Hypothesis, both aa and bb factor into primes. Hence k+1=abk + 1 = ab also factors into primes.

\blacksquare

Worked Example. Prove: i=0n2i=2n+11\sum_{i=0}^{n} 2^i = 2^{n+1} - 1 for all n0n \geq 0.

Solution

Base case: n=0n = 0: 20=1=20+112^0 = 1 = 2^{0+1} - 1. ✓

Inductive step: Assume i=0k2i=2k+11\sum_{i=0}^{k} 2^i = 2^{k+1} - 1. Then

i=0k+12i=2k+11+2k+1=22k+11=2k+21\sum_{i=0}^{k+1} 2^i = 2^{k+1} - 1 + 2^{k+1} = 2 \cdot 2^{k+1} - 1 = 2^{k+2} - 1

\blacksquare

For recursively defined structures (lists, trees, formulas), prove a property by induction on the Structure:

  1. Base cases (empty list, leaf node, atomic formula).
  2. Inductive cases (cons, node with children, compound formula).

Well-Ordering Principle (WOP). Every nonempty set of nonnegative integers has a least element.

Theorem 3.1. The Well-Ordering Principle is equivalent to the Principle of Mathematical Induction.

Proof (WOP implies induction). Let P(n)P(n) be a property with P(0)P(0) true and P(k)    P(k+1)P(k) \implies P(k+1). Suppose for contradiction that P(n)P(n) fails for some n0n \geq 0. Let S = \\{n \geq 0 : P(n)\; \mathrm{is\; false{}\\}. By assumption SS \neq \emptyset So by WOP, SS has a least Element mm. Since P(0)P(0) is true, m1m \geq 1. Then P(m1)P(m - 1) is true (by minimality of mm), And P(m1)    P(m)P(m - 1) \implies P(m) by the inductive hypothesis, so P(m)P(m) is true, contradicting mSm \in S. Therefore S=S = \emptyset and P(n)P(n) holds for all n0n \geq 0.

Proof (induction implies WOP). Let SNS \subseteq \mathbb{N} be nonempty. We prove by induction that If S0,1,,nS \cap \\{0, 1, \ldots, n\\} \neq \emptyset Then SS has a least element. For n=0n = 0, SS Contains 00Which is the least element. Assume the claim for n=kn = k. If 0S0,,k+10 \in S \cap \\{0, \ldots, k+1\\} Then 00 is the least element. Otherwise S0,,k+1=S1,,k+1S \cap \\{0, \ldots, k+1\\} = S \cap \\{1, \ldots, k+1\\} And by The induction hypothesis applied to the shifted set, a least element exists. \blacksquare

Worked Example. Use the WOP to prove that every n1n \geq 1 can be written as a sum of distinct Powers of 2.

Solution

Let SS be the set of positive integers that cannot be written as a sum of distinct powers of 2. Suppose SS \neq \emptyset. By WOP, SS has a least element mm.

Let 2k2^k be the largest power of 2 not exceeding mm (so 2km<2k+12^k \leq m \lt 2^{k+1}). Then m2k0m - 2^k \geq 0 and m2k<2km - 2^k \lt 2^k. If m2k=0m - 2^k = 0 Then m=2km = 2^k is a single power of 2, Contradicting mSm \in S. If m2k>0m - 2^k \gt 0 Then m2k<mm - 2^k \lt m So m2kSm - 2^k \notin S (by minimality Of mm). Hence m2km - 2^k is a sum of distinct powers of 2, all of which are <2k\lt 2^k. Adding 2k2^k Gives mm as a sum of distinct powers of 2, contradicting mSm \in S. Therefore S=S = \emptyset. \blacksquare

flowchart TD
A[3_Proof Techniques] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]

Proof techniques establish mathematical truth. Direct proof assumes premises and derives conclusions. Proof by contradiction assumes the negation and finds a contradiction. Mathematical induction proves statements for all natural numbers by showing a base case and inductive step. These techniques are essential for verifying algorithm correctness, proving complexity bounds, and establishing security properties.

Circular reasoning in direct proofs. A proof is circular when the conclusion is assumed (even implicitly) in the premises. For example, proving “if nn is even then n2n^2 is even” by writing n=2kn = 2k so n2=4k2=2(2k2)n^2 = 4k^2 = 2(2k^2) is valid, but assuming n2n^2 is even to prove nn is even is not. Always verify that your assumptions do not presuppose the result.

Incorrect base case in mathematical induction. Students sometimes start induction at n=0n = 0 when the statement only holds for n1n \geq 1, or verify only one base case when the inductive step requires two (as with Fibonacci-type recurrences). Check that the base case matches the domain of the statement and that enough base cases are proven.

Confusing contrapositive with converse. The contrapositive of P    QP \implies Q is ¬Q    ¬P\neg Q \implies \neg P, which is logically equivalent to the original. The converse is Q    PQ \implies P, which is not equivalent. Proving the converse does not prove the original statement.

  • [[1-discrete-mathematics/1_propositional-and-predicate-logic]] - Logical foundations

  • [[1-discrete-mathematics/2_sets-relations-and-functions]] - Set-theoretic proofs

  • [[1-algorithms/algorithm_design]] - Algorithm correctness proofs

  • [[1-algorithms/complexity-theory]] - Complexity proofs

  • Discrete Mathematics

  • Algorithm Implementation