21
Discrete Mathematics in Computer Science A3. Proofs II Malte Helmert, Gabriele R¨ oger University of Basel Malte Helmert, Gabriele R¨oger (University of Basel) Discrete Mathematics in Computer Science 1 / 21

Discrete Mathematics in Computer Science - Proofs II

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Discrete Mathematics in Computer Science - Proofs II

Discrete Mathematics in Computer ScienceA3. Proofs II

Malte Helmert, Gabriele Roger

University of Basel

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 1 / 21

Page 2: Discrete Mathematics in Computer Science - Proofs II

Discrete Mathematics in Computer Science— A3. Proofs II

A3.1 Mathematical Induction

A3.2 Structural Induction

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 2 / 21

Page 3: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

A3.1 Mathematical Induction

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 3 / 21

Page 4: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Proof Techniques

most common proof techniques:

I direct proof

I indirect proof (proof by contradiction)

I contrapositive

I mathematical induction

I structural induction

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 4 / 21

Page 5: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Mathematical Induction

Concrete Mathematics by Graham, Knuth and Patashnik (p. 3)

Mathematical induction proves that

we can climb as high as we like on a ladder,

by proving that we can climb onto the bottom rung (the basis)

and that

from each rung we can climb up to the next one (the step).

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 5 / 21

Page 6: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Propositions

Consider a statement on all natural numbers n with n ≥ m.I E.g. “Every natural number n ≥ 2 can be written as a product

of prime numbers.”I P(2): “2 can be written as a product of prime numbers.”I P(3): “3 can be written as a product of prime numbers.”I P(4): “4 can be written as a product of prime numbers.”I . . .I P(n): “n can be written as a product of prime numbers.”I For every natural number n ≥ 2 proposition P(n) is true.

A proposition P(n) is a mathematical statement that is defined interms of natural number n.

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 6 / 21

Page 7: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Mathematical Induction

Mathematical Induction

Proof (of the truth) of proposition P(n)for all natural numbers n with n ≥ m:

I basis: proof of P(m)

I induction hypothesis (IH):suppose that P(k) is true for all k with m ≤ k ≤ n

I inductive step: proof of P(n + 1)using the induction hypothesis

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 7 / 21

Page 8: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Mathematical Induction: Example I

Theorem

For all n ∈ N0 with n ≥ 1:∑n

k=1(2k − 1) = n2

Proof.Mathematical induction over n:

basis n = 1:∑1

k=1(2k − 1) = 2− 1 = 1 = 12

IH:∑m

k=1(2k − 1) = m2 for all 1 ≤ m ≤ n

inductive step n→ n + 1:∑n+1

k=1(2k − 1) =

(∑n

k=1(2k − 1)

)+ 2(n + 1)− 1

IH= n2 + 2(n + 1)− 1

= n2 + 2n + 1 = (n + 1)2

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 8 / 21

Page 9: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Mathematical Induction: Example II

TheoremEvery natural number n ≥ 2 can be written as a product of primenumbers, i. e. n = p1 · p2 · . . . · pm with prime numbers p1, . . . , pm.

Proof.Mathematical Induction over n:

basis n = 2: trivially satisfied, since 2 is prime

IH: Every natural number k with 2 ≤ k ≤ nIH: can be written as a product of prime numbers. . . .

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 9 / 21

Page 10: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Mathematical Induction: Example II

TheoremEvery natural number n ≥ 2 can be written as a product of primenumbers, i. e. n = p1 · p2 · . . . · pm with prime numbers p1, . . . , pm.

Proof (continued).

inductive step n→ n + 1:

I Case 1: n + 1 is a prime number trivial

I Case 2: n + 1 is not a prime number.There are natural numbers 2 ≤ q, r ≤ n with n + 1 = q · r .Using IH shows that there are prime numbersq1, . . . , qs with q = q1 · . . . · qs andr1, . . . , rt with r = r1 · . . . · rt .Together this means n + 1 = q1 · . . . · qs · r1 · . . . · rt .

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 10 / 21

Page 11: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Weak vs. Strong Induction

I Weak induction: Induction hypothesis only supposesthat P(k) is true for k = n

I Strong induction: Induction hypothesis supposesthat P(k) is true for all k ∈ N0 with m ≤ k ≤ nI also: complete induction

