45
The Integers

The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Embed Size (px)

Citation preview

Page 1: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Integers

Page 2: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Division Algorithms

A high-school question: Compute 58/17.

We can write 58 as 58 = 3 (17) + 7

This forms illustrates the answer: “3 remainder 7”.

In other words, the quotient is 3 and the remainder is 7.

It is also true that 58 = 2(17) + 24, but 24 > 17, and remainder must always be < divisor. (otherwise the “quotient” is not a quotient).

Page 3: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Quotient and Remainder are Unique

Theorem: Given natural numbers a and b, there are unique nonnegative integers q and r, with 0 r < b, s.t., a = q b + r

Proof (slightly informal):Consider the assignment (this part is a tweak of the real proof):• q = , that is q is the largest integer that is smaller than a/b. • r = a mod b.We claim that q and r satisfy a = q b + r . This follows by definition of mod.(Example: 58 = 3 (17) + 7, 22 = 7(3) + 1,…)

Page 4: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Representation is UniqueProof (Continue): Now we need to show that q, r are unique.

Assume, for the sake of contradiction, that there are two such presentations for a, that is:

a = q b+r , a = m b + n ,where 0 r < b, 0 n < b.Then q b+r = m b + n implies b(q-m) = n – r.Next, since qm, we have b(q-m) is an integral multiple of b.But since 0 r < b, 0 n < b we have –b < (n – r) < b always!Then |b(q-m)| is at least b, and (n-r) is at most b-1. So they cannot be equal: contradiction!Conclusion: a cannot have two presentations as above.

Page 5: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Proof of UniquenessRemark:The standard approach in uniqueness proofs is to assume by contradiction that there are two forms, and then apply a sequence of arguments leading to a contradiction.

Here we assumed a is two forms: a = q b+r and a = m b + n ,and then concluded this results in a contradiction.

Page 6: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Quotient and RemainderDefinition: Given such a presentation: a = q b+r , 0 r < b ,the two integers q and r are called quotient and remainder when a is divided by b.

Problem: Find the quotient and remainder when • a=19 is divided by b=7. • a=589621 is divided by b=7893.Solution: For a=19 , b=7, we have 19 = 2(7) + 5, i.e, q = 2, r = a – q b = 5.Using a calculator we can show that = 74, for a=589621 , b=7893. Thus q = 74, and r = a – q b =5539.

Page 7: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

An Extension to Integer NumbersThe property a = q b+r , 0 r < b can be extended to all integers (so far we discussed only natural numbers).

Exception: b cannot be 0, why?

Theorem (The Division Algorithm): Given integer numbers a and b, b0, there are unique integers q and r, with 0 r < |b|, s.t., a = q b+r

Proof: By case analysis.We already showed the case where a, b are both positive.If a=0, then q = r = 0 is the only solution.Consider next the other cases:

Page 8: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

An Extension to Integer Numbers: ProofProof (continue):Case 1: b > 0, a < 0.In this case, since –a > 0, we have unique integers q, r s.t., (-a) = q b + r , 0 r < b

a = (-q) b – r .Recall that our goal is to have a non-negative remainder term. Therefore, if r = 0, we just have a = (-q) b. Otherwise, r > 0, then write a as follows:

a = (-q -1)b + (b-r) .Here (-q-1) is an integer, and 0 < b-r < b = |b|.Thus we have the desired form.

Page 9: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

An Extension to Integer Numbers: ProofProof (continue):Case 2: b < 0, and either a < 0, a > 0.In this case, since –b > 0, we have unique integers q, r s.t.,

a = q(-b) + r , 0 r < |b| .[Here we apply the Theorem on the natural numbers if a > 0,

and case 1 of this proof if a < 0 .]

Thus a has the desired form and we are done! QEDRemarks:1. The proof indeed covers all cases of all values of a, b

(recall that b0 always).2. This proof is strongly relying on the same Theorem for

natural number (proved before).

Page 10: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

ExampleLet us verify that in each of the following cases a = qb+r:

1. a = 58, b = 17, q = 3, r = 7. Here q = (that is, floor of a / b ) since b > 0.

