CS104 : Discrete Structures - PowerPoint PPT Presentation

1 / 49
About This Presentation
Title:

CS104 : Discrete Structures

Description:

CS104 : Discrete Structures Chapter III Proof Techniques * Prepared by Dr. Zakir H. Ahmed * – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 50
Provided by: Dr23361
Category:

less

Transcript and Presenter's Notes

Title: CS104 : Discrete Structures


1
CS104 Discrete Structures
Chapter III Proof Techniques
2
Rules of Inference Valid Arguments in
Propositional Logic
  • Argument An argument is a sequence of statements
    that end with a conclusion.
  • Valid An argument is valid if and only if it is
    impossible for all premises (preceding
    statements) to be true and the conclusion to be
    false. By valid, we mean that the conclusion of
    the argument must follow from the truth of the
    premises of the argument.
  • Consider the arguments
  • If you have a current password, then you can
    log onto the network.
  • You have a current password.
  • Therefore,
  • You can log onto the network.

3
Rules of Inference Valid Arguments in
Propositional Logic
  • The conclusion You can log onto the network
    must be true when the premises If you have a
    current password, then you can log onto the
    network and You have a current password are
    true.
  • Let p You have a current password.
  • and qYou can log onto the network. Then the
    argument has the form
  • where ? is the symbol that denotes therefore.
  • The statement ((p ? q) p) ? q is a tautology.

p ? q p ? q
4
Rules of Inference Rule for Propositional Logic
  • The argument form with premises p1, p2, ., pn
    and conclusion q is valid, when (p1p2.pn) ? q
    is a tautology.
  • To show that an argument is valid, instead of
    showing by truth table, we can establish the
    validity of some relatively simple argument
    forms, called rules of inference, which can be
    used as building blocks to construct more
    complicated valid argument forms.
  • The tautology ((p ? q) p) ? q is the basis of
    the rule of inference called modus ponens or law
    of detachment.

5
Rules of Inference Rules for Propositional Logic
  • Example Suppose that the conditional statement
    If it snows today, then we will go skiing and
    its hypothesis It is snowing today, are true.
    Then by modus ponens, it follows that the
    conclusion of the conditional statement, We will
    go skiing is true.
  • Q1 Determine whether the argument given here is
    valid and determine whether its conclusion must
    be true because of the validity of the argument.

6
Rules of Inference Rules for Propositional Logic
7
Rules of Inference Rule for Propositional Logic
  • Example State which rule of inference is the
    basis of the following argument It is below
    freezing now. Therefore, it is either below
    freezing or raining now.
  • Sol Let p It is below freezing now. and q
    It is raining now. Then this argument is of the
    form
  • p
  • ?p v q
  • This is an argument that uses the addition rule.
  • Q2 State which rule of inference is the basis of
    the following argument It is below freezing and
    raining now. Therefore, it is below freezing.

8
Introduction to Proofs
  • A theorem is a statement that can be shown to be
    true (usually important statement)
  • Less important theorem sometimes are called
    propositions
  • A proof is a sequence of statements (valid
    argument) to show that a theorem is true
  • The statements to be used in proofs include
  • Axioms (statement assumed to be true without
    proof)
  • Ex If x is positive integer then x1 is positive
    integer.
  • Hypothesis (premises) of the theorem
  • Previously proven theorems
  • Rules of inference used to draw conclusions and
    to move from one step to another

9
Introduction to Proofs
Axioms
Rules of inference
New theorem
Hypothesis
proven theorems
  • A less important theorem that is helpful in the
    proof of other results is called a lemma
  • A corollary is a theorem that can be established
    directly from a theorem that has been proved
  • A conjuncture is a statement that is being
    proposed to be a true statement, usually on the
    basis of some partial evidence
  • When a proof of a conjuncture is found, the
    conjuncture becomes a theorem

10
Introduction to Proofs
  • Example 1 If I have a car (C) I will drive to
    Makkah (M). My boss gave me 60,000 (G) or Fired
    me (F). If I have SR60,000 (H) then I have a car
    (C). My boss did not fire me. Therefore I will
    drive to Makkah (M).
  • G?F Hypothesis
  • ?F Hypothesis
  • G Disjunctive syllogism rule using 1 and
    2
  • G?H Axiom ?
  • H ?C Hypothesis
  • G ?C Hypo. syllogism using 4,5
  • C Modus ponens using 3 and 6
  • C ?M Hypothesis
  • M Modus ponens using 7 and 8

