theorem exercise_2_1_18 {G : Type*} [group G]
  [fintype G] (hG2 : even (fintype.card G)) :
  ∃ (a : G), a ≠ 1 ∧ a = a⁻¹ :=

import .common

open set function nat fintype real subgroup ideal polynomial submodule zsqrtd
open char_p mul_aut matrix
open_locale big_operators
noncomputable theory

If $G$ is a finite group of even order, show that there must be an element $a \neq e$ such that $a=a^{-1}$.

\begin{proof}

    First note that $a=a^{-1}$ is the same as saying $a^2=e$, where $e$ is the identity. I.e. the statement is that there exists at least one element of order 2 in $G$.

Every element $a$ of $G$ of order at least 3 has an inverse $a^{-1}$ that is not itself -- that is, $a \neq a^{-1}$. So the subset of all such elements has an even cardinality (/size). There's exactly one element with order 1 : the identity $e^1=e$. So $G$ contains an even number of elements -call it $2 k$-- of which an even number are elements of order 3 or above -- call that $2 n$ where $n<k$-- and exactly one element of order 1 . Hence the number of elements of order 2 is

$$

2 k-2 n-1=2(k-n)-1

$$

This cannot equal 0 as $2(k-n)$ is even and 1 is odd. Hence there's at least one element of order 2 in $G$, which concludes the proof.

\end{proof}


theorem exercise_2_1_26 {G : Type*} [group G]
  [fintype G] (a : G) : ∃ (n : ℕ), a ^ n = 1 :=

If $G$ is a finite group, prove that, given $a \in G$, there is a positive integer $n$, depending on $a$, such that $a^n = e$.

\begin{proof}

    Because there are only a finite number of elements of $G$, it's clear that the set $\left\{a, a^2, a^3, \ldots\right\}$ must be a finite set and in particular, there should exist some $i$ and $j$ such that $i \neq j$ and $a^i=a^j$. WLOG suppose further that $i>j$ (just reverse the roles of $i$ and $j$ otherwise). Then multiply both sides by $\left(a^j\right)^{-1}=a^{-j}$ to get

$$

a^i * a^{-j}=a^{i-j}=e

$$

Thus the $n=i-j$ is a positive integer such that $a^n=e$.

\end{proof}


theorem exercise_2_2_3 {G : Type*} [group G]
  {P : ℕ → Prop} {hP : P = λ i, ∀ a b : G, (a*b)^i = a^i * b^i}
  (hP1 : ∃ n : ℕ, P n ∧ P (n+1) ∧ P (n+2)) : comm_group G :=

If $G$ is a group in which $(a b)^{i}=a^{i} b^{i}$ for three consecutive integers $i$, prove that $G$ is abelian.

\begin{proof}

    Let $G$ be a group, $a, b \in G$ and $i$ be any integer. Then from given condition,

$$

\begin{aligned}

(a b)^i & =a^i b^i \\

(a b)^{i+1} & =a^{i+1} b^{i+1} \\

(a b)^{i+2} & =a^{i+2} b^{i+2}

\end{aligned}

$$

From first and second, we get

$$

a^{i+1} b^{i+1}=(a b)^i(a b)=a^i b^i a b \Longrightarrow b^i a=a b^i

$$

From first and third, we get

$$

a^{i+2} b^{i+2}=(a b)^i(a b)^2=a^i b^i a b a b \Longrightarrow a^2 b^{i+1}=b^i a b a

$$

This gives

$$

a^2 b^{i+1}=a\left(a b^i\right) b=a b^i a b=b^i a^2 b

$$

Finally, we get

$$

b^i a b a=b^i a^2 b \Longrightarrow b a=a b

$$

This shows that $G$ is Abelian.

\end{proof}


theorem exercise_2_2_6c {G : Type*} [group G] {n : ℕ} (hn : n > 1)
  (h : ∀ (a b : G), (a * b) ^ n = a ^ n * b ^ n) :
  ∀ (a b : G), (a * b * a⁻¹ * b⁻¹) ^ (n * (n - 1)) = 1 :=

Let $G$ be a group in which $(a b)^{n}=a^{n} b^{n}$ for some fixed integer $n>1$ for all $a, b \in G$. For all $a, b \in G$, prove that $\left(a b a^{-1} b^{-1}\right)^{n(n-1)}=e$.

\begin{proof}

    We start with the following two intermediate results.

(1) $(a b)^{n-1}=b^{n-1} a^{n-1}$.

(2) $a^n b^{n-1}=b^{n-1} a^n$.

To prove (1), notice by the given condition for all $a, b \in G$

$(b a)^n=b^n a^n$, for some fixed integers $n>1$.

Then,

$(b a)^n=b^n a^n \Longrightarrow b .(a b)(a b) \ldots .(a b) . a=b\left(b^{n-1} a^{n-1}\right) a$, where $(a b)$ occurs $n-1$ times $\Longrightarrow(a b)^{n-1}=b^{n-1} a^{n-1}$, by cancellation law.

Hence, for all $a, b \in G$

$$

(a b)^{n-1}=b^{n-1} a^{n-1} .

$$

To prove (2), notice by the given condition for all $a, b \in G$

$(b a)^n=b^n a^n$, for some fixed integers $n>1$.

Then we have

$$

\begin{aligned}

& (b a)^n=b^n a^n \\

\Longrightarrow & b \cdot(a b)(a b) \ldots(a b) \cdot a=b\left(b^{n-1} a^{n-1}\right) a, \text { where }(a b) \text { occurs } n-1 \text { times } \\

\Longrightarrow & (a b)^{n-1}=b^{n-1} a^{n-1}, \text { by cancellation law } \\

\Longrightarrow & (a b)^{n-1}(a b)=\left(b^{n-1} a^{n-1}\right)(a b) \\

\Longrightarrow & (a b)^n=b^{n-1} a^n b \\

\Longrightarrow & a^n b^n=b^{n-1} a^n b, \text { given condition } \\

\Longrightarrow & a^n b^{n-1}=b^{n-1} a^n, \text { by cancellation law. }

\end{aligned}

$$

Therefore for all $a, b \in G$ we have

$$

a^n b^{n-1}=b^{n-1} a^n

$$

In order to show that

$$

\left(a b a^{-1} b^{-1}\right)^{n(n-1)}=e, \text { for all } a, b \in G

$$

it is enough to show that

$$

(a b)^{n(n-1)}=(b a)^{n(n-1)}, \quad \forall x, y \in G .

$$

Step 3

This is because of

$$

\begin{aligned}

(a b)^{n(n-1)}=(b a)^{n(n-1)} & \left.\Longrightarrow(b a)^{-1}\right)^{n(n-1)}(a b)^{n(n-1)}=e \\

& \Longrightarrow\left(a^{-1} b^{-1}\right)^{n(n-1)}(a b)^{n(n-1)}=e \\

& \Longrightarrow\left(\left(a^{-1} b^{-1}\right)^n\right)^{n-1}\left((a b)^n\right)(n-1)=e \\

& \Longrightarrow\left((a b)^n\left(a^{-1} b^{-1}\right)^n\right)^{n-1}=e, \text { by }(1) \\

& \Longrightarrow\left(a b a^{-1} b^{-1}\right)^{n(n-1)}=e, \text { ( given condition) }

\end{aligned}

$$

Now, it suffices to show that

$$

(a b)^{n(n-1)}=(b a)^{n(n-1)}, \quad \forall x, y \in G .

$$

Now, we have

$$

\begin{aligned}

(a b)^{n(n-1)} & =\left(a^n b^n\right)^{n-1}, \text { by the given condition } \\

& =\left(a^n b^{n-1} b\right)^{n-1} \\

& =\left(b^{n-1} a^n b\right)^{n-1}, \text { by }(2) \\

& =\left(a^n b\right)^{n-1}\left(b^{n-1}\right)^{n-1}, \text { by }(1) \\

& =b^{n-1}\left(a^n\right)^{n-1}\left(b^{n-1}\right)^{n-1}, \text { by }(1) \\

& =\left(b^{n-1}\left(a^{n-1}\right)^n\right)\left(b^{n-1}\right)^{n-1} \\

& =\left(a^{n-1}\right)^n b^{n-1}\left(b^{n-1}\right)^{n-1}, \text { by }(2) \\

& =\left(a^{n-1}\right)^n\left(b^{n-1}\right)^n \\

& =\left(a^{n-1} b^{n-1}\right)^n, \text { by }(1) \\

& =(b a)^{n(n-1)}, \text { by }(1) .

\end{aligned}

$$

This completes our proof.

\end{proof}


theorem exercise_2_3_16 {G : Type*} [group G]
  (hG : ∀ H : subgroup G, H = ⊤ ∨ H = ⊥) :
  is_cyclic G ∧ ∃ (p : ℕ) (fin : fintype G), nat.prime p ∧ @card G fin = p :=

If a group $G$ has no proper subgroups, prove that $G$ is cyclic of order $p$, where $p$ is a prime number.

\begin{proof}

    Case-1: $G=(e), e$ being the identity element in $G$. Then trivially $G$ is cyclic.

    Case-2: $G \neq(e)$. Then there exists an non-identity element in $G.$ Let us consider an non-identity element in $G$, say $a\neq (e)$. Now look at the cyclic subgroup generated by $a$, that is, $\langle a\rangle$. Since

    $a\neq (e) \in G,\langle a\rangle$ is a subgroup of $G$.

If $G \neq\langle a\rangle$ then $\langle a\rangle$ is a proper non-trivial subgroup of $G$, which is an impossibility. Therfore we must have

$$

G=\langle a\rangle .

$$

This implies, $G$ is a cyclic group generated by $a$. Then it follows that every non-identity element of $G$ is a generator of $G$. Now we claim that $G$ is finite.

\end{proof}


theorem exercise_2_5_23 {G : Type*} [group G]
  (hG : ∀ (H : subgroup G), H.normal) (a b : G) :
  ∃ (j : ℤ) , b*a = a^j * b:=

Let $G$ be a group such that all subgroups of $G$ are normal in $G$. If $a, b \in G$, prove that $ba = a^jb$ for some $j$.

\begin{proof}

    Let $G$ be a group where each subgroup is normal in $G$. let $a, b \in G$.

$$

\begin{aligned}

    \langle a\rangle\triangleright  G  &\Rightarrow b \cdot\langle a\rangle=\langle a\rangle \cdot b . \\

& \Rightarrow \quad b \cdot a=a^j \cdot b \text { for some } j \in \mathbb{Z}.

\end{aligned}

$$

(hence for $a_1 b \in G \quad a^j b=b \cdot a$ ).

\end{proof}


theorem exercise_2_5_31 {G : Type*} [comm_group G] [fintype G]
  {p m n : ℕ} (hp : nat.prime p) (hp1 : ¬ p ∣ m) (hG : card G = p^n*m)
  {H : subgroup G} [fintype H] (hH : card H = p^n) :
  characteristic H :=

Suppose that $G$ is an abelian group of order $p^nm$ where $p \nmid m$ is a prime.  If $H$ is a subgroup of $G$ of order $p^n$, prove that $H$ is a characteristic subgroup of $G$.

\begin{proof}

    Let $G$ be an abelian group of order $p^n m$, such that $p \nmid m$. Now, Given that $H$ is a subgroup of order $p^n$. Since $G$ is abelian $H$ is normal. Now we want to prove that $H$ is a characterestic subgroup, that is $\phi(H)=H$ for any automorphism $\phi$ of $G$. Now consider $\phi(H)$. Clearly $|\phi(H)|=p^n$. Suppose $\phi(H) \neq H$, then $|H \cap \phi(H)|=p^s$, where $s<n$. Consider $H \phi(H)$, this is a subgroup of $G$ as $H$ is normal. Also $|H \phi(H)|=\frac{|H||\phi(H)|}{|H \cap \phi(H)|}=\frac{p^{2 n}}{p^s}=p^{2 n-s}$, where $2 n-s>n$. By lagrange's theorem then $p^{2 n-s}\left|p^n m \Longrightarrow p^{n-s}\right| m \Longrightarrow p \mid m$-contradiction. So $\phi(H)=H$, and $H$ is characterestic subgroup of $G$.

\end{proof}


theorem exercise_2_5_43 (G : Type*) [group G] [fintype G]
  (hG : card G = 9) :
  comm_group G :=

Prove that a group of order 9 must be abelian.

\begin{proof}

    We use the result from problem 40 which is as follows: Suppose $G$ is a group, $H$ is a subgroup and $|G|=n$ and $n \nmid\left(i_G(H)\right) !$. Then there exists a normal subgroup $\$ K \backslash$ neq $\{$ e $\} \$$ and $K \subseteq H$.

So, we have now a group $G$ of order 9. Suppose that $G$ is cyclic, then $G$ is abelian and there is nothing more to prove. Suppose that $G$ s not cyclic,then there exists an element $a$ of order 3 , and $A=\langle a\rangle$. Now $i_G(A)=3$, now $9 \nmid 3$ !, hence by the above result there is a normal subgroup $K$, non-trivial and $K \subseteq A$. But $|A|=3$, a prime order subgroup, hence has no non-trivial subgroup, so $K=A$. So $A$ is normal subgroup. Now since $G$ is not cyclic any non-identity element is of order 3.So Let $a(\neq$ $e) \in G$.Consider $A=\langle a\rangle$. As shown before $A$ is normal. $a$ commutes with any if its powers. Now Let $b \in G$ such that $b \notin A$. Then $b a b^{-1} \in A$ and hence $b a b^{-1}=a^i$.This implies $a=b^3 a b^{-3}=a^{i^3} \Longrightarrow a^{i^3-1}=e$. So, 3 divides $i^3-1$. Also by fermat's little theorem 3 divides $i^2-1$.So 3 divides $i-1$. But $0 \leq i \leq 2$. So $i=1$, is the only possibility and hence $a b=b a$. So $a \in Z(G)$ as $b$ was arbitrary. Since $a$ was arbitrary $G=Z(G)$. Hence $G$ is abelian.

\end{proof}


theorem exercise_2_5_52 {G : Type*} [group G] [fintype G]
  (φ : G ≃* G) {I : finset G} (hI : ∀ x ∈ I, φ x = x⁻¹)
  (hI1 : 0.75 * card G ≤ card I) :
  ∀ x : G, φ x = x⁻¹ ∧ ∀ x y : G, x*y = y*x :=

Let $G$ be a finite group and $\varphi$ an automorphism of $G$ such that $\varphi(x) = x^{-1}$ for more than three-fourths of the elements of $G$. Prove that $\varphi(y) = y^{-1}$ for all $y \in G$, and so $G$ is abelian.

\begin{proof}

Let us start with considering $b$ to be an arbitrary element in $A$.

1. Show that $\left|A \cap\left(b^{-1} A\right)\right|>\frac{|G|}{2}$, where

$$

b^{-1} A=\left\{b^{-1} a \mid a \in A\right\}

$$

First notice that if we consider a map $f: A \rightarrow b^{-1} A$ defined by $f(a)=b^{-1} a$, for all $a \in A$, then $f$ is a 1-1 map and so $\left|b^{-1} A\right| \geq|A|>\frac{3}{4}|G|$. Now using inclusion-exclusion principle we have

$$

\left|A \cap\left(b^{-1} A\right)\right|=|A|+\left|b^{-1} A\right|-\left|A \cup\left(b^{-1} A\right)\right|>\frac{3}{4}|G|+\frac{3}{4}|G|-|G|=\frac{1}{2}|G|

$$

2. Argue that $A \cap\left(b^{-1} A\right) \subseteq C(b)$, where $C(b)$ is the centralizer of $b$ in $G$.

Suppose $x \in A \cap\left(b^{-1} A\right)$, that means, $x \in A$ and $x \in b^{-1} A$. Thus there exist an element $a \in A$ such that $x=$ $b^{-1} a$, which gives us $x b=a \in A$. Now notice that $x, b \in A$ and $x b \in A$, therefore we get

$$

\phi(x b)=(x b)^{-1} \Longrightarrow \phi(x) \phi(b)=(x b)^{-1} \Longrightarrow x^{-1} b^{-1}=b^{-1} x^{-1} \Longrightarrow x b=b x

$$

Therefore, we get $x b=b x$, for any $x \in A \cap\left(b^{-1} A\right)$, that means, $x \in C(b)$.

3. Argue that $C(b)=G$.

We know that centralizer of an element in a group $G$ is a subgroup (See Page 53). Therefore $C(b)$ is a subgroup of $G$. From statements $\mathbf{1}$ and $\mathbf{2}$, we have

$$

|C(b)| \geq\left|A \cap\left(b^{-1} A\right)\right|>\frac{|G|}{2}

$$

We need to use the following remark to argue $C(b)=G$ from the above step.

Remark. Let $G$ be a finite group and $H$ be a subgroup with more then $|G| / 2$ elements then $H=G$.

