% Copyright (C) He Guanyuming 2020
% The file is licensed under the MIT license.

\section{Set Theory}

\subsection{Fundamentals}
\declareexercise{3.1.1}
\begin{proof}
Reflexive: $\forall x \in S, x \in S$.

Symmetric:
\begin{align*}
X = Y
&\Longleftrightarrow \\
\forall x \in X, x \in Y \wedge \forall x \in Y, x \in X
&\Longleftrightarrow \\
Y = X
\end{align*}

Transitive:
$X=Y \Longrightarrow \forall x \in X, x \in Y$. Because $x \in Y$ and $Y = Z$, we can conclude that
$\forall x \in X, x \in Z$. Conduct the process from inversely, we can get $\forall x \in Z, x \in X$.
Therefore, $X=Z$.
\end{proof}

The reason for the content beneath Axiom 3.2 is clearly demonstrated in the proof of Lemma 3.1.6.

In Remarks 3.1.9, there are three ``Why''s. The reason can be concluded as: Because of the ``if and only
if'' in Axiom 3.3, or more precisely, ``only if'', if $x$ is a element in one of such sets, $x$ must
$=a$ or $b$. And because of the ``if'', $x$ is thus in another set. So the two sets are equal according
to Definition 3.1.4.

\declareexercise{3.1.2}
\begin{proof}
According to Axiom 3.2, $\varnothing$ exists, and is thus an object as stated by Axiom 3.1. Therefore,
by Axiom 3.3, $\{\varnothing\}$ also exists. $\varnothing$ is an element of $\{\varnothing\}$, but it
is not an element of $\varnothing$ because any object $\notin$ $\varnothing$.

For the same reason, any set that contains element(s) is not the same set as $\varnothing$. Furthermore,
there exists an object $\{\varnothing\}$ (Axiom 3.3 and 3.1), which is an element of
$\{\varnothing, \{\varnothing\}\}$, but which is not an element of $\{\varnothing\}$. So the two sets
are not equal.
\end{proof}

\paragraph{Remarks 3.1.12}
\begin{proof}
Let $x \in A'\cup B$. $x \in A' \Longrightarrow x \in A$ And if $x \notin A'$, $x \in B$. So either way
$x \in A\cup B$ and vice versa.
\end{proof}

\declareexercise{3.1.3}
\begin{proof}
(1)
\[
x \in A \cup B \equiv (x \in A \vee x \in B)
\]
\[
x \in A \Longrightarrow x \in B \cup A
\]
\[
x \in B \Longrightarrow x \in B \cup A
\]
So $x \in A \cup B \Longrightarrow x \in B \cup A$. And vice versa.

(2)
$x \in A \Rightarrow x \in A \cup A$ and $x \in A \cup A \Rightarrow x \in A$.

(3)
\begin{align*}
x \in A \cup \varnothing
&\Longrightarrow \\
x \in A \vee x \in \varnothing
&\Longrightarrow \\
x \in A \tag{$\forall a, a \notin \varnothing$}
\end{align*}

And obviously $x \in A \Rightarrow x \in A \cup \varnothing$. So $A \cup \varnothing = A$.

By transitivity of equality, and commutativity of pairwise union, we can conclude the others.
\end{proof}

\paragraph{Examples 3.1.17}
\begin{proof}
\[
\forall x(x\in A \Longrightarrow x \in A)
\]

And
\[
\forall x(x \in \varnothing \Longrightarrow x \in A)
\]
is vacuously true.
\end{proof}

\declareexercise{3.1.4}
\begin{proof}
(1)
On one hand,
\[
A \subseteq B \equiv \forall x(x \in A \Longrightarrow x \in B)
\].
On the other hand,
\[
B \subseteq A \equiv \forall x(x \in B \Longrightarrow x \in A)
\].
Thus $A=B$.

(2)
First, we prove that $A \subsetneq B \Longrightarrow \exists x(x \in B \wedge x \notin A)$. Suppose the
contradiction, that is, $\forall x(x\in B \Longrightarrow x \in A)$, which is impossible since
$(A \subseteq B \equiv \forall x(x\in A \Longrightarrow x \in B))\wedge A \neq B$.

According to what's proven in the book,
$A \subsetneq B \wedge B \subsetneq C \Longrightarrow A \subseteq C$.

Now we prove that $\exists x(x \in C \wedge x \notin A)$. Since $x \in A \Longrightarrow x \in B$,
$x \notin B \Longrightarrow x \notin A$. Because $B \subsetneq C$,
$\exists x(x \in C \wedge x \notin B)$, and thus for such $x$, $ x \notin A$. Then $A \neq C$.

So $A \subsetneq C$.
\end{proof}

\paragraph{Axiom 3.5}
(1) Because $x \in \{x \in A : P(x)\} \Rightarrow x \in A$.

(2) Because both $\in$ and $P(x)$ obey the axiom of substitution.

\declareexercise{3.1.5}
\begin{proof}
First we prove that $A \subseteq B \equiv A \cup B = B$. On one hand,
\begin{align*}
A \subseteq B
&\equiv \\
\forall x(x \in A \Longrightarrow x \in B)
&\Longrightarrow \\
\forall x((x \in A \vee x \in B) \Longrightarrow x \in B)
&\equiv \\
A \cup B = B
\end{align*}.

On the other hand,
\[
\forall x((x \in A \vee x \in B) \Longrightarrow x \in B) \Longrightarrow
\forall x(x \in A \Longrightarrow x \in B)
\]. The statement is therefore proven.

Then we prove that $A \subseteq B \equiv A \cap B = A$. On one hand,
\begin{align*}
(A \cap B = A \equiv \forall x(x \in A \wedge x \in B \equiv x \in A))
&\Longrightarrow \\
(\forall x(x \in A \Rightarrow x \in B) \equiv (A \subseteq B))
\end{align*}.

On the other hand,
\[
\forall x(x\in A\wedge x \in B \Longrightarrow x \in A)
\]
is always true (Vacuously true if $x \notin B$).

Logical equality is transitive, and thus all of the three statements are equal.
\end{proof}

\paragraph{Proposition 3.1.28} (Exercise 3.1.6) \label{exercise3.1.6}
\begin{proof}
(a) The two are identical to
\[
\forall x(x \in A \vee x \in \varnothing \equiv x \in A)
\],
and
\[
\nexists x(x \in A \wedge x \in \varnothing)
\],
which are all true since $\forall x(x \notin \varnothing)$.

(b) We have $A \subseteq X$. According to what we have proven in
\hyperref[exercise3.1.5]{Exercise 3.1.5}, the two statements are all true.

(c) Obvious since
\[
\forall x(x \in A \vee x \in A \equiv x \in A)
\]
and
\[
\forall x(x \in A \wedge x \in A \equiv x \in A)
\]

(d) All true since \emph{logical or} and \emph{logical and} are commutative.

(e) See Lemma 3.1.13. I believe that this can be concluded by the fact that \emph{logical or} and
\emph{logical and} are also associative.

(f)
First we prove the latter. On one hand, suppose
\[
x \in A \cup (B \cap C)
\] is ture.

If $x \in A$, then $x \in$ both $A \cup B$ and $A \cup C$, and thus $\in$
$(A \cup B)\cap(A \cup C)$.

If $x \notin A$, then $x \in B \cap C$, then $x \in$ both $A \cup B$ and $A \cup C$, and thus $\in$
$(A \cup B)\cap(A \cup C)$.

On the other hand,
suppose
\[
x \in (A \cup B)\cap(A \cup C)
\] is true.

If $x \in A$, obviously $x \in A \cup (B \cap C)$.

If $x \notin A$, then $x$ must $\in B \cap C$, and thus also $\in A \cup (B \cap C)$.

Now we prove the former. On one hand, suppose
\[
x \in A \cap (B \cup C)
\] is true.

If $x \in A \wedge x \in B$, then $x \in A \cap B$, and thus $\in (A \cap B)\cup(A \cap C)$.

If $x \notin A \vee x \notin B$, then
\begin{enumerate}
\item if $x \notin A$, this is impossible.
\item if $x \in A$, then $x \notin B$. But $x \in B \cup C$, so $x \in C$. And thus
$x \in A \cap C \Rightarrow x \in (A \cap B)\cup(A \cap C)$.
\end{enumerate}

On the other hand, suppose that
\[
x \in (A \cap B)\cup(A \cap C)
\] is true.

First we can see that $x \in A$.

If $x \in B$, then $x \in B \cup C$, and thus $\in A \cap (B \cup C)$.

If $x \notin B$, then $x \in C$. So $x \in B \cup C$, and thus $\in A \cap (B \cup C)$.

(g)
Now we prove the former: On one hand, suppose that
\[
x \in A \cup (X-A)
\].

If $x \in A$, then $x \in X$ since $A \subseteq X$.

If $x \notin A$, then $x \in X-A$, and thus also $\in X$.

On the other hand, suppose that
\[
x \in X
\]

If $x \in A$, then $x \in A \cup (X-A)$.

If $x \notin A$, then $x \in X-A$, and thus $\in A \cup (X-A)$.

(h)
$x \in X - A$ requires $x \notin A$. So $\forall x(x \in A \cap (X-A))$ is always false.
Thus
\[
\forall x(x \in A \cap (X-A) \Longleftrightarrow x \in \varnothing)
\] (vacuously true).
\end{proof}

\declareexercise{3.1.7}
\begin{proof}
(1)
$\forall x(x \in A \cap B \Longrightarrow x \in A)$. Similarly, we can prove that
$A \cap B \subseteq B$. (This can also be achieved via the commutativity).

(2)
On one hand, suppose that
\[
C \subseteq A \wedge C \subseteq B
\] is true.
Then,
\[
\forall x(x \in C \Longrightarrow x \in A \wedge x \in B \Longrightarrow x \in A \cap B)
\].

On the other hand, suppose that
\[
C \subseteq A \cap B
\] is true.
Then,
\[
\forall x(x \in C \Longrightarrow x \in A \wedge x \in B)
\].
That is, $C \subseteq A \wedge C \subseteq B$.

(3) It is immediately given by
\[
\forall x(x \in A \Longrightarrow x \in A \cup B)
\].
Since $\cup$ is commutative, the latter case is proven.

(4) On one hand, suppose that $A \subseteq C \wedge B \subseteq C$ and let $x \in A \cup B$.

If $x \in A$, then $x \in C$.

If $x \notin A$, then $x \in B$, and thus $x \in C$.

On the other hand, suppose that $A \cup B \subseteq C$. Then,
\[
\forall x(x \in A \Longrightarrow x \in A \cup B \Longrightarrow x \in C)
\]
\[
\forall x(x \in B \Longrightarrow x \in A \cup B \Longrightarrow x \in C) \qedhere
\].
\end{proof}

\declareexercise{3.1.8}
\begin{proof}
The former: On one hand,
Suppose that
\[
x \in A \cap (A \cup B)
\].

If $x \in A$, then $x \in A$.

If $x \notin A$, this is impossible.

On the other hand, suppose that $x \in A$.
Then $x \in A \wedge x \in (A \cup B)$, so $x \in A \cap (A \cup B)$.

The latter: On one hand, suppose that $x \in A \cup (A \cap B)$.
\[
x \in A \Longrightarrow x \in A.
\]
\[
x \notin A \Longrightarrow x \in (A \cap B) \Longrightarrow x \in A
\].

On the other hand, Suppose that $x \in A$, then $x \in A \cup (A \cap B)$.
\end{proof}

\declareexercise{3.1.9}
\begin{proof}
\begin{lem} \label{lem10}
\[
\nexists x\forall B\forall A(x \in A \wedge x \in B \wedge A \cap B = \varnothing)
\]
\end{lem}
\begin{proof}
Suppose the negation: $x \in A \wedge x \in B \wedge A \cap B = \varnothing$, then
$x \in A \cap B$, and thus $\in \varnothing$, which is impossible.
\end{proof}

The former: On one hand, suppose that $x \in A$. Then $x \notin B$ by Lemma \ref{lem10}. And
\[
x \in A \Longrightarrow x \in A \cup B \Longrightarrow x \in X
\].
So $x \in (X-B)$.

On the other hand, suppose that $x \in (X-B)$, then $x \in A \cup B$. But $x \notin B$, so $x \in A$ by
Lemma \ref{lem10}.

The latter is immediately proven since $\cap,\cup$ are commutative.
\end{proof}

\paragraph{Exercise 3.1.10} \label{exercise3.1.10}
\begin{proof}
Firstly we prove that $(A-B)\cap (A\cap B) = \varnothing$.

$x \in (A\cap B)$ gives $x \in B$, but $x \in (A-B)$ gives $x \notin B$. So the two statements can not
be true simultaneously. Which means
\[
x\in (A-B)\cap (A\cap B) \Longrightarrow x \in \varnothing
\]

And obviously
\[
x\in (A-B)\cap (A\cap B) \Longleftarrow x \in \varnothing
\].

Similarly we can conclude all of the three sets are disjoint by the fact that $\nexists x \in$ either
two of the three sets.

Now we are showing that their union is $A \cup B$.

On one hand, suppose that
\[
x \in (A-B)\cap(A\cap B)\cap(B-A)
\].
$x$ can at most be in one of these sets since they are disjoint.
If $x \in A$, then $x \in A \cup B$.

If $x \notin A$, then $x \in (B-A)$, and thus $x \in B$. So $x \in A \cup B$.

On the other hand, suppose that $x \in A \cup B$.
Then $x$ either
\begin{enumerate}
\item $\in A$, but $\notin B$, or
\item $\in B$, but $\notin A$, or
\item $\in$ both $A,B$.
\end{enumerate}

If (1), then $x \in (A-B)$.

If (2), then $x \in (B-A)$.

If (3), then $x \in A\cap B$.

In conclusion, we can see that $x \in (A-B)\cap(A\cap B)\cap(B-A)$.
\end{proof}

\paragraph{Exercise 3.1.11} \label{exercise3.1.11}
\begin{proof}
Let $S$ be a set.
Let $P(x,y)$ be a property pertaining to $x \in S$ and any object $y$, and is true iff
$Q(x) \wedge y = x$, where $Q(x)$ is a property pertaining to $x \in S$.

According to Axiom 3.6, there exists a set $Z$, such that
$y \in Z \equiv x \in S \wedge P(x,y)$, which means $y \in Z \equiv x \in S \wedge Q(x) \wedge x = y$.
So is the axiom of specification proven.
\end{proof}

