% This is a TeX file
% It is essentially a programming language for mathematics documents
% You can ignore this first portion of the file, as it is essentially a bunch of "include" statements.
\documentclass[10pt]{article}

\usepackage{pictex, latexsym, graphicx,amsmath,amssymb,amsbsy,amsfonts,amsthm,verbatim}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage{fancyhdr}
\usepackage{array}

\usepackage{algorithm,algorithmic}
\usepackage{multirow}

\setlength{\parskip}{0.5em}
\setlength{\parindent}{0em}
\setlength{\voffset}{-0.5in}
\setlength{\headsep}{0.25in}

% The following denotes a counter for the problems.
\newcounter{problem}
\newcommand{\problem}{\textbf{Problem \refstepcounter{problem}.}}

% These are macro shortcuts! Helpful!
\def\vu{\mathbf{u}}
\def\vx{\mathbf{x}}
\def\vb{\mathbf{b}}
\def\vv{\mathbf{v}}
\def\vw{\mathbf{w}}

\renewcommand{\implies}{\rightarrow}
%\newcommand{\lnot}{\neg}
\renewcommand{\lor}{\vee}
\renewcommand{\land}{\wedge}
\newcommand{\xor}{\oplus}
\newcommand{\symmdiff}{\triangle}
\renewcommand{\iff}{\leftrightarrow}
\newcommand{\TRUE}{\mathbf{T}}
\newcommand{\FALSE}{\mathbf{F}}
\newcommand{\universe}{\mathcal{U}}


\def\N{\mathbb{N}}
\def\Q{\mathbb{Q}}
\def\C{\mathbb{C}}
\def\Z{\mathbb{Z}}
\def\R{\mathbb{R}}
\def\cP{\mathcal{P}}



\begin{document}
\pagestyle{fancyplain}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOW you can start typing your text that will appear in the PDF!!!

% Note that anything after a '%' is a comment!

% Anything immediately after a '\' is a command. 
% Some denote formatting, some are for special characters.
% The '$' symbol starts and ends "math mode". Use this only for mathematical statements
% In math mode, any sequence of letters is meant to be a list of variables, so use "\sin x" for the sine of x, which will look much different from "sin x"

\lhead{}
\rhead{}
\chead{COM S 330 --- Lecture Notes --- Week of Feb 2--6}

\renewcommand{\arraystretch}{1.25}



\section{Monday, February 2}

\subsection{Rosen 2.1 -- Sets}

\textbf{Reading:} Rosen 2.1. LLM 4.1. Ducks 2.1, 2.2.


\textbf{Def:} A \emph{set} is an unordered collection of objects, called \emph{elements} or \emph{members} of the set.
A set is said to \emph{contain} its elements.
We write $a \in A$ to denote that $a$ is an element of the set $A$.
We write $a \notin A$ to denote that $a$ is not an element of the set $A$.

A set can be described by listing its entries between curly braces: $A = \{ a, b, c, d\}$ (the \emph{roster method}).

A set can be defined using propositional logic, where the set contains all elements that satisfy the propositional function: $A = \{ x : P(x)\text{ is true } \}$. (Some use colon, some use vertical bar. Both are accepted, but I like the colon.)

\textbf{Ex:} 

\textbf{Def:} $\N$, $\Z$, $\Z^+$, $\Q$, $\R$, $\R^+$, $\C$.

\textbf{Def:} Intervals $[a,b]$, $[a,b)$, $(a,b]$, $(a,b)$.

\textbf{Ex:} $\{ \N, \Q, \Z, \R, \C\}$

\textbf{Def:} Set are \emph{equal} if they contain the same elements.

\textbf{Def:} Empty set $\varnothing$, \emph{singleton set}.

\textbf{Note:} We say elements are ``objects'' without defining ``object.'' This is on purpose: a formal definition is outside the scope of this class. In the current definition, (and almost all definitions of set theory) we can find \emph{paradoxes}.



\subsection{Subsets}

\textbf{Def:} Let $A$ and $B$ be sets. $A$ is a \emph{subset} of $B$, denoted $A \subseteq B$, if every element of $A$ is an element of $B$. (If $A$ and $B$ are also not equal, then we use $A \subset B$.)

\textbf{Ex:} $A = \{ 1, 2, 3\}$, $B = \{1,2,3,4,5\}$, $C = \{1, 3, 5\}$.

To show that $A$ is a subset of $B$, you demonstrate $\forall x, (x \in A) \implies (x \in B)$.