11
Methods of proving theoremsDirect proofs
  • A direct proof of a conditional statement p?q is
    constructed when the first step is the assumption
    that p is true subsequent steps are constructed
    using rules of inference, with the final step
    showing that q must also be true
  • In a direct proof, we assume that p is true and
    use axioms, definitions, and previously proven
    theorems, together with rules of inference, to
    show that q must also be true
  • Def The integer n is even if there exists an
    integer k such that n 2k, and n is odd if there
    exists an integer k such that n 2k 1.

12
Methods of proving theoremsDirect proofs
  • Example 2 Use a direct proof to show that if n
    is even then n2 is even
  • Proof Assume that n is even (hypothesis)
  • gt n 2k where k is integer (definition of even
    number)
  • gt n2 (2k)2 4k2 2(2k2) (By squaring)
  • Since r 2K2 is integer (Axiom)
  • gt n2 2r is even
  • Q 3 Use a direct proof to show that if n is odd
    then n2 is odd

13
Methods of proving theoremsProof by
contraposition
  • An indirect proof of a conditional statement p ?q
    is a direct proof of its contraposition ?q ? ?p.
  • Example 3 Use an indirect proof to show that if
    a and b are integers, and (a b) 15, then a
    8 or b 8.
  • Proof The contraposition of (a b 15) ? (a
    8) v (b 8) is (a lt 8) ? (b lt 8) ? (a b lt 15)
  • Suppose (a lt 8) ? (b lt 8) (hypothesis).
  • gt (a 7) ? (b 7),
  • gt (a b) 14,
  • gt (a b) lt 15.

14
Methods of proving theoremsProof by
contraposition
  • Example 4 Use an indirect proof to show that if
    n2 is even then n is even
  • Proof The contraposition is if n is not even
    then n2 is not even
  • Assume that n is not even i.e., n is odd
    (hypothesis)
  • gt n 2k1 where k is integer (definition of
    odd number)
  • gt n2 (2k 1)2
  • 4k2 4k 1
  • 2(2k2 2k) 1 2r 1, where r 2k2
    2k
  • Since r is integer (Axiom) gt n2 is not even
  • Q 4 Use an indirect proof to show that if n is
    odd then n2 is odd

15
Methods of proving theoremsProof by
contraposition
  • Example 5 Prove that if n ab then a ? ?n or b
    ? ?n where a and b are positive integers
  • Proof Let pa??n, qb??n and rnab
  • We want to prove that r? p?q
  • gt The contraposition is ?(p?q ) ? ? r (By
    definition)
  • gt ?p ? ?q ? ? r (De Morgans law)
  • Now, assume that a??n and b??n (?p ? ?q)
  • gt a.b ? ?n.?n n (by multiplying above twos)
  • gt ab ? n
  • gt ? r

16
Methods of proving theoremsVacuous Proofs
  • Vacuous Proofs A conditional
  • statement p ? q is TRUE
  • if p is FALSE. If we can show
  • that p is False, then we have
  • a proof, called vacuous proof,
  • of the conditional statement p ? q
  • Example 6 Prove that if x2 ? 0 then 12 where x
    is a real number
  • Proof Since x2 ? 0 for every real number then
    the implication is vacuously true
  • Example 7 Prove that if he is alive and he is
    dead then the sun is ice cold.
  • Proof Since the hypothesis is always false the
    implication is vacuously true.

p q p ? q
F F T T F T F T T T F T
17
Methods of proving theoremsTrivial Proofs
  • Trivial Proofs A conditional
  • statement p ? q is TRUE if q
  • is TRUE. If we can show that
  • q is TRUE, then we have a
  • proof, called trivial proof, of
  • the conditional statement p ? q
  • Example 8 Prove that if x2 then x2 ? 0 for all
    real numbers
  • Proof Since x2 ? 0 is true then the implication
    is trivially true. (we didnt use the fact x2)
  • Q 5 Use a trivial proof to show that if n gt 1
    then n2 n for all integers

