Lecture 3 - Divisibility, Euclid's Algorithms

divisibility

a|b represents the fact that a divides b. This doesn't mean that ba is defined (since 00 is undefined) but rather that xN s.t. b=xa.

Easy proofs of divisibility

  1. a|0 a
  2. 0|a is FALSE unless a=0
  3. 2|a when a is EVEN.
  4. 6|n(n+1)(n+2) n

Proof
We'll prove (4). Notice that n(n+1) is always divisible by 2. Further, out of n(n+1)(n+2) one of these must be 3. Therefore 2,3 are factors of n(n+1)(n+2) so then it must be divisible by their factor 23=6. We haven't proved that we can combine products in this way, but it's pretty obvious why.

There's a neater way to show the divisibility of 6:
Proof
Notice that:

(n+23)=n(n+1)(n+2)3!=n(n+1)(n+2)6

By the definition of the binomial coefficient. This has to be a whole number on the LHS, finishing the proof.

Example

Prove 8|n21 if n is ODD.

As some examples: 121=0,321=8,521=24,... seems to work. Let's prove it:

Proof
Since n is odd then n=2m+1 for some mN. Then:

n21=(2m+1)21=4m2+4m+11=4(m2+m)=4m(m+1)=8(m(m+1)2)

Where the last step is allowed since m(m+1) is always even. Clearly then 8 divides the LHS, finishing the proof.

Ideal of Z

Next time we'll look at how the set of all d|x for some x is the ideal of Z, which is closed under addition (+) and subtraction (-). This has to do with Abstract Algebra.

This is saying that if we have like 3|x and 3|y then clearly 3|x+y and 3|xy and so on. The ideal for each d is closed under the addition and subtraction operations.

Euclid's Division Algorithm

Euclid's Division Algorithm

Suppose a,b>0. Then b=qa+r, where q is the quotient and r is the remainder, where 0r<a. Further, both q,r are unique.

You've done and seen the proof multiple times.

Ideal

I={d|x,xZ} forms an ideal, which is closed under + and -.

Suppose I is ideal. Then

I=set of multiples of some d0

Suppose I has some a>0, else have I={0}. Suppose bI:

b=aq+r0r<ar=baqIa is minimalr=0b=aq is a multiple of aI= multiples of a
Summary

Ideals of the integers are exactly the same as the multiples of some element.

GCD: Greatest Common Divisor

To find gcd(a,b) for a,bZ, we want to know the largest integer d such that d|a,d|b. If a=b=0 then gcd(0,0)=0 by definition (we'll see why later on).

gcd vs (,)

Sometimes mathematicians will just use (4,3) rather than gcd(4,3). You've been warned!

We say:

How do we find GCD?

Stupid Method

Check 1,2,..., a to see if they divide b, and pick the biggest. Clearly this will work, but it's really slow (especially O(n) in this case). We'd want something that'll work with really big numbers like a,b10100.

Better Method

We can factor a,b into primes. For example, what is gcd(24,180)? We have:

24=233;180=22325

Clearly then we take the minimums of each power. In this case 22, 3, and that's it. Giving:

gcd(24,180)=223=12

For small numbers this is probably the fastest way. But there's a problem! You have to start with the primes, and thus know your factors already! Plus, if you have a really big prime number, it can take literal years to factor the prime factors of some numbers.

Euclid's Algorithm

Let's start with an example: find gcd(78,14).

Notice:

78=145+8(14,8)

Using the division algorithm, dividing the bigger term with the smaller term. Repeat by moving the smaller a value to b and use the remainder as the a value now:

14=81+6(8,6)

Repeat:

8=61+2(6,2)6=23+0(2,0)=0

Namely, you ignore the quotients and take the divisor, and move it over to the left:

Notice that all the gcd's are equivalent (namely, repeating the process this way doesn't change the answer) since, at each step, we are just subtracting multiples of one from the other (which shouldn't change their divisors anyways)

8=7814c

If you want a more rigorous answer, look at:

GCD Equivalences

For any xZ, the following are equivalent:

  1. gcd(a,b)
  2. gcd(b,a)
  3. gcd(a,b)
  4. gcd(a,b+ax)

Notice that gcd(a,b)=gcd(a,b+ax) so then like before where a=14 and b=8 we can do it backwards. Namely:

(a=14):78=8+145=b+axgcd(78,14)=gcd(14,8)

When you get to gcd(2,0) clearly that's easy to find, it's just 2 in this case.

This will end since the remainders in our sequence get smaller (the divisors themselves get smaller) so clearly the algorithm terminates.

Euclid's Algorithm

The progression of the algorithm is as follows:

a=q1b+r1b=q2r1+r2r1=q3r2+r3rn1=qn+1rn+rn+1

Where here rn is our GCD and rn+1=0

How Fast is it?

What is the worst case for our GCD algorithm? Namely, we want r normally to be small (as once it's 0 then we are done). So the worst case is when q=1. For example:

gcd(13,8)13=81+58=51+35=31+23=21+12=12+0

In this case it took 5 iterations. But notice that each ri follows the recurrence relation:

ri=ri1+ri2

Since in each step upward, we add the previous remainder (literally, as the remainder) and 1 times the new divisor.

We want to start from the bottom case through when r0=0 and r1=1. Thus we get:

ri={0,1,1,2,3,5,8,13,...}

And it's Fibonacci! So the worst case is when finding:

gcd(Fn,Fn+1)
Note

It's interesting to note that 2n2<Fn<2n, so it's like a super-exponential.

Further note that the number of steps we take is given (roughly) by:

#Clog(n)

Because of the exponential ways of Fn. Thus then clearly we have O(log(n)), where n here is the Fibonacci number in question (the larger one).

Formula for Fn

As we know from linear algebra, we have:

Fn=(φ)n(1φ)n5

where here ϕ is the golden ratio φ=1.618....

Exercise

Prove that Fn2=Fn1Fn+1+(1)n1.

Proof
We'll prove this by induction.

For n=2 we have F22=2=13+(1)21 which works for the minus case.

Suppose the n case, and we'll show the n+1 case:

Fn+12=(Fn+Fn1)2=Fn2+2FnFn1+Fn12=Fn2+2FnFn1+Fn2Fn+(1)n2=Fn(Fn+2Fn1+Fn2)+(1)n=Fn(Fn+1+Fn)+(1)n=FnFn+2+(1)n