- Reading: MCS Chapter 9.1
We spent most of lecture talking about Turing machines; these notes have been added to the lecture 28 notes

We proved the Euclidean division algorithm/theorem

**Review exercises**- state and prove the euclidean division algorithm.
- "execute" the algorithm contained in the proof for a few steps to see how it works
- this is a different algorithm than you normally use for division with remainder; try to encode your algorithm for division with remainder as an inductive proof.
- Prove that if \(a|b\) and \(a|c\) then for any \(s\) and \(t\), \(a|sb+tc\).

\(\mathbb{Z}\) is the set of integers \(\{\dots, -2, -1, 0, 1, 2, \dots\}\)

If \(a,b \in \mathbb{Z}\) then \(a\)

**divides**\(b\) (written \(a | b\)) if there exists some \(k \in \mathbb{Z}\) such that \(b = ak\). In this case, \(b\) is a**multiple**of \(a\).Unless otherwise specified, for the lectures on number theory, variables are taken from \(\mathbb{Z}\). I will tend to use \(a\), \(b\), \(p\), \(q\), \(r\) to denote integers.

**Don't use fractions for a few weeks:**While studying number theory, we will be working exclusively with integers. The division operation doesn't make sense in general for integers; writing fractions in your equations will only lead to confusion.

**Claim (Euclidean division algorithm):** For any \(a\) and \(b > 0\) there exist \(q\) and \(r\) such that \(a = qb+r\) and \(0 \leq r \lt b\). Moreover, \(q\) and \(r\) are unique: if \(a = qb + r = q'b + r'\) then \(q = q'\) and \(r = r'\).

**Notation:** - \(q\) is called the **quotient** of \(a\) by \(b\), and is written **\(quot(a,b)\)**. Some programming languages write \(a/b\) to refer to \(q\). **Do not do this**. \(a/b\) should have the property that \(b \cdot (a/b) = a\); the quotient does not have this property.

\(r\) is called the

**remainder**of \(a\) by \(b\), and is written**\(rem(a,b)\)**. Some languages write \(a \% b\) to refer to \(r\), but many languages give the wrong answer when \(a\) is negative. Some books write \(a~mod~b\), but this notation will lead to confusion when we start talking about modular arithmetic, so it should be avoided.Note that the uniqueness criteria in the claim is another way of saying that \(quot\) and \(rem\) are well-defined functions from \(\mathbb{Z} \times \mathbb{Z}\) to \(\mathbb{Z}\).

**Proof of existence:** By induction on \(a\). Fix \(b\) and let \(P(a)\) be the statement "\(∃ q, r \in \mathbb{Z}\) such that \(a = qb + r\)." We must prove \(P(0)\) and \(P(a+1)\) assuming \(P(a)\).

For \(P(0)\), let \(q = r = 0\). Since \(b > 0\), \(0 \leq r \lt b\). Moreover, \(0 = qb + r\) as required.

To prove \(P(a+1)\), assume \(P(a)\). Then there exist some \(q'\) and \(r' \lt b\) with \(a = q'b + r'\). Since \(r' \lt b\), either \(r' = b-1\) or \(r' \lt b-1\). We want to show that in either case, there exist \(q\) and \(r\) with \(a + 1 = qb + r\).

In the former case, we have \(a = q'b + r' = q'b + b-1\). Therefore \(a + 1 = q'b + b = (q'+1)b + 0\). Let \(q = q'+1\) and \(r = 0\), and we see that \(a + 1 = qb + r\) as required.

In the latter case, we can let \(q = q'\) and \(r = r'+1\). Since \(0 \leq r' \lt b-1\), we see that \(0 \leq r \lt b\). Moreover, since \(a = q'b + r'\), we see that \(a + 1 = qb + r\) as required.

**Proof of uniqueness:** Assume there are two pairs of numbers \(q_1, r_1\) and \(q_2, r_2\) with \(a = q_1b + r_1 = q_2b + r_2\) and with \(0 \leq r_i \lt b\). We want to show that \(q_1 = q_2\) and \(r_1 = r_2\).

Rearranging \(q_1b + r_1 = q_2b + r_2\), we see that \((q_1 - q_2)b = r_2 - r_1\). I claim that \(-b \lt r_2 - r_1 \lt b\), and the only multiple of \(b\) between \(-b\) and \(b\) is \(0\), so \(r_2 - r_1 = 0\).

To see this more carefully, we know \(0 \leq r_2 \lt b\). The same equation holds for \(r_1\); negating it yields \(-b \lt -r_1 \leq 0\). Adding these equations together gives \(-b \lt r_2 - r_1 \lt b\).

Therefore \(r_2 - r_1 = 0\), so \(r_2 = r_1\). Since \((q_1 - q_2)b = r_2 - r_1 = 0\) and since \(b \neq 0\), we have \(q_1 - q_2 = 0\), or \(q_1 = q_2\).