Discrete Mathematics - NCKUmyweb.ncku.edu.tw/~hykao/course/dm/2009/slides/DMCH4.pdf · 自然數...

64
Discrete Mathematics Ch t 4P ti f th -- Chapter 4: Properties of the Integers: Mathematical Induction Hung-Yu Kao (高宏宇) Department of Computer Science and Information Engineering, N l Ch K U National Cheng Kung University

Transcript of Discrete Mathematics - NCKUmyweb.ncku.edu.tw/~hykao/course/dm/2009/slides/DMCH4.pdf · 自然數...

  • Discrete MathematicsCh t 4 P ti f th-- Chapter 4: Properties of the

    Integers: Mathematical Induction

    Hung-Yu Kao (高宏宇)Department of Computer Science and Information Engineering,

    N l Ch K UNational Cheng Kung University

  • Outline

    4.1 The Well-Ordering Principle: Mathematical InductionInduction4.2 Recursive Definitions

    h i i i l i h i b4.3 The Division Algorithm: Prime Numbers4.4 The Greatest Common Divisor: The Euclidean Algorithm4 5 The fundamental Theorem of Arithmetic4.5 The fundamental Theorem of Arithmetic

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 2

  • 自然數

    自然數要適合五點(Peano axioms):有一起始自然數 0。有一起始自然數 0任一自然數 a 必有後繼,記作 a +1。0並非任何自然數的後繼0 並非任何自然數的後繼。不同的自然數有不同的後繼。

    (數學歸納公設)有一與自然數有關的命題 設此(數學歸納公設)有一與自然數有關的命題。設此命題對 0 成立,而當對任一自然數成立時,則對其後繼亦成立 則此命題對所有自然數皆成立後繼亦成立,則此命題對所有自然數皆成立。

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 3

  • 4.1 The Well-Ordering Principle: g pMathematical Induction

    The Well-Ordering Principle: Every nonempty subset of Z+contains a smallest element.( )}1|{}0|{ ≥∈=>∈=+ xxxx ZΖZ Z

    + is well ordered( )The Principle of Mathematical Induction: Let S(n) denote an open mathematical statement that involves one or more

    f th i bl hi h t iti i t

    }1|{}0|{ ≥∈>∈ xxxx ZΖZ

    occurrences of the variable n, which represents a positive integer.a) If S(1) is true; and (basis step)b) If whenever S(k) is true, then S(k+1) is true. (inductive step)b) w e eve S(k) s ue, e S(k ) s ue. ( duc ve s ep)

    then S(n) is true for all Using quantifiers

    +∈Zn

    )()]]]1()([[)([ 000 nSnnkSkSnknS ≥∀⇒+⇒≥∀∧

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 4

    )()]]]()([[)([ 000

  • 4.1 The Well-Ordering Principle: Mathematical Induction

    P(n0)P(n0+1)P(n0+2)...

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 5

  • Why Induction WorksMore rigorously the validity of a proof by mathematical induction reliesMore rigorously, the validity of a proof by mathematical induction relies

    on the well-ordering of Z+.Let S be a statement for which we have proven that S(1) holds and for p ( )

    all n∈ Z+ we have S(n)⇒S(n+1). Claim: S(n) holds for all n∈ Z+

    Proof by contradiction: Define the set F⊆ Z+ of values for which S does not hold: F = { m | S(m) does not hold}.

    If F is non empt then F must have a smallest element ( ell ordering ofIf F is non-empty, then F must have a smallest element (well-ordering of Z+), let this number be z with ¬S(z). Because we know that S(1), it must hold that z>1. Because z is the smallest value, it must hold that S(z–1),

    hi h di f f ll + ( ) ( )which contradicts our proof for all n∈ Z+: S(n)⇒S(n+1). Contradiction: F has to be empty: S holds for all Z+.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 6

  • The Well-Ordering Principle: g pMathematical Induction

    Ex 4.1 : For anyProof

    2)1(

    1 321,+

    =+ =+⋅⋅⋅+++=∑∈ nnni nin Z

    )1(

    2)11(11

    1

    2)1(

    1

    1:)1( (i)

    321 :)(Let +×

    =

    +=

    ==∑

    =+⋅⋅⋅+++=∑

    i

    nnni

    iS

    ninS

    12

    )1(1

    21

    )1(321)1(Th(iii)

    i.e., true,is )( Assume (ii)

    )(( )

    +

    +=

    =

    =∑

    k

    kkki

    i

    kkikS

    ikS

    2)1(1

    1

    11

    )1()1()(

    )1(321:)1(Then (iii)+

    =

    +=

    ++=++∑=

    +++⋅⋅⋅+++=∑+kk

    i

    ki

    kki

    kkikS

    2)2)(1( ++= kk

    22321t +++ ++++∑ nnn iZDiscrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 7

    22

    1321,try ++

    =+ =+⋅⋅⋅+++=∈ ∑ nni nin Z

  • The Well-Ordering Principle: g pMathematical Induction

    Ex 4.3 : Among the 900 three-digit integers (100 to 999), where the integer is the same whether it is read from left to right or from right to left are called palindromes Without actually determining all of theseleft, are called palindromes. Without actually determining all of these three-digit palindromes, we would like to determine their sum.

    Solution

    )10101(

    1010110100 :palindrome typicalThe9 99 9∑ ∑ +∑ =

    ⎞⎜⎜⎛∑

    +=++=

    baaba

    baabaaba

    [ ]4510101010)101(10

    )(

    99 91 01 0

    ∑ ⋅+=∑ ⎥⎦

    ⎤⎢⎣

    ⎡∑+=

    ∑ ∑∑⎠

    ⎜⎜⎝∑

    = == = a ba b

    aba [ ]

    500,4945091010

    )(

    911 0

    =⋅+∑=

    ⎥⎦

    ⎢⎣ == = aa b

    a

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 8

    1=a

  • The Well-Ordering Principle: g pMathematical Induction

    Ex 4.5For triangular number t =1+2+ +i= i(i+1)/2

    22111 ⋅==t

    2323

    212⋅==

    +=t

    2436

    3213⋅==

    ++=t

    25410

    43214⋅==

    +++=t

    ti=1+2+…+i= i(i+1)/2We want a formula for the sum of the first n triangular numbers.P fProof

    ][][)( )1(1)12)(1(11)1( 2 +=∑ +=∑∑ = ++++ iit nnnnnnn iin ][][)(

    6)2)(1(

    2262121 21

    =

    +=∑ +=∑∑ =

    ++===

    iit

    nnniii

    i

    Ex 4.4 prove it

    700,171... 6)102)(101(100

    6

    10021 ==+++∴ ttt

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 9

  • The Well-Ordering Principle: g pMathematical Induction

    Ex 4.5Consider pseudocode procedures (comparisons)P d 1 dditi d lti li ti ( dditi ll t i)Procedure 1: n additions and n multiplications (additionally, counter i)Procedure 2: 2 additions, 3 multiplications, and 1 division

    procedure SumOfSquares1begin

    procedure SumOfSquares2begin

    ( 1) (2 1)/6begin

    sum:= 0for i:= 1 to n do

    sum := sum + i2

    sum:= n*(n+1)*(2*n+1)/6end

    end

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 10

  • The Well-Ordering Principle: g pMathematical Induction

    Ex 4.8 n 4n n2-7 n 4n n2-71 4 -62 8 -3

    5 20 186 24 29).7(4,6For 2 −

  • The Well-Ordering Principle: g pMathematical Induction

    nnHHH1

    21

    21 1, ,1 ,1 21 +⋅⋅⋅++=⋅⋅⋅+==

    nHnH njn

    −+=∑ )1(n, allFor

    Ex 4.9 : Harmonic numbers

    1)11(1:)1(Verify 111

    1HHHS j

    j−+===∑

    =

    jj=1Proof

    )1(: true)( Assume

    1

    1kHkHkS kj

    k k

    k

    j

    j

    −+=∑=

    1)(k

    ])1([:)1(Verify 111

    1 1

    HkH

    HkHkHHHkS kkkjjk

    j

    k

    j

    +−+=

    +−+=+=+ ++∑ ∑+

    = =

    )1(2)(k

    ]111)[(k

    1)(k

    11

    1

    kH

    HkkH

    HkH

    kk

    kk

    ++=

    +−+

    −+=

    ++

    ++

    +

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 12

    . trueis )()1(2)(k 1

    nSkH k

    ∴+−+= +

  • The Well-Ordering Principle: g pMathematical Induction

    E 4 10Ex 4.10 :The elements of An are listed in ascending order, and |An|= 2n.To determine whether we must compare r with no more thanAr∈To determine whether , we must compare r with no more than n+1 elements in An.Proof

    nAr∈

    brccCbbBccbbCBccbbAS

    aaaaAS==

  • The Well-Ordering Principle: g pMathematical Induction

    M th ti l i d ti l j l i i ifi tiMathematical induction plays a major role in programming verification.Ex 4.11 :

    The pseudocode program segment is supposed to produce the answer xyn.The pseudocode program segment is supposed to produce the answer xy .Proof

    answer : true)( Assume

    answer :)0(Verify 0

    xykS

    xyxSk=

    ==

    findwenowagainloopwhile''theoftopthe return to and executed nsareinstructio loop the,first time for the

    loop while'' theof top thereach the program the1,hen :)1(Verify knwkS +=+while n≠ 0 dobegin

    x := x * y

    1)1(k

    findwenowagain,loop whiletheoftop the

    1

    knxyx

    =−+=•=•

    n := n - 1end

    answer := x

    true.is)()(answer final The

    andwith continue willloopwhile''theAnd 1

    1

    ,1

    nSxyyxyyx

    knyxkkk

    ∴===∴

    =+

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 14

    )(S

  • The Well-Ordering Principle: g pMathematical Induction

    E 4 13Ex 4.13 :Show that for all we can express n using only 3’s and 8’s as summands (e g 14 = 3 + 3+ 8)

    14≥nsummands. (e.g., 14 3 + 3+ 8)Proof

    :true)(Assume kS

    While :)1(Verify

    :true)( Assume

    =+

    knkS

    kS

    1fors8'with twos3'fivereplace, s3' fiveleast at have sum the 14, sum, in the appears 8 no (ii) case

    1for s3'ewith thre8replacesum,in theappears8oneleast at (i) case

    +=∴≥

    +=

    kn

    knQ

    )1()(

    1for s8with twos3fivereplace +⇒∴

    +=kSkS

    kn

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 15

  • Fibonacci SequenceConsider the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,…Consider the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,…

    which is defined by F1 = F2 = 1 and Fn+2 = Fn+1 + FnClearly this sequence F1,F2,… will grow, but how fast?C j t F ≥ (3/2)n f ll >10Conjecture: Fn ≥ (3/2)n for all n>10Proof by induction:

    Base case: Indeed F11 = 89 ≥ (3/2)11 = 86.49756…

    Inductive step for n>10:

    Other base case: also F12 =144 ≥ (3/2)12 = 129.746338…Inductive step for n>10:

    Assume Fn ≥ (3/2)n and Fn+1 ≥ (3/2)n+1, then indeedFn+2 = Fn + Fn+1 ≥ (3/2)n + (3/2)n+1 = (3/2)n(1 + (3/2))

    2= (3/2)n(5/2) ≥ (3/2)n (9/4) = (3/2)n+2By induction on n, the conjecture holds.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 16

  • Other Induction ProofsWe just saw a different kind of proof by induction where the inductive step is ∀n>10: [P(n), P(n+1) ⇒ P(n+2)]This time the basis step is proving P(11) and P(12).p p g ( ) ( )

    There are many variations of proof by induction:Strong/ Complete induction: Here the inductive step is:Assume all of P(1),…,P(n), then prove P(n+1).The basis step is P(1) for this alternative form of induction.p ( )

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 17

  • Fibonacci NumbersThe sequence 1,1,2,3,5,8,13,21,34,… defined by Fn+2= Fn+Fn+1 is the famous Fibonacci sequence.

    A closed expression of Fn isnn

    511511 ⎞⎜⎛⎞⎜⎛ +n 2

    5151

    251

    51F ⎟

    ⎞⎜⎜⎝

    ⎛ −−⎟

    ⎞⎜⎜⎝

    ⎛ +=

    For large n, it grows like Fn ≈ 0.447214 × 1.61803n.This (1+√5)/2 ≈ 1.61803 is the Golden Ratio.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 18

  • Fibonacci in NatureFibonacci numbers often occur in the natural world.Shape of shells: Number of petals

    on flowers:

    htt // h tt / j / /i d ht l

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 19

    http://www.research.att.com/~njas/sequences/index.html

  • The Well-Ordering Principle: g pMathematical Induction

    Theorem 4.2: The Principle of Mathematical Induction –Alternative Form: (or the Principle of Strong Mathematical I d ti )Induction)

    Let S(n) denote an open mathematical statement that involves one or more occurrences of the variable n, which represents a positive p pinteger.a) If S(n0), S(n0+1), …, S(n1-1), and S(n1) are true

    If h S( ) S( 1) S(k 1) d S(k) f

    Basic step

    b) If whenever S(n0), S(n0+1), …, S(k-1), and S(k) are true for some , then S(k+1) is also true

    then S(n) is true for all1 where, nkk ≥∈

    +Z

    nn ≥ inductive stepthen S(n) is true for all .0nn ≥

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 20

  • The Well-Ordering Principle: g pMathematical Induction

    E 4 14Ex 4.14 :Show that for all , n can be written as a sum of only 3’s and 8’s. (e g 14 = 3+3+8 15 = 3+3+3+3+3 16 = 8+8)

    14≥n(e.g., 14 3+3+8, 15 3+3+3+3+3, 16 8+8)Proof

    trueare)16(and)15()14(Verify SSS

    :)1(Verify16 where true,are )( and )1(),2( , ),15(),14( Assume

    true.are)16(and),15(),14(Verify

    +≥−−⋅⋅⋅

    kSkkSkSkSSS

    SSS

    trueis )1( trueis )2(,214 and ,3)2(1

    :)1(Verify

    +∴−≤−≤+−=+

    +

    kSkSkkkk

    kSQ

    )(

    14 15 16 17 18 19 20 21 22 …

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 21

  • The Well-Ordering Principle: g pMathematical Induction

    E 4 15Ex 4.15 :Show that

    ≤ where,3a nn

    Proof⎩⎨⎧

    ≥∈++====

    +−−− 3 where allfor ,

    and,3,2,1

    321

    210

    nnaaaaaaa

    nnnn Z

    11

    000

    332

    331 (i)

    =≤=

    ≤==

    a

    a

    211

    22

    (ii)393

    −−+ ++==≤=

    kkkk aaaaa

    1

    21

    3)3(3333 333

    +

    −−

    ==++≤

    ++≤kkkkk

    kkk

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 22

  • Induction, another exampleTowers of Hanoi: (1883)Towers of Hanoi: (1883) We have three poles and n golden disksthe disks are only allowed in pyramid shape:the disks are only allowed in pyramid shape: no big disks on top of smaller onesHow to move the disks from one pole to another?How to move the disks from one pole to another?How many moves are requires?Call this number M(n)Call this number M(n).Note M(1)=1 and M(2)=3What about M(3)?W a abou (3)?

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 23

  • Inductive, Recursive

    7 moves for 3 disks7 moves for 3 disksffIn general, 2In general, 2nn‐‐11

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 24

  • Making a ConjectureTo prove something by induction, you need a conjecture about the

    general case M(n).

    Here we have: M(1)=1, M(2)=3, M(3)=7,…Obvious conjecture… M(n) = 2n – 1 for all n > 0

    Clearly, the basis step M(1)=1 holds.

    Feeling for general n case: Each additional disk (almost) doubles the number of moves: M( +1) i t f t M( )M(n+1) consists of two M(n) cases…

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 25

  • Inductive StepHow to move n+1 disks, using an n-disk ‘subroutine’?

    n nM(n) movesM(n) moves

    n1 move

    no e

    M(n) moves

    In sum: M(n+1) = 2 M(n)+1

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 26

    ( ) ( )

  • Proof of ToHWe just saw that for all n, we have M(n+1) = 2M(n)+1.

    This enables our proof of the conjecture M(n)=2n–1.Proof: Basis step: M(1) = 21–1 = 1 holds.A th t M( ) 2n 1 h ld Th f t +1Assume that M(n)=2n–1 holds. Then, for next n+1:M(n+1) = 2 M(n) + 1 = 2(2n–1) + 1 = 2n+1 – 1.Hence it holds for n+1 End of proof by induction on nHence it holds for n+1. End of proof by induction on n.

    With n=64 golden disks, and one move per second,this amounts to almost 600,000,000,000 years of work.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 27

  • How to Prove InductivelyGeneral strategy:

    1. Clarify on which variable you’re going to do the i d iinduction

    2. Calculate some small cases n=1,2,3,…(Come up with your conjecture)your conjecture)

    3. Make clear what the induction step n→n+1 is4 Prove the basis step prove the inductive step4. Prove the basis step, prove the inductive step,

    and say that you proved it.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 28

  • Induction in CSInductive proofs play an important role in computer science

    because of their similarity with recursive algorithms.

    Analyzing recursive algorithms often require the use of y g g qrecurrent equations, which require inductive proofs.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 29

  • Structural InductionTh th d f i d ti l b li d t t tThe method of induction can also be applied to structures other than integers, like graphs, matrices, trees, sequences and so on. The crucial property that must hold is the well-ordered principle: there has to be a notion of size such that all objects have a finite size and each set of objects must have aobjects have a finite size, and each set of objects must have a smallest object.Examples: vertex size of graphs, dimension of matrices, depth of trees, length of sequences and so on.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 30

  • L-Tiling an 2n×2n Square

    Take a 2n×2n square with one tile missingCan you tile it with L-shapes?y p

    Theorem: Yes, you can for all n.

    Example for 8×8:

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 31

    Example for 8×8:

  • Proving L-TilingBasis step of 2×2 squares is easy.

    Inductive step: Assuming that 2n×2n tiling is possible,tile a 2n+1×2n+1 square by looking at 4 sub-squares:P t th 3 h l i th iddlPut the 3 holes in the middle:Put an L in the middle, and tile the sub squaresand tile the sub-squares using the assumption.

    P f b i d tiProof by induction on n.This is a constructive proof.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 32

  • 4.2 Recursive DefinitionsE 4 19Ex 4.19 : Fibonacci numbers

    1) F0 = 0; F1 = 1;2) F = F + F 2hllf ≥+Z2) Fn = Fn-1 + Fn-2, 2whereallfor ≥∈ + nn Z

    10

    2+

    =

    + ×=∑∈∀ nnn

    ii FFFn Z

    Proof0=i

    12

    21

    20

    Assume

    1*1 step, basis

    +×=

    =+

    ∑ kkk

    i FFF

    FF

    21

    21

    2

    10

    Then

    Assume

    +

    +

    +=

    +=

    ×

    ∑∑

    k

    k

    i

    k

    i

    kki

    i

    FFF

    FFF

    211

    00

    )( ++

    ==

    +×=+×=

    ∑∑

    kkk

    ii

    FFFFFF

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 3321

    11

    )(

    ++

    ++

    ×=+×=

    kk

    kkk

    FFFFF

  • Recursive DefinitionsE 4 20Ex 4.20 : Lucas numbers

    1) L0 = 2; L1 = 1;2) Ln = Ln-1 + Ln-2, 2 where allfor ≥∈ + nn Z

    11 +−+ +=∈∀ nnn FFLn Z

    312201 213,101 step, basis:Proof

    +=+==+=+== FFLFFL

    2111kk1k

    11n

    )()(Then 2k wherek,1,-k1,2,3,...,nfor Assume

    −+−−+

    +−

    +++=+=≥=+=

    kkkk

    nn

    FFFFLLLFFL

    2

    121

    )()(

    +

    +−−

    +=+++=

    kk

    kkkk

    FFFFFF

    Fn-2 Fn-1 Fn Fn+1 Fn+2

    Ln-1 Ln Ln+1

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 34

    1)1(1)1( ++−+ += kk FF

  • Recursive DefinitionsE 4 21 E l i bEx 4.21 : Eulerian numbers

    0001,10 ,)1()( ,11,1,

    kkmkakakma kmkmkm

  • 4.3 The Division Algorithm: Prime gNumbers

    D fi iti 4 1 If b di id d it b| if0d bZbDefinition 4.1: If we say b divides a, and write b|a, if there is an integer n such that a = bn, then b is divisor of a, or a is multiple of b.

    ,0and, ≠∈ bZba

    We also say for b nonzero: b divides a or b is a factor of aTheorem 4.3:

    ,and,,integersthree theof twodividesand,Ife) allfor || d) |)]|()|[( c)

    )]|()|[(b) 0)(a0|and|1a)

    zyxazyxxbxabacacbba

    baabbaaa

    +=∈⇒⇒∧±=⇒∧≠Ζ

    )(|theneachdividesIf1Forg)), ofn combinatiolinear called isy (y),(|)]|()|[( f)

    integer. remaining thedivides then ,,,g,)

    xcxcxcacacnicbcbxcbxacaba

    ayy

    +++∈≤≤++⇒∧

    Ζ

    Proof

    )(|then ,each dividesIf.,1For g) 2211 nnii xcxcxcacacni +⋅⋅⋅++∈≤≤ Ζ

    and | and | If f) ancambcaba ==⇒

    y)(| )()()(y

    cbxanymxayanxamcbx

    +∴+=+=+∴

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 36

  • The Division Algorithm: Prime NumbersN b th i ti l li bl t l i d liNumber theory is now an essential applicable tool in dealing with computer and Internet security.

    Primes are the positive integers that have only two positive divisors, namely, 1 and n itself. All other positive integers are called composite.

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 37

    Sacks spiral, 1994Ulam spiral, 1963

  • The Division Algorithm: Prime NumbersL 4 1 If d i it th th i i+Lemma 4.1: If and n is composite, then there is a prime p such that p|n.

    Proof

    +∈ Zn

    ProofIf no such a primeLet S be the set of all composite integers that have no prime divisors.By Well-Ordering Principle, S has a least element m.If m is composite, then m=m1m2, 1

  • The Division Algorithm: Prime NumbersTh 4 4 Th i fi it l i (E lid B k IX)Theorem 4.4: There are infinitely many primes. (Euclid, Book IX)

    ProofIf notIf notLet p1 , p2, …, pk be the finite list of all primes.Let B = p1 p2 …pk+1.Let B p1 p2 …pk 1.Since B > pi , , B is not a prime.So B is composite, pj|B, . (Lemma 4.1)

    ki ≤≤1kj ≤≤1j

    Since pj|B and pj|p1 p2 …pk, so pj|1. (Contradiction, Theorem 4.3 (e))

    integer.remainingthedividesthen, and ,, integers three the

    of twodivides and , If e)

    azyx

    azyx +=

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 39

    integer.remainingthedivides then a

  • The Division Algorithm: Prime NumbersTheorem 4.5: The Division Algorithm, if , with b > 0, then there exist Z∈ba ,unique

    Proof

    .0,with , brrqbarq /

    =ab

    rabWe call r the remainder when a is divided by b, and q the quotient when a is divided by b.

    (1) q, r exist

    φ≠∈=>>−∈−=

    bbbbSSata

    tbaZttbaS

    )1()1(h1ld0If(ii), then ,0 and 0 If (i)}0,|{Let

    0r,|(b) >/ ab

    br ,| (c) −∴≤≤−

    +−=−−=−−=≤Stbaab

    bbabaatbaata,0 0 and 01

    )1()1(then ,1let and0If(ii)Q

    bSS P i i l )O d iW ll(0llhφ

    SSbqacqbacbrbr

    abbqabrqbarrSS

    ∈+−=⇒−=+=>/+==

    −−=

  • The Division Algorithm: Prime Numbers

    Ex 4.25If the dividend a =170 and the divisor b = 11, then the quotient q = 15 and the remainder r = 5 (170=15*11+5)15, and the remainder r = 5. (170=15*11+5)If the dividend a = 98 and the divisor b = 7, then the quotient q = 14, and the remainder r = 0. (98=14*7)f h di id d d h di i b h h iIf the dividend a = -45 and the divisor b = 8, then the quotient q = -6,

    and the remainder r = 3. (-45=(-6)*8+3 or -45=(-5)*8-5?)Let +∈Zba,

    If a = qb, then -a = (-q)b. So, the quotient is -q, and the remainder is 0.If a = qb + r, then -a = (-q)b - r = (-q - 1)b + (b - r). So, the quotient is -q -1, and the remainder is b - r.q ,

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 41

  • Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 42

  • The Division Algorithm: Prime Numbers

    Ex 4.27 : Write 6137 in the octal system (base 8)Here we seek nonnegative integers r0 , r1 , r2, …, rk , 0< rk

  • The Division Algorithm: Prime Numbers

    Ex 4.29 : Two’s Complement Method: binary representation of negative integers

    One’s Complement: interchange 0’s and 1’s.Add 1 to the prior result.

    E l 610100001100101106 ≡→+→≡Example:Example: How do we perform the subtraction 33 – 15 in base 2 with patterns of 8-bits?

    610100001100101106 −≡→+→≡

    with patterns of 8 bits?

    100010010(-15) 11110001(33) 00100001

    + 00001111 (+15)

    General formula: x – y = x + [(2n – 1) – y + 1] – 2n

    100010010

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 44

    One’s complement of y

  • The Division Algorithm: Prime NumbersE 4 31 If d i i h h i i h+Ex 4.31 : If and n is composite, then there exists a prime p such that p|n and

    Proof

    +∈Zn.np ≤

    Composite n = n1n2We claim that one of n1 , n2 must be less than or equal toIf not then d

    ,nIf not, then

    tion)(contradic

    and

    21

    21

    nnnnnn

    nnnn

    =>=

    >>

    So, assume (i) If n1 is prime, the statement is true.

    .1 nn ≤( ) 1 p ,(ii) If n1 is not prime, there exists a prime p < n1 where p|n1. (Lemma 4.1)

    thenSo p|n and .np ≤

    .1 nnp ≤<

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 45

    p|

  • 4.4 The Greatest Common Divisor: The Euclidean Algorithm

    Definition 4.3: For , a positive integer c is called a greatest common divisor of (最大公因數gcd(a,b) )

    Z∈ba,if ,ba

    cdbadbacbcc|a

    |havewe, andofdivisor common any for (b)), of divisorcommon a is ( | and (a)

    QuestionsDoes a greatest common divisor of a and b always exist?

    |,y( )

    Does a greatest common divisor of a and b always exist?What would we deal with greatest common divisors for large integers aand b ?

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 46

  • The Greatest Common Divisor: The Euclidean Algorithm

    Theorem 4.6: For all , there exists a unique that is the greatest common divisor of a and b.

    f

    +∈Zba,

    }0|{l tGi bttbtSb + ZZ

    +∈Zc

    Proof

    ., ofdivisor common greast a is that claim We:Existence (i)Principle) Ordering-(Well element least a has

    }0,,|{let ,,Given

    baccS

    btastsbtasSba >+∈+=∈ + ZZ

    0,,| If |

    4.3(f)) (Theorem then , and if ,,

    crrqcaaccd

    byd|axd|bd|abyaxcSc

  • The Greatest Common Divisor: The Euclidean Algorithm

    The greatest common divisor of a and b is denoted by gcd(a, b).gcd(a, b) = gcd(b, a)Also aa =≠∈ 0)gcd(athen0aifZAlso,

    gcd(a, b) = the smallest positive integer of the linear combination of a and b

    d b ll d l ti l i h d( b) 1

    aa ≠∈ 0)gcd(a,then ,0aif,Z

    a and b are called relatively prime when gcd(a, b)=1i.e,

    gcd(a, b)=c gcd(a/c, b/c)=1.1 with , =+∈ byaxyx Z

    Ex 4.33gcd(42 70) = 14 42x+70y=14gcd(42, 70) = 14, 42x+70y=14

    One solution x=2, y=-1x=2-5k, y=-1+3k

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 48

  • The Greatest Common Divisor: The Euclidean Algorithm

    Theorem 4.7: Euclidean Algorithm: Let Set r0 = a and r1 = b and apply the division algorithm n times as follows:

    ., +∈Zbaand apply the division algorithm n times as follows:

    rrrrqrrrrrqr

  • The Greatest Common Divisor: The Euclidean Algorithm

    Proof

    d)(|d|If , of divisor any for ,|Verify (i)

    ),gcd( at verify thTo

    bbacrc

    bar

    n

    n =

    ||and|Next)(e) 4.3 Theorem (|then

    and),,(|and|If ,21102

    21101010

    rcrcrcrrqrrc

    rrqrbrarrcrc

    ⇒+=

    +===Qrrqr

    rrqr+=+=

    3221

    2110

    | and |Verify (ii)|down Continuing ||and|Next 321

    brarrcrcrcrc

    nn

    n⇒⇒rrqr

    +

    +=⋅⋅⋅

    4332

    )(e) 4.3 Theorem ( equation last theFrom

    ,112 2|

    1|

    rrqrrrrr

    nnnnnn

    nn

    +=∴ −−−−−

    Qnnn

    nnnn

    rqrrrqr

    =+=

    −−−

    1

    112

    )gcd(),(|[

    ]|[up,Continuing

    100|]12|

    1|23|

    barbrarrrrrrr

    rrrrrr

    nnn

    nnn

    =∴==⇒∧

    ⇒∧

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 50

    ),gcd( barn =∴

  • The Greatest Common Divisor: The Euclidean Algorithm

    Ex 4.34 : find the gcd(250,111), and express the results as a linear combination of these integers.

    Solution

  • The Greatest Common Divisor: The Euclidean Algorithm

    Ex 4.35 : the integers 8n+3 and 5n+2 are relatively prime.Solution

    13120 )12()13(12525130 )13()25(138

    +

  • The Greatest Common Divisor: The Euclidean Algorithm

    An algorithm: a list of precise instructions designed to solve a particular type of problem, not just one special case.E 4 36 U E lid l ith t d l d (i d d )Ex 4.36 : Use Euclidean algorithm to develop a procedure (in pseudocode) that will find gcd(a, b) for all a, b ∈ Z+

    procedure gcd(a,b: positive integers)p g ( , p g )begin

    r:= a mod bd:= bwhile r > 0 do

    c:= dd:= rr:= c mod d

    endreturn(d)d { d( b) d}

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 53

    end {gcd(a,b) = d}

  • The Greatest Common Divisor: The Euclidean Algorithm

    Ex 4.37 : Griffin has two unmarked containers. One container holds 17 ounces and the other holds 55 ounces. Explain how Griffin can use his two containers to measure exactly one ouncecontainers to measure exactly one ounce.

    Solution

    1740 ,417355

  • The Greatest Common Divisor: The Euclidean Algorithm

    Ex 4.38 : On the average, Brian debug a Java program in six minutes, but it takes 10 minutes to debug a C++ program. If he works for 104 minutes and doesn’t waste any time how many programs can be debug in eachand doesn t waste any time, how many programs can be debug in each language.

    Solution =+⇒=+ 5253104106 yxyx

    +≤≤+−+−=−⋅+⋅=⇒

    −⋅+⋅=⇒=

    352051040)352(5)5104(3)52(5104352

    )1(52311)5,3gcd(

    kykxkk

    Q

    ⎧ ===

    ≤≤∴

    +−=≤−=≤

    214:18

    3520,51040

    5104

    352

    yxk

    k

    kykxQ

    ⎪⎩

    ⎪⎨

    =========

    ⇒8,4:205 ,9:192,14:18

    yxkyxkyxk

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 55

  • The Greatest Common Divisor: The Euclidean Algorithm

    Theorem 4.8: If the Diophantine equation ax + by = c has an integer solution x = x0, y = y0 if and only if gcd(a, b) divides c. Definition 4 4: For c is called a common multiple of a b

    ,,, +∈Zcba

    +∈ZcbaDefinition 4.4: For c is called a common multiple of a, bif c is a multiple of both a and b. Furthermore, c is the least common multiple of a, b if it is the smallest of all positive integers that are common

    l i l f b W d b l ( b)

    ,,, ∈Zcba

    multiples of a, b. We denote c by lcm(a, b).Theorem 4.9: Let with c = lcm(a, b). If d is a common multiple of a and b, then c|d.

    ,,, +∈Zcba, |

    Proof

    ),(lcm0 ,| Ifmacbac

    crrqcddc=∴=

  • The Greatest Common Divisor: The Euclidean Algorithm

    Theorem 4.10: For ab = lcm(a, b).gcd(a, b)Ex 4.40 : By Theorem 4.10 we have

    ,, +∈Zba

    (a) For all If a and b are relatively prime, then lcm(a, b) = ab.(b) The computations in Examples 4 36 (a = 168 b = 456) establish the

    ,, +∈Zba

    (b) The computations in Examples 4.36 (a = 168, b = 456) establish the fact that gcd(168,458) = 24. As a result we find that lcm(a, b)?Solution

    192,3)456,168(lcm

    24)456,168gcd(

    24456168 ==∴

    =⋅

    Q

    24

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 57

  • 4.5 The Fundamental Theorem of Arithmetic

    Lemma 4.2: If and p is prime, then

    .| || bpapabp ∨⇒,, +∈Zba

    Proof||| ppp

    |(ii)| (i)

    apap/

    )()(11),gcd(prime is

    |( )

    babypbxaypxapp

    p

    =+=+∴=∴Q

    | and | )()(,1

    abpppbabypbxaypx =+=+∴

    Q y)(|)]|()|[( cbxacaba +⇒∧

    Lemma 4.3:

    (f)) 4.3(Theorem| bp∴

    .1somefor || and prime is If .Let 21 niapaaappa ini ≤≤⇒∈ ⋅⋅⋅+Z

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 58

    21 ini

  • The Fundamental Theorem of Arithmetic

    Ex 4.41 : Show that is irrational.Proof

    2

    4 2)(Lemma|2|222

    1),gcd( and ,, where,2 not If

    2222 ⇒⇒=⇒=∴

    =∈=⇒ +

    aaab

    baba

    a

    ba Z

    i )( di)d(||4.2) (Lemma |2|2,2422

    4.2)(Lemma |2|222

    222222

    2

    ⇒=⇒==⇒=∴

    ⇒⇒=⇒=∴

    bbbbcbcabca

    aaabb

    tion)(Contradic2),gcd(|2|2 ≥∴∧ babaQ

    p primeevery for irrational is p

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 59

  • The Fundamental Theorem of ArithmeticTheorem 4.11: Every integer n > 1 can be written as a product of primes y g p puniquely, up to the order of the primes. ( )

    Proof

    kksss pppn ⋅⋅⋅= 2211

    existence(i)

    mmmmmmmmm

    m

    )1(primes ofproduct as written becan , and,composite) is (

    primes. ofproduct a as eexpressiblnot integer smallest theis not, If existence (i)

    21 21

  • The Fundamental Theorem of ArithmeticEx 4.44 : How many positive divisors do 29,338,848,000 have? HowEx 4.44 : How many positive divisors do 29,338,848,000 have? How many of the positive divisors are multiples of 360? How many of the positive divisors are perfect squares?

    Solution For(i) 21 pppn ksssSolution

    117532000,848,338,29

    )1()1)(1( is of divisors positive ofnumber The For (i)

    335821

    22

    11

    =

    +⋅⋅⋅++⋅⋅⋅=

    sssnpppn

    k

    kk

    7651)1)(11)(311)(325)(138(532360 (ii)

    17281)1)(11)(31)(35)(18(answer 23=

    =+++++=∴

    (0,2,4) choices 3 have we,5For )(0,2,4,6,8 choices 5 have we,8For (iii)

    7651)1)(11)(311)(325)(138(answer

    2

    1

    ==

    =+++−+−+−=∴

    ss

    6012235answer(0) choices 1 have we,1For

    (0,2) choices 2 have we,3For

    5

    4,3

    ∴=

    =s

    ss

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 61

    6012235answer =⋅⋅⋅⋅=∴

  • The Fundamental Theorem of Arithmetic

    Ex 4.46 : Can we find three consecutive positive integers whose product is a perfect square, i.e., m(m+1)(m+2) = n2 , ?

    Solution

    +∈Znm,Solution

    )4 4S tif21E i()2,1gcd(1)1,(gcdfact that the Use

    exist ,such Suppose++==+ mmmm

    nm

    squareperfectaalsois)1(squareperfectais

    | and ),2(|,| then ),1(| if , primeany For

    )4.4Section of21Exercise(

    2

    2

    +∴

    +//+∴

    mn

    npmpmpmpp

    Q

    )1(12)2(

    squareperfect a also is )2( squareperfect a alsois)1(squareperfect ais

    222

    +=++

  • Supplementary Exercise 34

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 63

  • Exercise (2009)

    4-1 :18, 244-2 :14, 194 2 :14, 194-3 :4, 104-4 :10 144-4 :10, 144-5 :8

    Discrete Mathematics Discrete Mathematics –– CH4CH42009 Spring2009 Spring 64