Our previous definition corresponds to strong induction.

Which of the examples had also worked with weak induction?

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 11 / 21

Page 12: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Is Strong Induction More Powerful than Weak Induction?

Are there statements that we can prove with strong inductionbut not with weak induction?

We can always use a stronger proposition:

I “Every n ∈ N0 with n ≥ 2 can be written as a product ofprime numbers.”

I P(n): “n can be written as a product of prime numbers.”

I P ′(n): “all k ∈ N0 with 2 ≤ k ≤ n can be writtenP ′(n) “ as a product of prime numbers.”

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 12 / 21

Page 13: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Mathematical Induction

Reformulating Statements

It is sometimes convenient to rephrase a statement.

For example:

I “7n + 3n is divisible by 10 for all odd n ∈ N0.”I “For all n ∈ N0: if n is odd then 7n + 3n is divisible by 10.”

I P(n) = “if n is odd then 7n + 3n is divisible by 10.”I Need two base cases.I Case distinction (n even or odd) in inductive step

I “For all n ∈ N0: 7(2n+1) + 3(2n+1) is divisible by 10.”I P ′(n) = “7(2n+1) + 3(2n+1) is divisible by 10.”

Be careful about how to reformulate a statement!

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 13 / 21

Page 14: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

A3.2 Structural Induction

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 14 / 21

Page 15: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Inductively Defined Sets: Examples

Example (Natural Numbers)

The set N0 of natural numbers is inductively defined as follows:

I 0 is a natural number.

I If n is a natural number, then n + 1 is a natural number.

Example (Binary Tree)

The set B of binary trees is inductively defined as follows:

I � is a binary tree (a leaf)

I If L and R are binary trees, then 〈L,©,R〉 is a binary tree(with inner node ©).

Implicit statement: all elements of the set can be constructedImplicit statement: by finite application of these rules

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 15 / 21

Page 16: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Inductive Definition of a Set

Inductive DefinitionA set M can be defined inductively by specifying

I basic elements that are contained in M

I construction rules of the form“Given some elements of M, another element of Mcan be constructed like this.”

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 16 / 21

Page 17: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Structural Induction

Structural InductionProof of statement for all elements of an inductively defined set

I basis: proof of the statement for the basic elements

I induction hypothesis (IH):suppose that the statement is true for some elements M

I inductive step: proof of the statement for elementsconstructed by applying a construction rule to M(one inductive step for each construction rule)

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 17 / 21

Page 18: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Structural Induction: Example (1)

Definition (Leaves of a Binary Tree)

The number of leaves of a binary tree B, written leaves(B),is defined as follows:

leaves(�) = 1

leaves(〈L,©,R〉) = leaves(L) + leaves(R)

Definition (Inner Nodes of a Binary Tree)

The number of inner nodes of a binary tree B, written inner(B),is defined as follows:

inner(�) = 0

inner(〈L,©,R〉) = inner(L) + inner(R) + 1

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 18 / 21

Page 19: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Structural Induction: Example (2)

Theorem

For all binary trees B: inner(B) = leaves(B)− 1.

Proof.induction basis:inner(�) = 0 = 1− 1 = leaves(�)− 1

statement is true for base case . . .

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 19 / 21

Page 20: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Structural Induction: Example (3)

Proof (continued).

induction hypothesis:to prove that the statement is true for a composite tree 〈L,©,R〉,we may use that it is true for the subtrees L and R.

inductive step for B = 〈L,©,R〉:

inner(B) = inner(L) + inner(R) + 1

IH= (leaves(L)− 1) + (leaves(R)− 1) + 1

= leaves(L) + leaves(R)− 1 = leaves(B)− 1

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 20 / 21

Page 21: Discrete Mathematics in Computer Science - Proofs II

A3. Proofs II Structural Induction

Structural Induction: Exercise

Definition (Height of a Binary Tree)

The height of a binary tree B, written height(B),is defined as follows:

height(�) = 0

height(〈L,©,R〉) = max{height(L), height(R)}+ 1

Prove by structural induction:

Theorem

For all binary trees B: leaves(B) ≤ 2height(B).

Malte Helmert, Gabriele Roger (University of Basel)Discrete Mathematics in Computer Science 21 / 21