H14-F12-CS40 page 1 section first name last name First name A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (M2,M5,M7 or T4) initial initial (color-in initial)

Last name A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (color-in initial)

H14: Due Mon 11.05 in Lecture. Total Points: 50

MAY ONLY BE TURNED IN DURING Lecture ON Mon 11.05, or offered in person, for in person grading, during instructor or TAs office hours.

See the course syllabus at https://foo.cs.ucsb.edu/40wiki/index.php/F12:Syllabus for more details.

(1) (10 pts) Fill in the information below. Also, fill in the A-Z header by

coloring in the first letter of your first and last name (as it would appears in Gauchospace), writing either M2, M5, M7 or T4 to indicate your discussion section meeting time, i.e., Monday at 2pm, Monday at 4pm, or Tuesday at 5pm. writing your first and last initial in large capital letters (e.g. P C).

All of this helps us to manage the avalanche of paper that results from the daily homework.

name:

umail address: @umail.ucsb.edu

Your reading assignment for H14/H15 includes

The handout given out with this assignment (which can be found on the wiki under the link for Homework H11---it is part of the printable PDF) Skimming selected portions of Sections 2.4 in the textbook, as guided by that handout. Section 4.4 in the textbook.

We may come back, as time permits, and look more deeply into some parts of this material we may have skimmed over on our first pass.

(2) We learn in Section 2.4 that the set ℕ×ℕ is countable (more specifically, countably infinite)

(a) (3 pts) Briefly, what does it mean for a set to be countably infinite?

(b) (3 pts) ℕ×ℕ can be shown to be countable using "Cantor's pairing function". What is the value of Cantor's pairing function for (2,1)?

(c) (3 pts) Which element of ℕ×ℕ is paired with the number 7? F12-H11-page 2

(3) Find problem 2(a) on page 274, then look at the answer in the back of the textbook. Also, review the notes from class where that proof was done on the board.

Then, consider an inductive proof for 2d.

2 + 6 + 10 + ... + (4n - 2) = 2n2.

On this assignment, less help than you had for H13, but still some help.

(a) (3 pts) Define f(n) as the sum.

That is, write down: Let f(n) = 2 + 6 + 10 + ... + (4n - 2)

(Go ahead, write it, for practice—so that you learn that this is a step in proof by induction for sums like this one.)

Then, fill in the empty spaces in the following table. A few have been done as examples, so you know what I'm looking for. (Note: this step is NOT a necessary step in the formal proof; it is just an exercise to help you understand what is going on in these inductive proofs.) f(0) = 0 f(0) = 0 (0 terms) f(1) = (4*1 - 2) = 2 f(1) = 2 (1 term) f(2) = f(2) = (2 terms) f(2) = f(2) = (3 terms) ... f(5) = 2 + 6 + 10 + 14 + (4*5 - 2) = 2 + 6 + 10 + 14 + 18 f(5) = 50 (5 terms) ...

(b) (5 pts) Define P(n) as an appropriate proposition, using the appropriate notation.

(a) (5 pts) Write down the proof for the base case, P(0).

(b) (8 pts) In the next step, you prove a statement of the form "if p then q".

p is your inductive hypothesis, something that you assume is true. q is the thing you prove, given the assumption that p is true.

Please identify both p and q:

p: q:

(c) (10 pts) Now, finish the proof—given your formulation of p and q, show that if p then q, which together with the base case, shows that P(n) is true for all n∈ℤ,n≥0. CS40-F12-H14 Handout Page 1 Handout to go with H14/H15 Reading Assignment: Skimming through 2.4

Our main goal for this section of the course is to really learn proof by induction well. To create the time to go DEEP on proof by induction, we have to skim over a lot of other topics. Those topics we need to skim over are covered on 118 pages of the text (pages 121 to 238) in sections 2.4, 3.1, 3.2, 3.3, 4.1, 4.2, and 4.3