\subsection{Russell's paradox}
I think one major reason for building such a ``cumbersome'' axiom system is to restrict the way to
construct sets. We can not construct just any set we want, there only exist certain kinds of sets.

\declareexercise{3.2.1}
\begin{proof}
(Axiom 3.2) To prove the existence of the empty set, simply choose a property that is false for all
objects.

(Axiom 3.3) To prove the existence of a \emph{pair set}, say $\{a,b\}$, let $P(x)$ be a property
pertaining to any object $x$, and is true iff $x = a \vee x = b$.

(Axiom 3.4) Let the property be $P(x): x \in A \vee x \in B$.

(Axiom 3.5) Let the property be $Q(x): x \in A \wedge P(x)$, where $P(x)$ is a property pertaining to
elements of $A$.

(Axiom 3.6) Let the property be $Q(y): P(x,y)$ is true for some $x \in A$.
\end{proof}

\declareexercise{3.2.2}
\begin{proof}
(1)
Suppose the negation: $\exists A(A \in A)$. Then by Axiom 3.3, construct a set $B:= \{A\}$. $A$ is
the only element in $B$. $A$ is a set. $A$ is not disjoint from $B$, for $A \in A \wedge A \in B$.

(2)
Suppose the negation: $A \in B \wedge B \in A$. Construct a set $S: \{A,B\}$. $A$ is an element of
$S$. $A$ is a set. $A$ is not disjoint from $S$, for $B \in A \wedge B \in S$.
\end{proof}

\declareexercise{3.2.3}
On one hand, if Axiom 3.8 is true, we can choose a property $P(x)$ which is true for all objects. Thus
we have $\Omega$.

On the other hand, if there exists such a set as $\Omega$, we can use Axiom 3.5 to construct any set
we want from it. (e.g. If we want a set to have these elements: $a,b,\dots$, we can let
$P(x):= x = a \vee x = b, \vee \dots$.)

\subsection{Functions}
In Example 3.3.3, Tao asked why $x'=x \Rightarrow f(x')=f(x)$. The reason is, the property $P(x,y)$
obeys the axiom of substitution. Thus, $P(x,y)\equiv P(x',y)$. According to definition, since
$x' \in X$, $y$ is unique.

In Example 3.3.9, Tao asked why all functions whose domain is $\varnothing$ and whose range is the same
are equal. The reason is $x \in \varnothing \Longrightarrow f(x) = g(x)$ is vacuously true.

\declareexercise{3.3.1}
\begin{proof}
The properties of equality are all true since in definition, we only use $f(x) = g(x)$, in which the $=$
obeys these rules, plus the fact that the output is unique.

Then the substitution:
\begin{align*}
f = \overset{\sim}{f} &\Longrightarrow \\
f(x) = \overset{\sim}{f}(x) &\Longrightarrow \\
g(f(x)) = g(\overset{\sim}{f}(x))
\end{align*}.
And then $\overset{\sim}{g}(\overset{\sim}{f}(x)) = g(\overset{\sim}{f}(x)) = g(x)$.
\end{proof}

\declareexercise{3.3.2}
\begin{proof}
The former: Suppose the negation:
\[
\exists x \exists x'(g(f(x)) = g(f(x')) \wedge x \neq x')
\]
Then,
\begin{align*}
g(f(x)) = g(f(x')) &\Longrightarrow \\
f(x)= f(x') \tag{$g$ is injective} &\Longrightarrow \\
x = x' \tag{$f$ is injective}
\end{align*},
which is impossible.

The latter: Suppose the negation:
\[
\exists z \forall x(z \in Z \wedge g \circ f(x) \neq z)
\]
Then, we can conclude that $\exists y \forall x(y \in Y \wedge y \neq f(x))$, since $g$ is surjective.
This is impossible as $f$ is surjective.
\end{proof}

\declareexercise{3.3.3}
\begin{proof}
\begin{large}
\textbf{Attention:}
\end{large}
Different interpretations for injectivity may result in different conclusions.
I have asked a question at
\href{https://math.stackexchange.com/questions/3800240/how-to-interpret-the-definition-of-injectivity}{Stack Exchange} regarding this problem.

Let the range be $Y$, and the function be $f$.
Injectivity:
\[
\forall x'\forall x((x \in \varnothing \wedge x' \in \varnothing) \Longrightarrow
(x \neq x' \Longrightarrow f(x) \neq f(x')))
\],
which is always vacuously true.

Surjectivity:
\[
\forall y(y \in Y \Longrightarrow \exists x(x \in \varnothing \wedge f(x) = y))
\],
which is false if $Y \neq \varnothing$, and which is vacuously true if $Y = \varnothing$.

Bijective: True if $Y = \varnothing$.
\end{proof}

\declareexercise{3.3.4}
\begin{proof}
The former: $f,\overset{\sim}{f}$ have the same range and domain.
\[
\forall x(g \circ f = g \circ \overset{\sim}{f} \Longrightarrow g(f(x)) = g(\overset{\sim}{f}(x)))
\]
We know that $g$ is injective, so $\forall x \in X, f(x) = \overset{\sim}{f}(x)$. Thus
$f = \overset{\sim}{f}$.

It is not true if $g$ is not injective. Consider an extreme condition, where $g$ is constant. So
whatever $f,\overset{\sim}{f}$ are, $g \circ f = g \circ \overset{\sim}{f}$ are always equal.

The latter: Suppose the negation:$g \neq \overset{\sim}{g}$.
$g,\overset{\sim}{g}$ have the same range and domain. But they are not equal, so
$\exists y(y \in Y \wedge g(y) \neq \overset{\sim}{g}(y))$. Because $f$ is surjective,
$\exists x(x \in X \wedge f(x) = y)$. However, $g \circ f(x) = \overset{\sim}{g} \circ f(x)$, so
this is impossible.

It is not true if $f$ is not surjective. We can make $g(y) = \overset{\sim}{g}(y)$ when $y=f(x)$, but
as well make $g(y') \neq \overset{\sim}{g}(y')$ if $\nexists x(y'=f(x))$.
\end{proof}

\declareexercise{3.3.5}
\begin{proof}
Injectivity:
Suppose the negation, that
\[
\exists x \exists x'(x \neq x' \wedge f(x) = f(x'))
\], which immediately gives
\[
g(f(x)) = g(f(x'))
\], and thus is impossible.

$g$ has not to be also injective, because $f$ being so ensures that an unique input $x$ gives an unique
input to $g$.

Surjectivity:
If $g$ is not surjective, then $\exists z \forall y(z \in Z \wedge y \in Y \wedge z \neq g(y))$
And whatever $x$ is, $f(x) \in Y$, so $g(f(x)) \neq z$, which is a contradiction.

$f$ has not to be surjective as long as its ``real'' domain is large enough to form the set $Z$ through
$g$. For example (Informal), let $g$ be $z = |y|, \mathbb{R} \rightarrow \mathbb{R}^{+}\cup\{0\}$, and
let $f$ be $y = x, \mathbb{R}^{+}\cup\{0\} \rightarrow \mathbb{R}$.
\end{proof}

\declareexercise{3.3.6}
\begin{proof}
The latter:
By definition, $P(y,x)$ of $x = f^{-1}(y)$ is $f(x)=y$. Substitute $x$ with $f^{-1}(y)$, and here we
have $f(f^{-1}(y)) = y$, where $y \in Y$.

The former: Let $y = f(x)$. According to what we have proven, \\
$f(f^{-1}(y)) = y$. Substitute $y$ with
$f(x)$, we have $f(f^{-1}(f(x))) = f(x)$. Since that $f(x)$ is injective, we have $f^{-1}(f(x)) = x$.

Now we need to show that $f^{-1}$ is bijective. Assume that it is not injective, thus
$\exists x \exists x'(x \in Y \wedge x' \in Y \Longrightarrow(x\neq x' \Longrightarrow f^{-1}(x) =
f^{-1}(x')))$.
However, according to the latter conclusion, $f^{-1}(x) = f^{-1}(x') \Longrightarrow x=x'$, a
contradiction, so $f^{-1}$ must be injective.

And it is also surjective. $\forall x \in X$, $\exists y \in Y, f^{-1}(y)=x$. According to the former
conclusion, $y$ is $f(x)$.

So now $f^{-1}$ is bijective, and thus has its inverse. By definition, $P(x,y)$ of
$y = (f^{-1})^{-1}(x)$ is $f^{-1}(y) = x$, where $x \in X$. According to the former conclusion,
$f^{-1}(f(x)) = x$. Thus
\[
f^{-1}(y) = f^{-1}(f(x)) \Longrightarrow y = f(x) \Longrightarrow (f^{-1})^{-1}(x) = f(x)
\], which is true $\forall x \in X$. And since they have the same domain and range, $(f^{-1})^{-1} = f$.
\end{proof}

\declareexercise{3.3.7}
\begin{proof}
Injectivity:
\[
g \circ f(x) = g \circ f(x') \Longrightarrow f(x) = f(x') \Longrightarrow x = x'
\]

Surjectivity:
For each $z \in Z$, we need to find $x \in X$ such that $g \circ f(x) = z$. By the surjectivity of $g$,
we can find $y \in Y$ such that $g(y) = z$. We can also find $a \in X$ such that $f(a) = y$ as $f$ is
surjective. So $a$ is our desired $x$.

The $P(z,x)$ of $x = (g \circ f)^{-1}(z)$ is $z = g \circ f(x)$. Consider the following expression:
\begin{align*}
f^{-1} \circ g^{-1} (z)
&= f^{-1} \circ g^{-1} (g \circ f(x)) \\
&= f^{-1}(\textcolor{red}{g^{-1}(g(}f(x)\textcolor{red}{))}) \\
&= f^{-1}(f(x)) \\
&= x
\end{align*}
So $(g \circ f)^{-1} = f^{-1} \circ g^{-1}$. Therefore, they are equal as they have the same domain and
range.
\end{proof}

\declareexercise{3.3.8}
\begin{proof}
(a) First they have the same domain and range. Finally,
\[
\forall x(x\in X \Longrightarrow x=x \Longrightarrow \iota_{Y \rightarrow Z} \circ
\iota_{X \rightarrow Y} = \iota_{X \rightarrow Z})
\]

(b) On one hand, they have the same domain and range.

On the other hand,
\begin{align*}
f \circ \iota_{A \rightarrow A}(x)
&= f(\iota_{A \rightarrow A}(x)) \\
&= f(x) \\
&= \iota_{B \rightarrow B}(f(x)) \\
&= \iota_{B \rightarrow B} \circ f (x)
\end{align*}

(c) It is easy to see that they have the same domain and range.

\[
f \circ f^{-1} (b) = b = \iota_{B \rightarrow B}
\]
\[
f \circ f^{-1} (a) = a = \iota_{A \rightarrow A}
\]

(d) It is easy to see that they have the same domain and range.

Let $h$ be
$h(x) = f(x)$, if $x \in X$, $h(x) = g(x)$, if $x \in Y$.

For each $x \in X$, $\iota_{X \rightarrow X \cup Y}(x) = x$, so
$h(\iota_{X \rightarrow X \cup Y}(x)) =f(x)$.

Similarly we can prove $h(\iota_{Y \rightarrow X \cup Y}(x)) = g(x)$ for each $x \in Y$.
\end{proof}

\subsection{Images and inverse Images}
\paragraph{Definition 3.4.1}
To prove that $f(S)$ is well-defined by using the axiom of specification, we need to apply it to set
$Y$, not $X$. Let $P(y)$ be a property pertaining to each $y \in Y$, which is true iff
$\exists x(x \in S \wedge f(x) = y)$. According to the axiom of specification, there exists a set that
contains every $y \in Y$ such that $P(y)$ is true.

In some places where Tao asked ``(Why?)'', the reason is obvious, so I don't write them here.

\paragraph{Example 3.4.6}
This is because
\[
f^{-1}(f(\{-1,0,1,2\})) = f^{-1}(\{1,0,4\}) = \{-1,1,0,2,-2\}
\].

More generally, if $f$ (whose domain is $X$, and whose range is $Y$) is not injective, then
\[
\exists x \exists x'((x \in X \wedge x' \in X) \wedge (x\neq x' \wedge f(x) = f(x')))
\].
Let $D \subseteq X$ such that $x \in D \wedge x' \notin D$. Then $f(x) = f(x') \in f(D)$. And thus
$x,x' \in f^{-1}(f(D)) \Longrightarrow f^{-1}(f(D)) \neq D$.

\declareexercise{3.4.1}
\begin{proof}
$f^{-1}(V)$ may be interpreted in two different ways:

(1) Interpret $f^{-1}(V)$ as an inverse image, that is,
\[
(\forall x \in X)(x \in f^{-1}(V) \equiv f(x) \in V)
\]
\[
(\forall x \notin X)(x \notin f^{-1}(V))
\]

(2) Interpret $f^{-1}(V)$ as an image, where we regard $f^{-1}$ as a function. So,
\[
\forall x(\exists y(y \in V \wedge x = f^{-1}(y)) \equiv x \in f^{-1}(V))
\]

We need to show that if the two statements are well-defined($x \in X$) , they are logically equivalent.

Let $S_1$ be the set defined in form (1), $S_2$ be the set defined in form (2). For every $x \in S_1$,
$f(x) \in V$. Let $y' = f(x), x' = f^{-1}(y')$, then by definition (2) we have $x' \in S_2$. But
$x' = x$, so $\forall x(x \in S_1 \Longrightarrow x \in S_2)$.

On the other hand, for every $a \in S_2$, $\exists b \in V$, such that $a = f^{-1}(b)$. Then $a \in X$.
$f(a) = f(f^{-1}(b)) = b \in V$, so $a \in S_1$. Thus, $S_1 = S_2$.
\end{proof}

\declareexercise{3.4.2}
(1) Generally we can say $S \subseteq f^{-1}(f(S))$ but we cannot say that they are equal; (2) we can
say $f(f^{-1}(U)) \subseteq U$ but we cannot say that they are equal.
\begin{proof}
(1) $x \in S \Longrightarrow f(x) \in f(S) \Longrightarrow x \in f^{-1}(f(S))$. However, it is possible
that $\exists x(x \in X \wedge x \notin S \wedge f(x) \in f(S))$

(2)
\[
x \in f^{-1}(U) \Longrightarrow f(x) \in U \Longrightarrow (y \in f(f^{-1}(U)) \Longrightarrow y \in U)
\]
However, it is still possible that
\[
\exists y(y \in U \wedge \forall x(x \in X \Longrightarrow f(x) \neq y))
\]
\end{proof}

\declareexercise{3.4.3}
\begin{proof}
(1)
\[
x \in A \cap B \Longrightarrow f(x) \in f(A) \wedge f(x) \in f(B) \Longrightarrow
f(x) \in f(A) \cap f(B)
\]
\[
y \in f(A \cap B) \equiv \exists x(x \in A \cap B \wedge f(x) = y)
\]
So $y \in f(A) \cap f(B)$, thus $f(A \cap B) \subseteq f(A) \cap f(B)$.

(2)
\[
x \in A \setminus B \Longrightarrow f(x) \in f(A\setminus B)
\]
\[
y \in f(A)\setminus f(B) \Longrightarrow \exists x(x \in A \wedge x \notin B \wedge f(x) = y)
\]
So $y \in f(A\setminus B)$, thus $f(A)\setminus f(B) \subseteq f(A\setminus B)$.

(3)
On one hand,
\[
y \in f(A \cup B) \equiv \exists x (x \in A \cup B \wedge f(x) = y)
\]
\begin{align*}
x \in A \cup B \Longrightarrow x \in A \vee x \in B \Longrightarrow \\
f(x) \in f(A) \vee f(x) \in f(B) \Longrightarrow f(x) \in f(A)\cup f(B)
\end{align*}

On the other hand,
\[
y \in f(A) \cup f(B) \Longrightarrow \exists x((x \in A \vee x \in B) \wedge f(x) = y)
\]
\[
x \in A \vee x \in B \Longrightarrow x \in A \cup B \Longrightarrow f(x) \in f(A\cup B)
\]
\end{proof}

(1) $\subseteq$ can not be improved. Since it is possible that
\[
\exists x \exists x'(x \in A \wedge x' \in B \wedge x \neq x' \wedge f(x) = f(x'))
\]

(2) $\subseteq$ can not be improved. Since it is possible that
\[
\exists x \exists x'(x \in A \setminus B \wedge x' \in B \wedge f(x) = f(x'))
\]

\declareexercise{3.4.4}
\begin{proof}
(1)
\begin{align*}
x \in f^{-1}(U \cup V) \equiv (x \in X \wedge f(x) \in U \cup V) \equiv \\
(x \in X \wedge (f(x) \in U \vee f(x) \in V))
\end{align*}
\begin{align*}
x \in  f^{-1}(U) \cup  f^{-1}(V) \equiv (x \in X \wedge f(x) \in U) \vee (x \in X \wedge f(x) \in V) \\
\equiv (x \in X \wedge (f(x) \in U \vee f(x) \in V))
\end{align*}

(2) and (3) can be proven in similar manners.
\end{proof}

\declareexercise{3.4.5}
\begin{proof}
(1) On one hand, if $f(f^{-1}(S)) = S$ for every $S \subseteq Y$, then \\
$f(f^{-1}(Y)) = Y$. That means,
$y \in Y \Longrightarrow \exists x (x \in f^{-1}(Y) \wedge f(x) \in Y)$. So even $f^{-1}(Y)$
is enough for $f$ to be surjective. And $f^{-1}(Y) \subseteq X$, so $f$ is surjective.

On the other hand, if $f$ is surjective, then for each $S \subseteq Y$,
\[
y \in S \Longrightarrow \exists x(x \in X \wedge f(x) = y)
\]
Such $x$ are elements of $f^{-1}(S)$ of course, so $f(f^{-1}(S)) = S$.

(2) On one hand, we show that $\forall S(S \subseteq X \Longrightarrow f^{-1}(f(S)) = S)$ implies that
$f$ is injective. Suppose the negation, that when
\[
\forall S(S \subseteq X \Longrightarrow f^{-1}(f(S)) = S)
\], but $f$ is not injective. Since $f$ is not injective,
\[
\exists x \exists x'(x \in X \wedge x' \in X \wedge x \neq x' \wedge f(x) = f(x'))
\]
Let $S \subseteq X$ and $x \in S \wedge x' \notin S$. There is always such a set $S$.
For example, we can let $S = X\setminus \{x'\}$. So we have $f^{-1}(f(S)) \neq S$ because $x' \in$ it.

On the other hand, if $f$ is injective, then for every $S \subseteq X$, and for every $x \in S$, we have
$f(x) \in f(S)$. And $f(x)$ are the only elements in $f(S)$, that is,
$y \in f(S) \Longrightarrow y = f(x)$ for some $x \in S$. So now we know that
$S \subseteq f^{-1}(f(S))$. Moreover, for every $x' \in f^{-1}(f(S))$, $f(x') \in f(S)$. We can let
$f(x') = y = f(x)$. As $f$ is injective, $x = x'$, so $x' \in S$. That means $f^{-1}(f(S)) \subseteq S$.
So $f^{-1}(f(S)) =  S$.
\end{proof}

\declareexercise{3.4.6}
\begin{proof}
My own proof: According to Axiom 3.10, we can construct the set $X^X$. Apply the axiom
of replacement to each element of $X^X$, we construct a set $Z$ such that
\[
\forall x(x \in Z \equiv \exists f(f \in X^X \wedge x = f(X)))
\]

Let $Y = \{\varnothing\} \cup Z$.

Now we prove that $Y$ is the set we want. On one hand, for any $S \subseteq X$,
if $S = \varnothing$, then $S \in Y$, as $Y = \{\varnothing\} \cup Z$.

If $S \neq \varnothing$, there exists a surjective function $g: X \rightarrow S$. $g\in X^X$, and
$g(X) = S$, so $S \in Z$, and thus $S \in Y$. (To show the existence of $g$, for example, let $x \in X,
g(x) = x$ if $x \in S$, and for $x \in X \wedge x \notin S$, $g(x)$ can be any element of $X$.)

On the other hand, for any $S' \nsubseteq X$, $\exists a(a \in S' \wedge a \notin X)$. To prove that
$S' \notin Y$, we need to show that $\nexists f(f \in X^X \wedge S' = f(X))$. We know that
$\nexists x(x \in X \wedge f(x) = a)$, so $a \notin f(X)$. Therefore $S' \neq f(X)$, so $S' \notin Y$.

$Y$ is the set we want.

I posted a question \href{https://math.stackexchange.com/questions/3803487/is-this-proof-to-the-existence-of-a-set-that-contains-all-subsets-of-another-set}{here} for verification for this proof.
Thanks to answers of people at Stack Exchange so that my proof can be refined.

Proof By Tao's Hint:
For each $S \subseteq X$, let a function $f_S$ be $f_S(x) = 1$ if $x \in S$, and $f_S(x)=0$ if
$x \in X \wedge x \notin S$. Then $f^{-1}_S(\{1\})$ gives $S$.

Now we show that any element in
$\{0,1\}^X$ is some $f_S$. Let $g \in \{0,1\}^X$. Then if $\forall x \in X, g(x) = 0$, then
$g = f_{\varnothing}$. Otherwise, there exists a set that contains all $x$ such that $g(x) = 0$ by
axiom of specification, namely $R$. Then $g = f_R$.

On the other hand, each $f_S$ is obviously an element of $\{0,1\}^X$.

Use the axiom of replacement, we construct a set $Y$ such that
\[
\forall x (x \in Y \equiv \exists f(f \in \{0,1\}^X \wedge x = f^{-1}(\{1\})))
\]

According to what we have proven, $Y$ is the set we want.
\end{proof}

\declareexercise{3.4.7}
\begin{proof}
As stated by the previous exercise, there exists a set $\mathbb{X}$ whose elements are all subsets of
$X$, and a set $\mathbb{Y}$ whose elements are all subsets of $Y$.

For every element $x \in \mathbb{X}$, apply the axiom of replacement to $\mathbb{Y}$, to obtain a set
$S_x := \{y^x\}$ for every element $y \in \mathbb{Y}$.

According to the axiom of union, using $\mathbb{X}$ as the index set, we have the set
\[
Z = \bigcup_{x \in \mathbb{X}} S_x
\]

Apply again the axiom of union to $Z$ to obtain $R$, which contains all elements of elements of $Z$. Now
we show that $R$ is the set we want.

On one hand, let $f$ be an arbitrary function with the domain of $X' \subseteq X$, and the range of $Y'
\subseteq Y$. We can see that $f \in {Y'}^{X'} \in S_{X'}$. ${Y'}^{X'}$ becomes an element of $Z$. And
thus $f$ becomes an element in $R$.

On the other hand, from the construction of $R$, we can see that $R$ contains only these elements.

\end{proof}

\declareexercise{3.4.8}
\begin{proof}
Let $A,B$ be two arbitrary sets. They are also objects as stated by Axiom 3.1. So according to
Axiom 3.3, there exists a set $S=\{A,B\}$. By Axiom 3.11, we have a set $Z$ such that
\[
\forall x(x \in Z \equiv \exists X(X \in S \wedge x \in X))
\]

Now we show that $Z$ is the set we want. If $x \in A \vee x \in B$, then
$\exists X(X \in S \wedge x \in X)$ is true. So $x \in Z$.

If $x \notin A \wedge x \notin B$, then $\forall X(X \in S \Longrightarrow x \notin X)$, that is,
$\exists X(X \in S \wedge x \in X)$ is false. So $x \notin Z$.

$Z$ is therefore the set we want.
\end{proof}

\paragraph{Example 3.4.11}
In (3.3), why do Tao choose some element $\beta$ of $I$? This is because we need to apply the axiom of
specification to $A_\beta$ with the restriction $x \in A_\alpha$ for all $\alpha \in I$.

\declareexercise{3.4.9}
\begin{proof}
This is quiet easy to prove. Let the left-handed side set be $S$, the RHS set be $S'$. For any
$x \in S$, $x \in A_\alpha$ for all $\alpha \in I$. So $x \in A_{\beta'}$. And $x \in A_\alpha$ for all
$\alpha \in I$. Therefore $x \in S'$.

It is nearly the same the prove $x \in S' \Longrightarrow x \in S$.
\end{proof}

\paragraph{Exercise 3.4.10} \label{exercise3.4.10}
\begin{proof}
For the sake of convenience, let
$(\bigcup_{\alpha \in I} A_{\alpha})\cup(\bigcup_{\alpha \in J}A_{\alpha})$ be $S$, \\
$\bigcup_{\alpha \in I \cup J} A_{\alpha}$ be $S'$,
$(\bigcap_{\alpha \in I} A_{\alpha})\cap(\bigcap_{\alpha \in J}A_{\alpha})$ be $Z$,
$\bigcap_{\alpha \in I \cup J} A_{\alpha}$ be $Z'$.

(1) When $I,J \neq \varnothing$:
On one hand,
\[
x \in S \Longrightarrow (x \in \bigcup_{\alpha \in I} A_{\alpha} \vee
x \in \bigcup_{\alpha \in J}A_{\alpha})
\]
If $x \in \bigcup_{\alpha \in I} A_{\alpha}$, then $x \in \bigcup_{\alpha \in I \cup J} A_{\alpha}$.
If $x \in \bigcup_{\alpha \in J} A_{\alpha}$, then $x \in \bigcup_{\alpha \in I \cup J} A_{\alpha}$.

On the other hand, if $x \in S'$, then there exists an object $a \in I \cup J$ such that $x \in A_a$.
If $a \in I$ then $x \in x \in \bigcup_{\alpha \in I} A_{\alpha} \Longrightarrow x \in S$.
If $a \in J$ then $x \in x \in \bigcup_{\alpha \in J} A_{\alpha} \Longrightarrow x \in S$.

When $I,J$ are both empty, $S,S'$ are all empty.

When there is only one of $I,J$ is empty, say it is $I$, then
$S = \varnothing \cup \bigcup_{\alpha \in J} = \bigcup_{\alpha \in J}$. And
$S' = \bigcup_{\alpha \in \varnothing \cup J} A_{\alpha} = \bigcup_{\alpha \in J}$.

(2)
\[
x \in Z \equiv \forall a(a \in I \Longrightarrow x \in A_a) \wedge
\forall b(b \in J \Longrightarrow x \in A_b)
\], which is equal to $\forall a(a \in I \cup J \Longrightarrow x \in A_a) \equiv x \in Z'$.
\end{proof}

\paragraph{Exercise 3.4.11} \label{exercise3.4.11}
\begin{proof}
(1) Let the LHS be $S$, the RHS be $S'$.
\begin{align*}
x \in S &\equiv \\
x \in X \wedge x \notin \bigcup_{\alpha \in I} A_{\alpha} &\equiv \\
x \in X \wedge \forall a(a \in I \Longrightarrow x \notin A_{a})
\end{align*}
\begin{align*}
x \in S' &\equiv \\
\forall a(a \in I \Longrightarrow x \in X \setminus A_a) &\equiv \\
x \in X \wedge \forall a(a \in I \Longrightarrow x \notin A_a)
\end{align*}.

So $S=S'$.

(2) Let the LHS be $Z$, the RHS be $Z'$.
\begin{align*}
x \in Z &\equiv \\
x \in X \wedge x \notin \bigcap_{\alpha \in I} A_{\alpha} &\equiv \\
x \in X \wedge \neg(\forall a(a \in I \Longrightarrow x \in A_a)) &\equiv \\
x \in X \wedge \exists a(a \in I \Longrightarrow x \notin A_a)
\end{align*}
\begin{align*}
x \in Z' &\equiv \\
x \in X \wedge \bigvee_{\alpha \in I}(x \notin A_{\alpha}) &\equiv \\
x \in X \wedge \exists a(a \in I \Longrightarrow x \notin A_a)
\end{align*}

Thus, $Z = Z'$
\end{proof}

\subsection{Cartesian products}
\declareexercise{3.5.1}
\begin{proof}
First we show that $(x,y) = \{\{x\},\{x,y\}\}$ is a good definition.
Let $S_1$ denote $(x_1,y_1) = \{\{x_1\},\{x_1,y_1\}\}$, $S_2$ denote
$(x_2,y_2) = \{\{x_2\},\{x_2,y_2\}\}$.

On one hand, if $x_1=x_2\wedge y_1=y_2$, then obviously $S_1=S_2$ for they have the same elements.

On the other hand, if $S_1 = S_2$, then
\[
\{x_1\} \in S_2 \wedge \{x_1,y_1\} \in S_2 \wedge
\{x_2\} \in S_1 \wedge \{x_2,y_2\} \in S_1
\].
We have that
\begin{align*}
\{x_1\} \in S_2 &\equiv \{x_1\} = \{x_2\} \vee \{x_1\} = \{x_2,y_2\} \\
&\equiv x_1=x_2 \vee x_1=x_2=y_2 \\
&\Longrightarrow x_1=x_2
\end{align*}
\begin{align*}
\{x_1,y_1\} \in S_2 &\equiv \{x_1,y_1\} = \{x_2\} \vee \{x_1,y_1\} = \{x_2,y_2\} \\
&\equiv x_1=x_2=y_1 \\
&\vee \textcolor{red}{((x_1=x_2\wedge y_1=y_2)\vee(x_1=y_2\wedge y_1=x_2))}
\end{align*}
Similarly we have that
\begin{align*}
\{x_2,y_2\} \in S_1
&\equiv x_2=x_1=y_2 \\
&\vee \textcolor{red}{((x_2=x_1\wedge y_2=y_1)\vee(x_2=y_1\wedge y_2=x_1))}
\end{align*}
We may notice that the red-colored text are two same statements. Thus from $\{x_1,y_1\} \in S_2$ and
$\{x_2,y_2\} \in S_1$ we can always conclude that $y_1=y_2$. Therefore,
$S_1 = S_2 \Longrightarrow x_1=x_2\wedge y_1=y_2$.

Then we show that if $X,Y$ are two sets, then $X \times Y$ is also a set. For each element $x \in X$,
construct a set $S_x$, where we replace each element $y \in Y$ with $(x,y)$. Then construct the set
$\bigcup_{x \in X}S_x$.
\end{proof}

\declareexercise{3.5.2}
\begin{proof}
Since $x,y$ are two functions, they are equal means that $\forall 1\leq i \leq n$, $x(i) = y(i)$. That
is, $x_i = y_i, 1\leq i \leq n$.

Now we show that $\displaystyle \prod_{1\leq i\leq n}X_i$ is a set. Let set $F$ be the set that contains
all partial functions from $N = \{i \in \mathbb{N}:1\leq i\leq n\}$ to
$\displaystyle X = \bigcup_{1\leq i\leq n}X_i$ (Exercise 3.4.7). Use the axiom of specification, select
such elements $f$ from $F$ that:
\begin{enumerate}
\item the element is surjective, and
\item its domain is $N$, and
\item $f(i) \in X_i$
\end{enumerate},
and use all of them to construct a set $Z$, which is the set we want.
\end{proof}

\declareexercise{3.5.3}
\begin{proof}
The definition is entirely based on the equality of objects (e.g. $x = x'$). The proof is immediately
done since this equality is reflective ($x = x$), symmetric ($x = x' \equiv x' = x$), and transitive
($x_0 = x_1 \wedge x_1 = x_2 \Longrightarrow x_0 = x_2$).
\end{proof}

\declareexercise{3.5.4}
\begin{proof}
(1)
\begin{align*}
(x,y) \in A \times (B \cup C) &\equiv x \in A \wedge y \in (B \cup C) \\
&\equiv x \in A \wedge (y \in B \vee y \in C) \\
&\equiv (x \in A \wedge y \in B) \vee (x \in A \wedge y \in C) \\
&\equiv ((x,y) \in A \times B) \vee ((x,y) \in A \times C) \\
&\equiv (x,y) \in (A \times B) \cup (A \times C)
\end{align*}

(2)
\begin{align*}
(x,y) \in A \times (B \cap C) &\equiv x \in A \wedge y \in (B \cap C) \\
&\equiv x \in A \wedge (y \in B \wedge y \in C) \\
&\equiv (x \in A \wedge y \in B) \wedge (x \in A \wedge y \in C) \\
&\equiv ((x,y) \in A \times B) \wedge ((x,y) \in A \times C) \\
&\equiv (x,y) \in (A \times B) \cap (A \times C)
\end{align*}

(3)
\begin{align*}
(x,y) \in A \times (B \setminus C) &\equiv x \in A \wedge y \in (B \setminus C) \\
&\equiv x \in A \wedge (y \in B \wedge \neg (y \in C)) \\
&\equiv (x \in A \wedge y \in B) \wedge \neg (x \in A \wedge y \in C) \\
\tag{The statement $x \in A$ implies $\neg (x \in A \wedge y \in C)
\Longrightarrow \neg (y \in C)$}\\
&\equiv ((x,y) \in A \times B) \wedge \neg((x,y) \in A \times C) \\
&\equiv (x,y) \in (A \times B) \setminus (A \times C)
\end{align*}
\end{proof}

\declareexercise{3.5.5}
\begin{proof}
(1)
\begin{align*}
(x,y) \in (A \times B) \cap (C \times D)
&\equiv (x,y) \in (A \times B) \wedge (x,y) \in (C \times D) \\
&\equiv (x \in A \wedge y \in B) \wedge (x \in C \wedge y \in D) \\
&\equiv (x \in A \wedge x \in C) \wedge (y \in B \wedge y \in D) \\
&\equiv x \in A \cap C \wedge y \in B \cap D \\
&\equiv (x,y) \in (A \cap C) \times (B \cap D)
\end{align*}

(2) It is not true since
\begin{align*}
(x,y) \in (A \times B) \cup (C \times D)
&\equiv (x,y) \in (A \times B) \vee (x,y) \in (C \times D) \\
&\equiv (x \in A \wedge y \in B) \vee (x \in C \wedge y \in D) \\
&\nLeftrightarrow (x \in A \vee x \in C) \wedge (y \in B \vee y \in D)
\end{align*}
Generally
\[
(x \in A \wedge y \in B) \vee (x \in C \wedge y \in D) \Longrightarrow
(x \in A \vee x \in C) \wedge (y \in B \vee y \in D)
\],
but
\[
(x \in A \vee x \in C) \wedge (y \in B \vee y \in D) \nRightarrow
(x \in A \wedge y \in B) \vee (x \in C \wedge y \in D)
\].

(3) It is not true since
\begin{align*}
(x,y) \in (A \times B) \setminus (C \times D)
&\equiv (x,y) \in (A \times B) \wedge (x,y) \notin (C \times D) \\
&\equiv (x \in A \wedge y \in B) \wedge (x \notin C \vee y \notin D) \\
&\nLeftrightarrow (x \in A \wedge x \notin C) \wedge (y \in B \wedge y \notin D)
\end{align*}
\end{proof}

\declareexercise{3.5.6}
\begin{proof}
(1) On one hand, if $A \subseteq C$ and $B \subseteq D$, then
\begin{align*}
(x,y) \in A \times B &\equiv x \in A \wedge y \in B \\
&\Longrightarrow x \in C \wedge y \in D \\
&\Longrightarrow (x,y) \in C \times D
\end{align*},
which means $A \times B \subseteq C \times D$.

On the other hand, if $A \times B \subseteq C \times D$, but we suppose that
\[
\neg(A \subseteq C \wedge B \subseteq D)
\].
We only consider that $A \nsubseteq C$, the other situations are similar. Then
$\exists x(x \in A \wedge x \notin C)$. Let $p = (x,y)$, where $y \in B$, then $p \in A \times B$.
But $x \notin C$, so $p \notin C \times D$, a contradiction. Therefore,
\[
A \times B \subseteq C \times D \Longrightarrow A \subseteq C \wedge B \subseteq D
\]

(2) On one hand, if $A = C \wedge B = D$, then
\begin{align*}
(x,y) \in A \times B &\equiv x \in A \wedge y \in B \\
&\equiv x \in C \wedge y \in D \\
&\equiv (x,y) \in C \times D
\end{align*}.

On the other hand, if $A \times B = C \times D$, but we suppose that $\neg(A = C \wedge B = D)$.
We only consider that $A \neq C$, the other situations are similar. Then we only consider
$\exists x(x \in A \wedge x \notin C)$, for the other situations are similar.

(3) It is easy to prove that $X \times \varnothing = \varnothing$ and
$\varnothing \times X = \varnothing$. Let $A = \varnothing$, we can see that even if $B \nsubseteq D$,
$A \times B \subseteq C \times D$.

Let $A = D = \varnothing$, then even if $A \neq C$, $A \times B = C \times D$.
\end{proof}

\declareexercise{3.5.7}
\begin{proof}
Existence: Let $h(t):=(f(t),y(t))$. It is easy to verify that $h(t) \in X \times Y$, and that given a
$t \in Z$, $h(t)$ is unique. Therefore, $h$ is a function. And it is obvious that
$\pi_{X\times Y \rightarrow X} \circ h = f$ and that $\pi_{X\times Y \rightarrow Y} \circ h = g$.

Uniqueness: $\pi_{X\times Y \rightarrow X} \circ h = f$ and $\pi_{X\times Y \rightarrow Y} \circ h = g$
imply that if there is another function $h'$ that satisfies the requirements, then $h'(t) = h(t)$. So $h$
is unique.
\end{proof}

\declareexercise{3.5.8}
\begin{proof}
On one hand, if for some $i, X_i = \varnothing$, then
\[
\forall (x_i)_{1\leq i \leq n}(\bigwedge^{n}_{i =1}x_i \in X_i \equiv (x_i)_{1\leq i \leq n} \in
\varnothing)
\],
which means that $\varnothing = \prod_{i=1}^{n}X_i$.

On the other hand, if $\prod_{i=1}^{n}X_i = \varnothing$ but we suppose that $X_i \neq \varnothing$. Then
for each $i$, $\exists x_i \in X_i$. We thus have a tuple $(x_i)_{1\leq i \leq n}$, which should be an
element of $\prod_{i=1}^{n}X_i$. Therefore we have a contradiction.
\end{proof}

\declareexercise{3.5.9}
\begin{proof}
On one hand, let $x \in (\bigcup_{\alpha \in I}A_{\alpha})\cap(\bigcup_{\beta \in J}B_{\beta})$. Then
\[
\exists a(a \in I \wedge x \in A_a) \wedge \exists b(b \in J \wedge x \in B_b)
\]
It is obvious that $x \in A_a \cap B_b$ and that $(a,b) \in I \times J$. Therefore
\[
x \in \bigcup_{(\alpha,\beta) \in I \times J}(A_\alpha \cap B_\beta)
\].

On the other hand, let $x \in \bigcup_{(\alpha,\beta) \in I \times J}(A_\alpha \cap B_\beta)$. Then
\begin{align*}
\exists (a,b) \in I \times J(x \in A_a \cap B_b)
&\Longrightarrow  x \in A_a \wedge x \in B_b \\
&\Longrightarrow x \in \bigcup_{\alpha \in I}A_{\alpha} \wedge x \in \bigcup_{\beta \in J}B_{\beta} \\
&\Longrightarrow x \in (\bigcup_{\alpha \in I}A_{\alpha})\cap(\bigcup_{\beta \in J}B_{\beta})
\end{align*}
\end{proof}

\paragraph{Exercise 3.5.10} \label{exercise3.5.10}
\begin{proof}
We denote $\overset{\sim}{f}$ as $f'$, the graph of $f$ as $G$, and the graph of $f'$ as $G'$ for the
sake of simplification.

(1) On one hand, if $f = f'$, then for every $(x,f(x)) \in G$, we can find $(x,f'(x)) \in G'$, and
obviously $(x,f(x)) = (x,f'(x))$, and vice versa.

On the other hand, if $G = G'$, then for each $(x,f(x)) \in G$, $(x,f(x)) \in G'$. Note that each
element of $G'$ obeys the form $(x,f'(x))$, so $f(x) = f'(x)$ for every $x \in X$, that is, $f=f'$.

(2) Existence: Let $f(x)$ be such a value that $(x,f(x)) \in G$. Thus the value is unique, so $f$ is a
function. According to its definition, the graph of $f$ is $G$.

Uniqueness: As proven in (1), if $f,f'$ have the same graph, then they are equal.
\end{proof}

\paragraph{Exercise 3.5.11} \label{exercise3.5.11}
I think this exercise is meaningless. Lemma 3.4.6 is proven by the fact that $X^Y$ exists, which depends
on Axiom 3.10. Then the exercise asks us to prove Axiom 3.10 using Lemma 3.4.6. So I looked up some books
about set theory and found out that the power set axiom is essentially Lemma 3.4.6, not Axiom 3.10.

Nevertheless, here is the proof:
\begin{proof}
Let set $Z$ contains all subsets of $X\times Y$. The specify such element in $Z$ that obey the vertical
line test, and let them form the set $S$. According to the previous exercise, for each element in $S$,
there exists an unique function whose graph is the element. Then we replace all elements in $S$ with
these functions to construct the set $F$. Obviously, each element in $F$ is a function with the domain
$X$ and the range $Y$.

Now we show that every function $f$ from $X$ to $Y$ is in $F$. Denote the graph of $f$ as $G$. We know
that $G$ obeys the vertical line test and $G \subseteq X \times Y$, so $G \in S$. Since $G$ is the graph
of $f$, $f \in F$.
\end{proof}

\paragraph{Exercise 3.5.12} \label{exercise3.5.12}
I am confused by this exercise. It seems that simply applying induction to $a$ can solve the
problem, just like what we did in Proposition 2.1.16. What is wrong?

By the way, according to the \href{https://terrytao.wordpress.com/books/analysis-i/}{corrections},
edit the exercise as the following:
\begin{quotation}
Let $X$ be an arbitrary set containing at least an element $c$ and obeys the Peano axioms. Let $f$ be a
function from $N \times X$ to $X$. ...

Show that there exists an unique function $a$ from $X$ to $X$ such that
\[
a(0) = c
\]
and
\[
a(n++) = f(n,a(n)), \forall n \in X
\]
...

such that $a_N(0) = c$ and $a_{N}(n++) = f(n,a_N(n))$ ...
\end{quotation}

Note that all properties (e.g. orders, addition) in section 2 are deduced from the Peano axioms and their
definitions. Since $X$ obeys these rules, we use such properties on elements of $X$ without proof.

The proof is now reserved for further research.
\begin{proof}
\end{proof}

\paragraph{Exercise 3.5.13} \label{exercise3.5.13}
\begin{proof}
Use induction.

Existence: We need to prove that for all $n \in \mathbb{N}$, $f(n)$ is defined. Use induction:
$f(0) = 0'$ is define. And the definition is unique for $0$ is not the successor of any natural number.
Now suppose that $f(n) = n'$ is defined, then $f(S(n)) = S'(f(n)) = S'(n')$ is also defined. The
definition is also unique. So we know that $f$ exists.

Injectivity: We need to prove that $f(m) = f(n) \Longrightarrow m = n$. If $f(m) = f(n)$, then $m' = n'$,
and thus $m=n$.

Surjectivity: Use induction:
The basic case is, for $0' \in \mathbb{N}'$, $f(0) = 0'$.

Now suppose that for $n' \in \mathbb{N}'$, we can find $n \in \mathbb{N}$ such that $f(n) = n'$, then
for $S'(n')$, we have $f(S(n)) = S'(n')$. We can close the induction now.
\end{proof}

\subsection{Cardinality of Sets}

\declareexercise{3.6.1}
\begin{proof}
Reflexivity: Let $f(x):= x, X \rightarrow X$. $f$ is bijective since $f^{-1}(x) = x$ exists.

Symmetry: If $X,Y$ have the same cardinality, then $\exists f:X\rightarrow Y$ which is bijective. So
$f^{-1}$ exists, and is also a bijection. Thus $Y,X$ have the same cardinality. Since then, we can say
that two sets have the same cardinality without caring about the order.

Transitivity: If $X,Y$ have the same cardinality, and $Y,Z$ also have the same cardinality, then there
exist two bijections: $f:X \rightarrow Y$ and $g:Y \rightarrow Z$. It is easy to verify that $g \circ f$
is also a bijection and is from $X$ to $Z$ (See \exerciseref{3.3.7}).
\end{proof}

\paragraph{Remark 3.6.6}
It is $f(n) := S(n)$. We are now proving something stronger
\begin{lem} \label{lem3.6.6}
For any natural number $m,n$, $\{i \in \mathbb{N}:0\leq i\leq n\}$ and
$\{i \in \mathbb{N}:m\leq i\leq n+m\}$ have the same cardinality.
\end{lem}
\begin{proof}
Use induction on $m$. When $m=0$, the statement is obviously true. Simply give the function $f(n):=n$.

Suppose that for some $m$, we have proven the statement. Then there exists a bijection:
\[
f:\{i \in \mathbb{N}:0\leq i\leq n\} \rightarrow \{i \in \mathbb{N}:m\leq i\leq n+m\}
\].
Let $g$ be a function from $\{i \in \mathbb{N}:0\leq i\leq n\}$ to $\mathbb{N}$ such that
$g(x) = S(f(x))$. We prove that $g$ is a bijection from $\{i \in \mathbb{N}:0\leq i\leq n\}$ to
$\{i \in \mathbb{N}:S(m)\leq i\leq n+S(m)\}$.

First we prove that $g(n)$ always in $\{i \in \mathbb{N}:S(m)\leq i\leq n+S(m)\}$, which is immediately
given by the fact that addition preserves order.

Surjectivity: For any $a \in \{i \in \mathbb{N}:S(m)\leq i\leq n+S(m)\}$, $a$ is positive. Then $a$ is
always some number's successor, that is $a = S(b) = b+1$ for some natural number $b$. Since addition
preserves order, $b \in \{i \in \mathbb{N}:m\leq i\leq n+m\}$. $f$ being surjective implies that there is
some $x$ in the domain such that $f(x) = b$, and $g(x) = f(x) + 1 = a$.

Injectivity: By cancellation law, $f(x) + 1 \neq f(x') + 1 \equiv f(x) \neq f(x') \equiv x \neq x'$.

We can now close the induction.
\end{proof}

\paragraph{Lemma 3.6.9}
Empty functions are not injective when the range is not empty (See \exerciseref{3.3.3}).

Now we show that $g$ is bijective:
\begin{proof}
Injectivity: $f$ being injective implies that
\[
\forall x \forall x'((x \in X \wedge x' \in X) \Longrightarrow (f(x) = f(x') \Rightarrow x = x'))
\]
For $a,a' \in X - \{x\}$, they also $\in X$. If $g(a) = g(a')$, then either directly $f(a) = f(a')$ or
$f(a) - 1 = f(a') - 1$, which gives $f(a) = f(a')$. Thus $a = a'$. (Note that subtraction is not defined
yet, see the footnote about this in the book).

