theorem exercise_2_1_21 (G : Type*) [group G] [fintype G]
  (hG : card G = 5) :
  comm_group G :=

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

Show that a group of order 5 must be abelian.

\begin{proof}

    Suppose $G$ is a group of order 5 which is not abelian. Then there exist two non-identity elements $a, b \in G$ such that $a * b \neq$ $b * a$. Further we see that $G$ must equal $\{e, a, b, a * b, b * a\}$. To see why $a * b$ must be distinct from all the others, not that if $a *$ $b=e$, then $a$ and $b$ are inverses and hence $a * b=b * a$.

Contradiction. If $a * b=a$ (or $=b$ ), then $b=e$ (or $a=e$ ) and $e$ commutes with everything. Contradiction. We know by supposition that $a * b \neq b * a$. Hence all the elements $\{e, a, b, a * b, b * a\}$ are distinct.

Now consider $a^2$. It can't equal $a$ as then $a=e$ and it can't equal $a * b$ or $b * a$ as then $b=a$. Hence either $a^2=e$ or $a^2=b$.

Now consider $a * b * a$. It can't equal $a$ as then $b * a=e$ and hence $a * b=b * a$. Similarly it can't equal $b$. It also can't equal $a * b$ or $b * a$ as then $a=e$. Hence $a * b * a=e$.

So then we additionally see that $a^2 \neq e$ because then $a^2=e=$ $a * b * a$ and consequently $a=b * a$ (and hence $b=e$ ). So $a^2=b$. But then $a * b=a * a^2=a^2 * a=b * a$. Contradiction.

Hence starting with the assumption that there exists an order 5 abelian group $G$ leads to a contradiction. Thus there is no such group.

\end{proof}


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

If $G$ is a finite group, prove that there is an integer $m > 0$ such that $a^m = e$ for all $a \in G$.

\begin{proof}

    Let $n_1, n_2, \ldots, n_k$ be the orders of all $k$ elements of $G=$ $\left\{a_1, a_2, \ldots, a_k\right\}$. Let $m=\operatorname{lcm}\left(n_1, n_2, \ldots, n_k\right)$. Then, for any $i=$ $1, \ldots, k$, there exists an integer $c$ such that $m=n_i c$. Thus

$$

a_i^m=a_i^{n_i c}=\left(a_i^{n_i}\right)^c=e^c=e

$$

Hence $m$ is a positive integer such that $a^m=e$ for all $a \in G$.

\end{proof}


theorem exercise_2_2_5 {G : Type*} [group G]
  (h : ∀ (a b : G), (a * b) ^ 3 = a ^ 3 * b ^ 3 ∧ (a * b) ^ 5 = a ^ 5 * b ^ 5) :
  comm_group G :=

Let $G$ be a group in which $(a b)^{3}=a^{3} b^{3}$ and $(a b)^{5}=a^{5} b^{5}$ for all $a, b \in G$. Show that $G$ is abelian.

\begin{proof}

 We have

$$

\begin{aligned}

& (a b)^3=a^3 b^3, \text { for all } a, b \in G \\

\Longrightarrow & (a b)(a b)(a b)=a\left(a^2 b^2\right) b \\

\Longrightarrow & a(b a)(b a) b=a\left(a^2 b^2\right) b \\

\Longrightarrow & (b a)^2=a^2 b^2, \text { by cancellation law. }

\end{aligned}

$$

Again,

$$

\begin{aligned}

& (a b)^5=a^5 b^5, \text { for all } a, b \in G \\

\Longrightarrow & (a b)(a b)(a b)(a b)(a b)=a\left(a^4 b^4\right) b \\

\Longrightarrow & a(b a)(b a)(b a)(b a) b=a\left(a^4 b^4\right) b \\

\Longrightarrow & (b a)^4=a^4 b^4, \text { by cancellation law. }

\end{aligned}

$$

Now by combining two cases we have

$$

\begin{aligned}

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

\Longrightarrow & \left((b a)^2\right)^2=a^2\left(a^2 b^2\right) b^2 \\

\Longrightarrow & \left(a^2 b^2\right)^2=a^2\left(a^2 b^2\right) b^2 \\

\Longrightarrow & \left(a^2 b^2\right)\left(a^2 b^2\right)=a^2\left(a^2 b^2\right) b^2 \\

\Longrightarrow & a^2\left(b^2 a^2\right) b^2=a^2\left(a^2 b^2\right) b^2 \\

\Longrightarrow & b^2 a^2=a^2 b^2, \text { by cancellation law. } \\

\Longrightarrow & b^2 a^2=(b a)^2, \text { since }(b a)^2=a^2 b^2 \\

\Longrightarrow & b(b a) a=(b a)(b a) \\

\Longrightarrow & b(b a) a=b(a b) a \\

\Longrightarrow & b a=a b, \text { by cancellation law. }

\end{aligned}

$$

It follows that, $a b=b a$ for all $a, b \in G$. Hence $G$ is abelian

\end{proof}


theorem exercise_2_3_17 {G : Type*} [has_mul G] [group G] (a x : G) :
  set.centralizer {x⁻¹*a*x} =
  (λ g : G, x⁻¹*g*x) '' (set.centralizer {a}) :=

If $G$ is a group and $a, x \in G$, prove that $C\left(x^{-1} a x\right)=x^{-1} C(a) x$

\begin{proof}

    Note that

$$

C(a):=\{x \in G \mid x a=a x\} .

$$

Let us assume $p \in C\left(x^{-1} a x\right)$. Then,

$$

\begin{aligned}

& p\left(x^{-1} a x\right)=\left(x^{-1} a x\right) p \\

\Longrightarrow & \left(p x^{-1} a\right) x=x^{-1}(a x p) \\

\Longrightarrow & x\left(p x^{-1} a\right)=(a x p) x^{-1} \\

\Longrightarrow & \left(x p x^{-1}\right) a=a\left(x p x^{-1}\right) \\

\Longrightarrow & x p x^{-1} \in C(a) .

\end{aligned}

$$

Therefore,

$$

p \in C\left(x^{-1} a x\right) \Longrightarrow x p x^{-1} \in C(a) .

$$

Thus,

$$

C\left(x^{-1} a x\right) \subset x^{-1} C(a) x .

$$

Let us assume

$$

q \in x^{-1} C(a) x .

$$

Then there exists an element $y$ in $C(a)$ such that

$$

q=x^{-1} y x

$$

Now,

$$

y \in C(a) \Longrightarrow y a=a y .

$$

Also,

$$

q\left(x^{-1} a x\right)=\left(x^{-1} y x\right)\left(x^{-1} a x\right)=x^{-1}(y a) x=x^{-1}(y a) x=\left(x^{-1} y x\right)\left(x^{-1} a x\right)=\left(x^{-1} y x\right) q .

$$

Therefore,

$$

q\left(x^{-1} a x\right)=\left(x^{-1} y x\right) q

$$

So,

$$

q \in C\left(x^{-1} a x\right) .

$$

Consequently we have

$$

x^{-1} C(a) x \subset C\left(x^{-1} a x\right) .

$$

It follows from the aforesaid argument

$$

C\left(x^{-1} a x\right)=x^{-1} C(a) x .

$$

This completes the proof.

\end{proof}


theorem exercise_2_4_36 {a n : ℕ} (h : a > 1) :
  n ∣ (a ^ n - 1).totient :=

If $a > 1$ is an integer, show that $n \mid \varphi(a^n - 1)$, where $\phi$ is the Euler $\varphi$-function.

\begin{proof}

    Proof: We have $a>1$. First we propose to prove that

$$

\operatorname{Gcd}\left(a, a^n-1\right)=1 .

$$

If possible, let us assume that

$\operatorname{Gcd}\left(a, a^n-1\right)=d$, where $d>1$.

Then

$d$ divides $a$ as well as $a^n-1$.

Now,

$d$ divides $a \Longrightarrow d$ divides $a^n$.

This is an impossibility, since $d$ divides $a^n-1$ by our assumption. Consequently, $d$ divides 1 , which implies $d=1$. Hence we are contradict to the fact that $d>1$. Therefore

$$

\operatorname{Gcd}\left(a, a^n-1\right)=1 .

$$

Then $a \in U_{a^n-1}$, where $U_n$ is a group defined by

$$

U_n:=\left\{\bar{a} \in \mathbb{Z}_n \mid \operatorname{Gcd}(a, n)=1\right\} .

$$

We know that order of an element divides the order of the group. Here order of the group $U_{a^n-1}$ is $\phi\left(a^n-1\right)$ and $a \in U_{a^n-1}$. This follows that $\mathrm{o}(a)$ divides $\phi\left(a^n-1\right)$.

\end{proof}


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

Suppose that $|G| = pm$, where $p \nmid m$ and $p$ is a prime. If $H$ is a normal subgroup of order $p$ in $G$, prove that $H$ is characteristic.

\begin{proof}

    Let $G$ be a group of order $p m$, such that $p \nmid m$. Now, Given that $H$ is a normal subgroup of order $p$. 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$. Suppose $\phi(H) \neq H$, then $H \cap \phi (H)=\{ e\}$. Consider $H \phi(H)$, this is a subgroup of $G$ as $H$ is normal. Also $|H \phi(H)|=p^2$. By lagrange's theorem then $p^2 \mid$ $p m \Longrightarrow p \mid m$ - contradiction. So $\phi(H)=H$, and $H$ is characterestic subgroup of $G$

\end{proof}