p q p ? q
F F T T F T F T T T F T
18
Methods of proving theoremsProofs by
Contradiction
  • Proof by Contradiction To prove a proposition p,
    assume not p and show a contradiction.
  • Example 9 Use a proof by contradiction to show
    that ?2 is irrational
  • Proof Let ?2 is rational
  • gt ?2 a/b for some integers a and b (b?0)
    (relatively prime).
  • (Definition of rational numbers)
  • gt 2 a2/b2 (Squaring both sides)
  • gt 2b2 a2
  • gt a2 is even (Definition of even numbers)
  • gt a is even (a 2k for some k)
  • gt 2b2 a2 (2k)2 4k2
  • gt b is even (Definition of even numbers)
  • But if a and b are both even, then they are not
    relatively prime!
  • Hence, ?2 is irrational

19
Methods of proving theoremsProofs by
Contradiction
  • Why is this method valid ?
  • The contradiction forces us to reject our
    assumption because our other steps based on that
    assumption are logical and justified. The only
    mistake that we could have made was the
    assumption itself.
  • Be careful!
  • Sometimes the contradiction comes from a mistake
    in the steps of the proof and not from the
    assumption. This makes the proof invalid.
  • Example 10 Prove that 12
  • Proof Suppose that 2?1 and ab for some a.
  • gt 2b ?b multiply by b
  • gt ab ?b 2bbbab by hypothesis
  • gt (a-b)(ab) ? b(a-b) multiply by a-b
  • gt a2-b2 ? ab-b2
  • gt a2 ?ab subtract b2
    from both sides
  • gt a ?b which contradicts our assumption that
    ab
  • Hence it follows that 12
  • Can you find the error ?

20
Methods of proving theoremsProofs by
Contradiction
  • To prove a conditional statement p ? q by
    contradiction we prove that p ? ?q? F is true
    which is equivalent to p ? q .
  • Example 11 Use a proof by contradiction to show
    that If 3n2 is odd then n is odd
  • Proof Suppose that 3n2 is odd and n is even p
    ? ?q
  • gt n 2r hypothesis ?q, definition of
    even numbers
  • gt 3n 6r multiply 1 by 3
  • gt 3n226r add 2 to both sides
  • gt 3n22(13r)
  • gt 3n22k let k13r
  • gt Thus 3n2 is even which is false (a
    contradiction !)
  • Therefore the implication is true.

21
Methods of proving theoremsProofs of Equivalence
  • Proofs of Equivalence To prove p ?q we have to
    prove p ? q and q ? p
  • Example 12 prove n is even if and only if n2 is
    even
  • if n is even then n2 is even proved in example
    2
  • n2 is even then n is even proved in example 4
  • Therefore, n is even if and only if n2 is even
  • Proving equivalence of several propositions If
    we want to prove that p1? p2 ? p3 ? pn
  • Then it is sufficient to prove p1 ? p2,, p2 ? p3
    pn ? p1
  • Disproof by Counterexample
  • Example 13 Prove that For all real numbers x2 gt
    x is false
  • Proof X0.5 is a counterexample since 0.52 gt 0.5
    is not true
  • Q 6 Prove that If n is not positive, then n2 is
    not positive is false

22
Methods of proving theorems Proof by Cases
  • Proof by Cases A proof by cases must cover all
    possible cases that arise in a theorem. Each case
    may cover an infinite number of instances
  • Example 15 Prove "if n is an integer then n2
    n".
  • Proof We can prove that n2 n for every integer
    by considering three cases, when n 0, when n
    1, and when n -1.
  • Case 1 When n 0, since 02 0, 02 gt 0. So,
    n2 n is true.
  • Case 2 When n 1, From n 1, we get n2 n
    (by multiplying with n).
  • Case 3 When n -1, since n is negative, n2 is
    positive, so n2 n.
  • Hence, if n is an integer then n2 n.
  • Q 7 Prove that xy xy, where x and y real
    numbers.
  • Hint Consider all 4 cases x and y positive or
    negative
  • Common errors with exhaustive proof and proof by
    cases
  • Draw conclusion from non-exhaustive examples
  • Not covering all possible cases