Because it isn't reasonable to expect you to do a deep reading of all of that in the time given, I'm going to first guide you through material, focusing JUST the portions of that material that are necessary for an understanding of proof by induction. I'll mention the other parts and we'll come back to them if time permits.

Your reading assignment for H14 includes

This handout Skimming selected portions of Sections 2.4 as guided by this handout. Notes on: Section 2.4: Countability, 2.4.1, Sizes of Sets

Why should I care about countability?

Two fundamental questions in Computer Science with real world implications:

Can such-and-such a problem be solved (i.e. can we write a computer program to solve this problem) If we can solve that problem, can we write it in a way that will scale (i.e. so that as the input gets large, the program will run in less time than a year, a human lifetime, or the age of the universe).

One of the most interesting aspects of Computer Science (one that you may investigate further in upper division courses such as CS130A, CS130B and/or CS138) is that there ARE problems:

that "can't be solved" by any computer program that always terminates with a correct answer (technically, these are "uncomputable" or "undecidable" problems) for which there is no "known" algorithm that runs in a reasonable amount of time for large size inputs. (these are the NP-hard and/or NP-complete problems.)

Even if you don't go on to take further upper-division CS courses, you may run into descriptions of problems in Math, Computer Engineering and Computer Science, that are "undecidable", "NP-hard", or "NP-complete", and it is helpful to have some insight into what those things mean.

It turns out that all of the following are important tools to establishing whether problems belong to the "undecidable", "NP-hard", or "NP- complete" class problems:

1-to-1 functions, onto functions and the relative sizes of sets, i.e, for two sets A and B, which one is the case: Is A bigger than B Is B bigger than A Are A and B exactly the same size Or is it not possible to even say? whether a specfic set is finite, countably infinite, or uncountably infinite (we'll discuss what each of those terms mean.) CS40-F12-H14 Handout page 2

An injection (1-to-1 function) f: A→B means |A| ≤ |B|

You've probably already figured out that a function can't be 1-to-1 from A to B if there are fewer elements in B than A. Think of it this way: a 1-to-1 function means that every element of A gets a different dance partner in set B—none of the elements of A have to share the same dance partner. That only works if there are enough elements in B to "go around". If there are 5 element in A, and only 4 in B, then at least two elements of A have to dance with the same element of B, and that means the function is no longer 1-to-1. (That's essentially an 'informal sketch' of how you prove this, using the "pigeonhole principle".

A surjection (onto function) f: A→B means |A| ≥ |B|

You've probably already figured out that a function can't be onto from A to B if there are fewer elements in A. Think of it this way: an onto function means that every element of B gets a dance partner. For the mapping to be a function, no-one in A is allowed to dance with more than one element of B (otherwise, it isn't a "function".) That means if there are 4 dancers in A, but 5 dancers in B, that at least one dancer in B has to sit out the dance. What it means for a function to be onto, is that every dancer in B gets to dance. means sets are the same size, |A| = |B|

If you can construct a function from set A to set B, f: A→B that is both 1-to-1 and onto, that function is called a bijection. It if is both 1-to-1 and onto, then |A| ≤ |B| and |B| ≥ |A| And the only way those can both be true is if |A| = |B|. That is, it is only possible to construct a bijection between two sets A and B if and only if the sets A and B have the same number of elements (i.e. the same ). Mathematicians like to make up new words for things, so they made the word "equipotent" to mean "the sets are the same size."

Countably infinfite: bijection with ℕ

A set is "countable" if it is finite (because clearly you can count anything that is finite).

There is one other kind of . If there is a bijection between a set A and the set ℕ={0,1,2,...} then the set is "countably infinite". Informally, that means that there is a way to associate every element of that set with some unique .

So:

X is countable ⇔ ( (x is finite) ∨ (x is countably infinite) )

This leads to some puzzling statements. For example:

Let O = {the set of all non-negative odd numbers} Let E = {the set of all non-negative even numbers}

Clearly, O∩E = ∅ and O∪E=ℕ.

That might lead you to think that O is "one-half" of all the natural numbers, and E is "one-half" of all the natural numbers, and thus:

|O| < |ℕ| (wrong!) |E| < |ℕ| (wrong!)

But, in fact, |O| = |E| = |ℕ| which is weird, but is considered by mathematicians to be a true statement! This is a consequence of the fact that we can construct a bijection between O and ℕ, between O and E, or between E and ℕ.

This leads us to question—what does it mean to say that "mathematicians consider this to be a true statement". It is important to recognize that we define what true means for any given mathematical notation. If we define A and B to have equal cardinality when both sets can be placed in a bijection to the same set (e.g. ℕ), then that is what cardinality means.

And it is true that the cardinality (or "size") of the set of non-negative even numbers, non-negative odd numbers, and the set of all non- negative numbers are all equal, even if that seems to "not make sense". It turns out that it make sense—ultimately—because that is a useful way to define those terms. By useful, what we mean here is that, ultimately, this way of defining these terms will allow us to prove things that apply to the real world of Computer Science. CS40-F12-H14 Handout page 3 Notes on 2.4.2: Sets that are Countable

Here are the most important results from this section:

Four properties of Countable sets

These are listed in the box marked 2.9 on p. 123, and there are proofs of (a) and (b) on that page. Try to understand what each of these means. Also, go through the proofs of (a) and (b), and try to imagine how you would go about proving (c) and (d). These are important lines of reasoning that may come up again in CISC138.

a. Every subset of ℕ is countable. b. S is countable if and only if | S| ≤ | ℕ | . c. Any subset of a countable set is countable. d. Any image of a countable set is countable.

ℕ×ℕ is countable

The way this is done is with a trick called "Cantor's pairing function". You should read about this on p. 124 so that if it comes up again in a later course, or later in the textbook, you'll know what they are talking about. One of the homework problems on H14 will check your understanding of this mapping.

ℚ is countable

The set ℚ is not one that we've talked much about, but its an important set—its the set of all rational numbers. That is, the subset of the real numbers that are formed by dividing one (the numerator) by another integer (the denominator).

The proof that the rationals are countable is built up a little bit at a time, and it is worth reading Section 2.4.2 from page 121 to 125 slowly and carefully to appreciate how this is done. Here's a sketch of the steps.

(1) First, the book establishes the principle (item d in the list above) that "any image of a countable set is countable". Another way of saying that is: if you have a function that maps a countable set A onto another set B, then B must be countable. (Do you see why? Stop and convince yourself of this before going on. If you don't understand this point, come to office hours and ask, or ask in lecture or discussion.)

(2) Next, the book establishes that any union of a set of countable sets (even one that is itself countably infinite) is, itself, countable. The proof here contains a bit of an unexpected twist—anything that is finite, is infinitely repeated. You might expect that would make things worse (i.e. harder to count!), but in fact, in a strange way, it does just the opposite. Read through that proof to see an example of some really cool "sleight of hand" in a proof! (More on that in a moment.)

(3) The book uses (1) and (2) above to prove that the Rationals, i.e. ℚ are countable. CS40-F12-H14 Handout page 4

The slight of hand in showing Union of countable sets is countable

Look again at the proof on p. 124 that the union of countable sets is countable (i.. result 2.11).

The final step of this proof uses the previous result that "any image of a countable set is countable", though it is sort of "disguised"—the book says that ℕ×ℕ is an "onto mapping" to the union of the countable sets. That is, every (m,n) is mapped to one and only one thing in the union, and there is nothing in the union that doesn't get mapped to.

Sometimes more than one (m,n) may map to the same thing in the union (because there are repeated elements)—and that's why the mapping from the union to ℕ×ℕ is NOT an injection.

Here's an illustration of that. There are two figures, one for each "strange case" When finite sets occur in the union

(Compare with Proof of 2.11 on p. 124) CS40-F12-H14 Handout page 5 When there is a finite number of countable sets being unioned together

(Compare with Proof of 2.11 on p. 124)