Application of the Euclidean Algorithm
From Math Images
What can I do with Euclidean algorithm? Euclidean Algorithm is very important and fundamental in alge [...]
What can I do with Euclidean algorithm? Euclidean Algorithm is very important and fundamental in algebra, in other number systems, classical mathematical problems, other applied algorithms, computer science and music.
If we know the gcd(greatest common divisor) of the numerator and denominator, we can know if they are prime to each other or not and use the gcd to reduce fractions:
By Euclidean algorithm, we know that gcd(168, 64) = 8 as we discussed in Euclidean Algorithm.
You can actually use any common denominator and then add the two equations to simplify it, but using the smallest common denominator is the easiest way. To find the smallest common denominator, we need to find the least common multiple(lcm) of the two denominators, which is the product of a and b divided by gcd(a, b) :
In this way, you don't need to reduce the fraction anymore because the denominator is the least common multiple of 64 and 168.
Given two fractions ( for instance) lcm(a, b) also helps us determine which fraction is larger:
How to change a fraction into a continued fraction? Well, we need the help of Euclidean algorithm.
Let with , then .
Do they look familiar to you? Don't they share similarities with division equations from Euclidean algorithm? Indeed, Euclidean algorithm is closely related to continued fractions.
As you've probably noticed, the second term on the right-hand side is the inverse of the left-hand side of the next equation, except in the last equation divides . In that case, we can combine those equations together. Start with the first two equations:
Next, move on with the third equation. Substitute with the inverse of the third equation:
Every time, the fraction could be replaced by the inverse of the next equation. Keep this process till we hit the last equation and we will eventually get a continued fraction:
Rewrite the fraction as continued fractions.
Apply Euclidean algorithm:
Therefore we could rewrite the fraction above as:
Suppose a, b and c are integers, linear Diophantine equations take the form ax + by = c and only have integer solutions. The equations honor the Greek mathematician Diophantus around the 3rd century A.D., who was interested in finding integer solutions to various equations in his whole life. See the figure below.
Therefore, c = c' gcd(a, b) = c'(am + bn) = (c'm)a + (c'n)b.
Therefore, x = c'm, y = c'n are the two coefficients we want.
We could solve for the coefficients in this way by using extended Euclidean algorithm (see the section we talked about before extended Euclidean algorithm ). If c is not the gcd nor is it a multiple of the gcd, then this equation has no solution. So Diophantine equations either have infinite solutions or no solution.
Now let's find out how to solve a linear Diophantine equation with extended Euclidean algorithm.
First, find out if it has a solution or not. Start by going through the steps of the Euclidean algorithm to show that gcd(348, 126) = 6:
Indeed, 6 is the gcd of 348 and 126. The equation has solutions.
Then solve for integers x and y.
According to Eq. 3, .
According to Eq. 2, . Substitute it into the previous equation above, and we get
According to Eq. 1, . Substitute it into the previous equation above, and we get
Therefore, x = 4 and y = -11.
Summary: In order to get the values of x and y, we need to keep trying to express gcd(348, 126) as an integer linear combination of 348 and 126 using equations from Euclidean algorithm step by step.
There are certain things whose number is unknown. Repeatedly divided by 3, the remainder is 2; by 5 the remainder is 3; and by 7 the remainder is 2. What will be the number?
A problem like this is called Chinese remainder problem, another classical application of Euclidean algorithm. It is posed by a Chinese mathematician, Sun Tsu, in 4th century A.D.
More mathematically, we could rewrite the Chinese remainder theorem in the following way.
where are relatively prime to each other or for . Then this system of congruences has a unique solution .
1. Before we prove this theorem, we need to know the modular arithmetic:
2. Let represents the product of all m's EXCEPT , where k is any integer that is not greater than n. For example, = .
. Thus, is prime to , . By extended Euclidean algorithm , there exist integers and , such that . In terms of congruence, We assume
and we are going to prove that it is correct.
Now all the terms in Eq. 5, meaning that we divide the terms with and obtaining the remainder. We only get because could divide other terms, which eventually turn to 0, but not the k-th term the k-th term doesn't have , so it is not a multiple of ). Therefore according to the operation of modular arithmetic:
Because k is no greater than n, Eq. 6 matches with the last equation from the description of the theorem . This shows that x is, indeed, a solution to the system of congruence and we even have a formula for x, which is :
Then we need to prove that it is the only solution to the congruence. Suppose there is another solution y.
Compared with x, we will find that . Thus, .
Then divides , or is a multiple of all the m's.
Thus, the least common multiple(lcm) of m's divides , denoted as .
Because the m's are relatively prime, the least common multiples of all m's are actually the product of all m's, so we get .
Hence, or .
Here, we know that x and y are the same solution. Therefore, there is one unique solution to the congruence: .
Go back to the original Chinese Remainder problem. Solve
Since 3, 5 and 7 are pairwise relatively prime, there is only one solution , which is .
As we did in the proof, we need to construct the formula for x:.
We know and , so let's find and .
To fin the value of integer , try each integer starting with 1 until we get the remainder 1 when we divide () by 3.
We find that .
Similarly, . We find that . Thus,
, therefore .
, therefore .
Therefore, the number is 23 or 128. See the right figure to check the smaller number 23.
Gaussian integers are complex numbers a + bi, where a and b are real integers and i is the imaginary integer. The formal set of Gaussian integers is
Gaussian integers satisfy the analog of Fundamental Theorem of Arithmetic by applying the analog of the Euclidean algorithm. In other words, a Gaussian integer has a unique factorization with certain prime factors multiplied together just as a natural integer does.
To prove that natural integers satisfy the fundamental theorem of arithmetic, we use Euclidean algorithm to find the gcd and list all the prime factors. We use the same method to show unique factorization of Gaussian integers. Please note, Euclidean algorithm is not the only effective way to prove this property, but it is the most convenient method.
First, denote as two Gaussian integers just as we denote a and b for two normal integers. Then, we start the process as we did for Euclidean algorithm: subtracting the smaller integer from the bigger one and obtaining a remainder that is strictly smaller than its predecessor from each step until it is 0. The general equation is the same,
but the quotients and remainders are complex numbers, starting with. You can treat those complex numbers separately as two parts, the real part and imaginary part. Then, we round the real and imaginary parts to the nearest integers. For example: .
By rounding to and to , we know that the quotient of is . Thus, the remainder is . Repeat this step by applying Euclidean algorithm in this way and we will get the gcd(), which is the last nonzero remainder. Note that there is going to be four greatest common divisor of and up to multiplication by +1, - 1, + i, - i.
For normal integers, it is easy to know which one is bigger. How do we compare Gaussian integers to see which one is bigger and which one is smaller when they are complex numbers? Graphically, we represent Gaussian integers with lattice points in the complex plane (a, b). We take the norm of every Gaussian integer , converting complex numbers to normal integers. See the right figure. The norm of the remainder decreases after each step of the Euclidean algorithm, meaning that it is getting closer to the origin. Therefore, we compare the distance from the point to the origin to see which Gaussian integer is smaller.
We can solve other applications and problems of the Euclidean algorithm for Gaussian integers as well, not only for normal integers. Applications like Chinese remainder theorem and linear Diophantine equations we discussed just now also work for complex numbers.
In addition to those applications of various mathematical problems and computer science, Euclidean algorithm could be used to generate a large number of traditional musical rhythms efficiently.
Generally, binary sequences are used to represent musical rhythms. Each bit is considered as one unit of time; a one bit “x” means an onset of a note whereas an unaccented note “.” means a silence. Given a certain amount of notes, we will get a pattern if we distribute the notes as evenly as possible in a certain period. For example: assume that the time interval is 12 and there are four notes to be played, then this is how we note them:
x . . x . . x . . x . .
This is a very basic pattern since it gives you one note in every three steps. What if the time interval could not be divided exactly? Let’s say we want to play 5 notes during the time interval 12 instead of 4. Since . First, we are going to start with a sequence of putting the same notes together:
x x x x x . . . . . . .
Then place a period after each x, which leaves 2 periods at the end:
[x . ] [x . ] [x . ] [x . ] [x . ] . .
We now have five paired bits “x .” and a remainder of two single bits each. Next, put the remaining 2 periods after each “x .” sequence:
[x . . ] [x . . ] [x . ] [x . ] [x . ]
We now have two sequences of bits “x . .” and a remainder of three paired bits "x . " . Next, put the remaining 3 bits after each “x . .” sequence:
[x . . x . ] [x . . x . ] [x . ]
This gives us only one remainder of “x . “ with two sequences of bits “x . . x . ". Although we could continue the distribution by putting “x . ” in the middle of “x . . x . ” and “x . . x . ”, it doesn’t matter because the sequence is cyclic (according to Bjorklund’s stopping rule). Therefore, the final sequence of 5 notes in an interval of 12 is:
x . . x . x . . x . x .
Did you find Euclidean algorithm lying in this process? When applying the Euclidean algorithm, we basically try to subtract the smaller number from the greater one again and again. The remainder is subtracted from the smaller number each time, generating a new remainder smaller than the quotient. We stop until the new remainder is zero. Let's go back to the process of finding a certain pattern of musical rhythms we did just now. When we pair up the 5 x’s and 7 periods and leave the two periods alone, we are doing the same thing as subtracting 5 (smaller number) from 12 (bigger number) twice and obtaining a remainder 2. This process mentioned above is actually called Bjorklund’s algorithm named after its creator. Bjorklund’s algorithm has the same principle and structure as Euclidean algorithm, so we now usually call these rhythms Euclidean rhythms.
Try this pattern by knocking on the table and you will probably find that it is not so regular compared with patterns whose notes divide evenly into the interval. Combine several different patterns to find their own beauty of showing unique musical rhythms. Go to Wouter’s website to generate your own rhythms with a cool flash application or watch the video of some beautiful rhythms Wouter has made!
RSA algorithm is invented by and named after Ron Rivest, Adi Shamir and Leonard Adleman in 1977. It is a widely used public key algorithm for encryption and digital signatures. It gets its security from integer factorization.
RSA algorithm has three steps: key generation, encryption and decryption. See the right figure.
We need a public key and a private key to do RSA algorithm. A public key, used for encrypting messages, is known to everyone. A private key, used for decrypting messages, is only known to the consignee. Messages encrypted with the public key can only be decrypted using the private key. This key generation is performed a single time for each person with the public and private keys.
Imagine you have the public key and private key now. You only give the public key to your friend A and A wants to send a secret message to you. This is what A should do.
Too hard to understand? No worries! There is going to be an example later.
This will give you a better understanding of how important extended Euclidean algorithm means to RSA algorithm. Modular multiplicative inverse, used to get the value of the private key, is an essential step in RSA, and extended Euclidean algorithm helps us solve modular multiplicative inverse.
How should we get d using extended Euclidean algorithm?
Here, it is complicated to solve the inverse of e directly, so we apply modular multiplicative inverse. The modular multiplicative inverse of an integer a modulo m is an integer x such that . This is equivalent to .
In this case, denote as the remainder of modulo m, such that , so
Now we just need to know 's value to get the value of . According to modular multiplicative inverse, , hence
By the definition of congruence, it means that we divide with and get a remainder 1. This could be noted as
Recall that and are coprime integers, so . Therefore,
Recall that our goal is to find the value of . Does this equation look familiar to you? Yes, it is in the form of Bézout's identity. In section extended Euclidean algorithm, we know that extended Euclidean algorithm can solve for the two coefficients x, y of Bézout's identity:
Solve for using extended Euclidean algorithm, and then we will know the value of d. Now we can tell that extended Euclidean algorithm is very important for RSA algorithm.
RSA algorithm is pretty secure. If people want to attack RSA, they have to fix the problem of factoring large numbers and the RSA problem. We won't talk about these two problems in detail, but what is worth mentioning is that full decryption of the RSA ciphertext is infeasible because there hasn't been an efficient way of solving the two problems so far.
As he said in his webpage, Wouter Hisschemöller is interested in lots of different aspects of audio, music and (ActionScript) programming: Manipulating existing sounds (like samplers do), generating new sounds (like synthesizers), capturing and storing musical data (as used in composition, sequencers and MIDI) etc.
 Loy, Jim. Euclid's Algorithm. Retrieved from http://www.jimloy.com/number/euclids.htm.
 Artmann, Benno. (1999) ‘‘ Euclid-the creation of mathematics.’’ New York: Springer-Verlag.
 Weisstein, Eric W. Euclidean Algorithm. From MathWorld--A Wolfram Web Resource. Retrieved from http://mathworld.wolfram.com/EuclideanAlgorithm.html.
 Klappenecker, Andreas. Euclid's Algorithm. Retrieved from http://faculty.cs.tamu.edu/klappi/alg/euclid.pdf.
 Wikipedia (Linear Diophatine Equation). (n.d.). Linear Diophantine Equation. Retrieved from http://en.wikipedia.org/wiki/Linear_diophantine_equation.
 W. H. Freeman and Company. The Euclidean Algorithm and Linear Diophantine Equations. Retrieved from http://www.math.mtu.edu/mathlab/COURSES/holt/dnt/euclid.html.
 Gallian, Joseph A. (2010) Contemporary Abstract Algebra Seventh Edition. Belmont: Brooks/Cole, Cengage Learning.
 Bogomolny, Alexander. Chinese Remainder Theorem. Retrieved from http://www.cut-the-knot.org/blue/chinese.shtml.
 Ikenaga, Bruce. The Chinese Remainder Theorem. Retrieved from http://marauder.millersville.edu/~bikenaga/numbertheory/chinese-remainder/chinese-remainder.html.
 Wikipedia(Gaussian Integer). (n.d.). Gaussian Integer. Retrieved from http://en.wikipedia.org/wiki/Gaussian_integer.
 Toussaint, Godfried. The Euclidean Algorithm Generates Traditional Musical Rhythms. Retrieved from http://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf.
 Hisschemöller, Wouter. Euclidean Rhythms. Retrieved from http://www.hisschemoller.com/2011/euclidean-rhythms/comment-page-1/#comment-4509.
 Voytko, Jake. Why Does RSA Work? Retrieved from http://www.jakevoytko.com/blog/2008/01/06/why-does-rsa-work/#totient.
 Wikipedia(RSA). (n. d.). RSA. Retrieved from http://en.wikipedia.org/wiki/RSA.