23
Methods of proving theorems Existence Proofs
  • Many theorems state that an object with certain
    properties exists, i.e., ?xP(x) where P is a
    predicate. A proof of such a theorem is called an
    existence proof. There are two kinds
  • Constructive Existence Proof The proof is
    established be giving example a such that P(a) is
    true
  • Example 16 Prove "there is a positive integer
    that can be written as the sum of cubes in two
    different ways.
  • Proof Consider 17291039312313. Finding such
    examples may require computer assistance.
  • Non-constructive Existence Proof The proof is
    established by showing that an object a with P(a)
    is true must exist without explicitly
    demonstrating one. Proofs by contradiction are
    usually used in such cases.

24
Methods of proving theorems Existence Proofs
  • Example 17 Let x1,x2,..,xn be positive integers
    such that their average is m. prove that there
    exists xi such that xi m
  • Proof Suppose that there is no such number,
    i,e.,
  • x1 ? m, x2 ? m, , xn ? m
  • By adding these inequalities we get x1 x2
    xn ? nm
  • Dividing by n (x1 x2 xn)/n ? m
  • But since the average is defined as (x1 x2
    xn)/n
  • Then we have m ? m which is a contradiction.
  • Therefore there must be a number xi such that xi
    m. But we can not specify which number is that.

25
Methods of proving theorems Uniqueness Proofs
  • Some theorems state that there is exactly one
    element with a certain property. A proof of such
    a theorem is called a uniqueness proof.
  • Strategy here is (1) show that an element x with
    the desired property exists (2) show that any
    other y (y ! x) does not have the property,
    i.e., if x and y both have the property, then x
    must equal y.
  • Example 18 Prove that the equation 3x5 9 has
    a unique solution.
  • Proof (1) There exists a solution namely x 4/3
  • (2) Suppose that y and z are solution then
  • 3y5 9 3z5
  • So 3y 3z
  • Dividing by 3 we get y z
  • This proves that the solution is unique

26
Methods of proving theoremsMathematical
Induction
  • Principle of Mathematical Induction
  • Let P(n) be a statement for all the positive
    integers (n 1, 2, 3, . .). If the following two
    properties hold
  • P(1) is true.
  • P(k1) is true if P(k) is true for each positive
    integer k.
  • Then P(n) is true for all n.
  • First part is a simple proposition we call the
    base step
  • Second part is an inductive step. Start by
    assuming P(k) is true, and show that P(k1) is
    also true
  • The assumption that P(k) is true called the
    inductive hypothesis
  • So, we prove that
  • (P(1) ? ?k (P(k) ? P(k1))) ? (?n P(n))

27
Methods of proving theoremsMathematical
Induction
  • Example 19 Suppose we have an infinite ladder,
    and we want to know whether we can reach every
    step on this ladder. We know two things
  • We can reach the first rung of the ladder
  • If we can reach a particular rung of the ladder,
    then we can reach the next rung.
  • How does Induction Work?
  • Consider the above example. The rules for
    reaching steps can help you remember how
    induction works
  • Statements (1) and (2) are the basic step and
    inductive step respectively of the proof that
    P(n) is true for all positive integers n, where
    P(n) is the statement that we can reach the nth
    rung of the ladder.
  • Consequently, we can invoke the mathematical
    induction to conclude that we can reach every
    rung of the ladder

28
Methods of proving theoremsMathematical
Induction
  • Example 20 (A Summation Problem) Prove that for
    any integer n 1 1 2 3 n
    n(n1)/2 .
  • Proof Let P(n) be the proposition that the sum
    of the first n positive integers is n(n1)/2.
    Then to proof that P(n) is true for all n 1, we
    have to show that P(1) is true and P(k1) is true
    if P(k) is true for k 1.
  • Basic step P(1) is true, because 1 1.(11)/2
  • Inductive step Let us assume that it is true
    for n k, that is, 123..k k(k1)/2
  • Now, if we can prove that it is true for n k1
    also, then it can be said that it is true for all
    n.
  • For, 1 2 k (k 1)
  • k(k 1)/2 (k 1)
  • (k 1)(k/2 1)
  • (k 1)(k 2)/2
  • gt P(k 1) is also true, hence P(n) is true for
    all integer n.