Surjectivity: The surjectivity of $f$ gives
\[
(\forall 1 \leq i \leq n)(\exists a(a \in X \wedge f(a) = i))
\].

If $f(x) = n$, then $g(a) = f(a)$ for all meaningful $a$. Then for $1 \leq i \leq n-1$, we can find $a$
such that $a \in X \wedge a \neq x$, that is, $x \in X - \{x\}$. So $g(a)$ is meaningful, then $g$ is
surjective.

If $f(x) \neq n$, then $f(x) < n$. For those $1 \leq i < f(x)$, $g$ is obviously surjective. For
$n-1 \geq i \geq f(x)$, since $S(i) \leq n$, $\exists a(a \in X \wedge f(a) = S(i))$. And we know that
$S(i) \neq f(x)$, then $a \in X - \{x\}$. So $g(a) = f(a) - 1 = i$.
\end{proof}

\declareexercise{3.6.2}
\begin{proof}
On one hand, if $X$ is empty, then we know that the empty function whose range is also empty is injective,
(See \exerciseref{3.3.3}) so its cardinality is $0$.

On the other hand, if $\# X = 0$ but $X \neq \varnothing$, then there exists an bijection
$f:X \rightarrow \varnothing$, which is impossible.
\end{proof}

\declareexercise{3.6.3}
\begin{proof}
When $n = 0$, this is vacuously true. The base case then becomes $n=1$. We simply let $M = f(1)$.

