[an error occurred while processing this directive]

[From previous lecture: What is the running time of mergesort?]
Compare n, n log n, n^2, n^3, 2^n for n=10,100,1000,2000

[Ian: potiential hw problem: characterize f(x) = x^k in terms of f(2n) vs f(n)?]

Division

Defn: a|b

Th'm 1: ∀a,b,c ∈ Z, a|b, a|c ⇒ a|(b+c)
Corrolary: ∀ a,b,c ∈ Z, a|b, a|c ⇒ a|(b-c)

For a base d, any integer a can be written
a=q⋅d+r [1]
where r "remainder" is 0 ≤ r < d; call q "quotient".
q = a div m
r = a mod m

Self-exercise:

Modular arithmetic

Seven o'clock + 6hrs ≡ 1 o'clock.
Seven o'clock + 50hrs ≡ 9 o'clock.
This is mod 12 arithmetic (or, mod 12 +1, since we go from 1..12 rather than 0..11.
Or on a 24hr clock, we go 0:00..23:59 back to 0:00.

[Note a 12hr clock inconsistency: midnight = 12:00am, but 1:00am is just after — that is, 12am < 1am, even though 12 isn't < 1. The off-by-one bug in pop culture, sigh.]

[With a 24hr clock, note that Wed.24:00 = Thurs 0:00. With this convention, we see that the term ``midnight'' is usually intended to mean ``24:00'', not ``0:00''.]

(Using mod 12 to represent months — a good idea? month+num okay, but month⋅num, month+month etc should be disallowed.)

Congruences

We say 13 ≡ 1, mod 12.
2 ≡ 14 ≡ 26 ≡ 38 ≡ 2 ≡ -10, mod 12.
(Other notations: div,mod; quotient,remainder, /,% )

a ≡ b mod 12, if 12|(a-b).
This is equivalent to: a mod 12 = b mod 12.

We call this structure "Z/12" or "Z12".
Note that Z/12 partitions Z into 12 "equivalence classes" —

(Aside:) Alternate, equivalent def'n of "mod":
"1 (mod 12)" can be viewed as the entire set {…,-11,1,13,25,…} = { 12k+1 | k in N }
Similarly "10 (mod 12)" can be viewed as the entire set {…,-2,10,22,34,…}

Note that we usually do think of 18 mod 12 as its "canonical representive" element, 6. We also say two numbers are congruent if they are in the same equivalence class, mod m. We usually stay in [0,m) or (when helpful) (-m,m).

Here's why we can conveniently just consider a representative:

So to add numbers mod n, replace each number with something congruent (mod n), and do the addition in regular ol' N. This phrasing of modular-addition raises a question: Is it well-defined? That is, do we get different answers depending on which elements a0,b0 we choose congruent to a,b?

Th'm: addition mod 12 is ``well defined''. Well, we'll phrase this as:
Th'm 2: ∀ n∈N+, ∀a,b,a0,b0 ∈ Z, we have:
If a≡a0 (mod n), and b≡b0 (mod n), then a+b &equiv a0+b0 (mod n).
Prove it!

We have a similar theorem to above:
Th'm 3: ∀ n∈N+, ∀a,b,a0,b0 ∈ Z, we have
If a≡a0 (mod n), and b≡b0 (mod n), then a⋅b &equiv a0⋅b0 (mod n).
Proof similar to Th'm 2.
Corollary 4: ∀ n∈N+, ∀a,a0 ∈ Z, ∀ k ∈ N,
a ≡ a0 (mod n)  ⇒  ak ≡ a0k (mod n).
Proof: by Th'm 3 and induction; left to the reader.

Note: ⟨Z/2,+,⋅⟩ is isomorphic to ⟨B,xor,and⟩; "or" corresponds to "max" (within Z/2).
Note that maxZ/2 isn't the extension of maxZ — (That is, Thm's 1 and 2 showed that + and ⋅ were robust under the mod operation, but max isn't.)

Casting out 11ses

A grade-school trick to check whether a number is divisible by three is to add up the numeral's digits; the original number is divisible the three iff the digit-sum is also divisible by 3. Thus, to check whether 48725 is divisible by three, we just need to know whether 4+8+7+2+5=26 is divisible by three. Repeating, we reduce this question further: 26 is divisible by three iff 2+6=8 is divisible by three, which it isn't.

Note that we need to distinguish between number, numeral, and digit — a numeral is a particular representation of a number. (Think of numerals as being strings.) We use the notation []10 to denote the function that takes a numeral and return the number it represents (base 10). This function might be called something like string->number or new java.math.BigDecimal(•) in your programming language.

Why does this trick work? I'll leave it to you to figure out, but we will look at a different trick:
Let ads(n) be the ``alternating digit sum'' of n. The alternating digit sum of 48725 is 4-8+7-2+5 = 6. We will magically conclude that 48725 ≡ 6 (mod 11). (Sure enough, we can double-check that 48725 = 11⋅4429 + 6.)

Before discussing why this works, How do we define ads() more precisely?

Defn: ads([dm…d2d1d0]10) = ∑i=0i=m(-1)idi.
Note that we make the final digit of the sum always be added positively. (We do our alternating sum right-to-left, if you prefer.)

Theorem: n ≡ ads(n) (mod 11).

As always, the first step to understanding (the proof of) the theorem is to look at some examples.
After satisfied that it works on test cases, we wonder why it works. Clearly we are relating a number to its base-10 representation; it's helpful to remember that 48725 = 4⋅10000 + 8⋅1000 + 7⋅100 + 2⋅10 + 5⋅1.
Note that some of these numbers are nice, mod 11: 100 = 99 + 1 = 9⋅11 + 1 ≡ 1 (mod 11), and similarly 10000 = 9999 + 1 = 909⋅11+1 ≡ 1 (mod 11). So actually, 48725 ≡ 4⋅1 + 8⋅1000 + 7⋅1 + 2⋅10 + 5⋅1 (mod 11).
Alas, 10 and 1000 (and odd powers of 10) aren't congruent to 1 mod 11. But, 10 ≡ -1 (mod 11), and hey -1 is what puts the ``alternate'' into ``ads''. Could we be on to something? Is 1000 ≡ -1 (mod 11)? Yes, after checking by hand, we realize 1000 = 11⋅91-1 ≡ -1 (mod 11). Upon more reflection, we could have said 103 ≡ (-1)3 ≡ -1 (mod 11). So now we have some understanding of why 40000 - 8000 + 700 - 20 + 5 ≡ 4-8+7-2+5 (mod 11).

How do we prove this in general? (Is this just a fluke of the particular number 48725?)

Proof: We need to get at the digits of n. Let
n = [dm…d2d1d0]10.
(We know n has a unique representation base 10; we have just given names to the digits.)
Note that n = ∑i=0i=mdi⋅10i (by the meaning of arabic numerals base 10).
This is easy once we observe that 10i ≡ (-1)i (mod 11) for all i ∈ N (by Corollary 4 above).
Then: n = ∑i=0i=mdi⋅10i ≡ ∑i=0i=mdi⋅(-1)i (mod 11) = ads(n).

Challenge: The above proof generalizes to any base b, not just base 10! Prove the theorem using not eleven, but rather [11]b.

Other problems:

[an error occurred while processing this directive] [an error occurred while processing this directive]