theorem exercise_2_5_37 (G : Type*) [group G] [fintype G]
  (hG : card G = 6) (hG' : is_empty (comm_group G)) :
  G ≃* equiv.perm (fin 3) :=

If $G$ is a nonabelian group of order 6, prove that $G \simeq S_3$.

\begin{proof}

    Suppose $G$ is a non-abelian group of order 6 . We need to prove that $G \cong S_3$. Since $G$ is non-abelian, we conclude that there is no element of order 6. Now all the nonidentity element has order either 2 or 3 . All elements cannot be order 3 .This is because except the identity elements there are 5 elements, but order 3 elements occur in pair, that is $a, a^2$, both have order 3 , and $a \neq a^2$. So, this is a contradiction, as there are only 5 elements. So, there must be an element of order 2 . All elements of order 2 will imply that $G$ is abelian, hence there is also element of order 3 . Let $a$ be an element of order 2 , and $b$ be an element of order 3 . So we have $e, a, b, b^2$, already 4 elements. Now $a b \neq e, b, b^2$. So $a b$ is another element distinct from the ones already constructed. $a b^2 \neq e, b, a b, b^2, a$. So, we have got another element distinct from the other. So, now $ G=\left\{e, a, b, b^2, a b, a b^2\right\}$. Also, ba must be equal to one of these elements. But $b a \neq e, a, b, b^2$. Also if $b a=a b$, the group will become abelian. so $b a=a b^2$. So what we finally get is $G=\left\langle a, b \mid a^2=e=b^3, b a=a b^2\right\rangle$. Hence $G \cong S_3$.

\end{proof}


theorem exercise_2_5_44 {G : Type*} [group G] [fintype G] {p : ℕ}
  (hp : nat.prime p) (hG : card G = p^2) :
  ∃ (N : subgroup G) (fin : fintype N), @card N fin = p ∧ N.normal :=

Prove that a group of order $p^2$, $p$ a prime, has a normal subgroup of order $p$.

\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 \neq \{ e \}$ and $K \subseteq H$.

So, we have now a group $G$ of order $p^2$. Suppose that the group is cyclic, then it is abelian and any subgroup of order $p$ is normal. Now let us suppose that $G$ is not cyclic, then there exists an element $a$ of order $p$, and $A=\langle a\rangle$. Now $i_G(A)=p$, so $p^2 \nmid p$ ! , hence by the above result there is a normal subgroup $K$, non-trivial and $K \subseteq A$. But $|A|=p$, a prime order subgroup, hence has no non-trivial subgroup, so $K=A$. so $A$ is normal subgroup.

\end{proof}


theorem exercise_2_6_15 {G : Type*} [comm_group G] {m n : ℕ}
  (hm : ∃ (g : G), order_of g = m)
  (hn : ∃ (g : G), order_of g = n)
  (hmn : m.coprime n) :
  ∃ (g : G), order_of g = m * n :=

If $G$ is an abelian group and if $G$ has an element of order $m$ and one of order $n$, where $m$ and $n$ are relatively prime, prove that $G$ has an element of order $mn$.

\begin{proof}

Let $G$ be an abelian group, and let $a$ and $b$ be elements in $G$ of order $m$ and $n$, respectively, where $m$ and $n$ are relatively prime. We will show that the product $ab$ has order $mn$ in $G$, which will prove that $G$ has an element of order $mn$.

To show that $ab$ has order $mn$, let $k$ be the order of $ab$ in $G$. We have $a^m = e$, $b^n = e$, and $(ab)^k = e$, where $e$ denotes the identity element of $G$. Since $G$ is abelian, we have

$$(ab)^{mn} = a^{mn}b^{mn} = e \cdot e = e.$$

Thus, $k$ is a divisor of $mn$.

Now, observe that $a^k = b^{-k}$. Since $m$ and $n$ are relatively prime, there exist integers $x$ and $y$ such that $mx + ny = 1$. Taking $kx$ on both sides of the equation, we get $a^{kx} = b^{-kx}$, or equivalently, $(a^k)^x = (b^k)^{-x}$. It follows that $a^{kx} = (a^m)^{xny} = e$, and similarly, $b^{ky} = (b^n)^{mxk} = e$. Therefore, $m$ divides $ky$ and $n$ divides $kx$. Since $m$ and $n$ are relatively prime, it follows that $mn$ divides $k$. Hence, $k = mn$, and $ab$ has order $mn$ in $G$. This completes the proof.

\end{proof}


theorem exercise_2_8_12 {G H : Type*} [fintype G] [fintype H]
  [group G] [group H] (hG : card G = 21) (hH : card H = 21)
  (hG1 : is_empty(comm_group G)) (hH1 : is_empty (comm_group H)) :
  G ≃* H :=

Prove that any two nonabelian groups of order 21 are isomorphic.

\begin{proof}

    By Cauchy's theorem we have that if $G$ is a group of order 21 then it has an element $a$ of order 3 and an element $b$ of order 7. By exercise 2.5.41 we have that the subgroup generated by $b$ is normal, so there is some $i=0,1,2,3,4,5,6$ such that $a b a^{-1}=b^i$. We know $i \neq$ 0 since that implies $a b=a$ and so that $b=e$, a contradiction, and we know $i \neq 1$ since then $a b=b a$ and this would imply $G$ is abelian, which we are assuming is not the case.

Now, $a$ has order 3 so we must have $b=a^3 b a^{-3}=b^{i^3}$ mod 7 , and so $i$ is restricted by the modular equation $i^3 \equiv 1 \bmod 7$

\begin{center}

\begin{tabular}{|c|c|}

\hline$x$ & $x^3 \bmod 7$ \\

\hline 2 & 1 \\

\hline 3 & 6 \\

\hline 4 & 1 \\

\hline 5 & 6 \\

\hline 6 & 6 \\

\hline

\end{tabular}

\end{center}

Therefore the only options are $i=2$ and $i=4$. Now suppose $G$ is such that $a b a^{-1}=b^2$ and let $G^{\prime}$ be another group of order 21 with an element $c$ of order 3 and an element $d$ of order 7 such that $c d c^{-1}=d^4$. We now prove that $G$ and $G^{\prime}$ are isomorphic. Define

$$

\begin{aligned}

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

a & \mapsto c^{-1} \\

b & \mapsto d

\end{aligned}

$$

since $a$ and $c^{-1}$ have the same order and $b$ and $d$ have the same order this is a well defined function. Since

$$

\begin{aligned}

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

& =\left(c d^{-1} c^{-1}\right)^{-1} \\

& =\left(d^{-4}\right)^{-1} \\

& =d^4 \\

& =\left(d^2\right)^2 \\

& =\phi(b)^2

\end{aligned}

$$

$\phi$ is actually a homomorphism. For any $c^i d^j \in G^{\prime}$ we have $\phi\left(a^{-i} b^j\right)=c^i d^j$ so $\phi$ is onto and $\phi\left(a^i b^j\right)=c^{-i} d^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 21 .

\end{proof}


theorem exercise_2_9_2 {G H : Type*} [fintype G] [fintype H] [group G]
  [group H] (hG : is_cyclic G) (hH : is_cyclic H) :
  is_cyclic (G × H) ↔ (card G).coprime (card H) :=

If $G_1$ and $G_2$ are cyclic groups of orders $m$ and $n$, respectively, prove that $G_1 \times G_2$ is cyclic if and only if $m$ and $n$ are relatively prime.

\begin{proof}

    The order of $G \times H$ is $n$. $m$. Thus, $G \times H$ is cyclic iff it has an element with order n. $m$. Suppose $\operatorname{gcd}(n . m)=1$. This implies that $g^m$ has order $n$, and analogously $h^n$ has order $m$. That is, $g \times h$ has order $n$. $m$, and therefore $G \times H$ is cyclic.

Suppose now that $\operatorname{gcd}(n . m)>1$. Let $g^k$ be an element of $G$ and $h^j$ be an element of $H$. Since the lowest common multiple of $n$ and $m$ is lower than the product $n . m$, that is, $\operatorname{lcm}(n, m)<n$. $m$, and since $\left(g^k\right)^{l c m(n, m)}=e_G,\left(h^j\right)^{l c m(n, m)}=e_H$, we have $\left(g^k \times h^j\right)^{l c m(n, m)}=e_{G \times H}$. It follows that every element of $G \times H$ has order lower than $n . m$, and therefore $G \times H$ is not cyclic.

\end{proof}


theorem exercise_2_11_6 {G : Type*} [group G] {p : ℕ} (hp : nat.prime p)
  {P : sylow p G} (hP : P.normal) :
  ∀ (Q : sylow p G), P = Q :=

If $P$ is a $p$-Sylow subgroup of $G$ and $P \triangleleft G$, prove that $P$ is the only $p$-Sylow subgroup of $G$.

\begin{proof}

    let $G$ be a group and $P$ a sylow-p subgroup. Given $P$ is normal. By sylow second theorem the sylow-p subgroups are conjugate. Let $K$ be any other sylow-p subgroup. Then there exists $g \in G$ such that $K=g P g^{-1}$. But since $P$ is normal $K=g P g^{-1}=P$. Hence the sylow-p subgroup is unique.

\end{proof}


theorem exercise_2_11_22 {p : ℕ} {n : ℕ} {G : Type*} [fintype G]
  [group G] (hp : nat.prime p) (hG : card G = p ^ n) {K : subgroup G}
  [fintype K] (hK : card K = p ^ (n-1)) :
  K.normal :=

Show that any subgroup of order $p^{n-1}$ in a group $G$ of order $p^n$ is normal in $G$.

\begin{proof}

Proof: First we prove the following lemma.

\textbf{Lemma:} If $G$ is a finite $p$-group with $|G|>1$, then $Z(G)$, the center of $G$, has more than one element; that is, if $|G|=p^k$ with $k\geq 1$, then $|Z(G)|>1$.

\textit{Proof of the lemma:} Consider the class equation

$$

|G|=|Z(G)|+\sum_{a \notin Z(G)}[G: C(a)],

$$

where $C(a)$ denotes the centralizer of $a$ in $G$. If $G=Z(G)$, then the lemma is immediate. Suppose $Z(G)$ is a proper subset of $G$ and consider an element $a\in G$ such that $a\notin Z(G)$. Then $C(a)$ is a proper subgroup of $G$. Since $C(a)$ is a subgroup of a $p$-group, $[G:C(a)]$ is divisible by $p$ for all $a\notin Z(G)$. This implies that $p$ divides $|G|=|Z(G)|+\sum_{a\notin Z(G)} [G:C(a)]$.

Since $p$ also divides $|G|$, it follows that $p$ divides $|Z(G)|$. Hence, $|Z(G)|>1$. $\Box$

This proves our \textbf{lemma}.

We will prove the result by induction on $n$.

If $n=1$, the $G$ is a cyclic group of prime order and hence every subgroup of $G$ is normal in $G$. Thus, the result is true for $n=1$.

Suppose the result is true for all groups of order $p^m$, where $1 \leq m<n$.

Let $H$ be a subgroup of order $p^{n-1}$.

Consider $N(H)=\{g \in H: g H=H g\}$.

If $H \neq N(H)$, then $|N(H)|>p^{n-1}$. Thus, $|N(H)|=p^n$ and $N(H)=G$.

In this case $H$ is normal in $G$.

Let $H=N(H)$. Then $Z(G)$, the center of $G$, is a subset of $H$ and $Z(G) \neq$ $\{e\}$.

By Cauchy's theorem and the above Claim, there exists $a \in Z(G)$ such that $o(a)=p$.

Let $K=\langle a\rangle$, a cyclic group generated by $a$.

Then $K$ is a normal subgroup of $G$ of order $p$. Now, $|H / K|=p^{n-2}$ and $|G / K|=p^{n-1}$.

Thus, by induction hypothesis, $H / K$ is a normal subgroup of $G / K$.

\end{proof}


theorem exercise_4_1_19 : infinite {x : quaternion ℝ | x^2 = -1} :=

Show that there is an infinite number of solutions to $x^2 = -1$ in the quaternions.

\begin{proof}

Let $x=a i+b j+c k$ then

$$

x^2=(a i+b j+c k)(a i+b j+c k)=-a^2-b^2-c^2=-1

$$

This gives $a^2+b^2+c^2=1$ which has infinitely many solutions for $-1<a, b, c<1$.

\end{proof}


theorem exercise_4_2_5 {R : Type*} [ring R]
  (h : ∀ x : R, x ^ 3 = x) : comm_ring R :=

Let $R$ be a ring in which $x^3 = x$ for every $x \in R$. Prove that $R$ is commutative.

\begin{proof}

To begin with

$$

2 x=(2 x)^3=8 x^3=8 x .

$$

Therefore $6 x=0 \quad \forall x$.

Also

$$

(x+y)=(x+y)^3=x^3+x^2 y+x y x+y x^2+x y^2+y x y+y^2 x+y^3

$$

and

$$

(x-y)=(x-y)^3=x^3-x^2 y-x y x-y x^2+x y^2+y x y+y^2 x-y^3

$$

Subtracting we get

$$

2\left(x^2 y+x y x+y x^2\right)=0

$$

Multiply the last relation by $x$ on the left and right to get

$$

2\left(x y+x^2 y x+x y x^2\right)=0 \quad 2\left(x^2 y x+x y x^2+y x\right)=0 .

$$

Subtracting the last two relations we have

$$

2(x y-y x)=0 .

$$

We then show that $3\left(x+x^2\right)=0 \forall x$. You get this from

$$

x+x^2=\left(x+x^2\right)^3=x^3+3 x^4+3 x^5+x^6=4\left(x+x^2\right) .

$$

In particular

$$

3\left(x+y+(x+y)^2\right)=3\left(x+x^2+y+y^2+x y+y x\right)=0

$$

we end-up with $3(x y+y x)=0$. But since $6 x y=0$, we have $3(x y-y x)=0$. Then subtract $2(x y-y x)=0$ to get $x y-y x=0$.

\end{proof}


theorem exercise_4_2_9 {p : ℕ} (hp : nat.prime p) (hp1 : odd p) :
  ∃ (a b : ℤ), a / b = ∑ i in finset.range p, 1 / (i + 1) → ↑p ∣ a :=

Let $p$ be an odd prime and let $1 + \frac{1}{2} + ... + \frac{1}{p - 1} = \frac{a}{b}$, where $a, b$ are integers. Show that $p \mid a$.

\begin{proof}

    First we prove for prime $p=3$ and then for all prime $p>3$.

Let us take $p=3$. Then the sum

$$

\frac{1}{1}+\frac{1}{2}+\ldots+\frac{1}{(p-1)}

$$

becomes

$$

1+\frac{1}{3-1}=1+\frac{1}{2}=\frac{3}{2} .

$$

Therefore in this case $\quad \frac{a}{b}=\frac{3}{2} \quad$ implies $3 \mid a$, i.e. $p \mid a$.

Now for odd prime $p>3$.

Let us consider $f(x)=(x-1)(x-2) \ldots(x-(p-1))$.

Now, by Fermat, we know that the coefficients of $f(x)$ other than the $x^{p-1}$ and $x^0$ are divisible by $p$.

So if,

$$

\begin{array}{r}

f(x)=x^{p-1}+\sum_{i=0}^{p-2} a_i x^i \\

\text { and } p>3 .

\end{array}

$$

Then $p \mid a_2$, and

$$

f(p) \equiv a_1 p+a_0 \quad\left(\bmod p^3\right)

$$

But we see that

$$

f(x)=(-1)^{p-1} f(p-x) \text { for any } x,

$$

so if $p$ is odd,

$$

f(p)=f(0)=a_0,

$$

So it follows that:

$$

0=f(p)-a_0 \equiv a_1 p \quad\left(\bmod p^3\right)

$$

Therefore,

$$

0 \equiv a_1 \quad\left(\bmod p^2\right) .

$$

Hence,

$$

0 \equiv a_1 \quad(\bmod p) .

$$

Now our sum is just $\frac{a_1}{(p-1) !}=\frac{a}{b}$.

It follows that $p$ divides $a$. This completes the proof.

\end{proof}


theorem exercise_4_3_25 (I : ideal (matrix (fin 2) (fin 2) ℝ)) :
  I = ⊥ ∨ I = ⊤ :=

Let $R$ be the ring of $2 \times 2$ matrices over the real numbers; suppose that $I$ is an ideal of $R$. Show that $I = (0)$ or $I = R$.

\begin{proof}

    Suppose that $I$ is a nontrivial ideal of $R$, and let

$$

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

a & b \\

c & d

\end{array}\right)

$$

where not all of $a, b, c d$ are zero. Suppose, without loss of generality -- our steps would be completely analogous, modulo some different placement of 1 s in our matrices, if we assumed some other element to be nonzero -- that $a \neq 0$. Then we have that

$$

\left(\begin{array}{ll}

1 & 0 \\

0 & 0

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

a & b \\

c & d

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

a & b \\

0 & 0

\end{array}\right) \in I

$$

and so

$$

\left(\begin{array}{ll}

a & b \\

0 & 0

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

1 & 0 \\

0 & 0

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

a & 0 \\

0 & 0

\end{array}\right) \in I

$$

so that

$$

\left(\begin{array}{ll}

x & 0 \\

0 & 0

\end{array}\right) \in I

$$

for any real $x$. Now, also for any real $x$,

$$

\left(\begin{array}{ll}

x & 0 \\

0 & 0

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

0 & 1 \\

0 & 0

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

0 & x \\

0 & 0

\end{array}\right) \in I .

$$

Likewise

$$

\left(\begin{array}{ll}

0 & 0 \\

1 & 0

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

0 & x \\

0 & 0

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

0 & 0 \\

0 & x

\end{array}\right) \in I

$$

and

$$

\left(\begin{array}{ll}

0 & 0 \\

0 & x

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

0 & 0 \\

1 & 0

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

0 & 0 \\

x & 0

\end{array}\right)

$$

Thus, as

$$

\left(\begin{array}{ll}

a & b \\

c & d

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

a & 0 \\

0 & 0

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

0 & b \\

0 & 0

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

0 & 0 \\

c & 0

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

0 & 0 \\

0 & d

\end{array}\right)

$$

and since all the terms on the right side are in $I$ and $I$ is an additive group, it follows that

$$

\left(\begin{array}{ll}

a & b \\

c & d

\end{array}\right)

$$

for arbitrary $a, b, c, d$ is in $I$, i.e. $I=R$

Note that the intuition for picking these matrices is that, if we denote by $E_{i j}$ the matrix with 1 at position $(i, j)$ and 0 elsewhere, then

$$

E_{i j}\left(\begin{array}{ll}

a_{1,1} & a_{1,2} \\

a_{2,1} & a_{2,2}

\end{array}\right) E_{n m}=a_{j, n} E_{i m}

$$

\end{proof}


theorem exercise_4_5_16 {p n: ℕ} (hp : nat.prime p)
  {q : polynomial (zmod p)} (hq : irreducible q) (hn : q.degree = n) :
  ∃ is_fin : fintype $ polynomial (zmod p) ⧸ ideal.span ({q} : set (polynomial $ zmod p)),
  @card (polynomial (zmod p) ⧸ ideal.span {q}) is_fin = p ^ n ∧
  is_field (polynomial $ zmod p):=

Let $F = \mathbb{Z}_p$ be the field of integers $\mod p$, where $p$ is a prime, and let $q(x) \in F[x]$ be irreducible of degree $n$. Show that $F[x]/(q(x))$ is a field having at exactly $p^n$ elements.

\begin{proof}

    In the previous problem we have shown that any for any $p(x) \in F[x]$, we have that

$$

p(x)+(q(x))=a_{n-1} x^{n-1}+\cdots+a_1 x+a_0+(q(x))

$$

for some $a_{n-1}, \ldots, a_0 \in F$, and that there are $p^n$ choices for these numbers, so that $F[x] /(q(x)) \leq p^n$. In order to show that equality holds, we have to show that each of these choices induces a different element of $F[x] /(q(x))$; in other words, that each different polynomial of degree $n-1$ or lower belongs to a different coset of $(q(x))$ in $F[x]$.

Suppose now, then, that

$$

a_{n-1} x^{n-1}+\cdots+a_1 x+a_0+(q(x))=b_{n-1} x^{n-1}+\cdots+b_1 x+b_0+(q(x))

$$

which is equivalent with $\left(a_{n-1}-b_{n-1}\right)^{n-1}+\cdots\left(a_1-b_1\right) x+\left(a_0-b_0\right) \in(q(x))$, which is in turn equivalent with there being a $w(x) \in F[x]$ such that

$$

q(x) w(x)=\left(a_{n-1}-b_{n-1}\right)^{n-1}+\cdots\left(a_1-b_1\right) x+\left(a_0-b_0\right) .

$$

Degree of the right hand side is strictly smaller than $n$, while the degree of the left hand side is greater or equal to $n$ except if $w(x)=0$, so that if equality is hold we must have that $w(x)=0$, but then since polynomials are equal iff all of their coefficient are equal we get that $a_{n-1}-b_{n-1}=$ $0, \ldots, a_1-b_1=0, a_0-b_0=0$, i.e.

$$

a_{n-1}=b_{n-1}, \ldots, a_1=b_1, a_0=b_0

$$

which is what we needed to prove.

\end{proof}


theorem exercise_4_5_25 {p : ℕ} (hp : nat.prime p) :
  irreducible (∑ i : finset.range p, X ^ p : polynomial ℚ) :=

If $p$ is a prime, show that $q(x) = 1 + x + x^2 + \cdots x^{p - 1}$ is irreducible in $Q[x]$.

\begin{proof}

    Lemma: Let $F$ be a field and $f(x) \in F[x]$. If $c \in F$ and $f(x+c)$ is irreducible in $F[x]$, then $f(x)$ is irreducible in $F[x]$.

Proof of the Lemma: Suppose that $f(x)$ is reducible, i.e., there exist non-constant $g(x), h(x) \in F[x]$ so that

$$

f(x)=g(x) h(x) .

$$

In particular, then we have

$$

f(x+c)=g(x+c) h(x+c) .

$$