To show that $A$ is \emph{not} a subset of $B$, you demonstrate $\exists x, (x \in A) \land (x \notin B)$.

\textbf{Thm:} For every set $S$, $\varnothing \subseteq S$ and $S \subseteq S$.

To show that $A$ and $B$ are equal, you demonstrate $A \subseteq B$ and $B \subseteq A$.

\textbf{Def:} Let $S$ be a set. If there are exactly $n$ distinct elements of $S$, then $S$ is a \emph{finite set} and $n$ is the \emph{cardinality} of $S$, denoted $|S|$. (If $S$ has an infinite number of elements, then we say $|S| = \infty$.)


\textbf{Def:} If $S$ is a set, then the \emph{power set} of $S$, denoted $\cP(S)$ or $2^S$, is the set of subsets of $S$.


\subsection{Cartesian Products}

\textbf{Def:} An \emph{ordered $n$-tuple} $(a_1,a_2,\dots,a_n)$ is the ordered collection that has $a_1$ as its first element, $a_2$ as its second element, and so on until $a_n$ the $n$th element.

2-tuples are called \emph{ordered pairs}.

\textbf{Def:} If $A$ and $B$ are sets, then the \emph{cartesian product} of $A$ and $B$, denoted $A \times B$, is the set of ordered pairs $(a,b)$ where the first element $a$ is an element of $A$ and the second element $b$ is an element of $B$.
\[
	A \times B = \{ (a,b) : a\in A \land b \in B\}.
\]	


\textbf{Def:} If $A_1,\dots,A_n$ are sets, then the \emph{cartesian product} of $A_1,\dots,A_n$, denoted $A_1 \times A_2 \times \cdots \times A_n$ or $\prod_{i=1}^n A_i$, is the set of $n$-tuples $(a_1,a_2,\dots,a_n)$ where for all $i$ with $1 \leq i \leq n$, the $i$th element $a_i$ is an element of $A_i$.
\[
\prod_{i=1}^n A_i = A_1 \times A_2 \times \cdot \times A_n = \{ (a_1,a_2,\dots,a_n) : \forall i \in \{1,\dots,n\} a_i \in A_i\}.
\]


\subsubsection{Suggested Homework}

Rosen 2.1: 1,3--8,9--11,  14--17, 18--24, 25$^*$, 26--30, 35--37, 46$^*$, 47$^*$.




\clearpage
\section{Wednesday, February 4}
\subsection{Rosen 2.2 -- Set Operations}

\textbf{Reading:} Rosen 2.2, LLM 4.1, 4.4, Ducks 2.2.4.

\textbf{Def:} \emph{union} $A \cup B$, \emph{intersection} $A \cap B$, \emph{disjoint} ($A \cap B = \varnothing$), \emph{difference} ($A - B$ or $A \setminus B$) also called \emph{complement of $B$ with respect to $A$}, \emph{complement} ($\overline{A} = U \setminus A$) [Redefine difference as $A \setminus B = A \cap \overline{B}$], \emph{symmetric difference} ($A \oplus B = A \symmdiff B = (A \setminus B) \cup (B \setminus A)$)

\textbf{Thm:} Let $A$ and $B$ be subsets of $U$. $A \symmdiff B = (A \cup B) \setminus (A \cap B)$.

\begin{proof}
Let $A$ and $B$ be subsets of $U$. 
The set $A \symmdiff B$ consists of elements $a \in U$ such that ($a \in A$ and $a \notin B$) or ($a \in B$ and $a \notin A$).
The set $(A \cup B) \setminus (A \cap B)$ consists of elements $a \in U$ such that ($a \in A$ or $a \in B)$ and not ($a \in A$ and $a \in B$).
To show equality, we must show $A \symmdiff B \subseteq (A \cup B) \setminus (A \cap B)$ and $(A \cup B) \setminus (A \cap B) \subseteq A \symmdiff B$.

($A \symmdiff B \subseteq (A \cup B) \setminus (A \cap B)$) 
Let $a \in A \symmdiff B$.
Since  ($a \in A$ and $a \notin B$) or ($a \in B$ and $a \notin A$), we consider two cases.
If $a \in A$ and $a \notin B$, then $a$ is in $A \cup B$ and $a$ is not in $A \cap B$. Therefore, $a$ is in $(A \cup B) \setminus (A \cap B)$.
If $a \in B$ and $a \notin A$, then $a$ is in $A \cup B$ and $a$ is not in $A \cap B$. Therefore, $a$ is in $(A \cup B) \setminus (A \cap B)$.