Proof of Remark. Suppose $|H|=p$ Then by Lagrange Theorem, there exist an $n \in \mathbb{N}$, such that $|G|=n p$, as $|H|$ divide $|G|$. Now by hypothesis $p>\frac{G]}{2}$ gives us,

$$

p>\frac{|G|}{2} \Longrightarrow n p>\frac{n|G|}{2} \Longrightarrow n<2 \Longrightarrow n=1

$$

Therefore we get $H=G$.

Now notice that $C(b)$ is a subgroup of $G$ with $C(b)$ having more than $|G| / 2$ elements. Therefore, $C(b)=G$.

4. Show that $A \in Z(G)$.

We know that $x \in Z(G)$ if and only if $C(a)=G$. Now notice that, for any $b \in A$ we have $C(b)=G$. Therefore, every element of $A$ is in the center of $G$, that means, $A \subseteq Z(G)$.

5. 5how that $Z(G)=G$.

As it is given that $|A|>\frac{3|G|}{4}$ and $A \leq|Z(G)|$, therefore we get

$$

|Z(G)|>\frac{3}{4}|G|>\frac{1}{2}|G| .

$$

As $Z(G)$ is a subgroup of $G$, so by the above Remark we have $Z(G)=G$. Hence $G$ is abelian.

6. Finally show that $A=G$.

First notice that $A$ is a subgroup of $G$. To show this let $p, q \in A$. Then we have

$$

\phi(p q)=\phi(p) \phi(q)=p^{-1} q^{-1}=(q p)^{-1}=(p q)^{-1}, \quad \text { As } G \text { is abelian. }

$$

Therefore, $p q \in A$ and so we have $A$ is a subgroup of $G$. Again by applying the above remark. we get $A=G$. Therefore we have

$$

\phi(y)=y^{-1}, \quad \text { for all } y \in G

$$

\end{proof}


theorem exercise_2_7_7 {G : Type*} [group G] {G' : Type*} [group G']
  (φ : G →* G') (N : subgroup G) [N.normal] :
  (map φ N).normal  :=

If $\varphi$ is a homomorphism of $G$ onto $G'$ and $N \triangleleft G$, show that $\varphi(N) \triangleleft G'$.

\begin{proof}

We first claim that $\varphi(N)$ is a subgroup of $G'$. To see this, note that since $N$ is a subgroup of $G$, the identity element $e_G$ of $G$ belongs to $N$. Therefore, the element $\varphi(e_G) \in \varphi(N)$, so $\varphi(N)$ is a non-empty subset of $G'$.

Now, let $a', b' \in \varphi(N)$. Then there exist elements $a, b \in N$ such that $\varphi(a) = a'$ and $\varphi(b) = b'$. Since $N$ is a subgroup of $G$, we have $a, b \in N$, so $ab^{-1} \in N$. Thus, we have

$$\varphi(ab^{-1}) = \varphi(a) \varphi(b^{-1}) = a'b'^{-1} \in \varphi(N),$$

which shows that $a', b' \in \varphi(N)$ implies $a'b'^{-1} \in \varphi(N)$. Therefore, $\varphi(N)$ is a subgroup of $G'$.

Next, we will show that $\varphi(N)$ is a normal subgroup of $G'$. Let $\varphi(N) = N'$, a subgroup of $G'$. Let $x' \in G'$ and $h' \in N'$. Since $\varphi$ is onto, there exist elements $x \in G$ and $h \in N$ such that $\varphi(x) = x'$ and $\varphi(h) = h'$.

Since $N$ is a normal subgroup of $G$, we have $xhx^{-1} \in N$. Thus,

$$\varphi(xhx^{-1}) = \varphi(x)\varphi(h)\varphi(x^{-1}) = x'h'x'^{-1} \in \varphi(N),$$

which shows that $x' \in G'$ and $h' \in N'$ implies $x'h'x'^{-1} \in \varphi(N)$. Therefore, $\varphi(N)$ is a normal subgroup of $G'$. This completes the proof.

\end{proof}


theorem exercise_2_8_15 {G H: Type*} [fintype G] [group G] [fintype H]
  [group H] {p q : ℕ} (hp : nat.prime p) (hq : nat.prime q)
  (h : p > q) (h1 : q ∣ p - 1) (hG : card G = p*q) (hH : card G = p*q) :
  G ≃* H :=

Prove that if $p > q$ are two primes such that $q \mid p - 1$, then any two nonabelian groups of order $pq$ are isomorphic.

\begin{proof}

    For a nonabelian group of order $p q$, the structure of the group $G$ is set by determining the relation $a b a^{-1}=b^{k^{\frac{p-1}{q}}}$ for some generator $k$ of the cyclic group. Here we are using the fact that $k^{\frac{p-1}{q}}$ is a generator for the unique subgroup of order $q$ in $U_p$ (a cyclic group of order $m$ has a unique subgroup of order $d$ for each divisor $d$ of $m$ ). The other possible generators of this subgroup are $k^{\frac{l(p-1)}{q}}$ for each $1 \leq l \leq q-1$, so these give potentially new group structures. Let $G^{\prime}$ be a group with an element $c$ of order $q$, an element $d$ of order $p$ with structure defined by the relation $c d c^{-1}=d^{k^{\frac{l(p-1)}{q}}}$. We may then define

$$

\begin{aligned}

\phi: G^{\prime} & \rightarrow G \\

c & \mapsto a^l \\

d & \mapsto b

\end{aligned}

$$

since $c$ and $a^l$ have the same order and $b$ and $d$ have the same order this is a well defined function.

Since

$$

\begin{aligned}

\phi(c) \phi(d) \phi(c)^{-1} & =a^l b a^{-l} \\

& =b^{\left(k^{\frac{p-1}{q}}\right)^l} \\

& =b^{k^{\frac{l(p-1)}{q}}} \\

& =\phi(d)^{k^{\frac{l(p-1)}{q}}}

\end{aligned}

$$

$\phi\left(c^i d^j\right)=a^{l i} b^j=e$ only if $i=j=0$, so $\phi$ is 1-to-l. Therefore $G$ and $G^{\prime}$ are isomorphic and so up to isomorphism there is only one nonabelian group of order $p q$.

\end{proof}


theorem exercise_2_10_1 {G : Type*} [group G] (A : subgroup G)
  [A.normal] {b : G} (hp : nat.prime (order_of b)) :
  A ⊓ (closure {b}) = ⊥ :=

Let $A$ be a normal subgroup of a group $G$, and suppose that $b \in G$ is an element of prime order $p$, and that $b \not\in A$. Show that $A \cap (b) = (e)$.

\begin{proof}

If $b \in G$ has order $p$, then $(b)$ is a cyclic group of order $p$. Since $A$ is a subgroup of $G$, we have $A \cap (b)$ is a subgroup of $G$. Also, $A \cap (b) \subseteq (b)$. So $A \cap (b)$ is a subgroup of $(b)$. Since $(b)$ is a cyclic group of order $p$, the only subgroups of $(b)$ are $(e)$ and $(b)$ itself.

Therefore, either $A \cap (b) = (e)$ or $A \cap (b) = (b)$. If $A \cap (b) = (e)$, then we are done. Otherwise, if $A \cap (b) = (b)$, then $A \subseteq (b)$. Since $A$ is a subgroup of $G$ and $A \subseteq (b)$, it follows that $A$ is a subgroup of $(b)$.

Since the only subgroups of $(b)$ are $(e)$ and $(b)$ itself, we have either $A = (e)$ or $A = (b)$. If $A = (e)$, then $A \cap (b) = (e)$ and we are done. But if $A = (b)$, then $b \in A$ as $b \in (b)$, which contradicts our hypothesis that $b \notin A$. So $A \neq (b)$.

Hence $A \cap (b) \neq (b)$. Therefore, $A \cap (b) = (e)$. This completes our proof.

\end{proof}


theorem exercise_2_11_7 {G : Type*} [group G] {p : ℕ} (hp : nat.prime p)
  {P : sylow p G} (hP : P.normal) :
  characteristic (P : subgroup G) :=

If $P \triangleleft G$, $P$ a $p$-Sylow subgroup of $G$, prove that $\varphi(P) = P$ for every automorphism $\varphi$ of $G$.

\begin{proof}

    Let $\phi$ be an automorphism of $G$. Let $P$ be a normal sylow p-subgroup. $\phi(P)$ is also a sylow-p subgroup. But since $P$ is normal, it is unique. Hence $\phi(P)=P$.

\end{proof}


theorem exercise_3_2_21 {α : Type*} [fintype α] {σ τ: equiv.perm α}
  (h1 : ∀ a : α, σ a = a ↔ τ a ≠ a) (h2 : τ ∘ σ = id) :
  σ = 1 ∧ τ = 1 :=

If $\sigma, \tau$ are two permutations that disturb no common element and $\sigma \tau = e$, prove that $\sigma = \tau = e$.

\begin{proof}

    Note that $\sigma \tau=e$ can equivalentnly be phrased as $\tau$ being the inverse of $\sigma$. Our statement is then equivalent to the statement that an inverse of a nonidentity permutation disturbs at least one same element as that permutation. To prove this, let $\sigma$ be a nonidentity permutation, then let $\left(i_1 \cdots i_n\right)$ be a cycle in $\sigma$. Then we have that

$$

\sigma\left(i_1\right)=i_2, \sigma\left(i_2\right)=i_2, \ldots, \sigma\left(i_{n-1}\right)=i_n, \sigma\left(i_n\right)=i_1,

$$

but then also

$$

i_1=\tau\left(i_2\right), i_2=\tau\left(i_3\right), \ldots, i_{n-1}=\tau\left(i_n\right), i_n=\tau\left(i_1\right),

$$

i.e. its inverse disturbs $i_1, \ldots, i_n$.

\end{proof}


theorem exercise_4_1_34 : equiv.perm (fin 3) ≃* general_linear_group (fin 2) (zmod 2) :=

Let $T$ be the group of $2\times 2$ matrices $A$ with entries in the field $\mathbb{Z}_2$ such that $\det A$ is not equal to 0. Prove that $T$ is isomorphic to $S_3$, the symmetric group of degree 3.

\begin{proof}

    The order of $T$ is $2^4-2^3-2^2+2=6$; we now find those six matrices:

$$

\begin{array}{ll}

A_1=\left(\begin{array}{ll}

1 & 0 \\

0 & 1

\end{array}\right), & A_2=\left(\begin{array}{ll}

0 & 1 \\

1 & 0

\end{array}\right) \\

A_3=\left(\begin{array}{ll}

1 & 0 \\

1 & 1

\end{array}\right), & A_4=\left(\begin{array}{ll}

1 & 1 \\

0 & 1

\end{array}\right) \\

A_5=\left(\begin{array}{ll}

0 & 1 \\

1 & 1

\end{array}\right), & A_6=\left(\begin{array}{ll}

1 & 1 \\

1 & 0

\end{array}\right)

\end{array}

$$

with orders $1,2,2,2,3,3$ respectively.

Note that $S_3$ is composed of elements

$$

\text{ id, (1 2), (1 3), (2 3), (1 2 3), (1 3 2)}

$$

with orders 1, 2, 2, 2, 3, 3 respectively. Also note that, by Problem 17 of generate $S_3$. We also have that $\left(\begin{array}{llll}1 & 3 & 2\end{array}\right)=\left(\begin{array}{llll}1 & 2 & 3\end{array}\right)\left(\begin{array}{lll}1 & 2 & 3\end{array}\right)$, that $\left(\begin{array}{lll}1 & 3\end{array}\right)=\left(\begin{array}{lll}1 & 2 & 3\end{array}\right)\left(\begin{array}{ll}1 & 2\end{array}\right)$, $\left(\begin{array}{ll}1 & 2\end{array}\right)\left(\begin{array}{lll}1 & 2 & 3\end{array}\right)=\left(\begin{array}{ll}2 & 3\end{array}\right)$ and $\left(\begin{array}{lll}1 & 2\end{array}\right)\left(\begin{array}{ll}1 & 2\end{array}\right)=\mathrm{id}$

Now we can check that $\tau\left(A_2\right)=\left(\begin{array}{ll}1 & 2\end{array}\right), \tau\left(A_5\right)=\left(\begin{array}{lll}1 & 2 & 3\end{array}\right)$ induces an isomorphism. We compute

$$

\begin{aligned}

& \tau\left(A_1\right)=\tau\left(A_2 A_2\right)=\tau\left(A_2\right) \tau\left(A_2\right)=\mathrm{id} \\

& \tau\left(A_3\right)=\tau\left(A_5 A_2\right)=\tau\left(A_5\right) \tau\left(A_2\right)=\left(\begin{array}{llll}

1 & 2 & 3

\end{array}\right)\left(\begin{array}{lll}

1 & 2

\end{array}\right)=\left(\begin{array}{ll}

1 & 3

\end{array}\right) \\

& \tau\left(A_4\right)=\tau\left(A_2 A_5\right)=\tau\left(A_2\right) \tau\left(A_5\right)=\left(\begin{array}{lll}

1 & 2

\end{array}\right)\left(\begin{array}{lll}

1 & 2 & 3

\end{array}\right)=\left(\begin{array}{ll}

2 & 3

\end{array}\right) \\

& \tau\left(A_6\right)=\tau\left(A_5 A_5\right)=\tau\left(A_5\right) \tau\left(A_5\right)=\left(\begin{array}{lll}

1 & 3 & 2

\end{array}\right)

\end{aligned}

$$

Thus we see that $\tau$ extendeds to an isomorphism, since $A_2$ and $A_5$ generate $T$, so that $\tau\left(A_i A_j\right)=\tau\left(A_i\right) \tau\left(A_j\right)$ follows from writing $A_i$ and $A_j$ in terms of $A_2$ and $A_5$ and using the equlities and relations shown above.

\end{proof}


theorem exercise_4_2_6 {R : Type*} [ring R] (a x : R)
  (h : a ^ 2 = 0) : a * (a * x + x * a) = (x + x * a) * a :=

If $a^2 = 0$ in $R$, show that $ax + xa$ commutes with $a$.

\begin{proof}

We need to show that

$$

a(a x+x a)=(a x+x a) a \text { for } a, x \in R .

$$

Now,

$$

\begin{gathered}

a(a x+x a)=a(a x)+a(x a) \\

=a^2 x+a x a \\

=0+a x a=a x a .

\end{gathered}

$$

Again,

$$

\begin{gathered}

(a x+x a) a=(a x) a+(x a) a \\

=a x a+x a^2 \\

=a x a+0=a x a .

\end{gathered}

$$

It follows that,

$$

a(a x+x a)=(a x+x a) a, \text { for } x, a \in R .

$$

This shows that $a x+x a$ commutes with $a$. This completes the proof.

\end{proof}


theorem exercise_4_3_1 {R : Type*} [comm_ring R] (a : R) :
  ∃ I : ideal R, {x : R | x*a=0} = I :=

If $R$ is a commutative ring and $a \in R$, let $L(a) = \{x \in R \mid xa = 0\}$. Prove that $L(a)$ is an ideal of $R$.

\begin{proof}

    First, note that if $x \in L(a)$ and $y \in L(a)$ then $x a=0$ and $y a=0$, so that

$$

\begin{aligned}

x a-y a & =0 \\

(x-y) a & =0,

\end{aligned}

$$

i.e. $L(a)$ is an additive subgroup of $R$. (We have used the criterion that $H$ is a subgroup of $G$ if for any $h_1, h_2 \in H$ we have that $h_1 h_2^{-1} \in H$.

Now we prove the conclusion. Let $r \in R$ and $b \in L(a)$, then $b a=0$, and so $x b a=0$ which by associativity of multiplication in $R$ is equivalent to

$$

(x b) a=0,

$$

so that $x b \in L(a)$. Since $R$ is commutative, (1) implies that $(bx)a=0$, so that $b x \in L(a)$, which concludes the proof that $L(a)$ is an ideal.

\end{proof}


theorem exercise_4_4_9 (p : ℕ) (hp : nat.prime p) :
  ∃ S : finset (zmod p), S.card = (p-1)/2 ∧ ∃ x : zmod p, x^2 = p ∧
  ∃ S : finset (zmod p), S.card = (p-1)/2 ∧ ¬ ∃ x : zmod p, x^2 = p :=

Show that $(p - 1)/2$ of the numbers $1, 2, \ldots, p - 1$ are quadratic residues and $(p - 1)/2$ are quadratic nonresidues $\mod p$.

\begin{proof}

    To find all the quadratic residues $\bmod p$ among the integers $1,2, \ldots, p-1$, we compute the least positive residues modulo $p$ of the squares of the integers $1,2, \ldots, p-1\}$.

Since there are $p-1$ squares to consider, and since each congruence $x^2 \equiv a (\bmod p)$ has either zero or two solutions, there must be exactly $\frac{(p-1)}{2}$ quadratic residues mod $p$ among the integers $1,2, \ldots, p-1$.

The remaining

$$

(p-1)-\frac{(p-1)}{2}=\frac{(p-1)}{2}

$$

positive integers less than $p-1$ are quadratic non-residues of $\bmod p$.

\end{proof}


theorem exercise_4_5_23 {p q: polynomial (zmod 7)}
  (hp : p = X^3 - 2) (hq : q = X^3 + 2) :
  irreducible p ∧ irreducible q ∧
  (nonempty $ polynomial (zmod 7) ⧸ ideal.span ({p} : set $ polynomial $ zmod 7) ≃+*
  polynomial (zmod 7) ⧸ ideal.span ({q} : set $ polynomial $ zmod 7)) :=

Let $F = \mathbb{Z}_7$ and let $p(x) = x^3 - 2$ and $q(x) = x^3 + 2$ be in $F[x]$. Show that $p(x)$ and $q(x)$ are irreducible in $F[x]$ and that the fields $F[x]/(p(x))$ and $F[x]/(q(x))$ are isomorphic.

\begin{proof}

    We have that $p(x)$ and $q(x)$ are irreducible if they have no roots in $\mathbb{Z}_7$, which can easily be checked. E.g. for $p(x)$ we have that $p(0)=5, p(1)=6, p(2)=6, p(3)=4, p(4)=6$, $p(5)=4, p(6)=4$, and similarly for $q(x)$.

We have that every element of $F[x] /(p(x))$ is equal to $a x^2+b x+c+(p(x))$, and likewise for $F[x] /(q(x))$. We consider a map $\tau$ : $F[x] /(p(x)) \rightarrow F[x] /(q(x))$ given by

$$

\tau\left(a x^2+b x+c+(p(x))\right)=a x^2-b x+c+(q(x)) .

$$

This map is obviously onto, and since $|F[x] /(p(x))|=|F[x] /(q(x))|=7^3$ by Problem 16, it is also one-to-one. We claim that it is a homomorphism. Additivity of $\tau$ is immediate by the linearity of addition of polynomial coefficient, so we just have to check the multiplicativity; if $n=a x^2+b x+$ $c+(p(x))$ and $m=d x^2+e x+f+(p(x))$ then

$$

\begin{aligned}

\tau(n m) & =\tau\left(a d x^4+(a e+b d) x^3+(a f+b e+c d) x^2+(b f+c e) x+c f+(p(x))\right) \\

& =\tau\left(2 a d x+2(a e+b d)+(a f+b e+c d) x^2+(b f+c e) x+c f+(p(x))\right) \\

& =\tau\left((a f+b e+c d) x^2+(b f+c e+2 a d) x+(c f+2 a e+2 b d)+(p(x))\right) \\

& =(a f+b e+c d) x^2-(b f+c e+2 a d) x+c f+2 a e+2 b d+(q(x)) \\

& =a d x^4-(a e+b d) x^3+(a f+b e+c d) x^2-(b f+c e) x+c f+(q(x)) \\

& =\left(a x^2-b x+c+(q(x))\right)\left(d x^2-e x+f+(q(x))\right) \\

& =\tau(n) \tau(m) .

\end{aligned}

$$

where in the second equality we used that $x^3+p(x)=2+p(x)$ and in the fifth we used that $x^3+$ $q(x)=-2+q(x)$

\end{proof}


theorem exercise_4_6_2 : irreducible (X^3 + 3*X + 2 : polynomial ℚ) :=

Prove that $f(x) = x^3 + 3x + 2$ is irreducible in $Q[x]$.

\begin{proof}

Let us assume that $f(x)$ is reducible over $\mathbb{Q}[x]$.

Then there exists a rational root of $f(x)$.

Let $p / q$ be a rational root of $f(x)$, where $\operatorname{gcd}(p, q)=1$.

Then $f(p / q)=0$.

Now,

$$

\begin{aligned}

& f(p / q)=(p / q)^3+3(p / q)+2 \\

\Longrightarrow & (p / q)^3+3(p / q)+2=0 \\

\Longrightarrow & p^3+3 p q^2=-2 q^3 \\

\Longrightarrow & p\left(p^2+3 q^2\right)=-q^3

\end{aligned}

$$

It follows that, $p$ divides $q$ which is a contradiction to the fact that $\operatorname{gcd}(p, q)=1$.

This implies that $f(x)$ has no rational root.

Now we know that, a polynomial of degree two or three over a field $F$ is reducible if and only if it has a root in $F$.

Now $f(x)$ is a 3 degree polynomial having no root in $\mathbb{Q}$.

So, $f(x)$ is irreducible in $\mathbb{Q}[x]$.

This completes the proof.

\end{proof}


theorem exercise_5_1_8 {p m n: ℕ} {F : Type*} [field F]
  (hp : nat.prime p) (hF : char_p F p) (a b : F) (hm : m = p ^ n) :
  (a + b) ^ m = a^m + b^m :=

If $F$ is a field of characteristic $p \neq 0$, show that $(a + b)^m = a^m + b^m$, where $m = p^n$, for all $a, b \in F$ and any positive integer $n$.

\begin{proof}

    Since $F$ is of characteristic $p$ and we have considered arbitrary two elements $a, b$ in $F$ we have

$$

\begin{aligned}

& p a=p b=0 \\

& \Longrightarrow p^n a=p^n b=0 \\

& \Longrightarrow m a=m b=0 \text {. } \\

&

\end{aligned}

$$

Now we know from Binomial Theorem that

$$

(a+b)^m=\sum_{i=0}^m\left(\begin{array}{c}

m \\

i

\end{array}\right) a^i b^{m-i}

$$

Here

$$

\left(\begin{array}{c}

m \\

i

\end{array}\right)=\frac{m !}{i !(m-i) !} .

$$

Now we know that for any integer $n$ and any integer $k$ satisfying $1 \leq k<n, n$ always divides $\left(\begin{array}{l}n \\ k\end{array}\right)$. So in our case for $i$ in the range $1 \leq i<m, m$ divides $\left(\begin{array}{c}m \\ i\end{array}\right)$. It follows that $p$ divides $\left(\begin{array}{c}m \\ i\end{array}\right)$, for $i$ satisfying $1 \leq i<m$, since $m=p^n$ for any integer $n$. Therefore other than the terms $a^m$ and $b^m$ in the expansion $\sum_{i=0}^m\left(\begin{array}{c}m \\ i\end{array}\right) a^i b^{m-i}$ will vanish due to char $p$ nature of $F$.

Hence we have

$$

\sum_{i=0}^m\left(\begin{array}{c}

m \\

i

\end{array}\right) a^i b^{m-i}=a^m+b^m

$$

This follows that, for all $a, b \in F$

$$

(a+b)^m=a^m+b^m .

$$

This completes the proof.

\end{proof}


theorem exercise_5_3_7 {K : Type*} [field K] {F : subfield K}
  {a : K} (ha : is_algebraic F (a ^ 2)) : is_algebraic F a :=

If $a \in K$ is such that $a^2$ is algebraic over the subfield $F$ of $K$, show that a is algebraic over $F$.

\begin{proof}

    Since $a^2$ is algebraic over $F$, there exist a non-zero polynomial $f(x)$ in $F[x]$ such that $f\left(a^2\right)=0$. Consider a new polynomial $g(x)$ defined as $g(x)=f\left(x^2\right)$. Clearly $g(x) \in F[x]$ and $g(a)=f\left(a^2\right)= 0$.

\end{proof}


theorem exercise_5_4_3 {a : ℂ} {p : ℂ → ℂ}
  (hp : p = λ x, x^5 + real.sqrt 2 * x^3 + real.sqrt 5 * x^2 +
  real.sqrt 7 * x + 11)
  (ha : p a = 0) :
  ∃ p : polynomial ℂ , p.degree < 80 ∧ a ∈ p.roots ∧
  ∀ n : p.support, ∃ a b : ℤ, p.coeff n = a / b :=

If $a \in C$ is such that $p(a) = 0$, where $p(x) = x^5 + \sqrt{2}x^3 + \sqrt{5}x^2 + \sqrt{7}x + \sqrt{11}$, show that $a$ is algebraic over $\mathbb{Q}$ of degree at most 80.

\begin{proof}

    Given $a \in \mathbb{C}$ such that $p(a)=0$, where

$$

p(x)=x^5+\sqrt{2} x^3+\sqrt{5} x^2+\sqrt{7} x+\sqrt{11}

$$

Here, we note that $p(x) \in \mathbb{Q}(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11})$ and

