Download Responses: Euclid`s Algorithm

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Infinity wikipedia , lookup

Location arithmetic wikipedia , lookup

Infinitesimal wikipedia , lookup

Georg Cantor's first set theory article wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Approximations of π wikipedia , lookup

Positional notation wikipedia , lookup

Large numbers wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Arithmetic wikipedia , lookup

Addition wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Responses: Euclid’s Algorithm
General method and validation
Suppose two integers a and b (where a > b) share a common factor c. Euclid’s
algorithm relies on the fact that c also divides the difference a − kb for any
integer k. So we can reduce the problem to looking for the HCF of the two
smaller numbers b and a − kb. Repeating this step eventually yields our answer.
As an example, to evaluate the HCF of 371 and 84, which is denoted as (371,84):
371 = 4(84) + 35
84 = 2(35) + 14
35 = 2(14) + 7
14 = 2(7) + 0
We stop on the appearance of a zero remainder, and (371,84) is given by the
penultimate remainder, which is 7 in this case.
To demonstrate that the algorithm terminates at the correct solution in general,
define the series of quotients and remainders as follows:
a = q1 b + r 1
b = q2 r 1 + r 2
r 1 = q3 r 2 + r 3
.. .. ..
. . .
rn−4 = qn−2 rn−3 + rn−2
rn−3 = qn−1 rn−2 + rn−1
rn−2 = qn rn−1 + 0
So n steps are required here, and we claim that (a, b) = rn−1 . The proof is a neat
two-part “sandwiching” trick. Henceforth we’ll use the notation m | n to signify
that m divides n. Firstly, note that for any common factor c (be it the HCF or
smaller), c | a and c | b, so c | r1 . By extension,
c | b, c | r1 ⇒ c | r2
c | r1 , c | r2 ⇒ c | r3
..
..
..
.
.
.
c | rn−4 , c | rn−3 ⇒ c | rn−2
c | rn−3 , c | rn−2 ⇒ c | rn−1
1
So c | rn−1 . Hence specifically (a, b) | rn−1 so (a, b) ≤ rn−1 . But starting from the
bottom and working up,
rn−1 | rn−2 ⇒ rn−1 | rn−3 ⇒ rn−1 | rn−4 ⇒ · · · ⇒ rn−1 | b ⇒ rn−1 | a.
So rn−1 is a common factor of a and b, hence rn−1 ≤ (a, b). Putting these two
results together gives (a, b) ≤ rn−1 ≤ (a, b) – so rn−1 has to equal the HCF, and
we are done.
In spite of its age (some 2300 years old!), Euclid’s algorithm stands out as a
benchmark for what a good algorithm should be because it
a) always terminates at the correct answer
b) is easy to perform (and automate)
c) is lightning quick – as we shall see!
Another vital asset of the method is that, unlike the most elementary way to
find HCFs, we do not need to know the prime factorisation of the numbers in
question. If this seems like a minor point, consider that RSA public key cryptography, which is used for instance every time we use a secure webpage or make an
online credit card purchase, routinely performs Euclid’s algorithm on numbers
around 200 digits long. Finding prime factors of numbers this size can be like a
needle in a haystack.
Speed and Efficiency
The numbers requiring the most steps are successive members of the Fibonacci
sequence
1, 1, 2, 3, 5, 8, 13, 21, 34, 55 . . .
For example (34,21) is calculated thus:
34 = 1(21) + 13
21 = 1(13) + 8
13 = 1(8) + 5
8 = 1(5) + 3
5 = 1(3) + 2
3 = 1(2) + 1
2 = 2(1) + 0
For numbers of a given size, this has to be maximal in terms of steps taken
as the quotients are equal to one at every stage, so if we imagine running the
process backwards, we are forcing the successive remainders to increase as slowly
as possible. The Fibonacci numbers are generated by the second-order recurrence
relation
FN +2 = FN +1 + FN ,
2
with initial members F1 = F2 = 1. You may have encountered the theory needed
to solve difference equations of this kind to get an exact expression for FN . This
turns out to take the form
√ √ 1
1+ 5 N
1− 5 N
FN = √
−
.
2
2
5
Curiously, for any N , the square root terms cancel to give an integer value for
FN . Try it! The first bracketed quantity is the famous golden ratio
√
1+ 5
= 1.61803 . . .
φ=
2
which appears frequently in mathematics, nature, art and architecture and is
worth looking into in its own right. The second term has magnitude less than 1
so decays to zero for large N . Hence φ is the approximate ratio between Fibonacci
numbers and to a high degree of accuracy for larger N we may write
1
FN ' √ φN .
5
So taking logs and using some fundamental laws we obtain
log10 FN ' N log10 φ −
1
log10 5
2
log10 FN + 12 log10 5
⇒N '
.
log10 φ
But since every member of the Fibonacci series appears in the list of remainders,
N is also the number of steps in the worst case for Euclid’s algorithm, with
a = FN and b = FN −1 . Hence the maximum number of steps is
log10 FN + 21 log10 5
D + 0.3495 . . .
≤
' 4.785D + 1.672,
log10 φ
0.2089 . . .
in which D is the number of digits in a. This result is known as Lamé’s theorem.
So even for the aforementioned 200-digit numbers typically utilised in RSA encryption, we are guaranteed to find our HCF in less than 1000 steps – which takes
a blink of an eye to compute on any modern PC. Moreover, this is a worst-case
scenario. The great majority of numbers of comparable size will take far fewer
steps. In fact it can be shown that the average number of steps to compute (a, b)
with a > b is
12 ln 2
ln n ' 0.843 ln n,
π2
predicting about 120 steps for 200-digit candidates.
3
The procedure can be improved if we allow remainders to be negative: we simply
choose the sign of the remainder which makes each ri as small as possible. For
the Fibonacci numbers, this generates a big improvement. For example
89 = 2(55) − 21
55 = 3(21) − 8
21 = 3(8) − 3
8 = 3(3) − 1.
Each line after the first is now effectively of the form Fi+4 = 3Fi+2 −Fi , so we only
use every second member of the sequence. This results in the worst-case scenario
taking half the number of steps. You might like to see if you can incorporate this
refinement in general into any computer programs you may have written.
4