The division algorithm
When reading this section, ask yourself why is this called an algorithm? You have not understood the main result below until you can confidently answer this question.
Theorem (Division algorithm / Q-R formula).
Let and be integers. Then, there are such that (1) ; and (2) .
And any two integers and satisfying (1) and (2) above are unique.
The integers and are called the quotient and the remainder, respectively, of the division of by . The next section is dedicated to the special case when ; here I denote by the symbol .
# Most programming languages have built-in methods to compute these
# The most common notation is:
q = a // d # The double / means integer division, as opposed to float.
r = a % d # Read as "a mod d".
Examples.
17 8 2 1 17 3 5 2 -17 8 -3 7
Proof of the division algorithm.
Let and be integers. I only focus on proving the existence of and in the case when is non negative, as this is the only part of the argument that requires induction. Concretely, the uniqueness argument should be done separately, and the general case when is an integer follows from the discussion presented here.
The case when is clear, since for any . Now, assume that the statement holds for all naturals smaller than and consider the following cases.
If , then writing fulfills the sought conditions, and no induction is needed.
If, on the other hand, , then applying the inductive hypothesis to the natural , which is of course less than , I get integers such that . But then, so letting I am done.
This is another illustrative example of how strong induction can be useful. Attempting to prove this by weak induction, one runs into the problem of having to use the fact that can be written as to accomplish the same for , which is cumbersome and not intuitive.
Exercises.
(For CS students) Implement this proof as an actual recursive algorithm.
Note:
Illustrative examples are seen in the lectures.
Divisibility
Definition.
Let and be integers. I say divides , in symbols , if there is an integer such that . Under these circumstances, I also say that is a divisor or factor of , and that is a multiple of .
Reflect.
How are this definition and the Q-R formula related? Could I have defined the relation in terms of the quotient and remainder? How?
An important observation is that the integer above, if it exists, must be unique by the Q-R formula.
As an example, because . Also, because . On the other hand, does not divide , because there is no integer such that .
Let us prove some elementary properties of divisibility before I leave some exercises.
Reflect.
As an exercise in abstraction, reflect on the fact that the first two properties of divisibility proved below are shared by other relations such as among sets, and among numbers.
Proposition.
Let be integers.
- Every integer divides itself. In symbols, . (Reflexivity)
- If and , then . (Transitivity)
- If and , then for any , . (Linearity, not to be confused with the Linear Algebra concept for transformations!)
Proof:
- Since , . The same equality proves that .
- Assume that and . By definition, there are integers and such that and . Then, using the associative properties of the product of integers, , and so .
- Solved in Tutorial 4.
An integer is called even if and odd otherwise. That is, even integers are of the form for some . By the division algorithm, an odd integer can be written as for some integer . Convince yourself of this fact before moving forward.
Exercises.
- For all , and .
- If is even, then ; but if is odd, then .
Hard problem.
The product of consecutive integers is divisible by . (, read as factorial is the product .)
Hint.
Use that and apply induction. Alternatively, use the result proved in Tutorial 4.
Prime numbers
Numbers with precisely four divisors (two positive and two negative) are called prime. Integers bigger than that are not prime are called composite. For example, is a prime number: its four divisors are and . is neither prime nor composite because it has two divisors: and . is composite because it has six divisors; the positive ones are .
To decide if a number is prime, it is not necessary to check for all numbers smaller than it for possible divisors.
Exercise.
Show that if an integer has no divisors satisfying , then must be prime. Give an example as to why the bound on is the best possible. In other words, the statement fails when I replace the bound by or .
Exercise.
There are arbitrarily large gaps between primes. Concretely, show that for any positive integer , you can find consecutive composite integers.
Hint.
Show that are always composite.
The lattice of integer divisibility
Note:
The concept of lattice is not explicitly part of the course, but several important examples are seen in the lectures. These follow informal discussions (and are hence inadequate for these notes) that summarize large portions of theory.