$$

\begin{aligned}

    {[Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11}): \mathbb{Q}] } & =[Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11}): Q(\sqrt{2}, \sqrt{5}, \sqrt{7})] \cdot[\mathbb{Q}(\sqrt{2}, \sqrt{5}, \sqrt{7}): \mathbb{Q}(\sqrt{2}, \sqrt{5})] \\

& \cdot[\mathbb{Q}(\sqrt{2}, \sqrt{5}): \mathbb{Q}(\sqrt{2})] \cdot[\mathbb{Q}(\sqrt{2}): \mathbb{Q}] \\

& =2 \cdot 2 \cdot 2 \cdot 2 \\

& =16

\end{aligned}

$$

Here, we note that $p(x)$ is of degree 5 over $\mathbb{Q}(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11})$. If $a$ is root of $p(x)$, then

$$

[Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11}, a): \mathbb{Q}]=[Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11}): Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11})] \cdot 15

$$

and $[Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11}): Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11})] \leq 5$. We get equality if $p(x)$ is irreducible over $Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11})$. This gives

$$

[Q(\sqrt{2}, \sqrt{5}, \sqrt{7}, \sqrt{11}, a): \mathbb{Q}] \leq 16 \cdot 5=80

$$

\end{proof}


theorem exercise_5_6_14 {p m n: ℕ} (hp : nat.prime p) {F : Type*}
  [field F] [char_p F p] (hm : m = p ^ n) :
  card (root_set (X ^ m - X : polynomial F) F) = m :=

If $F$ is of characteristic $p \neq 0$, show that all the roots of $x^m - x$, where $m = p^n$, are distinct.

\begin{proof}

    Let us consider $f(x)=x^m-x$. Then $f \in F[x]$.

Claim: $f(x)$ has a multiple root in some extension of $F$ if and only if $f(x)$ is not relatively prime to its formal derivative, $f^{\prime}(x)$.

Proof of the Claim: Let us assume that $f(x)$ has a multiple root in some extension of $F$. Let $y$ be a multiple root of $f(x)$. Then over a splitting field, we have

$$

f(x)=(x-y)^n g(x), \text { for some integer } n \geq 2 .

$$

Here $g(x)$ is a polynomial such that $g(y) \neq 0$. Now taking derivative of $f$ we get

$$

f^{\prime}(x)=n \cdot(x-y)^{n-1} g(x)+(x-y)^n g^{\prime}(x)

$$

here $g^{\prime}(x)$ implies derivative of $g$ with respect to $x$. Since we have $n \geq 2$, this implies $(n-1) \geq 1$. Hence, (1) shows that $f^{\prime}(x)$ has $y$ as a root. Therefore, $f(x)$ is not relatively prime to $f^{\prime}(x)$. We now prove the other direction.

Conversely, let us assume that $f(x)$ is not relatively prime to $f^{\prime}(x)$. Let $y$ is a root of both $f(x)$ and $f^{\prime}(x)$. Since $y$ is a root of $f(x)$, we can write

$$

f(x)=(x-y) \cdot g(x)

$$

for some polynomial $g(x)$. then taking derivative of $f(x)$ we have

$$

f^{\prime}(x)=g(x)+(x-y) \cdot g^{\prime}(x)

$$

where $g^{\prime}(x)$ is the derivative of $g(x)$ with respect to $x$. Since $y$ is a root of $f^{\prime}(x)$ also we have

$$

f^{\prime}(y)=0

$$

Then we have

$$

\begin{aligned}

& f^{\prime}(y)=g(y)+(y-y) \cdot g^{\prime}(y) \\

\Longrightarrow & f^{\prime}(y)=g(y) \\

\Longrightarrow & g(y)=0 .

\end{aligned}

$$

This implies $y$ is a root of $g(x)$ also. Therefore we have

$$

g(x)=(x-y) \cdot h(x)

$$

for some polynomial $h(x)$. Now form (2) we have

$$

f(x)=(x-y)^2 \cdot h(x) .

$$

This follows that $y$ is a multiple root of $f(x)$. Therefore, $f(x)$ has a multiple root in some extension of the field $F$. This completes the proof of the Claim.

In our case, $f(x)=x^m-x$, where $m=p^n$. Now we calculate the derivative of $f$. That is

$$

f^{\prime}(x)=m x^{m-1}-1=-1(\bmod p) .

$$

By the above condition it follows that, $f^{\prime}$ has no root same as $f$, that is, $f(x)$ and $f^{\prime}(x)$ are relatively prime. Hence, $f(x)$ has no multiple root in $F$. Since $f(x)=x^m-x$ is a polynomial of degree $m$, it follows that $f(x)$ has $m$ distinct roots in $F$, where $m=p^n$. This completes the proof.

\end{proof}


theorem exercise_2_26 {M : Type*} [topological_space M]
  (U : set M) : is_open U ↔ ∀ x ∈ U, ¬ cluster_pt x (𝓟 Uᶜ) :=

import .common

open set real filter function ring_hom topological_space

open_locale big_operators
open_locale filter
open_locale topology
noncomputable theory

Prove that a set $U \subset M$ is open if and only if none of its points are limits of its complement.

\begin{proof}

    Assume that none of the points of $U$ are limits of its complement, and let us prove that $U$ is open. Assume by contradiction that $U$ is not open, so there exists $p \in M$ so that $\forall r>0$ there exists $q \in M$ with $d(p, q)<r$ but $q \notin U$. Applying this to $r=1 / n$ we obtain $q_n \in U^c$ such that $d\left(q_n, p\right)<1 / n$. But then $q_n \rightarrow p$ and $p$ is a limit of a sequence of points in $U^c$, a contradiction.

Assume now that $U$ is open. Assume by contradiction there exists $p \in U$ and $p_n \in U^c$ such that $p_n \rightarrow p$. Since $U$ is open, there exists $r>0$ such that $d(p, x)<r$ for $x \in M$ implies $x \in U$. But since $p_n \rightarrow p$, there exists $n_0 \in \mathbb{N}$ such that $n \geq n_0$ implies $d\left(p_n, p\right)<r$, therefore $p_n \in U$ for $n \geq n_0$, a contradiction since $p_n \in U^c$.

\end{proof}


theorem exercise_2_32a (A : set ℕ) : is_clopen A :=

Show that every subset of $\mathbb{N}$ is clopen.

\begin{proof}

    32. The one-point set $\{n\} \subset \mathbb{N}$ is open, since it contains all $m \in \mathbb{N}$ that satisfy $d(m, n)<\frac{1}{2}$. Every subset of $\mathbb{N}$ is a union of one-point sets, hence is open. Then every set it closed, since its complement is necessarily open.

\end{proof}


theorem exercise_2_46 {M : Type*} [metric_space M]
  {A B : set M} (hA : is_compact A) (hB : is_compact B)
  (hAB : disjoint A B) (hA₀ : A ≠ ∅) (hB₀ : B ≠ ∅) :
  ∃ a₀ b₀, a₀ ∈ A ∧ b₀ ∈ B ∧ ∀ (a : M) (b : M),
  a ∈ A → b ∈ B → dist a₀ b₀ ≤ dist a b :=

Assume that $A, B$ are compact, disjoint, nonempty subsets of $M$. Prove that there are $a_0 \in A$ and $b_0 \in B$ such that for all $a \in A$ and $b \in B$ we have $d(a_0, b_0) \leq d(a, b)$.

\begin{proof}

Let $A$ and $B$ be compact, disjoint and non-empty subsets of $M$. We want to show that there exist $a_0 \in A, b_0 \in B$ such that for all $a \in A, b \in B$,

$$

d\left(a_0, b_0\right) \leq d(a, b) .

$$

We saw in class that the distance function $d: M \times M \rightarrow \mathbb{R}$ is continuous. We also saw in class that any continuous, real-valued function assumes maximum and minimum values on a compact set. Since $A$ and $B$ are compact, $A \times B$ is (non-empty) compact in $M \times M$. Therefore there exists $\left(a_0, b_0\right) \in A \times B$ such that $d\left(a_0, b_0\right) \leq d(a, b), \forall(a, b) \in A \times B$.

\end{proof}


theorem exercise_2_92 {α : Type*} [topological_space α]
  {s : ℕ → set α}
  (hs : ∀ i, is_compact (s i))
  (hs : ∀ i, (s i).nonempty)
  (hs : ∀ i, (s i) ⊃ (s (i + 1))) :
  (⋂ i, s i).nonempty :=

