Discrete Mathematics and Its Application - Chapter 4
Discrete Mathematics and Its Application - Chapter 4
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2011
Proof Strategy (4.1)
• Introduction
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
2 CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
• Proof Strategies
– Proof of a statement
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
3 CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
– Example: p q
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
4 CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
5 CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
6 CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
– Example:
Conjecture: Do other primes of the special form an –1, where a
and n are positive integers, exist?
26 –1 = 63, 28 –1 = 255
34 –1 = 80, 45 –1 = 1023
10 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
• Theorem 1:
12 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
13 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
– Theorem 2:
14 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
x
if x is an even integer
f ( x ) 2
3x 1 if x is an odd integer
15 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 1)
Proof Strategy (4.1) (cont.)
x = 13 f(13) = 3 * 13 + 1 = 40
x = 40 f(40) = 40/2 = 20
x = 20 f(20) = 20/2 = 10
x = 10 f(10) = 10/2 = 5
x = 5 f(5) = 3 * 5 + 1 = 16
x = 16 f(16) =16/2 = 8
x = 8 f(8) = 8/2 = 4
x = 4 f(4) = 4/2 =2
x = 2 f(2) = 1
17 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 1)
Chapter 4 (Part 2):
Mathematical Reasoning, Induction
& Recursion
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2011
Introduction
• Define an object in
terms of itself: this
process is called
recursion
19 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 2)
Introduction (cont.)
20 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 2)
Recursively Defined Functions
• We use 2 steps to define a function
recursively:
– Such a definition
© by Kenneth is called a recursive or 20112)
21 H. Rosen, Discrete Mathematics
CS 210 Discrete&Structures, its Applications, Seventh Edition, Mc Graw-Hill,
Chapter 4 (Part
Recursively Defined Functions (cont.)
Solution: by definition:
f(1) = 2f(0) + 3 = 2 * 3 + 3 = 9
f(2) = 2f(1) + 3 = 2 * 9 + 3 = 21
f(3) = 2f(2) + 3 = 2 * 21 + 3 = 45
f(4) = 2f(3) + 3 = 2 * 45 + 3 = 93
22 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 2)
Recursively Defined Functions (cont.)
Solution:
Basis step: Specify the initial value of
this function; f(0) = 1.
ak of
• Example: Give a recursive definition
k 0
Solution:
0
a k a0
Basis step:
k 0
n 1
n
k 0
ak ak an 1
k 0
Recursive step:
24 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 2)
Recursively Defined Functions (cont.)
• Definition 1:
25 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CS 210 Discrete Structures, Chapter 4 (Part 2)
Recursively Defined Functions (cont.)
Solution:
Basis step: f0 = 0 and f1 = 1
Recursive step: fn = fn-1 + fn-2
f2 = f1 + f0 = 1 + 0 = 1
f3 = f2 + f1 = 1 + 1 = 2
f4 = f3 + f2 = 2 + 1 = 3
f5 = f4 + f3 = 3 + 2 = 5
26 © by Kenneth H.CS f6 =Discrete
f5 + f4 =Structures,
5 + 3 = 8 Chapter 4 (Part 2)
Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
210
Recursively Defined Functions (cont.)
3 S (basis step)
3 S 3 S 3 + 3 = 6 S (recursive
step)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
27 CS 210 Discrete Structures, Chapter 4 (Part 2)
Recursively Defined Functions (cont.)
• Definition 2:
Example: if = {0, 1}
Basis step: *
Recursive step: 0, 1 (0 *, 1 *)
Recursive step: 00 01 10 11 *
28 © by Kenneth H.CS
Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
210 Discrete Structures, Chapter 4 (Part 2)
Recursively Defined Functions (cont.)
• Definition 3
Two strings can be combined via the operation of
concatenation. Let be a set of symbols and * the set of
strings formed from symbols in . We can define the
concatenation of two strings, denoted by recursively as
follows:
• Definition 4
Step 1
Step 2
… …
31 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
Chapter 4 (Part 3):
Mathematical Reasoning, Induction
& Recursion
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2011
Recursive Algorithm (4.4)
• Goal: Reduce the solution to a problem
with a particular set of input to the
solution of the same problem with smaller
input values
33 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
• Definition 1:
Solution:
©
an+1 = a*an for n>0 a 0 = 1
34 by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
35 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
Solution:
gcd(a,b) = gcd(b mod a, a)
and the condition gcd(0,b) = b (b>0).
36 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
37 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
• Example: Express the linear search as a
recursive procedure: search x in the search
sequence
aiai+1… aj.
procedure search(i, j, x)
if ai = x then
location := i
else if i = j then
location := 0
38else
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
39 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
40 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
41 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
42 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Recursive algorithm (4.4) (cont.)
• Program verification
46 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Program Correctness (4.5) (cont.)
– Definition 1:
Solution:
© by Kenneth H.pRosen,
is Discrete x& =
trueMathematics 1 Seventh 2
y :=Edition, z :=2011 3
48 its Applications,
CSE 504 Discrete Structures & Foundations of Mc Graw-Hill,
Program Correctness (4.5) (cont.)
• Rules of inference
– Goal: Split the program into a series of
subprograms and show that each
subprogram is correct. This is done through
a rule of inference.
– It is written as:
© by Kenneth
50 H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Program Correctness (4.5) (cont.)
• Conditional Statements
Strategy:
a) We© bymust show Discrete that when p is trueEdition,and
51 Kenneth H. Rosen, Mathematics & its Applications,
CSE 504 Discrete Structures & Foundations ofSeventh Mc Graw-Hill, 2011
Program Correctness (4.5) (cont.)
– We can summarize the conditional statement as:
(p condition) {S}q
(p condition) q
Solution:
a) If T = true
52 ©and x>y
by Kenneth
CSEisDiscrete
H. Rosen, true
504 then
Mathematics
Discrete the final
& its Applications,
Structures &assertion
Seventh Edition, y of
Mc Graw-Hill, 2011
Foundations
Program Correctness (4.5) (cont.)
2. “if condition then S1 else S2”
if condition is true then S1 executes; otherwise
S2 executes
(p condition) {S1}q
(p condition) {S2}q
© by Kenneth H. Rosen, Discrete Mathematics &
53 its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Program Correctness (4.5) (cont.)
Solution:
a) If T = true and (x<0) = true abs := -x;
compatible
© by Kenneth H. Rosen,with definition of Seventh
absEdition, Mc Graw-Hill, 2011
54 Discrete Mathematics & its Applications,
CSE 504 Discrete Structures & Foundations of
Program Correctness (4.5) (cont.)
• Loop invariants
– In this case, we prove codes that contain the
while loop: “while condition S”
i := 1
factorial := 1
While i < n
begin
i := i + 1
Rosen,factorial := Seventh
factorial Mc Graw-Hill, 2011*
56 © by Kenneth H.CSE Discrete Mathematics & its Applications,
504 Discrete Structures &Edition,
Foundations of
Program Correctness (4.5) (cont.)
Solution:
57 © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
CSE 504 Discrete Structures & Foundations of
Program Correctness (4.5) (cont.)
a) P is a loop invariant:
factorial = i! i < n
inew = i + 1
• Historic
• Introduction (5.1)
• Discrete Theory (5.2)
• Expected Value &
Variance (5.3)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2011
61
Historic
• The theory of probability was first developed
more than three hundred years ago by Blaise
Pascal for gambling purposes
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Seventh Edition, Mc Graw-Hill, 2011
Dr. Djamel CSE 504 Discrete Structures & Foundations of
62
Historic (cont.)