($(A \cup B) \setminus (A \cap B) \subseteq A \symmdiff B$)
Let $a \in (A \cup B) \setminus (A \cap B)$.
Since $a \in (A \cup B)$, we have that $a \in A$ or $a \in B$.
If $a \in A$, then since $a \notin (A \cap B)$, we have $a \notin B$. Therefore, $a \in A \symmdiff B$.
If $a \in B$, then since $a \notin (A \cap B)$, we have $a \notin A$. Therefore, $a \in A \symmdiff B$.
\end{proof}

This would be easier if we have some helpful tools. We will prove it again later.

\textbf{Note:} Suppose the universe $U$ is a finite set. Then list the elements of $U$ as $a_1, a_2, \dots, a_n$ where $n = |U|$. For each set $A \subseteq U$, we can associate $A$ with a binary string $\vx_A = (x_1,\dots,x_n)$ where $x_i = 1$ if and only if $a_i \in A$. So, this bit string encodes the truth values of the $n$ propositions $p_i = ``a_i \in A''$.

\begin{center}
\begin{tabular}[h]{|r|c|c|c|}
\hline
& \textbf{And/Intersection}  & \textbf{Or/Union} & \textbf{Xor/Symmetric Difference} \\
\hline
\emph{Sets} &
$A \cap B$
&$A \cup B$
&$A \symmdiff B$\\
\hline
\emph{Logic} &
$(a \in A \cap B) \iff (a \in A \land a \in B)$
&$(a \in A \cup B) \iff (a \in A \lor a \in B)$
&$(a \in A \symmdiff B) \iff ( a \in A \xor a \in B)$\\
\hline
\emph{Bit Strings} &
$\vx_{A \cap B} = \vx_A \land \vx_B$
&$\vx_{A\cup B} = \vx_A \lor \vx_B$
&$\vx_{A \symmdiff B} = \vx_A \xor \vx_B$\\
\hline
\end{tabular}
\end{center}

See Table~\ref{tab:setidentities} for a list of set identities.
 
\begin{table}[htp]
\centering
\renewcommand{\arraystretch}{1.25}
\begin{tabular}[h]{|p{1.5in}|p{2.5in}|p{1.4in}|}
\hline
\multicolumn{3}{|l|}{{\sc Table:} \textbf{Logical Equivalences and Set Identities}}\\
\hline
\textit{Logical Equivalence} & 
\textit{Set Identity} & \textit{Name}\\
\hline
$p \land \TRUE \equiv p$ & $A \cap \universe = A$ & Identity laws\\
$p \lor \FALSE \equiv p$ & $A \cup \varnothing = A$ & \\
\hline
$p \lor \TRUE \equiv \TRUE$ & $A \cup \universe = \universe$ & Domination laws\\
$p \land \FALSE \equiv \FALSE$ & $A \cap \varnothing = \varnothing$ & \\
\hline
$p \lor p \equiv p$ & $A \cup A = A$ & Idempotent laws\\
$p \land p \equiv p$ & $A \cap A = A$ & \\
\hline
\vspace{0.05em}$\lnot (\lnot p) \equiv p$ &\vspace{0.05em}$\overline{\left(\overline{A}\right)}$ & Double negation law / Complementation law\\
\hline
$p \lor q \equiv q \lor p$ & $A \cup B = B \cup A$ & Commutative laws\\
$p \land q \equiv q \land p$ & $A \cap B = B \cap A$ & \\
\hline
$(p\lor q)\lor r \equiv p \lor (q\lor r)$ & $(A \cup B) \cup C = A \cup (B \cup C)$ & Associative laws\\
$(p\land q)\land r \equiv p \land (q \land r)$ & $(A \cap B) \cap C = A \cap (B \cap C)$ & \\
\hline
$p \lor (q \land r) \equiv (p \lor q ) \land (p \lor r)$ &$A \cup (B \cap C) = (A \cup B) \cap (A \cup C)$ & Distributive laws\\
$p \land (q \lor r) \equiv (p \land q ) \lor (p \land r)$ & $A \cap (B \cup C) = (A \cap B) \cup (A \cap C)$ & \\
\hline
$\lnot (p \land q) \equiv \lnot p \lor \lnot q$ & $\overline{A \cap B} = \overline{A} \cup \overline{B}$ & De Morgan's laws\\
$\lnot (p \lor q) \equiv \lnot p \land \lnot q$ & $\overline{A \cup B} = \overline{A} \cap \overline{B}$ & \\
\hline
$p \lor (p \land q) \equiv p$ &  $A \cup (A \cap B) = A$ & Absorption laws\\
$p \land (p \lor q ) \equiv p$ & $A \cap (A \cup B) = A$ & \\
\hline
$p \lor \lnot p \equiv \TRUE$ & $A \cup \overline{A} = \universe$ & Negation laws /\\
$p \land \lnot p \equiv \FALSE$ & $A \cap \overline{A} = \varnothing$ & Complement laws\\
\hline
\end{tabular}
\caption{\label{tab:setidentities} Set Identities.}
\end{table}


