Discrete Maths: Supervision 2 + 3 Extra Questions

Some OCaml exercises

Exercise 1: Modify the pow method to compute \(x^n\ \mathrm{mod}\ m\).

Exercise 2: Write a function in OCaml that given an integer \(n\), it returns the divisors of \(n\). (Can you make your function return a lazy list?)

Exercise 3: Write a function in OCaml that given two integers \(n\) and \(m\), returns the common divisors of \(n\) and \(m\). (Can you make your function return a lazy list?)

Exercise 4: Write a function in OCaml that computes the \(\mathrm{gcd}\).

Exercise 5: A Carmichael number is a composite number \(n\), which satisfies \(b^{(n-1)} \equiv 1\ (\mathrm{mod}\ n)\) for all \(b\) relatively prime to \(n\). Write a function in OCaml that given an integer \(k\), it returns a Carmichael number greater than \(k\).

Modulo, divisibility and properties

Revision

These questions should aid your revision. Send me your answers if you want me to verify.

R1: State the definition of \(\vert\).

R2: Collect and prove the properties of \(\vert\).

R3: State the definition of \(\mathrm{mod}\).

R4: Collect and prove the properties of \(\mathrm{mod}\).

R5: State the division theorem. What is the quotient and what is the remainder?

R6: How is \(\mathrm{rem}\) defined?

R7: State the definition of \(+_m\) for \(m \in\mathbb{N}\).

R8: Collect and prove the properties of \(+_m\).

Exercises

Exercise 1: Show that \(\sqrt{\sqrt{2}}\) is irrational.

Exercise 2: Show that \(2^{1/n}\) is irrational for $n \in \mathbb{N}$ and \(n > 1\).

Exercise 3: Find \(x\) such that \(\sum_{k=1}^{1000} k! \equiv x \ (\mathrm{mod\ } 30)\).

Exercise 4: For $n \in \mathbb{N}$ and $n \geq 1$, show that

  1. $7 \vert (5^{2n} + 3\times 2^{5n - 2})$
  2. $13 \vert (3^{n+2} + 4^{2n + 1})$
  3. $27 \vert (5^{n+2} + 2^{5n + 1})$

Exercise 5: For what values of \(n \in \mathbb{N}\) is \(\sum_{k = 1}^{n} k!\) a square?

Exercise 6 [Fibonacci’s Algorithm]: Egyptian mathematicians represented rational numbers between \(0\) and \(1\) as sums of unit fractions \(1/x_1 + \ldots + 1/x_k\), where \(x\)’s are distinct positive integers. For example, they wrote \(1/3 + 1/15\) instead of \(2/5\). Prove that it is always possible to do this in a systematic way: If \(0 < m/n < 1\), then

\[\frac{m}{n} = \frac{1}{q} + \left\lbrace \text{representation of } \frac{m}{n} - \frac{1}{q} \right\rbrace\]

where \(q = \lceil \frac{n}{m} \rceil\). (Note: You need to show that all summands will be \(1/x_i\) for some \(x_i\) and the procedure produces a finite number of summands).

[Source: Exercise 3.9 in “Concrete Mathematics”]

Exercise 7:

  1. Factorise \(2^{2m + 1} - 2^m -1\) for \(m \in \mathbb{Z}^+\).
  2. Find the values of \(m\) for which this expression gives a prime number.
  3. (optional) Watch this Numberphile video.

Past papers

Divisibility rules

Revision

R1: State and prove divisibility rules for \(3\), \(9\) and \(11\).

R2: What are the divisibility rules for \(4\), \(5\), \(6\) and \(8\)?

Exercises