Give a direct proof that the nested decreasing intersection of nonempty covering compact sets is nonempty.

\begin{proof}

    Let

$$

A_1 \supset A_2 \supset \cdots \supset A_n \supset \cdots

$$

be a nested decreasing sequence of compacts. Suppose that $\bigcap A_n=\emptyset$. Take $U_n=A_n^c$, then

$$

\bigcup U_n=\bigcup A_n^c=\left(\bigcap A_n\right)^c=A_1 .

$$

Here, I'm thinking of $A_1$ as the main metric space. Since $\left\{U_n\right\}$ is an open covering of $A_1$, we can extract a finite subcovering, that is,

$$

A_{\alpha_1}^c \cup A_{\alpha_2}^c \cup \cdots \cup A_{\alpha_m}^c \supset A_1

$$

or

$$

\left(A_1 \backslash A_{\alpha_1}\right) \cup\left(A_1 \backslash A_{\alpha_2}\right) \cup \cdots \cup\left(A_1 \backslash A_{\alpha_m}\right) \supset A_1 .

$$

But, this is true only if $A_{\alpha_i}=\emptyset$ for some $i$, a contradiction.

\end{proof}


theorem exercise_3_1 {f : ℝ → ℝ}
  (hf : ∀ x y, |f x - f y| ≤ |x - y| ^ 2) :
  ∃ c, f = λ x, c :=

Assume that $f \colon \mathbb{R} \rightarrow \mathbb{R}$ satisfies $|f(t)-f(x)| \leq|t-x|^{2}$ for all $t, x$. Prove that $f$ is constant.

\begin{proof}

    We have $|f(t)-f(x)| \leq|t-x|^2, \forall t, x \in \mathbb{R}$. Fix $x \in \mathbb{R}$ and let $t \neq x$. Then

$$

\left|\frac{f(t)-f(x)}{t-x}\right| \leq|t-x| \text {, hence } \lim _{t \rightarrow x}\left|\frac{f(t)-f(x)}{t-x}\right|=0 \text {, }

$$

so $f$ is differentiable in $\mathbb{R}$ and $f^{\prime}=0$. This implies that $f$ is constant, as seen in class.

\end{proof}


theorem exercise_3_63a (p : ℝ) (f : ℕ → ℝ) (hp : p > 1)
  (h : f = λ k, (1 : ℝ) / (k * (log k) ^ p)) :
  ∃ l, tendsto f at_top (𝓝 l) :=

Prove that $\sum 1/k(\log(k))^p$ converges when $p > 1$.

\begin{proof}

    Using the integral test, for a set $a$, we see

$$

\lim _{b \rightarrow \infty} \int_a^b \frac{1}{x \log (x)^c} d x=\lim _{b \rightarrow \infty}\left(\frac{\log (b)^{1-c}}{1-c}-\frac{\log (a)^{1-c}}{1-c}\right)

$$

which goes to infinity if $c \leq 1$ and converges if $c>1$. Thus,

$$

\sum_{n=2}^{\infty} \frac{1}{n \log (n)^c}

$$

converges if and only if $c>1$.

\end{proof}


theorem exercise_4_15a {α : Type*}
  (a b : ℝ) (F : set (ℝ → ℝ)) :
  (∀ (x : ℝ) (ε > 0), ∃ (U ∈ (𝓝 x)),
  (∀ (y z ∈ U) (f : ℝ → ℝ), f ∈ F → (dist (f y) (f z) < ε)))
  ↔
  ∃ (μ : ℝ → ℝ), ∀ (x : ℝ), (0 : ℝ) ≤ μ x ∧ tendsto μ (𝓝 0) (𝓝 0) ∧
  (∀ (s t : ℝ) (f : ℝ → ℝ), f ∈ F → |(f s) - (f t)| ≤ μ (|s - t|)) :=

A continuous, strictly increasing function $\mu \colon (0, \infty) \rightarrow (0, \infty)$ is a modulus of continuity if $\mu(s) \rightarrow 0$ as $s \rightarrow 0$. A function $f \colon [a, b] \rightarrow \mathbb{R}$ has modulus of continuity $\mu$ if $|f(s) - f(t)| \leq \mu(|s - t|)$ for all $s, t \in [a, b]$. Prove that a function is uniformly continuous if and only if it has a modulus of continuity.

\begin{proof}

    Suppose there exists a modulus of continuity $w$ for $f$, then fix $\varepsilon>0$, since $\lim _{s \rightarrow 0} w(s)=0$, there exists $\delta>0$ such that for any $|s|<\delta$, we have $w(s)<\varepsilon$, then we have for any $x, z \in X$ such that $d_X(x, z)<\delta$, we have $d_Y(f(x), f(z)) \leq w\left(d_X(x, z)\right)<\varepsilon$, which means $f$ is uniformly continuous.

Suppose $f:\left(X, d_X\right) \rightarrow\left(Y, d_Y\right)$ is uniformly continuous.

Let $\delta_1>0$ be such that $d_X(a, b)<\delta_1$ implies $d_Y(f(a), f(b))<1$.

Define $w:[0, \infty) \rightarrow[0, \infty]$ by

$$

w(s)= \begin{cases}\left.\sup \left\{d_Y(f(a), f(b))\right\} \mid d_X(a, b) \leq s\right\} & \text { if } s \leq \delta_1 \\ \infty & \text { if } s>\delta_1\end{cases}

$$

We'll show that $w$ is a modulus of continuity for $f \ldots$

By definition of $w$, it's immediate that $w(0)=0$ and it's clear that

$$

d_Y(f(a), f(b)) \leq w\left(d_X(a, b)\right)

$$

for all $a, b \in X$.

It remains to show $\lim _{s \rightarrow 0^{+}} w(s)=0$.

It's easily seen that $w$ is nonnegative and non-decreasing, hence $\lim _{s \rightarrow 0^{+}}=L$ for some $L \geq 0$, where $L=\inf w((0, \infty))$

Let $\epsilon>0$.

By uniform continuity of $f$, there exists $\delta>0$ such that $d_X(a, b)<\delta$ implies $d_Y(f(a), f(b))<\epsilon$, hence by definition of $w$, we get $w(\delta) \leq \epsilon$.

Thus $L \leq \epsilon$ for all $\epsilon>0$, hence $L=0$.

This completes the proof.

\end{proof}


theorem exercise_2_3_2 {G : Type*} [group G] (a b : G) :
  ∃ g : G, b* a = g * a * b * g⁻¹ :=

import .common

open function fintype subgroup ideal polynomial submodule zsqrtd char_p
open_locale big_operators
noncomputable theory

Prove that the products $a b$ and $b a$ are conjugate elements in a group.

\begin{proof}

    We have that $(a^{-1})ab(a^{-1})^{-1} = ba$.

\end{proof}


theorem exercise_2_8_6 {G H : Type*} [group G] [group H] :
  center (G × H) ≃* (center G) × (center H) :=

Prove that the center of the product of two groups is the product of their centers.

\begin{proof}

    We have that $(g_1, g_2)\cdot (h_1, h_2) = (h_1, h_2)\cdot (g_1, g_2)$ if and only if $g_1h_1 = h_1g_1$ and $g_2h_2 = h_2g_2$.

\end{proof}


theorem exercise_3_2_7 {F : Type*} [field F] {G : Type*} [field G]
  (φ : F →+* G) : injective φ :=

Prove that every homomorphism of fields is injective.

\begin{proof}

    Suppose $f(a)=f(b)$, then $f(a-b)=0=f(0)$. If $u=(a-b) \neq 0$, then $f(u) f\left(u^{-1}\right)=f(1)=1$, but that means that $0 f\left(u^{-1}\right)=1$, which is impossible. Hence $a-b=0$ and $a=b$.

\end{proof}


theorem exercise_3_7_2 {K V : Type*} [field K] [add_comm_group V]
  [module K V] {ι : Type*} [fintype ι] (γ : ι → submodule K V) :
  (⋂ (i : ι), (γ i : set V)) ≠ ⊤ :=

Let $V$ be a vector space over an infinite field $F$. Prove that $V$ is not the union of finitely many proper subspaces.

\begin{proof}

    If $V$ is the set-theoretic union of $n$ proper subspaces $W_i$ ( $1 \leq i \leq n$ ), then $|F| \leq n-1$.

Proof. We may suppose no $W_i$ is contained in the union of the other subspaces. Let $u \in W_i, \quad u \notin \bigcup_{j \neq i} W_j$ and $v \notin W_i$.

Then $(v+F u) \cap W_i=\varnothing$ and $(v+F u) \cap W_j(j \neq i)$ contains at most one vector since otherwise $W_j$ would contain $u$. Hence

$$

|v+F u|=|F| \leq n-1 .

$$

Corollary: Avoidance lemma for vector spaces.

Let $E$ be a vector space over an infinite field. If a subspace is contained in a finite union of subspaces, it is contained in one of them.

\end{proof}


theorem exercise_6_4_2 {G : Type*} [group G] [fintype G] {p q : ℕ}
  (hp : prime p) (hq : prime q) (hG : card G = p*q) :
  is_simple_group G → false :=

Prove that no group of order $p q$, where $p$ and $q$ are prime, is simple.

\begin{proof}

    If $|G|=n=p q$ then the only two Sylow subgroups are of order $p$ and $q$.

From Sylow's third theorem we know that $n_p \mid q$ which means that $n_p=1$ or $n_p=q$.

