Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

23
Mathematics Review • Exponents • Logarithms • Series Modular arithmetic • Proofs

Transcript of Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

Page 1: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

Mathematics Review

• Exponents• Logarithms• Series• Modular arithmetic• Proofs

Page 2: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• Manipulation of exponents – When the operation involves multiplication, add the

exponents algebraically

– When the operation involves division, subtract the divisor exponent from the numerator exponent.

– When the operation involves powers or roots, multiply the exponent by the power number or divide the exponent by the power number, respectively.

– Others

BABA XXX

BAB

A

XX

X

ABBA XX B

AB A XX

1

2

222

2

NNN

NNNN XXXX

Page 3: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• In computer science, all logarithms are to the base 2 unless specified otherwise.

• DEFINITION: XA = B if and only if logXB = A

Logarithms

Page 4: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• THEOREM 1.1 1,0,,;log

loglog ACBA

A

BB

C

CA

Proof: Let X = logCB, Y = logCA, Z = logAB.By the definition of logarithms, CX = B, CY = A, and AZ = BCombining these three equalities yields CX = B = AZ = (CY)Z = CYZ Therefore, X = YZ, which implies Z = X/Y, proving the theorem.

Page 5: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– THEOREM 1.2 logAB = logA + logB; A, B > 0

Proof: Let X = logA, Y = logB, Z = logAB.By the definition of logarithms, 2X = A, 2Y = B, and 2Z = ABCombining these three equalities yields 2X2y = 2x+y= AB = 2Z Therefore, X+Y = Z, proving the theorem.

AB = 2X2y = 2x+y

2Z = AB

Page 6: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Some other useful formulas:log (A/B) = log A – log Blog (AB) = B log Alog X < X for all X > 0

Page 7: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

Series

• Two usual types– Geometric series:

• Such that for a constant g, n=1, 2, …

– Mathematical progressions:

• Such that for some constant d , n=1, 2, …

,,,,, 121 nn aaaag

a

a

n

n 1

,,,,, 121 nn aaaa

daa nn 1

Page 8: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Geometric series• A common one:

• Its companion:

How to compute it?

N

i

Ni

0

1 122

N

i

Ni

A

AA

0

1

1

1

Let S = ,

That is, S = A0 + A1 + A2 + … + AN-1 + AN

AS = A1 + A2 + … + AN-1 + AN +AN+1

AS – S = AN+1 – 1Therefore,

N

i

Ni

A

AA

0

1

1

1

N

i

iA0

If 0 < A < 1, then

N

i

i

AA

0 1

1

Why ?

AA

AA

AAA

A

A

A

AA

NN

i

i

NN

NN

i

Ni

1

1

1

1

1101010

1

1

1

1

1

0

11

1

0

1

Page 9: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• For 0 < A < 1 and N tends to ,

• Another sum that occurs frequently We write

S =

and multiply by 2, obtaining

2S =

Subtracting these two equations yields

S =Thus, S = 2.

0 1

1

i

i

AA

1 2ii

i

...2

5

2

4

2

3

2

2

2

15432

...2

6

2

5

2

4

2

3

2

21

5432

...2

1

2

1

2

1

2

1

2

11

5432

Page 10: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Arithmetic series

1 2 3 4 5 … N-2 N-1 N

Therefore, (N+1)*(N/2) =