Exercise 1: (Assumes knowledge of \(\mathrm{gcd}\))

  1. By solving \(10 x \equiv 1 \ (\mathrm{mod\ } 7)\), show that \(-2\) is an inverse of \(10\ (\mathrm{mod\ } 7)\).
  2. Show that if \(7 \nmid a\) then \(7 \vert x\) iff \(7 \vert a \cdot x\).
  3. Show that the following divisibility criterion for \(x\) works for \(7\):
    1. Remove the last digit from \(x\) to get \(x_{1:(n-1)}\).
    2. Subtract twice the last digit from \(x' = x_{1:(n-1)} - 2x_0\).
    3. Repeat for \(x'\)
    4. \(7 \vert x\) iff \(7 \vert x'\).
  4. Determine whether \(7\) divides \(259\) and \(2481\).

Past papers

Fermat’s little theorem

Revision

R1: State Fermat’s little theorem.

R2: Prove Fermat’s little theorem.

Exercises

Exercise 1: Using Fermat’s Little theorem, solve \(5x \equiv 3 \ (\mathrm{mod\ } 11)\).

Exercise 2: Deduce that:

  1. \(17 \vert (13^{16n + 2} + 1)\) for \(n \in \mathbb{Z}^+\)
  2. \(13 \vert (9^{12n + 4} - 9)\) for \(n \in \mathbb{Z}^+\)

Exercise 3: Show that for \(p\) an odd prime:

  1. \[\sum_{k=1}^{p-1} k^{p-1} \equiv -1 \ (\mathrm{mod\ } p)\]
  2. \[\sum_{k=1}^{p-1} k^{p} \equiv 0 \ (\mathrm{mod\ } p)\]

Past papers

Greatest Common Divisor and the Fundametal theorem of arithmetic

Revision

GCD

R1: State the definition for the greatest common divisor.

R2: Collect and prove the properties of the gcd function.

R3: Show that the gcd algorithm computes a common divisor of the inputs.

R4: Show that the gcd algorithm computes the greatest common divisor of the inputs.

Linear Combinations

R5: Let \(a, n \in \mathbb{Z}^+\) with \(\mathrm{gcd}(a, n) = 1\). Show how to compute an element \(x \in \mathbb{Z}\) such that \(ax \equiv 1 \ (\mathrm{mod\ } n)\). Show how to compute all \(x \in \mathbb{Z}\) such that \(ax \equiv 1 \ (\mathrm{mod\ } n)\).

R6: Show that for \(a, b \in \mathbb{Z}^+\) and \(x, y \in \mathbb{Z}\) if \(ax + by = d\), then \(\mathrm{gcd}(a, b) \vert d\). This makes \(\mathrm{gcd}(a, b)\) the smallest possible linear combination of \(a\) and \(b\).

R7: Show that if \(ax + by = d'\) for \(a, b \in \mathbb{Z}^+\), \(d' \in \mathbb{Z}\) and \(\mathrm{gcd}(a, b) \nmid d'\), then it has no solutions.

R7: Show how the extended gcd algorithm computes a linear combination of \(\mathrm{gcd}(a, b)\) in terms of \(a, b \in \mathbb{Z}^+\).

R8: Let \(a, b \in \mathbb{Z}^+\) and \(x, y \in \mathbb{Z}\). Let \(g = \mathrm{gcd}(a, b)\). Show that if \(x_0, y_0 \in \mathbb{Z}\) is a solution to \(ax + by = g\), then

  1. Any solution has the form \(x = x_0 + k \cdot \left(\frac{b}{g}\right)\) and \(y = y_0 - k \cdot \left(\frac{a}{g}\right)\) for \(k \in \mathbb{Z}\).
  2. All pairs of the form \(x = x_0 + k \cdot \left(\frac{b}{g}\right)\) and \(y = y_0 - k \cdot \left(\frac{a}{g}\right)\) for \(k \in \mathbb{Z}\) are solutions to \(ax + by = g\).

Foundamental theorem of arithmetic

R9: State and prove Euclid’s theorem.

R10: State and prove the fundamental theorem of arithmetic.

Examples

Example: Solve the linear equation \(54 x + 21 y = 906\).

(solution) Run the gcd algorithm, keeping on the RHS the current remainder as a linear combination of the input terms \(54\) and \(21\).

\(54 = 21 \cdot 2 + 12\) \(12 = 54 + (-2) \cdot 21\)
\(21 = 12 \cdot 1 + 9\) \(9 = 21 + (-1) \cdot 12 = 21 + (-1) \cdot (54 + (-2) \cdot 21) = (-1) \cdot 54 + 3 \cdot 21\)
\(12 = 9 \cdot 1 + 3\) \(3 = 12 + (-1)\cdot 9 = (54 + (-2) \cdot 21) + (-1)\cdot ((-1) \cdot 54 + 3 \cdot 21) = 2\cdot 54 + (-5) \cdot 21\)
\(9 = 3\cdot 3\)  

Therefore, the \(gcd\) is \(3\) and the RHS gives us the coefficients for a linear combination of the gcd \(3 = 2\cdot 54 + (-5) \cdot 21\). Note that \(3 \vert 906\), since \(906 = 3\cdot 302\).

We have a solution for \(54x + 21y = 3\), but we need a solution for \(54x' + 21y' = 906\). Note that by multiplying the initial solution by \(302\) we get

\[302 \cdot (54 x_0 + 21 y_0) = 302 \cdot 3 \Leftrightarrow 54 (302 \cdot x_0) + 21 (302 \cdot y_0) = 906\]

So, \(x_0' = 302 \cdot (2) = 604\) and \(y_0' = 302 \cdot (-5) = -1510\). Therefore, the general solution has the form (for \(k \in \mathbb{Z}\)):

\[x = x_0' + \left( \frac{21}{3} \right) \cdot k = 604 + 7 k\] \[y = y_0' - \left( \frac{54}{3} \right) \cdot k = -1510 - 18k\ \ \ \ \blacksquare\]

Exercises

Exercise 1: Determine whether the following equations have solutions for \(x, y \in \mathbb{Z}\). If they do find an initial solution and state the general form for all solutions.

Note: Check your solutions using this tool.

Exercise 2: Use the fundamental theorem of arithmetic to compute the gcd and lcm of the following pairs of natural numbers (Hint: write the answers in factored form):

Exercise 3: Find the prime factorisations for:

Exercise 4: Prove that if \(p \vert a^n\), then \(p^n \vert a^n\).

Exercise 5: Show that for all \(k\in \mathbb{Z}\):

Exercise 6: Show that \(5k + 3\) and \(11k + 7\) are relatively prime.

Exercise 7: Given \(a, b \in \mathbb{Z}\) and \(\mathrm{gcd}(a, b) = 1\), show that \(\mathrm{gcd}(a - b, a + b) = 1\) or \(2\).

Exercise 8: Given \(a, b \in \mathbb{Z}\) such that \(\mathrm{gcd}(a, b) = 1\). Prove that \(\mathrm{gcd}(a^2, b^2) = 1\).

Exercise 9:

  1. Prove that if \(d \vert n\), then \((2^d - 1) \vert (2^n - 1)\).
  2. Prove that \(31 \vert (2^{35} -1)\) and \(127 \vert (2^{35} - 1)\).

Exercise 10 [Chicken McNugget theorem]: In this exercise, we are trying to find for \(a, b \in \mathbb{Z}^+\) with \(\mathrm{gcd}(a, b)\), the largest \(m \in \mathbb{Z}\) that is not representable by \(ax + by = m\) for \(x, y \in \mathbb{N}\) (i.e. \(x \geq 0, y \geq 0\)).

  1. (Optional) Watch this Numberphile video.
  2. Show that for a given \(m\), there is always a unique solution \((x_0, y_0)\) such that \(0 \leq x_0 < b\).
  3. Show that the larger \(x\) is, the smaller \(y\) must be.
  4. Show that given \(0 \leq x_0 < b\), the smallest integer not representable with solution \(x_0\) is given when \(y_0 = -1\).
  5. Show that the smallest \(m\) not representable is for \(x_0 = b -1\) and \(y_0 = -1\) and find its value.
  6. Explain why all \(m\)s greater than this value are representable.

Past papers

Encryption

Past papers

Discrete structure

Revision

R1: State the definition for a monoid.

R2: State the definition for a group.

Exercises

Exercise 1 [Identity is unique]: Show that the identity element in a group is unique.

Exercise 2 [Inverses are unique]: Show that the inverse for each element in a group are unique.

Exercise 3: Let \((G, \cdot)\) be a group. Show that if for every \(a \in G\), \(a^2 = e\) (where \(e\) is the identity), then the group operator is commutative.

Exercise 4 [Subgroup]: A subset \(H \subseteq G\) of a group \((G, \cdot)\) is a subgroup iff \((H, \cdot)\) is a subgroup. Show that \((H, \cdot)\) being a subgroup of \((G, \cdot)\) is equivalent to \(e_G \in H\) and \(\forall a, b\in H a \cdot b^{-1} \in H\).

Note: Strictly speaking \(\cdot\) is the operator constrained on \(H\) when refered to the group \((H, \cdot)\).

Exercise 5 [Exponents in groups]: Let \((G, \cdot)\) be a group and \(a\in G\). For convenience,

Prove that:

  1. $(a^{-1})^m = a^{-m} = (a^m)^{-1}$
  2. $a^{n + m} = a^n \cdot a^m$
  3. $(a^n)^m = a^{n\cdot m}$

Exercise 6 [Cyclic groups]: A group is cyclic if \(\exists a . \forall b .\exists n \in \mathbb{Z} . b = a^n\). The element \(a\) is called a generator of \(G\).

  1. Show that \((\mathbb{Z}_n, +_n)\) is a cyclic group.
  2. Given a group \((G, \cdot)\) and an element \(a \in G\), we define \(\langle a \rangle = \lbrace a^n : n \in \mathbb{Z} \rbrace\). Show that \(\langle a \rangle\) forms a subgroup of \((G, \cdot)\).

Past papers