2. a = 58, b = -17, q = -3, r = 7. Here q = (that is, ceiling of a / b ) since b < 0.

3. a = -58, b = 17, q = -4, r = 10. Here q = = (that is, floor of a / b ) since b > 0.

4. a = -58, b = -17, q = 4, r = 10. Here q = = (that is, ceiling of a / b ) since b < 0.

Conclusion: q is floor of a / b if b > 0, and ceiling of a / b is b < 0.

Page 11: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Sign of bProposition (w/o proof):If a = q b + r, with 0 r < |b|, then:

q = , if b > 0, and q =, if b < 0 .

Example: a = -1027, b = 38.

It is now straightforward to determine r:

r = a – q b = -1027 + 28 38 = 37 .

Page 12: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Divisibility and the Euclidean AlgorithmDefinition (“a is divisible by b”):Given integers a, b, with b 0, we say that b is a divisor or a factor of a, and that a is divisible by b iff a = q b, for some integer q. We write this as b | a , and say “b divides a”.

Examples:2 is a divisor of 4. 2 | 4.-7 is a divisor of 35. -7 | 35.For any natural number n, 2 is a divisor of -4 is not a divisor of 38.

Page 13: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Three consecutive integersProblem:Given three consecutive integers a, a+1, a+2, prove that one of them must be divisible by 3.

proof:By the division algorithm we have: a = 3 q + r, where 0 r < 3.That is, there are three possible values for r, r = 0, 1, 2.We follow each of these cases:Case 1, r = 0: here we have a = 3 q is divisible by 3.Case 2, r = 1: here we have a = 3 q +1 , and thus a+2 = 3 q + 3 is divisible by 3.Case 3, r = 2: here we have a = 3 q +2 , and thus a+1 = 3 q + 3 is divisible by 3.

Page 14: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Division and Partial OrdersLet us define a binary relation on the natural numbers:

R = { (a,b) a, b and a | b }

[That is, we consider only those pairs (a,b) of naturals s.t. a divides b.]

Proposition:The binary relation R is a partial order.

proof:For partial orders, one needs to show reflexivisity, antisymmetry, and transitivity.

Page 15: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Division and Partial OrdersProof (continue):R is reflexive: For any a , a | a, since a/a = 1.

R is antisymmetric: Suppose we are given a pair a, b , s.t. a | b and b | a . Then a = m b, for some natural number m, and b = q a, for some natural number q.

a = m b = m (q a) = (m q) a .

Since a > 0 we must have m q = 1, but since m, q are natural numbers then we must have m = q =1.Thus a = m b = b .

Page 16: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Division and Partial OrdersProof (continue):R is transitive: Suppose a, b, c , s.t. a | b and b | c . Then b = q a, for some natural number q, and c = m b, for some natural number m.

c = m b = m (q a) = (m q) a ,

and (m q) is a natural number.We thus conclude a | c. QED

Remark: The proposition implies that (, | ) is a partially ordered set (POSET).

Page 17: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Division and Partial OrdersExample: A = {1, 2, 3, 4, 5, 6}.In the poset (A, | ) what are the maximal elements?

- 4 is maximal because there is no other a A s.t. 4 | a. - 5, 6 are also maximal since they do not divide any other

number. However, 4 does not divide 5 nor 6 and thus it is NOT maximum.

- 3 is NOT maximal as 3 | 6.- 2 is NOT maximal as 2 | 4, 2 | 6.- 1 is minimum, as 1 divides each number in A.

Page 18: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

Division and Partial OrdersProposition:Suppose a, b, c are integers such that c | a, a | b.Then c | (xa +yb) , for any integers x, y . Proof:Since c | a we have a = q c, for some integer q. Since c | b we also have b = m c, for some integer m. Thus

xa +yb = x (q c) + y (m c) = (xq + ym) c.

Since (xq + ym) is an integer, we indeed have c | (xa +yb) .

Page 19: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The greatest common divisorDefinition:Let a, b be integers, s.t. at least one of them is not 0.An integer g is the greatest common divisor (gcd) of a and biff g is the largest common divisor of a and b, that is:

1. g | a, g | b.2. If c is any integer s.t. c | a, c | b, then c g.

We write g = gcd(a,b) to imply that g is the greatest common divisor of a and b.In this notation, a b.

Page 20: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The greatest common divisorExamples:1. gcd(15, 3) = 3.2. gcd(-24, 18) = 6.3. gcd(756, 210) = 42.4. gcd(-756, 210) = 42.5. gcd(-756, -210) = 42

If a, b are integers and a | b, we have gcd(b, a) = a.

Suppose a is non zero, then gcd(a, 0) = a. Why?

Claim: dcg(a, b) 1 always! (when one of a, b is nonzero)[1 is always a common divisor.]

Page 21: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean AlgorithmIn general, an algorithm is a computational procedure that computes/reports an output given an input.

Given two integers a, b , we would like to computer their gcd.

This computation relies on the following key property:Based on the Division algorithm, we have

a = q b + r , (recall a b ) Lemma (proved below) :

gcd(a, b) = gdc(b, r)

Page 22: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean AlgorithmWe first discuss the consequences of the lemma, and only then prove it.

This lemma implies that we can reduce the problem to a pair of smaller numbers, intuitively, this should make the problem easier, and it does!

Example:58 = 3 (17) + 7 , therefore gcd(58,17) = gcd(17,7).On the next iteration, we have 17 = 2(7) + 3, then gcd(17,7) = gcd(7,3). Next, we have 7 = 2(3) + 1, then gcd(7,3) = gcd(3,1) = 1.

Page 23: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean AlgorithmLemma (proved now) :If a = q b + r, for naturals a, b, q, and r. Assume a b .Then

gcd(a, b) = gdc(b, r) .Proof:By assumption, none of a, b are zero.

This in particular implies that both g1 = gcd(a, b) , and

g2 = gcd(b, r) are well defined (i.e., we do not divide by 0).

By definition, g2 | b and g2 | r so

g2 | (q b + r) , (why?)

and therefore g2 | a . Thus g2 is a common divisor of a and b.

Page 24: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean AlgorithmProof (continue):

But since g1 is the largest common divisor of a, b we must have

g2 g1 .

Similarly, since g1 | a and g1 | b , we have

g1 | (a – q b) (Why?)

That is, g1 | r . So g1 divides both r and b.

Once again, since g2 is the greatest common divisor of b and r:

g1 g2 .Then we conclude:

g1 = g2 .

Page 25: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

First, observe that it is sufficient to assume a, b are natural numbers, as we can change the sign of the gcd if exactly one of a or b is negative.

[For example, gcd(756, 210) = 42, gcd(-756, 210) = 42, etc. ] Input: Two natural numbers a, b, with a b .Output: gcd(a, b).

We need to describe a procedure to compute gcd(a, b)

Page 26: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm: The actual procedure

procedure to compute gcd(a, b):

Write a = q1 b + r1 , with 0 r1 < b .

If r1 0, write b = q2 r1 + r2, with 0 r2 < r1 .

If r2 0, write r1 = q3 r_2 + r3, with 0 r3 < r2 .

If r3 0, write r2 = q4 r3 + r4, with 0 r4 < r3 .

Continue in this manner until some remainder rk = 0.

Then gcd(a, b) is rk-1 (the last non-zero reminder).

But why does the process must converge?

Page 27: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm: Convergence

Why do we always end up with a remainder 0?

In the process, we always have r1 > r2 > r3 > r4 > …

That is, at every iteration the value of rk decreases by at least one, but all remainders are non-negative.

Therefore, sooner or later one of the remainders rk will become 0.[This is called the “Well-Ordering Principle”.] At that step, we have

rk-2 = qk rk-1 + rk ,

Then since rk = 0 we have

gcd(a, b) = gcd(rk-2 , rk-1) = rk-1 .

Page 28: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm: Convergence

More specifically, since rk = 0 we have

gcd(a, b) = gcd(n, r1) = gcd (r1, r2) = gcd (r2, r3) = …

gcd(rk-2 , rk-1) = gcd(rk-1 , 0) = rk-1 .

