HW5 Proofs and Induction

CSE20F21

Due: Tuesday, November 16, 2021 at 11:00PM on Gradescope

In this assignment,

You will work with recursively defined sets and functions and prove properties about them, practicing induction and other proof strategies.

Instructions and academic integrity reminders for all homework assignments in CSE20 this quarter are on the class website and on the hw1-definitions-and-notations assignment.

You will submit this assignment via Gradescope (https://www.gradescope.com) in the assignment called “hw5-proofs-and-induction”.

Resources: To review the topics you are working with for this assignment, see the class material from Weeks 5 through 7. We will post frequently asked questions and our answers to them in a pinned Piazza post.

In your proofs and disproofs of statements below, justify each step by reference to a component of the following proof strategies we have discussed so far, and/or to relevant definitions and calculations.

Assigned questions

  1. Recall the definitions from class about factoring and divisibility: when \(a\) and \(b\) are integers and \(a\) is nonzero, \(a\) divides \(b\) means there is an integer \(c\) such that \(b = ac\) . In this case, we say \(a\) is a factor of \(b\), \(a\) is a divisor of \(b\), \(b\) is a multiple of \(a\), \(a | b\). We define the function \(PosFactors: \mathbb{Z}^+ \to \mathcal{P}(\mathbb{Z}^+)\) by \[PosFactors (n) = \{ x \in \mathbb{Z}^+ \mid x\text{ is a factor of } n\}\]


    Sample calculation that can be used as reference for the detail expected in your answer when working with this function:

    The function application \(PosFactors(4)\) evaluates to \[PosFactors (4) = \{ 1,2,4\}\] because the only possible positive factors of \(4\) are \(1,2,3,4\) (the positive integers less than or equal to \(4\)) and when we divide we get: \[\begin{aligned} 4 &= 4 \cdot 1 + 0 \qquad \text{so $4$ is a factor of $4$}\\ 4 &= 3 \cdot 1 + 1 \qquad \text{so $3$ is not a factor of $4$}\\ 4 &= 2 \cdot 2 + 0 \qquad \text{so $2$ is a factor of $4$}\\ 4 &= 1 \cdot 4 + 0 \qquad \text{so $1$ is a factor of $4$} \end{aligned}\]


    1. (Graded for correctness1) Give a witness that proves the statement \[\exists x \in \mathbb{Z}^+ ~\forall y \in \mathbb{Z}^+ ~\left(~x \in PosFactors(y)~\right)\] Justify your choice of witness by explanations that include references to the relevant definitions.

    2. (Graded for correctness) Give a counterexample that disproves the statement \[\forall n \in \mathbb{Z}^+ ~\left(~ PosFactors(n) \subseteq PosFactors(n+1)~\right)\] Justify your choice of counterexample by explanations that include references to the relevant definitions.

    3. (Graded for fair effort completeness) Consider the following attempted proof.

      Attempted proof: For arbitrary integers \(a, b, c\), assume towards a direct proof that \((a+b) | c\). We need to show that \(a|c\) and \(b | c\). Let \(n\) be the integer \(c \text{\bf ~div~} (a+b)\). Since \((a+b) | c\), by definition of divides, \(n | c\) and \(n\) is an integer. Since \(c = 1 \cdot n \cdot (a+b)\), \((n \cdot (a+b) ) | c\). Rewriting by distributing multiplication over addition, we have \(na | c\) and \(nb | c\). Since \(a | na\) and \(na | c\), we have \(a | c\). Similarly, since \(b | nb\) and \(nb | c\), we have \(b | c\). Thus, we have proved both conjuncts and the proof is complete.

      Select the statement below that the attempted proof is trying to prove.

      1. \(\forall a \in \mathbb{Z}^+ ~\forall b \in \mathbb{Z}^+ ~\forall c \in \mathbb{Z} ~( ~( ~a|c ~\lor~b |c~) ~\to~ (a+b) |c~)\)

      2. \(\forall a \in \mathbb{Z}^+ ~\forall b \in \mathbb{Z}^+ ~\forall c \in \mathbb{Z} ~( ~( ~a|b ~\land~a |c~) ~\to~ a |(b+c)~)\)

      3. \(\forall a \in \mathbb{Z}^+ ~\forall b \in \mathbb{Z}^+ ~\forall c \in \mathbb{Z} ~(~ (a+b) | c ~\to ~( ~a|c ~\land~b |c~)~)\)

      Identify the first major error in the attempted proof and explain why it is incorrect.

      Next, disprove the statement the attempted proof was attempting to prove.

      Extra practice; not for credit: prove or disprove the other two statements.

  2. In this question, we’ll consider the function which calculates the sum of the first \(n\) positive integers.

    1. (Graded for fair effort completeness2)

      Give a recursive definition of this function, including domain, codomain and both the basis step and recursive step of the rule. That is, fill in the blanks \[sumOfFirst: \underline{~~domain~~} \to \underline{~~codomain}\] given by \[\begin{aligned} &\textbf{Basis step}: \underline{\text{fill in basis step}} \\ &\textbf{Recursive step}: \underline{\text{fill in recursive step}} \end{aligned}\]

      Notation: Using summation, this function can be written \(sumOfFirst(n) = \sum_{i=1}^n i\).

    2. (Graded for fair effort completeness) It turns out that the value of this function can also be calculated explicitly (without recursion)3. You will prove this by completing the proof of the identity \[\forall n \in \mathbb{Z}^+ ~\left(~sumOfFirst(n) = \frac{n(n+1)}{2} \right)\]

      Fill in the missing parts of the proof of this statement:
      Proof: We proceed by mathematical induction on the set of positive integers.

      Basis Step: Choose \(n = 1\) as the basis step. Using the Basis Step in the recursive definiton of \(sumOfFirst\), \(sumOfFirst(1) = 1\). Plugging \(n\) into the RHS of the desired formula, \(\frac{1 (1+1)}{2} = \frac{2}{2} = 1\). Since LHS=RHS, the Basis step is complete.

      Recursive Step: Consider an arbitrary \(k \geq 1\). We assume (as the induction hypothesis) that fill in the blank here.

      We want to show that \(sumOfFirst(k+1) = \frac{(k + 1) \cdot ((k + 1) + 1)}{2}\).

      Fill in the rest of the proof here.

    3. (Graded for fair effort completeness) When calculating the runtime of an algorithm, nested for loops sometimes lead to program runtimes that involve the sum of the first \(n\) positive integers. To estimate the rate of growth of this runtime, it is useful to find an upper bound for this function in terms of a simpler function. Use the explicit formula from the earlier parts of this question and mathematical induction to prove \[\forall n \in \mathbb{Z}^+~ \left(~sumOfFirst(n) \leq n^2 \right)\]

  3. Recall the definition of linked lists that we discussed in class.

    Define the function \(count\) which returns the number of occurrences of a datum in the list. Formally, \(count: L \times \mathbb{N} \to \mathbb{N}\), where \[\begin{aligned} \textbf{Basis Step:} \qquad &\textrm{If } m \in \mathbb{N},~~ count(~( [], m)~ ) = 0 \\ \textbf{Recursive Step:} \qquad &\textrm{If } l \in L\textrm{ and }n \in \mathbb{N} \textrm{ and }m \in \mathbb{N} \textrm{, then } \\ &count(~(~(n, l),m~)~ ) = \begin{cases} 1 + count(~(l,m)~) &\text{if $n=m$} \\ count(~(l,m)~) &\text{otherwise} \\ \end{cases} \end{aligned}\]

    A mystery function is defined by \(mystery : L \times \mathbb{N} \to L\), where

    \[\begin{aligned} \textbf{Basis Step:} \qquad &\textrm{If } m \in \mathbb{N},~~ mystery(~( [], m)~ ) = [] \\ \textbf{Recursive Step:} \qquad &\textrm{If } l \in L\textrm{ and }n \in \mathbb{N} \textrm{ and }m \in \mathbb{N} \textrm{, then } \\ &mystery(~(~(n, l),m~)~ ) = \begin{cases} l &\text{if $n=m$} \\ mystery(~(l,m)~) &\text{otherwise} \\ \end{cases} \end{aligned}\]

    1. (Graded for correctness) Prove that \[\forall m \in \mathbb{N}~ \exists l \in L ~\left( count(~(l,20)~) = m~ \right)\]

    2. (Graded for correctness) Give an example input \(x\) to the function such that \[mystery( ~(~ x ~,~ 2~) ~) = []\] For full credit, include all intermediate steps of the function application that justifies your choice of \(x\), with brief justifications for each.

    3. (Graded for correctness) Evaluate the function application \[mystery( ~(~ (2, (0, (2, []) ) ) ~,~ 2~) ~)\] For full credit, include all intermediate steps of the function application, with brief justifications for each.

    4. (Graded for fair effort completeness for English statements and correctness in use of syntax for symbolic statements) Describe the rule of the function \(mystery\) in English. Then, write a true statement that describes an invariant using both the functions \(mystery\) and \(count\). Express this invariant both symbolically and in English.


  1. Graded for correctness means your solution will be evaluated not only on the correctness of your answers, but on your ability to present your ideas clearly and logically. You should explain how you arrived at your conclusions, using mathematically sound reasoning. Whether you use formal proof techniques or write a more informal argument for why something is true, your answers should always be well-supported. Your goal should be to convince the reader that your results and methods are sound.↩︎

  2. Graded for fair effort completeness means you will get full credit so long as your submission demonstrates honest effort to answer the question. You will not be penalized for incorrect answers.↩︎

  3. When the value of a function that is recursively defined can also be calculated without recursion, we call the formula that we can use to calculate the value without recursion the “closed form formula” for the function.↩︎