Subsection 2.1.1 Statement and examples
Letβs start off with the division algorithm. This is the familiar elementary school fact that if you divide an integer
by a positive integer
you will always get an integer remainder
that is nonnegative, but less than
Equally important, there is
only one possible remainder under these circumstances.
Theorem 2.1.1. Division Algorithm.
For
and
we can always write
with
and
an integer. Moreover, given
there is only one pair
which satisfy these constraints. We call the first element
the quotient, and the second one
the remainder.
Proof.
Finding
and
is easy in small examples like
For bigger values itβs nice to have the result implemented in Sage.
We can check the correctness of the Sage output by multiplying and adding back together.
Sage note 2.1.2. Counting begins at zero.
There are several things to note about this early computation. First, note that the answer to
divmod
came in parentheses, a so-called
tuple data type.
Second, there is another way to approach this computation, more programmatically so that itβs easier to reuse. What do you think the
[0]
and
[1]
mean?
To access the first and second parts of the answer (the quotient and remainder), we use square brackets, asking for the
0th and 1st parts of the tuple
(9702,18)
! (This operation is called
indexing.) In Python, the programming language behind Sage (as in many other languages), counting begins at zero.
The discussion in the previous note actually turns out to be an enduring argument in number theory, too. Do we only care about positive numbers, or nonnegative ones as well? We saw this in the stamps example, since one could send a package for free under certain circumstances (campus mail), but might not care about that case. Similarly, are we required to use at least one of each type of stamp, or is it okay (as in our problem) to not use one type?
Subsection 2.1.2 Proof of the Division Algorithm
One neat thing about the division algorithm is that it is not hard to prove but still uses the
Well-Ordering Principle; indeed, it depends on it. The key set is the set of all possible remainders of
when subtracting multiples of
which we call
(Note that the set looks the same if we
add multiples of
since
but for the purposes of exposition it is easier to think of it as subtraction.)
The object of main interest in the proof will be the nonnegative piece of
which we will call
For example, if
then
while
Our strategy will be to apply the well-ordering principle to
(It is worth thinking briefly about why both
and
are nonempty.) Give the name
to the smallest element of
which must be writeable as
(thatβs the definition of being an element of
after all).
Now letβs briefly suppose by way of contradiction that
In that case we could subtract
from
and then
as well. So
would not be the least element of
which is a contradiction. Hence we know that
(Note that
is the smallest nonnegative number in
just as with our intuition regarding remainders from school.)
We still have to show that
and
are the only numbers fulfilling this statement. Suppose
for some integers
where
clearly if
then we can solve
to get
(since
), so the only interesting case is if
Without loss of generality, we can assume
In that case,
which can be rewritten as
Since
by
Fact 1.2.2 must be at least one if it isnβt zero. But then
or
which contradicts
Thus
and hence
and
Itβs worth actually trying out the details of this proof with some
and
say with
and
As a scholium (see
Exercise 2.5.1) note that if
there can still be a positive remainder, but here we would need
in the theorem.
Subsection 2.1.3 Uses of the division algorithm
Itβs kind of fun to prove interesting things about powers using the division algorithm, and likely you did in a previous course. For instance, there is an interesting pattern in the remainders of integers when dividing by 4. If you are online, evaluate the following Sage cell to see the pattern. (Itβs also easy to just get the remainders of the first ten or so perfect squares by hand.)
Sage note 2.1.3. Repeating commands for different input.
The syntax
for i in [0..10]:
just means we want to do the next command for integers from 0 to 10. Such a repetition is called a
loop.
Another way Python uses to generate the list of different input is the
range
command; try substituting
range(11)
for
[0..10]
in the Sage cell above. Can you discover what the difference is between these?
The rest of the command (all the percent symbols and so forth) is mostly for correct formatting. That includes the indentation in the second line β an essential part of Python and Sage.
This certainly provides strong numerical evidence for the following proposition. But better than that will be the proof!
Proposition 2.1.4.
A perfect square always leaves remainder
or
when divided by 4.
Proof.
Using the division algorithm, we can write What happens if we square it,
Algebraically this yields Clearly this is a multiple of 4 plus So the only possible remainders of are the remainders of where is already known to be less than 4!
Now check these yourself to see that the only possibilities are the ones in the statement of the proposition.
One cool thing about this proof is that if we just change the proof from using
to one using
we can essentially do the same thing for several divisions at once. If the number we divide by is
then
hence all that matters for the final remainder is
since the rest is already divisible by
But we know that there are only
possibilities for
so itβs easy to check all
their squares. For
the following cell checks for you if you donβt want to check them by hand.
This verifies that
are the only possible remainders of perfect squares when you divide by six.