Problem: Find gcd(630, 196).Solution: 630 = 3(196) + 42.196 = 4(42) + 28.42 = 1(28) + 14.28 = 2(14) + 0The last non-zero reminder is 14, and thus gcd(630, 196)=14.

Page 29: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

Same Problem: Find gcd(630, 196).

We now write the same equations slightly differently,expressing each remainder in terms of a and b.

42 = 630 – 3(196) : r1 = a – 3b

28 = 196 – 4(42) : r2 = b – 4r1 = b – 4(a – 3b) = -4a + 13b

14 = 42 – 28 : r3 = r1 - r2 = (a – 3b) – (-4a + 13b) = 5a – 16b

Then we have: gcd(630, 196) = 14 = 5a – 16b = 5(630) – 16(196).

Page 30: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

This example shows that gcd(a, b) can be expressed as anintegral linear combination of a and b.That is, each remainder can be written as:

m a + n b ,for some integers m, n.In particular, this is the form of the greatest common divisor.In our example we have:

gcd(630, 196) = 14 = 5a – 16b = 5(630) – 16(196).

More examples:gcd(1800, 756) = 36 and here gcd(1800, 756) = 36 = 8(1800) – 19(756). (Check!)

Page 31: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

This example shows that gcd(a, b) can be expressed as anintegral linear combination of a and b.That is, each remainder can be written as:

m a + n b ,for some integers m, n.In particular, this is the form of the greatest common divisor.In our example we have:

gcd(630, 196) = 14 = 5a – 16b = 5(630) – 16(196).

More examples:gcd(1800, 756) = 36 and here gcd(1800, 756) = 36 = 8(1800) – 19(756). (Check!)

Page 32: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

This principle is summarized in the following theorem:Theorem [An important property!]: The greatest common divisor of integers a, b is an integral linear combination of them. That is, there are integers m, n such that:

gcd(a, b) = m a + n b

Remark: The sign of n, m is determined by the sign of a, b.If a, b, are naturals then n must be negative. If, for example, only b is negative, then m, n are positive etc.gcd(1800, 756) = 36 = 8(1800) - 19(756) gcd(1800, -756) = 36 = 8(1800) + 19(-756)

Page 33: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

Definition (Relatively prime):Two non-zero integers a, b are relatively prime iff gcd(a, b) = 1, that is, 1 is the only positive integer that dividesboth of them.

Example: gcd(15, 4) = 1, gcd(21, 6) = 1. Note that a, b, are not necessarily prime, only their dcg is 1.

Corollary of previous therem:Let a, b, x be integers with a | b x. If a, b are relatively prime, then a | x.

Page 34: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

Proof:Since a, b, are relatively primes, gcd(a, b) = 1.Then, by previous theorem, there are integers, m, n s.t.:

1 = m a + n b.Multiplying by x:

x = x m a + x n b.Clearly, a | (x m a) . We also have a | (x n b), as we assumed a | b x

(and x n b = n (b x) .)So a | (x m a) + (x n b) , but the latter is x, thus:

a | x . QED

Page 35: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

Problem:Suppose a, b, c are three non-zero integers, with a and c being relatively prime. Show that gcd(a, bc) = gcd(a, b).

Solution:

Let g1 = gcd(a, bc) , g2 = gcd(a, b) .

Since g2 | b we have g2 | bc, and since also g2 | a , we have g2 is

a divisor of a, and bc. Thus g2 g1 .

Next we show g2 g1.Since gcd(a, c) = 1 (a, c are relatively primes), there are integers m, n s.t.

1 = m a + n c.

Page 36: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Euclidean Algorithm

Solution (continue):1 = m a + n c.

Multiplying by b, we obtain: b = b m a + b n c.

By definition, g1 | a , g1 | b c , then we must have g1 | b m a + b n c (similarly to the corollary above). Thus

g1 | b .

Thus g1 is a divisor of a and b and we indeed have g1 g2 .

Therefore g1 = g2 .

QED

Page 37: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

gcd and glb in PosetsConsider the partial ordered set (N, | ) [That is, all ordered pairs of natural numbers (a,b) s.t. a | b .

We showed that it is reflexive, anti-symmetric, and transitive.]

Greatest lower bound:A greatest lower bound (glb, for short) of two elements a, b N (in the poset (N, | ) ) is an element g N , s.t.1. g | a, and g | b.2. If c | a , and c | b for some c N , then c | g .

What is the meaning of g in this case?- This is exactly gcd(a, b) ! In fact, it is divisible by any other common divisor of a and b.

Page 38: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The least common Multiple

We now would like to consider the smallest positive integer l that is divisible by two integer numbers a, b: this is the least common multiple.

Least common multiple:A least common multiple (lcm) of two integers a, b is an element l N , s.t.1. a | l , and b | l.2. If there is m N s.t. a | m , and b | m then m l.

Examples: lcm(4, 14) = 28, lcm(-6, 21) = 42, lcm(-5, -25) = 25 .

Page 39: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The least common Multiple

For two integers a, b , we have that |a| |b| is always a common multiple of a and b .Therefore lcm(a, b) always exists and lcm(a, b) |a| |b| .

Lemma:For any two integers a, b :

gcd(a, b) lcm(a, b) = |a| |b| .Proof sketch:When gcd(a, b) = 1, it is clear that lcm(a, b) = |a| |b|, as a, b are relatively primes (e.g., think about lcm(5, 7)=35 ). In this case,We indeed have gcd(a, b) lcm(a, b) = lcm(a, b) = |a| |b| .

Page 40: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The least common Multiple

Proof sketch (continue):When gcd(a, b) > 1, we make two observations:

• b / gcd(a,b) and b do not have any common divisor greater than 1. That is:

gcd(a, b / gcd(a,b) ) = 1 . (*)

Indeed, if gcd(a, b / gcd(a,b) ) = g > 1 then a, b are both divided by g gcd(a, b) , which is impossible, as gcd(a, b) is the greatest common divisor.

• lcm (a, b) = lcm (a, b / gcd(a,b) ) (we do not prove this part).

Page 41: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The least common Multiple

Proof sketch (continue):Putting these observations together, let c = b / gcd(a,b). Then:

lcm(a, b) = lcm(a, c) .Since gcd(a, c) = 1 (shown in (*) ) , we obtain

lcm (a, c) = |a| |c| = |a| |b| / gcd(a,b) Thus, we obtain:

lcm (a, b) = |a| |b| / gcd(a,b)

QED

Page 42: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The least common Multiple

The lemma gives an easy way to compute lcm(a, b): Just computegcd(a, b), and then extract |a| |b| / gcd(a, b) .

Examples:gcd(6, 12) = 3, thus lcm(6, 21) = 6(21)/3 = 6(7) = 42 .

gcd(630, -196) = 14, thus lcm(630, -196) = 630 (196)/14 = 8820.

Page 43: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The least common Multiple

gcd(630, -196) = 14, thus lcm(630, -196) = 630 (196)/14 = 8820.

Claim (w/o proof): Let a, b be integerslcm(a, b) is a divisor of all multiples of a and b.That is, least common multiple actually divides any other common multiple of a, b.

Examples:lcm(6, 21) = 6(21)/3 = 6(7) = 42 , and 6(21)/42 = 3. lcm(8, 12) = 8(12)/4 = 24, and 8(12)/24 = 4, but also 48 is a common multiple, and then 48/24 = 2.

Page 44: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

lub and lcm in PosetsConsider the partial ordered set (N, | ) as above.

Least upper bound:A least upper bound (lub, for short) of two elements a, b N (in the poset (N, | ) ) is an element l N , s.t.1. a | l, and b | l.2. If a | m , and b | m for some m N , then l | m .

What is the meaning of l in this case?- This is exactly lub(a, b) ! Due to the claim that lcm(a,b) divides any other (larger) common multiple of a and b.

Page 45: The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3

The Poset (N, | ) is a latticeRecall that a partial ordered set is a lattice if every two elements have a glb and a lub. Thus:

Proposition: The Poset (N, | ) is a lattice.[Any pair of elements a, b N have a gcd (glb) and a lcm (lub) .]