Reading: MCS 9.2 (gcd) 5.2-5.3 (strong induction)
Base-b representation of numbers
Strong induction
Euclid's GCD algorithm
When we write a number n∈N, we represent it as a sequence of digits dkdk−1…d2d1d0 where for each di, 0≤di<10. We interpret this string of digits as a number by reading d0 in the ones place, d1 in the tens place, d2 in the hundreds place, and so on. In other words, we have
n=dk⋅10k+dk−1⋅10k−1+⋯+d2⋅102+d1⋅101+d0⋅100=∑idi10i
We can represent the same number with digits between 0 and b for an arbitrary b using exactly the same interpretation (with b replacing 10); if dkdk−1…d2d1d0 is a string of digits with each di satisfying 0≤di<b, then
(dkdk−1…d2d1d0$)b=∑idibi
If this sum is n, we say that dk…d1d0 is a base-b representation of n.
binary is another name for base 2, octal means base 8, and hexadecimal means base 16. In computer languages, one often writes octal numbers with a preceeding 0 and hexadecimal numbers with a proceeding 0x.
When writing numbers in a base greater than 10, it is conventional to use letters for digits bigger than 10. The usual convention is a=10, b=11, …, f=15. For example, 930=(3A2)16 which might be written 0x3A2 in some programming languages; this is also equal to (1110100010)2.
The primary reason to use number bases other than 10 is that it is easy to divide by b with remainder: the remainder is just the last digit, and the quotient is given by the remaining digits. For example, hexadecimal is useful because when building computer systems it is convenient to store blocks of data of sizes that are powers of two; counting the number of blocks means dividing by a power of two, and often that means dividing by 16.
Claim: Every n∈N has a base-b representation for all b≥2.
Proof attempt: By induction on n. Fix b, and let P(n) be the statement "n has a base b representation." We will try to show P(0) and P(n) assuming P(n−1).
P(0) is easy: 0 is represented by the empty string of digits, because the sum over the empty sequence is 0:
()b=∑0≤i<0dibi=0.
If you prefer, we could take a single-digit representation 0=(0)b.
To prove P(n), first assume P(n−1), i.e. that n−1 has a base-b representation. We would like to use the fact that the last digit of the base b representation of n should be rem(n,b) and the other digits are the digits of quot(n,b). In other words, we would like to write the following:
Let q and r be the quotient and remainder of n over b. Let d0=r and let djdj−1…d2d1 be the digits of the base-b representation of q. Note that we have relabeled them so that the last digit is d1; this means quot(n,b)=∑idibi−1. Then n=qb+r=(∑i>0dibi−1)b+d0=∑i≥0dibi as required.
However, this proof is invalid, because of the line "let ⋯ be digits of the base-b representation of q". We can only do this if we know that q has a base-b representation, and that is what we are trying to prove.
We could consider using the inductive hypothesis, but this doesn't help, because the inductive hypothesis says that n-1 has a base-b representation, not that q has a base-b representation.
To make this proof go through, we need to strengthen the inductive hypothesis, so that it not only tells us n−1 has a base-b representation, but that every number less than or equal to n−1 has a base b representation. This will let us finish the proof as above, because q will be less than n.
Fixed proof: By induction on n. Let P(n) be the statement "for all k∈N with k≤n, k has a base-b representation." (Compare this to P(n) in the failed proof above). We will prove P(0) and P(n) assuming P(n−1).
To prove P(0), we must show that for all k with k≤0, that k has a base b representation. Since the only k≤0 is 0, this is exactly the same as the proof of P(0) above.
To prove P(n), we first assume P(n−1), i.e. that for all k≤n−1, k has a base-b representation. We must show that for all k≤n, that k has a base-b representation. Note that our assumption gives us almost all of the cases: if k≠n, then k≤n−1 so P(n−1) tells us that k has a base b representation. So all that's left is to show that n has a base b representation.
This part is the same as our aborted proof above, except that it works.
Let q and r be the quotient and remainder of n over b. Let d0=r and let djdj−1…d2d1 be the digits of the base-b representation of q we know this representation exists because q<n. Note that we have relabeled them so that the last digit is d1; this means quot(n,b)=∑idibi−1. Then n=qb+r=(∑i>0dibi−1)b+d0=∑i≥0dibi as required.
This is the idea behind strong induction. Given a statement P(n), you can prove ∀n,P(n) by proving P(0) and proving P(n) under the assumption ∀k<n,P(k). Compare this to weak induction, which requires you to prove P(0) and P(n) under the assumption P(n−1). Here is the proof above written using strong induction:
Rewritten proof: By strong induction on n. Let P(n) be the statement " n has a base-b representation." (Compare this to P(n) in the successful proof above). We will prove P(0) and P(n) assuming P(k) for all k<n.
To prove P(0), we must show that for all k with k≤0, that k has a base b representation. Since the only k≤0 is 0, this is exactly the same as the proof of P(0) above.
To prove P(n), we first assume P(k) for all k<n. We want to show that n has a base b representation.
Let q and r be the quotient and remainder of n over b. Let d0=r and let djdj−1…d2d1 be the digits of the base-b representation of q we know this representation exists because q<n so we have assumed P(q). Note that we have relabeled them so that the last digit is d1; this means quot(n,b)=∑idibi−1. Then n=qb+r=(∑i>0dibi−1)b+d0=∑i≥0dibi as required.
A technical tool that will be useful to us in the coming lectures is Euclid's algorithm for finding the greatest common divisor. The algorithm is given by an inductively defined function:
Let g:N×N→N be given as follows: g(a,0)::=a, and g(a,b)::=g(b,rem(a,b)). This inductive use of g is justified because rem(a,b)<b.
Claim: g(a,b) gives the greatest common divisor of a and b. That is, g(a,b) is a divisor of both a and b, and any other divisor c of both a and b is less than g(a,b). In fact, c|g(a,b).
Proof: By strong induction on b. Let P(b) be the statement "for all a, g(a,b)|a, g(a,b)|b, and if c|a and c|b then c|g(a,b)."
In the base case, we must choose an arbitrary a and show that:
In the inductive case, we assume that for all k<b, that P(k) holds. We wish to show P(n). Choose an arbitrary a.
We know g(a,b)=g(b,r) where a=qb+r and r<b. Since r<b, we can apply P(r) to conclude g(b,r)|b and g(b,r)|r, and also that if c|b and c|r then c|g(b,r). We must show:
Note that a|b if and only if −a|b if and only if a|−b. Therefore, for any a,b∈Z one can find gcd(a,b) by finding g(|a|,|b|).