\textbf{Thm:} Let $A$ and $B$ be subsets of $U$. $A \symmdiff B = (A \cup B) \setminus (A \cap B)$.

\begin{proof}
We will use set identities.

\begin{tabular}[h]{rll}
$A \symmdiff B$ & $= (A \setminus B) \cup (B \setminus A)$ & Definition of Symmetric Difference\\
&$= (A \cap \overline{B}) \cup (B \cap \overline{A}) $ & Definition of Set Subtraction\\
&$= ((A \cap \overline{B}) \cup B) \cap ((A \cap \overline{B}) \cup \overline{A})$ & Distributive Law\\
&$= ((A \cup B) \cap (\overline{B} \cup B)) \cap ((A \cap \overline{A}) \cup (\overline{B} \cap \overline{A}))$ & Distributive Law\\
&$= ((A \cup B) \cap U) \cap ((A \cup \overline{A}) \cap (\overline{B} \cup \overline{A}))$ & Complement Law\\
&$= ((A \cup B) \cap U) \cap (U \cap (\overline{B} \cup \overline{A}))$ & Complement Law\\
&$= (A \cup B) \cap (U \cap (\overline{B} \cup \overline{A}))$ & Identity Law\\
&$= (A \cup B) \cap (\overline{B} \cup \overline{A})$ & Identity Law\\
&$= (A \cup B) \cap \overline{(A \cap B)}$ & DeMorgan's Law\\
&$= (A \cup B) \setminus {(A \cap B)}$ & Definition of Set Subtraction
\end{tabular}

We have thus demonstrated the equality of these sets.
\end{proof}
 
 

\subsubsection{Suggested Homework}

Rosen 2.2: 5--10, 11--17, 18$^*$, 19--20, 32--39, 40$^*$, 41$^*$, 46$^*$, 47--51, 53, 57, 59--60.




\clearpage
\section{Friday, February 6}
\subsection{Set Leftovers}

\textbf{Def:} $A$ and $B$ are \emph{disjoint} if $A \cap B = \varnothing$.

 
\textbf{Generalized Unions and Intersections:}

\[
	\bigcup_{i=1}^n A_i = A_1 \cup A_2 \cup A_3 \cup \cdots \cup A_n.
\]
\[
	\bigcap_{i=1}^n A_i = A_1 \cap A_2 \cap A_3 \cap \cdots \cap A_n.
\]
 
\textbf{Def:} A subset $R$ of $A \times B$ is called a \emph{relation} between $A$ and $B$. The ordered pairs in $R$ describe pairs $(a,b)$ that are related in some way. 

\emph{Show how to visualize $A \times B$ and a relation using a bipartite graph.}

\textbf{Ex:} Let $A = \{1,\dots,n\}$ and $B = \cP(A)$. Let $R = \{ (S, T) : S,T \in \cP(A), S \subseteq T\}$. Then $R \subseteq \cP(A) \times \cP(A)$ and the ``relation'' of a pair $(S, T) \in R$ is ``$S$ is a subset of $T$.'' 

Not all relations are as nicely defined as the one above.


\subsection{Rosen 2.3 -- Functions}

\textbf{Reading:} Rosen 2.3, LLM 4.3, Ducks 3.1, 3.2.

\textbf{Def:} Let $A$ and $B$ be sets. A \emph{function} $f$ from $A$ to $B$ is an assignment of exactly one element of $B$ to each element of $A$. We write $f(a) = b$ if $b$ is the unique element of $B$ assigned by the function $f$ to the element $a$ of $A$. If $f$ is a function from $A$ to $B$, we write $f : A \to B$.

\textbf{Def:} \emph{domain}, \emph{codomain}, \emph{image} ($f(a) = b$), \emph{preimage}, \emph{range}, \emph{maps} $A$ to $B$.