Suppose that the statement for $n$ is true. And for $1\leq i\leq n$ we have the number $M$. Then $f(S(n))$
either $\geq$ or $<$ $M$. On the former case, let $f(S(n))$ be $M'$, and on the latter case, let $M' = M$.
It is east to verify that $M'$ is the number we want.
\end{proof}

From now on we will denote $\{i\in \mathbb{N}:1\leq i \leq n\}$ as $\mathbb{N}_n$

\declareexercise{3.6.4}
\begin{proof}
(a)
Let $n = \#X$. There is an injective  $f$ from $X$ to $\{i\in \mathbb{N}:1\leq i\leq n\}$. Let $g$ be a
function from $X \cup \{x\}$ to $\{i\in \mathbb{N}:1\leq i\leq n+1\}$ such that $g(a) = f(a)$ if
$a\neq x$, and $g(x) = n+1$. Now we show that $g$ is bijective.

Injectivity: We know that $\forall x \in X$, $g$ is already injective. Since that $g(x) = n+1 \neq g(a)$
for all $a \in X$, so $g$ is injective on $X \cup \{x\}$.

Surjectivity: We know that $\forall i \in \{i\in \mathbb{N}:1\leq i\leq n\}$, we can find
$a \in X \cup \{x\}$ such that $g(a) = i$. And we have $g(x) = n+1$, so
$\forall a \in \{i\in \mathbb{N}:1\leq i\leq n+1\}$, we can find $a \in X \cup \{x\}$ such that
$g(a) = i$.