Note that $g(x+c)$ and $h(x+c)$ have the same degree at $g(x)$ and $h(x)$ respectively; in particular, they are non-constant polynomials. So our assumption is wrong.

Hence, $f(x)$ is irreducible in $F[x]$. This proves our Lemma.

Now recall the identity

$$

\frac{x^p-1}{x-1}=x^{p-1}+x^{p-2}+\ldots \ldots+x^2+x+1 .

$$

We prove that $f(x+1)$ is $\$$ |textbffirreducible in $\mathbb{Q}[x]$ and then apply the Lemma to conclude that $f(x)$ is irreducible in $\mathbb{Q}[x] .3 \$$ Note that

$$

\begin{aligned}

& f(x+1)=\frac{(x+1)^p-1}{x} \\

& =\frac{x^p+p x^{p-1}+\ldots+p x}{x} \\

& =x^{p-1}+p x^{p-2}+\ldots .+p .

\end{aligned}

$$

Using that the binomial coefficients occurring above are all divisible by $p$, we have that $f(x+1)$ is irreducible $\mathbb{Q}[x]$ by Eisenstein's criterion applied with prime $p$.

Then by the lemma $f(x)$ is irreducible $\mathbb{Q}[x]$. This completes the proof.

\end{proof}


theorem exercise_4_6_3 :
  infinite {a : ℤ | irreducible (X^7 + 15*X^2 - 30*X + a : polynomial ℚ)} :=

Show that there is an infinite number of integers a such that $f(x) = x^7 + 15x^2 - 30x + a$ is irreducible in $Q[x]$.

\begin{proof}

    Via Eisenstein's criterion and observation that 5 divides 15 and $-30$, it is sufficient to find infinitely many $a$ such that 5 divides $a$, but $5^2=25$ doesn't divide $a$. For example $5 \cdot 2^k$ for $k=0,1, \ldots$ is one such infinite sequence.

\end{proof}


theorem exercise_5_2_20 {F V ι: Type*} [infinite F] [field F]
  [add_comm_group V] [module F V] {u : ι → submodule F V}
  (hu : ∀ i : ι, u i ≠ ⊤) :
  (⋃ i : ι, (u i : set V)) ≠ ⊤ :=

Let $V$ be a vector space over an infinite field $F$. Show that $V$ cannot be the set-theoretic union of a finite number of proper subspaces of $V$.

\begin{proof}

    Assume that $V$ can be written as the set-theoretic union of $n$ proper subspaces $U_1, U_2, \ldots, U_n$. Without loss of generality, we may assume that no $U_i$ is contained in the union of other subspaces.

Let $u \in U_i$ but $u \notin \bigcup_{j \neq i} U_j$ and $v \notin U_i$. Then, we have $(v + Fu) \cap U_i = \varnothing$, and $(v + Fu) \cap U_j$ for $j \neq i$ contains at most one vector, since otherwise $U_j$ would contain $u$.

Therefore, we have $|v + Fu| \leq |F| \leq n-1$. However, since $n$ is a finite natural number, this contradicts the fact that the field $F$ is finite.

Thus, our assumption that $V$ can be written as the set-theoretic union of proper subspaces is wrong, and the claim is proven.

\end{proof}


theorem exercise_5_3_10 : is_algebraic ℚ (cos (real.pi / 180)) :=

Prove that $\cos 1^{\circ}$  is algebraic over $\mathbb{Q}$.

\begin{proof}

    Since $\left(\cos \left(1^{\circ}\right)+i \sin \left(1^{\circ}\right)\right)^{360}=1$, the number $\cos \left(1^{\circ}\right)+i \sin \left(1^{\circ}\right)$ is algebraic. And the real part and the imaginary part of an algebraic number are always algebraic numbers.

\end{proof}


theorem exercise_5_5_2 : irreducible (X^3 - 3*X - 1 : polynomial ℚ) :=

Prove that $x^3 - 3x - 1$ is irreducible over $\mathbb{Q}$.

\begin{proof}

Let $p(x)=x^3-3 x-1$. Then

$$

p(x+1)=(x+1)^3-3(x+1)-1=x^3+3 x^2-3

$$

We have $3|3,3| 0$ but $3 \nmid 1$ and $3^2 \nmid 3$. Thus the polynomial is irreducible over $\mathbb{Q}$ by 3 -Eisenstein criterion.

\end{proof}


theorem exercise_2_12a (f : ℕ → ℕ) (p : ℕ → ℝ) (a : ℝ)
  (hf : injective f) (hp : tendsto p at_top (𝓝 a)) :
  tendsto (λ n, p (f n)) at_top (𝓝 a) :=

import .common

open set real filter function ring_hom topological_space

open_locale big_operators
open_locale filter
open_locale topology
noncomputable theory

Let $(p_n)$ be a sequence and $f:\mathbb{N}\to\mathbb{N}$. The sequence $(q_k)_{k\in\mathbb{N}}$ with $q_k=p_{f(k)}$ is called a rearrangement of $(p_n)$. Show that if $f$ is an injection, the limit of a sequence is unaffected by rearrangement.

\begin{proof}

    Let $\varepsilon>0$. Since $p_n \rightarrow L$, we have that, for all $n$ except $n \leq N$, $d\left(p_n, L\right)<\epsilon$. Let $S=\{n \mid f(n) \leq N\}$, let $n_0$ be the largest $n \in S$, we know there is such a largest $n$ because $f(n)$ is injective. Now we have that $\forall n>n_0 f(n)>N$ which implies that $p_{f(n)} \rightarrow L$, as required.

\end{proof}


theorem exercise_2_29 (M : Type*) [metric_space M]
  (O C : set (set M))
  (hO : O = {s | is_open s})
  (hC : C = {s | is_closed s}) :
  ∃ f : O → C, bijective f :=

Let $\mathcal{T}$ be the collection of open subsets of a metric space $\mathrm{M}$, and $\mathcal{K}$ the collection of closed subsets. Show that there is a bijection from $\mathcal{T}$ onto $\mathcal{K}$.

\begin{proof}

   The bijection given by $x\mapsto X^C$ suffices.

\end{proof}


theorem exercise_2_41 (m : ℕ) {X : Type*} [normed_space ℝ ((fin m) → ℝ)] :
  is_compact (metric.closed_ball 0 1) :=

Let $\|\cdot\|$ be any norm on $\mathbb{R}^{m}$ and let $B=\left\{x \in \mathbb{R}^{m}:\|x\| \leq 1\right\}$. Prove that $B$ is compact.

\begin{proof}

    Let us call $\|\cdot\|_E$ the Euclidean norm in $\mathbb{R}^m$. We start by claiming that there exist constants $C_1, C_2>0$ such that

$$

C_1\|x\|_E \leq\|x\| \leq C_2\|x\|_E, \forall x \in \mathbb{R}^m .

$$

Assuming (1) to be true, let us finish the problem. First let us show that $B$ is bounded w.r.t. $d_E$, which is how we call the Euclidean distance in $\mathbb{R}^m$. Indeed, given $x \in B,\|x\|_E \leq \frac{1}{C_1}\|x\| \leq \frac{1}{C_1}$. Hence $B \subset\left\{x \in \mathbb{R}^m: d_E(x, 0)<\frac{1}{C_1}+1\right\}$, which means $B$ is bounded w.r.t $d_E$.

Now let us show that $B$ is closed w.r.t. $d_E$. Let $x_n \rightarrow x$ w.r.t. $d_E$, where $x_n \in B$. Notice that this implies that $x_n \rightarrow x$ w.r.t. $d(x, y)=\|x-y\|$, the distance coming from $\|\cdot\|$, since by (1) we have

$$

d\left(x_n, x\right)=\left\|x_n-x\right\| \leq C_2\left\|x_n-x\right\|_E \rightarrow 0 .

$$

Also, notice that

$$

\|x\| \leq\left\|x_n-x\right\|+\left\|x_n\right\| \leq\left\|x_n-x\right\|+1,

$$

hence passing to the limit we obtain that $\|x\| \leq 1$, therefore $x \in B$ and so $B$ is closed w.r.t. $d_E$. Since $B$ is closed and bounded w.r.t. $d_E$, it must be compact. Now we claim that the identity function, $i d:\left(\mathbb{R}^m, d_E\right) \rightarrow\left(\mathbb{R}^m, d\right)$ where $\left(\mathbb{R}^m, d_E\right)$ means we are using the distance $d_E$ in $\mathbb{R}^m$ and $\left(\mathbb{R}^m, d\right)$ means we are using the distance $d$ in $\mathbb{R}^m$, is a homeomorphism. This follows by (1), since $i d$ is always a bijection, and it is continuous and its inverse is continuous by (1) (if $x_n \rightarrow x$ w.r.t. $d_E$, then $x_n \rightarrow x$ w.r.t. $d$ and vice-versa, by (1)). By a result we saw in class, since $B$ is compact in $\left(\mathbb{R}^m, d_E\right)$ and $i d$ is a homeomorphism, then $i d(B)=B$ is compact w.r.t. $d$.

We are left with proving (1). Notice that it suffices to prove that $C_1 \leq\|x\| \leq$ $C_2, \forall x \in \mathbb{R}^m$ with $\|x\|_E=1$. Indeed, if this is true, given $x \in \mathbb{R}^m$, either $\|x\|_E=0$ (which implies $x=0$ and (1) holds in this case), or $x /\|x\|_E=y$ is such that $\|y\|_E=1$, so $C_1 \leq\|y\| \leq C_2$, which implies $C_1\|x\|_E \leq\|x\| \leq C_2\|x\|_E$.

We want to show now that $\|\cdot\|$ is continuous w.r.t. $d_E$, that is, given $\varepsilon>0$ and $x \in \mathbb{R}^m$, there exists $\delta>0$ such that if $d_E(x, y)<\delta$, then $\|\mid x\|-\|y\| \|<\varepsilon$.

By the triangle inequality, $\|x\|-\|y\| \leq\|x-y\|$, and $\|y\|-\|x\| \leq\|x-y\|$, therefore

$$

|\|x||-\| y|\|\leq\| x-y \| .

$$

Writing now $x=\sum_{i=1}^m a_i e_i, y=\sum_{i=1}^m b_i e_i$, where $e_i=(0, \ldots, 1,0, \ldots, 0)$ (with 1 in the i-th component), we obtain by the triangle inequality,

$$

\begin{aligned}

\|x-y\| & =\left\|\sum_{i=1}^m\left(a_i-b_i\right) e_i\right\| \leq \sum_{i=1}^m\left|a_i-b_i\left\|\left|\left\|e_i\right\| \leq \max _{i=1, \ldots, m}\left\|e_i\right\| \sum_{i=1}^m\right| a_i-b_i \mid\right.\right. \\

& =\max _{i=1, \ldots, m}\left\|e_i\right\| d_{s u m}(x, y) \leq \max _{i=1, \ldots, m}\left\|e_i\right\| m d_{\max }(x, y) \\

& \leq \max _{i=1, \ldots, m}\left\|e_i\right\| m d_E(x, y) .

\end{aligned}

$$

Let $\delta=\frac{\varepsilon}{m \max _{i=1, \ldots, m}\left\|e_i\right\|}$. Then if $d_E(x, y)<\delta,\|x\|-\|y\|||<\varepsilon$.

Since $\|\cdot\|$ is continuous w.r.t. $d_E$ and $K=\left\{x \in \mathbb{R}^m:\|x\|_E=1\right\}$ is compact w.r.t. $d_E$, then the function $\|\cdot\|$ achieves a maximum and a minimum value on $K$. Call $C_1=\min _{x \in K}\|x\|, C_2=\max _{x \in K}\|x\|$. Then

$$

C_1 \leq\|x\| \leq C_2, \forall x \in \mathbb{R}^m \text { such that }\|x\|_E=1,

$$

which is what we needed.

\end{proof}


theorem exercise_2_57 {X : Type*} [topological_space X]
  : ∃ (S : set X), is_connected S ∧ ¬ is_connected (interior S) :=

Show that if $S$ is connected, it is not true in general that its interior is connected.

\begin{proof}

    Consider $X=\mathbb{R}^2$ and

$$

A=([-2,0] \times[-2,0]) \cup([0,2] \times[0,2])

$$

which is connected, while $\operatorname{int}(A)$ is not connected.

To see this consider the continuous function $f: \mathbb{R}^2 \rightarrow \mathbb{R}$ is defined by $f(x, y)=x+y$. Let $U=f^{-1}(0,+\infty)$ which is open in $\mathbb{R}^2$ and so $U \cap \operatorname{int}(A)$ is open in $\operatorname{int}(A)$. Also, since $(0,0) \notin \operatorname{int}(A)$, so for all $(x, y) \in \operatorname{int}(A), f(x, y) \neq 0$ and $U \cap \operatorname{int}(A)=f^{-1}[0,+\infty) \cap \operatorname{int}(A)$ is closed in $\operatorname{int}(A)$. Furthermore, $(1,1)=f^{-1}(2) \in U \cap \operatorname{int}(A)$ shows that $U \cap \operatorname{int}(A) \neq \emptyset$ while $(-1,-1) \in \operatorname{int}(A)$ and $(-1,-1) \notin U$ shows that $U \cap \operatorname{int}(A) \neq \operatorname{int}(A)$.

\end{proof}


theorem exercise_2_126 {E : set ℝ}
  (hE : ¬ set.countable E) : ∃ (p : ℝ), cluster_pt p (𝓟 E) :=

Suppose that $E$ is an uncountable subset of $\mathbb{R}$. Prove that there exists a point $p \in \mathbb{R}$ at which $E$ condenses.

\begin{proof}

    I think this is the proof by contrapositive that you were getting at.

Suppose that $E$ has no limit points at all. Pick an arbitrary point $x \in E$. Then $x$ cannot be a limit point, so there must be some $\delta>0$ such that the ball of radius $\delta$ around $x$ contains no other points of $E$ :

$$

B_\delta(x) \cap E=\{x\}

$$

Call this "point 1 ". For the next point, take the closest element to $x$ and on its left; that is, choose the point

$$

\max [E \cap(-\infty, x)]

$$

if it exists (that is important - if not, skip to the next step). Note that by the argument above, this supremum, should it exist, cannot equal $x$ and is therefore a new point in $E$.

Call this "point 2 ". Now take the first point to the right of $x$ for "point 3 ". Take the first point to the left of point 2 for "point 4 ". And so on, ad infinitum.

This gives a countable list of unique points; we must show that it exhausts the entire set $E$. Suppose not. Suppose there is some element $a<x$ which is never included in the list (picking $a$ on the negative side of $x$ is arbitrary, and the same argument would work for the second case). Then the element closest and to the right of $a$ in $E$ (which exists, by the no-limit-points argument at the beginning) is also not in the list; if it was, $a$ would have been in one of the next two spots. And same with that point (call it $a_1$ ); there is a closest $a_2>a_1 \in E$ such that $a_2$ is not in the list. Repeating, we generate an infinite monotone-increasing sequence $\left\{a_i\right\}$ of elements in $E$ and not in the list, which is clearly bounded above by $x$. By the Monotone

Convergence Theorem this sequence has a limit. But that means the sequence $\left\{a_i\right\} \subset E$ converges to a limit, and hence $E$ has a limit point, contradicting the assumption. Therefore our list exhausts $E$, and we have enumerated all its elements.

\end{proof}


theorem exercise_3_4 (n : ℕ) :
  tendsto (λ n, (sqrt (n + 1) - sqrt n)) at_top (𝓝 0) :=

Prove that $\sqrt{n+1}-\sqrt{n} \rightarrow 0$ as $n \rightarrow \infty$.

\begin{proof}

    $$

\sqrt{n+1}-\sqrt{n}=\frac{(\sqrt{n+1}-\sqrt{n})(\sqrt{n+1}+\sqrt{n})}{\sqrt{n+1}+\sqrt{n}}=\frac{1}{\sqrt{n+1}+\sqrt{n}}<\frac{1}{2 \sqrt{n}}

