CPSC 229 Foundations of Computation Spring 2024

Exam 1 Review

Show the following logical equivalence using Boolean algebra. \[ p \lor (q \lor p) \equiv p \lor q \] \[\!\begin{aligned} \end{aligned}\]

Answer:
\[\!\begin{aligned} p \lor (q \lor p) & \equiv p \lor (p \lor q) & \mbox{commutative law}\\ & \equiv (p \lor p) \lor q & \mbox{associative law}\\ & \equiv p \lor q & \mbox{idempotent law}\\ \end{aligned}\]
Show the following logical equivalence using Boolean algebra. \[ (p \rightarrow r) \land ( q \rightarrow r) \equiv (p \lor q) \rightarrow r \] \[\!\begin{aligned} \end{aligned}\]
Simplify the following, so that in the end the $\neg$ operator is applied only to individual predicates. \[ \neg ( \exists x ( P(x) \land \forall y ( Q(x,y) \lor R(x,y) ) ) ) \]
Give a formal proof that the following argument is valid. \[\!\begin{aligned} & (q \land \neg s ) \rightarrow p \\ & s \rightarrow t \\ & \neg t \\ & q \\ \hline & \therefore p \end{aligned}\] \[\!\begin{aligned} \end{aligned}\]
Prove that for any integers $a$, $b$, and $c$, if $a$ is divisible by $c$ and $b$ is divisible by $c$, then the sum $a+b$ is also divisible by $c$.

Answer: Show if $a$ is divisible by $c$ and $b$ is divisible by $c$, then $a+b$ is divisible by $c$.

Assume $a$ is divisible by $c$ and $b$ is divisible by $c$. Then $a = k_1c$ for integer $k_1$, and $b = k_2c$ for integer $k_2$.
$a+b = k_1c+k_2c = (k_1+k_2)c$ where $k_1+k_2$ is integer because the sum of two integers is integer.

Thus $a+b$ is divisible by $c$.
Prove that for any real number $x$, if $x^2$ is an irrational number, then $x$ is also irrational. (Use proof by contrapositive.)

Answer: Use the contrapositive: show if $x$ is rational, then $x^2$ is rational.

Assume $x$ is rational. Then $x = a/b$ for integer $a,b$ and $b \neq 0$.
$x^2 = (a/b)^2 = a^2/b^2$ where $a^2, b^2$ are integer (product of two integers) and $b^2 \neq 0$ ($b \neq 0$).

Thus $x^2$ is rational, showing that if $x^2$ is an irrational number, then $x$ is also irrational.

Give a proof by contradiction of the following statement: if $x^2$ is an odd integer, then $x$ is also odd.
Use a proof by induction to show that for any integer $n \geq 1$, $\sum\limits_{i=1}^{n} (2i-1) = n^2$.

Answer: Let P($n$) be that $\sum\limits_{i=1}^{n} (2i-1) = n^2$. Then we need to show P($1$) and P($k$) $\rightarrow$ P($k+1$).

Base case P(1):
Let $n=1$. Then we want to show $\sum\limits_{i=1}^{1} (2i-1) = 1^2$.
$\sum\limits_{i=1}^{1} (2i-1) = 2(1)-1 = 1 $
$1^2 = 1$
Both sides are equal, so $\sum\limits_{i=1}^{n} (2i-1) = n^2$ holds for $n=1$.

Inductive case P($k$) $\rightarrow$ P($k+1$):
Assume that $\sum\limits_{i=1}^{k} (2i-1) = k^2$. Show $\sum\limits_{i=1}^{k+1} (2i-1) = (k+1)^2$ .
$\sum\limits_{i=1}^{k+1} (2i-1) = \sum\limits_{i=1}^{k} (2i-1) + 2(k+1)-1 = k^2+2k+2-1 = k^2+2k+1$ using the induction hypothesis.
$(k+1)^2 = k^2+2k+1$
Both sides are equal, so $\sum\limits_{i=1}^{k+1} (2i-1) = (k+1)^2$.

Thus $\sum\limits_{i=1}^{n} (2i-1) = n^2$.
Use a proof by induction to show that for any integer $n \geq 1$, $n^3+2n$ is a multiple of 3. (That is, there is some integer $j$ such that $n^3+2n = 3j$.)
Consider the function $f: \mathbb{Z} \rightarrow \mathbb{Z}$ given by $f(n) = n+1$. If $f$ a one-to-one function? Is $f$ an onto function?

Answer:
$f$ is one-to-one: $f(x) = x+1$ and $f(y) = y+1$ for integers $x,y$, so $f(x)=f(y)$ means $x+1=y+1$ and thus $x=y$.
$f$ is onto: $\{ f(a)\ | \ a \in \mathbb{Z} \} = \{ a+1\ |\ \ a \in \mathbb{Z} \} $, which is still the set $\mathbb{Z}$.

Discussion:
For a function $f: A \rightarrow B$, one-to-one means that each element of the range is associated with at most one element of the domain, which can be expressed as $\forall x \in A \forall y \in A ( x \neq y \rightarrow f(x) \neq f(y) )$ or, alternatively, as $\forall x \in A \forall y \in A ( f(x) = f(y) \rightarrow x \ y )$. In other words, you can't plug different numbers into $f$ and get the same result out.

Onto means that the image (the values that the function produces) is equal to the range i.e. $\forall b \in B ( \exists a \in A ( b = f(a)))$.
Consider the function $f: \mathbb{N} \rightarrow \mathbb{N}$ given by $f(n) = n+1$. If $f$ a one-to-one function? Is $f$ an onto function?
Let $A$, $B$, $C$ be the sets: \[ A = \{ 2, 3, 5, 7, 11, 13 \} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ B = \{ 1, 2, 3 \} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ C = \{ a, b \} \] Find $B \times C$, $C \times B$, and $A \times B$.

Answer:
$B \times C = \{ (1,a), (1,b), (2,a), (2,b), (3,a), (3,b) \}$
$C \times B = \{ (a,1), (a,2), (a,3), (b,1), (b,2), (b,3) \}$
$A \times B = \{ (2,1), (2,2), (2,3), (3,1), (3,2), (3,3), (5,1), (5,2), (5,3), (7,1), (7,2), (7,3), (11,1), (11,2), (11,3), (13,1), (13,2), (13,3) \}$

Discussion: $A \times B = \{ (a,b)\ |\ a \in A \land b \in B \}$