29
Methods of proving theoremsMathematical
Induction
  • Example 21 Use induction to prove that the sum
    of the first n odd integers is n2.
  • Proof Let P(n) be the proposition that the sum
    of the first n odd integers is n2. Then to proof
    that P(n) is true for all n 1, we have to show
    that P(1) is true and P(k1) is true if P(k) is
    true for k 1.
  • Basic step P(1) is true, because the sum of the
    first 1 odd integer is 12.
  • Inductive step Assume P(k) the sum of the
    first k odd integers is k2, that is, 1 3
    (2k - 1) k2
  • Now, if we can prove that it is true for n k1
    also, then it can be said that it is true for all
    n.
  • For, 1 3 (2k-1) (2k1)
  • k2 (2k 1)
  • (k1)2
  • gt P(k 1) is also true, hence P(n) is true for
    all integer n.

30
Methods of proving theoremsMathematical
Induction
  • Q 8 Use induction to prove that
  • 1?1! 2?2! n?n! (n1)! - 1, ?n
  • Q 9 Use induction to prove that for all n,
  • Q 10 Use induction to prove that for all n,

31
Methods of proving theoremsMathematical
Induction
  • Example 22 Use induction to prove the inequality
    n lt 2n, ?n gt 0.
  • Proof Let P(n) be the proposition that n lt 2n
  • Basic step P(1) is true, because 1 lt 21 2.
  • Inductive step Assume P(k) is true, that is, k
    lt 2K
  • Now, if we can prove that it is true for n k1
    also, then it can be said that it is true for all
    n.
  • For, k lt 2K
  • gt k 1 lt 2K 1
  • 2K 2K
  • 2. 2K
  • 2K1
  • gt k 1 lt 2K1
  • gt P(k 1) is also true, hence P(n) is true for
    all integer n.
  • Q 11 Use induction to prove the inequality 2n lt
    n! ?n gt 3.

32
Methods of proving theorems Recursive
Definitions
  • Recursion Sometimes it is difficult to define an
    object explicitly. However, it may be easy to
    define this object in terms of itself. This
    process is called recursion.
  • Recursive defined functions We use two steps to
    define a function with the nonnegative integers
    as its domain
  • Basis Step Specify the value of the function at
    zero.
  • Recursive Step Give a rule for finding its
    value at an integer from its values at smaller
    integers.
  • Such definition is called a recursive or
    inductive definition.
  • Example 25 The definition of factorial function
  • n! 1 2 3 (n-1) n, n ? 1
  • But equivalently, we could define it like this

33
Methods of proving theorems Recursive
Definitions
  • Example 26 The definition of Fibonacci Numbers

34
Methods of proving theorems Recursive
Definitions
  • Example 27 Suppose that f is defined by
  • f(0) 3,
  • f(n1) 2f(n) 3.
  • Find f(1), f(2), f(3), and f(4).
  • Solution From the recursive definition, it
    follows that
  • 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.
  • Example 28 Give a recursive definition of
  • Solution The first and second part of the
    recursive definition are

35
Methods of proving theorems Recursive
Definitions
  • Example 29 Give an inductive definition of S
    x x is a multiple of 3
  • Solution
  • 3 ? S
  • x,y ? S ? x y ? S
  • x,y ? S ? x - y ? S
  • No other numbers are in S.
  • Q 12 Find the Fibonacci numbers f(2), f(3),
    f(4), f(5), and f(6).
  • Q 13 Give an inductive definition of an.

36
Methods of proving theorems Recursive
Definitions
  • Recursively Defined Sets and Structures Sets can
    be defined recursively. Recursive definition of
    sets have two part basis step and recursive
    step.
  • Basis Step An initial collection of elements is
    specified.
  • Recursive Step Rules for forming new elements
    in the set from those already known to be in the
    set are provided.
  • Example 30 Consider subset S of the set of
    integers defined by
  • Basis Step 3? S.
  • Recursive Step If x, y ? S then x y ? S .
  • The new elements found to be in S are 3 by the
    basis step,
  • 336 at the first application of the recursive
    step,
  • 36639 at the second application of the
    recursive step,
  • 6612 at the third application of the recursive
    step, and so on.
  • We will show later that S is set of all positive
    multiples of 3.

