1 / 51

CS322

Week 6 - Friday. CS322. Last time. What did we talk about last time? Solving recurrence relations. Questions?. Logical warmup. This is a donkey made of toothpicks Move exactly one toothpick to make an identical donkey oriented in another direction.

bess
Download Presentation

CS322

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 6 - Friday CS322

  2. Last time • What did we talk about last time? • Solving recurrence relations

  3. Questions?

  4. Logical warmup • This is a donkey made of toothpicks • Move exactly one toothpick to make an identical donkey oriented in another direction

  5. Solving Second-Order Linear Homogeneous Relations with Constant Coefficients Student Lecture

  6. Solving Second-Order Linear Homogeneous Relations with Constant Coefficients

  7. Second-Order Linear Homogeneous Relations with Constant Coefficients • Second-order linear homogeneous relations with constant coefficients are recurrence relations of the following form: • ak = Aak-1 + Bak-2 where A, B R and B  0 • These relations are: • Second order because they depend on ak-1 and ak-2 • Linear because ak-1 and ak-2 are to the first power and not multiplied by each other • Homogeneous because there is no constant term • Constant coefficients because A and B are fixed values

  8. Why do we care? • I'm sure you're thinking that this is an awfully narrow class of recurrence relations to have special rules for • It's true: There are many (infinitely many) ways to formulate a recurrence relation • Some have explicit formulas • Some do not have closed explicit formulas • We care about this one partly for two reasons • We can solve it • It lets us get an explicit formula for Fibonacci!

  9. Pick 'em out • Which of the following are second-order linear homogeneous recurrence relations with constant coefficients? • ak = 3ak-1 + 2ak-2 • bk = bk-1 + bk-2+ bk-3 • ck = (1/2)ck-1 – (3/7)ck-2 • dk = d2k-1 + dk-1dk-2 • ek = 2ek-2 • fk = 2fk-1 + 1 • gk = gk-1 + gk-2 • hk = (-1)hk-1 + (k-1)hk-2

  10. Characteristic equation • We will use a tool to solve a SOLHRRwCC called its characteristic equation • The characteristic equation of ak = Aak-1 + Bak-2 is: • t2 – At – B = 0 where t 0 • Note that the sequence 1, t, t2, t3, …, tn satisfies ak = Aak-1 + Bak-2 if and only if t satisfies t2 – At – B = 0

  11. Demonstrating the characteristic equation • We can see that 1, t, t2, t3, …, tn satisfies ak = Aak-1 + Bak-2 if and only if t satisfies t2 – At – B = 0 by substituting in t terms for ak as follows: • tk = Atk-1 + Btk-2 • Since t 0, we can divide both sides through by tk-2 • t2 = At + B • t2 – At – B = 0

  12. Using the characteristic equation • Consider ak = ak-1 + 2ak-2 • What is its characteristic equation? • t2 – t – 2 = 0 • What are its roots? • t = 2 and t = -1 • What are the sequences defined by each value of t? • 1, 2, 22, 23, …, 2n, … • 1, -1, 1, -1, …, (-1)n, … • Do these sequences satisfy the recurrence relation?

  13. Finding other sequences • An infinite number of sequences satisfy the recurrence relation, depending on the initial conditions • If r0, r1, r2, … and s0, s1, s2, … are sequences that satisfy the same SOLHRRwCC, then, for any C, D R, the following sequence also satisfies the SOLHRRwCC • an = Crn + Dsn, for integers n ≥ 0

  14. Finding a sequence with specific initial conditions • Solve the recurrence relation ak = ak-1 + 2ak-2 where a0 = 1 and a1 = 8 • The result from the previous slide says that, for any sequence rk and sk that satisfy ak • an = Crn + Dsn, for integers n ≥ 0 • We have these sequences that satisfy ak • 1, 2, 22, 23, …, 2n, … • 1, -1, 1, -1, …, (-1)n, … • Thus, we have • a0 = 1 = C20 + D(-1)0 = C + D • a1 = 8 = C21 + D(-1)1 = 2C – D • Solving for C and D, we get: • C = 3 • D = -2 • Thus, our final result is an = 3∙2n – 2(-1)n

  15. Distinct Roots Theorem • We can generalize this result • Let sequence a0, a1, a2, … satisfy: • ak = Aak-1 + Bak-2 for integers k ≥ 2 • If the characteristic equation t2 – At – B = 0 has two distinct roots r and s, then the sequence satisfies the explicit formula: • an = Crn + Dsn • where C and D are determined by a0 and a1

  16. Now we can solve Fibonacci! • Fibonacci is defined as follows: • Fk = Fk-1 + Fk-2, k ≥ 2 • F0 = 1 • F1 = 1 • What is its characteristic equation? • t2 – t – 1 = 0 • What are its roots? • Thus,

  17. We just need C and D • So, we plug in F0 = 1 and F1 = 1 • Solving for C and D, we get • Substituting in, this yields

  18. Single-Root Case • Our previous technique only works when the characteristic equation has distinct roots r and s • Consider sequence ak = Aak-1 + Bak-2 • If t2 – At – B = 0 only has a single root r, then the following sequences both satisfy ak • 1, r1, r2, r3, … rn, … • 0, r, 2r2, 3r3, … nrn, …

  19. Single root equation • Our old rule said that if r0, r1, r2, … and s0, s1, s2, … are sequences that satisfy the same SOLHRRwCC, then, for any C, D R, the following sequence also satisfies the SOLHRRwCC • an = Crn + Dsn, for integers n ≥ 0 • For the single root case, this means that the explicit formula is: • an = Crn + Dnrn, for integers n ≥ 0 • where C and D are determined by a0 and a1

  20. SOLHRRwCC recap • To solve sequence ak = Aak-1 + Bak-2 • Find its characteristic equation t2 – At – B = 0 • If the equation has two distinct roots r and s • Substitute a0 and a1 into an = Crn + Dsn to find C and D • If the equation has a single root r • Substitute a0 and a1 into an = Crn + Dnrn to find C and D

  21. General Recursive Definitions

  22. Defining anything recursively • For example, we can define sets recursively • To do so, we need three things: • Base: A statement of that certain things are in the set • Recursion: A set of rules saying how new objects can be shown to be in the set based on ones that are already known to be in the set • Restriction: A statement that no objects belong to the set other than those coming from I and II

  23. Example • The set P of all strings of legal parenthesizations • Base: () is in P • Recursion: • If E is in P, so is (E) • If E and F are in P, so is E F • Restriction: No configurations of parentheses are in P other than those derived from I and II

  24. Ackermann function • Even functions can be defined recursively • The Ackermann function is famous because it grows faster than any algebraic function • It is defined for all non-negative integers as follows: • A(0,n) = n + 1 • A(m,0) = A(m – 1, 1) • A(m,n) = A(m – 1, A(m,n – 1)) • Find A(1,2) • I won't make you find A(4,4), because it is roughly

  25. Set Theory

  26. Sets • A set is a collection of elements • The set is defined entirely by its elements • Order doesn't matter • Repetitions don't matter (but, in general, we write each element of set only a single time) • Examples • { 1, 4, 9, 25 } • { 1 } is not the same as 1 • { } is the empty set

  27. Notation • For a finite set, we can write all of the elements inside curly braces • For infinite sets, we don't have that luxury • What's in each of the following sets? • A = { x R | -3 < x < 4 } • B = { x Z | -3 < x < 4 } • C = { x Z+ | -3 < x < 4 } • D = { x Q | -3 < x < 4 }

  28. Subsets • Perhaps the simplest relationship between sets is the subset relationship • We say that X is a subset of Yiff every element of X is an element of Y • Notation X Y • Examples: • Is { 1, 2, 3 }  { 1, 2, 3, 4 } ? • Is { 1, 2, 3, 4 }  { 1, 2, 3 } ? • Is { 1, 2, 3 }  { 1, 2, 3 } ? • Is { }  { 1, 2, 3 } ? • Is { {1}, {2}, {3} }  { 1, 2, 3 } ?

  29. Proper subsets • We say that X is a proper subset of Yiff every element of X is an element of Y, but there is some element of Y that is not an element of X • Notation X Y • Examples: • Is { 1, 2, 3 }  { 1, 2, 3, 4 } ? • Is { 1, 2, 3, 4 }  { 1, 2, 3 } ? • Is { 1, 2, 3 }  { 1, 2, 3 } ? • Is { }  { 1, 2, 3 } ? • Is { {1}, {2}, {3} }  { 1, 2, 3 } ?

  30. Venn diagrams • Venn diagrams show relationships between sets • They can help build intuition about relationships, but they do not prove anything • Also, their usefulness is limited to 2 or 3 sets • Beyond that, they become difficult to interpret • Example: For XY, there are 3 possibilities: X X Y X Y Y

  31.  vs.  • The idea of being an element of a set is strongly tied to the idea of one set being the subset of another • These two relationships are different, however • xX means that x is an element of X • Y  X means that Y is a subset of X • Which of the following are true? • 2  {1, 2, 3} • {2}  {1, 2, 3} • 2  {1, 2, 3} • {2}  {1, 2, 3} • {2}  {{1}, {2}} • {2}  {{1}, {2}}

  32. Set equality • We say that two sets are equal if they contain exactly the same elements • Another way of saying this is that X = YiffX Y and Y  X • Examples: • A = { n  Z | n = 2p, p  Z } • B = the set of all even integers • C = { m  Z | m = 2q – 2, q  Z } • D = { k  Z | k = 3r + 1, r  Z } • Does A = B? • Does A = C? • Does A = D?

  33. Set operations • We usually discuss sets within some superset U called the universe of discourse • Assume that A and B are subsets of U • The union of A and B, written A B is the set of all elements of U that are in either AorB • The intersection of A and B, written A B is the set of all elements of U that are in AandB • The difference of B minus A, written B – A, is the set of all elements of U that are in B and not in A • The complement of A, written Ac is the set of all elements of U that are not in A

  34. Examples • Let U = {a, b, c, d, e, f, g} • Let A = {a, c, e, g} • Let B = {d, e, f, g} • What are: • A B • A  B • B – A • Ac

  35. The empty set • There is a set with no elements in it called the empty set • We can write the empty set { } or  • It comes up very often • For example, {1, 3, 5}  {2, 4, 6} =  • The empty set is a subset of every other set (including the empty set)

  36. Disjoint sets and partitions • Two sets A and B are considered disjoint if A B =  • Sets A1, A2, … An are mutually disjoint (or nonoverlapping) if Ai  Aj =  for all i  j • A collection of nonempty sets {A1, A2, … An} is a partition of set Aiff: • A = A1  A2  …  An • A1, A2, … An are mutually disjoint

  37. Power set • Given a set A, the power set of A, writtenP(A) or 2A is the set of all subsets of A • Example: B = {1, 3, 6} • P(B) = {, {1}, {3}, {6}, {1,3}, {1,6}, {3,6}, {1,3,6}} • Let n be the number of elements in A, called the cardinality of A • Then, the cardinality of P(A) is 2n

  38. Cartesian product • An ordered n-tuple (x1, x2, … xn) is an ordered sequence of n elements, not necessarily from the same set • The Cartesian product of sets A and B, written A x B is the set of all ordered 2-tuples of the form (a, b), a A, b  B • Thus, (x, y) points are elements of the Cartesian product R x R (sometimes written R2)

  39. Subset Relations

  40. Basic subset relations • Inclusion of Intersection: • For all sets A and B • A B  A • A B  B • Inclusion in Union: • For all sets A and B • A A B • B  A B • Transitive Property of Subsets: • If A  B and B  C, then A  C

  41. Element argument • The basic way to prove that X is a subset of Y • Suppose that x is a particular but arbitrarily chosen element of X • Show that x is an element of Y • If every element in X must be in Y, by definition, X is a subset of Y

  42. Procedural versions • We want to leverage the techniques we've already used in logic and proofs • The following definitions help with this goal: • x X  Y  x  X  x  Y • x X  Y  x  X  x  Y • x X – Y  x  X  x  Y • x Xc  x  X • (x, y)  X  Y  x  X  y  Y

  43. Example proof Theorem: For all sets A and B, A B  A Proof: • Let x be some element in A  B • x  A  x  B • x  A • Thus, all elements in A  B are in A • A B  A QED • Premise • Definition of intersection • Specialization • By generalization • Definition of subset

  44. Laying down the law (again)

  45. Proving set equivalence • To prove that X = Y • Prove that X Y and • Prove that Y X

  46. Example proof of equivalence Theorem: For all sets A,B, and C, A (B  C) = (A B) (A C) Proof: • Let x be some element in A (B  C) • x  A  x  (B  C) • Case 1: Let x  A • x  A  x  B • x  A  B • x  A  x  C • x  A  C • x  A  B  x  A  C • x  (A B) (A C) • Case 2: Let x  B  C • x  B  x  C • x  B • x  A  x  B • x  A  B • x  C • x  A  x  C • x  A  C • x  A  B  x  A  C • x  (A B) (A C) • In all possible cases, x  (A B) (A C), thus A (B  C)  (A B) (A C)

  47. Proof of equivalence continued • Let x be some element in (A B) (A C) • x  (A B)  x  (A C) • Case 1: Let x  A • x  A  x  B  C • x  A  (B  C) • Case 2: Let x  A • x  A B • x  A  x B • x  B • x  A  C • x  A  x C • x  C • x  B  x  C • x  B  C • x  A  x  B  C • x  A  (B  C) • In all possible cases, x  A  (B  C), thus (A B) (A C)  A (B  C) • Since both A (B  C)  (A B) (A C) and (A B) (A C)  A (B  C), A (B  C) = (A B) (A C) QED

  48. Proof example • Prove that, for any set A, A  =  • Hint: Use a proof by contradiction

  49. Upcoming

  50. Next time… • More on set theory • Russell’s paradox

More Related