Draw pictures of the above things.

\textbf{Examples:}

\[
	f : \Z \to \Q, \quad f(a) = \frac{1}{1+|a|}.
\]


\[
	f : \Z \to \Z, \quad f(a) = 2a
\]
\[
	f : \R \to \R, \quad f(x) = x^2.
\]

\[
	f : \{a,b,c\} \to \{1,2,3,4\}, \quad f(a) = 1, f(b) = 2, f(c) = 1.
\]

\textbf{Ex:} With the finite set examples, discuss how functions create relations, but not all relations create functions.

\textbf{Def:} If $f : A \to B$ and $S \subseteq A$, let $f(S) = \{ f(a) : a \in S\}$, and call $f(S)$ the \emph{range of $S$}.

\textbf{Def:} \emph{integer-valued}, \emph{real-valued}.

\textbf{Def:} Let $f_1, f_2 : \R \to \R$. $(f_1 + f_2)(x) = f_1(x) + f_2(x)$, $(f_1f_2)(x) = f_1(x)f_2(x)$.

\subsubsection{Types of Functions}

\textbf{Def:} \emph{injective} (or \emph{one-to-one}), \emph{surjective} (or \emph{onto}), and \emph{bijective}.

Let $f : A \to B$ be a function.

\emph{To show that $f$ is injective:} Prove $\forall x, y \in A (f(x) = f(y) \implies x = y)$.

\emph{To show that $f$ is NOT injective:} Prove $\exists x, y \in A (f(x) = f(y) \land x \neq y)$.

\emph{To show that $f$ is surjective:} Prove $\forall y \in B \exists x\in A (f(x) = y)$.

\emph{To show that $f$ is NOT surjective:} Prove $\exists y \in B \forall x\in A (f(x) \neq y)$.

\textbf{Def:} Let $f$ be a bijective function from $A$ to $B$. The \emph{inverse function} of $f$ is the function, denoted $f^{-1}$, that assigns to an element $b \in B$ the unique element $a \in A$ such that $f(a) = b$, i.e. $f^{-1}(b)=a$ when $f(a) = b$.

A bijective function is \emph{invertible}, as we can construct the inverse.
A function $f : A \to B$ that is not bijective is \emph{not invertible}, since one of two things fails:
\begin{itemize}
\item $f$ is not injective, so $f(a) = f(a') = b$ for two elements $a, a' \in A$ where $a \neq a'$. Then $f^{-1}(b)$ cannot be both $a$ and $a'$.
\item $f$ is not surjective, so for some element $b \in B$ there is no element $a \in A$ where $f(a) = b$, so $f^{-1}(b)$ cannot be any element of $A$.
\end{itemize}

\textbf{Def:} If $f : A \to B$ and $g : B \to C$ are functions, then the \emph{composition of $g$ and $f$}, denoted $g \circ f$, is the function $g \circ f : A \to C$ where $(g\circ f)(a) = g(f(a))$ for all $a \in A$.

\emph{Draw a picture.}

\textbf{Note:} If $f$ is a bijection, then $f^{-1}\circ f : A \to A$ is the \emph{identity map}: $f^{-1}\circ f(a) = a$. Note that $f \circ f^{-1} : B \to B$.

\subsubsection{Plots of Functions}

A drawing of a real-valued function on the $(x,y)$-plane is a \emph{plot} of the function. (Not a \emph{graph} because that means something DIFFERENT in this class!)

\textbf{Ex:} $f : \Z \to \Z$: $f(x) = x^2$.

\textbf{Ex:} $f : \R \to \R$: $f(x) = \lfloor x \rfloor$.

\textbf{Ex:} $f : \R \to \R$: $f(x) = \lceil x \rceil$.

\textbf{Ex:} $f : \R \to \R$: $f(x) = [ x ]$.

\textbf{Def:} The \emph{factorial function} $*! : \N \to \Z^+$, denoted by $n!$, is the function $n(n-1)(n-2)\cdots(3)(2)(1)$ or $\prod_{i=1}^n i$. (Note: The empty product is considered to be multiplied by 1, so $0!=1$. There is a reason for this!)




\subsubsection{Suggested Homework}

Rosen 2.3: 1--3, 10--15, 20--25, 26$^*$, 28--29, 33--37, 42--44, 47, 77.







% good example for _induction_
%\textbf{Ex:} Give a direct proof of the statement ``If $n$ is an integer, then $n$ is either odd or even (but not both).''



\end{document} 