$$

\end{proof}


theorem exercise_3_63b (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$ diverges when $p \leq 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_2_2_9 {G : Type*} [group G] {a b : G}
  (h : a * b = b * a) :
  ∀ x y : closure {x | x = a ∨ x = b}, x*y = y*x :=

import .common

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

Let $H$ be the subgroup generated by two elements $a, b$ of a group $G$. Prove that if $a b=b a$, then $H$ is an abelian group.

\begin{proof}

    Since $a$ and $b$ commute, for any $g, h\in H$ we can write $g=a^ib^j$ and $h = a^kb^l$. Then $gh = a^ib^ja^kb^l = a^kb^la^ib^j = hg$. Thus $H$ is abelian.

\end{proof}


theorem exercise_2_4_19 {G : Type*} [group G] {x : G}
  (hx : order_of x = 2) (hx1 : ∀ y, order_of y = 2 → y = x) :
  x ∈ center G :=

Prove that if a group contains exactly one element of order 2 , then that element is in the center of the group.

\begin{proof}

   Let $x$ be the element of order two. Consider the element $z=y^{-1} x y$, we have: $z^2=\left(y^{-1} x y\right)^2=\left(y^{-1} x y\right)\left(y^{-1} x y\right)=e$. So: $z=x$, and $y^{-1} x y=x$. So: $x y=y x$. So: $x$ is in the center of $G$.

\end{proof}


theorem exercise_2_11_3 {G : Type*} [group G] [fintype G]
  (hG : even (card G)) : ∃ x : G, order_of x = 2 :=

Prove that a group of even order contains an element of order $2 .$

\begin{proof}

    Pair up if possible each element of $G$ with its inverse, and observe that

$$

g^2 \neq e \Longleftrightarrow g \neq g^{-1} \Longleftrightarrow \text { there exists the pair }\left(g, g^{-1}\right)

$$

Now, there is one element that has no pairing: the unit $e$ (since indeed $e=e^{-1} \Longleftrightarrow e^2=e$ ), so since the number of elements of $G$ is even there must be at least one element more, say $e \neq a \in G$, without a pairing, and thus $a=a^{-1} \Longleftrightarrow a^2=e$

\end{proof}


theorem exercise_3_5_6 {K V : Type*} [field K] [add_comm_group V]
  [module K V] {S : set V} (hS : set.countable S)
  (hS1 : span K S = ⊤) {ι : Type*} (R : ι → V)
  (hR : linear_independent K R) : countable ι :=

Let $V$ be a vector space which is spanned by a countably infinite set. Prove that every linearly independent subset of $V$ is finite or countably infinite.

\begin{proof}

    Let $A$ be the countable generating set, and let $U$ be an uncountable linearly independent set. It can be extended to a basis $B$ of the whole space. Now consider the subset $C$ of elements of $B$ that appear in the $B$-decompositions of elements of $A$.

Since only finitely many elements are involved in the decomposition of each element of $A$, the set $C$ is countable. But $C$ also clearly generates the vector space $V$. This contradicts the fact that it is a proper subset of the basis $B$ (since $B$ is uncountable).

\end{proof}


theorem exercise_6_1_14 (G : Type*) [group G]
  (hG : is_cyclic $ G ⧸ (center G)) :
  center G = ⊤  :=

Let $Z$ be the center of a group $G$. Prove that if $G / Z$ is a cyclic group, then $G$ is abelian and hence $G=Z$.

\begin{proof}

    We have that $G / Z(G)$ is cyclic, and so there is an element $x \in G$ such that $G / Z(G)=\langle x Z(G)\rangle$, where $x Z(G)$ is the coset with representative $x$. Now let $g \in G$

We know that $g Z(G)=(x Z(G))^m$ for some $m$, and by definition $(x Z(G))^m=x^m Z(G)$.

Now, in general, if $H \leq G$, we have by definition too that $a H=b H$ if and only if $b^{-1} a \in H$.

In our case, we have that $g Z(G)=x^m Z(G)$, and this happens if and only if $\left(x^m\right)^{-1} g \in Z(G)$.

Then, there's a $z \in Z(G)$ such that $\left(x^m\right)^{-1} g=z$, and so $g=x^m z$.

$g, h \in G$ implies that $g=x^{a_1} z_1$ and $h=x^{a_2} z_2$, so

$$

\begin{aligned}

g h & =\left(x^{a_1} z_1\right)\left(x^{a_2} z_2\right) \\

& =x^{a_1} x^{a_2} z_1 z_2 \\

& =x^{a_1+a_2} z_2 z_1 \\

& =\ldots=\left(x^{a_2} z_2\right)\left(x^{a_1} z_1\right)=h g .

\end{aligned}

$$

Therefore, $G$ is abelian.

\end{proof}


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

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

\begin{proof}

    We may as well assume $p<q$. The number of Sylow $q$-subgroups is $1 \bmod q$ and divides $p^2$. So it is $1, p$, or $p^2$. We win if it's 1 and it can't be $p$, so suppose it's $p^2$. But now $q \mid p^2-1$, so $q \mid p+1$ or $q \mid p-1$.

Thus $p=2$ and $q=3$. But we know no group of order 36 is simple.

\end{proof}


theorem exercise_6_8_1 {G : Type*} [group G]
  (a b : G) : closure ({a, b} : set G) = closure {b*a*b^2, b*a*b^3} :=

Prove that two elements $a, b$ of a group generate the same subgroup as $b a b^2, b a b^3$.

\begin{proof}

    Let $H = \langle bab^2, bab^3\rangle$. It is clear that $H\subset \langle a, b\rangle$. Note that $(bab^2)^{-1}(bab^3)=b$, therefore $b\in H$. This then implies that $b^{-1}(bab^2)b^{-2}=a\in H$. Thus $\langle a, b\rangle\subset H$.

\end{proof}


theorem exercise_10_2_4 :
  span ({2} : set $ polynomial ℤ) ⊓ (span {X}) =
  span ({2 * X} : set $ polynomial ℤ) :=

Prove that in the ring $\mathbb{Z}[x],(2) \cap(x)=(2 x)$.

\begin{proof}

    Let $f(x) \in(2 x)$. Then there exists some polynomial $g(x) \in \mathbb{Z}$ such that

$$

f(x)=2 x g(x)

$$

But this means that $f(x) \in(2)$ (because $x g(x)$ is a polynomial), and $f(x) \in$ $(x)$ (because $2 g(x)$ is a polynomial). Thus, $f(x) \in(2) \cap(x)$, and

$$

(2 x) \subseteq(2) \cap(x)

$$

On the other hand, let $p(x) \in(2) \cap(x)$. Since $p(x) \in(2)$, there exists some polynomial $h(x) \in \mathbb{Z}[x]$ such that

$$

p(x)=2 h(x)

$$

Furthermore, $p(x) \in(x)$, so

$$

p(x)=x h_2(x)

$$

So, $2 h(x)=x h_2(x)$, for some $h_2(x) \in \mathbb{Z}[x]$. This means that $h(0)=0$, so $x$ divides $h(x)$; that is,

$$

h(x)=x q(x)

$$

for some $q(x) \in \mathbb{Z}[x]$, and

$$

p(x)=2 x q(x)

$$

Thus, $p(x) \in(2 x)$, and

$$

\text { (2) } \cap(x) \subseteq(2 x)

$$

Finally,

(2) $\cap(x)=(2 x)$,

as required.

\end{proof}


theorem exercise_10_4_6 {R : Type*} [comm_ring R]
  [no_zero_divisors R] {I J : ideal R} (x : I ⊓ J) :
  is_nilpotent ((ideal.quotient.mk (I*J)) x) :=

Let $I, J$ be ideals in a ring $R$. Prove that the residue of any element of $I \cap J$ in $R / I J$ is nilpotent.

\begin{proof}

    If $x$ is in $I \cap J, x \in I$ and $x \in J . R / I J=\{r+a b: a \in I, b \in J, r \in R\}$. Then $x \in I \cap J \Rightarrow x \in I$ and $x \in J$, and so $x^2 \in I J$. Thus

$$

[x]^2=\left[x^2\right]=[0] \text { in } R / I J

$$

\end{proof}


theorem exercise_10_7_10 {R : Type*} [ring R]
  (M : ideal R) (hM : ∀ (x : R), x ∉ M → is_unit x) :
  is_maximal M ∧ ∀ (N : ideal R), is_maximal N → N = M :=

Let $R$ be a ring, with $M$ an ideal of $R$. Suppose that every element of $R$ which is not in $M$ is a unit of $R$. Prove that $M$ is a maximal ideal and that moreover it is the only maximal ideal of $R$.

\begin{proof}

Suppose there is an ideal $M\subset I\subset R$. If $I\neq M$, then $I$ contains a unit, thus $I=R$. Therefore $M$ is a maximal ideal.

Suppose we have an arbitrary maximal ideal $M^\prime$ of $R$. The ideal $M^\prime$ cannot contain a unit, otherwise $M^\prime =R$. Therefore $M^\prime \subset M$. But we cannot have $M^\prime \subsetneq M \subsetneq R$, therefore $M=M^\prime$.

\end{proof}


theorem exercise_11_4_1b {F : Type*} [field F] [fintype F] (hF : card F = 2) :
  irreducible (12 + 6 * X + X ^ 3 : polynomial F) :=

Prove that $x^3 + 6x + 12$ is irreducible in $\mathbb{Q}$.

\begin{proof}

    Apply Eisenstein's criterion with $p=3$.

\end{proof}


theorem exercise_11_4_6b {F : Type*} [field F] [fintype F] (hF : card F = 31) :
  irreducible (X ^ 3 - 9 : polynomial F) :=

Prove that $x^2+1$ is irreducible in $\mathbb{F}_7$

\begin{proof}

    If $p(x)=x^2+1$ were reducible, its factors must be linear. But no $p(a)$ for $a\in\mathbb{F}_7$ evaluates to 0, therefore $x^2+1$ is irreducible.

\end{proof}


theorem exercise_11_4_8 {p : ℕ} (hp : prime p) (n : ℕ) :
  irreducible (X ^ n - p : polynomial ℚ) :=

Let $p$ be a prime integer. Prove that the polynomial $x^n-p$ is irreducible in $\mathbb{Q}[x]$.

\begin{proof}

   Straightforward application of Eisenstein's criterion with $p$.

\end{proof}


Prove that if a prime integer $p$ has the form $2^r+1$, then it actually has the form $2^{2^k}+1$.

\begin{proof}

    In particular, we have

$$

\frac{x^a+1}{x+1}=\frac{(-x)^a-1}{(-x)-1}=1-x+x^2-\cdots+(-x)^{a-1}

$$

by the geometric sum formula. In this case, specialize to $x=2^{2^m}$ and we have a nontrivial divisor.

\end{proof}


import .common

open real topological_space filter polynomial
open_locale topology big_operators complex_conjugate filter ennreal

\begin{proof}

    It will suffice to show that for any $z_1, z_2, z_3, z_4 \in \mathbb{C}$ of modulus 1 such that $|3-z_1-z_2-z_3-z_4| = |z_1z_2z_3z_4|$, at least one of $z_1, z_2, z_3$ is equal to 1.

To this end, let $z_1=e^{\alpha i}, z_2=e^{\beta i}, z_3=e^{\gamma i}$ and

\[

f(\alpha, \beta, \gamma)=|3-z_1-z_2-z_3|^2-|1-z_1z_2z_3|^2.

\]

 A routine calculation shows that

\begin{align*}

f(\alpha, \beta, \gamma)&=

10 - 6\cos(\alpha) - 6\cos(\beta) - 6\cos(\gamma) \\

&\quad + 2\cos(\alpha + \beta + \gamma) + 2\cos(\alpha - \beta) \\

&\quad + 2\cos(\beta - \gamma) + 2\cos(\gamma - \alpha).

\end{align*}

Since the function $f$ is continuously differentiable, and periodic in each variable, $f$ has a maximum and a minimum and it attains these values only at points where $\nabla f=(0,0,0)$.  A routine calculation now shows that

\begin{align*}

\frac{\partial f}{\partial \alpha} + \frac{\partial f}{\partial \beta} + \frac{\partial f}{\partial \gamma} &=

6(\sin(\alpha) +\sin(\beta)+\sin(\gamma)-  \sin(\alpha + \beta + \gamma)) \\

&=

24\sin\left(\frac{\alpha+\beta}{2}\right) \sin\left(\frac{\beta+\gamma}{2}\right)

\sin\left(\frac{\gamma+\alpha}{2}\right).

\end{align*}

Hence every critical point of $f$ must satisfy one of $z_1z_2=1$, $z_2z_3=1$, or $z_3z_1=1$. By symmetry, let us assume that $z_1z_2=1$. Then

\[

f = |3-2\mathrm{Re}(z_1)-z_3|^2-|1-z_3|^2;

\]

since $3-2\mathrm{Re}(z_1)\ge 1$, $f$ is nonnegative and can be zero only if the real part of $z_1$, and hence also $z_1$ itself, is equal to $1$.

\end{proof}


theorem exercise_2018_b2 (n : ℕ) (hn : n > 0) (f : ℕ → ℂ → ℂ)
  (hf : ∀ n : ℕ, f n = λ z, (∑ (i : fin n), (n-i)* z^(i : ℕ))) :
  ¬ (∃ z : ℂ, ‖z‖ ≤ 1 ∧ f n z = 0) :=

Let $n$ be a positive integer, and let $f_{n}(z)=n+(n-1) z+$ $(n-2) z^{2}+\cdots+z^{n-1}$. Prove that $f_{n}$ has no roots in the closed unit disk $\{z \in \mathbb{C}:|z| \leq 1\}$.

\begin{proof}

    Note first that $f_n(1) > 0$, so $1$ is not a root of $f_n$.

Next, note that

\[

(z-1)f_n(z) = z^n + \cdots + z - n;

\]

however, for $\left| z \right| \leq 1$, we have

$\left| z^n + \cdots + z \right| \leq n$ by the triangle inequality;

equality can only occur if $z,\dots,z^n$ have norm 1 and the same argument, which only happens for $z=1$.

Thus there can be no root of $f_n$ with $|z| \leq 1$.

\end{proof}


Suppose that $f(x)=\sum_{i=0}^{\infty} c_{i} x^{i}$ is a power series for which each coefficient $c_{i}$ is 0 or 1 . Show that if $f(2 / 3)=3 / 2$, then $f(1 / 2)$ must be irrational.

\begin{proof}

    Suppose by way of contradiction that $f(1/2)$ is rational. Then $\sum_{i=0}^{\infty} c_i 2^{-i}$ is the binary expansion of a rational number, and hence must be eventually periodic; that is, there exist some integers $m,n$ such that

$c_i = c_{m+i}$ for all $i \geq n$. We may then write

\[

f(x) = \sum_{i=0}^{n-1} c_i x^i + \frac{x^n}{1-x^m} \sum_{i=0}^{m-1} c_{n+i} x^i.

\]

Evaluating at $x = 2/3$, we may equate $f(2/3) = 3/2$ with

\[

\frac{1}{3^{n-1}} \sum_{i=0}^{n-1} c_i 2^i 3^{n-i-1} + \frac{2^n 3^m}{3^{n+m-1}(3^m-2^m)} \sum_{i=0}^{m-1} c_{n+i} 2^i 3^{m-1-i};

\]

since all terms on the right-hand side have odd denominator, the same must be true of the sum, a contradiction.

\end{proof}


Prove that for each positive integer $n$, the number $10^{10^{10^n}}+10^{10^n}+10^n-1$ is not prime.

\begin{proof}

    Put

\[

N = 10^{10^{10^n}} + 10^{10^n} + 10^n - 1.

\]

Write $n = 2^m k$ with $m$ a nonnegative integer and $k$ a positive odd integer.

For any nonnegative integer $j$,

\[

10^{2^m j} \equiv (-1)^j \pmod{10^{2^m} + 1}.

\]

Since $10^n \geq n \geq 2^m \geq m+1$, $10^n$ is divisible by $2^n$ and hence by $2^{m+1}$,

and similarly $10^{10^n}$ is divisible by $2^{10^n}$ and hence by $2^{m+1}$. It follows that

\[

N \equiv 1 + 1 + (-1) + (-1) \equiv 0 \pmod{10^{2^m} + 1}.

\]

Since $N \geq 10^{10^n} > 10^n + 1 \geq 10^{2^m} + 1$, it follows that $N$ is composite.

\end{proof}


Prove that there exist infinitely many integers $n$ such that $n, n+1, n+2$ are each the sum of the squares of two integers.

\begin{proof}

    It is well-known that the equation $x^2-2y^2=1$ has infinitely

many solutions (the so-called ``Pell'' equation).  Thus setting

$n=2y^2$ (so that $n=y^2+y^2$, $n+1=x^2+0^2$, $n+2=x^2+1^2$)

yields infinitely many $n$ with the desired property.

\end{proof}


theorem exercise_1998_a3 (f : ℝ → ℝ) (hf : cont_diff ℝ 3 f) :
  ∃ a : ℝ, (f a) * (deriv f a) * (iterated_deriv 2 f a) * (iterated_deriv 3 f a) ≥ 0 :=

Let $f$ be a real function on the real line with continuous third derivative. Prove that there exists a point $a$ such that


theorem exercise_1_1a
  (x : ℝ) (y : ℚ) :
  ( 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 $r+x$ is irrational.

\begin{proof}

    If $r$ and $r+x$ were both rational, then $x=r+x-r$ would also be rational.

\end{proof}


theorem exercise_1_2 : ¬ ∃ (x : ℚ), ( x ^ 2 = 12 ) :=

Prove that there is no rational number whose square is $12$.

\begin{proof}

    Suppose $m^2=12 n^2$, where $m$ and $n$ have no common factor. It follows that $m$ must be even, and therefore $n$ must be odd. Let $m=2 r$. Then we have $r^2=3 n^2$, so that $r$ is also odd. Let $r=2 s+1$ and $n=2 t+1$. Then

$$

4 s^2+4 s+1=3\left(4 t^2+4 t+1\right)=12 t^2+12 t+3,

$$

so that

$$

4\left(s^2+s-3 t^2-3 t\right)=2 .

$$

But this is absurd, since 2 cannot be a multiple of 4 .

\end{proof}


theorem exercise_1_5 (A minus_A : set ℝ) (hA : A.nonempty)
  (hA_bdd_below : bdd_below A) (hminus_A : minus_A = {x | -x ∈ A}) :
  Inf A = Sup minus_A :=

Let $A$ be a nonempty set of real numbers which is bounded below. Let $-A$ be the set of all numbers $-x$, where $x \in A$. Prove that $\inf A=-\sup (-A)$.

\begin{proof}

    We need to prove that $-\sup (-A)$ is the greatest lower bound of $A$. For brevity, let $\alpha=-\sup (-A)$. We need to show that $\alpha \leq x$ for all $x \in A$ and $\alpha \geq \beta$ if $\beta$ is any lower bound of $A$.

Suppose $x \in A$. Then, $-x \in-A$, and, hence $-x \leq \sup (-A)$. It follows that $x \geq-\sup (-A)$, i.e., $\alpha \leq x$. Thus $\alpha$ is a lower bound of $A$.

Now let $\beta$ be any lower bound of $A$. This means $\beta \leq x$ for all $x$ in $A$. Hence $-x \leq-\beta$ for all $x \in A$, which says $y \leq-\beta$ for all $y \in-A$. This means $-\beta$ is an upper bound of $-A$. Hence $-\beta \geq \sup (-A)$ by definition of sup, i.e., $\beta \leq-\sup (-A)$, and so $-\sup (-A)$ is the greatest lower bound of $A$.

\end{proof}


theorem exercise_1_11a (z : ℂ) :
  ∃ (r : ℝ) (w : ℂ), abs w = 1 ∧ z = r * w :=

If $z$ is a complex number, prove that there exists an $r\geq 0$ and a complex number $w$ with $| w | = 1$ such that $z = rw$.

\begin{proof}

    If $z=0$, we take $r=0, w=1$. (In this case $w$ is not unique.) Otherwise we take $r=|z|$ and $w=z /|z|$, and these choices are unique, since if $z=r w$, we must have $r=r|w|=|r w|=|z|, z / r$

\end{proof}


theorem exercise_1_13 (x y : ℂ) :
  |(abs x) - (abs y)| ≤ abs (x - y) :=

If $x, y$ are complex, prove that $||x|-|y|| \leq |x-y|$.

\begin{proof}

    Since $x=x-y+y$, the triangle inequality gives

$$

|x| \leq|x-y|+|y|

$$

so that $|x|-|y| \leq|x-y|$. Similarly $|y|-|x| \leq|x-y|$. Since $|x|-|y|$ is a real number we have either ||$x|-| y||=|x|-|y|$ or ||$x|-| y||=|y|-|x|$. In either case, we have shown that ||$x|-| y|| \leq|x-y|$.

\end{proof}


theorem exercise_1_16a
  (n : ℕ)
  (d r : ℝ)
  (x y z : euclidean_space ℝ (fin n)) -- R^n
  (h₁ : n ≥ 3)
  (h₂ : ‖x - y‖ = d)
  (h₃ : d > 0)
  (h₄ : r > 0)
  (h₅ : 2 * r > d)
  : set.infinite {z : euclidean_space ℝ (fin n) | ‖z - x‖ = r ∧ ‖z - y‖ = r} :=

Suppose $k \geq 3, x, y \in \mathbb{R}^k, |x - y| = d > 0$, and $r > 0$. Prove that if $2r > d$, there are infinitely many $z \in \mathbb{R}^k$ such that $|z-x|=|z-y|=r$.

\begin{proof}

    (a) Let w be any vector satisfying the following two equations:

$$

\begin{aligned}

\mathbf{w} \cdot(\mathbf{x}-\mathbf{y}) &=0, \\

|\mathbf{w}|^2 &=r^2-\frac{d^2}{4} .

\end{aligned}

$$

From linear algebra it is known that all but one of the components of a solution $\mathbf{w}$ of the first equation can be arbitrary. The remaining component is then uniquely determined. Also, if $w$ is any non-zero solution of the first equation, there is a unique positive number $t$ such that $t$ w satisfies both equations. (For example, if $x_1 \neq y_1$, the first equation is satisfied whenever

$$

z_1=\frac{z_2\left(x_2-y_2\right)+\cdots+z_k\left(x_k-y_k\right)}{y_1-x_1} .

$$

If $\left(z_1, z_2, \ldots, z_k\right)$ satisfies this equation, so does $\left(t z_1, t z_2, \ldots, t z_k\right)$ for any real number $t$.) Since at least two of these components can vary independently, we can find a solution with these components having any prescribed ratio. This ratio does not change when we multiply by the positive number $t$ to obtain a solution of both equations. Since there are infinitely many ratios, there are infinitely many distinct solutions. For each such solution $\mathbf{w}$ the vector $\mathbf{z}=$ $\frac{1}{2} \mathrm{x}+\frac{1}{2} \mathrm{y}+\mathrm{w}$ is a solution of the required equation. For

$$

\begin{aligned}

|\mathrm{z}-\mathbf{x}|^2 &=\left|\frac{\mathbf{y}-\mathbf{x}}{2}+\mathbf{w}\right|^2 \\

&=\left|\frac{\mathbf{y}-\mathbf{x}}{2}\right|^2+2 \mathbf{w} \cdot \frac{\mathbf{x}-\mathbf{y}}{2}+|\mathbf{w}|^2 \\

&=\frac{d^2}{4}+0+r^2-\frac{d^2}{4} \\

&=r^2

\end{aligned}

$$

and a similar relation holds for $|z-y|^2$.

\end{proof}


theorem exercise_1_18a
  (n : ℕ)
  (h : n > 1)
  (x : euclidean_space ℝ (fin n)) -- R^n
  : ∃ (y : euclidean_space ℝ (fin n)), y ≠ 0 ∧ (inner x y) = (0 : ℝ) :=

If $k \geq 2$ and $\mathbf{x} \in R^{k}$, prove that there exists $\mathbf{y} \in R^{k}$ such that $\mathbf{y} \neq 0$ but $\mathbf{x} \cdot \mathbf{y}=0$

\begin{proof}

    If $\mathbf{x}$ has any components equal to 0 , then $\mathbf{y}$ can be taken to have the corresponding components equal to 1 and all others equal to 0 . If all the components of $\mathbf{x}$ are nonzero, $\mathbf{y}$ can be taken as $\left(-x_2, x_1, 0, \ldots, 0\right)$. This is, of course, not true when $k=1$, since the product of two nonzero real numbers is nonzero.

\end{proof}


theorem exercise_1_19
  (n : ℕ)
  (a b c x : euclidean_space ℝ (fin n))
  (r : ℝ)
  (h₁ : r > 0)
  (h₂ : 3 • c = 4 • b - a)
  (h₃ : 3 * r = 2 * ‖x - b‖)
  : ‖x - a‖ = 2 * ‖x - b‖ ↔ ‖x - c‖ = r :=

Suppose $a, b \in R^k$. Find $c \in R^k$ and $r > 0$ such that $|x-a|=2|x-b|$ if and only if $| x - c | = r$. Prove that $3c = 4b - a$ and $3r = 2 |b - a|$.

\begin{proof}

    Since the solution is given to us, all we have to do is verify it, i.e., we need to show that the equation

$$

|\mathrm{x}-\mathrm{a}|=2|\mathrm{x}-\mathrm{b}|

$$

is equivalent to $|\mathrm{x}-\mathbf{c}|=r$, which says

$$

\left|\mathbf{x}-\frac{4}{3} \mathbf{b}+\frac{1}{3} \mathbf{a}\right|=\frac{2}{3}|\mathbf{b}-\mathbf{a}| .

$$

If we square both sides of both equations, we an equivalent pair of equations, the first of which reduces to

$$

3|\mathbf{x}|^2+2 \mathbf{a} \cdot \mathbf{x}-8 \mathbf{b} \cdot \mathbf{x}-|\mathbf{a}|^2+4|\mathbf{b}|^2=0,

$$

and the second of which reduces to this equation divided by 3 . Hence these equations are indeed equivalent.

\end{proof}


theorem exercise_2_24 {X : Type*} [metric_space X]
  (hX : ∀ (A : set X), infinite A → ∃ (x : X), x ∈ closure A) :
  separable_space X :=

Let $X$ be a metric space in which every infinite subset has a limit point. Prove that $X$ is separable.

\begin{proof}

    We observe that if the process of constructing $x_j$ did not terminate, the result would be an infinite set of points $x_j, j=1,2, \ldots$, such that $d\left(x_i, x_j\right) \geq \delta$ for $i \neq j$. It would then follow that for any $x \in X$, the open ball $B_{\frac{\delta}{2}}(x)$ contains at most one point of the infinite set, hence that no point could be a limit point of this set, contrary to hypothesis. Hence $X$ is totally bounded, i.e., for each $\delta>0$ there is a finite set $x_1, \ldots, x_{N\delta}$such that $X=\bigcup_{j / 1}^{N\delta} B_\delta\left(x_j\right)$

Let $x_{n_1}, \ldots, x_{n N_n}$ be such that $X=\bigcup_{j / 1}^{N_n} B_{\frac{1}{n}}\left(x_{n j}\right), n=1,2, \ldots$ We claim that $\left\{x_{n j}: 1 \leq j \leq N_n ; n=1,2, \ldots\right\}$ is a countable dense subset of $X$. Indeed

25

if $x \in X$ and $\delta>0$, then $x \in B_{\frac{1}{n}}\left(x_{n j}\right)$ for some $x_{n j}$ for some $n>\frac{1}{\delta}$, and hence $d\left(x, x_{n j}\right)<\delta$. By definition, this means that $\left\{x_{n j}\right\}$ is dense in $X$.

\end{proof}


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

Suppose $E\subset\mathbb{R}^k$ is uncountable, and let $P$ be the set of condensation points of $E$. Prove that $P$ is perfect.

\begin{proof}

    We see that $E \cap W$ is at most countable, being a countable union of at-most-countable sets. It remains to show that $P=W^c$, and that $P$ is perfect.

\end{proof}


theorem exercise_2_28 (X : Type*) [metric_space X] [separable_space X]
  (A : set X) (hA : is_closed A) :
  ∃ P₁ P₂ : set X, A = P₁ ∪ P₂ ∧
  is_closed P₁ ∧ P₁ = {x | cluster_pt x (𝓟 P₁)} ∧
  set.countable P₂ :=

Prove that every closed set in a separable metric space is the union of a (possibly empty) perfect set and a set which is at most countable.

\begin{proof}

    If $E$ is closed, it contains all its limit points, and hence certainly all its condensation points. Thus $E=P \cup(E \backslash P)$, where $P$ is perfect (the set of all condensation points of $E$ ), and $E \backslash P$ is at most countable.

Since a perfect set in a separable metric space has the same cardinality as the real numbers, the set $P$ must be empty if $E$ is countable. The at-mostcountable set $E \backslash P$ cannot be perfect, hence must have isolated points if it is nonempty.

\end{proof}


theorem exercise_3_1a
  (f : ℕ → ℝ)
  (h : ∃ (a : ℝ), tendsto (λ (n : ℕ), f n) at_top (𝓝 a))
  : ∃ (a : ℝ), tendsto (λ (n : ℕ), |f n|) at_top (𝓝 a) :=

Prove that convergence of $\left\{s_{n}\right\}$ implies convergence of $\left\{\left|s_{n}\right|\right\}$.

\begin{proof}

    Let $\varepsilon>0$. Since the sequence $\left\{s_n\right\}$ is a Cauchy sequence, there exists $N$ such that $\left|s_m-s_n\right|<\varepsilon$ for all $m>N$ and $n>N$. We then have $\left| |s_m| - |s_n| \right| \leq\left|s_m-s_n\right|<\varepsilon$ for all $m>N$ and $n>N$. Hence the sequence $\left\{\left|s_n\right|\right\}$ is also a Cauchy sequence, and therefore must converge.

\end{proof}


theorem exercise_3_3
  : ∃ (x : ℝ), tendsto f at_top (𝓝 x) ∧ ∀ n, f n < 2 :=

If $s_{1}=\sqrt{2}$, and $s_{n+1}=\sqrt{2+\sqrt{s_{n}}} \quad(n=1,2,3, \ldots),$ prove that $\left\{s_{n}\right\}$ converges, and that $s_{n}<2$ for $n=1,2,3, \ldots$.

\begin{proof}

    Since $\sqrt{2}<2$, it is manifest that if $s_n<2$, then $s_{n+1}<\sqrt{2+2}=2$. Hence it follows by induction that $\sqrt{2}<s_n<2$ for all $n$. In view of this fact,it also follows that $\left(s_n-2\right)\left(s_n+1\right)<0$ for all $n>1$, i.e., $s_n>s_n^2-2=s_{n-1}$. Hence the sequence is an increasing sequence that is bounded above (by 2 ) and so converges. Since the limit $s$ satisfies $s^2-s-2=0$, it follows that the limit is 2.

\end{proof}


theorem exercise_3_6a
: tendsto (λ (n : ℕ), (∑ i in finset.range n, g i)) at_top at_top :=

Prove that $\lim_{n \rightarrow \infty} \sum_{i<n} a_i = \infty$, where $a_i = \sqrt{i + 1} -\sqrt{i}$.

\begin{proof}

    (a) Multiplying and dividing $a_n$ by $\sqrt{n+1}+\sqrt{n}$, we find that $a_n=\frac{1}{\sqrt{n+1}+\sqrt{n}}$, which is larger than $\frac{1}{2 \sqrt{n+1}}$. The series $\sum a_n$ therefore diverges by comparison with the $p$ series $\left(p=\frac{1}{2}\right)$.

\end{proof}


theorem exercise_3_8
  (a b : ℕ → ℝ)
  (h1 : ∃ y, (tendsto (λ n, (∑ i in (finset.range n), a i)) at_top (𝓝 y)))
  (h2 : monotone b)
  (h3 : metric.bounded (set.range b)) :
  ∃ y, tendsto (λ n, (∑ i in (finset.range n), (a i) * (b i))) at_top (𝓝 y) :=

If $\Sigma a_{n}$ converges, and if $\left\{b_{n}\right\}$ is monotonic and bounded, prove that $\Sigma a_{n} b_{n}$ converges.

\begin{proof}

    We shall show that the partial sums of this series form a Cauchy sequence, i.e., given $\varepsilon>0$ there exists $N$ such that $\left|\sum_{k=m+1}^n a_k b_k\right|\langle\varepsilon$ if $n\rangle$ $m \geq N$. To do this, let $S_n=\sum_{k=1}^n a_k\left(S_0=0\right)$, so that $a_k=S_k-S_{k-1}$ for $k=1,2, \ldots$ Let $M$ be an uppper bound for both $\left|b_n\right|$ and $\left|S_n\right|$, and let $S=\sum a_n$ and $b=\lim b_n$. Choose $N$ so large that the following three inequalities hold for all $m>N$ and $n>N$ :

$$

\left|b_n S_n-b S\right|<\frac{\varepsilon}{3} ; \quad\left|b_m S_m-b S\right|<\frac{\varepsilon}{3} ; \quad\left|b_m-b_n\right|<\frac{\varepsilon}{3 M} .

$$

Then if $n>m>N$, we have, from the formula for summation by parts,

$$

\sum_{k=m+1}^n a_n b_n=b_n S_n-b_m S_m+\sum_{k=m}^{n-1}\left(b_k-b_{k+1}\right) S_k

$$

Our assumptions yield immediately that $\left|b_n S_n-b_m S_m\right|<\frac{2 \varepsilon}{3}$, and

$$

\left|\sum_{k=m}^{n-1}\left(b_k-b_{k+1}\right) S_k\right| \leq M \sum_{k=m}^{n-1}\left|b_k-b_{k+1}\right| .

$$

Since the sequence $\left\{b_n\right\}$ is monotonic, we have

$$

\sum_{k=m}^{n-1}\left|b_k-b_{k+1}\right|=\left|\sum_{k=m}^{n-1}\left(b_k-b_{k+1}\right)\right|=\left|b_m-b_n\right|<\frac{\varepsilon}{3 M},

$$

from which the desired inequality follows.

\end{proof}


theorem exercise_3_20 {X : Type*} [metric_space X]
  (p : ℕ → X) (l : ℕ) (r : X)
  (hp : cauchy_seq p)
  (hpl : tendsto (λ n, p (l * n)) at_top (𝓝 r)) :
  tendsto p at_top (𝓝 r) :=

Suppose $\left\{p_{n}\right\}$ is a Cauchy sequence in a metric space $X$, and some sequence $\left\{p_{n l}\right\}$ converges to a point $p \in X$. Prove that the full sequence $\left\{p_{n}\right\}$ converges to $p$.

\begin{proof}

    Let $\varepsilon>0$. Choose $N_1$ so large that $d\left(p_m, p_n\right)<\frac{\varepsilon}{2}$ if $m>N_1$ and $n>N_1$. Then choose $N \geq N_1$ so large that $d\left(p_{n_k}, p\right)<\frac{\varepsilon}{2}$ if $k>N$. Then if $n>N$, we have

$$

d\left(p_n, p\right) \leq d\left(p_n, p_{n_{N+1}}\right)+d\left(p_{n_{N+1}}, p\right)<\varepsilon

$$

For the first term on the right is less than $\frac{\varepsilon}{2}$ since $n>N_1$ and $n_{N+1}>N+1>$ $N_1$. The second term is less than $\frac{\varepsilon}{2}$ by the choice of $N$.

\end{proof}


theorem exercise_3_22 (X : Type*) [metric_space X] [complete_space X]
  (G : ℕ → set X) (hG : ∀ n, is_open (G n) ∧ dense (G n)) :
  ∃ x, ∀ n, x ∈ G n :=

Suppose $X$ is a nonempty complete metric space, and $\left\{G_{n}\right\}$ is a sequence of dense open sets of $X$. Prove Baire's theorem, namely, that $\bigcap_{1}^{\infty} G_{n}$ is not empty.

\begin{proof}

    Let $F_n$ be the complement of $G_n$, so that $F_n$ is closed and contains no open sets. We shall prove that any nonempty open set $U$ contains a point not in any $F_n$, hence in all $G_n$. To this end, we note that $U$ is not contained in $F_1$, so that there is a point $x_1 \in U \backslash F_1$. Since $U \backslash F_1$ is open, there exists $r_1>0$ such that $B_1$, defined as the open ball of radius $r_1$ about $x_1$, is contained in $U \backslash F_1$. Let $E_1$ be the open ball of radius $\frac{r_1}{2}$ about $x_1$, so that the closure of $E_1$ is contained in $B_1$. Now $F_2$ does not contain $E_1$, and so we can find a point $x_2 \in E_1 \backslash F_2$. Since $E_1 \backslash F_2$ is an open set, there exists a positive number $r_2$ such that $B_2$, the open ball of radius $R_2$ about $x_2$, is contained in $E_1 \backslash F_2$, which in turn is contained in $U \backslash\left(F_1 \cup F_2\right)$. We let $E_2$ be the open ball of radius $\frac{r_2}{2}$ about $x_2$, so that $\bar{E}_2 \subseteq B_2$. Proceeding in this way, we construct a sequence of open balls $E_j$, such that $E_j \supseteq \bar{E}_{j+1}$, and the diameter of $E_j$ tends to zero. By the previous exercise, there is a point $x$ belonging to all the sets $\bar{E}_j$, hence to all the sets $U \backslash\left(F_1 \cup F_2 \cup \cdots \cup F_n\right)$. Thus the point $x$ belongs to $U \cap\left(\cap_1^{\infty} G_n\right)$.

\end{proof}


theorem exercise_4_2a
  {α : Type} [metric_space α]
  {β : Type} [metric_space β]
  (f : α → β)
  (h₁ : continuous f)
  : ∀ (x : set α), f '' (closure x) ⊆ closure (f '' x) :=

If $f$ is a continuous mapping of a metric space $X$ into a metric space $Y$, prove that $f(\overline{E}) \subset \overline{f(E)}$ for every set $E \subset X$. ($\overline{E}$ denotes the closure of $E$).

\begin{proof}

    Let $x \in \bar{E}$. We need to show that $f(x) \in \overline{f(E)}$. To this end, let $O$ be any neighborhood of $f(x)$. Since $f$ is continuous, $f^{-1}(O)$ contains (is) a neighborhood of $x$. Since $x \in \bar{E}$, there is a point $u$ of $E$ in $f^{-1}(O)$. Hence $\frac{f(u)}{f(E)} \in O \cap f(E)$. Since $O$ was any neighborhood of $f(x)$, it follows that $f(x) \in \overline{f(E)}$

\end{proof}


theorem exercise_4_4a
  {α : Type} [metric_space α]
  {β : Type} [metric_space β]
  (f : α → β)
  (s : set α)
  (h₁ : continuous f)
  (h₂ : dense s)
  : f '' set.univ ⊆ closure (f '' s) :=

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 $f(E)$ is dense in $f(X)$.

\begin{proof}

    To prove that $f(E)$ is dense in $f(X)$, simply use that $f(X)=f(\bar{E}) \subseteq \overline{f(E)}$.

\end{proof}


theorem exercise_4_5a
  (f : ℝ → ℝ)
  (E : set ℝ)
  (h₁ : is_closed E)
  (h₂ : continuous_on f E)
  : ∃ (g : ℝ → ℝ), continuous g ∧ ∀ x ∈ E, f x = g x :=

If $f$ is a real continuous function defined on a closed set $E \subset \mathbb{R}$, prove that there exist continuous real functions $g$ on $\mathbb{R}$ such that $g(x)=f(x)$ for all $x \in E$.

\begin{proof}

Following the hint, let the complement of $E$ consist of a countable collection of finite open intervals $\left(a_k, b_k\right)$ together with possibly one or both of the the semi-infinite intervals $(b,+\infty)$ and $(-\infty, a)$. The function $f(x)$ is already defined at $a_k$ and $b_k$, as well as at $a$ and $b$ (if these last two points exist). Define $g(x)$ to be $f(b)$ for $x>b$ and $f(a)$ for $x<a$ if $a$ and $b$ exist. On the interval $\left(a_k, b_k\right)$ let

$$

g(x)=f\left(a_k\right)+\frac{x-a_k}{b_k-a_k}\left(f\left(b_k\right)-f\left(a_k\right)\right) .

$$

Of course we let $g(x)=f(x)$ for $x \in E$. It is now fairly clear that $g(x)$ is continuous. A rigorous proof proceeds as follows. Let $\varepsilon>0$. To choose $\delta>0$ such that $|x-u|<\delta$ implies $|g(x)-g(u)|<\varepsilon$, we consider three cases.

i. If $x>b$, let $\delta=x-b$. Then if $|x-u|<\delta$, it follows that $u>b$ also, so that $g(u)=f(b)=g(x)$, and $|g(u)-g(x)|=0<\varepsilon$. Similarly if $x<a$, let $\delta=a-x$

ii. If $a_k<x<b_k$ and $f\left(a_k\right)=f\left(b_k\right)$, let $\delta=\min \left(x-a_k, b_k-x\right)$. Since $|x-u|<\delta$ implies $a_k<u<b_k$, so that $g(u)=f\left(a_k\right)=f\left(b_k\right)=g(x)$, we again have $|g(x)-g(u)|=0<\varepsilon$. If $a_k<x<b_k$ and $f\left(a_k\right) \neq f\left(b_k\right)$, let $\delta=\min \left(x-a_k, b_k-x, \frac{\left(b_k-a_k\right) \varepsilon}{\left|f\left(b_k\right)-f\left(a_k\right)\right|}\right)$. Then if $|x-u|<\delta$, we again have $a_k<u<b_k$ and so

$$

|g(x)-g(u)|=\frac{|x-u|}{b_k-a_k}\left|f\left(b_k\right)-f\left(a_k\right)\right|<\varepsilon .

$$

iii. If $x \in E$, let $\delta_1$ be such that $|f(u)-f(x)|<\varepsilon$ if $u \in E$ and $|x-u|<\delta_1$. (Subcase a). If there are points $x_1 \in E \cap\left(x-\delta_1, x\right)$ and $x_2 \in E \cap\left(x, x+\delta_1\right)$, let $\delta=\min \left(x-x_1, x_2-x\right)$. If $|u-x|<\delta$ and $u \in E$, then $|f(u)-f(x)|<\varepsilon$ by definition of $\delta_1$. if $u \notin E$, then, since $x_1, x$, and $x_2$ are all in $E$, it follows that $u \in\left(a_k, b_k\right)$, where $a_k \in E, b_k \in E$, and $\left|a_k-x\right|<\delta$ and $\left|b_k-x\right|<\delta$, so that $\left|f\left(a_k\right)-f(x)\right|<\varepsilon$ and $\left|f\left(b_k\right)-f(x)\right|<\varepsilon$. If $f\left(a_k\right)=f\left(b_k\right)$, then $f(u)=f\left(a_k\right)$ also, and we have $|f(u)-f(x)|<\varepsilon$. If $f\left(a_k\right) \neq f\left(b_k\right)$, then

$$

\begin{aligned}

|f(u)-f(x)| & =\left|f\left(a_k\right)-f(x)+\frac{u-a_k}{b_k-a_k}\left(f\left(b_k\right)-f\left(a_k\right)\right)\right| \\

& =\left|\frac{b_k-u}{b_k-a_k}\left(f\left(a_k\right)-f(x)\right)+\frac{u-a_k}{b_k-a_k}\left(f\left(b_k\right)-f(x)\right)\right| \\

& <\frac{b_k-u}{b_k-a_k} \varepsilon+\frac{u-a_k}{b_k-a_k} \varepsilon \\

& =\varepsilon

\end{aligned}

$$

(Subcase b). Suppose $x_2$ does not exist, i.e., either $x=a_k$ or $x=a_k$ and $b_k>a_k+\delta_1$. Let us consider the second of these cases and show how to get $|f(u)-f(x)|<\varepsilon$ for $x<u<x+\delta$. If $f\left(a_k\right)=f\left(b_k\right)$, let $\delta=\delta_1$. If $u>x$ we have $a_k<u<b_k$ and $f(u)=f\left(a_k\right)=f(x)$. If $f\left(a_k\right) \neq f\left(b_k\right)$, let $\delta=$ $\min \left(\delta_1, \frac{\left(b_k-a_k\right) \varepsilon}{\left|f\left(b_k\right)-f\left(a_k\right)\right|}\right)$. Then, just as in Subcase a, we have $|f(u)-f(x)|<\varepsilon$.

The case when $x=b_k$ for some $k$ and $a_k<x-\delta_1$ is handled in exactly the same way.

\end{proof}


theorem exercise_4_6
  (f : ℝ → ℝ)
  (E : set ℝ)
  (G : set (ℝ × ℝ))
  (h₁ : is_compact E)
  (h₂ : G = {(x, f x) | x ∈ E})
  : continuous_on f E ↔ is_compact G :=

If $f$ is defined on $E$, the graph of $f$ is the set of points $(x, f(x))$, for $x \in E$. In particular, if $E$ is a set of real numbers, and $f$ is real-valued, the graph of $f$ is a subset of the plane. Suppose $E$ is compact, and prove that $f$ is continuous on $E$ if and only if its graph is compact.

\begin{proof}

    Let $Y$ be the co-domain of the function $f$. We invent a new metric space $E \times Y$ as the set of pairs of points $(x, y), x \in E, y \in Y$, with the metric $\rho\left(\left(x_1, y_1\right),\left(x_2, y_2\right)\right)=d_E\left(x_1, x_2\right)+d_Y\left(y_1, y_2\right)$. The function $\varphi(x)=(x, f(x))$ is then a mapping of $E$ into $E \times Y$.

We claim that the mapping $\varphi$ is continuous if $f$ is continuous. Indeed, let $x \in X$ and $\varepsilon>0$ be given. Choose $\eta>0$ so that $d_Y(f(x), f(u))<\frac{\varepsilon}{2}$ if $d_E(x, y)<\eta$. Then let $\delta=\min \left(\eta, \frac{\varepsilon}{2}\right)$. It is easy to see that $\rho(\varphi(x), \varphi(u))<\varepsilon$ if $d_E(x, u)<\delta$. Conversely if $\varphi$ is continuous, it is obvious from the inequality $\rho(\varphi(x), \varphi(u)) \geq d_Y(f(x), f(u))$ that $f$ is continuous.

From these facts we deduce immediately that the graph of a continuous function $f$ on a compact set $E$ is compact, being the image of $E$ under the continuous mapping $\varphi$. Conversely, if $f$ is not continuous at some point $x$, there is a sequence of points $x_n$ converging to $x$ such that $f\left(x_n\right)$ does not converge to $f(x)$. If no subsequence of $f\left(x_n\right)$ converges, then the sequence $\left\{\left(x_n, f\left(x_n\right)\right\}_{n=1}^{\infty}\right.$ has no convergent subsequence, and so the graph is not compact. If some subsequence of $f\left(x_n\right)$ converges, say $f\left(x_{n_k}\right) \rightarrow z$, but $z \neq f(x)$, then the graph of $f$ fails to contain the limit point $(x, z)$, and hence is not closed. A fortiori it is not compact.

\end{proof}


theorem exercise_4_8b
  (E : set ℝ) :
  ∃ f : ℝ → ℝ, uniform_continuous_on f E ∧ ¬ metric.bounded (set.image f E) :=

Let $E$ be a bounded set in $R^{1}$. Prove that there exists a real function $f$ such that $f$ is uniformly continuous and is not bounded on $E$.

\begin{proof}

    The function $f(x)=x$ is uniformly continuous on the entire line, but not bounded.

\end{proof}


theorem exercise_4_12
  {α β γ : Type*} [uniform_space α] [uniform_space β] [uniform_space γ]
  {f : α → β} {g : β → γ}
  (hf : uniform_continuous f) (hg : uniform_continuous g) :
  uniform_continuous (g ∘ f) :=

A uniformly continuous function of a uniformly continuous function is uniformly continuous.

\begin{proof}

    Let $f: X \rightarrow Y$ and $g: Y \rightarrow Z$ be uniformly continuous. Then $g \circ f: X \rightarrow Z$ is uniformly continuous, where $g \circ f(x)=g(f(x))$ for all $x \in X$.

To prove this fact, let $\varepsilon>0$ be given. Then, since $g$ is uniformly continuous, there exists $\eta>0$ such that $d_Z(g(u), g(v))<\varepsilon$ if $d_Y(u, v)<\eta$. Since $f$ is uniformly continuous, there exists $\delta>0$ such that $d_Y(f(x), f(y))<\eta$ if $d_X(x, y)<\delta$

It is then obvious that $d_Z(g(f(x)), g(f(y)))<\varepsilon$ if $d_X(x, y)<\delta$, so that $g \circ f$ is uniformly continuous.

\end{proof}


theorem exercise_4_19
  {f : ℝ → ℝ} (hf : ∀ a b c, a < b → f a < c → c < f b → ∃ x, a < x ∧ x < b ∧ f x = c)
  (hg : ∀ r : ℚ, is_closed {x | f x = r}) : continuous f :=

Suppose $f$ is a real function with domain $R^{1}$ which has the intermediate value property: if $f(a)<c<f(b)$, then $f(x)=c$ for some $x$ between $a$ and $b$. Suppose also, for every rational $r$, that the set of all $x$ with $f(x)=r$ is closed. Prove that $f$ is continuous.

\begin{proof}

    The contradiction is evidently that $x_0$ is a limit point of the set of $t$ such that $f(t)=r$, yet, $x_0$ does not belong to this set. This contradicts the hypothesis that the set is closed.

\end{proof}


theorem exercise_4_24 {f : ℝ → ℝ}
  (hf : continuous f) (a b : ℝ) (hab : a < b)
  (h : ∀ x y : ℝ, a < x → x < b → a < y → y < b → f ((x + y) / 2) ≤ (f x + f y) / 2) :
  convex_on ℝ (set.Ioo a b) f :=

Assume that $f$ is a continuous real function defined in $(a, b)$ such that $f\left(\frac{x+y}{2}\right) \leq \frac{f(x)+f(y)}{2}$ for all $x, y \in(a, b)$. Prove that $f$ is convex.

\begin{proof}

    We shall prove that

$$

f(\lambda x+(1-\lambda) y) \leq \lambda f(x)+(1-\lambda) f(y)

$$

for all "dyadic rational" numbers, i.e., all numbers of the form $\lambda=\frac{k}{2^n}$, where $k$ is a nonnegative integer not larger than $2^n$. We do this by induction on $n$. The case $n=0$ is trivial (since $\lambda=0$ or $\lambda=1$ ). In the case $n=1$ we have $\lambda=0$ or $\lambda=1$ or $\lambda=\frac{1}{2}$. The first two cases are again trivial, and the third is precisely the hypothesis of the theorem. Suppose the result is proved for $n \leq r$, and consider $\lambda=\frac{k}{2^{r+1}}$. If $k$ is even, say $k=2 l$, then $\frac{k}{2^{r+1}}=\frac{l}{2^r}$, and we can appeal to the induction hypothesis. Now suppose $k$ is odd. Then $1 \leq k \leq 2^{r+1}-1$, and so the numbers $l=\frac{k-1}{2}$ and $m=\frac{k+1}{2}$ are integers with $0 \leq l<m \leq 2^r$. We can now write

$$

\lambda=\frac{s+t}{2},

$$

where $s=\frac{k-1}{2^{r+1}}=\frac{l}{2^r}$ and $t=\frac{k+1}{2^{r+1}}=\frac{m}{2^r}$. We then have

$$

\lambda x+(1-\lambda) y=\frac{[s x+(1-s) y]+[t x+(1-t) y]}{2}

$$

Hence by the hypothesis of the theorem and the induction hypothesis we have

$$

\begin{aligned}

f(\lambda x+(1-\lambda) y) & \leq \frac{f(s x+(1-s) y)+f(t x+(1-t) y)}{2} \\

& \leq \frac{s f(x)+(1-s) f(y)+t f(x)+(1-t) f(y)}{2} \\

&=\left(\frac{s+t}{2}\right) f(x)+\left(1-\frac{s+t}{2}\right) f(y) \\

&=\lambda f(x)+(1-\lambda) f(y)

\end{aligned}

$$

This completes the induction.

Now for each fixed $x$ and $y$ both sides of the inequality

$$

f(\lambda x+(1-\lambda) y) \leq \lambda f(x)+(1-\lambda) f(y)

$$

are continuous functions of $\lambda$. Hence the set on which this inequality holds (the inverse image of the closed set $[0, \infty)$ under the mapping $\lambda \mapsto \lambda f(x)+(1-$ $\lambda) f(y)-f(\lambda x+(1-\lambda) y))$ is a closed set. Since it contains all the points $\frac{k}{2^n}$, $0 \leq k \leq n, n=1,2, \ldots$, it must contain the closure of this set of points, i.e., it must contain all of $[0,1]$. Thus $f$ is convex.

\end{proof}


theorem exercise_5_2 {a b : ℝ}
  {f g : ℝ → ℝ} (hf : ∀ x ∈ set.Ioo a b, deriv f x > 0)
  (hg : g = f⁻¹)
  (hg_diff : differentiable_on ℝ g (set.Ioo a b)) :
  differentiable_on ℝ g (set.Ioo a b) ∧
  ∀ x ∈ set.Ioo a b, deriv g x = 1 / deriv f x :=

Suppose $f^{\prime}(x)>0$ in $(a, b)$. Prove that $f$ is strictly increasing in $(a, b)$, and let $g$ be its inverse function. Prove that $g$ is differentiable, and that $g^{\prime}(f(x))=\frac{1}{f^{\prime}(x)} \quad(a<x<b)$.

\begin{proof}

   For any $c, d$ with $a<c<d<b$ there exists a point $p \in(c, d)$ such that $f(d)-f(c)=f^{\prime}(p)(d-c)>0$. Hence $f(c)<f(d)$

We know from Theorem $4.17$ that the inverse function $g$ is continuous. (Its restriction to each closed subinterval $[c, d]$ is continuous, and that is sufficient.) Now observe that if $f(x)=y$ and $f(x+h)=y+k$, we have

$$

\frac{g(y+k)-g(y)}{k}-\frac{1}{f^{\prime}(x)}=\frac{1}{\frac{f(x+h)-f(x)}{h}}-\frac{1}{f^{\prime}(x)}

$$

Since we know $\lim \frac{1}{\varphi(t)}=\frac{1}{\lim \varphi(t)}$ provided $\lim \varphi(t) \neq 0$, it follows that for any $\varepsilon>0$ there exists $\eta>0$ such that

$$

\left|\frac{1}{\frac{f(x+h)-f(x)}{h}}-\frac{1}{f^{\prime}(x)}\right|<\varepsilon

$$

if $0<|h|<\eta$. Since $h=g(y+k)-g(y)$, there exists $\delta>0$ such that $0<|h|<\eta$ if $0<|k|<\delta$. The proof is now complete.

\end{proof}


theorem exercise_5_4 {n : ℕ}
  (C : ℕ → ℝ)
  (hC : ∑ i in (finset.range (n + 1)), (C i) / (i + 1) = 0) :
  ∃ x, x ∈ (set.Icc (0 : ℝ) 1) ∧ ∑ i in finset.range (n + 1), (C i) * (x^i) = 0 :=

If $C_{0}+\frac{C_{1}}{2}+\cdots+\frac{C_{n-1}}{n}+\frac{C_{n}}{n+1}=0,$ where $C_{0}, \ldots, C_{n}$ are real constants, prove that the equation $C_{0}+C_{1} x+\cdots+C_{n-1} x^{n-1}+C_{n} x^{n}=0$ has at least one real root between 0 and 1.

\begin{proof}

    Consider the polynomial

$$

p(x)=C_0 x+\frac{C_1}{2} x^2+\cdots+\frac{C_{n-1}}{n} x^n+\frac{C_n}{n+1} x^{n+1},

$$

whose derivative is

$$

p^{\prime}(x)=C_0+C_1 x+\cdots+C_{n-1} x^{n-1}+C_n x^n .

$$

It is obvious that $p(0)=0$, and the hypothesis of the problem is that $p(1)=0$. Hence Rolle's theorem implies that $p^{\prime}(x)=0$ for some $x$ between 0 and 1 .

\end{proof}


theorem exercise_5_6
  {f : ℝ → ℝ}
  (hf1 : continuous f)
  (hf2 : ∀ x, differentiable_at ℝ f x)
  (hf3 : f 0 = 0)
  (hf4 : monotone (deriv f)) :
  monotone_on (λ x, f x / x) (set.Ioi 0) :=

Suppose (a) $f$ is continuous for $x \geq 0$, (b) $f^{\prime}(x)$ exists for $x>0$, (c) $f(0)=0$, (d) $f^{\prime}$ is monotonically increasing. Put $g(x)=\frac{f(x)}{x} \quad(x>0)$ and prove that $g$ is monotonically increasing.

\begin{proof}

    Put

$$

g(x)=\frac{f(x)}{x} \quad(x>0)

$$

and prove that $g$ is monotonically increasing.

By the mean-value theorem

$$

f(x)=f(x)-f(0)=f^{\prime}(c) x

$$

for some $c \in(0, x)$. Since $f^{\prime}$ is monotonically increasing, this result implies that $f(x)<x f^{\prime}(x)$. It therefore follows that

$$

g^{\prime}(x)=\frac{x f^{\prime}(x)-f(x)}{x^2}>0,

$$

so that $g$ is also monotonically increasing.

\end{proof}


theorem exercise_5_15 {f : ℝ → ℝ} (a M0 M1 M2 : ℝ)
  (hf' : differentiable_on ℝ f (set.Ici a))
  (hf'' : differentiable_on ℝ (deriv f) (set.Ici a))
  (hM0 : M0 = Sup {(| f x | )| x ∈ (set.Ici a)})
  (hM1 : M1 = Sup {(| deriv f x | )| x ∈ (set.Ici a)})
  (hM2 : M2 = Sup {(| deriv (deriv f) x | )| x ∈ (set.Ici a)}) :
  (M1 ^ 2) ≤ 4 * M0 * M2 :=

Suppose $a \in R^{1}, f$ is a twice-differentiable real function on $(a, \infty)$, and $M_{0}, M_{1}, M_{2}$ are the least upper bounds of $|f(x)|,\left|f^{\prime}(x)\right|,\left|f^{\prime \prime}(x)\right|$, respectively, on $(a, \infty)$. Prove that $M_{1}^{2} \leq 4 M_{0} M_{2} .$

\begin{proof}

    The inequality is obvious if $M_0=+\infty$ or $M_2=+\infty$, so we shall assume that $M_0$ and $M_2$ are both finite. We need to show that

$$

\left|f^{\prime}(x)\right| \leq 2 \sqrt{M_0 M_2}

$$

for all $x>a$. We note that this is obvious if $M_2=0$, since in that case $f^{\prime}(x)$ is constant, $f(x)$ is a linear function, and the only bounded linear function is a constant, whose derivative is zero. Hence we shall assume from now on that $0<M_2<+\infty$ and $0<M_0<+\infty$.

Following the hint, we need only choose $h=\sqrt{\frac{M_0}{M_2}}$, and we obtain

$$

\left|f^{\prime}(x)\right| \leq 2 \sqrt{M_0 M_2},

$$

which is precisely the desired inequality.

The case of equality follows, since the example proposed satisfies

$$

f(x)=1-\frac{2}{x^2+1}

$$

for $x \geq 0$. We see easily that $|f(x)| \leq 1$ for all $x>-1$. Now $f^{\prime}(x)=\frac{4 x}{\left(x^2+1\right)^2}$ for $x>0$ and $f^{\prime}(x)=4 x$ for $x<0$. It thus follows from Exercise 9 above that $f^{\prime}(0)=0$, and that $f^{\prime}(x)$ is continuous. Likewise $f^{\prime \prime}(x)=4$ for $x<0$ and $f^{\prime \prime}(x)=\frac{4-4 x^2}{\left(x^2+1\right)^3}=-4 \frac{x^2-1}{\left(x^2+1\right)^3}$. This shows that $\left|f^{\prime \prime}(x)\right|<4$ for $x>0$ and also that $\lim _{x \rightarrow 0} f^{\prime \prime}(x)=4$. Hence Exercise 9 again implies that $f^{\prime \prime}(x)$ is continuous and $f^{\prime \prime}(0)=4$.

On $n$-dimensional space let $\mathbf{f}(x)=\left(f_1(x), \ldots, f_n(x)\right), M_0=\sup |\mathbf{f}(x)|$, $M_1=\sup \left|\mathbf{f}^{\prime}(x)\right|$, and $M_2=\sup \left|\mathbf{f}^{\prime \prime}(x)\right|$. Just as in the numerical case, there is nothing to prove if $M_2=0$ or $M_0=+\infty$ or $M_2=+\infty$, and so we assume $0<M_0<+\infty$ and $0<M_2<\infty$. Let $a$ be any positive number less than $M_1$, let $x_0$ be such that $\left|\mathbf{f}^{\prime}\left(x_0\right)\right|>a$, and let $\mathbf{u}=\frac{1}{\left|\mathbf{f}^{\prime}\left(x_0\right)\right|} \mathbf{f}^{\prime}\left(x_0\right)$. Consider the real-valued function $\varphi(x)=\mathrm{u} \cdot \mathrm{f}(x)$. Let $N_0, N_1$, and $N_2$ be the suprema of $|\varphi(x)|,\left|\varphi^{\prime}(x)\right|$, and $\left|\varphi^{\prime \prime}(x)\right|$ respectively. By the Schwarz inequality we have (since $|\mathbf{u}|=1) N_0 \leq M_0$ and $N_2 \leq M_2$, while $N_1 \geq \varphi\left(x_0\right)=\left|\mathbf{f}^{\prime}\left(x_0\right)\right|>a$. We therefore have $a^2<4 N_0 N_2 \leq 4 M_0 M_2$. Since $a$ was any positive number less than $M_1$, we have $M_1^2 \leq 4 M_0 M_2$, i.e., the result holds also for vector-valued functions.

Equality can hold on any $R^n$, as we see by taking $\mathbf{f}(x)=(f(x), 0, \ldots, 0)$ or $\mathbf{f}(x)=(f(x), f(x), \ldots, f(x))$, where $f(x)$ is a real-valued function for which equality holds.

\end{proof}


theorem exercise_1_27 {n : ℕ} (hn : odd n) : 8 ∣ (n^2 - 1) :=

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

For all odd $n$ show that $8 \mid n^{2}-1$.

\begin{proof}

    We have $n^2-1=(n+1)(n-1)$. Since $n$ is odd, both $n+1, n-1$ are even, and moreso, one of these must be divisible by 4 , as one of the two consecutive odd numbers is divisible by 4 . Thus, their product is divisible by 8 . Similarly, if 3 does not divide $n$, it must divide one of $n-1, n+1$, otherwise it wouldn't divide three consecutive integers, which is impossible. As $n$ is odd, $n+1$ is even, so $(n+1)(n-1)$ is divisible by both 2 and 3 , so it is divisible by 6 .

\end{proof}


theorem exercise_1_31  : (⟨1, 1⟩ : gaussian_int) ^ 2 ∣ 2 :=

Show that 2 is divisible by $(1+i)^{2}$ in $\mathbb{Z}[i]$.


theorem exercise_2_21 {l : ℕ → ℝ}
  (hl : ∀ p n : ℕ, p.prime → l (p^n) = log p )
  (hl1 : ∀ m : ℕ, ¬ is_prime_pow m → l m = 0) :
  l = λ n, ∑ d : divisors n, moebius (n/d) * log d  :=

Define $\wedge(n)=\log p$ if $n$ is a power of $p$ and zero otherwise. Prove that $\sum_{A \mid n} \mu(n / d) \log d$ $=\wedge(n)$.

\begin{proof}

$$

\left\{

\begin{array}{cccl}

    \land(n)& =  & \log p & \mathrm{if}\  n =p^\alpha,\ \alpha \in \mathbb{N}^*  \\

  &  = &   0 & \mathrm{otherwise }.

\end{array}

\right.

$$

Let $n = p_1^{\alpha_1}\cdots p_t^{\alpha_t}$ the decomposition of $n$ in prime factors. As $\land(d) = 0$ for all divisors of $n$, except for $d = p_j^i, i>0, j=1,\ldots t$,

\begin{align*}

\sum_{d \mid n} \land(d)&= \sum_{i=1}^{\alpha_1} \land(p_1^{i}) + \cdots+ \sum_{i=1}^{\alpha_t} \land(p_t^{i})\\

&= \alpha_1 \log p_1+\cdots + \alpha_t \log p_t\\

&= \log n

\end{align*}

By Mobius Inversion Theorem,

$$\land(n) = \sum_{d \mid n} \mu\left (\frac{n}{d}\right ) \log d.$$

\end{proof}


theorem exercise_3_1 : infinite {p : primes // p ≡ -1 [ZMOD 6]} :=

Show that there are infinitely many primes congruent to $-1$ modulo 6 .

\begin{proof}

Let $n$ any integer such that $n\geq 3$, and $N = n! -1 =   2 \times 3 \times\cdots\times n - 1 >1$.

Then $N \equiv -1 \pmod 6$. As $6k +2, 6k +3, 6k +4$ are composite for all integers $k$, every prime factor of $N$ is congruent to $1$ or $-1$ modulo $6$.  If every prime factor of $N$ was congruent to 1, then $N \equiv 1 \pmod 6$ : this is a contradiction because $-1 \not \equiv 1 \pmod 6$.  So there exists a prime factor $p$ of $N$ such that $p\equiv -1 \pmod 6$.

If $p\leq n$, then $p \mid n!$, and $p \mid N = n!-1$, so $p \mid 1$. As $p$ is prime, this is a contradiction, so $p>n$.

Conclusion :

 for any integer $n$, there exists a prime $p >n$ such that $p \equiv -1 \pmod 6$ : there are infinitely many primes congruent to $-1$ modulo $6$.

\end{proof}


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

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

\begin{proof}

    If $7x^2 + 2 = y^3,\ x,y \in \mathbb{Z}$, then $y^3 \equiv 2 \pmod 7$ (so $y \not \equiv 0 \pmod 7$)

From Fermat's Little Theorem, $y^6 \equiv 1 \pmod 7$, so $2^2 \equiv y^6 \equiv 1 \pmod 7$, which implies $7 \mid 2^2-1 = 3$ : this is a contradiction. Thus the equation $7x^2 + 2 = y^3$ has no solution in integers.

\end{proof}


theorem exercise_3_14 {p q n : ℕ} (hp0 : p.prime ∧ p > 2)
  (hq0 : q.prime ∧ q > 2) (hpq0 : p ≠ q) (hpq1 : p - 1 ∣ q - 1)
  (hn : n.gcd (p*q) = 1) :
  n^(q-1) ≡ 1 [MOD p*q] :=

Let $p$ and $q$ be distinct odd primes such that $p-1$ divides $q-1$. If $(n, p q)=1$, show that $n^{q-1} \equiv 1(p q)$.

\begin{proof}

As $n \wedge pq = 1, n\wedge p=1, n \wedge q = 1$, so from Fermat's Little Theorem

$$n^{q-1} \equiv 1 \pmod q,\qquad n^{p-1} \equiv 1 \pmod p.$$

$p-1 \mid q-1$, so there exists $k \in \mathbb{Z}$ such that $q-1 = k(p-1)$.

Thus

$$n^{q-1} = (n^{p-1})^k \equiv 1 \pmod p.$$

$p \mid n^{q-1} - 1, q \mid n^{q-1} - 1$, and $p\wedge q = 1$, so $pq \mid n^{q-1} - 1$ :

$$n^{q-1} \equiv 1 \pmod{pq}.$$

\end{proof}


theorem exercise_4_5 {p t : ℕ} (hp0 : p.prime) (hp1 : p = 4*t + 3)
  (a : zmod p) :
  is_primitive_root a p ↔ ((-a) ^ ((p-1)/2) = 1 ∧ ∀ (k : ℕ), k < (p-1)/2 → (-a)^k ≠ 1) :=

Consider a prime $p$ of the form $4 t+3$. Show that $a$ is a primitive root modulo $p$ iff $-a$ has order $(p-1) / 2$.

\begin{proof}

    Let $a$ a primitive root modulo $p$.

As $a^{p-1} \equiv 1(\bmod p), p \mid\left(a^{(p-1) / 2}-1\right)\left(a^{(p-1) / 2}+1\right)$, so $p \mid a^{(p-1) / 2}-1$ or $p \mid$ $a^{(p-1) / 2}+1$. As $a$ is a primitive root modulo $p, a^{(p-1) / 2} \not \equiv 1(\bmod p)$, so

$$

a^{(p-1) / 2} \equiv-1 \quad(\bmod p) .

$$

Hence $(-a)^{(p-1) / 2}=(-1)^{2 t+1} a^{(p-1) / 2} \equiv(-1) \times(-1)=1(\bmod p)$.

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

Then $a^{2 n}=(-a)^{2 n} \equiv 1(\bmod p)$, so $p-1\left|2 n, \frac{p-1}{2}\right| n$.

So $-a$ has order $(p-1) / 2$ modulo $p$.

Conversely, suppose that $-a$ has order $(p-1) / 2=2 t+1$ modulo $p$. Let $2, p_1, \ldots p_k$ the prime factors of $p-1$, where $p_i$ are odd.

$a^{(p-1) / 2}=a^{2 t+1}=-(-a)^{2 t+1}=-(-a)^{(p-1) / 2} \equiv-1$, so $a^{(p-1) / 2} \not \equiv 1(\bmod 2)$.

As $p-1$ is even, $(p-1) / p_i$ is even, so $a^{(p-1) / p_i}=(-a)^{(p-1) / p_i} \not \equiv 1(\bmod p)($ since $-a$ has order $p-1)$.

So the order of $a$ is $p-1$ (see Ex. 4.8) : $a$ is a primitive root modulo $p$.

\end{proof}


theorem exercise_4_8 {p a : ℕ} (hp : odd p) :
  is_primitive_root a p ↔ (∀ q ∣ (p-1), q.prime → ¬ a^(p-1) ≡ 1 [MOD p]) :=

Let $p$ be an odd prime. Show that $a$ is a primitive root modulo $p$ iff $a^{(p-1) / q} \not \equiv 1(p)$ for all prime divisors $q$ of $p-1$.

\begin{proof}

$\bullet$ If $a$ is a primitive root, then $a^k \not \equiv 1$ for all $k, 1\leq k < p-1$, so $a^{(p-1)/q} \not \equiv 1 \pmod p$ for all prime divisors $q$ of $p - 1$.

$\bullet$ In the other direction, suppose $a^{(p-1)/q} \not \equiv 1 \pmod p$ for all prime divisors $q$ of $p - 1$.

Let $\delta$ the order of $a$, and $p-1 = q_1^{a_1}q_2^{a_2}\cdots q_k^{a_k}$ the decomposition of $p-1$ in prime factors. As $\delta \mid p-1, \delta = q_1^{b_1}p_2^{b_2}\cdots q_k^{b_k}$, with $b_i \leq a_i, i=1,2,\ldots,k$. If $b_i < a_i$ for some index $i$, then $\delta \mid (p-1)/q_i$, so $a^{(p-1)/q_i} \equiv 1 \pmod p$, which is in contradiction with the hypothesis. Thus $b_i = a_i$ for all $i$, and $\delta = q-1$ : $a$ is a primitive root modulo $p$.

\end{proof}


theorem exercise_5_13 {p x: ℤ} (hp : prime p)
  (hpx : p ∣ (x^4 - x^2 + 1)) : p ≡ 1 [ZMOD 12] :=

Show that any prime divisor of $x^{4}-x^{2}+1$ is congruent to 1 modulo 12 .


theorem exercise_5_37 {p q : ℕ} [fact(p.prime)] [fact(q.prime)] {a : ℤ}
  (ha : a < 0) (h0 : p ≡ q [ZMOD 4*a]) (h1 : ¬ ((p : ℤ) ∣ a)) :
  legendre_sym p a = legendre_sym q a :=

Show that if $a$ is negative then $p \equiv q(4 a) together with p\not | a$ imply $(a / p)=(a / q)$.


theorem exercise_18_4 {n : ℕ} (hn : ∃ x y z w : ℤ,
  x^3 + y^3 = n ∧ z^3 + w^3 = n ∧ x ≠ z ∧ x ≠ w ∧ y ≠ z ∧ y ≠ w) :
  n ≥ 1729 :=

Show that 1729 is the smallest positive integer expressible as the sum of two different integral cubes in two ways.

\begin{proof}

    Let $n=a^3+b^3$, and suppose that $\operatorname{gcd}(a, b)=1$. If a prime $p \mid a^3+b^3$, then

$$

\left(a b^{-1}\right)^3 \equiv_p-1

$$

Thus $3 \mid \frac{p-1}{2}$, that is, $p \equiv_6 1$.

If we have $n=a^3+b^3=c^3+d^3$, then we can factor $n$ as

$$

\begin{aligned}

& n=(a+b)\left(a^2-a b+b^2\right) \\

& n=(c+d)\left(c^2-c d+d^2\right)

\end{aligned}

$$

Thus we need $n$ to have atleast 3 disctinct prime factors, and so the smallest taxicab number is on the form

$$

n=(6 k+1)(12 k+1)(18 k+1)

$$

\end{proof}


theorem exercise_1_3 {F V : Type*} [add_comm_group V] [field F]
  [module F V] {v : V} : -(-v) = v :=

import .common

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

open_locale big_operators

Prove that $-(-v) = v$ for every $v \in V$.

\begin{proof}

    By definition, we have

$$

(-v)+(-(-v))=0 \quad \text { and } \quad v+(-v)=0 .

$$

This implies both $v$ and $-(-v)$ are additive inverses of $-v$, by the uniqueness of additive inverse, it follows that $-(-v)=v$.

\end{proof}


theorem exercise_1_6 : ∃ U : set (ℝ × ℝ),
  (U ≠ ∅) ∧
  (∀ (u v : ℝ × ℝ), u ∈ U ∧ v ∈ U → u + v ∈ U) ∧
  (∀ (u : ℝ × ℝ), u ∈ U → -u ∈ U) ∧
  (∀ U' : submodule ℝ (ℝ × ℝ), U ≠ ↑U') :=

Give an example of a nonempty subset $U$ of $\mathbf{R}^2$ such that $U$ is closed under addition and under taking additive inverses (meaning $-u \in U$ whenever $u \in U$), but $U$ is not a subspace of $\mathbf{R}^2$.

\begin{proof}

    \[U=\mathbb{Z}^2=\left\{(x, y) \in \mathbf{R}^2: x, y \text { are integers }\right\}\]

$U=\mathbb{Z}^2$ satisfies the desired properties. To come up with this, note by assumption, $U$ must be closed under addition and subtraction, so in particular, it must contain 0 . We need to find a set which fails scalar multiplication. A discrete set like $\mathbb{Z}^2$ does this.

\end{proof}


theorem exercise_1_8 {F V : Type*} [add_comm_group V] [field F]
  [module F V] {ι : Type*} (u : ι → submodule F V) :
  ∃ U : submodule F V, (⋂ (i : ι), (u i).carrier) = ↑U :=

Prove that the intersection of any collection of subspaces of $V$ is a subspace of $V$.

\begin{proof}

Let $V_1, V_2, \ldots, V_n$ be subspaces of the vector space $V$ over the field $F$. We must show that their intersection $V_1 \cap V_2 \cap \ldots \cap V_n$ is also a subspace of $V$.

To begin, we observe that the additive identity $0$ of $V$ is in $V_1 \cap V_2 \cap \ldots \cap V_n$. This is because $0$ is in each subspace $V_i$, as they are subspaces and hence contain the additive identity.

Next, we show that the intersection of subspaces is closed under addition. Let $u$ and $v$ be vectors in $V_1 \cap V_2 \cap \ldots \cap V_n$. By definition, $u$ and $v$ belong to each of the subspaces $V_i$. Since each $V_i$ is a subspace and therefore closed under addition, it follows that $u+v$ belongs to each $V_i$. Thus, $u+v$ belongs to the intersection $V_1 \cap V_2 \cap \ldots \cap V_n$.

Finally, we show that the intersection of subspaces is closed under scalar multiplication. Let $a$ be a scalar in $F$ and let $v$ be a vector in $V_1 \cap V_2 \cap \ldots \cap V_n$. Since $v$ belongs to each $V_i$, we have $av$ belongs to each $V_i$ as well, as $V_i$ are subspaces and hence closed under scalar multiplication. Therefore, $av$ belongs to the intersection $V_1 \cap V_2 \cap \ldots \cap V_n$.

Thus, we have shown that $V_1 \cap V_2 \cap \ldots \cap V_n$ is a subspace of $V$.

\end{proof}


theorem exercise_3_1 {F V : Type*}
  [add_comm_group V] [field F] [module F V] [finite_dimensional F V]
  (T : V →ₗ[F] V) (hT : finrank F V = 1) :
  ∃ c : F, ∀ v : V, T v = c • v:=

Show that every linear map from a one-dimensional vector space to itself is multiplication by some scalar. More precisely, prove that if $\operatorname{dim} V=1$ and $T \in \mathcal{L}(V, V)$, then there exists $a \in \mathbf{F}$ such that $T v=a v$ for all $v \in V$.

\begin{proof}

    If $\operatorname{dim} V=1$, then in fact, $V=\mathbf{F}$ and it is spanned by $1 \in \mathbf{F}$.

Let $T$ be a linear map from $V$ to itself. Let $T(1)=\lambda \in V(=\mathbf{F})$.

Step 2

2 of 3

Every $v \in V$ is a scalar. Therefore,

$$

\begin{aligned}

T(v) & =T(v \cdot 1) \\

& =v T(1) \ldots .(\text { By the linearity of } T) \\

& =v \lambda

\end{aligned}

$$

Hence, $T v=\lambda v$ for every $v \in V$.

\end{proof}