If $n_p=1$ then we are done (by a corollary of Sylow's theorem)

If $n_p=q$ then we have accounted for $q(p-1)=p q-q$ elements of $G$ and so there is only one group of order $q$ and again we are done.

\end{proof}


theorem exercise_6_4_12 {G : Type*} [group G] [fintype G]
  (hG : card G = 224) :
  is_simple_group G → false :=

Prove that no group of order 224 is simple.

\begin{proof}

    The following proves there must exist a normal Sylow 2 -subgroup of order 32 ,

Suppose there are $n_2=7$ Sylow 2 -subgroups in $G$. Making $G$ act on the set of these Sylow subgroups by conjugation (Mitt wrote about this but on the set of the other Sylow subgroups, which gives no contradiction), we get a homomorphism $G \rightarrow S_7$ which must be injective if $G$ is simple (why?).

But this cannot be since then we would embed $G$ into $S_7$, which is impossible since $|G| \nmid 7 !=\left|S_7\right|$ (why?)

\end{proof}


theorem exercise_10_1_13 {R : Type*} [ring R] {x : R}
  (hx : is_nilpotent x) : is_unit (1 + x) :=

An element $x$ of a ring $R$ is called nilpotent if some power of $x$ is zero. Prove that if $x$ is nilpotent, then $1+x$ is a unit in $R$.


theorem exercise_10_6_7 {I : ideal gaussian_int}
  (hI : I ≠ ⊥) : ∃ (z : I), z ≠ 0 ∧ (z : gaussian_int).im = 0 :=

Prove that every nonzero ideal in the ring of Gauss integers contains a nonzero integer.

\begin{proof}

    Let $I$ be some nonzero ideal. Then there exists some $z \in \mathbb{Z}[i], z \neq 0$ such that $z \in I$. We know that $z=a+b i$, for some $a, b \in \mathbb{Z}$. We consider three cases:

1. If $b=0$, then $z=a$, so $z \in \mathbb{Z} \cap I$, and $z \neq 0$, so the statement of the exercise holds.

2. If $a=0$, then $z=i b$. Since $z \neq 0$, we conclude that $b \neq 0$. Since $I$ is an ideal in $\mathbb{Z}[i]$, and $i \in \mathbb{Z}[i]$, we conclude that $i z \in I$. Furthermore, $i z=-b \in \mathbb{Z}$. Thus, $i z$ is a nonzero integer which is in $I$.

3. Let $a \neq 0$ and $b \neq 0$. Since $I$ is an ideal and $z \in I$, we conclude that $z^2 \in I$; that is,

$$

(a+b i)^2=a^2-b^2+2 a b i \in I

$$

Furthermore, since $-2 a \in \mathbb{Z}[i]$, and $z \in I$ and $I$ is an ideal, $-2 a z \in I$; that is,

$$

-2 a z=-2 a(a+b i)=-2 a^2-2 a b i \in I

$$

Since $I$ is closed under addition,

$$

\left(a^2-b^2+2 a b i\right)+\left(-2 a^2-2 a b i\right) \in I \Longrightarrow-a^2-b^2 \in I

$$

Notice that $-a^2-b^2 \neq 0$ since $a^2>0$ and $b^2>0$, so $-a^2-b^2<0$. Furthermore, it is an integer. Thus, we have found a nonzero integer in $I$.

\end{proof}


theorem exercise_10_4_7a {R : Type*} [comm_ring R] [no_zero_divisors R]
  (I J : ideal R) (hIJ : I + J = ⊤) : I * J = I ⊓ J :=

Let $I, J$ be ideals of a ring $R$ such that $I+J=R$. Prove that $I J=I \cap J$.

\begin{proof}

    We have seen that $IJ \subset I \cap J$, so it remains to show that $I \cap J \subset IJ$.  Since $I+J = (1)$, there are elements $i \in I$ and $j \in J$ such that $i+j = 1$.  Let $k \in I \cap J$, and multiply $i+j=1$ through by $k$ to get $ki+kj = k$.  Write this more suggestively as

\[ k = ik+kj. \]

The first term is in $IJ$ because $k \in J$, and the second term is in $IJ$ because $k \in I$, so $k \in IJ$ as desired.

\end{proof}


theorem exercise_11_2_13 (a b : ℤ) :
  (of_int a : gaussian_int) ∣ of_int b → a ∣ b :=

If $a, b$ are integers and if $a$ divides $b$ in the ring of Gauss integers, then $a$ divides $b$ in $\mathbb{Z}$.

\begin{proof}

    Suppose $a|b$ in $\mathbb{Z}[i]$ and $a,b\in\mathbb{Z}$. Then $a(x+yi)=b$ for $x,y\in\mathbb{Z}$. Expanding this we get $ax+ayi=b$, and equating imaginary parts gives us $ay=0$, implying $y=0$.

\end{proof}


theorem exercise_11_4_6a {F : Type*} [field F] [fintype F] (hF : card F = 7) :
  irreducible (X ^ 2 + 1 : polynomial F) :=

Prove that $x^2+x+1$ is irreducible in the field $\mathbb{F}_2$.

\begin{proof}

    If $x^2+x+1$ were reducible in $\mathbb{F}_2$, its factors must be linear. But we neither have that $0^2+0+1=$ nor $1^2+1+1=0$, therefore $x^2+x+1$ is irreducible.

\end{proof}


theorem exercise_11_4_6c : irreducible (X^3 - 9 : polynomial (zmod 31)) :=

Prove that $x^3 - 9$ is irreducible in $\mathbb{F}_{31}$.

\begin{proof}

    If $p(x) = x^3-9$ were reducible, it would have a linear factor, since it either has a linear factor and a quadratic factor or three linear factors. We can then verify by brute force that $p(x)\neq 0$ for $x \in \mathbb{F}_31$.

\end{proof}


theorem exercise_11_13_3 (N : ℕ):
  ∃ p ≥ N, nat.prime p ∧ p + 1 ≡ 0 [MOD 4] :=

Prove that there are infinitely many primes congruent to $-1$ (modulo $4$).

\begin{proof}

    First we show a lemma: if $a \equiv 3(\bmod 4)$ then there exists a prime $p$ such that $p \mid a$ and $p \equiv 3(\bmod 4)$.

    Clearly, all primes dividing $a$ are odd. Suppose all of them would be $\equiv 1(\bmod 4)$. Then their product would also be $a \equiv 1(\bmod 4)$, which is a contradiction.

To prove the main claim, suppose that $p_1, \ldots, p_n$ would be all such primes. (In particular, we have $p_1=3$.) Consider $a=4 p_2 \cdots p_n+3$. (Or you can take $a=4 p_2 \cdots p_n-1$.) Show that $p_i \nmid a$ for $i=1, \ldots, n$. (The case $3 \nmid a$ is solved differently than the other primes - this is the reason for omitting $p_1$ in the definition of $a$.) Then use the above lemma to get a contradiction.

\end{proof}


theorem exercise_13_6_10 {K : Type*} [field K] [fintype Kˣ] :
  ∏ (x : Kˣ), x = -1 :=

Let $K$ be a finite field. Prove that the product of the nonzero elements of $K$ is $-1$.

\begin{proof}

    Since we are working with a finite field with $q$ elements, anyone of them is a root of the following polynomial

$$

x^q-x=0 .

$$

In particular if we rule out the 0 element, any $a_i \neq 0$ is a root of

$$

x^{q-1}-1=0 .

$$

This polynomial splits completely in $\mathbb{F}_q$ so we find

$$

\left(x-a_1\right) \cdots\left(x-a_{q-1}\right)=0

$$

in particular

$$

x^{q-1}-1=\left(x-a_1\right) \cdots\left(x-a_{q-1}\right)

$$

Thus $a_1 \cdots a_{q-1}=-1$.

\end{proof}


theorem exercise_2018_a5 (f : ℝ → ℝ) (hf : cont_diff ℝ ⊤ f)
  (hf0 : f 0 = 0) (hf1 : f 1 = 1) (hf2 : ∀ x, f x ≥ 0) :
  ∃ (n : ℕ) (x : ℝ), iterated_deriv n f x = 0 :=

import .common

open real topological_space filter polynomial
open_locale topology big_operators complex_conjugate filter ennreal

Let $f: \mathbb{R} \rightarrow \mathbb{R}$ be an infinitely differentiable function satisfying $f(0)=0, f(1)=1$, and $f(x) \geq 0$ for all $x \in$ $\mathbb{R}$. Show that there exist a positive integer $n$ and a real number $x$ such that $f^{(n)}(x)<0$.

\begin{proof}

    Call a function $f\colon \mathbb{R} \to \mathbb{R}$ \textit{ultraconvex} if $f$ is infinitely differentiable and $f^{(n)}(x) \geq 0$ for all $n \geq 0$ and all $x \in \mathbb{R}$, where $f^{(0)}(x) = f(x)$;

note that if $f$ is ultraconvex, then so is $f'$.

Define the set

\[

S = \{ f :\thinspace \mathbb{R} \to \mathbb{R} \,|\,f \text{ ultraconvex and } f(0)=0\}.

\]

For $f \in S$, we must have $f(x) = 0$ for all $x < 0$: if $f(x_0) > 0$ for some $x_0 < 0$, then

by the mean value theorem there exists $x \in (0,x_0)$ for which $f'(x) = \frac{f(x_0)}{x_0} < 0$.

In particular, $f'(0) = 0$, so $f' \in S$ also.

We show by induction that for all $n \geq 0$,

\[

f(x) \leq \frac{f^{(n)}(1)}{n!} x^n \qquad (f \in S, x \in [0,1]).

\]

We induct with base case $n=0$, which holds because any $f \in S$ is nondecreasing. Given the claim for $n=m$,

we apply the induction hypothesis to $f' \in S$ to see that

\[

f'(t) \leq \frac{f^{(n+1)}(1)}{n!} t^n \qquad (t \in [0,1]),

\]

then integrate both sides from $0$ to $x$ to conclude.

Now for $f \in S$, we have $0 \leq f(1) \leq \frac{f^{(n)}(1)}{n!}$ for all $n \geq 0$.

On the other hand, by Taylor's theorem with remainder,

\[

f(x) \geq \sum_{k=0}^n \frac{f^{(k)}(1)}{k!}(x-1)^k \qquad (x \geq 1).

\]

Applying this with $x=2$, we obtain $f(2) \geq \sum_{k=0}^n \frac{f^{(k)}(1)}{k!}$ for all $n$;

this implies that $\lim_{n\to\infty}  \frac{f^{(n)}(1)}{n!} = 0$.

Since $f(1) \leq \frac{f^{(n)}(1)}{n!}$, we must have $f(1) = 0$.

For $f \in S$, we proved earlier that $f(x) = 0$ for all $x\leq 0$, as well as for $x=1$. Since

the function $g(x) = f(cx)$ is also ultraconvex for $c>0$, we also have $f(x) = 0$ for all $x>0$;

hence $f$ is identically zero.

To sum up, if $f\colon \mathbb{R} \to \mathbb{R}$ is infinitely differentiable, $f(0)=0$, and $f(1) = 1$,

then $f$ cannot be ultraconvex. This implies the desired result.

\end{proof}


theorem exercise_2018_b4 (a : ℝ) (x : ℕ → ℝ) (hx0 : x 0 = a)
  (hx1 : x 1 = a)
  (hxn : ∀ n : ℕ, n ≥ 2 → x (n+1) = 2*(x n)*(x (n-1)) - x (n-2))
  (h : ∃ n, x n = 0) :
  ∃ c, function.periodic x c :=

Given a real number $a$, we define a sequence by $x_{0}=1$, $x_{1}=x_{2}=a$, and $x_{n+1}=2 x_{n} x_{n-1}-x_{n-2}$ for $n \geq 2$. Prove that if $x_{n}=0$ for some $n$, then the sequence is periodic.

\begin{proof}

    We first rule out the case $|a|>1$. In this case, we prove that $|x_{n+1}| \geq |x_n|$ for all $n$, meaning that we cannot have $x_n = 0$. We proceed by induction; the claim is true for $n=0,1$ by hypothesis. To prove the claim for  $n \geq 2$, write

\begin{align*}

|x_{n+1}| &= |2x_nx_{n-1}-x_{n-2}| \\

&\geq 2|x_n||x_{n-1}|-|x_{n-2}| \\

&\geq |x_n|(2|x_{n-1}|-1) \geq |x_n|,

\end{align*}

where the last step follows from $|x_{n-1}| \geq |x_{n-2}| \geq \cdots \geq |x_0| = 1$.

We may thus assume hereafter that $|a|\leq 1$. We can then write $a = \cos b$ for some $b \in [0,\pi]$.

Let $\{F_n\}$ be the Fibonacci sequence, defined as usual by $F_1=F_2=1$ and $F_{n+1}=F_n+F_{n-1}$. We show by induction that

\[

x_n = \cos(F_n b) \qquad (n \geq 0).

\]

Indeed, this is true for $n=0,1,2$; given that it is true for $n \leq m$, then

\begin{align*}

2x_mx_{m-1}&=2\cos(F_mb)\cos(F_{m-1}b) \\

&= \cos((F_m-F_{m-1})b)+\cos((F_m+F_{m-1})b) \\

&= \cos(F_{m-2}b)+\cos(F_{m+1}b)

\end{align*}

and so

$x_{m+1} = 2x_mx_{m-1}-x_{m-2} = \cos(F_{m+1}b)$. This completes the induction.

Since $x_n = \cos(F_n b)$, if $x_n=0$ for some $n$ then $F_n b = \frac{k}{2} \pi$ for some odd integer $k$. In particular, we can write $b = \frac{c}{d}(2\pi)$ where $c = k$ and $d = 4F_n$ are integers.

Let $x_n$ denote the pair $(F_n,F_{n+1})$, where each entry in this pair is viewed as an element of $\mathbb{Z}/d\mathbb{Z}$. Since there are only finitely many possibilities for $x_n$, there must be some $n_2>n_1$ such that $x_{n_1}=x_{n_2}$. Now $x_n$ uniquely determines both $x_{n+1}$ and $x_{n-1}$, and it follows that the sequence $\{x_n\}$ is periodic: for $\ell = n_2-n_1$, $x_{n+\ell} = x_n$ for all $n \geq 0$. In particular, $F_{n+\ell} \equiv F_n \pmod{d}$ for all $n$. But then $\frac{F_{n+\ell}c}{d}-\frac{F_n c}{d}$ is an integer, and so

\begin{align*}

x_{n+\ell} &= \cos\left(\frac{F_{n+\ell}c}{d}(2\pi)\right)\\

& = \cos\left(\frac{F_n c}{d}(2\pi)\right) = x_n

\end{align*}

for all $n$. Thus the sequence $\{x_n\}$ is periodic, as desired.

\end{proof}


theorem exercise_2014_a5 (P : ℕ → polynomial ℤ)
  (hP : ∀ n, P n = ∑ (i : fin n), (n+1) * X ^ n) :
  ∀ (j k : ℕ), j ≠ k → is_coprime (P j) (P k) :=


Prove that there are unique positive integers $a, n$ such that $a^{n+1}-(a+1)^n=2001$.

\begin{proof}

    Suppose $a^{n+1} - (a+1)^n = 2001$.

Notice that $a^{n+1} + [(a+1)^n - 1]$ is a multiple of $a$; thus

$a$ divides $2002 = 2 \times 7 \times 11 \times 13$.

Since $2001$ is divisible by 3, we must have $a \equiv 1 \pmod{3}$,

otherwise one of $a^{n+1}$ and $(a+1)^n$ is a multiple of 3 and the

other is not, so their difference cannot be divisible by 3. Now

$a^{n+1} \equiv 1 \pmod{3}$, so we must have $(a+1)^n \equiv 1

\pmod{3}$, which forces $n$ to be even, and in particular at least 2.

If $a$ is even, then $a^{n+1} - (a+1)^n \equiv -(a+1)^n \pmod{4}$.

Since $n$ is even, $-(a+1)^n \equiv -1 \pmod{4}$. Since $2001 \equiv 1

\pmod{4}$, this is impossible. Thus $a$ is odd, and so must divide

$1001 = 7 \times 11 \times 13$. Moreover, $a^{n+1} - (a+1)^n \equiv a

\pmod{4}$, so $a \equiv 1 \pmod{4}$.

Of the divisors of $7 \times 11 \times 13$, those congruent to 1 mod 3

are precisely those not divisible by 11 (since 7 and 13 are both

congruent to 1 mod 3). Thus $a$ divides $7 \times 13$. Now

$a \equiv 1 \pmod{4}$ is only possible if $a$ divides $13$.

We cannot have $a=1$, since $1 - 2^n \neq 2001$ for any $n$. Thus

the only possibility is $a = 13$. One easily checks that $a=13, n=2$ is a

solution; all that remains is to check that no other $n$ works. In fact,

if $n > 2$, then $13^{n+1} \equiv 2001 \equiv 1 \pmod{8}$.

But $13^{n+1} \equiv 13 \pmod{8}$ since $n$ is even, contradiction.

Thus $a=13, n=2$ is the unique solution.

Note: once one has that $n$ is even, one can use that $2002

=a^{n+1} + 1 - (a+1)^n$ is divisible by $a+1$ to rule out cases.

\end{proof}


theorem exercise_1999_b4 (f : ℝ → ℝ) (hf: cont_diff ℝ 3 f)
  (hf1 : ∀ (n ≤ 3) (x : ℝ), iterated_deriv n f x > 0)
  (hf2 : ∀ x : ℝ, iterated_deriv 3 f x ≤ f x) :
  ∀ x : ℝ, deriv f x < 2 * f x :=

Let $f$ be a real function with a continuous third derivative such that $f(x), f^{\prime}(x), f^{\prime \prime}(x), f^{\prime \prime \prime}(x)$ are positive for all $x$. Suppose that $f^{\prime \prime \prime}(x) \leq f(x)$ for all $x$. Show that $f^{\prime}(x)<2 f(x)$ for all $x$.

\begin{proof}

\setcounter{equation}{0}

We make repeated use of the following fact: if $f$ is a differentiable function on all of

$\mathbb{R}$, $\lim_{x \to -\infty} f(x) \geq 0$, and $f'(x) > 0$ for all $x \in \mathbb{R}$, then

$f(x) > 0$ for all $x \in \mathbb{R}$. (Proof: if $f(y) < 0$ for some $x$, then $f(x)< f(y)$ for all

$x<y$ since $f'>0$, but then $\lim_{x \to -\infty} f(x) \leq f(y) < 0$.)

From the inequality $f'''(x) \leq f(x)$ we obtain

\[

f'' f'''(x) \leq f''(x) f(x) < f''(x) f(x) + f'(x)^2

\]

since $f'(x)$ is positive. Applying the fact to the difference between the right and left sides,

we get

\begin{equation}

\frac{1}{2} (f''(x))^2 < f(x) f'(x).

\end{equation}

On the other hand, since $f(x)$ and $f'''(x)$ are both positive for all $x$,

we have

\[

2f'(x) f''(x) < 2f'(x)f''(x) + 2f(x) f'''(x).

\]

Applying the fact to the difference between the sides yields

\begin{equation}

f'(x)^2 \leq 2f(x) f''(x).

\end{equation}

Combining (1) and (2), we obtain

\begin{align*}

