Due Friday, April 26 at 3:00 pm Pacific
Solutions are available!
This third problem set explores functions and set theory. 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.
- Read the Guide to Proofs on Sets, which talks about how to write proofs involving sets (e.g. $\cap\text,$ $\subseteq\text,$ etc.)
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:
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:
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.

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.
- $f : \mathbb{N} \to \mathbb{N}$ defined as $f(n) = 137$.
-
$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!
-
$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$.
- $f : \mathbb{Z} \to \mathbb{N}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
- $f : \mathbb{Z} \to \mathbb{Z}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
- $f : \mathbb{R} \to \mathbb{N}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
- $f : \mathbb{N} \to \mathbb{R}$ defined as $f(n) = \frac{n + \abs{n}}{2}$.
-
$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.
- $f : \mathbb{R} \to \Set{ x \in \mathbb{R}\ \vert\ x \ge 0 }$ defined as $f(n) = \sqrt{n}$.
- $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}$.
- $f : \Set{ x \in \mathbb{R} \ \vert\ x \ge 0 } \to \mathbb{R}$ defined as $f(n) = \sqrt{n}$.
-
$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.\] -
$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.\] -
$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}\] -
$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: All You Need Is Love
Let $P$ be a set consisting of some number of entities (cats, robots, and people). Here are three possible properties the set $P$ might have:
\[\begin{aligned} \text{(I)} & \quad \forall x \in P. Loves(x, x). \\ \text{(II)} & \quad \forall x \in P. \forall y \in P. (Loves(x, y) \to Loves(y, x)). \\ \text{(III)} & \quad \forall x \in P. \forall y \in P. \forall z \in P. (Loves(x, y) \land Loves(y, z) \to Loves(x, z)). \end{aligned}\]Below is an incorrect proof that if $P$ has properties (II) and (III), then $P$ also has property (I):
Incorrect Proof: Assume $P$ has properties (II) and (III). We need to show that $P$ has property (I).
Pick any $x, y \in P$ such that $x$ loves $y\text.$ Since $x$ loves $y\text,$ by property (II) we know that $y$ loves $x\text.$ Then, since $x$ loves $y$ and $y$ loves $x\text,$ by property (III) we see that $x$ loves $x\text.$ And since $x$ loves $x\text,$ we see that $P$ has property (I), as required. $\qed$
The error in this proof turns out to be one of the most common mistakes we see on this problem set, so before we jump into formal proofwriting, let's take a minute to figure out what's the error is.
-
The proof (correctly) starts off by assuming property (II) is true. Based on the assume/prove table for first-order logic, what variables, if any, should the proof introduce as a result of this? If any variables are introduced, what assumptions, if any, should the proof make about them? If any variables are introduced, what should the proof aim to show about them?
-
The proof (correctly) starts off by assuming property (III) is true. Based on the assume/prove table for first-order logic, what variables, if any, should the proof introduce as a result of this? If any variables are introduced, what assumptions, if any, should the proof make about them? If any variables are introduced, what should the proof aim to show about them?
-
The proof (correctly) starts off by stating it will prove property (I) is true. Based on the assume/prove table for first-order logic, what variables, if any, should the proof introduce as a result of this? If any variables are introduced, what assumptions, if any, should the proof make about them? If any variables are introduced, what should the proof aim to show about them?
-
Based on your answers to parts (i), (ii), and (iii) of this problem, what is the error in this proof? Be as specific as possible. (If the proof contains multiple logical errors, we just care about the first one. After all, once it's made a logical error, everything after that point is irrelevant.)
Problem Three: $\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}\]-
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$.
-
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 Four: 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.
-
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.
-
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.
-
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 Five: Eventual Bijections
Suppose you have a function $f : A \to A$ from some set back to itself. This allows us to compose $f$ with itself multiple times. To make things a bit easier to talk about, let’s introduce some notation. For any natural number $n$, we’ll define $f^n : A \to A$ to be the function $f \circ f \circ \dots \circ f$, with $f$ appearing $n$ times in the expression. So, for example, $f^1$ is just the function $f$ itself, while $f^2$ is the function $f \circ f$ and $f^3$ is the function $f \circ f \circ f$. As a special case, we’ll say that $f^0$ is the function $f^0(x) = x$; this is chosen to make things behave more consistently.
-
Let $f : \integers \to \integers$ be the function $f(n) = 2n - 1$. Fill in the blanks below. No justification is required.
- $f^3(2) = \blank$
- $f^{137}(1) = \blank$
- $f^0(137) = \blank$
In many cases, if you know something about how a power of a function works, you can learn something about the function itself.
-
Let $f : A \to A$ be a function. Prove that if $f^3$ is surjective, then $f$ is surjective.
Make sure you’re proving the right thing. Here, you know something about $f^3$, and your goal is to infer something about $f$ itself. Make sure not to instead assume $f$ is surjective and prove $f^3$ is surjective; that follows from what we proved in lecture and is a different argument.
This is a great place to write out what it is that you're assuming and what it is you're proving. Much of the complexity of this problem stems from differentiating between the two.
-
Let $f : A \to A$ be a function. Prove that if $f^3$ is injective, then $f$ is injective.
Problem Six: Set Theory Warmup
Proofs on sets and set theory can take some time to get used to. These problems are designed to get you comfortable writing formal proofs on sets that engage with common set theory definitions (e.g. $\subseteq\text,$ $\cup\text,$ set-builder notation, etc.).
Read the Guide to Proofs on Sets before starting this problem.
-
Prove that if $A \subseteq C$ and $B \subseteq C\text,$ then $A \cup B \subseteq C\text.$
-
Let $A$ be a set. Prove by contradiction that $A \subseteq A\text.$
This result might seem obvious, but it's worth proving it rigorously to see how it follows from the definitions.
-
Let $A$ and $B$ be sets. Prove that $A \subseteq B$ if and only if $\powerset{A} \subseteq \powerset{B}\text.$
Note that this result is a biconditional rather than a regular implication.
Check the Guide to Proofs on Sets and the table in the set theory lecture slides for information about how to write proofs involving power sets.
Problem Seven: 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.\]To get a better feel for that definition, let's explore some simple cases.
-
Answer each of the following questions. No justification is required.
- Let $A = \set{1, 2, 3}$ and $B = \emptyset\text.$ Is $1 \in A + B\text?$
- Let $A = \set{1, 2, 3}$ and $B = \set{0}\text.$ Is $1 \in A + B\text?$
- Let $A = \set{1, 2, 3}$ and $B = \set{1}\text.$ Is $1 \in A + B\text?$
- Let $A = \set{1, 2, 3}\text.$ Is $1 \in A + A\text?$
-
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.
-
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 does it mean for two sets to be equal? How do you prove one set is a subset of another? What does it mean to assume $x \in \Set{ y \suchthat P(y) }\text?$ Proceed slowly and deliberatively here to make sure you set up the proof correctly and prove all the right things.
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.$
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!
Problem Eight: Putting It All Together
Let $f : \reals \to \powerset{\reals}$ be the function defined as follows:
\[f(x) = \set{y \suchthat y \in \reals \land y \le x}\text.\]Prove that $f$ is injective.
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)}$.