Problem Set 3


Due Friday, February 2 at 4:00 pm Pacific


Solutions are available!

🔑 Solutions


This third problem set explores functions and writing proofs on first-order logic definitions. We've chosen these problems to help you learn how to reason about injections, surjections, bijections, and the like; how to write proofs using formal mathematical definitions; and why all this matters in practice. Before beginning this problem set, we strongly recommend doing the following:

  • Read the Guide to Proofs on Discrete Structures, which explores how to write proofs when definitions are rigorously specified in first-order logic. This handout contains both general guiding principles to follow and some sample proof templates that you’re welcome to use here.
  • Read the Discrete Structures Proofwriting Checklist, which contains some specific items to look for when proofreading your work. We will be applying the items on this checklist when grading your work, so it’s worthwhile to apply this checklist to your work before submitting.

We also recommend that you take a look at the proofs from this week’s lectures to get a sense of what this looks like and how to approach these problems. In particular, the two-column proof organizer and the table of how to assume/prove things will be extremely helpful here.

Good luck, and have fun!

Starter Files

Here are the starter files for the problems you'll submit electronically:

📦 PS3 Starter Files

Unpack the files somewhere convenient and open up the bundled project.

If you would like to type your solutions in $\LaTeX$, you may want to download this template file where you can place your answers:

đź–‹ PS3 $\LaTeX$ Template

Problem One: Properties of Functions

Below is a list of purported functions. For each of those purported functions, determine where in the following Venn diagram that object goes.

A Venn diagram. There is a bubble marked Functions separating the outside from the inside. Inside of Functions are two partially-overlapping circles. One is labeled Injections. One is labeled Surjections. The intersection is labeled Bijections. Inside the bubble labeled "functions" and outside the other bubbles is the number 1. Outside all of the bubbles is the number 2.

To get you started, we’ve shown you where functions 1 and 2 go.

To submit your answers, run the starter files for PS3 and choose the “Properties of Functions” option. This program will write your answers to res/PropertiesOfFunctions.answers. You can use the provided test cases to check your work, and when you’re ready you can submit this file to Gradescope. Do not manually edit this file; use the program instead.

As a reminder, in this class we consider $0$ to be a natural number.

  1. $f : \mathbb{N} \to \mathbb{N}$ defined as $f(n) = 137$.
  2. $f : \mathbb{N} \to \mathbb{N}$ defined as $f(n) = -137$.

    Make sure you can explain why these first two items go where they do in this diagram!

  3. $f : \mathbb{N} \to \mathbb{N}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.

    The notation $\abs{n}$ means “the absolute value of n.” For example, $\abs{\pi} = \abs{-\pi} = \pi$.

  4. $f : \mathbb{Z} \to \mathbb{N}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
  5. $f : \mathbb{Z} \to \mathbb{Z}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
  6. $f : \mathbb{R} \to \mathbb{N}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
  7. $f : \mathbb{N} \to \mathbb{R}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
  8. $f : \mathbb{R} \to \mathbb{R}$ defined as $f(n) = \sqrt{n}$.

    The notation $\sqrt{n}$ denotes the principal square root of $n$, the nonnegative one.

  9. $f : \mathbb{R} \to \Set{ x \in \mathbb{R}\ \vert\ x \ge 0 }$ defined as $f(n) = \sqrt{n}$.
  10. $f : \Set{ x \in \mathbb{R} \ \vert\ x \ge 0 } \to \Set{ x \in \mathbb{R}\ \vert\ x \ge 0 }$ defined as $f(n) = \sqrt{n}$.
  11. $f : \Set{ x \in \mathbb{R} \ \vert\ x \ge 0 } \to \mathbb{R}$ defined as $f(n) = \sqrt{n}$.
  12. $f : \mathbb{N} \to \mathbb{N}$ defined as follows:

    \[f(n) = \left\lbrace \begin{aligned} &n^2 + 2 &\text{if } n \lt 137 \\ &n^2 - 2 &\text{if } n \gt 137 \end{aligned} \right.\]
  13. $f : \mathbb{N} \to \mathbb{N}$ defined as follows:

    \[f(n) = \left\lbrace \begin{aligned} &2 - n &\text{if } n \le 2 \\ &n - 2 &\text{if } n \ge 2 \end{aligned} \right.\]
  14. $f : \mathbb{N} \to \mathbb{N}$ defined as follows:

    \[f(n) = \begin{cases} n-1 & \text{if } n \text{ is even} \\ n+1 & \text{if } n \text{ is odd} \\ \end{cases}\]
  15. $f : \mathbb{N} \to \mathbb{N}$ defined as follows:

    \[f(n) = \begin{cases} n+1 & \text{if } n \text{ is even} \\ n-1 & \text{if } n \text{ is odd} \\ \end{cases}\]

Problem Two: $\abs{\naturals} = \abs{\integers}$

Although intuitively it might seem like there are more integers than natural numbers, surprisingly, the two sets have the same cardinality.

Consider the function $f : \naturals \to \integers$ defined as follows:

