section \Assessed Exercise I: Euler's totient function\ (*<*)theory Totient_ex imports "HOL-Computational_Algebra.Computational_Algebra" begin(*>*) text\ Euler's totient function, written $\phi(n)$, denotes the number of integers 1, 2, \ldots,~$n$ that are coprime to the positive integer~$n$. So for example $\phi(1)=\phi(2)=1$ and $\phi(3)=\phi(4)=2$. The totient function is fundamental to number theory and this exercise establishes some of its elementary properties. See Baker, \emph{A Concise Introduction to the Theory of Numbers} (Cambridge University Press, 1984), page 9. Other books on elementary number theory will also cover this function. \ text \\begin{task} Define the totient function @{text \} of type @{typ"nat \ nat"} as described above. Note that the cardinality of a finite set can be expressed using the built-in function @{term card}, and the two-argument predicate @{term coprime} is also available. Greek letters can be inserted using the Symbols palette, but you may give the function the name @{text phi} if you prefer. Then prove the following two facts. \points{5} \end{task} \ (*<*)consts \ :: "nat \ nat"(*>*) lemma phi_1: "\ 1 = 1" (*<*) oops (*>*) lemma phi_2: "\ 2 = 1" (*<*) oops (*>*) text \\begin{task} The following exercise establishes an alternative characterisation of the totient function. \points{10} \end{task} \ lemma phi_altdef: "\(n) = card {m. coprime m n \ m < n}" (*<*) oops (*>*) text \\begin{task} Among the other straightforward properties of the totient function is that $\phi(p)=p-1$ if $p$ is prime. \points{10} \end{task} \ lemma phi_prime [simp]: assumes "prime p" shows "\ p = (p-1)" (*<*) oops (*>*) text \\begin{task} The result above can be generalised to $\phi(p^j)=p^j-p^{j-1}$, where $p$ is prime and $j>0$. \points{25} \end{task} \ lemma phi_prime_power [simp]: assumes "prime p" "j > 0" shows "\ (p ^ j) = p ^ j - p ^ (j-1)" (*<*) oops (*>*) text \ \noindent\emph{Hint}: none of these proofs require induction. Typically they involve manipulations of sets of positive integers, perhaps using equational reasoning. \newpage\ (*<*) end (*>*)