37
Recursive DefinitionsRecursively Defined Sets
  • Example 31 The set of Natural Numbers N can be
    defined recursively as follows
  • 1?N basis
    step
  • If x ?N then x1?N Recursive step
  • Lets try to constructs the set using this
    definition
  • 1 in N basis step
  • 112 in N Recursive step
  • 213 in N Recursive step
  • Etc

38
  • Algorithms

39
AlgorithmsDefinitions
  • The word algorithm comes from the name of a
    Persian author, Abu Jafar Mohammad Ibn Musa Al
    Khowarizmi (825 AD).
  • Definition An algorithm is a finite set of
    instructions that, if followed, carries out a
    particular task. In addition, all algorithms must
    satisfy the following criteria
  • Input Zero or more quantities are externally
    supplied.
  • Output At least one quantity is produced.
  • Definiteness Each instruction is clear and
    unambiguous.
  • Finiteness If we trace out the instructions of
    an algorithm, then for all cases, the algorithm
    terminates after a finite number of steps.
  • Effectiveness Every instruction must be very
    basic so that it can be carried out, in
    principle, by a person using only pen and paper.
    It must be feasible.

40
Study of Algorithms
  • How to devise algorithms?
  • Creating an algorithm is an art which may never
    be fully automated.
  • How to validate algorithms?
  • Once an algorithm is devised, it is necessary to
    show that it computes the correct answer for all
    possible legal inputs.
  • A program can be written and then be verified.
  • How to test a program?
  • Debugging is the process of executing programs on
    sample data sets to determine whether the faulty
    results occur and, if so, to correct them.
  • Profiling is the process of executing a correct
    program on data sets and measuring the time and
    space it takes to compute the results.

41
Pseudocode Conventions
  • Comments begin with // and continue until the end
    of line.
  • Blocks are indicated with matching braces and.
  • An Identifier begins with a letter max.
  • Assignment of values to variables is done using
    assignment statement Variableexpression.
  • Logical operators and, or and not are provided.
  • Relational operators lt, , , ?, and gt
    provided.
  • Elements of arrays are accessed using and .
  • While loop
  • while (condition) do
  • statements

42
Pseudocode Conventions
  • For loop
  • for variablevalue1 to value2 step
    step do
  • Statements
  • Repeat-until loop
  • repeat
  • Statements
  • until (condition)
  • Conditional statement
  • if (condition) then (statement)
  • if (condition) then (statement 1)
  • else (statement 2)

43
Pseudocode Conventions
  • Case statement
  • case
  • (condition 1) (statement 1)
  • .
  • (condition n) (statement n)
  • else (statement n1)
  • Input and output are done using read and write.
  • There is only one type of procedure Algorithm.
  • An algorithm consists of a heading and a body.
  • The heading of an algorithm takes the form
  • Algorithm Name ((parameter list))

44
Finding Maximum Value
  • Input A sequence of n numbers (a1, a2,, an).
  • Output Maximum of (a1, a2,, an).
  • Algorithm Maximum(A, n)
  • MaxA1
  • for i2 to n do
  • if ( Max lt Ai) then
  • MaxAi

45
Sorting Problem
  • Input A sequence of n numbers (a1, a2,, an).
  • Output A permutation of n numbers (reordering)
    (a'1, a'2,, a'n) of the input sequence such that
    a'1 a'2 a'n.
  • Bubble Sort-
  • It is a popular sorting algorithm
  • It swaps adjacent elements that are out of order
  • Insertion sort-
  • Insert an element to a sorted array such that the
    order of the resultant array be not changed.

46
Bubble Sort Algorithm
  • Bubble sort
  • Algorithm BubbleSort (A, n)
  • for i1 to n-1 do
  • for j n downto i1 do
  • if ( AjltAj-1) then
  • exchange Aj ? Aj-1

47
Bubble Sort Algorithm
48
Insertion Sort Algorithm
  • Insertion sort
  • Algorithm InsertionSort (A, n)
  • for i2 to n do
  • keyAi
  • // Insert Ai into the sorted
    sequence A1i-1.
  • ji-1
  • while ( (jgt0) and (Ajgtkey) ) do
  • Aj1Aj
  • jj-1
  • Aj1key

49
  • End of Chapter III
Write a Comment
User Comments (0)
About PowerShow.com