\[f(n) = \begin{cases} k & \text{if } \exists k \in \naturals. n = 2k \\ -(k+1) & \text{if } \exists k \in \naturals. n = 2k+1 \end{cases}\]
  1. Fill in the blanks below. No justification is necessary.

    • $f(0) = $ $\blank$.
    • $f(1) = $ $\blank$.
    • $f(2) = $ $\blank$.
    • $f(3) = $ $\blank$.
    • $f(4) = $ $\blank$.
    • $f(5) = $ $\blank$.
  1. Prove that $f$ is a bijection.

    This one is all about calling back to definitions. To prove $f$ is a bijection, you need to prove it's injective and surjective. What do you need to prove to show that $f$ is injective? What do you need to prove to show that $f$ is surjective?

Formally speaking, two sets have the same cardinality when there's a bijection between them. Your result from part (ii) therefore shows that $\abs{\naturals} = \abs{\integers}\text.$

One way of interpreting the result you've just proved here is that $\aleph_0 = 2\aleph_0$, since you can think of $\integers$ as having twice as many elements as $\naturals\text.$ Isn't infinity weird?

Problem Three: Strictly Increasing Functions

A function $f : \mathbb{Z} \to \mathbb{Z}$ is called strictly increasing if the following statement is true about $f\text:$

\[\forall x \in \mathbb{Z}. \forall y \in \mathbb{Z}. (x \lt y \ \to \ f(x) \lt f(y)).\]

Strictly increasing functions have a bunch of nice properties.

  1. Is the function $f : \mathbb{Z} \to \mathbb{Z}$ defined as $f(x) = x^2$ strictly increasing? How about if we defined it as $f(x) = x^3$? No justification is necessary.

  1. Let $f : \mathbb{Z} \to \mathbb{Z}$ and $g : \mathbb{Z} \to \mathbb{Z}$ be arbitrary strictly increasing functions. Prove that $g \circ f$ is strictly increasing.

    This is a proof of the form “any object with property $X$ also has property $Y\text{.”}$ Look back at the lecture examples involving involutions for some guidance about how to proceed here.

    Make sure to distinguish what you're assuming from what you're proving. Introduce variables when you're asked to prove a universally-quantified statement, and don't introduce them when you're assuming a universally-quantified statement.

  1. Let $f : \mathbb{Z} \to \mathbb{Z}$ be an arbitrary strictly increasing function. Prove that $f$ is injective.

    If you have two integers $x$ and $y$ where $x \ne y$, then you know either that $x \lt y$ or that $y \lt x$. If $x$ and $y$ are otherwise arbitrarily chosen, you can avoid doing a proof by cases by using this magic phrase:

    "Assume, without loss of generality, that $x \lt y$."

    This phrase tells the reader "dear reader, who I am sure is well-dressed, very refined, and very classy, there really isn't a difference in the logic between the cases where $x \lt y$ and $y \lt x$. Therefore, to avoid boring you, I'm going to just prove one of those two cases. And since you are so Smart and Wise and Funny, you surely are smart enough to see what the other case would be, because it's literally the same except that we swap the roles of $x$ and $y\text{."}$ It's a great way to cut down on the amount you have to write without losing anything.

    You can use this phrase in other contexts where there are two symmetric choices. Just make sure that those cases really truly are identical except for which variable plays which part!

Problem Four: Left and Right Inverses

Let $f : A \to B$ be a function. A function $g : B → A$ is called a left inverse of $f$ if the following is true:

\[\forall a \in A. g(f(a)) = a.\]
  1. Find examples of a function $f$ and two different functions $g$ and $h$ such that both $g$ and $h$ are left inverses of $f$. This shows that left inverses don't have to be unique. (Two functions $g$ and $h$ are different if there is some $x$ where $g(x) \neq h(x)$.) Express your answer by drawing pictures of $f$, $g$, and $h$ along the lines of what we did in class.

  1. Prove that if $f$ is a function that has a left inverse, then $f$ is injective.

    As a hint on this problem, look back at the proofs we did with injections in lecture. To prove that a function is an injection, what should you assume about that function, and what will you end up proving about it?

Let $f : A \to B$ be a function. A function $g : B \to A$ is called a right inverse of $f$ if the following is true:

\[\forall b \in B. f(g(b)) = b.\]
  1. Find examples of a function $f$ and two different functions $g$ and $h$ such that both $g$ and $h$ are right inverses of $f$. This shows that right inverses don't have to be unique. As in part (i), express your answer by drawing pictures of $f$, $g$, and $h$ along the lines of what we did in lecture.

  1. Prove that if $f$ is a function that has a right inverse, then $f$ is surjective.

Problem Five: True Inverses

If $f : A \to B$ is a function, then a true inverse (often just called an inverse) of $f$ is a function $g$ that's simultaneously a left and right inverse of $f$. In Problem Five you saw that functions can have several different left inverses or right inverses. However, a function can only have a single true inverse.

Prove that if $f : A \to B$ is a function and both $g_1 : B \to A$ and $g_2 : B \to A$ are inverses of $f$, then $g_1(b) = g_2(b)$ for all $b \in B$.

