The idea of the following is to extended the simple notion that two numbers can divide with an integer remainder into the full set of integers (including zero and negative numbers
Theorem
Given two integers with , there exists unique . Note that represents the quotient and represents a remainder. Proof of remainder division theorem.excalidraw
Extending the theorem into the negative world is simple (proven above), changing the restricting inequality into .
Notation to expresses results of division can be in a multitude of ways, for example such that divides :
- : good for us, shows what we need to know
- The quotient is and the remainder is : Good
- : Okay
- : Often in school, but misleads to think that
- : Mathematically correct, but using rational numbers opposed to integers
Greatest common divisor
Let be integers. An integer is called the greatest common divisor of and if:
- divides and
- if is any integer which divides both then
This definition however does not generalise well to the entire set of or to polynomials etc.
For a simple rule to find the GCD could be as follows: Finding a GCD.excalidraw
Expanding this into the entire set of can be done by using divisors, by replacing with . This is also easier to figure out graphically with a Hasse diagram.
So we define the greatest common divisor of and if:
- divides and
- if is any integer with divides both then .
Now the GCD is not unique (although isn’t that much of a big deal; the magnitude is still unique): if is a GCD of and then is another GCD, but there are no more GCDs. The GCD of and and integer now exists, and equals because . Including when .
Euclid’s Algorithm
Euclid’s Algorithm is an efficient method for computing the greatest common divisor of two numbers, and . The main principle behind the algorithm is that the greatest common divisor of and is the same as the greatest common divisor of and .
The Euclidean Algorithm starts with a pair of positive integers and forms a new pair that consists of the lesser number and the remainder of the Euclidean division (also called division with remainder) of the greater by the lesser. This process repeats until the pair is where is the greatest common divisor.
The algorithm can be written as follows:
- If , then the GCD is and the process ends.
- Otherwise, compute and as and .
- Replace and with and respectively and return to step 1.
Implemented in a loop-free manner, the algorithm can be expressed as:
function EuclidGCD(a, b)
while b ≠ 0
t := b;
b := a mod b;
a := t;
return a;
This algorithm is particularly efficient because it rapidly reduces the size of the numbers. This reduction is based on the observation that, if is the remainder of divided by , then the common divisors of and are precisely the same as the common divisors of and . Thus we can use the remainder operation to successively reduce the pair of numbers until we reach a pair where the second number is . At this point, the other number will be the greatest common divisor.
Least Common Multiple
Let . An integer (also denoted [a,b])is called a least common multiple of and if
- and divide , and
- if is any integer which is a multiple of both and , then .
There is a theorem that relates this number with the greatest common divisor: