theorem exercise_2_13 {f : ℂ → ℂ}
    (hf : ∀ z₀ : ℂ, ∃ (s : set ℂ) (c : ℕ → ℂ), is_open s ∧ z₀ ∈ s ∧
      ∀ z ∈ s, tendsto (λ n, ∑ i in finset.range n, (c i) * (z - z₀)^i) at_top (𝓝 (f z₀))
      ∧ ∃ i, c i = 0) :
    ∃ (c : ℕ → ℂ) (n : ℕ), f = λ z, ∑ i in finset.range n, (c i) * z ^ n :=

Suppose $f$ is an analytic function defined everywhere in $\mathbb{C}$ and such that for each $z_0 \in \mathbb{C}$ at least one coefficient in the expansion $f(z) = \sum_{n=0}^\infty c_n(z - z_0)^n$ is equal to 0. Prove that $f$ is a polynomial.

\begin{proof}

Say that at least one of the coefficients of the Taylor series vanishes is the same as saying that for every $a \in \mathbb{C}$ there is $m \in \mathbb{N}$ such that $f^{(m)}(a)=0$.

Consider $A_n:=\left\{z \in \mathbb{C}: f^{(n)}(z)=0\right\}$ for each $n \in \mathbb{N}$. Note that:

$f$ is polynomial iff $A_n$ is not countable for some $n \in \mathbb{N}$.

Indeed, if $f$ is polynomial of degree $n$, then $f^{(n+1)}(z)=0$ for all $z \in \mathbb{C}$, then $A_{n+1}=\mathbb{C}$, so, $A_{n+1}$ is not countable. Conversely, if there is $n \in \mathbb{C}$ such that $A_n$ is not countable, then $A_n$ has a limit point, then by Identity principle we have $f^{(n)}(z)=0$ for all $z \in \mathbb{C}$, so, $f$ is a polynomial of degree at most $n-1$.

Therefore, tt suffices to show that there is $n \in \mathbb{N}$ such that $A_n$ is not countable. Indeed, consider $\bigcup_{n \in \mathbb{N}} A_n$, by hypothesis for each $a \in \mathbb{C}$ there is $m \in \mathbb{N}$ such that $f^{(m)}(a)=0$, then $\mathbb{C} \subseteq \bigcup_{n \in \mathbb{N}} A_n$. Therefore, $\bigcup_{n \in \mathbb{N}} A_n$ is not countable, then there is $n \in \mathbb{N}$ such that $A_n$ is not countable.

\end{proof}


theorem exercise_3_4 (a : ℝ) (ha : 0 < a) :
    tendsto (λ y, ∫ x in -y..y, x * real.sin x / (x ^ 2 + a ^ 2))
    at_top (𝓝 (real.pi * (real.exp (-a)))) :=

import .common

open complex filter function interval_integral metric

open_locale big_operators
open_locale filter
open_locale topology

Show that $ \int_{-\infty}^{\infty} \frac{x \sin x}{x^2 + a^2} dx = \pi e^{-a}$ for $a > 0$.


theorem exercise_3_14 {f : ℂ → ℂ} (hf : differentiable ℂ f)
    (hf_inj : function.injective f) :
    ∃ (a b : ℂ), f = (λ z, a * z + b) ∧ a ≠ 0 :=

Prove that all entire functions that are also injective take the form $f(z) = az + b$, $a, b \in \mathbb{C}$ and $a \neq 0$.

\begin{proof}

Look at $f(1 / z)$. If it has an essential singularity at 0 , then pick any $z_0 \neq 0$. Now we know that the range of $f$ is dense as $z \rightarrow 0$. We also know that the image of $f$ in some small ball around $z_0$ contains a ball around $f\left(z_0\right)$. But this means that the image of $f$ around this ball intersects the image of $f$ in any arbitrarily small ball around 0 (because of the denseness). Thus, $f$ cannot be injective. So the singularity at 0 is not essential, so $f(1 / z)$ is some polynomial of $1 / z$, so $f$ is some polynomial of $z$. If its degree is more than 1 it is not injective (fundamental theorem of algebra), so the degree of $f$ is 1 .

\end{proof}


theorem exercise_5_1 (f : ℂ → ℂ) (hf : differentiable_on ℂ f (ball 0 1))
  (hb : bounded (set.range f)) (h0 : f ≠ 0) (zeros : ℕ → ℂ) (hz : ∀ n, f (zeros n) = 0)
  (hzz : set.range zeros = {z | f z = 0 ∧ z ∈ (ball (0 : ℂ) 1)}) :
  ∃ (z : ℂ), tendsto (λ n, (∑ i in finset.range n, (1 - zeros i))) at_top (𝓝 z) :=

Prove that if $f$ is holomorphic in the unit disc, bounded and not identically zero, and $z_{1}, z_{2}, \ldots, z_{n}, \ldots$ are its zeros $\left(\left|z_{k}\right|<1\right)$, then $\sum_{n}\left(1-\left|z_{n}\right|\right)<\infty$.

\begin{proof}

    Fix $\mathrm{N}$ and let $D(0, R)$ contains the first $\mathrm{N}$ zeroes of f. Let $S_N=\sum_{k=1}^N\left(1-\left|z_k\right|\right)=$ $\sum_{k=1}^N \int_{\left|z_k\right|}^1 1 d r$. Let $\eta_k$ be the characteristic function of the interval $\left.\| z_k \mid, 1\right]$. We have $S_N=\sum_{k=1}^N \int_0^1 \eta(r) d r=\int_0^1\left(\sum_{k=1}^N \eta_k(r)\right) d r \leq \int_0^1 n(r) d r$, where $n(r)$ is the number of zeroes of $f$ at the disk $D(0, r)$. For $r \leq 1$ we have $n(r) \leq \frac{n(r)}{r}$. This means that $S_N \leq \int_0^1 n(r) \frac{d r}{r}$. If $f(0)=0$ then we have $f(z)=z^m g(z)$ for some integer $\mathrm{m}$ and some holomorphic $g$ with $g(0) \neq 0$. The other zeroes of $\mathrm{f}$ are precisely the zeroes of $g$. Thus we have reduced the problem to $f(0) \neq 0$. By the Corollary of the Jensen's equality we get $S_N \leq \int_0^1 n(r) \frac{d r}{r}=\frac{1}{2 \pi} \int_0^{2 \pi} \log \left|f\left(R e^{i \pi}\right)\right| d \phi-\log |f(0)|<M$ since $f$ is bounded. The partial sums of the series are boundend and therefore the series converges.

\end{proof}


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

import .common

open real topological_space filter polynomial
open_locale topology big_operators complex_conjugate filter ennreal

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

\begin{proof}

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

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

Define the set

\[

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

\]

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

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

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

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

\[

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

\]

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

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

\[

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

\]

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

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

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

\[

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

\]

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

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

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

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

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

hence $f$ is identically zero.

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

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

\end{proof}


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

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

\begin{proof}

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

\begin{align*}

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

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

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

\end{align*}

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

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

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

\[

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

\]

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

\begin{align*}

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

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

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

\end{align*}

and so

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

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

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

\begin{align*}

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

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

\end{align*}

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

\end{proof}


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


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

\begin{proof}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

\end{proof}


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

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

\begin{proof}

\setcounter{equation}{0}

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

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

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

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

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

\[

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

\]

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

we get

\begin{equation}

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

\end{equation}

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

we have

\[

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

\]

Applying the fact to the difference between the sides yields

\begin{equation}

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

\end{equation}

Combining (1) and (2), we obtain

\begin{align*}

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

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

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

\end{align*}

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

\end{proof}


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

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

\begin{proof}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

is not a perfect square.

\end{proof}


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

import .common

open set real filter function ring_hom topological_space

open_locale big_operators
open_locale filter
open_locale topology
noncomputable theory

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

\begin{proof}

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

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

\end{proof}


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

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

\begin{proof}

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

\end{proof}


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

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

\begin{proof}

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

$$

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

$$

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

\end{proof}


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

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

\begin{proof}

    Let

$$

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

$$

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

$$

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

$$

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

$$

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

$$

or

$$

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

$$

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

\end{proof}


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

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

\begin{proof}

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

$$

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

$$

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

\end{proof}


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

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

\begin{proof}

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

$$

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

$$

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

$$

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

$$

converges if and only if $c>1$.

\end{proof}


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

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

\begin{proof}

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

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

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

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

$$

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

$$

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

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

$$

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

$$

for all $a, b \in X$.

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

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

Let $\epsilon>0$.

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

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

This completes the proof.

\end{proof}


theorem exercise_2_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_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}


theorem exercise_1_1_2a : ∃ a b : ℤ, a - b ≠ b - a :=

import .common

open set function nat int fintype real polynomial mv_polynomial
open subgroup ideal submodule zsqrtd gaussian_int char_p mul_aut matrix

open_locale pointwise
open_locale big_operators
noncomputable theory

Prove the the operation $\star$ on $\mathbb{Z}$ defined by $a\star b=a-b$ is not commutative.

\begin{proof}

    Not commutative since

$$

1 \star(-1)=1-(-1)=2

$$

$$

(-1) \star 1=-1-1=-2 .

$$

\end{proof}


theorem exercise_1_1_4 (n : ℕ) :
  ∀ (a b c : ℕ), (a * b) * c ≡ a * (b * c) [ZMOD n] :=

Prove that the multiplication of residue class $\mathbb{Z}/n\mathbb{Z}$ is associative.

\begin{proof}

    We have

$$

\begin{aligned}

(\bar{a} \cdot \bar{b}) \cdot \bar{c} &=\overline{a \cdot b} \cdot \bar{c} \\

&=\overline{(a \cdot b) \cdot c} \\

&=\overline{a \cdot(b \cdot c)} \\

&=\bar{a} \cdot \overline{b \cdot c} \\

&=\bar{a} \cdot(\bar{b} \cdot \bar{c})

\end{aligned}

$$

since integer multiplication is associative.

\end{proof}


theorem exercise_1_1_15 {G : Type*} [group G] (as : list G) :
  as.prod⁻¹ = (as.reverse.map (λ x, x⁻¹)).prod :=

\begin{proof}

    For $n=1$, note that for all $a_1 \in G$ we have $a_1^{-1}=a_1^{-1}$.

Now for $n \geq 2$ we proceed by induction on $n$. For the base case, note that for all $a_1, a_2 \in G$ we have

$$

\left(a_1 \cdot a_2\right)^{-1}=a_2^{-1} \cdot a_1^{-1}

$$

since

$$

a_1 \cdot a_2 \cdot a_2^{-1} a_1^{-1}=1 .

$$

For the inductive step, suppose that for some $n \geq 2$, for all $a_i \in G$ we have

$$

\left(a_1 \cdot \ldots \cdot a_n\right)^{-1}=a_n^{-1} \cdot \ldots \cdot a_1^{-1} .

$$

Then given some $a_{n+1} \in G$, we have

$$

\begin{aligned}

\left(a_1 \cdot \ldots \cdot a_n \cdot a_{n+1}\right)^{-1} &=\left(\left(a_1 \cdot \ldots \cdot a_n\right) \cdot a_{n+1}\right)^{-1} \\

&=a_{n+1}^{-1} \cdot\left(a_1 \cdot \ldots \cdot a_n\right)^{-1} \\

&=a_{n+1}^{-1} \cdot a_n^{-1} \cdot \ldots \cdot a_1^{-1},

\end{aligned}

$$

using associativity and the base case where necessary.

\end{proof}


theorem exercise_1_1_17 {G : Type*} [group G] {x : G} {n : ℕ}
  (hxn: order_of x = n) :
  x⁻¹ = x ^ (n-1) :=

Let $x$ be an element of $G$. Prove that if $|x|=n$ for some positive integer $n$ then $x^{-1}=x^{n-1}$.

\begin{proof}

    We have $x \cdot x^{n-1}=x^n=1$, so by the uniqueness of inverses $x^{-1}=x^{n-1}$.

\end{proof}


theorem exercise_1_1_20 {G : Type*} [group G] {x : G} :
  order_of x = order_of x⁻¹ :=

For $x$ an element in $G$ show that $x$ and $x^{-1}$ have the same order.

\begin{proof}

    Recall that the order of a group element is either a positive integer or infinity.

Suppose $|x|$ is infinite and that $\left|x^{-1}\right|=n$ for some $n$. Then

$$

x^n=x^{(-1) \cdot n \cdot(-1)}=\left(\left(x^{-1}\right)^n\right)^{-1}=1^{-1}=1,

$$

a contradiction. So if $|x|$ is infinite, $\left|x^{-1}\right|$ must also be infinite. Likewise, if $\left|x^{-1}\right|$ is infinite, then $\left|\left(x^{-1}\right)^{-1}\right|=|x|$ is also infinite.

Suppose now that $|x|=n$ and $\left|x^{-1}\right|=m$ are both finite. Then we have

$$

\left(x^{-1}\right)^n=\left(x^n\right)^{-1}=1^{-1}=1,

$$

so that $m \leq n$. Likewise, $n \leq m$. Hence $m=n$ and $x$ and $x^{-1}$ have the same order.

\end{proof}


theorem exercise_1_1_22b {G: Type*} [group G] (a b : G) :
  order_of (a * b) = order_of (b * a) :=

Deduce that $|a b|=|b a|$ for all $a, b \in G$.

\begin{proof}

    Let $a$ and $b$ be arbitrary group elements. Letting $x=a b$ and $g=a$, we see that

$$

|a b|=\left|a^{-1} a b a\right|=|b a| .

$$

\end{proof}


theorem exercise_1_1_29 {A B : Type*} [group A] [group B] :
  ∀ x y : A × B, x*y = y*x ↔ (∀ x y : A, x*y = y*x) ∧
  (∀ x y : B, x*y = y*x) :=

Prove that $A \times B$ is an abelian group if and only if both $A$ and $B$ are abelian.

\begin{proof}

    $(\Rightarrow)$ Suppose $a_1, a_2 \in A$ and $b_1, b_2 \in B$. Then

$$

\left(a_1 a_2, b_1 b_2\right)=\left(a_1, b_1\right) \cdot\left(a_2, b_2\right)=\left(a_2, b_2\right) \cdot\left(a_1, b_1\right)=\left(a_2 a_1, b_2 b_1\right) .

$$

Since two pairs are equal precisely when their corresponding entries are equal, we have $a_1 a_2=a_2 a_1$ and $b_1 b_2=b_2 b_1$. Hence $A$ and $B$ are abelian.

$(\Leftarrow)$ Suppose $\left(a_1, b_1\right),\left(a_2, b_2\right) \in A \times B$. Then we have

$$

\left(a_1, b_1\right) \cdot\left(a_2, b_2\right)=\left(a_1 a_2, b_1 b_2\right)=\left(a_2 a_1, b_2 b_1\right)=\left(a_2, b_2\right) \cdot\left(a_1, b_1\right) .

$$

Hence $A \times B$ is abelian.

\end{proof}


theorem exercise_1_3_8 : infinite (equiv.perm ℕ) :=

Prove that if $\Omega=\{1,2,3, \ldots\}$ then $S_{\Omega}$ is an infinite group

\begin{proof}

    Recall that the codomain of an injective function must be at least as large (in cardinality) as the domain of the function. With that in mind, define the function

$$

\begin{gathered}

f: \mathbb{N} \rightarrow S_{\mathbb{N}} \\

f(n)=(1 n)

\end{gathered}

$$

where $(1 n)$ is the cycle decomposition of an element of $S_{\mathbb{N}}$ (specifically it's the function given by $g(1)=n, g(2)=2, g(3)=3, \ldots)$. The function $f$ maps every natural number to a distinct one of these functions. Hence $f$ is injective. Hence $\infty=|\mathbb{N}| \leq\left|S_{\mathbb{N}}\right|$.

\end{proof}


theorem exercise_1_6_11 {A B : Type*} [group A] [group B] :
  A × B ≃* B × A :=

Let $A$ and $B$ be groups. Prove that $A \times B \cong B \times A$.

\begin{proof}

    We know from set theory that the mapping $\varphi: A \times B \rightarrow B \times A$ given by $\varphi((a, b))=(b, a)$ is a bijection with inverse $\psi: B \times A \rightarrow A \times B$ given by $\psi((b, a))=(a, b)$. Also $\varphi$ is a homomorphism, as we show below.

Let $a_1, a_2 \in A$ and $b_1, b_2 \in B$. Then

$$

\begin{aligned}

\varphi\left(\left(a_1, b_1\right) \cdot\left(a_2, b_2\right)\right) &=\varphi\left(\left(a_1 a_2, b_1 b_2\right)\right) \\

&=\left(b_1 b_2, a_1 a_2\right) \\

&=\left(b_1, a_1\right) \cdot\left(b_2, a_2\right) \\

&=\varphi\left(\left(a_1, b_1\right)\right) \cdot \varphi\left(\left(a_2, b_2\right)\right)

\end{aligned}

$$

Hence $A \times B \cong B \times A$.

\end{proof}


theorem exercise_1_6_23 {G : Type*}
  [group G] (σ : mul_aut G) (hs : ∀ g : G, σ g = 1 → g = 1)
  (hs2 : ∀ g : G, σ (σ g) = g) :
  ∀ x y : G, x*y = y*x :=

Let $G$ be a finite group which possesses an automorphism $\sigma$ such that $\sigma(g)=g$ if and only if $g=1$. If $\sigma^{2}$ is the identity map from $G$ to $G$, prove that $G$ is abelian.

\begin{proof}

    Solution: We define a mapping $f: G \rightarrow G$ by $f(x)=x^{-1} \sigma(x)$.

Claim: $f$ is injective.

Proof of claim: Suppose $f(x)=f(y)$. Then $y^{-1} \sigma(y)=x^{-1} \sigma(x)$, so that $x y^{-1}=\sigma(x) \sigma\left(y^{-1}\right)$, and $x y^{-1}=\sigma\left(x y^{-1}\right)$. Then we have $x y^{-1}=1$, hence $x=y$. So $f$ is injective.

Since $G$ is finite and $f$ is injective, $f$ is also surjective. Then every $z \in G$ is of the form $x^{-1} \sigma(x)$ for some $x$. Now let $z \in G$ with $z=x^{-1} \sigma(x)$. We have

$$

\sigma(z)=\sigma\left(x^{-1} \sigma(x)\right)=\sigma(x)^{-1} x=\left(x^{-1} \sigma(x)\right)^{-1}=z^{-1} .

$$

Thus $\sigma$ is in fact the inversion mapping, and we assumed that $\sigma$ is a homomorphism. By a previous example, then, $G$ is abelian.

\end{proof}


theorem exercise_2_1_13 (H : add_subgroup ℚ) {x : ℚ}
  (hH : x ∈ H → (1 / x) ∈ H):
  H = ⊥ ∨ H = ⊤ :=

Let $H$ be a subgroup of the additive group of rational numbers with the property that $1 / x \in H$ for every nonzero element $x$ of $H$. Prove that $H=0$ or $\mathbb{Q}$.

\begin{proof}

    Solution: First, suppose there does not exist a nonzero element in $H$. Then $H=0$.

Now suppose there does exist a nonzero element $a \in H$; without loss of generality, say $a=p / q$ in lowest terms for some integers $p$ and $q$ - that is, $\operatorname{gcd}(p, q)=1$. Now $q \cdot \frac{p}{q}=p \in H$, and since $q / p \in H$, we have $p \cdot \frac{q}{p} \in H$. There exist integers $x, y$ such that $q x+p y=1$; note that $q x \in H$ and $p y \in H$, so that $1 \in H$. Thus $n \in H$ for all $n \in \mathbb{Z}$. Moreover, if $n \neq 0,1 / n \in H$. Then $m / n \in H$ for all integers $m, n$ with $n \neq 0$; hence $H=\mathbb{Q}$.

\end{proof}


theorem exercise_2_4_16a {G : Type*} [group G] {H : subgroup G}
  (hH : H ≠ ⊤) :
  ∃ M : subgroup G, M ≠ ⊤ ∧
  ∀ K : subgroup G, M ≤ K → K = M ∨ K = ⊤ ∧
  H ≤ M :=

A subgroup $M$ of a group $G$ is called a maximal subgroup if $M \neq G$ and the only subgroups of $G$ which contain $M$ are $M$ and $G$. Prove that if $H$ is a proper subgroup of the finite group $G$ then there is a maximal subgroup of $G$ containing $H$.

\begin{proof}

If $H$ is maximal, then we are done. If $H$ is not maximal, then there is a subgroup $K_1$ of $G$ such that $H<K_1<G$. If $K_1$ is maximal, we are done. But if $K_1$ is not maximal, there is a subgroup $K_2$ with $H<K_1<K_2<G$. If $K_2$ is maximal, we are done, and if not, keep repeating the procedure. Since $G$ is finite, this process must eventually come to an end, so that $K_n$ is maximal for some positive integer $n$. Then $K_n$ is a maximal subgroup containing $H$.

\end{proof}


theorem exercise_2_4_16c {n : ℕ} (H : add_subgroup (zmod n)) :
  ∃ p : ℕ, nat.prime p ∧ H = add_subgroup.closure {p} ↔
  H ≠ ⊤ ∧ ∀ K : add_subgroup (zmod n), H ≤ K → K = H ∨ K = ⊤ :=

Show that if $G=\langle x\rangle$ is a cyclic group of order $n \geq 1$ then a subgroup $H$ is maximal if and only $H=\left\langle x^{p}\right\rangle$ for some prime $p$ dividing $n$.

\begin{proof}

    Suppose $H$ is a maximal subgroup of $G$. Then $H$ is cyclic, and we may write $H=\left\langle x^k\right\rangle$ for some integer $k$, with $k>1$. Let $d=(n, k)$. Since $H$ is a proper subgroup, we know by Proposition 6 that $d>1$. Choose a prime factor $p$ of $d$. If $k=p=d$ then $k \mid n$ as required.

If, however, $k$ is not prime, then consider the subgroup $K=\left\langle x^p\right\rangle$. Since $p$ is a proper divisor of $k$, it follows that $H<K$. But $H$ is maximal, so we must have $K=G$. Again by Proposition 6 , we must then have $(p, n)=1$. However, $p$ divides $d$ which divides $n$, so $p \mid n$ and $(p, n)=p>1$, a contradiction. Therefore $k=p$ and the left-to-right implication holds.

Now, for the converse, suppose $H=\left\langle x^p\right\rangle$ for $p$ a prime dividing $n$. If $H$ is not maximal then the first part of this exercise shows that there is a maximal subgroup $K$ containing $H$. Then $K=\left\langle x^q\right\rangle$. So $x^p \in\left\langle x^q\right\rangle$, which implies $q \mid p$. But the only divisors of $p$ are 1 and $p$. If $q=1$ then $K=G$ and $K$ cannot be a proper subgroup, and if $q=p$ then $H=K$ and $H$ cannot be a proper subgroup of $K$. This contradiction shows that $H$ is maximal.

\end{proof}


theorem exercise_3_1_22a (G : Type*) [group G] (H K : subgroup G)
  [subgroup.normal H] [subgroup.normal K] :
  subgroup.normal (H ⊓ K) :=

Prove that if $H$ and $K$ are normal subgroups of a group $G$ then their intersection $H \cap K$ is also a normal subgroup of $G$.

\begin{proof}

    Suppose $H$ and $K$ are normal subgroups of $G$. We already know that $H \cap K$ is a subgroup of $G$, so we need to show that it is normal. Choose any $g \in G$ and any $x \in H \cap K$. Since $x \in H$ and $H \unlhd G$, we know $g x g^{-1} \in H$. Likewise, since $x \in K$ and $K \unlhd G$, we have $g x g^{-1} \in K$. Therefore $g x g^{-1} \in H \cap K$. This shows that $g(H \cap K) g^{-1} \subseteq H \cap K$, and this is true for all $g \in G$. By Theorem 6 (5) (which we will prove in Exercise 3.1.25), this is enough to show that $H \cap K \unlhd G$.

\end{proof}


theorem exercise_3_2_8 {G : Type*} [group G] (H K : subgroup G)
  [fintype H] [fintype K]
  (hHK : nat.coprime (fintype.card H) (fintype.card K)) :
  H ⊓ K = ⊥ :=

Prove that if $H$ and $K$ are finite subgroups of $G$ whose orders are relatively prime then $H \cap K=1$.

\begin{proof}

    Solution: Let $|H|=p$ and $|K|=q$. We saw in a previous exercise that $H \cap K$ is a subgroup of both $H$ and $K$; by Lagrange's Theorem, then, $|H \cap K|$ divides $p$ and $q$. Since $\operatorname{gcd}(p, q)=1$, then, $|H \cap K|=1$. Thus $H \cap K=1$.

\end{proof}


theorem exercise_3_2_16 (p : ℕ) (hp : nat.prime p) (a : ℕ) :
  nat.coprime a p → a ^ p ≡ a [ZMOD p] :=

Use Lagrange's Theorem in the multiplicative group $(\mathbb{Z} / p \mathbb{Z})^{\times}$to prove Fermat's Little Theorem: if $p$ is a prime then $a^{p} \equiv a(\bmod p)$ for all $a \in \mathbb{Z}$.

\begin{proof}

    Solution: If $p$ is prime, then $\varphi(p)=p-1$ (where $\varphi$ denotes the Euler totient). Thus

$$

\mid\left((\mathbb{Z} /(p))^{\times} \mid=p-1 .\right.

$$

So for all $a \in(\mathbb{Z} /(p))^{\times}$, we have $|a|$ divides $p-1$. Hence

$$

a=1 \cdot a=a^{p-1} a=a^p \quad(\bmod p) .

$$

\end{proof}


theorem exercise_3_3_3 {p : primes} {G : Type*} [group G]
  {H : subgroup G} [hH : H.normal] (hH1 : H.index = p) :
  ∀ K : subgroup G, K ≤ H ∨ H ⊔ K = ⊤ ∨ (K ⊓ H).relindex K = p :=

Prove that if $H$ is a normal subgroup of $G$ of prime index $p$ then for all $K \leq G$ either $K \leq H$, or $G=H K$ and $|K: K \cap H|=p$.

\begin{proof}

    Solution: Suppose $K \backslash N \neq \emptyset$; say $k \in K \backslash N$. Now $G / N \cong \mathbb{Z} /(p)$ is cyclic, and moreover is generated by any nonidentity- in particular by $\bar{k}$

Now $K N \leq G$ since $N$ is normal. Let $g \in G$. We have $g N=k^a N$ for some integer a. In particular, $g=k^a n$ for some $n \in N$, hence $g \in K N$. We have $[K: K \cap N]=p$ by the Second Isomorphism Theorem.

\end{proof}


theorem exercise_3_4_4 {G : Type*} [comm_group G] [fintype G] {n : ℕ}
    (hn : n ∣ (fintype.card G)) :
    ∃ (H : subgroup G) (H_fin : fintype H), @card H H_fin = n  :=

Use Cauchy's Theorem and induction to show that a finite abelian group has a subgroup of order $n$ for each positive divisor $n$ of its order.

\begin{proof}

    Let $G$ be a finite abelian group. We use induction on $|G|$. Certainly the result holds for the trivial group. And if $|G|=p$ for some prime $p$, then the positive divisors of $|G|$ are 1 and $p$ and the result is again trivial.

Now assume that the statement is true for all groups of order strictly smaller than $|G|$, and let $n$ be a positive divisor of $|G|$ with $n>1$. First, if $n$ is prime then Cauchy's Theorem allows us to find an element $x \in G$ having order $n$. Then $\langle x\rangle$ is the desired subgroup. On the other hand, if $n$ is not prime, then $n$ has a prime divisor $p$, so that $n=k p$ for some integer $k$. Cauchy's Theorem allows us to find an element $x$ having order $p$. Set $N=\langle x\rangle$. By Lagrange's Theorem,

$$

|G / N|=\frac{|G|}{|N|}<|G| .

$$

Now, by the inductive hypothesis, the group $G / N$ must have a subgroup of order $k$. And by the Lattice Isomorphism Theorem, this subgroup has the form $H / N$ for some subgroup $H$ of $G$. Then $|H|=k|N|=k p=n$, so that $H$ has order $n$. This completes the inductive step.

\end{proof}


theorem exercise_3_4_5b {G : Type*} [group G] [is_solvable G]
  (H : subgroup G) [subgroup.normal H] :
  is_solvable (G ⧸ H) :=

Prove that quotient groups of a solvable group are solvable.

\begin{proof}

    Next, note that

$$

H_i=G_i \cap H=\left(G_i \cap G_{i+1}\right) \cap H=G_i \cap H_{i+1} .

$$

By the Second Isomorphism Theorem, we then have

$$

H_{i+1} / H_i=H_{i+1} /\left(H_{i+1} \cap G_i\right) \cong H_{i+1} G_i / G_i \leq G_{i+1} / G_i .

$$

Since $H_{i+1} / H_i$ is isomorphic to a subgroup of the abelian group $G_{i+1} / G_i$, it follows that $H_{i+1} / H_i$ is also abelian. This completes the proof that $H$ is solvable.

Next, let $N \unlhd G$. For each $i$, define

$$

N_i=G_i N, \quad 0 \leq i \leq n .

$$

Now let $g \in N_{i+1}$, where $g=g_0 n_0$ with $g_0 \in G_{i+1}$ and $n_0 \in N$. Also let $x \in N_i$, where $x=g_1 n_1$ with $g_1 \in G_i$ and $n_1 \in N$. Then

$$

g x g^{-1}=g_0 n_0 g_1 n_1 n_0^{-1} g_0^{-1} .

$$

Now, since $N$ is normal in $G, N g=g N$, so $n_0 g_1=g_1 n_2$ for some $n_2 \in N$. Then

$$

g x g^{-1}=g_0 g_1\left(n_2 n_1 n_0^{-1}\right) g_0^{-1}=g_0 g_1 n_3 g_0^{-1}

$$

for some $n_3 \in N$. Then $n_3 g_0^{-1}=g_0^{-1} n_4$ for some $n_4 \in N$. And $g_0 g_1 g_0^{-1} \in G_i$ since $G_i \unlhd G_{i+1}$, so

$$

g x g^{-1}=g_0 g_1 g_0^{-1} n_4 \in N_i .

$$

This shows that $N_i \unlhd N_{i+1}$. So by the Lattice Isomorphism Theorem, we have $N_{i+1} / N \unlhd N_i / N$. This shows that

$$

1=N_0 / N \unlhd N_1 / N \unlhd N_2 / N \unlhd \cdots \unlhd N_n / N=G / N .

$$

Moreover, the Third Isomorphism Theorem says that

$$

\left(N_{i+1} / N\right) /\left(N_i / N\right) \cong N_{i+1} / N_i,

$$

so the proof will be complete if we can show that $N_{i+1} / N_i$ is abelian.

Let $x, y \in N_{i+1} / N_i$. Then

$$

x=\left(g_0 n_0\right) N_i \quad \text { and } \quad y=\left(g_1 n_1\right) N_i

$$

for some $g_0, g_1 \in G_{i+1}$ and $n_0, n_1 \in N$. We have

$$

\begin{aligned}

x y x^{-1} y^{-1} & =\left(g_0 n_0\right)\left(g_1 n_1\right)\left(g_0 n_0\right)^{-1}\left(g_1 n_1\right)^{-1} N_i \\

& =g_0 n_0 g_1 n_1 n_0^{-1} g_0^{-1} n_1^{-1} g_1^{-1} N_i .

\end{aligned}

$$

Since $N \unlhd G, g N=N g$ for any $g \in G$, so we can find $n_2 \in N$ such that

$$

x y x^{-1} y^{-1}=g_0 g_1 g_0^{-1} g^{-1} n_2 N_i .

$$

Now $N_i=G_i N=N G_i$ since $N \unlhd G$ (see Proposition 14 and its corollary). Therefore

$$

n_2 N_i=n_2 N G_i=N G_i=G_i N

$$

and we get

$$

x y x^{-1} y^{-1}=g_0 g_1 g_0^{-1} g^{-1} G_i N=G_i N .

$$

So $x y x^{-1} y^{-1}=1 N_i$ or $x y=y x$. This completes the proof that $G / N$ is solvable.

\end{proof}


theorem exercise_4_2_8 {G : Type*} [group G] {H : subgroup G}
  {n : ℕ} (hn : n > 0) (hH : H.index = n) :
  ∃ K ≤ H, K.normal ∧ K.index ≤ n.factorial :=

Prove that if $H$ has finite index $n$ then there is a normal subgroup $K$ of $G$ with $K \leq H$ and $|G: K| \leq n!$.

\begin{proof}

    Solution: $G$ acts on the cosets $G / H$ by left multiplication. Let $\lambda: G \rightarrow S_{G / H}$ be the permutation representation induced by this action, and let $K$ be the kernel of the representation.

Now $K$ is normal in $G$, and $K \leq \operatorname{stab}_G(H)=H$. By the First Isomorphism Theorem, we have an injective group homomorphism $\bar{\lambda}: G / K \rightarrow S_{G / H}$. Since $\left|S_{G / H}\right|=n !$, we have $[G: K] \leq n !$.

\end{proof}


theorem exercise_4_2_9a {G : Type*} [fintype G] [group G] {p α : ℕ}
  (hp : p.prime) (ha : α > 0) (hG : card G = p ^ α) :
  ∀ H : subgroup G, H.index = p → H.normal :=

Prove that if $p$ is a prime and $G$ is a group of order $p^{\alpha}$ for some $\alpha \in \mathbb{Z}^{+}$, then every subgroup of index $p$ is normal in $G$.

\begin{proof}

    Solution: Let $G$ be a group of order $p^k$ and $H \leq G$ a subgroup with $[G: H]=p$. Now $G$ acts on the conjugates $g H g^{-1}$ by conjugation, since

$$

g_1 g_2 \cdot H=\left(g_1 g_2\right) H\left(g_1 g_2\right)^{-1}=g_1\left(g_2 H g_2^{-1}\right) g_1^{-1}=g_1 \cdot\left(g_2 \cdot H\right)

$$

and $1 \cdot H=1 H 1=H$. Moreover, under this action we have $H \leq \operatorname{stab}(H)$. By Exercise 3.2.11, we have

$$

[G: \operatorname{stab}(H)][\operatorname{stab}(H): H]=[G: H]=p,

$$

a prime.

If $[G: \operatorname{stab}(H)]=p$, then $[\operatorname{stab}(H): H]=1$ and we have $H=\operatorname{stab}(H)$; moreover, $H$ has exactly $p$ conjugates in $G$. Let $\varphi: G \rightarrow S_p$ be the permutation representation induced by the action of $G$ on the conjugates of $H$, and let $K$ be the kernel of this representation. Now $K \leq \operatorname{stab}(H)=H$. By the first isomorphism theorem, the induced map $\bar{\varphi}: G / K \rightarrow S_p$ is injective, so that $|G / K|$ divides $p$ !. Note, however, that $|G / K|$ is a power of $p$ and that the only powers of $p$ that divide $p$ ! are 1 and $p$. So $[G: K]$ is 1 or $p$. If $[G: K]=1$, then $G=K$ so that $g H g^{-1}=H$ for all $g \in G$; then $\operatorname{stab}(H)=G$ and we have $[G: \operatorname{stab}(H)]=1$, a contradiction. Now suppose $[G: K]=p$. Again by Exercise $3.2$.11 we have $[G: K]=[G: H][H: K]$, so that $[H: K]=1$, hence $H=K$. Again, this implies that $H$ is normal so that $g H g^{-1}=H$ for all $g \in G$, and we have $[G: \operatorname{stab}(H)]=1$, a contradiction. Thus $[G: \operatorname{stab}(H)] \neq p$

If $[G: \operatorname{stab}(H)]=1$, then $G=\operatorname{stab}(H)$. That is, $g H g^{-1}=H$ for all $g \in G$; thus $H \leq G$ is normal.

\end{proof}


theorem exercise_4_4_2 {G : Type*} [fintype G] [group G]
  {p q : nat.primes} (hpq : p ≠ q) (hG : card G = p*q) :
  is_cyclic G :=

Prove that if $G$ is an abelian group of order $p q$, where $p$ and $q$ are distinct primes, then $G$ is cyclic.

\begin{proof}

    Let $G$ be an abelian group of order $p q$. We need to prove that if $p$ and $q$ are distinct primes than $G$ is cyclic. By Cauchy's theorem there are $a, b \in G$ with $a$ of order $p$ and $b$ of order $q$. Since $(|a|,|b|)=1$ and $a b=b a$ then $|a b|=|a| \cdot|b|=p q$. Therefore $a b$ is an element of order $p q$, the order of $G$, which means $G$ is cyclic.

\end{proof}


theorem exercise_4_4_6b {G : Type*} [group G] :
  ∃ H : subgroup G, H.characteristic ∧ ¬ H.normal :=

Prove that there exists a normal subgroup that is not characteristic.

\begin{proof}

    We have to produce a group $G$ and a subgroup $H$ such that $H$ is normal in $G$, but not characterestic. Consider the Klein's four group $G=\{ e, a, b, a b\}$. This is an abelian group with each element having order 2. Consider $H=\{ e, a\}$. $H$ is normal in $G$. Define $\sigma: G \rightarrow G$ as $\sigma(a)=b, \sigma(b)=a, \sigma(a b)=a b$. Clearly $\sigma$ does not fix $H$. So, $H$ is not characterestic.

\end{proof}


theorem exercise_4_4_8a {G : Type*} [group G] (H K : subgroup G)
  (hHK : H ≤ K) [hHK1 : (H.subgroup_of K).normal] [hK : K.normal] :
  H.normal :=

Let $G$ be a group with subgroups $H$ and $K$ with $H \leq K$. Prove that if $H$ is characteristic in $K$ and $K$ is normal in $G$ then $H$ is normal in $G$.

\begin{proof}

We prove that $H$ is invariant under every inner automorphism of $G$. Consider a inner automorphism $\phi_g$ of $G$. Now, $\left.\phi_g\right|_K$ is a automorphism of $K$ because $K$ is normal in $G$. But $H$ is a characterestic subgroup of $K$, so $\left.\phi_g\right|_K(H) \subset H$, so in general $\phi_g(H) \subset H$. Hence $H$ is characteretstic in $G$.

\end{proof}


theorem exercise_4_5_13 {G : Type*} [group G] [fintype G]
  (hG : card G = 56) :
  ∃ (p : ℕ) (P : sylow p G), P.normal :=

Prove that a group of order 56 has a normal Sylow $p$-subgroup for some prime $p$ dividing its order.

\begin{proof}

Since $|G|=56=2^{3}.7$, $G$ has $2-$Sylow subgroup of order $8$, as well as $7-$Sylow subgroup of order $7$. Now, we count the number of such subgroups. Let $n_{7}$ be the number of  $7-$Sylow subgroup and $n_{2}$ be the number of  $2-$Sylow subgroup. Now $n_{7}=1+7k$ where $1+7k|8$. The choices for $k$ are $0$ or $1$. If $k=0$, there is only one $7-$Sylow subgroup and hence normal. So, assume now, that there are $8$ $7-$Sylow subgroup(for $k=1$). Now we look at $2-$ Sylow subgroups. $n_{2}=1+2k| 7$. So choice for $k$ are $0$ and $3$. If $k=0$, there is only one $2-$Sylow subgroup and hence normal. So, assume now, that there are $7$ $2-$Sylow subgroup (for $k=3$). Now we claim that simultaneously, there cannot be $8$ $7-$Sylow subgroup and $7$ $2-$Sylow subgroup. So, either $7-$Sylow subgroup is normal being unique, or  the $2-$Sylow subgroup is normal. Now, to prove the claim, we observe that there are 48 elements of order $7$. Let $H_{1}$ and $H_{2}$ be two distinct  $2-$Sylow subgroup. Now $|H_{1}|=8$. So we already get $48+8=56$ distinct elements in the group. Now $H_{2}$ being distinct from $H_{1}$, has at least one element which is not in $H_{1}$. This adds one more element in the group, at the least. Now already we have number of elements in the group exceeding the number of element in $G$. This gives a contradiction and proves the claim.

\end{proof}


theorem exercise_4_5_15 {G : Type*} [group G] [fintype G]
  (hG : card G = 351) :
  ∃ (p : ℕ) (P : sylow p G), P.normal :=

Prove that a group of order 351 has a normal Sylow $p$-subgroup for some prime $p$ dividing its order.

\begin{proof}

    Since $|G|=351=3^{2}.13$, $G$ has $3-$Sylow subgroup of order $9$, as well as $13-$Sylow subgroup of order $13$. Now, we count the number of such subgroups. Let $n_{13}$ be the number of $13-$Sylow subgroup and $n_{3}$ be the number of  $3-$Sylow subgroup. Now $n_{13}=1+13k$ where $1+13k|9$. The choices for $k$ is $0$. Hence, there is a unique $13-$Sylow subgroup and hence is normal.

\end{proof}


theorem exercise_4_5_17 {G : Type*} [fintype G] [group G]
  (hG : card G = 105) :
  nonempty(sylow 5 G) ∧ nonempty(sylow 7 G) :=

Prove that if $|G|=105$ then $G$ has a normal Sylow 5 -subgroup and a normal Sylow 7-subgroup.

\begin{proof}

Since $|G|=105=3.5.7$, $G$ has $3-$Sylow subgroup of order $3$, as well as $5-$Sylow subgroup of order $5$ and, $7-$Sylow subgroup of order 7. Now, we count the number of such subgroups. Let $n_{3}$ be the number of $3-$Sylow subgroup, $n_{5}$ be the number of  $5-$Sylow subgroup, and $n_{7}$ be the number of $7-$Sylow subgroup. Now $n_{7}=1+7k$ where $1+7k|15$. The choices for $k$ are $0$ or $1$. If $k=0$, there is only one $7-$Sylow subgroup and hence normal. So, assume now, that there are $15$ $7-$Sylow subgroup(for $k=1$). Now we look at $5-$ Sylow subgroups. $n_{5}=1+5k| 21$. So choice for $k$ are $0$ and $4$. If $k=0$, there is only one $5-$Sylow subgroup and hence normal. So, assume now, that there are $24$ $5-$Sylow subgroup (for $k=4$). Now we claim that simultaneously, there cannot be $15$ $7-$Sylow subgroup and $24$ $5-$Sylow subgroup. So, either $7-$Sylow subgroup is normal being unique, or  the $5-$Sylow subgroup is normal. Now, to prove the claim, we observe that there are 90 elements of order $7$. Also, see that there are $24\times 4=96$ number of elements of order 5. So we get $90+94=184$ number of elements which exceeds the order of the group. This gives a contradiction and proves the claim. So, now we have proved that there is either a normal $5-$Sylow subgroup or a normal $7-$Sylow subgroup.

    Now we prove that indeed both $5-$ Sylow subgroup and 7 -Sylow subgroup are normal. Assume that 7 -Sylow subgroup is normal. So, there is a unique 7 -Sylow subgroup, say $H$. Now assume that there are 245 -Sylow subgroups. So, we get again $24 \times 4=96$ elements of order 5 . From $H$ we get 7 elements which gives us total of $96+7=103$ elements. Now consider the number of 3 -Sylow subgroups. $n_3=1+3 k \mid 35$. Then the possibilities for $k$ are 0 and 2 . But we can rule out $k=2$ because having 73 -Sylow subgroup, will mean we have 14 elements of order 3 . So we get $103+14=117$ elements in total which exceeds the order of the group. So we have now that there is a unique 3 -Sylow subgroup and hence normal. Call that subgroup $K$. Now take any one 5 -Sylow subgroup, call it $L$. Now observe $L K$ is a subgroup of $G$ with order 15 . We know that a group of order 15 is cyclic by an example in Page-143 of the book. So, there is an element of order 15. Actually we have $\phi(15)=8$ number of elements of order 15. But then again we already had 103 elements and then we actually get at least $103+8=111$ elements which exceeds the order of the group. So, there can't be 24 5-Sylow subgroups, and hence there is a unique 5-Sylow subgroup, and hence normal.

\end{proof}


theorem exercise_4_5_19 {G : Type*} [fintype G] [group G]
  (hG : card G = 6545) : ¬ is_simple_group G :=

Prove that if $|G|=6545$ then $G$ is not simple.

\begin{proof}

Since $|G|=132=2^{2}.3.11$, $G$ has $2-$Sylow subgroup of order $4$, as well as $11-$Sylow subgroup of order $11$, and $3-$Sylow subgroup of order $3$. Now, we count the number of such subgroups. Let $n_{11}$ be the number of  $11-$Sylow subgroup and $n_{3}$ be the number of  $3-$Sylow subgroup. Now $n_{11}=1+11k$ where $1+11k|12$. The choices for $k$ are $0$ or $1$. If $k=0$, there is only one $11-$Sylow subgroup and hence normal. So, assume now, that there are $12$ $11-$Sylow subgroup(for $k=1$). Now we look at $3-$ Sylow subgroups. $n_{3}=1+3k| 44$. So choice for $k$ are $0$, $1$, and $7$. If $k=0$, there is only one $3-$Sylow subgroup and hence normal. So, assume now, that there are $4$ $2-$Sylow subgroup (for $k=3$). Now we claim that simultaneously, there cannot be $12$ $11-$Sylow subgroup and $4$ $3-$Sylow subgroups provided there is more than one $2-$Sylow subgroups. So, either $2-$Sylow subgroup is normal or if not, then, either $11-$Sylow subgroup is normal being unique, or  the $3-$Sylow subgroup is normal(We don't consider the possibility of $22$ $3-$Sylow subgroup because of obvious reason). Now, to prove the claim, we observe that there are $120$ elements of order $11$. Also there are $8$ elements of order $3$. So we already get $120+8+1=129$ distinct elements in the group. Let us count the number of $2-$Sylow subgroups in $G$. $n_{2}=1+2k|33$. The possibilities for $k$ are $0$, $1$, $5$, $16$. Now, assume there is more than one $2-$Sylow subgroups. Let $H_{1}$ and $H_{2}$ be two distinct  $2-$Sylow subgroup. Now $|H_{1}|=4$. So we already get $129+3=132$ distinct elements in the group. Now $H_{2}$ being distinct from $H_{1}$, has at least one element which is not in $H_{1}$. This adds one more element in the group, at the least. Now already we have number of elements in the group exceeding the number of element in $G$. This gives a contradiction and proves the claim.

Hence $G$ is not simple.

\end{proof}


theorem exercise_4_5_21 {G : Type*} [fintype G] [group G]
  (hG : card G = 2907) : ¬ is_simple_group G :=

Prove that if $|G|=2907$ then $G$ is not simple.

\begin{proof}

Since $|G|=2907=3^{2}.17.19$, $G$ has $19-$Sylow subgroup of order $19$. Now, we count the number of such subgroups. Let $n_{19}$ be the number of $19-$Sylow subgroup. Now $n_{19}=1+19k$ where $1+19k|3^{2}.17$. The choices for $k$ is $0$. Hence, there is a unique $19-$Sylow subgroup and hence is normal. so $G$ is not simple.

\end{proof}


theorem exercise_4_5_23 {G : Type*} [fintype G] [group G]
  (hG : card G = 462) : ¬ is_simple_group G :=

Prove that if $|G|=462$ then $G$ is not simple.

\begin{proof}

    Let $G$ be a group of order $462=11 \cdot 42$. Note that 11 is a prime not dividing 42 . Let $P \in$ $S y l_{11}(G)$. [We know $P$ exists since $S y l_{11}(G) \neq \emptyset$]. Note that $|P|=11^1=11$ by definition.

The number of Sylow 11-subgroups of $G$ is of the form $1+k \cdot 11$, i.e., $n_{11} \equiv 1$ (mod 11) and $n_{11}$ divides 42 . The only such number that divides 42 and equals 1 (mod 11) is 1 so $n_{11}=1$. Hence $P$ is the unique Sylow 11-subgroup.

Since $P$ is the unique Sylow Il-subgroup, this implies that $P$ is normal in $G$.

\end{proof}


theorem exercise_4_5_33 {G : Type*} [group G] [fintype G] {p : ℕ}
  (P : sylow p G) [hP : P.normal] (H : subgroup G) [fintype H] :
  ∀ R : sylow p H, R.to_subgroup = (H ⊓ P.to_subgroup).subgroup_of H ∧
  nonempty (sylow p H) :=

Let $P$ be a normal Sylow $p$-subgroup of $G$ and let $H$ be any subgroup of $G$. Prove that $P \cap H$ is the unique Sylow $p$-subgroup of $H$.

\begin{proof}

    Let $G$ be a group and $P$ is a normal $p$-Sylow subgroup of $G .|G|=p^a . m$ where $p \nmid m$. Then $|P|=p^a$. Let $H$ be a subgroup of $G$. Now if $|H|=k$ such that $p \nmid k$. Then $P \cap H=\{e\}$. There is nothing to prove in this case. Let $|H|=p^b . n$, where $b \leq a$, and $p \nmid n$. Now consider $P H$ which is a subgroup of $G$, as $P$ is normal. Now $|P H|=\frac{|P||H|}{|P \cap H|}=\frac{p^{a+b} \cdot n}{|P \cap H|}$. Now since $P H \leq G$, so $|P H|=p^a$.l, as $P \leq P H$. This forces $|P \cap H|=p^b$. So by order consideration we have $P \cap H$ is a sylow $-p$ subgroup of $H$. Now we know $P$ is unique $p$ - Sylow subgroup. Suppose $H$ has a sylow-p subgroup distinct from $P \cap H$, call it $H_1$. Now $H_1$ is a p-subgroup of $G$. So, $H_1$ is contained in some Sylow-p subgroup of $G$, call it $P_1$. Clearly $P_1$ is distinct from $P$, which is a contradiction. So $P \cap H$ is the only $p$-Sylow subgroup of $H$, and hence normal in $H$

\end{proof}


theorem exercise_7_1_2 {R : Type*} [ring R] {u : R}
  (hu : is_unit u) : is_unit (-u) :=

Prove that if $u$ is a unit in $R$ then so is $-u$.

\begin{proof}

    Solution: Since $u$ is a unit, we have $u v=v u=1$ for some $v \in R$. Thus, we have

$$

(-v)(-u)=v u=1

$$

and

$$

(-u)(-v)=u v=1 .

$$

Thus $-u$ is a unit.

\end{proof}


theorem exercise_7_1_12 {F : Type*} [field F] {K : subring F}
  (hK : (1 : F) ∈ K) : is_domain K :=

Prove that any subring of a field which contains the identity is an integral domain.

\begin{proof}

    Solution: Let $R \subseteq F$ be a subring of a field. (We need not yet assume that $1 \in R$ ). Suppose $x, y \in R$ with $x y=0$. Since $x, y \in F$ and the zero element in $R$ is the same as that in $F$, either $x=0$ or $y=0$. Thus $R$ has no zero divisors. If $R$ also contains 1 , then $R$ is an integral domain.

\end{proof}


theorem exercise_7_2_2 {R : Type*} [ring R] (p : polynomial R) :
  p ∣ 0 ↔ ∃ b : R, b ≠ 0 ∧ b • p = 0 :=

Let $p(x)=a_{n} x^{n}+a_{n-1} x^{n-1}+\cdots+a_{1} x+a_{0}$ be an element of the polynomial ring $R[x]$. Prove that $p(x)$ is a zero divisor in $R[x]$ if and only if there is a nonzero $b \in R$ such that $b p(x)=0$.

\begin{proof}

    Solution: If $b p(x)=0$ for some nonzero $b \in R$, then it is clear that $p(x)$ is a zero divisor.

Now suppose $p(x)$ is a zero divisor; that is, for some $q(x)=\sum_{i=0}^m b_i x^i$, we have $p(x) q(x)=0$. We may choose $q(x)$ to have minimal degree among the nonzero polynomials with this property.

We will now show by induction that $a_i q(x)=0$ for all $0 \leq i \leq n$.

For the base case, note that

$$

p(x) q(x)=\sum_{k=0}^{n+m}\left(\sum_{i+j=k} a_i b_j\right) x^k=0 .

$$

The coefficient of $x^{n+m}$ in this product is $a_n b_m$ on one hand, and 0 on the other. Thus $a_n b_m=0$. Now $a_n q(x) p(x)=0$, and the coefficient of $x^m$ in $q$ is $a_n b_m=0$. Thus the degree of $a_n q(x)$ is strictly less than that of $q(x)$; since $q(x)$ has minimal degree among the nonzero polynomials which multiply $p(x)$ to 0 , in fact $a_n q(x)=0$. More specifically, $a_n b_i=0$ for all $0 \leq i \leq m$.

For the inductive step, suppose that for some $0 \leq t<n$, we have $a_r q(x)=0$ for all $t<r \leq n$. Now

$$

p(x) q(x)=\sum_{k=0}^{n+m}\left(\sum_{i+j=k} a_i b_j\right) x^k=0 .

$$

On one hand, the coefficient of $x^{m+t}$ is $\sum_{i+j=m+t} a_i b_j$, and on the other hand, it is 0 . Thus

$$

\sum_{i+j=m+t} a_i b_j=0 .

$$

By the induction hypothesis, if $i \geq t$, then $a_i b_j=0$. Thus all terms such that $i \geq t$ are zero. If $i<t$, then we must have $j>m$, a contradiction. Thus we have $a_t b_m=0$. As in the base case,

$$

a_t q(x) p(x)=0

$$

and $a_t q(x)$ has degree strictly less than that of $q(x)$, so that by minimality, $a_t q(x)=0$.

By induction, $a_i q(x)=0$ for all $0 \leq i \leq n$. In particular, $a_i b_m=0$. Thus $b_m p(x)=0$.

\end{proof}


theorem exercise_7_3_16 {R S : Type*} [ring R] [ring S]
  {φ : R →+* S} (hf : surjective φ) :
  φ '' (center R) ⊂ center S :=

Let $\varphi: R \rightarrow S$ be a surjective homomorphism of rings. Prove that the image of the center of $R$ is contained in the center of $S$.

\begin{proof}

    Suppose $r \in \varphi[Z(R)]$. Then $r=\varphi(z)$ for some $z \in Z(R)$. Now let $x \in S$. Since $\varphi$ is surjective, we have $x=\varphi y$ for some $y \in R$. Now

$$

x r=\varphi(y) \varphi(z)=\varphi(y z)=\varphi(z y)=\varphi(z) \varphi(y)=r x .

$$

Thus $r \in Z(S)$.

\end{proof}


theorem exercise_7_4_27 {R : Type*} [comm_ring R] (hR : (0 : R) ≠ 1)
  {a : R} (ha : is_nilpotent a) (b : R) :
  is_unit (1-a*b) :=

Let $R$ be a commutative ring with $1 \neq 0$. Prove that if $a$ is a nilpotent element of $R$ then $1-a b$ is a unit for all $b \in R$.

\begin{proof}

    $\mathfrak{N}(R)$ is an ideal of $R$. Thus for all $b \in R,-a b$ is nilpotent. Hence $1-a b$ is a unit in $R$.

\end{proof}


theorem exercise_8_2_4 {R : Type*} [ring R][no_zero_divisors R]
  [cancel_comm_monoid_with_zero R] [gcd_monoid R]
  (h1 : ∀ a b : R, a ≠ 0 → b ≠ 0 → ∃ r s : R, gcd a b = r*a + s*b)
  (h2 : ∀ a : ℕ → R, (∀ i j : ℕ, i < j → a i ∣ a j) →
  ∃ N : ℕ, ∀ n ≥ N, ∃ u : R, is_unit u ∧ a n = u * a N) :
  is_principal_ideal_ring R :=

Let $R$ be an integral domain. Prove that if the following two conditions hold then $R$ is a Principal Ideal Domain: (i) any two nonzero elements $a$ and $b$ in $R$ have a greatest common divisor which can be written in the form $r a+s b$ for some $r, s \in R$, and (ii) if $a_{1}, a_{2}, a_{3}, \ldots$ are nonzero elements of $R$ such that $a_{i+1} \mid a_{i}$ for all $i$, then there is a positive integer $N$ such that $a_{n}$ is a unit times $a_{N}$ for all $n \geq N$.

\begin{proof}

    Let $I \leq R$ be a nonzero ideal and let $I / \sim$ be the set of equivalence classes of elements of $I$ with regards to the relation of being associates. We can equip $I / \sim$ with a partial order with $[x] \leq[y]$ if $y \mid x$. Condition (ii) implies all chains in $I / \sim$ have an upper bound, so By Zorn's lemma $I / \sim$ contains a maximal element, i.e. $I$ contains a class of associated elements which are minimal with respect to divisibility.

Now let $a, b \in I$ be two elements such that $[a]$ and $[b]$ are minimal with respect to divisibility. By condition (i) $a$ and $b$ have a greatest common divisor $d$ which can be expressed as $d=$ $a x+b y$ for some $x, y \in R$. In particular, $d \in I$. Since $a$ and $b$ are minimal with respect to divisibility, we have that $[a]=[b]=[d]$. Therefore $I$ has at least one element $a$ that is minimal with regard to divisibility and all such elements are associate, and we have $I=\langle a\rangle$ and so $I$ is principal. We conclude $R$ is a principal ideal domain.

\end{proof}


theorem exercise_8_3_5a {n : ℤ} (hn0 : n > 3) (hn1 : squarefree n) :
  irreducible (2 :zsqrtd $ -n) ∧
  irreducible (⟨0, 1⟩ : zsqrtd $ -n) ∧
  irreducible (1 + ⟨0, 1⟩ : zsqrtd $ -n) :=

Let $R=\mathbb{Z}[\sqrt{-n}]$ where $n$ is a squarefree integer greater than 3. Prove that $2, \sqrt{-n}$ and $1+\sqrt{-n}$ are irreducibles in $R$.

\begin{proof}

    Suppose $a=a_1+a_2 \sqrt{-n}, b=b_1+b_2 \sqrt{-n} \in R$ are such that $2=a b$, then $N(a) N(b)=4$. Without loss of generality we can assume $N(a) \leq N(b)$, so $N(a)=1$ or $N(a)=2$. Suppose $N(a)=2$, then $a_1^2+n a_2^2=2$ and since $n>3$ we have $a_2=0$, which implies $a_1^2=2$, a contradiction. So $N(a)=1$ and $a$ is a unit. Therefore 2 is irreducible in $R$.

Suppose now $\sqrt{-n}=a b$, then $N(a) N(b)=n$ and we can assume $N(a)<$ $N(b)$ since $n$ is square free. Suppose $N(a)>1$, then $a_1^2+n a_2^2>1$ and $a_1^2+n a_2^2 \mid n$, so $a_2=0$, and therefore $a_1^2 \mid n$. Since $n$ is squarefree, $a_1=\pm 1$, a contradiction. Therefore $N(a)=1$ and so $a$ is a unit and $\sqrt{-n}$ is irreducible.

Suppose $1+\sqrt{-n}=a b$, then $N(a) N(b)=n+1$ and we can assume $N(a) \leq N(b)$. Suppose $N(a)>1$, then $a_1^2+n a_2^2>1$ and $a_1^2+n a_2^2 \mid n+1$. If $\left|a_2\right| \geq 2$, then since $n>3$ we have a contradiction since $N(a)$ is too large. If $\left|a_2\right|=1$, then $a_1^2+n$ divides $1+n$ and so $a_1=\pm 1$, and in either case $N(a)=n+1$ which contradicts $N(a) \leq N(b)$. If $a_2=0$ then $a_1^2\left(b_1^2+n b_2^2\right)=\left(a_1 b_1\right)^2+n\left(a_1 b_2\right)^2=n+1$. If $\left|a_1 b_2\right| \geq 2$ we have a contradiction. If $\left|a_1 b_2\right|=1$ then $a_1=\pm 1$ which contradicts $N(a)>1$. If $\left|a_1 b_2\right|=0$, then $b_2=0$ and so $a_1 b_1=\sqrt{-n}$, a contradiction. Therefore $N(a)=1$ and so $a$ is a unit and $1+\sqrt{-n}$ is irreducible.

\end{proof}