You should be able to explain why your proof doesn't work if $g_1$ and $g_2$ are just left inverses of $f$, not full inverses. That is, you should point at a specific claim in your proof that is no longer true if you relax this assumption. If you can't find such a claim, that is a strong suggestion that you have an error in your proof somewhere.

Similarly, you should be able to explain why your proof doesn't work if $g_1$ and $g_2$ are just right inverses of $f$, not full inverses.

Problem Six: Minkowski Sums

Let's begin with a new definition. Suppose we have two sets $A, B \in \powerset{\naturals}\text.$ The Minkowksi sum of $A$ and $B\text,$ denoted $A + B\text,$ is defined as follows:

\[A + B = \Set{ x \suchthat \exists m \in A. \exists n \in B. x = m + n }\text.\]
  1. To get a better feel for that definition, let's explore some simple cases. Answer each of the following questions. If you answer "yes", give a choice of $m \in A$ and $n \in B$ that meet the requirements defined above. If you answer "no", no justification is necessary.

    • Let $A = \Set{1, 2, 3}$ and $B = \emptyset$ and consider the set $A + B$. Is $1 \in A + B$?
    • Now, let $A = \Set{1, 2, 3}$ and $B = \Set{0}$. Is $1 \in A + B$?
    • Finally, let $A = \Set{1, 2, 3}$ and $B = \Set{1}$. Is $1 \in A + B$?
  1. Fill in each of the following blanks without using set-builder notation. No justification is necessary.

    • $\Set{1, 2, 3} + \Set{10, 20} = \blank\text.$
    • $\emptyset + \Set{1, 2, 3} = \blank\text.$
    • $\naturals + \naturals = \blank\text.$

Here's an interesting fact about Minkowski sums that, surprisingly, was a key part of a landmark paper on string data structures from 2003. Specifically, the paper used the theorem below to ensure that all possible cases for how two sets would interact with another were covered.

  1. Let $S = \Set{ n \suchthat n \in \naturals \land n \not\equiv_3 2 }\text.$ Prove that $S + S = \naturals\text.$

    The hardest part of this problem is getting the setup correct and figuring out what you need to show in the proof. You aren't expected to see this immediately. Instead, work slowly and deliberately to unpack the definitions and see what they tell you to do. We recommend using the two-column strategy shown in lecture where you write out one column for “what I’m assuming” and one for “what I need to show.”.

    This is a proof on sets, so proceed accordingly. What are the steps required to prove that two sets are equal to one another? How do you prove one set is a subset of another? What does it mean to assume $x \in \Set{ y \suchthat P(y) }$?

    Feel free to use the following fact: for every integer $x\text,$ exactly one of the following is true: $x \equiv_3 0\text,$ $x \equiv_3 1\text,$ or $x \equiv_3 2\text.$

How does the Minkowski sum iteract with the standard set operations you've grown to know and love? Let's look at two examples.

  1. Prove or disprove: for all sets $A, B, C \in \powerset{\naturals}\text,$ we have $A + (B \cup C) = (A + B) \cup (A + C)\text.$

    This is a prove-or-disprove problem, so your first task is to figure out whether this statement is true or false. To do that, we recommend doing the following. First, write out the negation of the statement. You know that either the statement is true or the negation is true, and your task is to determine which one of those statements is true. Next, work through some examples and see what you find. If you find an example that disproves the claim, great! You're done - just write it up. If you can't find a counterexample, then maybe the statement is true. Use the two-column organization strategy to map out what you would need to assume and prove. Start working through the proof, and if you find any points where you get stuck or aren't sure what to do, try checking whether there might be a counterexample. After iterating this a few times, you'll either find a counterexample and you have your disproof, or you'll figure out how to get the proof working.

    You already know how to write up a proof. If you want to write a disproof, use the following template:

    Disproof: We will prove the negation of the claim, namely, [insert negation here]. [proof of negation]. $\qed$

  1. Prove or disprove: for all sets $A, B, C \in \powerset{\naturals}\text,$ we have $A + (B \cap C) = (A + B) \cap (A + C)\text.$

Minkowksi sums have applications in computer graphics. Here, we're dealing with Minkowksi sums on sets of natural numbers, but they can be generalized to work with sets of vectors as well. There, they're used to define operations that expand and contract images given in a vector representation. Want to learn more about computer graphics and image processing? Take CS148!

Optional Fun Problem: Infinity Minus Two

Let $[0, 1]$ denote the set $\Set{ x \in \mathbb{R} \ \vert \ 0 \le x \le 1 }$ and $(0, 1)$ denote the set $\Set{ x \in \mathbb{R} \ \vert \ 0 \lt x \lt 1 }$. That is, the set $[0, 1]$ is the set of all real numbers between $0$ and $1$, inclusive, and the set $(0, 1)$ is the set of all real numbers between $0$ and $1$, exclusive. These sets differ only in that the set $[0, 1]$ includes $0$ and $1$ and the set $(0, 1)$ excludes $0$ and $1$.

Give a definition of bijection $f : [0, 1] \to (0, 1)$ via an explicit rule (i.e. writing out $f(x) = \blank$ or defining $f$ as a piecewise function), then prove that your function is a bijection. This proves that $\abs{[0, 1]} = \abs{(0, 1)}$.