22

)1( 2

1

NNNi

N

i

N+1

N+1

N+1

N/2 pairs

2

)1( NN

How to compute ?

N

k

kda1

)(

Page 11: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Harmonic seriesFor positive integers N , the N th harmonic number is

HN =

=

– Other formulas

N

1...

4

1

3

1

2

11

Ni e

N

i

log1

1

11

36

)12)(1(

1

1

3

1

2

kk

Ni

NNNNi

kN

i

k

N

i

Page 12: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• Modular Arithmetic

– A is congruent to B modulo N, written A B (mod N), if N divides A-B.

– Intuitively, this means that the remainder is the same when either A or B is divided by N.

– Ex’s, • Check the following

– 20 ? 6 (mod 2)– 25 ? 10 (mod 3)– 20 ? 6 (mod 4)– 100 ? 23 (mod 6)

Page 13: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– If A B (mod N), thenA+C B+C (mod N)AD BD (mod N)

(A+C) – (B+C) = A – BSince A B (mod N), from thedefinition, N divides A-B.Thus, N divides (A+C)-(B+C)Therefore, A+C B+C (mod N)

Since A B (mod N), based on the definition, there exists an integer k such that A-B = k N.Now, AD-BD = (A-B)D = k NDSo, N divides AD-BD.Therefore, AD BD (mod N)

Page 14: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• Proofs

– Two most common ways of proving statements in data structure analysis: proof by induction and proof by contradiction.

– The best way of proving that a theorem is false is by exhibiting a counterexample.

Page 15: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• Proof by induction (two steps)– Base case: Establish that a theorem is true for some

small value(s). This step is almost always trivial.– Induction step: • An inductive hypothesis is assumed (which means

that the theorem is assumed to be true for all cases up to some limit k)• Using this assumption, the theorem is then shown

to be true for the next value, which is typically k+1.

Page 16: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Example 1: Fibonacci numbers Fi < (5/3)i, for i >=1Fibonacci numbers: F0 = 1, F1 = 1, F2 = 2, …, Fi = Fi-1 + Fi-2

Base case: verify that the theorem is true for the trivial cases. F1 = 1 < 5/3 F2 = 2 < 25/9

Inductive hypothesis: We assume that the theorem is true for i = 1, 2, …, k. To prove the theorem, we need to show that

Fk+1 < (5/3)k+1 We have

Fk+1 = Fk + Fk-1

< (5/3)k+ (5/3)k-1 (using inductive hypothesis) = (3/5) (5/3)k+1 + (3/5)2(5/3)k+1 = (3/5) (5/3)k+1 + (9/25)(5/3)k+1 = (3/5 + 9/25) (5/3)k+1 = (24/25) (5/3)k+1

< (5/3)k+1

which proves the theorem.

Page 17: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Example 2: THEOREM 1.3 If N >= 1, then

Proof: The proof is by induction.Base case: Obviously, the theorem is true when N = 1Inductive hypothesis: Assume that the theorem is true for 1 <= k <= N.

We need to establish that, under this assumption, the theorem is true for N+1.

We have

Applying the inductive hypothesis, we obtain

Thus,

6

)12)(1(

1

2

NNNi

N

i

2

1

21

1

2 )1(

NiiN

i

N

i

6

)32)(2)(1(6

672)1(

)1(6

)12()1(

)1(6

)12)(1(

2

21

1

2

NNN

NNN

NNN

N

NNNN

iN

i

6

]1)1(2][1)1)[(1(1

1

2

NNNi

N

i

= (N+2)(2N+3)

Page 18: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Proof by contradiction• Strategies:

– Assume that the theorem is false– Show that this assumption implies that some know property is false, which

indicates the original assumption was wrong.• Example 1:

The number of primes is infinite.A positive integer number is a prime if and only if only 1 and itself divide the

number. Proof: We assume that there is a finite number of primes, so that there is

some largest prime Pk. Let P1, P2, …, Pk be all the primes in order and consider

N = P1P2 … Pk + 1Clearly, N > Pk, so by assumption N is not prime.However, none of P1, P2, …, Pk divides N exactly.This is a contradiction, because every number is either prime or a product of

primes.Hence, the original assumption is false, which implies that thetheorem is true.

Page 19: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

Example 1

• is not a rational number.– Note: a rational number can be represented by a

irreducible fraction of two integers

• Proof. By contradiction– (Who can do this?)

2

Page 20: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

– Proof by counterexample• Proof by counterexample is usually used to prove that a

theorem is false.• Constructing a counterexample is not as easy as it seems• Example 1: The statement Fibonacci number Fk <= k2 is false.

• Proof: F11 = 144 > 112. Therefore, the statement is false.

Page 21: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

A Brief Introduction to Recursion

• A function is recursive if itself is used in its definition.

• A recursive function must have a base (base cases) and a general relation which reduces a general case to simple case, and eventually to the base (or base cases).

• Ex’s?

Page 22: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

• A good way to understand recursion is through building a recursion tree

• The good points for recursion are– To write elegant codes– Easier analysis of the algorithm performance

• The bad points are– Time consuming (Why?)– Space consuming (Why?)

Page 23: Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.

Four Basic Rules of Recursion• Base cases: You must always have some base cases, which can

be solved without recursion.• Making progress: For cases that are to be solved recursively,

the recursive call must be always be to a case that makes progress toward a base case.

• Design rule. Assume that all the recursive calls work.• Compound interest rule. Never duplicate work by solving the

same instance of a problem in separate recursive calls.