(b)
First we prove that if $X,Y$ are disjoint, then $\#X + \#Y = \#(X\cup Y)$. Let $f$ be a bijection from $X$
to $\mathbb{N}_{\#X}$, and $g$ be a bijection from $Y$ to $\mathbb{N}_{\#Y}$. According to
\hyperref[lem3.6.6]{this Lemma}, there exists a bijection $h$ from $\mathbb{N}_{\#Y}$ to
$\{i\in \mathbb{N}:\#X+1\leq i \leq \#X+\#Y\}$. Thus $h \circ g$ is also a bijection. Let $u$ be a
function from $X \cup Y$ to $\mathbb{N}_{\#X} \cup\{i\in \mathbb{N}:\#X+1\leq i \leq \#X+\#Y\}$. Now we
show that $u$ is bijective.

Injectivity: For $x \neq x'$ in the domain. If $x,x'$ are both in $X$ or $Y$, then $f(x)\neq f(x')$ is
immediately given by the injectivity of $f$ and $h \circ g$. If one of them is in $X$, and the other is
in $Y$, then they can also never be equal because the ranges of the two functions are disjoint.

Surjectivity: It is easy to verify that the range is equal to $\mathbb{N}_{\#X + \#Y}$. For any $y$ in the
range, if $y \in$ the range of $f$, then $u$ is surjective since $f$ is, and if $y \in$ the range of $h
\circ g$, $u$ is surjective for the same reason. The range consists of only this two sets, so $u$ is
surjective on the whole range.

The proof is over. This also implies that $X \cup Y$ is finite. Now we need only to show that
$\#(X \cup Y) < \#X + \#Y$ when $X,Y$ are not disjoint. It is easy to see that
\begin{align*}
\#A + \#B
&= \#(A - A \cap B) + \#(A \cap B) + \#(B - A \cap B) + \#(A \cap B) \\
&= (\#(A - A \cap B) + \#(A \cap B) + \#(B - A \cap B)) + \#(A \cap B) \\
&= \#(A \cup B) + \#(A \cap B) \\
&> \#(A \cup B)
\end{align*}

(c)
If $X \subseteq Y \wedge X \neq Y$, then $\#(Y \setminus X) \neq 0$.
\[
\#Y = \#X + \#(Y \setminus X) > \#X
\].

If $X = Y$, then $\#(Y \setminus X) = 0$, and $\#Y$ becomes $\#X$.

(d)
$f: X \rightarrow f(X)$ is always surjective. If $f$ is also injective, then $f$ is bijective. On this
occasion, $\#f(X) = \#X$. If $f$ is not injective, we can select a set $X' \subseteq X \wedge X' \neq X$,
on which $f$ is bijective. Then $\#X' = \#f(X') = \#f(X)$. According to (c), $\#X' < \#X$, so
$\#f(X) < \#X$.

(e)
Suppose that $\#Y = n$. Use induction on $n$.

When $n=0$, $Y$ is empty, then $\#(X \times Y) = 0 = \#X \times 0$. Here we additionally prove that
when $n=1$, this is also true for further usage. When $n=1$, let $Y = \{a\}$. Then the bijection is
$f(x):=(x,a), X \rightarrow X \times \{a\}$.

Suppose that we have proven for some $n$, $\#(X \times Y) = \#X \times \#Y$. Then when $\#Y = S(n)$,
let $Y = Y\setminus\{x\}\cup\{x\}$, where $x \in Y$. Lemma 3.6.9 tells us that
$\#(Y\setminus\{x\}) = S(n)-1 = n$. And \exerciseref{3.5.4} tells us that
$X \times Y = X \times (Y\setminus\{x\}) \cup X \times \{x\}$.
\begin{align*}
\#(X \times Y)
&= \#(X \times (Y\setminus\{x\}) \cup X \times \{x\}) \\
&= \#(X \times (Y\setminus\{x\})) + \#(X \times \{x\}) \\
&= \#X \times n + \#X \\
&= \#X \times S(n)
\end{align*}

We can now close the induction.

(f)
We should first define $m^n$ for natural numbers $m,n$. It has not been done yet. Exponentiation is
defined for rational numbers at Definition 4.3.9.
\begin{definition}
\begin{itemize}
\item $m^0=1$,
\item $m^{S(n)} = m^n \times m$
\end{itemize}
\end{definition}

Suppose that $\#Y = m,\#X = n$. Use induction on $n$.

When $n=0$, $X$ is empty, then $Y^X$ has one function $f:\varnothing \rightarrow Y$.

Suppose that we have proven the statement for some $n$. Before we proceed the proof, we need some lemmas.
\begin{lem}
If $X$ is not empty,
\[
\#Y^{X\setminus\{x'\}\cup\{x'\}} = \#Y^{X\setminus\{x'\}} \times \#Y
\],
where $x'$ is an element of $X$.
\end{lem}
\begin{proof}
By (e) we know that
\[
\#Y^{X\setminus\{x'\}} \times \#Y = \#(Y^{X\setminus\{x'\}} \times Y)
\].

Try to build a bijection between $Y^{X\setminus\{x'\}} \times Y$ and $Y^X$. Let $f' \in Y^X$.

Let $h$ be a function from $Y^X$ to $Y^{X\setminus\{x'\}} \times Y$ such that
\[
h(f') = (f,f'(x')),
\]
where $f(x):=f'(x)$ when $x \neq x'$. Now we show that $h$ is bijective.

Injectivity:
If ${f_1}' \neq {f_2}'$, then
\[
{f_1}'(x') \neq {f_2}'(x') \vee \exists x(x \neq x' \wedge {f_1}'(x) \neq {f_2}'(x))
\]
That is,
\[
{f_1}'(x') \neq {f_2}'(x') \vee f_1 \neq f_2,
\]
which means
\[
(f_1,{f_1}'(x')) \neq (f_2,{f_2}'(x')).
\]

Surjectivity:
For any $(f,a) \in Y^{X\setminus\{x'\}} \times Y$, let $f'$ be $f$ if $x\neq x'$, and $f'(x') = a$. Then
$f' \in Y^X$ and $h(f') = (f,a)$.

So,
\[
\#Y^X = \#(Y^{X\setminus\{x'\}} \times Y)
\], which gives the lemma.
\end{proof}

Now we proceed the proof. Suppose that $\#X = n+1$, then $\#(X \setminus\{x'\}) = n$. By induction
hypothesis, $\#(Y^{X \setminus\{x'\}}) = m^n$.

By the lemma,
\[
\#Y^X = \#Y^{X\setminus\{x'\}\cup\{x'\}} = \#Y^{X\setminus\{x'\}} \times \#Y,
\]
which equals to $m^n \times m$.

Now we can close the induction.

We have proven that the cardinality of power sets obeys the definition of power. This ensures the
exercise.
\end{proof}

\declareexercise{3.6.5}
\begin{proof}
Let $f((x,y)):= (y,x), A\times B \rightarrow B \times A$. The bijectivity is obvious.

Now we are using set theory to prove the commutativity of multiplication of natural number. For any
natural number $m,n$, construct two sets: $M = \mathbb{N}_{m}, N = \mathbb{N}_{n}$. According to (e) in
Proposition 3.6.14, we have that $\#(M \times N) = \#M \times \#N$. Then by what we have just proven,
\[
\#(M \times N) = \#(N \times M) \Longrightarrow \#M \times \#N = \#N \times \#M \Longrightarrow mn = nm
\]
\end{proof}

\declareexercise{3.6.6}
\begin{proof}
Let $c \in C$, $f \in (A^B)^C$. Then $f(c)$ is a function $B\rightarrow A$. Let
$b \in B, h \in A^{B\times C}$. Let
\[
g:A^{B\times C} \rightarrow (A^B)^{C}
\]
be such a function that for all $b,c$,
\[
g(h) = f \equiv h(b,c) = (f(c))\,(b)
\]
. Now we show that $g$ is bijective.

Injectivity:
If $h \neq h'$, then $\exists b_0,c_0(h(b_0,c_0) \neq h'(b_0,c_0))$. Let $g(h) =f, g(h') = f'$. Then we
know that $(f(c_0))\,(b_0) \neq (f'(c_0))\,(b_0)$, so $f(c_0) \neq f'(c_0) \Longrightarrow f \neq f'$.
That means, $g(h) \neq g(h')$.

Surjectivity:
For any $f \in (A^B)^{C}$, let $h$ be such a function $\in A^{B\times C}$ that for all $b \in B,c \in C$,
$h(b,c) := (f(c))\,(b)$. It is easy to see that $h$ is well-defined. So $g(h) = f$.

Note that by Proposition 3.6.14 we have $\#M^N = m^n$ and $\#(M \times N) = mn$, where $\#M =m, \#N =n$.
Suppose that $\#A = a, \#B = b, \#C = c$, then
\[
\#(A^B)^C = (\#A^B)^{\#C} = (a^b)^c
\]
\[
\#A^{B\times C} = \#A^{\#(B \times C)} = a^{bc}
\]
So we have proven that $(a^b)^c = a^{bc}$.

Now we try to prove $a^b \times a^c = a^{b+c}$. Let $B,C$ be disjoint sets with the cardinality $b,c$
respectively. What we need to show is that
\[
\#(A^B \times A^C) = \#(A^{B \cup C}).
\]

Similarly, let
\[
f: (A^{B \cup C}) \rightarrow (A^B \times A^C)
\]
be such a function that
\[
f(g) = (u,v) \equiv \forall x(x \in B \Rightarrow g(x) = u(x) \wedge x \in C \Rightarrow g(x) = v(x)),
\]
where $g\in A^{B \cup C}, (u,v) \in A^B \times A^C$.

We can verify the bijectivity of $f$ nearly in the same way as way did previously. So I won't write it
down here.

Then, we know $B \cap C = \varnothing \Rightarrow \#(B \cup C) = \#B + \#C$. So we can conclude that
\[
a^b \times a^c = a^{b+c}
\]
\end{proof}

\declareexercise{3.6.7}
\begin{proof}
On one hand, if $\#A = a \leq \#B = b$, we show that $A$ has lesser or equal cardinalty to $B$. Let $f$
be a bijection from $A$ to $\mathbb{N}_{a}$, $g$ be a bijection from $B$ to $\mathbb{N}_b$. Let
$\iota(x):=x, \mathbb{N}_{a} \rightarrow \mathbb{N}_b$. Then $g^{-1} \circ \iota \circ f$ is an injection
from $A$ to $B$.

On the other hand, suppose that there is an injection $f$ from $A$ to $B$. We know that
$f:A\rightarrow f(A)$ is bijective. So $\#A = \#f(A)$. Since $f(A) \subseteq B$, $\#f(A) \leq B$ (See (c)
in Proposition 3.6.14). That is, $\#A \leq \#B$
\end{proof}

\declareexercise{3.6.8}
\begin{proof}
$f:A \rightarrow f(A)$ is bijective. So $f^{-1}: f(A) \rightarrow A$ is surjective. Let $g$ be defined as:
\begin{itemize}
\item $b \in f(A) \Longrightarrow g(b) = f^{-1}(b)$
\item $b \in B\setminus f(A) \Longrightarrow g(b)$ is any element of $A$.
\end{itemize}

Then $g$ is surjective.
\end{proof}

\declareexercise{3.6.9}
\begin{proof}
\begin{align*}
\#A + \#B
&= \#(A - A \cap B) + \#(A \cap B) + \#(B - A \cap B) + \#(A \cap B) \\
&= (\#(A - A \cap B) + \#(A \cap B) + \#(B - A \cap B)) + \#(A \cap B) \\
&= \#(A \cup B) + \#(A \cap B)
\end{align*}
\end{proof}

\paragraph{Exercise 3.6.10} \label{exercise3.6.10}
\begin{proof}
Presume the negation:
\[
\forall i(i \in \{1,\dots,n\} \Longrightarrow \#(A_i) < 2)
\]

Use mathematical induction for (b) in Proposition 3.6.14, we can easily get:
\[
\#\bigcup_{i \in \{1,\dots,n\}}A_i \leq \sum_{i \in \{1,\dots,n\}} \#A_i
\]
We can also use mathematical induction to furthermore enhance what we proved while dealing with natural
numbers to:
\[
\bigwedge_{i} a_{i} \leq b_{i} \Longrightarrow \sum_{i} a_{i} \leq \sum_{i} b_i
\].

Then because $\# A_i \leq 1$, so
\[
\sum_{i \in \{1,\dots,n\}} A_i \leq (\sum_{i \in \{1,\dots,n\}} 1 = n)
\],
which is impossible.
\end{proof}


\subsection{Quotient spaces}
\begin{defn}
Let $X$ be a topological space and $\sim$ an equivalence relation
on $X$. ($a\sim a$, $a\sim b\Leftrightarrow b\sim a,a\sim b,b\sim c,a\sim c$.)
Let $Y=X/\sim$ be the set of equivalence classes and define

\begin{align*}
\pi:X\to Y=X/\sim\\
\pi(x)=[x]=\text{equiv class of \ensuremath{X}under \ensuremath{\sim}}
\end{align*}

then the quotient space $Y=X/\sim$ has a \emph{quotient topology}
such that $V\subseteq X/\sim$ is open iff $\pi^{-1}(V)$ is open
in $X$.

Note: A continuous map $f:X\to Y$ is a \emph{quotient map} if $f$
is onto and $U\subset Y$ is open $\Leftrightarrow$ $f^{-1}(U)$
is open in $X$.
\end{defn}

\begin{thm}
$g:X/\sim\to Z$ is continuous $\Leftrightarrow$ $g\circ\pi:X\to Z$
is continuous.

\begin{align*}
\xymatrix{X\ar[r]^{g\circ\pi}\ar[d]_{\pi} & Z\\
X/\sim\ar[ur]_{g}
}
\end{align*}
\end{thm}
\begin{cor}
Let $f:X\to Z$ be a continuous map which is constant of equivalence
classes (if $u\sim v$ then $f(u)=f(v)$), then $f$ induces a unique
continuous map $\bar{f}:X/\sim\to Z$ such that $\bar{f}\circ\pi=f$.
\end{cor}
\begin{align*}
\xymatrix{X\ar[r]^{f}\ar[d]_{\pi} & Z\\
X/\sim\ar[ur]_{\bar{f}}
}
\end{align*}

Note: $\pi:X\to X/\sim$ is continuous, so if $X$ is compact or connected
or path connected, then so is $X/\sim$.
\begin{thm}
If $f:X\to Y$ continuous and onto, and\end{thm}
\begin{itemize}
\item $f$ is an open map, or
\item $f$ is a closed map
\end{itemize}
then $Y\approx X/\sim$ where $x\sim y\Leftrightarrow f(x)=f(y)\forall x,y\in X$.
\begin{defn}
Let $X,Y$ be topological spaces. Two continuous maps $f,g:X\to Y$
are \emph{homotopic} if there exists a continuous map $F:X\times I\to Y$
such that $F(x,0)=f(x)$ and $F(x,1)=g(x)$ for all $x\in X$. We
write $f\simeq g$ if $F$ exists, and say that $F$ is a homotopy
from $f$ to $g$.\end{defn}
\begin{thm}
Homotopy is an equivalence relation on the set of all continuous maps
$\{\text{cts maps}:X\to Y\}$ between spaces $X,Y$. I.e.\end{thm}
\begin{itemize}
\item $f\simeq f$
\item If $f\simeq g\implies g\simeq f$
\item If $f\simeq g$, $g\simeq h$, $\implies f\simeq h$.
\end{itemize}
Note: Let $X=A\cup B$, $A,B$ subspaces of $X$. Suppose $f:A\to Y$,
$g:B\to Y$ are continuous maps such that $f(x)=g(x)$ $\forall x\in A\cap B$.
Then define $h:A\cup B\to Y$ by

\begin{align*}
h(x) & =\begin{cases}
f(x) & x\in A\\
g(x) & x\in B
\end{cases}
\end{align*}

then $h$ is continuous if either
\begin{itemize}
\item $A,B$ are closed subsets
\item $A,B$ are open subsets\end{itemize}
\begin{defn}
Let $f,g:X\to Y$ be continuous maps which agree on $A$. Then $f\simeq g$
\emph{relative to $A$ }if there is a homotopy $F:f\to g$ which fixes
all points in $A$. I.e. we have $F:X\times I\to Y$ with $F(x,0)=f(x)$
$F(x,1)=g(x)$ and $\forall a\in A$ $F(a,t)=f(a)=g(a)$ $\forall t$.
\end{defn}

\begin{defn}
A continuous map $f:X\to Y$ is a \emph{homotopy equivalence} if there
exists a continuous map $g:Y\to X$ such that

\begin{align*}
g\circ f\simeq1_{X}:X\to X\\
f\circ g\simeq1_{y}:Y\to Y
\end{align*}

we say that $X$ and $Y$ are homotopy equivalent of there exists
such a map, and write $X\simeq Y$.
\end{defn}

\begin{defn}
A topological space $X$ is \emph{contractible} if the identity map
$\text{id}_{X}:X\to X$ is homotopic to a constant map $c:X\to X,c(x)=x_{0}$
for all $x\in X$.

Note/Exercise: $X$ contractible $\Leftrightarrow$ $X\simeq\{\text{pt}\}$.
\end{defn}

\begin{defn}
Given $A$ a subspace of $X$, a \emph{(strong) deformation retraction}
of $X$ onto $A$ is a homotopy rel $A$, $H:X\times I\to X$ such
that $H_{0}=1_{X}$, $H_{1}:X\to A$. Then we have $A\simeq X$.
\end{defn}

\begin{defn}
Let $\pi_{1}(X,x_{0})$ be a set of homotopy classes (rel endpoints)
of loops in $X$ based at $x_{0}$ (with a suitably defined product.)
This is the \emph{fundamental group of $X$ at $x_{0}$.}\end{defn}
\begin{thm}
If $X$ is path connected, then $\pi_{1}(X,x_{0})\cong\pi_{1}(X,x_{j})\forall x_{j}\in X$.
\marginpar{Maybe add in the picture?}
\end{thm}

\textbf{Effects of continuous maps}

Let $f:X\to Y$ be a continuous map. Then
\begin{itemize}
\item $\alpha$ a path in $X$ $\implies$ $f\circ\alpha=f\alpha$ is a
path in $Y$
\item $\alpha\sim\alpha'$ in $X\implies f\circ\alpha\sim f\circ\alpha'$
in $Y$.
\item $\alpha$ a loop at $x_{0}$ $\implies f\circ\alpha$ is a loop at
$f(x_{0})$. So there is a well-defined function $f_{*}:\pi_{1}(X,x_{0})\to\pi_{1}(F,f(x_{0}))$
given by $f_{*}([\alpha])=[f\circ\alpha]$.\end{itemize}
\begin{thm}
~\end{thm}
\begin{enumerate}
\item $f_{*}$ is a group homomorphism.
\item If $f=\text{identity}=1_{X}:X\to X$ then the induced map is the identity
map $f_{*}:\pi_{1}(X,x_{0})\to\pi_{1}(X,x_{0})$.
\item $(f\circ g)_{*}=f_{*}\circ g_{*}$.\end{enumerate}
\begin{cor}
If $f:X\to Y$ is a homeomorphism, then $f_{*}:\pi_{1}(X,x_{0})\to\pi_{1}(Y,f(x_{0}))$
is a group isomorphism. So the fundamental group is a topological
invariant.\end{cor}
\begin{thm}
Let $f,g:X\to Y$ be homotopic maps via a homotopy $F:X\times I\to Y$.
Let $\gamma:I\to Y$ be the path $\gamma(t):F(x_{0},t)$ traced out
by the basepoint $x_{0}$ under $F$ and let $y_{0}:y(0)=F(x_{0},0)$,
$y_{1}=y(1)=F(x_{0},1)$, then $g_{*}=\gamma_{*}\circ f_{*}$ where
$\gamma_{*}([\alpha])=[\gamma^{-1}*\alpha*\gamma]=\text{change of base point isomorphism}$,
i.e. the diagram

\begin{align*}
\xymatrix{\pi_{1}(X,x_{0})\ar[dr]_{g_{*}}\ar[r]^{f_{*}} & \pi_{1}(Y,y_{0})\ar[d]_{\gamma_{*}\cong}\\
 & \pi_{1}(Y,y_{1})
}
\end{align*}

commutes.

Note: If $F$ does not move the basepoint $x_{0}$ then $\gamma_{*}=\text{id}$
and $f_{*}=g_{*}$.\end{thm}
\begin{lem}
Let $G:I\times I\to Y$ be continuous and let $a,b:I\to I\times I$
be paths such that $a(0)=b(0)$ and $a(1)=b(1)$. Then $G\circ a\cong G\circ b$
rel endpoints.
\end{lem}
Application: If $f:X\to Y$ is a homotopy-equivalence then $f_{*}:\pi_{1}(X,x_{0})\to\pi_{1}(Y,f(x_{0}))$
is an ismorphism for all $x_{0}\in X$. So homotopically-equivalence
spaces has isomorphic fundamental groups.
\begin{defn}
$X$ is simply-connected if $X$ is path connected and $\pi_{1}(X,x_{0})\cong\{1\}$
for all $x_{0}\in X$.\end{defn}
\begin{lem}
If $X\simeq Y$ then $X$ is path connected iff $Y$ is path connected.\end{lem}
\begin{thm}
Let $p_{1}:X\times Y\to X$ and $p_{2}:X\times Y\to Y$ be projection
maps. Then $(p_{1*})\times(p_{2*}):\pi_{1}(X\times Y,(x_{0},y_{0}))\to\pi_{1}(X,x_{0})\times\pi_{1}(Y,y_{0})$
is an isomorphism. Explicitly

\begin{align*}
p_{1*}\times p_{2*}([\alpha]) & =([p_{1}\circ\alpha],[p_{2}\circ\alpha])
\end{align*}
\end{thm}
\begin{lem}
(Homotopy lemma) If $\alpha_{0},\alpha_{1}:I\to S^{1}$ are paths
such that $\alpha_{0}\simeq\alpha_{1}$ rel endpoints, then $\deg(\alpha_{0})=\deg(\alpha_{1})$.
(Where we defined the degree to be that ``distance moved upwards'',
i.e. $\tilde{\alpha}(1)$, where $\tilde{\alpha}$ is the lifted path. \end{lem}
\begin{thm}
(Fundamental theorem of algebra) Every non-constant polynomial with
complex coefficients has a complex zero.

Idea:\end{thm}
\begin{enumerate}
\item Let $f:B\to\mathbb{C}$ be continuous and defined on a closed 2-ball
$B\approx B^{2}$. Assume $f(z)\neq0$ on the boundary, i.e. $\forall z\in\partial B\approx S^{1}$.
Define $g:\partial B\to S^{1}$ by $g(z)=f(z)/|f(z)|$ (continuous).
Then If $g_{*}:\pi_{1}(\partial B)\cong\mathbb{Z}\to\pi_{1}(S^{1})\cong\mathbb{Z}$
is non-trivial $f$ has a zero inside $B$. (To prove this, try the
contrapositive.)
\item To prove FTA: Apply this result to $f(z)=z^{n}+a_{n-1}z^{n-1}+\cdots$
and $B$ a sufficiently large ball of radius $r$ around the origin.\end{enumerate}
\begin{thm}
Any homeomorphism $B^{2}\to B^{2}$ takes $\partial B^{2}=S^{1}$
to $S^{1}$. (Idea: Remove various points.)
\end{thm}


\documentclass[]{article}

\usepackage{amsmath}
\usepackage[backend=bibtex]{biblatex}
\addbibresource{main.bib}

%opening
\title{Multiple Disjunctively Constrained Knapsack Problem}
\author{Marco Favorito}
\date{}

\begin{document}

\maketitle

\begin{abstract}
In this document, we will present a problem, \emph{Multiple Disjunctively Constrained Knapsack Problem} (MDCKP), that is a combination of well-known problems: \emph{Multiple 0-1 Knapsack Problem} (MKP) and \emph{Disjunctively Constrained Knapsack Problem} (DCKP). Linear programming formulation is provided, as well as correlations with other Knapsack problem variants. Finally, we describe a (naive) algorithm.
\end{abstract}

\section{Introduction}

Multiple Disjunctively Constrained Knapsack Problem (MDCKP) is a combination of two Knapsack-like problems, namely:

\begin{itemize}
	\item Multiple 0-1 Knapsack Problem (MKP) \cite{Lagoudakis96the0-1, Martello:1990:KPA:98124};
	\item Disjunctively Constrained Knapsack Problem (DCKP) \cite{Senisuka_reductionand}
\end{itemize}

Informally, it is about how to assign $n$ items to $m$ knapsacks, each of them with limited capacity, in order to maximize the total profit of assigned items, where:
\begin{itemize}
	\item each item has a weight;
	\item there are some items that cannot be assigned to the same knapsack, due to intrinsic incompatibility.
\end{itemize}

\section{Linear Programming}
More formally, we have $n$ items, each of them with $p_1, \dots, p_n$ profits and $w_1, \dots, w_n$ weights.  Each of them can be assigned to only one of the $m$ knapsacks, which have capacities $c_1, \dots, c_m$. Let $E$ be the set of incompatible pairs, such that $(i, j)\in E$ iff items $i$ and $j$ are incompatible. To avoid duplicates, we define $E \subset \{(i, j) | 1 \le i \neq j \le n\}$ and assume $E$ to be a reflective relation.

Now follow a LP formulation of the problem:

\begin{align*}
\text{maximize }   & \sum_j^m \sum_i^n p_i x_{ij} 	&\\
\text{subject to } & \sum_i^n w_i x_{ij} \le c_j 	& j \in M = \{1, \dots m\}\\
				   & \sum_j^m x_{ij} \le 1 			& i \in N = \{1, \dots n\}\\
				   & x_{kj} + x_{hj} \le 1			& (k, h)\in E, j\in M\\
				   & x_{ij} \in \{0, 1\} 			& i \in N, j \in M\\
\end{align*}
where:

\begin{equation*}
x_{ij} = \begin{cases}
	1 & \text{if item $i$ is assigned to knapsack $j$} \\
	0 & \text{otherwise}
\end{cases}
\end{equation*}

Notice: with $E=\emptyset$ and $m=1$, the problem reduces to the classic 0-1 Knapsack problem. Hence, MDCKP is $\mathcal{NP}$-hard, since KP is $\mathcal{NP}$-hard too.

\section{Naive Approximation Algorithm}
The simplest approximation algorithm one can think of is the following:
\begin{itemize}
	\item sort the items by non-increasing profit per weight, that is:
	\begin{equation*}
		p_1/w_1 \ge p_2/w_2 \ge \dots \ge p_n/w_n
	\end{equation*}
	\item start to fill up the knapsacks and, if there is not enough capacity or there is some incompatibility with other items, then go to the next knapsack. If no knapsack is available, then leave the item out.
	\item perform some local search algorithm by defining the neighborhood of a solution as the following:

	\paragraph{} Look for a pair of items, one inside and the outer outside the knapsacks, and see if it is possible to exchange those items. If the exchange yields a better solution, swap the items.

\end{itemize}

\section{Implementation}
We provided an implementation of the approximation algorithm in C++.

The input file should have this format:
\begin{align*}
&n\ m								    \\
&c_1 \; c_2 \; \dots \; c_m			    \\
&p_1 \; w_1							    \\
& \vdots							    \\
&p_n \; w_n							    \\
& i \; j \; \;	(\forall (i,j)\in E)	\\
\end{align*}

Whereas the output file:

\begin{align*}
&\sum_j^m \sum_i^n p_i x_{ij}			\\
&x_{11} \; x_{21} \; \dots \; x_{n1}    \\
\vdots									\\
&x_{1m} \; x_{2m} \; \dots \; x_{nm}    \\
\end{align*}

\subsection{Example}

To build the solution:
\begin{verbatim}
mkdir build && cd build
cmake ..
make -j4
\end{verbatim}

To run the algorithm:
\begin{verbatim}
build/apps/mdckp-cli/mdckp-cli < input_file
\end{verbatim}

\printbibliography

\end{document}


\documentclass{amsart}

\usepackage{amssymb}
\usepackage{amsmath}

\title{Probability: Quiz 1}
\author{Mark Ditsworth}

\begin{document}
	\maketitle
	\section{Problem 1}
	Indicate  \textit{True} or \textit{False} for each claim.
	\subsection{Part A}
	If $\mathbf{P}(A) \leq \mathbf{P}(B)$, then $A \subseteq B$.\\
	\textbf{False}. Let $A$ and $B$ be independent, but $\mathbf{P}(A) \leq \mathbf{P}(B)$.
	\\
	\subsection{Part B}
	If $\mathbf{P}(B) > 0$, $\mathbf{P}(A|B)$ is at least as large as $\mathbf{P}(A)$.\\
	\textbf{False}. $\mathbf{P}(A)$ can decrease if it is dependent on $B$. For example, the probability of rain today ($\mathbf{P}(A)$) may historically be 35\%. But the probability of rain today given clear skies ($\mathbf{P}(A|B)$) is lower than $\mathbf{P}(A)$.\\
	\subsection{Part C}
	If $\mathbf{E}[X] > \mathbf{E}[Y]$, then $\mathbf{E}[X^2] > \mathbf{E}[Y^2]$.\\
	\textbf{False}. Let $X$ take the values 0 and 1 with equal probability, and $Y$ take the values -4 and -2 with equal probability. $\mathbf{E}[X]=0.5 > \mathbf{E}[Y] = -3$. But $\mathbf{E}[X^2]=0.5 < \mathbf{E}[Y^2] = 10$.\\
	\subsection{Part D}
	Suppose $\mathbf{P}(A) > 0$. Then $\mathbf{E}[X] = \mathbf{E}[X|A]+ \mathbf{E}[X|A^C]$.\\
	\textbf{False}. Assume $X$ is independent of $A$. Then $\mathbf{E}[X]=\mathbf{E}[X|A]= \mathbf{E}[X|A^C]$, so $\mathbf{E}[X|A]+ \mathbf{E}[X|A^C] = 2\mathbf{E}[X]$.\\
	\subsection{Part E}
	If $X$ and $Y$ are independent and $\mathbf{P}(C)>0$, then $p_{X,Y|C}(x,y) = p_{X|C}(x)p_{Y|C}(y)$.\\
	\textbf{False}. Independence between $X$ and $Y$ does not guarantee conditional independence.\\
	\subsection{Part F}
	If for some constant $c$, we have $\mathbf{P}(\{X>c\})=\frac{1}{2}$, then $\mathbf{E}[X]>\frac{c}{2}$.\\
	\textbf{False}. Let $X$ take the values between -1 and 1, uniformly. $\mathbf{P}(\{X>0\})=\frac{1}{2}$, and $\mathbf{E}[X] = 0 \ngtr \frac{0}{2}$.\\
	\subsection{Part G}
	In a game involving the flip of a fair coin, you win a dollar for each head flipped. The maximum number of flips is 10, but the game ends when you flip a tail. The expected gain from this game is 1.\\
	\textbf{False}. $\mathbf{E}[g(X)] = \sum g(x) p_X(x) =
	\sum_{k=0}^{9}\left(k(0.5)^{k+1}\right) + (0.5)^{10} = 0.99902$.\\
	\subsection{Part H}
	Let $X$ be a uniformly distributed continuous random variable over some interval $[a,b]$. We can uniquely describe $f_X(x)$ from knowing its mean and variance.\\
	\textbf{True}. For a uniform distribution, $\mathbf{E}[X]=\frac{a+b}{2}$ and $\sigma_X^2 = \frac{(b-a)^2}{12}$. Two equations and two unknowns result in a solvable system of equations for $a$ and $b$.\\
	\subsection{Part I}
	Let $X$ be an exponentially distributed random variable with a probability density function $f_X(x)= e^{-x}$. $P\left(\{0 \leq X \leq 3\} \cup \{2 \leq X\leq 4\}\right) = 1-e^{-4}$.\\
	\textbf{True}. $P\left(\{0 \leq X \leq 3\} \cup \{2 \leq X\leq 4\}\right) = \int_{0}^{4}e^{-x}  dx = 1-e^{-4}$.\\
	\subsection{Part J}
	Let $X$ be a normal random variable with mean 1 and variance 2. Let $Y$ be a normal random variable with mean 1 and variance 1. $\mathbf{P}(X<0) < \mathbf{P}(Y<0)$.\\
	\textbf{False}. Since $X$ has a larger variance than $Y$ its tails are thicker, thus the integral over the left tail will be greater for $X$ and $Y$.
	\pagebreak
	\section{Problem 2}
	Marketing Team A has found that 1/4 of their customers are low-frequency buyers. But out of their low-frequency buyers, 1/3 are high spenders, whereas 1/10 of their high-frequency buyers are high spenders. Assume that each customer is either low-frequency or high frequency, and low spender of high spender.\\
	\subsection{Part A}
	Compute the probability that a randomly chosen customer is a high spender.\\
	$\mathbf{P}(HS)=\mathbf{P}(HFB)\mathbf{P}(HS|HFB)+\mathbf{P}(LFB)\mathbf{P}(HS|LFB)=\frac{1}{4}\frac{1}{3}+\frac{3}{4}\frac{1}{10} = \frac{19}{120}$.\\
	\subsection{Part B}
	Compute the probability that a randomly chosen customer is a high-frequency buyer given that they are a low spender.\\
	$\mathbf{P}(HFB|LS) = \frac{\mathbf{P}(HFB)\mathbf{P}(LS|HFB)}{\mathbf{P}(LS)} = \frac{\frac{3}{4}\frac{9}{10}}{1-\frac{19}{120}}=\frac{81}{101}$\\\\
	You are told that the only products sold are books (B), CDs (CD), and DVDs (DVD). Marketing team B has found three customer groups $C_1$, $C_2$, $C_3$. These groups are collectively exhaustive and mutually exclusive. Each customer is equally likely to be in any group, and customers are \textit{i.i.d.}. Each customer only buys one item per day. Marketing team B has determined the following purhcasing conditional probabilities:\\
	\begin{table}[h!]
		\centering
		\begin{tabular}{rcl}
			$\mathbf{P}(B|C_1)$&=&$\frac{1}{2}$\\
			$\mathbf{P}(CD|C_1)$&=&$\frac{1}{4}$\\
			$\mathbf{P}(DVD|C_1)$&=&$\frac{1}{4}$\\
			$\mathbf{P}(B|C_2)$&=&$\frac{1}{2}$\\
			$\mathbf{P}(CD|C_2)$&=&$0$\\
			$\mathbf{P}(DVD|C_2)$&=&$\frac{1}{2}$\\
			$\mathbf{P}(B|C_3)$&=&$\frac{1}{3}$\\
			$\mathbf{P}(CD|C_3)$&=&$\frac{1}{3}$\\
			$\mathbf{P}(DVD|C_3)$&=&$\frac{1}{3}$
		\end{tabular}
	\end{table}
	\subsection{Part C}
	Compute the probability that a customer purchases a book or CD.\\
	Since $C_1$, $C_2$, and $C_3$ are mutually exclusive and customers are \textit{i.i.d.},\\
	$\mathbf{P}(B\cup CD) = \mathbf{P}(B) + \mathbf{P}(CD)$\\
	$\mathbf{P}(B) = \sum_{i=1}^{3} \mathbf{P}(C_i)\mathbf{P}(B|C_i) = \frac{1}{6} + \frac{1}{6} + \frac{1}{9} = \frac{4}{9}$\\
	$\mathbf{P}(CD) = \sum_{i=1}^{3} \mathbf{P}(C_i)\mathbf{P}(CD|C_i) = \frac{1}{12} + 0 + \frac{1}{9} = \frac{7}{36}$\\
	$\mathbf{P}(B\cup CD) = \frac{4}{9} + \frac{7}{36} = \frac{23}{36} \approx 0.6389$\\
	\subsection{Part D}
	Compute the probability that a customer is in group $C_2$ or $C_3$ given they purchased a book.\\
	$\mathbf{P}(C_2 \cup C_3 | B) = \frac{\mathbf{P}(C_2 \cup C_3) \mathbf{P}(B|C_2 \cup C_3)}{\mathbf{P}(B)}=
	\frac{\mathbf{P}(B \cap (C_2 \cup C_3))}{\mathbf{P}(B)} = \frac{\mathbf{P}(B \cap C_2) + \mathbf{P}(B \cap C_3)}{\mathbf{P}(B)} = \frac{5}{8}$\\
	\\
	Each book costs \$15, each CD costs \$10, and each DVD costs \$15.
	\subsection{Part E}
	Compute the PDF, expected value, and variance of the revenue ($R$) collected by a single customer's purchase.
	\\
	$\mathbf{P}(R=\text{\$10})=\mathbf{P}(CD) = \frac{7}{36}$\\
	$\mathbf{P}(R=\text{\$15})=\mathbf{P}(B)+\mathbf{P}(DVD) = \frac{4}{9}+\frac{13}{36}$\\
	\[
	p_R(r) =
	\begin{cases}
		\frac{7}{36} & r = \$10\\
		\frac{29}{36} & r = \$15\\
		0 & \text{otherwise}
	\end{cases}
	\]\\
	$\mathbf{E}[R] = \sum r \cdot p_R(r) = 10(\frac{7}{36}) + 15(\frac{29}{36}) = \$14.03$\\\\
	$\text{Var}(R) = \sum (r-\textbf{E}[R])^2 \cdot p_R(r) \approx 3.9159$\\
	\subsection{Part F}
	If the store gets $n$ customers in a day, what is the total expected revenue and variance?\\
	$\text{Total Revenue}~ TR = nR$\\
	$\mathbf{E}[TR] = \mathbf{E}[nR] = n\mathbf{R} = n\cdot\$14.03$\\\\
	$\text{Var}(nR) = n^2\text{Var}(R) = n^2\cdot \$3.9159$\\
	\subsection{Part G}
	Skip is an abnormal customer. When he goes to the store, he flips a fair coin until he gets his seconds tails. The number of heads that have been flipped is the number of DVDs he buys. What is the expected dollar amount he spends and the variance?\\
	\\
	This process follows the $k$th arrival time process, modeled by the pascal distribution. Each time Skip flips his coin, he has a 50\% probability of getting tails. We want to know the expected number of flips it takes to get his second tails. The number of heads is 2 less than this number since 2 of them are the 2 arrivals of tails.
	\\\\
	$\text{For pascal},~\mathbf{E}[Y_k] = \frac{k}{p}$\\
	\\
	$\mathbf{E}[Y_2] = \frac{2}{0.5} = 4$\\
	Thus, the expected number of heads is 2, resulting in an expected revenue of \$30.
	\\\\
	$\text{For pascal},~\text{Var}[Y_k] = \frac{k(1-p)}{p^2}$\\
	\\
	$\text{Var}(Y_2) = \frac{2(1-0.5)}{0.5^2}=4$\\
	$\text{Var}(R) = \text{Var}(\$15\cdot Y_2) = \$15^2\text{Var}(Y_2) = \$900$
	\pagebreak
	\section{Problem 3}
	We have $s$ urns and $n$ balls ($n \geq s$). Each ball is placed in an urn at random. Each ball has equal probability of being placed in any urn, and it's placement is independent of the other ball placements. Each urn can fit any number of balls.\\
	Define the following random variables:\\\\
	Let $X_i$ be the number of balls in urn $i$.\\
	Let $Y_k$ be the number of urns that have exactly $k$ balls.\\
	\subsection{Part A}
	Are the $X_i$'s independent? Why or why not?\\
	\textbf{They are not independent.}  Without loss of generality, if $X_1=j$, then $X_2$ through $X_s$ can be at most $n-j$.\\
	\subsection{Part B}
	Find the PMF, mean, and variance of $X_i$.\\
	\\
	If there are $k$ balls in urn $i$, there must have been $k$ occurrences of successful placement, and $n-k$ occurrences of unsuccessful placement: $p^k(1-p)^{(n-k)}$. Since the order in which the $k$ balls are placed in urn $i$ does not matter, there are $\binom{n}{k}$ possible combinations of this placement. Since urn placement is equally distributed, the probability of placement in urn $i$ is $\frac{1}{s}$. Thus, the PMF is:
	\[
		p_{X_{i}}(k) = \left(\frac{1}{s}\right)^k \left(1-\frac{1}{s}\right)^{(n-k)}\binom{n}{k}
	\]\\
	\\
	This PMF is the binomial distribution. Thus, the mean is:\\
	\[
		\textbf{E}(X_i) = np = \frac{n}{s}
	\]\\
	and the variance is:\\
	\[
		\text{Var}(X_i) = np(1-p) = \frac{n}{s}\left(1-\frac{1}{s}\right)
	\]\\
	\\
	\subsection{Part C}
	Assume $n=10$ and $s=3$. Find the probability that the first urn has 3 balls, the second has 2, and the third has 5.\\
	\\
	The number of combinations of dividing the 10 balls into partitions of 3, 2, and 5 is $\binom{10}{3,2,5}$. The total number of ways to divide 10 balls among the 3 urns is $3^{10}$. Thus, the probability is $\frac{\binom{10}{3,2,5}}{3^{10}} \approx 0.0427$.\\
	\\
	\subsection{Part D}
	Compute \textbf{E}[$Y_k$].\\
	\\
	Recall that $Y_k$ is the number of urns that have exactly $k$ balls. Define:\\
	\[
		I_i=
		\begin{cases}
			1 & \text{urn } i \text{ has } k \text{ balls}\\
			0 & \text{otherwise}
		\end{cases}
	\]
	Now we can write $Y_k = \sum_{i=1}^{s} I_i$. Due to linearity, $\textbf{E}[Y_k] = \textbf{E}\left[\sum_{i=1}^{s}\right] =\sum_{i=1}^{s} \textbf{E}[I_i]$.\\
	\\
	$\textbf{E}[I_i]$ is just the probability that urn $i$ has $k$ balls, $p_{X_i}(k)$, which is known from Part B. Thus,
	\[
		\textbf{E}[Y_k] = \sum_{i=1}^{s} \left(\frac{1}{s}\right)^k\left(1-\frac{1}{s}\right)^{(n-k)}\binom{n}{k} = s \left(\frac{1}{s}\right)^k\left(1-\frac{1}{s}\right)^{(n-k)}\binom{n}{k}
	\]
	\\
	\subsection{Part E}
	Compute Var($Y_k$).\\
	\\
	Var($Y_k$)$= \textbf{E}[Y_k^2] - \textbf{E}[Y_k]^2$. The second term is known from Part D. Thus, we need to find $\textbf{E}[Y_k^2]$.\\
	\[
		\textbf{E}[Y_k^2] = \textbf{E}\left[\left( \sum_{i=1}^{s}I_i\right)^2\right]
		=
		\textbf{E}\left[
		\sum_{i=1}^{s}I_i^2\right] + 2\textbf{E}\left[ \sum_{i=1}^{s-1}\sum_{j=i+1}^{s}I_iI_j
		\right]
	\]\\
	Since $I_i$ is either 0 or 1, $I_i^2 = I_i$. Thus,
	$\textbf{E}\left[\sum_{i=1}^{s}I_i^2\right] = \textbf{E}\left[\sum_{i=1}^{s}I_i\right] = \textbf{E}[Y_k]$, which is known from Part D. We now need to find $\textbf{E}\left[\sum_{i=1}^{s-1}\sum_{j=i+1}^{s}I_iI_j
	\right]$ to be done.\\
	\\
	$\textbf{E}\left[\sum_{i=1}^{s-1}\sum_{j=i+1}^{s}I_iI_j
	\right] = \sum_{i=1}^{s-1}\sum_{j=i+1}^{s}\textbf{E}\left[I_iI_j
	\right]$\\\\
	$\textbf{E}\left[I_iI_j\right]$ is the probability that $X_i$ and $X_j$ both equal $k$. This is $2k$ successful placements and $n-2k$ unsuccessful placements. The number of combinations of these placements is the number of ways to partition the $n$ balls into 2 sets of size $k$ and a third set of size $n-2k$. Thus this probability is $\binom{n}{k,k,n-2k}\left(\frac{1}{s}\right)^{2k}\left(1-\frac{1}{s}\right)^{n-2k}$.\\
	\\
	Putting it all together:
	\[
	\text{Var}(Y_k) = s \left(\frac{1}{s}\right)^k\left(1-\frac{1}{s}\right)^{(n-k)}\binom{n}{k} +
	(s)(s-1)\binom{n}{k,k,n-2k}\left(\frac{1}{s}\right)^{2k}\left(1-\frac{1}{s}\right)^{n-2k}\]
	\[-\left(s \left(\frac{1}{s}\right)^k\left(1-\frac{1}{s}\right)^{(n-k)}\binom{n}{k}
	\right)^2
	\]

\end{document}


\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\title{The Factorization Problem\\In\\Computational Group Theory}
\author{Spencer T. Parkin}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{definition}{Definition}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{identity}{Identity}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{result}{Result}[section]

\newcommand{\stab}{\mbox{stab}}

\begin{document}
\maketitle

\section*{The Problem And Solution}

For any given element $g$ of a finite permutation group $G$ generated
by a set of permutation $S$, we wish to factor $g^{-1}$ in terms of $S$.
Since $g\in G=\langle S\rangle$, it is clear that for some positive integer $k$, there exists
a sequence of $k$ elements $\{s_i\}_{i=1}^k$ taken from $S$ such that
\begin{equation*}
g = s_1s_2\dots s_k,
\end{equation*}
and therefore,
\begin{equation*}
g^{-1} = s_k^{-1}s_{k-1}^{-1}\dots s_1^{-1}.
\end{equation*}
Indeed, there may be many such sequences.
How we might come up with such a sequence, however, is not immediately clear.
Our goal is to come up with a systematic way of producing such a sequence, even if it
is not of minimal length.

Associated with our group $G$ is a set $\Omega$ over which each $g\in G$ is defined.
That each $g$ is a permutation of this set $\Omega$ is to say that $g$ is a one-to-one and onto
mapping from $\Omega$ to $\Omega$.
For a given $\omega\in\Omega$,
we define the stabilizer subgroup of $G$ with respect to $\omega$ as
\begin{equation*}
\stab_{\omega}(G) = \{g\in G|g(\omega)=\omega\}.
\end{equation*}
This is the set of all permutation of $g$ that stabilize $\omega$.  It is not hard to show
that this is a subgroup of $G$.  Furthermore, it is a normal subgroup of $G$.
For any $h\in\stab_{\omega}(G)$,
and any $g\in G$, we have
\begin{equation*}
g(h(g^{-1}(\omega))) = g(g^{-1}(\omega)) = \omega.
\end{equation*}
EDIT: WRONG!!!!!!  You moron!!!

Being normal, we can consider the factor group
\begin{equation*}
G/H = \{gH|g\in G\},
\end{equation*}
where $H=\stab_{\omega}(G)$.  We now make the observation that since $S$
generates $G$, we must have $SH=\{sH|s\in S\}$ generating $G/H$.  To see this, we write
the typical element of $G/H$ as
\begin{equation*}
gH = \left(\prod_{i=1}^k s_i\right)H = \prod_{i=1}^k (s_iH).
\end{equation*}

We now let $R$ be a set of coset representatives for $G/H$, and $[\cdot]:G\to R$ a function
mapping any element of $g$ to the coset representative in $R$ representing the coset in $G/H$ that contains $g$.
That is, $|R|=|G|/|H|=|G/H|$, and $G/H=\{rH|r\in R\}$, and for all $g\in G$, $gH=[g]H$ with $[g]\in R$.
Computationally, coming up with $R$ is really just the same problem as generating $G/H$ as we would simply use
coset representatives to represent each coset of $G/H$ anyway.  An implementation of $[g]$ might,
for each $r\in R$, check whether $g^{-1}r\in H$.

Armed with all this, and letting $g$ be any element of $G$, we're now going to begin to address our original
question by finding an element $q$ in terms of the generators of $S$ such that $gq\in H$.  Clearly, a procedure
for such a thing is recursively applicable, for $H$ is simply a permutation group associated with $\Omega-\{\omega\}$,
bringing us one step closer to the trivial group $\{e\}$.  The trick is that at each step, we must keep track of all new
generators in terms of the original generators in $S$.

So how do we go about finding $q$?  Well, if $g\in H$ (i.e., $g(\omega)=\omega$), then $q=e=ss^{-1}$ for any $s\in S$,
and we're done.  If not, consider $q=[g]^{-1}$.  Clearly $g[g]^{-1}\in H$, since $gH=[g]H$, and furthermore,
we know the factorization of $[g]^{-1}$ in terms of the generators in $S$, because we know such a factorization
for $[g]\in R$ by virtue of how we generated $R$ from $S$.

We are now almost there!  All that remains is our ability to continue this process in $H$ with $gq\in H$ and a stabilizer
subgroup of $H$ with respect to some element in $\Omega-\{\omega\}$.  For that, we need a generating set for $H$,
and this is where Schreier's Lemma comes into play.  According to Schreier, this set of generators is given by
\begin{equation*}
\{rs[rs]^{-1}|r\in R, s\in S\},
\end{equation*}
provided $e\in R$.
Note that computationally, while we might boil each generator down to its permutation $g\in G$, we would need
to keep its expression (or ``word'') in terms of our original generators in $S$.

So there we have it!  In closing, it might be worth considering why the algorithm thus described does
better than the most obvious, naive and impractical approach to solving the factorization problem, which is to
simply generate all of $G$ from $S$, then search for $g^{-1}$ in $G$.  To begin, $|G|$ may be
extremely large, making its complete generation take too long and require too much memory.
That being said, the stabilizer-chain approach may have its own, similar problems.  For a group $G$
of large order, how big is the order of a factor group likely to get?  How big is a set of generators
likely to get?  I'll have to give it a try.  I believe it can also be shown that this method does not
produce solution sequences anywhere near minimal length.

\section*{Generating Groups}

For a finite group $G=\langle S\rangle$, how do we go about generating all elements of $G$ using that of $S$?
Letting $G=\{e\}$, we proceed until $S$ is empty.  Remove $s$ from $S$ and then, for each $g\in G$,
add $gs$ or $sg$ to $S$ if they're not found in $G$ or $S$, then add $s$ to $G$.

Clearly this algorithm will terminate, but is it correct?  As elements are added to $G$, keep them in order so
that in the end, we have $G$ as an array of elements showing the order that they were added.  Then for any $g\in G$,
we know that $G$ also contains $rg$ and $gr$ for every $r\in G$ left of $g$.  We also know that this is true for
all $r\in G$ right of $g$.  In fine, we should have closure in $G$.  Now since $G$ is a finite subset of a larger group (since
the original $S$ was a subset of that larger group),
it must be a subgroup of that group.  Lastly, can we claim that $G$ is the smallest group containing all original elements of $S$?
Well, since we never added any elements to $G$ unnecessarily, I would have to think so.

This line of reasoning is not terribly rigorous, but it is the best I can come up with for now.

% Maybe note a recursive algorithm for generating a group in the case that it is abelian.
% In that case, all subgroups are normal.  If H is a subgroup of such a G, and g is in G-H,
% Then <gH> is the smallest subgroup of G containing g and H.

\end{document}


\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\title{Mathematical software - homework 1}
\author{Sebastiano Tronto}

\newtheorem{thm}{Theorem}
\newtheorem{prop}[thm]{Proposition}

\theoremstyle{definition}
\newtheorem{ex}{Exercise}

\theoremstyle{definition}
\newtheorem*{remark}{Remark}

\begin{document}

\noindent\hrulefill

\begin{center}
\Huge{\textbf{Mathematical Software - Homework 1}}
\end{center}

\noindent\hrulefill
\begin{center}
\begin{tabular}{lcr}
\texttt{sebastiano.tronto@uni.lu} & \qquad \qquad \qquad \qquad &
\textbf{Deadline: Sunday, March 28th}
\end{tabular}
\end{center}

\vspace{1cm}

\begin{center}
  \emph{\large
    For each of the following exercises submit a .tex and a .pdf file.
  }
\end{center}

\vspace{1cm}

\begin{ex}
  Write a short Latex document that contains the following theorem-like
  environments using the \texttt{\textbackslash newtheorem} command of the
  \texttt{amsthm} package (the box around the text is not needed):
  \begin{center}
    \fbox{\parbox{0.95\textwidth}{
      \begin{prop}[Fundamental Theorem of Algebra]
        \label{prop:fta}
        Let \(p(x)\) be a non-constant polynomial with coefficients in
        $\mathbb C$. Then there is \(z\in\mathbb C\) such that $p(z)=0$.
      \end{prop}

      \begin{remark}
        Proposition \ref{prop:fta} is not true for polynomials with
        coefficients in $\mathbb R$. For example
        \begin{align}
          p(x) = x^2+1
        \end{align}
        does not have real roots.
      \end{remark}

      \begin{thm}
        If $X$ and $Y$ are $\sigma$-finite measure spaces and $f:X\times Y\to
        \mathbb R$ is measurable and such that
        \begin{align*}
          \int_{X\times Y}|f(x,y)|\mathrm d(x,y) < \infty
        \end{align*}
        then
        \begin{align}
          \label{eq:fubini}
          \int_X\left(\int_Yf(x,y)\mathrm d y\right)\mathrm d x =
          \int_Y\left(\int_Xf(x,y)\mathrm d x\right)\mathrm d y =
          \int_{X\times Y} f(x,y)\mathrm d(x,y)\,.
        \end{align}
      \end{thm}

      \begin{remark}
        In practice, equation \eqref{eq:fubini} means that we can switch the
        order of integration in a double integral.
      \end{remark}
    }}
  \end{center}
  Notice that Propositions, Theorems and some of the equations are numbered,
  and some of them are referred to in the Remarks. This numbering should change
  accordingly if more numbered Theorems and equations are added before this
  part of the text.
\end{ex}

\vspace{0.8cm}

\begin{ex}
[This is basically a ``do whatever you want, just do something'' exercise]
Write a Mathematical document in Latex, where ``Mathematical'' means any text
that contains both inline and displaystyle symbols and formulas, and where most
of the sentences contain a Mathematical symbol.
For example, you can submit (part of) your homework or notes for another course
that you are following at the moment.

You must follow the following rules:
\begin{itemize}
  \item Your document must be at least 2 pages long.
  \item Use the following in your preamble:
    \begin{verbatim}
\documentaclass[12pt,a4paper]{article}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
    \end{verbatim}
\end{itemize}
The document itself can be about any area of Mathematics, Physics or similar.
The correctness of the Mathematics itself will not be judged for this course.
\end{ex}

\section*{Grading}

This homework assignment is worth 25\% of your final grade.

\vspace{0.3cm}
\textbf{Exercise 1 (10 points).}
\begin{itemize}
  \item A correct use of the \texttt{\textbackslash newtheorem} command is
        worth 4 out of 10 points.
  \item A correct use of the labelling and reference system is worth 4 points.
  \item Reproducing correctly the mathematical formulas is worth 2 points.
\end{itemize}

\textbf{Exercise 2 (10 points).}
\begin{itemize}
  \item A resulting pdf file that looks readable and correct is worth 6 out of
        10 points.
  \item The correct use of latex commands and environments is worth 4 out of
        10 points. \emph{Examples of mistakes in this sense: adjusting manually
        the size of parenthesis instead of using \texttt{\textbackslash left}
        and \texttt{\textbackslash right}; using \texttt{\textbackslash Sigma}
        when you actually want to write a sum symbol.}
\end{itemize}

\end{document}


\documentclass[letter,10pt]{article}

\usepackage{amsmath}
%\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
%\usepackage[ngerman,english]{babel}
%\usepackage{hyperref}
%\usepackage{graphicx}
%\usepackage{listings}
%\usepackage{adjustbox}
%\usepackage[affil-it]{authblk}
%\usepackage[T1]{fontenc}
%\usepackage{lmodern}
%\usepackage[space]{grffile}
\usepackage{hyperref}

\begin{document}

\section*{Note on Analog-to-Digital Converter (ADC)}

``What does the ADC output mean? What are those big numbers?''

\subsection*{Resolution}
An ADC linearly maps an input voltage to a range of numbers. The ADC we use has a 5V reference and is a 10-bit ADC, so it maps an input voltage between 0 and 5V to a number between 0 to $2^{10} - 1$:
\begin{equation}
ADC = V_{input} / V_{ref} * 2^{10} = V_{input} / 5V * 1024
\end{equation}
(Reality is a bit more complicated than that. Divide by 1023 or 1024, which is correct? Or does it matter?)\\
\\
For example, if the ADC outputs 365, then the voltage of the input is
\begin{equation}
\frac{365}{1024}*5V = 1.78V
\end{equation}
You should verify this with a voltmeter. Also try to verify that the reference voltage is indeed (not exactly) 5V. How does that affect your measurement?

\end{document}