\frac{1}{2} \left( \frac{f'(x)^2}{2f(x)} \right)^2

&< \frac{1}{2} (f''(x))^2 \\

&< f(x) f'(x),

\end{align*}

or $(f'(x))^3 < 8 f(x)^3$. We conclude $f'(x) < 2f(x)$, as desired.

\end{proof}


theorem exercise_1998_b6 (a b c : ℤ) :
  ∃ n : ℤ, n > 0 ∧ ¬ ∃ m : ℤ, sqrt (n^3 + a*n^2 + b*n + c) = m :=

Prove that, for any integers $a, b, c$, there exists a positive integer $n$ such that $\sqrt{n^3+a n^2+b n+c}$ is not an integer.

\begin{proof}

    We prove more generally that for any polynomial $P(z)$ with integer

coefficients which is not a perfect square, there exists a positive

integer $n$ such that $P(n)$ is not a perfect square. Of course it

suffices to assume $P(z)$ has no repeated factors, which is to say $P(z)$

and its derivative $P'(z)$ are relatively prime.

In particular, if we carry out the Euclidean algorithm on $P(z)$ and $P'(z)$

without dividing, we get an integer $D$ (the discriminant of $P$) such that

the greatest common divisor of $P(n)$ and $P'(n)$ divides $D$ for any $n$.

Now there exist infinitely many primes $p$ such that $p$ divides $P(n)$ for

some $n$: if there were only finitely many, say, $p_1, \dots, p_k$, then

for any $n$ divisible by $m = P(0) p_1 p_2 \cdots p_k$, we have $P(n)

\equiv P(0) \pmod{m}$, that is, $P(n)/P(0)$ is not divisible by $p_1,

\dots, p_k$, so must be $\pm 1$, but then $P$ takes some value infinitely

many times, contradiction. In particular, we can choose some such $p$ not

dividing $D$, and choose $n$ such that $p$ divides $P(n)$. Then $P(n+kp)

\equiv P(n) + kp P'(n) (\mathrm{mod}\,p)$

(write out the Taylor series of the left side);

in particular, since $p$ does not divide $P'(n)$, we can find some $k$

such that $P(n+kp)$ is divisible by $p$ but not by $p^2$, and so

is not a perfect square.

\end{proof}


theorem exercise_1_1b
(x : ℝ)
(y : ℚ)
(h : y ≠ 0)
: ( irrational x ) -> irrational ( x * y ) :=

import .common

open real complex
open topological_space
open filter
open_locale real
open_locale topology
open_locale big_operators
open_locale complex_conjugate
open_locale filter

noncomputable theory

If $r$ is rational $(r \neq 0)$ and $x$ is irrational, prove that $rx$ is irrational.

\begin{proof}

    If $r x$ were rational, then $x=\frac{r x}{r}$ would also be rational.

\end{proof}


theorem exercise_1_4
(α : Type*) [partial_order α]
(s : set α)
(x y : α)
(h₀ : set.nonempty s)
(h₁ : x ∈ lower_bounds s)
(h₂ : y ∈ upper_bounds s)
: x ≤ y :=

Let $E$ be a nonempty subset of an ordered set; suppose $\alpha$ is a lower bound of $E$ and $\beta$ is an upper bound of $E$. Prove that $\alpha \leq \beta$.

\begin{proof}

Since $E$ is nonempty, there exists $x \in E$. Then by definition of lower and upper bounds we have $\alpha \leq x \leq \beta$, and hence by property $i i$ in the definition of an ordering, we have $\alpha<\beta$ unless $\alpha=x=\beta$.

\end{proof}


theorem exercise_1_8 : ¬ ∃ (r : ℂ → ℂ → Prop), is_linear_order ℂ r :=

Prove that no order can be defined in the complex field that turns it into an ordered field.

\begin{proof}

    By Part (a) of Proposition $1.18$, either $i$ or $-i$ must be positive. Hence $-1=i^2=(-i)^2$ must be positive. But then $1=(-1)^2$, must also be positive, and this contradicts Part $(a)$ of Proposition 1.18, since 1 and $-1$ cannot both be positive.

\end{proof}


theorem exercise_1_12 (n : ℕ) (f : ℕ → ℂ) :
  abs (∑ i in finset.range n, f i) ≤ ∑ i in finset.range n, abs (f i) :=

If $z_1, \ldots, z_n$ are complex, prove that $|z_1 + z_2 + \ldots + z_n| \leq |z_1| + |z_2| + \cdots + |z_n|$.

\begin{proof}

    We can apply the case $n=2$ and induction on $n$ to get

$$

\begin{aligned}

\left|z_1+z_2+\cdots z_n\right| &=\left|\left(z_1+z_2+\cdots+z_{n-1}\right)+z_n\right| \\

& \leq\left|z_1+z_2+\cdots+z_{n-1}\right|+\left|z_n\right| \\

& \leq\left|z_1\right|+\left|z_2\right|+\cdots+\left|z_{n-1}\right|+\left|z_n\right|

\end{aligned}

$$

\end{proof}


If $z$ is a complex number such that $|z|=1$, that is, such that $z \bar{z}=1$, compute $|1+z|^{2}+|1-z|^{2}$.


theorem exercise_1_17
  (n : ℕ)
  (x y : euclidean_space ℝ (fin n)) -- R^n
  : ‖x + y‖^2 + ‖x - y‖^2 = 2*‖x‖^2 + 2*‖y‖^2 :=

Prove that $|\mathbf{x}+\mathbf{y}|^{2}+|\mathbf{x}-\mathbf{y}|^{2}=2|\mathbf{x}|^{2}+2|\mathbf{y}|^{2}$ if $\mathbf{x} \in R^{k}$ and $\mathbf{y} \in R^{k}$.

\begin{proof}

    The proof is a routine computation, using the relation

$$

|x \pm y|^2=(x \pm y) \cdot(x \pm y)=|x|^2 \pm 2 x \cdot y+|y|^2 .

$$

If $\mathrm{x}$ and $\mathrm{y}$ are the sides of a parallelogram, then $\mathrm{x}+\mathrm{y}$ and $\mathbf{x}-\mathrm{y}$ are its diagonals. Hence this result says that the sum of the squares on the diagonals of a parallelogram equals the sum of the squares on the sides.

\end{proof}


theorem exercise_1_18b
  : ¬ ∀ (x : ℝ), ∃ (y : ℝ), y ≠ 0 ∧ x * y = 0 :=

If $k = 1$ and $\mathbf{x} \in R^{k}$, prove that there does not exist $\mathbf{y} \in R^{k}$ such that $\mathbf{y} \neq 0$ but $\mathbf{x} \cdot \mathbf{y}=0$

\begin{proof}

    Not true when $k=1$, since the product of two nonzero real numbers is nonzero.

\end{proof}


theorem exercise_2_19a {X : Type*} [metric_space X]
  (A B : set X) (hA : is_closed A) (hB : is_closed B) (hAB : disjoint A B) :
  separated_nhds A B :=

If $A$ and $B$ are disjoint closed sets in some metric space $X$, prove that they are separated.

\begin{proof}

    We are given that $A \cap B=\varnothing$. Since $A$ and $B$ are closed, this means $A \cap \bar{B}=\varnothing=\bar{A} \cap B$, which says that $A$ and $B$ are separated.

\end{proof}


theorem exercise_2_25 {K : Type*} [metric_space K] [compact_space K] :
  ∃ (B : set (set K)), set.countable B ∧ is_topological_basis B :=

Prove that every compact metric space $K$ has a countable base.

\begin{proof}

    $K$ can be covered by a finite union of neighborhoods of radius $1 / n$, and this shows that this implies that $K$ is separable.

It is not entirely obvious that a metric space with a countable base is separable. To prove this, let $\left\{V_n\right\}_{n=1}^{\infty}$ be a countable base, and let $x_n \in V_n$. The points $V_n$ must be dense in $X$. For if $G$ is any non-empty open set, then $G$ contains $V_n$ for some $n$, and hence $x_n \in G$. (Thus for a metric space, having a countable base and being separable are equivalent.)

\end{proof}


theorem exercise_2_27b (k : ℕ) (E P : set (euclidean_space ℝ (fin k)))
  (hE : E.nonempty ∧ ¬ set.countable E)
  (hP : P = {x | ∀ U ∈ 𝓝 x, (P ∩ E).nonempty ∧ ¬ set.countable (P ∩ E)}) :
  set.countable (E \ P) :=

Suppose $E\subset\mathbb{R}^k$ is uncountable, and let $P$ be the set of condensation points of $E$. Prove that at most countably many points of $E$ are not in $P$.

\begin{proof}

    If $x \in W^c$, and $O$ is any neighborhood of $x$, then $x \in V_n \subseteq O$ for some n. Since $x \notin W, V_n \cap E$ is uncountable. Hence $O$ contains uncountably many points of $E$, and so $x$ is a condensation point of $E$. Thus $x \in P$, i.e., $W^c \subseteq P$.

Conversely if $x \in W$, then $x \in V_n$ for some $V_n$ such that $V_n \cap E$ is countable. Hence $x$ has a neighborhood (any neighborhood contained in $V_n$ ) containing at most a countable set of points of $E$, and so $x \notin P$, i.e., $W \subseteq P^c$. Hence $P=W^c$.

It is clear that $P$ is closed (since its complement $W$ is open), so that we need only show that $P \subseteq P^{\prime}$. Hence suppose $x \in P$, and $O$ is any neighborhood of $x$. (By definition of $P$ this means $O \cap E$ is uncountable.) We need to show that there is a point $y \in P \cap(O \backslash\{x\})$. If this is not the case, i.e., if every point $y$ in $O \backslash\{x\}$ is in $P^c$, then for each such point $y$ there is a set $V_n$ containing $y$ such that $V_n \cap E$ is at most countable. That would mean that $y \in W$, i.e., that $O \backslash\{x\}$ is contained in $W$. It would follow that $O \cap E \subseteq\{x\} \cup(W \cap E)$, and so $O \cap E$ contains at most a countable set of points, contrary to the hypothesis that $x \in P$. Hence $O$ contains a point of $P$ different from $x$, and so $P \subseteq P^{\prime}$. Thus $P$ is perfect.

\end{proof}


theorem exercise_2_29 (U : set ℝ) (hU : is_open U) :
  ∃ (f : ℕ → set ℝ), (∀ n, ∃ a b : ℝ, f n = {x | a < x ∧ x < b}) ∧ (∀ n, f n ⊆ U) ∧
  (∀ n m, n ≠ m → f n ∩ f m = ∅) ∧
  U = ⋃ n, f n :=

Prove that every open set in $\mathbb{R}$ is the union of an at most countable collection of disjoint segments.

\begin{proof}

    Let $O$ be open. For each pair of points $x \in O, y \in O$, we define an equivalence relation $x \sim y$ by saying $x \sim y$ if and only if $[\min (x, y), \max (x, y)] \subset$ 0 . This is an equivalence relation, since $x \sim x([x, x] \subset O$ if $x \in O)$; if $x \sim y$, then $y \sim x$ (since $\min (x, y)=\min (y, x)$ and $\max (x, y)=\max (y, x))$; and if $x \sim y$ and $y \sim z$, then $x \sim z([\min (x, z), \max (x, z)] \subseteq[\min (x, y), \max (x, y)] \cup$ $[\min (y, z), \max (y, z)] \subseteq O)$. In fact it is easy to prove that

$$

\min (x, z) \geq \min (\min (x, y), \min (y, z))

$$

and

$$

\max (x, z) \leq \max (\max (x, y), \max (y, z))

$$

It follows that $O$ can be written as a disjoint union of pairwise disjoint equivalence classes. We claim that each equivalence class is an open interval.

To show this, for each $x \in O$; let $A=\{z:[z, x] \subseteq O\}$ and $B=\{z:[x, z] \subseteq$ $O\}$, and let $a=\inf A, b=\sup B$. We claim that $(a, b) \subset O$. Indeed if $a<z<b$, there exists $c \in A$ with $c<z$ and $d \in B$ with $d>z$. Then $z \in[c, x] \cup[x, d] \subseteq O$. We now claim that $(a, b)$ is the equivalence class containing $x$. It is clear that each element of $(a, b)$ is equivalent to $x$ by the way in which $a$ and $b$ were chosen. We need to show that if $z \notin(a, b)$, then $z$ is not equivalent to $x$. Suppose that $z<a$. If $z$ were equivalent to $x$, then $[z, x]$ would be contained in $O$, and so we would have $z \in A$. Hence $a$ would not be a lower bound for $A$. Similarly if $z>b$ and $z \sim x$, then $b$ could not be an upper bound for $B$.

We have now established that $O$ is a union of pairwise disjoint open intervals. Such a union must be at most countable, since each open interval contains a rational number not in any other interval.

\end{proof}


theorem exercise_3_2a
  : tendsto (λ (n : ℝ), (sqrt (n^2 + n) - n)) at_top (𝓝 (1/2)) :=

Prove that $\lim_{n \rightarrow \infty}\sqrt{n^2 + n} -n = 1/2$.

\begin{proof}

    Multiplying and dividing by $\sqrt{n^2+n}+n$ yields

$$

\sqrt{n^2+n}-n=\frac{n}{\sqrt{n^2+n}+n}=\frac{1}{\sqrt{1+\frac{1}{n}}+1} .

$$

It follows that the limit is $\frac{1}{2}$.

\end{proof}


theorem exercise_3_5 -- TODO fix
  (a b : ℕ → ℝ)
  (h : limsup a + limsup b ≠ 0) :
  limsup (λ n, a n + b n) ≤ limsup a + limsup b :=

For any two real sequences $\left\{a_{n}\right\},\left\{b_{n}\right\}$, prove that $\limsup _{n \rightarrow \infty}\left(a_{n}+b_{n}\right) \leq \limsup _{n \rightarrow \infty} a_{n}+\limsup _{n \rightarrow \infty} b_{n},$ provided the sum on the right is not of the form $\infty-\infty$.

\begin{proof}

    Since the case when $\limsup _{n \rightarrow \infty} a_n=+\infty$ and $\limsup _{n \rightarrow \infty} b_n=-\infty$ has been excluded from consideration, we note that the inequality is obvious if $\limsup _{n \rightarrow \infty} a_n=+\infty$. Hence we shall assume that $\left\{a_n\right\}$ is bounded above.

Let $\left\{n_k\right\}$ be a subsequence of the positive integers such that $\lim _{k \rightarrow \infty}\left(a_{n_k}+\right.$ $\left.b_{n_k}\right)=\limsup _{n \rightarrow \infty}\left(a_n+b_n\right)$. Then choose a subsequence of the positive integers $\left\{k_m\right\}$ such that

$$

\lim _{m \rightarrow \infty} a_{n_{k_m}}=\limsup _{k \rightarrow \infty} a_{n_k} .

$$

The subsequence $a_{n_{k_m}}+b_{n_{k_m}}$ still converges to the same limit as $a_{n_k}+b_{n_k}$, i.e., to $\limsup _{n \rightarrow \infty}\left(a_n+b_n\right)$. Hence, since $a_{n_k}$ is bounded above (so that $\limsup _{k \rightarrow \infty} a_{n_k}$ is finite), it follows that $b_{n_{k_m}}$ converges to the difference

$$

\lim _{m \rightarrow \infty} b_{n_{k_m}}=\lim _{m \rightarrow \infty}\left(a_{n_{k_m}}+b_{n_{k_m}}\right)-\lim _{m \rightarrow \infty} a_{n_{k_m}} .

$$

Thus we have proved that there exist subsequences $\left\{a_{n_{k_m}}\right\}$ and $\left\{b_{n_{k_m}}\right\}$ which converge to limits $a$ and $b$ respectively such that $a+b=\limsup _{n \rightarrow \infty}\left(a_n+b_n^*\right)$. Since $a$ is the limit of a subsequence of $\left\{a_n\right\}$ and $b$ is the limit of a subsequence of $\left\{b_n\right\}$, it follows that $a \leq \limsup _{n \rightarrow \infty} a_n$ and $b \leq \limsup _{n \rightarrow \infty} b_n$, from which the desired inequality follows.

\end{proof}


theorem exercise_3_7
  (a : ℕ → ℝ)
  (h : ∃ y, (tendsto (λ n, (∑ i in (finset.range n), a i)) at_top (𝓝 y))) :
  ∃ y, tendsto (λ n, (∑ i in (finset.range n), sqrt (a i) / n)) at_top (𝓝 y) :=

Prove that the convergence of $\Sigma a_{n}$ implies the convergence of $\sum \frac{\sqrt{a_{n}}}{n}$ if $a_n\geq 0$.

\begin{proof}

    Since $\left(\sqrt{a_n}-\frac{1}{n}\right)^2 \geq 0$, it follows that

$$

\frac{\sqrt{a_n}}{n} \leq \frac{1}{2}\left(a_n^2+\frac{1}{n^2}\right) .

$$

Now $\Sigma a_n^2$ converges by comparison with $\Sigma a_n$ (since $\Sigma a_n$ converges, we have $a_n<1$ for large $n$, and hence $\left.a_n^2<a_n\right)$. Since $\Sigma \frac{1}{n^2}$ also converges ($p$ series, $p=2$ ), it follows that $\Sigma \frac{\sqrt{a_n}}{n}$ converges.

\end{proof}


theorem exercise_3_13
  (a b : ℕ → ℝ)
  (ha : ∃ y, (tendsto (λ n, (∑ i in (finset.range n), |a i|)) at_top (𝓝 y)))
  (hb : ∃ y, (tendsto (λ n, (∑ i in (finset.range n), |b i|)) at_top (𝓝 y))) :
  ∃ y, (tendsto (λ n, (∑ i in (finset.range n),
  λ i, (∑ j in finset.range (i + 1), a j * b (i - j)))) at_top (𝓝 y)) :=

Prove that the Cauchy product of two absolutely convergent series converges absolutely.

\begin{proof}

    Since both the hypothesis and conclusion refer to absolute convergence, we may assume both series consist of nonnegative terms. We let $S_n=\sum_{k=0}^n a_n, T_n=\sum_{k=0}^n b_n$, and $U_n=\sum_{k=0}^n \sum_{l=0}^k a_l b_{k-l}$. We need to show that $U_n$ remains bounded, given that $S_n$ and $T_n$ are bounded. To do this we make the convention that $a_{-1}=T_{-1}=0$, in order to save ourselves from having to separate off the first and last terms when we sum by parts. We then have

$$

\begin{aligned}

U_n &=\sum_{k=0}^n \sum_{l=0}^k a_l b_{k-l} \\

&=\sum_{k=0}^n \sum_{l=0}^k a_l\left(T_{k-l}-T_{k-l-1}\right) \\

&=\sum_{k=0}^n \sum_{j=0}^k a_{k-j}\left(T_j-T_{j-1}\right) \\

&=\sum_{k=0}^n \sum_{j=0}^k\left(a_{k-j}-a_{k-j-1}\right) T_j \\

&=\sum_{j=0}^n \sum_{k=j}^n\left(a_{k-j}-a_{k-j-1}\right) T_j

&=\sum_{j=0}^n a_{n-j} T_j \\

&\leq T \sum_{m=0}^n a_m \\

&=T S_n \\

&\leq S T .

\end{aligned}

$$

Thus $U_n$ is bounded, and hence approaches a finite limit.

\end{proof}


theorem exercise_3_21
  {X : Type*} [metric_space X] [complete_space X]
  (E : ℕ → set X)
  (hE : ∀ n, E n ⊃ E (n + 1))
  (hE' : tendsto (λ n, metric.diam (E n)) at_top (𝓝 0)) :
  ∃ a, set.Inter E = {a} :=

If $\left\{E_{n}\right\}$ is a sequence of closed nonempty and bounded sets in a complete metric space $X$, if $E_{n} \supset E_{n+1}$, and if $\lim _{n \rightarrow \infty} \operatorname{diam} E_{n}=0,$ then $\bigcap_{1}^{\infty} E_{n}$ consists of exactly one point.

\begin{proof}

    Choose $x_n \in E_n$. (We use the axiom of choice here.) The sequence $\left\{x_n\right\}$ is a Cauchy sequence, since the diameter of $E_n$ tends to zero as $n$ tends to infinity and $E_n$ contains $E_{n+1}$. Since the metric space $X$ is complete, the sequence $x_n$ converges to a point $x$, which must belong to $E_n$ for all $n$, since $E_n$ is closed and contains $x_m$ for all $m \geq n$. There cannot be a second point $y$ in all of the $E_n$, since for any point $y \neq x$ the diameter of $E_n$ is less $\operatorname{than} d(x, y)$ for large $n$.

\end{proof}


theorem exercise_4_1a
  : ∃ (f : ℝ → ℝ), (∀ (x : ℝ), tendsto (λ y, f(x + y) - f(x - y)) (𝓝 0) (𝓝 0)) ∧ ¬ continuous f :=

Suppose $f$ is a real function defined on $\mathbb{R}$ which satisfies $\lim_{h \rightarrow 0} f(x + h) - f(x - h) = 0$ for every $x \in \mathbb{R}$. Show that $f$ does not need to be continuous.

\begin{proof}

    $$

f(x)= \begin{cases}1 & \text { if } x \text { is an integer } \\ 0 & \text { if } x \text { is not an integer. }\end{cases}

$$

(If $x$ is an integer, then $f(x+h)-f(x-h) \equiv 0$ for all $h$; while if $x$ is not an integer, $f(x+h)-f(x-h)=0$ for $|h|<\min (x-[x], 1+[x]-x)$.

\end{proof}


theorem exercise_4_3
  {α : Type} [metric_space α]
  (f : α → ℝ) (h : continuous f) (z : set α) (g : z = f⁻¹' {0})
  : is_closed z :=

Let $f$ be a continuous real function on a metric space $X$. Let $Z(f)$ (the zero set of $f$ ) be the set of all $p \in X$ at which $f(p)=0$. Prove that $Z(f)$ is closed.

\begin{proof}

    $Z(f)=f^{-1}(\{0\})$, which is the inverse image of a closed set. Hence $Z(f)$ is closed.

\end{proof}


theorem exercise_4_4b
  {α : Type} [metric_space α]
  {β : Type} [metric_space β]
  (f g : α → β)
  (s : set α)
  (h₁ : continuous f)
  (h₂ : continuous g)
  (h₃ : dense s)
  (h₄ : ∀ x ∈ s, f x = g x)
  : f = g :=

Let $f$ and $g$ be continuous mappings of a metric space $X$ into a metric space $Y$, and let $E$ be a dense subset of $X$. Prove that if $g(p) = f(p)$ for all $p \in P$ then $g(p) = f(p)$ for all $p \in X$.

\begin{proof}

    The function $\varphi: X \rightarrow R^1$ given by

$$

\varphi(p)=d_Y(f(p), g(p))

$$

is continuous, since

$$

\left|d_Y(f(p), g(p))-d_Y(f(q), g(q))\right| \leq d_Y(f(p), f(q))+d_Y(g(p), g(q))

$$

(This inequality follows from the triangle inequality, since

$$

d_Y(f(p), g(p)) \leq d_Y(f(p), f(q))+d_Y(f(q), g(q))+d_Y(g(q), g(p)),

$$

and the same inequality holds with $p$ and $q$ interchanged. The absolute value $\left|d_Y(f(p), g(p))-d_Y(f(q), g(q))\right|$ must be either $d_Y(f(p), g(p))-d_Y(f(q), g(q))$ or $d_Y(f(q), g(q))-d_Y(f(p), g(p))$, and the triangle inequality shows that both of these numbers are at most $d_Y(f(p), f(q))+d_Y(g(p), g(q))$.)

By the previous problem, the zero set of $\varphi$ is closed. But by definition

$$

Z(\varphi)=\{p: f(p)=g(p)\} .

$$

Hence the set of $p$ for which $f(p)=g(p)$ is closed. Since by hypothesis it is dense, it must be $X$.

\end{proof}


theorem exercise_4_5b
  : ∃ (E : set ℝ) (f : ℝ → ℝ), (continuous_on f E) ∧
  (¬ ∃ (g : ℝ → ℝ), continuous g ∧ ∀ x ∈ E, f x = g x) :=

Show that there exist a set $E \subset \mathbb{R}$ and a real continuous function $f$ defined on $E$, such that there does not exist a continuous real function $g$ on $\mathbb{R}$ such that $g(x)=f(x)$ for all $x \in E$.

\begin{proof}

    Let $E:=(0,1)$, and define $f(x):=1 / x$ for all $x \in E$. If $f$ has a continuous extension $g$ to $\mathbb{R}$, then $g$ is continuous on $[-1,1]$, and therefore bounded by the intermediate value theorem. However, $f$ is not bounded in any neighborhood of $x=0$, so therefore $g$ is not bounded either, a contradiction.

\end{proof}


theorem exercise_4_8a
  (E : set ℝ) (f : ℝ → ℝ) (hf : uniform_continuous_on f E)
  (hE : metric.bounded E) : metric.bounded (set.image f E) :=

Let $f$ be a real uniformly continuous function on the bounded set $E$ in $R^{1}$. Prove that $f$ is bounded on $E$.

\begin{proof}

    Let $a=\inf E$ and $b=\sup E$, and let $\delta>0$ be such that $|f(x)-f(y)|<1$ if $x, y \in E$ and $|x-y|<\delta$. Now choose a positive integer $N$ larger than $(b-a) / \delta$, and consider the $N$ intervals $I_k=\left[a+\frac{k-1}{b-a}, a+\frac{k}{b-a}\right], k=1,2, \ldots, N$. For each $k$ such that $I_k \cap E \neq \varnothing$ let $x_k \in E \cap I_k$. Then let $M=1+\max \left\{\left|f\left(x_k\right)\right|\right\}$. If $x \in E$, we have $\left|x-x_k\right|<\delta$ for some $k$, and hence $|f(x)|<M$.

\end{proof}


theorem exercise_4_11a
  {X : Type*} [metric_space X]
  {Y : Type*} [metric_space Y]
  (f : X → Y) (hf : uniform_continuous f)
  (x : ℕ → X) (hx : cauchy_seq x) :
  cauchy_seq (λ n, f (x n)) :=

Suppose $f$ is a uniformly continuous mapping of a metric space $X$ into a metric space $Y$ and prove that $\left\{f\left(x_{n}\right)\right\}$ is a Cauchy sequence in $Y$ for every Cauchy sequence $\{x_n\}$ in $X$.

\begin{proof}

    Suppose $\left\{x_n\right\}$ is a Cauchy sequence in $X$. Let $\varepsilon>0$ be given. Let $\delta>0$ be such that $d_Y(f(x), f(u))<\varepsilon$ if $d_X(x, u)<\delta$. Then choose $N$ so that $d_X\left(x_n, x_m\right)<\delta$ if $n, m>N$. Obviously $d_Y\left(f\left(x_n\right), f\left(x_m\right)\right)<\varepsilon$ if $m, n>N$, showing that $\left\{f\left(x_n\right)\right\}$ is a Cauchy sequence.

\end{proof}


theorem exercise_4_15 {f : ℝ → ℝ}
  (hf : continuous f) (hof : is_open_map f) :
  monotone f :=

Prove that every continuous open mapping of $R^{1}$ into $R^{1}$ is monotonic.

\begin{proof}

    Suppose $f$ is continuous and not monotonic, say there exist points $a<b<c$ with $f(a)<f(b)$, and $f(c)<f(b)$. Then the maximum value of $f$ on the closed interval $[a, c]$ is assumed at a point $u$ in the open interval $(a, c)$. If there is also a point $v$ in the open interval $(a, c)$ where $f$ assumes its minimum value on $[a, c]$, then $f(a, c)=[f(v), f(u)]$. If no such point $v$ exists, then $f(a, c)=(d, f(u)]$, where $d=\min (f(a), f(c))$. In either case, the image of $(a, c)$ is not open.

\end{proof}


theorem exercise_4_21a {X : Type*} [metric_space X]
  (K F : set X) (hK : is_compact K) (hF : is_closed F) (hKF : disjoint K F) :
  ∃ (δ : ℝ), δ > 0 ∧ ∀ (p q : X), p ∈ K → q ∈ F → dist p q ≥ δ :=

Suppose $K$ and $F$ are disjoint sets in a metric space $X, K$ is compact, $F$ is closed. Prove that there exists $\delta>0$ such that $d(p, q)>\delta$ if $p \in K, q \in F$.

\begin{proof}

Following the hint, we observe that $\rho_F(x)$ must attain its minimum value on $K$, i.e., there is some point $r \in K$ such that

$$

\rho_F(r)=\min _{q \in K} \rho_F(q) .

$$

Since $F$ is closed and $r \notin F$, it follows from Exercise $4.20$ that $\rho_F(r)>0$. Let $\delta$ be any positive number smaller than $\rho_F(r)$. Then for any $p \in F, q \in K$, we have

$$

d(p, q) \geq \rho_F(q) \geq \rho_F(r)>\delta .

$$

This proves the positive assertion.

\end{proof}


theorem exercise_5_1
  {f : ℝ → ℝ} (hf : ∀ x y : ℝ, | (f x - f y) | ≤ (x - y) ^ 2) :
  ∃ c, f = λ x, c :=

Let $f$ be defined for all real $x$, and suppose that $|f(x)-f(y)| \leq (x-y)^{2}$ for all real $x$ and $y$. Prove that $f$ is constant.

\begin{proof}

    Dividing by $x-y$, and letting $x \rightarrow y$, we find that $f^{\prime}(y)=0$ for all $y$. Hence $f$ is constant.

\end{proof}


theorem exercise_5_3 {g : ℝ → ℝ} (hg : continuous g)
  (hg' : ∃ M : ℝ, ∀ x : ℝ, | deriv g x | ≤ M) :
  ∃ N, ∀ ε > 0, ε < N → function.injective (λ x : ℝ, x + ε * g x) :=

Suppose $g$ is a real function on $R^{1}$, with bounded derivative (say $\left|g^{\prime}\right| \leq M$ ). Fix $\varepsilon>0$, and define $f(x)=x+\varepsilon g(x)$. Prove that $f$ is one-to-one if $\varepsilon$ is small enough.

\begin{proof}

    If $0<\varepsilon<\frac{1}{M}$, we certainly have

$$

f^{\prime}(x) \geq 1-\varepsilon M>0,

$$

and this implies that $f(x)$ is one-to-one, by the preceding problem.

\end{proof}


theorem exercise_5_5
  {f : ℝ → ℝ}
  (hfd : differentiable ℝ f)
  (hf : tendsto (deriv f) at_top (𝓝 0)) :
  tendsto (λ x, f (x + 1) - f x) at_top at_top :=

Suppose $f$ is defined and differentiable for every $x>0$, and $f^{\prime}(x) \rightarrow 0$ as $x \rightarrow+\infty$. Put $g(x)=f(x+1)-f(x)$. Prove that $g(x) \rightarrow 0$ as $x \rightarrow+\infty$.

\begin{proof}

    Let $\varepsilon>0$. Choose $x_0$ such that $\left|f^{\prime}(x)\right|<\varepsilon$ if $x>x_0$. Then for any $x \geq x_0$ there exists $x_1 \in(x, x+1)$ such that

$$

f(x+1)-f(x)=f^{\prime}\left(x_1\right) .

$$

Since $\left|f^{\prime}\left(x_1\right)\right|<\varepsilon$, it follows that $|f(x+1)-f(x)|<\varepsilon$, as required.

\end{proof}


theorem exercise_5_7
  {f g : ℝ → ℝ} {x : ℝ}
  (hf' : differentiable_at ℝ f 0)
  (hg' : differentiable_at ℝ g 0)
  (hg'_ne_0 : deriv g 0 ≠ 0)
  (f0 : f 0 = 0) (g0 : g 0 = 0) :
  tendsto (λ x, f x / g x) (𝓝 x) (𝓝 (deriv f x / deriv g x)) :=

Suppose $f^{\prime}(x), g^{\prime}(x)$ exist, $g^{\prime}(x) \neq 0$, and $f(x)=g(x)=0$. Prove that $\lim _{t \rightarrow x} \frac{f(t)}{g(t)}=\frac{f^{\prime}(x)}{g^{\prime}(x)}.$

\begin{proof}

    Since $f(x)=g(x)=0$, we have

$$

\begin{aligned}

\lim _{t \rightarrow x} \frac{f(t)}{g(t)} &=\lim _{t \rightarrow x} \frac{\frac{f(t)-f(x)}{t-x}}{\frac{g(t)-g(x)}{t-x}} \\

&=\frac{\lim _{t \rightarrow x} \frac{f(t)-f(x)}{t-x}}{\lim _{t \rightarrow x} \frac{g(t)-g(x)}{t-x}} \\

&=\frac{f^{\prime}(x)}{g^{\prime}(x)}

\end{aligned}

$$

\end{proof}


theorem exercise_5_17
  {f : ℝ → ℝ}
  (hf' : differentiable_on ℝ f (set.Icc (-1) 1))
  (hf'' : differentiable_on ℝ (deriv f) (set.Icc 1 1))
  (hf''' : differentiable_on ℝ (deriv (deriv f)) (set.Icc 1 1))
  (hf0 : f (-1) = 0)
  (hf1 : f 0 = 0)
  (hf2 : f 1 = 1)
  (hf3 : deriv f 0 = 0) :
  ∃ x, x ∈ set.Ioo (-1 : ℝ) 1 ∧ deriv (deriv (deriv f)) x ≥ 3 :=

Suppose $f$ is a real, three times differentiable function on $[-1,1]$, such that $f(-1)=0, \quad f(0)=0, \quad f(1)=1, \quad f^{\prime}(0)=0 .$ Prove that $f^{(3)}(x) \geq 3$ for some $x \in(-1,1)$.

\begin{proof}

    Following the hint, we observe that Theorem $5.15$ (Taylor's formula with remainder) implies that

$$

\begin{aligned}

f(1) &=f(0)+f^{\prime}(0)+\frac{1}{2} f^{\prime \prime}(0)+\frac{1}{6} f^{(3)}(s) \\

f(-1) &=f(0)-f^{\prime}(0)+\frac{1}{2} f^{\prime \prime}(0)-\frac{1}{6} f^{(3)}(t)

\end{aligned}

$$

for some $s \in(0,1), t \in(-1,0)$. By subtracting the second equation from the first and using the given values of $f(1), f(-1)$, and $f^{\prime}(0)$, we obtain

$$

1=\frac{1}{6}\left(f^{(3)}(s)+f^{(3)}(t)\right),

$$

which is the desired result. Note that we made no use of the hypothesis $f(0)=0$.

\end{proof}


theorem exercise_1_30 {n : ℕ} :
  ¬ ∃ a : ℤ, ∑ (i : fin n), (1 : ℚ) / (n+2) = a :=

import .common

open set function nat int fintype real polynomial mv_polynomial
open zsqrtd gaussian_int char_p nat.arithmetic_function

open_locale big_operators
noncomputable theory

Prove that $\frac{1}{2}+\frac{1}{3}+\cdots+\frac{1}{n}$ is not an integer.

\begin{proof}

Let $2^s$ be the largest power of 2 occuring as a denominator in $H_n$, say $2^s=k \leqslant n$. Write $H_n=$ $\frac{1}{2^s}+\left(1+1 / 2+\ldots+1 /(k-1)+1 /(k+1)+\ldots+1 / n\right.$. The sum in parentheses can be written as $1 / 2^{s-1}$ times sum of fractions with odd denominators, so the denominator of the sum in parentheses will not be divisible by $2^s$, but it must equal $2^s$ by Ex $1.29$.

\end{proof}


theorem exercise_2_4 {a : ℤ} (ha : a ≠ 0)
  (f_a :=

If $a$ is a nonzero integer, then for $n>m$ show that $\left(a^{2^{n}}+1, a^{2^{m}}+1\right)=1$ or 2 depending on whether $a$ is odd or even.

\begin{proof}

\begin{align*}

\operatorname{ord}_p\, n!  &= \sum_{k\geq 1} \left \lfloor \frac{n}{p^{k}}\right \rfloor \leq  \sum_{k\geq 1}  \frac{n}{p^{k}} = \frac{n}{p} \frac{1}{1 - \frac{1}{p}} = \frac{n}{p-1}

\end{align*}

The decomposition of $n!$ in prime factors is

$n! = p_1^{\alpha_1}p_2^{\alpha_2}\cdots p_k^{\alpha_k}$

where $\alpha_i = \operatorname{ord}_{p_i}\, n! \leq \frac{n}{p_i-1}$, and $p_i \leq n, \ i=1,2,\cdots,k$.

Then

\begin{align*}

n! &\leq p_1^{\frac{n}{p_1-1}}p_2^{\frac{n}{p_2-1}}\cdots p_k^{\frac{n}{p_n-1}}\\

\sqrt[n]{n!} &\leq p_1^{\frac{1}{p_1-1}}p_2^{\frac{1}{p_2-1}}\cdots p_k^{\frac{1}{p_n-1}}\\

&\leq \prod_{p\leq n} p^{\frac{1}{p-1}}

\end{align*}

(the values of $p$ in this product describe all prime numbers $p\leq n$.)

\end{proof}


theorem exercise_2_27a :
  ¬ summable (λ i : {p : ℤ // squarefree p}, (1 : ℚ) / i) :=

Show that $\sum^{\prime} 1 / n$, the sum being over square free integers, diverges.

\begin{proof}

Let $S \subset \mathbb{N}^*$ the set of square free integers.

Let $N \in \mathbb{N}^*$. Every integer $n, \, 1\leq n \leq N$ can be written as $n = a b^2$, where $a,b$ are integers and $a$ is square free. Then $1\leq a \leq N$, and $1\leq b \leq \sqrt{N}$, so

$$\sum_{n\leq N} \frac{1}{n} \leq \sum_{a \in S, a\leq N}\  \sum_{1\leq b \leq \sqrt{N}} \frac{1}{ab^2} \leq  \sum_{a \in S, a\leq N}\ \frac{1}{a} \, \sum_{b=1}^\infty  \frac{1}{b^2} = \frac{\pi^2}{6} \sum_{a \in S, a\leq N}\ \frac{1}{a}.$$

So $$\sum_{a \in S, a\leq N} \frac{1}{a}  \geq \frac{6}{\pi^2} \sum_{n\leq N} \frac{1}{n}.$$

As $\sum_{n=1}^\infty \frac{1}{n}$ diverges, $\lim\limits_{N \to \infty} \sum\limits_{a \in S, a\leq N} \frac{1}{a} = +\infty$, so the family $\left(\frac{1}{a}\right)_{a\in S}$ of the inverse of square free integers is not summable.

Let $S_N = \prod_{p<N}(1+1/p)$ , and $p_1,p_2,\ldots, p_l\ (l = l(N))$ all prime integers less than $N$. Then

\begin{align*}

S_N &= \left(1+\frac{1}{p_1}\right) \cdots \left(1+\frac{1}{p_l}\right)\\

&=\sum_{(\varepsilon_1,\cdots,\varepsilon_l) \in \{0,1\}^l } \frac{1}{p_1^{\varepsilon_1} \cdots p_l^{\varepsilon_l}}

\end{align*}

We prove this last formula  by induction. This is true for $l=1$ : $\sum_{\varepsilon \in \{0,1\}} 1/p_1^\varepsilon = 1 + 1/p_1$.

If it is true for the integer $l$, then

\begin{align*}

\left(1+\frac{1}{p_1}\right) \cdots \left(1+\frac{1}{p_l}\right)\left(1+\frac{1}{p_{l+1}}\right) &= \sum_{(\varepsilon_1,\ldots,\varepsilon_l) \in \{0,1\}^l } \frac{1}{p_1^{\varepsilon_1} \cdots p_l^{\varepsilon_l}} \left(1+\frac{1}{p_{l+1}}\right)\\

&=\sum_{(\varepsilon_1,\ldots,\varepsilon_l) \in \{0,1\}^l } \frac{1}{p_1^{\varepsilon_1} \cdots p_l^{\varepsilon_l}} + \sum_{(\varepsilon_1,\ldots,\varepsilon_l) \in \{0,1\}^l } \frac{1}{p_1^{\varepsilon_1} \cdots p_l^{\varepsilon_l}p_{l+1}}\\

&=\sum_{(\varepsilon_1,\ldots,\varepsilon_l,\varepsilon_{l+1}) \in \{0,1\}^{l+1} } \frac{1}{p_1^{\varepsilon_1} \cdots p_l^{\varepsilon_l}p_{l+1}^{\varepsilon_{l+1}}}

\end{align*}

So it is true for all $l$.

Thus $S_N = \sum_{n\in \Delta} \frac{1}{n}$, where $\Delta$ is the set of square free integers whose prime factors are less than $N$.

As $\sum 1/n$, the sum being over square free integers, diverges, $\lim\limits_{N\to \infty} S_N = + \infty$ :

$$\lim_{N \to \infty} \prod_{p<N} \left(1+\frac{1}{p}\right) = +\infty.$$

 $e^x \geq 1+x, x \geq \log (1+x)$ for $x>0$, so

$$\log S_N = \sum_{k=1}^{l(N)} \log\left(1+\frac{1}{p_k}\right) \leq \sum_{k=1}^{l(N)} \frac{1}{p_k}.$$

$\lim\limits_{N\to \infty} \log S_N = +\infty$ and $\lim\limits_{N\to \infty} l(N) = +\infty$, so

$$\lim_{N\to \infty} \sum_{p<N} \frac{1}{p} = +\infty.$$

\end{proof}


theorem exercise_3_4 : ¬ ∃ x y : ℤ, 3*x^2 + 2 = y^2 :=

Show that the equation $3 x^{2}+2=y^{2}$ has no solution in integers.

\begin{proof}

If $3x^2+2 = y^2$, then  $\overline{y}^2 = \overline{2}$ in $\mathbb{Z}/3\mathbb{Z}$.

As $\{-1,0,1\}$ is a complete set of residues modulo $3$, the squares in $\mathbb{Z}/3\mathbb{Z}$ are $\overline{0} = \overline{0}^2$ and  $\overline{1} = \overline{1}^2 = (\overline{-1})^2$, so $\overline{2}$ is not a square in $\mathbb{Z}/3\mathbb{Z}$ : $\overline{y}^2 = \overline{2}$ is impossible in $\mathbb{Z}/3\mathbb{Z}$.

Thus $3x^2+2 = y^2$ has no solution in integers.

\end{proof}


theorem exercise_3_10 {n : ℕ} (hn0 : ¬ n.prime) (hn1 : n ≠ 4) :
  factorial (n-1) ≡ 0 [MOD n] :=

If $n$ is not a prime, show that $(n-1) ! \equiv 0(n)$, except when $n=4$.

\begin{proof}

Suppose that $n >1$ is not a prime. Then $n = uv$, where $2 \leq u \leq v \leq n-1$.

$\bullet$ If $u \neq v$, then $n = uv \mid (n-1)! = 1\times 2 \times\cdots \times u \times\cdots \times v \times \cdots \times (n-1)$ (even if $u\wedge v \neq 1$ !).

$\bullet$ If $u=v$, $n = u^2$ is a square.

If $u$ is not prime, $u =st,\ 2\leq s \leq t \leq u-1 \leq n-1$, and $n = u' v'$, where $u' =s,v' =st^2$ verify  $2 \leq u' < v' \leq n-1$. As in the first case, $n = u'v' \mid (n-1)!$.

If $u = p$ is a prime, then $n =p^2$.

In the case $p = 2$, $n = 4$ and $n=4  \nmid (n-1)! = 6$. In the other case $p >2$, and $(n-1)! = (p^2 - 1)!$ contains the factors $p < 2p < p^2$, so $p^2 \mid (p^2-1)!, n \mid (n-1)!$.

Conclusion : if $n$ is not a prime, $(n - 1)! \equiv 0 \pmod n$, except when $n=4$.

\end{proof}


theorem exercise_4_4 {p t: ℕ} (hp0 : p.prime) (hp1 : p = 4*t + 1)
  (a : zmod p) :
  is_primitive_root a p ↔ is_primitive_root (-a) p :=

Consider a prime $p$ of the form $4 t+1$. Show that $a$ is a primitive root modulo $p$ iff $-a$ is a primitive root modulo $p$.

\begin{proof}

    Suppose that $a$ is a primitive root modulo $p$. As $p-1$ is even, $(-a)^{p-1}=a^{p-1} \equiv 1$ $(\bmod p)$

If $(-a)^n \equiv 1(\bmod p)$, with $n \in \mathbb{N}$, then $a^n \equiv(-1)^n(\bmod p)$.

Therefore $a^{2 n} \equiv 1(\bmod p)$. As $a$ is a primitive root modulo $p, p-1|2 n, 2 t| n$, so $n$ is even.

Hence $a^n \equiv 1(\bmod p)$, and $p-1 \mid n$. So the least $n \in \mathbb{N}^*$ such that $(-a)^n \equiv 1$ $(\bmod p)$ is $p-1:$ the order of $-a$ modulo $p$ is $p-1,-a$ is a primitive root modulo $p$. Conversely, if $-a$ is a primitive root modulo $p$, we apply the previous result at $-a$ to to obtain that $-(-a)=a$ is a primitive root.

\end{proof}


theorem exercise_4_6 {p n : ℕ} (hp : p.prime) (hpn : p = 2^n + 1) :
  is_primitive_root 3 p :=

If $p=2^{n}+1$ is a Fermat prime, show that 3 is a primitive root modulo $p$.

\begin{proof}

 \newcommand{\legendre}[2]{\genfrac{(}{)}{}{}{#1}{#2}}

Write $p = 2^k + 1$, with $k = 2^n$.

We suppose that $n>0$, so $k\geq 2, p \geq 5$. As $p$ is prime, $3^{p-1} \equiv 1 \pmod p$.

In other words, $3^{2^k} \equiv 1 \pmod p$ : the order of $3$ is a divisor of $2^k$, a power of $2$.

$3$ has order $2^k$ modulo $p$ iff $3^{2^{k-1}} \not \equiv 1 \pmod p$. As $\left (3^{2^{k-1}} \right)^2 \equiv 1 \pmod p$, where $p$ is prime, this is equivalent to $3^{2^{k-1}}  \equiv -1 \pmod p$, which remains to prove.

$3^{2^{k-1}} = 3^{(p-1)/2} \equiv \legendre{3}{p} \pmod p$.

As the result is true for $p=5$, we can suppose $n\geq 2$.

From the law of quadratic reciprocity :

$$\legendre{3}{p} \legendre{p}{3} = (-1)^{(p-1)/2} = (-1)^{2^{k-1}} = 1.$$

So $\legendre{3}{p} = \legendre{p}{3}$

\begin{align*}

p = 2^{2^n}+1 &\equiv (-1)^{2^n} + 1 \pmod 3\\

&\equiv 2 \equiv -1 \pmod 3,

\end{align*}

so $\legendre{3}{p} = \legendre {p}{3} = -1$, that is to say

$$3^{2^{k-1}}  \equiv -1 \pmod p.$$

The order of $3$ modulo $p = 2^{2^n} + 1$ is $p-1 = 2^{2^n}$ : $3$ is a primitive root modulo $p$.

(On the other hand, if $3$ is of order $p-1$ modulo $p$, then $p$ is prime, so

$$ F_n = 2^{2^n} + 1 \ \mathrm{is}\ \mathrm{prime}\ \iff 3^{(F_n-1)/2} = 3^{2^{2^n - 1}} \equiv -1 \pmod {F_n}.)$$

\end{proof}


theorem exercise_4_11 {p : ℕ} (hp : p.prime) (k s: ℕ)
  (s :=

Prove that $1^{k}+2^{k}+\cdots+(p-1)^{k} \equiv 0(p)$ if $p-1 \nmid k$ and $-1(p)$ if $p-1 \mid k$.

\begin{proof}

Let $S_k = 1^k+2^k+\cdots+(p-1)^k$.

Let $g$ a primitive root modulo $p$ : $\overline{g}$ a generator of $\mathbb{F}_p^*$.

As $(\overline{1},\overline{g},\overline{g}^{2}, \ldots, \overline{g}^{p-2}) $ is a permutation of $ (\overline{1},\overline{2}, \ldots,\overline{p-1})$,

\begin{align*}

\overline{S_k} &= \overline{1}^k + \overline{2}^k+\cdots+ \overline{p-1}^k\\

&= \sum_{i=0}^{p-2} \overline{g}^{ki} =

\left\{

\begin{array}{ccc}

\overline{ p-1} = -\overline{1} &  \mathrm{if} &  p-1 \mid k  \\

 \frac{ \overline{g}^{(p-1)k} -1}{ \overline{g}^k -1} = \overline{0}&  \mathrm{if}  &   p-1 \nmid k

\end{array}

\right.

\end{align*}

since $p-1 \mid k \iff \overline{g}^k = \overline{1}$.

Conclusion :

\begin{align*}

1^k+2^k+\cdots+(p-1)^k&\equiv 0 \pmod p\ \mathrm{if} \ p-1 \nmid k\\

1^k+2^k+\cdots+(p-1)^k&\equiv -1 \pmod p\ \mathrm{if} \ p-1 \mid k\\

\end{align*}

\end{proof}


theorem exercise_5_28 {p : ℕ} (hp : p.prime) (hp1 : p ≡ 1 [MOD 4]):
  ∃ x, x^4 ≡ 2 [MOD p] ↔ ∃ A B, p = A^2 + 64*B^2 :=

Show that $x^{4} \equiv 2(p)$ has a solution for $p \equiv 1(4)$ iff $p$ is of the form $A^{2}+64 B^{2}$.

\begin{proof}

If  $p\equiv 1\ [4]$ and if there exists $x \in \mathbb{Z}$ such that $x^4 \equiv 2\ [p]$, then

$$2^{\frac{p-1}{4} }\equiv  x^{p-1} \equiv 1 \ [p].$$

From Ex. 5.27, where $p = a^2 +b^2, a$ odd,  we know that $$f^{\frac{ab}{2}} \equiv 2^{\frac{p-1}{4} } \equiv 1 \ [p].$$

Since $f^2 \equiv -1\ [p]$, the order of $f$ modulo $p$ is 4, thus $4 \mid \frac{ab}{2}$, so $8\mid ab$.

As $a$ is odd, $8 | b$, then $p = A^2 + 64 B^2$ (with $A = a, B = b/8$).

\bigskip

Conversely, if $p=A^2+64 B^2$, then $p\equiv A^2 \equiv 1 \ [4]$.

Let $a=A,b=8B$. Then $$2^{\frac{p-1}{4} } \equiv f^{\frac{ab}{2}} \equiv f^{4AB} \equiv (-1)^{2AB} \equiv 1 \ [p].$$

As $2^{\frac{p-1}{4} } \equiv 1 \ [p]$, $x^4 \equiv 2 \ [p]$ has a solution in $\mathbb{Z}$ (Prop. 4.2.1) : $2$ is a biquadratic residue modulo $p$.

Conclusion :

$$\exists A \in \mathbb{Z}, \exists B \in \mathbb{Z}\,, p = A^2+64 B^2 \iff( p\equiv 1 \ [4] \ \mathrm{and} \ \exists x \in \mathbb{Z}, \, x^4 \equiv 2 \ [p]).$$

\end{proof}


theorem exercise_12_12 : is_algebraic ℚ (sin (real.pi/12)) :=

Show that $\sin (\pi / 12)$ is an algebraic number.

\begin{proof}

$$

\begin{aligned}

    \sin \pi/12=\sin \left(\pi/4-\pi/6\right) & =\sin \pi/4 \cos \pi/6-\cos \pi/4 \sin \pi/6 \\

& =\frac{\sqrt{3}}{2 \sqrt{2}}-\frac{1}{2 \sqrt{2}} \\

& =\frac{\sqrt{3}-1}{2 \sqrt{2}}

\end{aligned}

$$

\end{proof}


theorem exercise_1_2 :
  (⟨-1/2, real.sqrt 3 / 2⟩ : ℂ) ^ 3 = -1 :=

import .common

open set fintype complex polynomial submodule linear_map finite_dimensional
open module module.End inner_product_space

open_locale big_operators

Show that $\frac{-1 + \sqrt{3}i}{2}$ is a cube root of 1 (meaning that its cube equals 1).

\begin{proof}

$$

\left(\frac{-1+\sqrt{3} i}{2}\right)^2=\frac{-1-\sqrt{3} i}{2},

$$

hence

$$

\left(\frac{-1+\sqrt{3} i}{2}\right)^3=\frac{-1-\sqrt{3} i}{2} \cdot \frac{-1+\sqrt{3} i}{2}=1

$$

This means $\frac{-1+\sqrt{3} i}{2}$ is a cube root of 1.

\end{proof}


theorem exercise_1_4 {F V : Type*} [add_comm_group V] [field F]
  [module F V] (v : V) (a : F): a • v = 0 ↔ a = 0 ∨ v = 0 :=

Prove that if $a \in \mathbf{F}$, $v \in V$, and $av = 0$, then $a = 0$ or $v = 0$.

\begin{proof}

    If $a=0$, then we immediately have our result. So suppose $a \neq 0$. Then, because $a$ is some nonzero real or complex number, it has a multiplicative inverse $\frac{1}{a}$. Now suppose that $v$ is some vector such that

$$

a v=0

$$

Multiply by $\frac{1}{a}$ on both sides of this equation to get

$$

\begin{aligned}

\frac{1}{a}(a v) & =\frac{1}{a} 0 & & \\

\frac{1}{a}(a v) & =0 & & \\

\left(\frac{1}{a} \cdot a\right) v & =0 & & \text { (associativity) } \\

1 v & =0 & & \text { (definition of } 1/a) \\

v & =0 & & \text { (multiplicative identity) }

\end{aligned}

$$

Hence either $a=0$ or, if $a \neq 0$, then $v=0$.

\end{proof}


theorem exercise_1_7 : ∃ U : set (ℝ × ℝ),
  (U ≠ ∅) ∧
  (∀ (c : ℝ) (u : ℝ × ℝ), u ∈ U → c • u ∈ U) ∧
  (∀ U' : submodule ℝ (ℝ × ℝ), U ≠ ↑U') :=

Give an example of a nonempty subset $U$ of $\mathbf{R}^2$ such that $U$ is closed under scalar multiplication, but $U$ is not a subspace of $\mathbf{R}^2$.

\begin{proof}

$$

U=\left\{(x, y) \in \mathbf{R}^2:|x|=|y|\right\}

$$

For $(x, y) \in U$ and $\lambda \in \mathbb{R}$, it follows $\lambda(x, y)=$ $(\lambda x, \lambda y)$, so $|\lambda x|=|\lambda||x|=|\lambda||y|=|\lambda y|$. Therefore, $\lambda(x, y) \in U$.

On the other hand, consider $a=(1,-1), b=$ $(1,1) \in U$. Then, $a+b=(1,-1)+(1,1)=$ $(2,0) \notin U$. So, $U$ is not a subspace of $\mathbb{R}^2$.

\end{proof}