Week 6 notes

Comp 163-002, Spring 2020, MWF, 12:35-1:25, in Mundelein 620

The primary goal of this course is to become familiar with some of the basic mathematical ideas used in programming.


Homework 5

Levin p 146: 13abc, p 156: 1abcd, 5, 6; p 164: 1


Levin 1.6: Derangements

1.6.4: Derangements

-------------------

Reading for Levin Chapter 2

2.1: Recursive definition, p 138; Common sequences, p 140; Partial sums, p 142; Σ notation, p 143
2.2: Arithmetic and geometric sequences, and their sums. Entire section
2.3: Finite differences, and polynomial fitting in theory (in practice is a lot of algebra)
2.4: Closed forms for recursive definitions ("solving recurrence relations"): an+1 = an + f(n), (examples 2.4.3 and 2.44, p 168)
    an+1 = Aan + Ban-1 (characteristic roots, p 171)
2.5: Mathematical induction


Example 2.2.9

    S = 0.464646.... When we subtract from 100S, we get +46 on the right, but there is no minus term. Why?

2.3: Polynomial Fitting

Find 12 + 22 + 32 + ... + N2.

Polynomial fitting in general

Wednesday, Feb 19: Homework discussion

2.4: Recurrence Relations

Investigate!, page 167

def a(n):
    if n== 0: return 1
    if n==1: return 2
    return 5*a(n-1) - 6*a(n-2)
def b(n):
    if n== 0: return 1
    if n==1: return 3
    return 5*b(n-1) - 6*b(n-2)

def c(n):
    if n== 0: return 1
    if n==1: return 4
    return 5*c(n-1) - 6*c(n-2)

Example 2.4.2, p 168: verifying a recurrence rule

Example 2.4.3: an = an-1 + n: telescoping combined with known sum formulas

Example 2.4.4: same problem, alternative approach

Example 2.4.5: introduce a factor: an = 3*an-1 + 2. Make a guess?

def a(n):
    if n== 0: return 1
    return 3*a(n-1) + 2

    

Characteristic roots

Example 2.4.6

Example at start of section: an = 5*an-1 - 6*an-2

Fibonacci example

Friday: start here

An introduction to divisibility and congruence:

if a,b are in N, then a|b, or "a divides b" if ∃k∈N b=ak

b≡c mod a if a|(b-c)

2.5: Mathematical Induction

(and some from 5.2: Number Theory, p 307)

Postage in Investigate!; show 8 cent and 5 cent stamps can make any amount greater than or equal to 28 cents. Proof on p 179

Example 2.5.1: triangle numbers

Example 2.5.2: 6n-1 is divisible by 5 (p 182)

Fact: ∀a,d∈N ∃q,r∈N a = dq+r    d = divisor, q=quotient, r=remainder
Prove this by induction and by well-ordering

Consequence: for all a,n∈N there is b so: 0≤b<n and b≡a (mod n). So modular arithmetic comes down to Zn = {0,1,...,n-1}

Example 2.5.3: n2 < 2n for n>=5

Warning: Canadians, p 184

Euclidean algorithm theorem: for integers a and b<a, we can find q and r so a=qb+r