Properties of greatest common divisors [01E9]
- October 20, 2026
- Marcelo Fiore, Jon Sterling
Corollary [01ED]
- October 20, 2026
- October 20, 2026
- Marcelo Fiore, Jon Sterling
Let m and n be integers.
- For all integers k and l and g\in \mathsf {CD}{\mathopen {}\left (m,n\right )\mathclose {}} we have g\mid {\mathopen {}\left (k\cdot m + l\cdot n\right )\mathclose {}} . In other words, a common divisor of m and n divides any integer linear combination of m and n.
- If 1 is an integer linear combination of m and n, then m and n are coprime in the sense that \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = 1.
After attempting to prove this yourself, you may click this text to see my proof.
Proof of (1).
- October 20, 2026
- October 20, 2026
- Marcelo Fiore, Jon Sterling
Fix k and l and g such that g\mid m and g\mid n. Then m = g\cdot \operatorname {quo}{\mathopen {}\left (m,g\right )\mathclose {}} and n = g\cdot \operatorname {quo}{\mathopen {}\left (n,g\right )\mathclose {}} and hence k\cdot m + l\cdot n = k\cdot g \cdot \operatorname {quo}{\mathopen {}\left (m,g\right )\mathclose {}} + l \cdot g \cdot \operatorname {quo}{\mathopen {}\left (n,g\right )\mathclose {}} = g\cdot {\mathopen {}\left (k\cdot \operatorname {quo}{\mathopen {}\left (m,g\right )\mathclose {}} + l\cdot \operatorname {quo}{\mathopen {}\left (n,g\right )\mathclose {}}\right )\mathclose {}} and so g\mid k\cdot m + l\cdot n.
Proof of (2).
- October 20, 2026
- October 20, 2026
- Marcelo Fiore, Jon Sterling
We recall the definition of integer linear combination: we assume some k,l:\mathbb {Z} such that k\cdot m + l\cdot n = 1 and must prove that \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = 1. By (1), we have \gcd {\mathopen {}\left (m,n\right )\mathclose {}}\mid 1 which immediately implies \gcd {\mathopen {}\left (m,n\right )\mathclose {}}=1.
We will now establish some important algebraic laws concerning greatest common divisors. In fact, if you knew just a little bit about preorders we would be able to derive what follows in vastly greater generality with no mucking about with numbers whatsoever; ask me about category theory if you want to know why!
Lemma \gcd is commutative [01EE]
- October 20, 2026
- Marcelo Fiore, Jon Sterling
For all positive integers m and n, we have \gcd {\mathopen {}\left (m,n\right )\mathclose {}}=\gcd {\mathopen {}\left (n,m\right )\mathclose {}}\text {.}
After attempting to prove this yourself, you may click this text to see my proof.
Proof.
- October 20, 2026
- Marcelo Fiore, Jon Sterling
We recall from Observation [01E7] that \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = k if and only if \mathsf {CD}{\mathopen {}\left (m,n\right )\mathclose {}} = \mathsf {D}{\mathopen {}\left (k\right )\mathclose {}}. Therefore, it suffices to show observe \mathsf {CD}{\mathopen {}\left (m,n\right )\mathclose {}} = \mathsf {CD}{\mathopen {}\left (n,m\right )\mathclose {}} = \mathsf {D}{\mathopen {}\left (\gcd {\mathopen {}\left (n,m\right )\mathclose {}}\right )\mathclose {}} \text {.}
Lemma \gcd is associative [01EF]
- October 20, 2026
- Marcelo Fiore, Jon Sterling
For all positive integers l, m, and n, we have \gcd {\mathopen {}\left (l,\gcd {\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}}=\gcd {\mathopen {}\left (\gcd {\mathopen {}\left (l,m\right )\mathclose {}},n\right )\mathclose {}}
After attempting to prove this yourself, you may click this text to see my proof.
Proof using Observation [01E7].
- October 20, 2026
- Marcelo Fiore, Jon Sterling
By Observation [01E7], it suffices to show \mathsf {CD}{\mathopen {}\left (l,\gcd {\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} = \mathsf {D}{\mathopen {}\left (\gcd {\mathopen {}\left (\gcd {\mathopen {}\left (l,m\right )\mathclose {}},n\right )\mathclose {}}\right )\mathclose {}} \text {.} We calculate using the principle of subset extensionality as follows, using the fact that subset intersection is associative:
\begin {aligned} \mathsf {CD}{\mathopen {}\left (l,\gcd {\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} &= \mathsf {D}{\mathopen {}\left (l\right )\mathclose {}}\cap \mathsf {D}{\mathopen {}\left (\gcd {\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} \\ &= \mathsf {D}{\mathopen {}\left (l\right )\mathclose {}}\cap \mathsf {CD}{\mathopen {}\left (m,n\right )\mathclose {}} \\ &= \mathsf {D}{\mathopen {}\left (l\right )\mathclose {}}\cap {\mathopen {}\left ( \mathsf {D}{\mathopen {}\left (m\right )\mathclose {}}\cap \mathsf {D}{\mathopen {}\left (n\right )\mathclose {}} \right )\mathclose {}} \\ &= {\mathopen {}\left (\mathsf {D}{\mathopen {}\left (l\right )\mathclose {}}\cap \mathsf {D}{\mathopen {}\left (m\right )\mathclose {}}\right )\mathclose {}} \cap \mathsf {D}{\mathopen {}\left (n\right )\mathclose {}} \\ &= \mathsf {CD}{\mathopen {}\left (l,m\right )\mathclose {}}\cap \mathsf {D}{\mathopen {}\left (n\right )\mathclose {}} \\ &= \mathsf {D}{\mathopen {}\left (\gcd {\mathopen {}\left (l,m\right )\mathclose {}}\right )\mathclose {}}\cap \mathsf {D}{\mathopen {}\left (n\right )\mathclose {}} \\ &= \mathsf {CD}{\mathopen {}\left (\gcd {\mathopen {}\left (l,m\right )\mathclose {}},\mathsf {D}{\mathopen {}\left (n\right )\mathclose {}}\right )\mathclose {}} \\ &= \mathsf {D}{\mathopen {}\left ( \gcd {\mathopen {}\left ( \gcd {\mathopen {}\left (l,m\right )\mathclose {}}, n \right )\mathclose {}} \right )\mathclose {}} \end {aligned}Proof by universal property.
- October 20, 2026
- Marcelo Fiore, Jon Sterling
Alternatively, we can give a direct proof using the universal property of the greatest common divisor. It suffices to show that for all naturals d, we have d\mid \gcd {\mathopen {}\left (l,\gcd {\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} \Longleftrightarrow d\mid \gcd {\mathopen {}\left (\gcd {\mathopen {}\left (l,m\right )\mathclose {}},n\right )\mathclose {}}\text {.}
We calculate:
\begin {aligned} d \mid \gcd {\mathopen {}\left (l,\gcd {\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} &\Longleftrightarrow d \mid l \land d\mid \gcd {\mathopen {}\left (m,n\right )\mathclose {}} \\ &\Longleftrightarrow d\mid l \land {\mathopen {}\left (d \mid m\land d\mid n\right )\mathclose {}} \\ &\Longleftrightarrow {\mathopen {}\left (d\mid l\land d\mid m\right )\mathclose {}}\land d\mid n \\ &\Longleftrightarrow d\mid \gcd {\mathopen {}\left (l,m\right )\mathclose {}}\land d\mid n \\ &\Longleftrightarrow d\mid \gcd {\mathopen {}\left (\gcd {\mathopen {}\left (l,m\right )\mathclose {}},n\right )\mathclose {}} \end {aligned}Both proofs are correct! In some cases one style might be easier than the other. Universal properties are very powerful and one should not be afraid to use them directly.
Lemma \gcd is linear [01EG]
- October 20, 2026
- Marcelo Fiore, Jon Sterling
For positive integers l, m, and n we have l\cdot \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = \gcd {\mathopen {}\left (l\cdot m, l\cdot n\right )\mathclose {}}\text {.}
Hint: for this one, try thinking about how Euclid’s algorithm computes.
After attempting to prove this yourself, you may click this text to see my proof.
Proof.
- October 20, 2026
- Marcelo Fiore, Jon Sterling
We recall Euclid’s algorithm below:
let rec gcd (m, n) = let r = rem (m, n) in if r = 0 then n else gcd (n, r)
We consider the case where both arguments are multiplied by l:
gcd (l * m, l * n) = let r = rem (l * m, l * n) in if r = 0 then l * n else gcd (l * n, r)
Note that rem (l * m, l * n) = l * (rem (m, n)).
gcd (l * m, l * n) = let r = l * (rem (m, n)) in if r = 0 then l * n else gcd (l * n, r)
Furthemore, because l is assumed positive, l * (rem (m, n)) is equal to zero if and only if rem (m, n) is. So we may rewrite as follows:
gcd (l * m, l * n) = let r = rem (m, n) in if r = 0 then l * n else gcd (l * n, l * r)
We now consider the entire trace of recursive calls. If gcd (l * m, l * n) returns straightaway, we must have had rem (m, n) = 0 and it returns l * n which is indeed l * (gcd (m, n)). If there is a recursive call to gcd (l * n, l * r) we may assume by induction that gcd (l * n, l * r) = l * (gcd (n, r)), which is exactly what we needed.