/-- Suppose that $f$ is holomorphic in an open set $\Omega$. Prove that if $\text{Re}(f)$ is constant, then $f$ is constant.-/

theorem exercise_1_13a {f : ℂ → ℂ} (Ω : Set ℂ) (a b : Ω) (h : IsOpen Ω)
  (hf : DifferentiableOn ℂ f Ω) (hc : ∃ (c : ℝ), ∀ z ∈ Ω, (f z).re = c) :
  f a = f b :=

f : ℂ → ℂ
Ω : Set ℂ
a b : ↑Ω
h : IsOpen Ω
hf : DifferentiableOn ℂ f Ω
hc : ∃ c, ∀ z ∈ Ω, (f z).re = c
⊢ f ↑a = f ↑b

import Mathlib

open Complex Filter Function Metric Finset
open scoped BigOperators Topology

open scoped BigOperators Topology


/-- Suppose that $f$ is holomorphic in an open set $\Omega$. Prove that if $|f|$ is constant, then $f$ is constant.-/

theorem exercise_1_13c {f : ℂ → ℂ} (Ω : Set ℂ) (a b : Ω) (h : IsOpen Ω)
  (hf : DifferentiableOn ℂ f Ω) (hc : ∃ (c : ℝ), ∀ z ∈ Ω, abs (f z) = c) :
  f a = f b :=

f : ℂ → ℂ
Ω : Set ℂ
a b : ↑Ω
h : IsOpen Ω
hf : DifferentiableOn ℂ f Ω
hc : ∃ c, ∀ z ∈ Ω, Complex.abs (f z) = c
⊢ f ↑a = f ↑b

import Mathlib

open Complex Filter Function Metric Finset
open scoped BigOperators Topology


/-- Prove that the power series $\sum zn/n^2$ converges at every point of the unit circle.-/

theorem exercise_1_19b (z : ℂ) (hz : abs z = 1) (s : ℕ → ℂ)
    (h : s = (λ n => ∑ i in (range n), i * z / i ^ 2)) :
    ∃ y, Tendsto s atTop (𝓝 y) :=

z : ℂ
hz : Complex.abs z = 1
s : ℕ → ℂ
h : s = fun n => ∑ i ∈ range n, ↑i * z / ↑i ^ 2
⊢ ∃ y, Tendsto s atTop (𝓝 y)


/-- Suppose $f$ is continuous in a region $\Omega$. Prove that any two primitives of $f$ (if they exist) differ by a constant.-/

theorem exercise_1_26
  (f F₁ F₂ : ℂ → ℂ) (Ω : Set ℂ) (h1 : IsOpen Ω) (h2 : IsConnected Ω)
  (hF₁ : DifferentiableOn ℂ F₁ Ω) (hF₂ : DifferentiableOn ℂ F₂ Ω)
  (hdF₁ : ∀ x ∈ Ω, deriv F₁ x = f x) (hdF₂ : ∀ x ∈ Ω, deriv F₂ x = f x)
  : ∃ c : ℂ, ∀ x, F₁ x = F₂ x + c :=

f F₁ F₂ : ℂ → ℂ
Ω : Set ℂ
h1 : IsOpen Ω
h2 : IsConnected Ω
hF₁ : DifferentiableOn ℂ F₁ Ω
hF₂ : DifferentiableOn ℂ F₂ Ω
hdF₁ : ∀ x ∈ Ω, deriv F₁ x = f x
hdF₂ : ∀ x ∈ Ω, deriv F₂ x = f x
⊢ ∃ c, ∀ (x : ℂ), F₁ x = F₂ x + c


/-- Let $\Omega$ be a bounded open subset of $\mathbb{C}$, and $\varphi: \Omega \rightarrow \Omega$ a holomorphic function. Prove that if there exists a point $z_{0} \in \Omega$ such that $\varphi\left(z_{0}\right)=z_{0} \quad \text { and } \quad \varphi^{\prime}\left(z_{0}\right)=1$ then $\varphi$ is linear.-/

theorem exercise_2_9
  {f : ℂ → ℂ} (Ω : Set ℂ) (b : Bornology.IsBounded Ω) (h : IsOpen Ω)
  (hf : DifferentiableOn ℂ f Ω) (z : Ω) (hz : f z = z) (h'z : deriv f z = 1) :
  ∃ (f_lin : ℂ →L[ℂ] ℂ), ∀ x ∈ Ω, f x = f_lin x :=

f : ℂ → ℂ
Ω : Set ℂ
b : Bornology.IsBounded Ω
h : IsOpen Ω
hf : DifferentiableOn ℂ f Ω
z : ↑Ω
hz : f ↑z = ↑z
h'z : deriv f ↑z = 1
⊢ ∃ f_lin, ∀ x ∈ Ω, f x = f_lin x


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

theorem exercise_3_3 (a : ℝ) (ha : 0 < a) :
    Tendsto (λ y => ∫ x in -y..y, Real.cos x / (x ^ 2 + a ^ 2))
    atTop (𝓝 (Real.pi * (Real.exp (-a) / a))) :=

a : ℝ
ha : 0 < a
⊢ Tendsto (fun y => ∫ (x : ℝ) in -y..y, x.cos / (x ^ 2 + a ^ 2)) atTop (𝓝 (Real.pi * ((-a).exp / a)))


/-- Show that $\int_0^1 \log(\sin \pi x) dx = - \log 2$.-/

theorem exercise_3_9 : ∫ x in (0 : ℝ)..(1 : ℝ),
    Real.log (Real.sin (Real.pi * x)) = - Real.log 2 :=

⊢ ∫ (x : ℝ) in 0 ..1, (Real.pi * x).sin.log = -Real.log 2


/-- Show that there is no holomorphic function $f$ in the unit disc $D$ that extends continuously to $\partial D$ such that $f(z) = 1/z$ for $z \in \partial D$.-/

theorem exercise_3_22 (D : Set ℂ) (hD : D = ball 0 1) (f : ℂ → ℂ)
    (hf : DifferentiableOn ℂ f D) (hfc : ContinuousOn f (closure D)) :
    ¬ ∀ z ∈ (sphere (0 : ℂ) 1), f z = 1 / z :=

D : Set ℂ
hD : D = ball 0 1
f : ℂ → ℂ
hf : DifferentiableOn ℂ f D
hfc : ContinuousOn f (closure D)
⊢ ¬∀ z ∈ sphere 0 1, f z = 1 / z


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

theorem exercise_1_1a
  (x : ℝ) (y : ℚ) :
  ( Irrational x ) -> Irrational ( x + y ) :=

x : ℝ
y : ℚ
⊢ Irrational x → Irrational (x + ↑y)

import Mathlib

open Topology Filter Real Complex TopologicalSpace Finset
open scoped BigOperators


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

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


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

theorem exercise_1_5 (A minus_A : Set ℝ) (hA : A.Nonempty)
  (hA_bdd_below : BddBelow A) (hminus_A : minus_A = {x | -x ∈ A}) :
  Inf A = Sup minus_A :=

A minus_A : Set ℝ
hA : A.Nonempty
hA_bdd_below : BddBelow A
hminus_A : minus_A = {x | -x ∈ A}
⊢ Inf ↑A = Sup ↑minus_A


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

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

z : ℂ
⊢ ∃ r w, Complex.abs w = 1 ∧ z = ↑r * w


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

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

x y : ℂ
⊢ |Complex.abs x - Complex.abs y| ≤ Complex.abs (x - y)


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

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

n : ℕ
d r : ℝ
x y z : EuclideanSpace ℝ (Fin n)
h₁ : n ≥ 3
h₂ : ‖x - y‖ = d
h₃ : d > 0
h₄ : r > 0
h₅ : 2 * r > d
⊢ {z | ‖z - x‖ = r ∧ ‖z - y‖ = r}.Infinite


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

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

n : ℕ
h : n > 1
x : EuclideanSpace ℝ (Fin n)
⊢ ∃ y, y ≠ 0 ∧ ⟪x, y⟫_ℝ = 0


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

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

n : ℕ
a b c x : EuclideanSpace ℝ (Fin n)
r : ℝ
h₁ : r > 0
h₂ : 3 • c = 4 • b - a
h₃ : 3 * r = 2 * ‖x - b‖
⊢ ‖x - a‖ = 2 * ‖x - b‖ ↔ ‖x - c‖ = r


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

theorem exercise_2_24 {X : Type*} [MetricSpace X]
  (hX : ∀ (A : Set X), Infinite A → ∃ (x : X), x ∈ closure A) :
  SeparableSpace X :=

X : Type u_1
inst✝ : MetricSpace X
hX : ∀ (A : Set X), Infinite ↑A → ∃ x, x ∈ closure A
⊢ SeparableSpace X


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

theorem exercise_2_27a (k : ℕ) (E P : Set (EuclideanSpace ℝ (Fin k)))
  (hE : E.Nonempty ∧ ¬ Set.Countable E)
  (hP : P = {x | ∀ U ∈ 𝓝 x, ¬ Set.Countable (P ∩ E)}) :
  IsClosed P ∧ P = {x | ClusterPt x (𝓟 P)} :=

k : ℕ
E P : Set (EuclideanSpace ℝ (Fin k))
hE : E.Nonempty ∧ ¬E.Countable
hP : P = {x | ∀ U ∈ 𝓝 x, ¬(P ∩ E).Countable}
⊢ IsClosed P ∧ P = {x | ClusterPt x (𝓟 P)}


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

theorem exercise_2_28 (X : Type*) [MetricSpace X] [SeparableSpace X]
  (A : Set X) (hA : IsClosed A) :
  ∃ P₁ P₂ : Set X, A = P₁ ∪ P₂ ∧
  IsClosed P₁ ∧ P₁ = {x | ClusterPt x (𝓟 P₁)} ∧
  Set.Countable P₂ :=

X : Type u_1
inst✝¹ : MetricSpace X
inst✝ : SeparableSpace X
A : Set X
hA : IsClosed A
⊢ ∃ P₁ P₂, A = P₁ ∪ P₂ ∧ IsClosed P₁ ∧ P₁ = {x | ClusterPt x (𝓟 P₁)} ∧ P₂.Countable


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

theorem exercise_3_1a
  (f : ℕ → ℝ)
  (h : ∃ (a : ℝ), Tendsto (λ (n : ℕ) => f n) atTop (𝓝 a))
  : ∃ (a : ℝ), Tendsto (λ (n : ℕ) => |f n|) atTop (𝓝 a) :=

f : ℕ → ℝ
h : ∃ a, Tendsto (fun n => f n) atTop (𝓝 a)
⊢ ∃ a, Tendsto (fun n => |f n|) atTop (𝓝 a)


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

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

⊢ ∃ x, Tendsto f atTop (𝓝 x) ∧ ∀ (n : ℕ), f n < 2

import Mathlib

open Topology Filter Real Complex TopologicalSpace Finset
open scoped BigOperators

noncomputable def f : ℕ → ℝ
| 0 => sqrt 2
| (n + 1) => sqrt (2 + sqrt (f n))


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

theorem exercise_3_6a
: Tendsto (λ (n : ℕ) => (∑ i in range n, g i)) atTop atTop :=

⊢ Tendsto (fun n => ∑ i ∈ range n, g i) atTop atTop

import Mathlib

open Topology Filter Real Complex TopologicalSpace Finset
open scoped BigOperators

noncomputable section

def g (n : ℕ) : ℝ := sqrt (n + 1) - sqrt n


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

theorem exercise_3_8
  (a b : ℕ → ℝ)
  (h1 : ∃ y, (Tendsto (λ n => (∑ i in (range n), a i)) atTop (𝓝 y)))
  (h2 : Monotone b)
  (h3 : Bornology.IsBounded (Set.range b)) :
  ∃ y, Tendsto (λ n => (∑ i in (range n), (a i) * (b i))) atTop (𝓝 y) :=

a b : ℕ → ℝ
h1 : ∃ y, Tendsto (fun n => ∑ i ∈ range n, a i) atTop (𝓝 y)
h2 : Monotone b
h3 : Bornology.IsBounded (Set.range b)
⊢ ∃ y, Tendsto (fun n => ∑ i ∈ range n, a i * b i) atTop (𝓝 y)


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

theorem exercise_3_20 {X : Type*} [MetricSpace X]
  (p : ℕ → X) (l : ℕ) (r : X)
  (hp : CauchySeq p)
  (hpl : Tendsto (λ n => p (l * n)) atTop (𝓝 r)) :
  Tendsto p atTop (𝓝 r) :=

X : Type u_1
inst✝ : MetricSpace X
p : ℕ → X
l : ℕ
r : X
hp : CauchySeq p
hpl : Tendsto (fun n => p (l * n)) atTop (𝓝 r)
⊢ Tendsto p atTop (𝓝 r)


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

theorem exercise_3_22 (X : Type*) [MetricSpace X] [CompleteSpace X]
  (G : ℕ → Set X) (hG : ∀ n, IsOpen (G n) ∧ Dense (G n)) :
  ∃ x, ∀ n, x ∈ G n :=

X : Type u_1
inst✝¹ : MetricSpace X
inst✝ : CompleteSpace X
G : ℕ → Set X
hG : ∀ (n : ℕ), IsOpen (G n) ∧ Dense (G n)
⊢ ∃ x, ∀ (n : ℕ), x ∈ G n


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

theorem exercise_4_2a
  {α : Type} [MetricSpace α]
  {β : Type} [MetricSpace β]
  (f : α → β)
  (h₁ : Continuous f)
  : ∀ (x : Set α), f '' (closure x) ⊆ closure (f '' x) :=

α : Type
inst✝¹ : MetricSpace α
β : Type
inst✝ : MetricSpace β
f : α → β
h₁ : Continuous f
⊢ ∀ (x : Set α), f '' closure x ⊆ closure (f '' x)


/-- Let $f$ and $g$ be continuous mappings of a metric space $X$ into a metric space $Y$, and let $E$ be a dense subset of $X$. Prove that $f(E)$ is dense in $f(X)$.-/

theorem exercise_4_4a
  {α : Type} [MetricSpace α]
  {β : Type} [MetricSpace β]
  (f : α → β)
  (s : Set α)
  (h₁ : Continuous f)
  (h₂ : Dense s)
  : f '' Set.univ ⊆ closure (f '' s) :=

α : Type
inst✝¹ : MetricSpace α
β : Type
inst✝ : MetricSpace β
f : α → β
s : Set α
h₁ : Continuous f
h₂ : Dense s
⊢ f '' Set.univ ⊆ closure (f '' s)


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

theorem exercise_4_5a
  (f : ℝ → ℝ)
  (E : Set ℝ)
  (h₁ : IsClosed E)
  (h₂ : ContinuousOn f E)
  : ∃ (g : ℝ → ℝ), Continuous g ∧ ∀ x ∈ E, f x = g x :=

f : ℝ → ℝ
E : Set ℝ
h₁ : IsClosed E
h₂ : ContinuousOn f E
⊢ ∃ g, Continuous g ∧ ∀ x ∈ E, f x = g x


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

theorem exercise_4_6
  (f : ℝ → ℝ)
  (E : Set ℝ)
  (G : Set (ℝ × ℝ))
  (h₁ : IsCompact E)
  (h₂ : G = {(x, f x) | x ∈ E})
  : ContinuousOn f E ↔ IsCompact G :=

f : ℝ → ℝ
E : Set ℝ
G : Set (ℝ × ℝ)
h₁ : IsCompact E
h₂ : G = {x | ∃ x_1 ∈ E, (x_1, f x_1) = x}
⊢ ContinuousOn f E ↔ IsCompact G


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

theorem exercise_4_8b
  (E : Set ℝ) :
  ∃ f : ℝ → ℝ, UniformContinuousOn f E ∧ ¬ Bornology.IsBounded (Set.image f E) :=

E : Set ℝ
⊢ ∃ f, UniformContinuousOn f E ∧ ¬Bornology.IsBounded (f '' E)


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

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

α : Type u_1
β : Type u_2
γ : Type u_3
inst✝² : UniformSpace α
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
f : α → β
g : β → γ
hf : UniformContinuous f
hg : UniformContinuous g
⊢ UniformContinuous (g ∘ f)


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

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

f : ℝ → ℝ
hf : ∀ (a b c : ℝ), a < b → f a < c → c < f b → ∃ x, a < x ∧ x < b ∧ f x = c
hg : ∀ (r : ℚ), IsClosed {x | f x = ↑r}
⊢ Continuous f


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

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

f : ℝ → ℝ
hf : Continuous f
a b : ℝ
hab : a < b
h : ∀ (x y : ℝ), a < x → x < b → a < y → y < b → f ((x + y) / 2) ≤ (f x + f y) / 2
⊢ ConvexOn ℝ (Set.Ioo a b) f


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

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

a b : ℝ
f g : ℝ → ℝ
hf : ∀ x ∈ Set.Ioo a b, deriv f x > 0
hg : g = f⁻¹
hg_diff : DifferentiableOn ℝ g (Set.Ioo a b)
⊢ DifferentiableOn ℝ g (Set.Ioo a b) ∧ ∀ x ∈ Set.Ioo a b, deriv g x = 1 / deriv f x


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

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

n : ℕ
C : ℕ → ℝ
hC : ∑ i ∈ range (n + 1), C i / (↑i + 1) = 0
⊢ ∃ x ∈ Set.Icc 0 1, ∑ i ∈ range (n + 1), C i * x ^ i = 0


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

theorem exercise_5_6
  {f : ℝ → ℝ}
  (hf1 : Continuous f)
  (hf2 : ∀ x, DifferentiableAt ℝ f x)
  (hf3 : f 0 = 0)
  (hf4 : Monotone (deriv f)) :
  MonotoneOn (λ x => f x / x) (Set.Ioi 0) :=

f : ℝ → ℝ
hf1 : Continuous f
hf2 : ∀ (x : ℝ), DifferentiableAt ℝ f x
hf3 : f 0 = 0
hf4 : Monotone (deriv f)
⊢ MonotoneOn (fun x => f x / x) (Set.Ioi 0)


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

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

f : ℝ → ℝ
a M0 M1 M2 : ℝ
hf' : DifferentiableOn ℝ f (Set.Ici a)
hf'' : DifferentiableOn ℝ (deriv f) (Set.Ici a)
hM0 : M0 = sSup {x | ∃ x_1 ∈ Set.Ici a, |f x_1| = x}
hM1 : M1 = sSup {x | ∃ x_1 ∈ Set.Ici a, |deriv f x_1| = x}
hM2 : M2 = sSup {x | ∃ x_1 ∈ Set.Ici a, |deriv (deriv f) x_1| = x}
⊢ M1 ^ 2 ≤ 4 * M0 * M2


/-- Show that a group of order 5 must be abelian.-/

def exercise_2_1_21 (G : Type*) [Group G] [Fintype G]
  (hG : card G = 5) :
  CommGroup G :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
hG : card G = 5
⊢ CommGroup G

import Mathlib

open Fintype Set Real Ideal Polynomial
open scoped BigOperators


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

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

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
⊢ ∃ m, ∀ (a : G), a ^ m = 1


/-- 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.-/

def 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) :
  CommGroup G :=

G : Type u_1
inst✝ : Group G
h : ∀ (a b : G), (a * b) ^ 3 = a ^ 3 * b ^ 3 ∧ (a * b) ^ 5 = a ^ 5 * b ^ 5
⊢ CommGroup G


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

theorem exercise_2_3_17 {G : Type*} [Mul G] [Group G] (a x : G) :
  centralizer {x⁻¹*a*x} =
  (λ g : G => x⁻¹*g*x) '' (centralizer {a}) :=

G : Type u_1
inst✝¹ : Mul G
inst✝ : Group G
a x : G
⊢ {x⁻¹ * a * x}.centralizer = (fun g => x⁻¹ * g * x) '' {a}.centralizer


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

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

a n : ℕ
h : a > 1
⊢ n ∣ (a ^ n - 1).totient


/-- 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.-/

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):
  Subgroup.Characteristic H :=

G : Type u_1
inst✝³ : Group G
inst✝² : Fintype G
p m : ℕ
hp : p.Prime
hp1 : ¬p ∣ m
hG : card G = p * m
H : Subgroup G
inst✝¹ : Fintype ↥H
inst✝ : H.Normal
hH : card ↥H = p
⊢ H.Characteristic


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

def exercise_2_5_37 (G : Type*) [Group G] [Fintype G]
  (hG : card G = 6) (hG' : IsEmpty (CommGroup G)) :
  G ≃* Equiv.Perm (Fin 3) :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
hG : card G = 6
hG' : IsEmpty (CommGroup G)
⊢ G ≃* Equiv.Perm (Fin 3)


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

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 :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
p : ℕ
hp : p.Prime
hG : card G = p ^ 2
⊢ ∃ N Fin, card ↥N = p ∧ N.Normal


/-- 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$.-/

theorem exercise_2_6_15 {G : Type*} [CommGroup G] {m n : ℕ}
  (hm : ∃ (g : G), orderOf g = m)
  (hn : ∃ (g : G), orderOf g = n)
  (hmn : m.Coprime n) :
  ∃ (g : G), orderOf g = m * n :=

G : Type u_1
inst✝ : CommGroup G
m n : ℕ
hm : ∃ g, orderOf g = m
hn : ∃ g, orderOf g = n
hmn : m.Coprime n
⊢ ∃ g, orderOf g = m * n


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

def exercise_2_8_12 {G H : Type*} [Fintype G] [Fintype H]
  [Group G] [Group H] (hG : card G = 21) (hH : card H = 21)
  (hG1 : IsEmpty (CommGroup G)) (hH1 : IsEmpty (CommGroup H)) :
  G ≃* H :=

G : Type u_1
H : Type u_2
inst✝³ : Fintype G
inst✝² : Fintype H
inst✝¹ : Group G
inst✝ : Group H
hG : card G = 21
hH : card H = 21
hG1 : IsEmpty (CommGroup G)
hH1 : IsEmpty (CommGroup H)
⊢ G ≃* 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.-/

theorem exercise_2_9_2 {G H : Type*} [Fintype G] [Fintype H] [Group G]
  [Group H] (hG : IsCyclic G) (hH : IsCyclic H) :
  IsCyclic (G × H) ↔ (card G).Coprime (card H) :=

G : Type u_1
H : Type u_2
inst✝³ : Fintype G
inst✝² : Fintype H
inst✝¹ : Group G
inst✝ : Group H
hG : IsCyclic G
hH : IsCyclic H
⊢ IsCyclic (G × H) ↔ (card G).Coprime (card H)


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

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 :=

G : Type u_1
inst✝ : Group G
p : ℕ
hp : p.Prime
P : Sylow p G
hP : (↑P).Normal
⊢ ∀ (Q : Sylow p G), P = Q


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

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 :=

p n : ℕ
G : Type u_1
inst✝² : Fintype G
inst✝¹ : Group G
hp : p.Prime
hG : card G = p ^ n
K : Subgroup G
inst✝ : Fintype ↥K
hK : card ↥K = p ^ (n - 1)
⊢ K.Normal


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

theorem exercise_4_1_19 : Infinite {x : Quaternion ℝ | x^2 = -1} :=


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

def exercise_4_2_5 {R : Type*} [Ring R]
  (h : ∀ x : R, x ^ 3 = x) : CommRing R :=

R : Type u_1
inst✝ : Ring R
h : ∀ (x : R), x ^ 3 = x
⊢ CommRing R


/-- 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$.-/

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 :=

p : ℕ
hp : p.Prime
hp1 : Odd p
⊢ ∃ a b, ↑a / ↑b = ↑(∑ i ∈ Finset.range p, 1 / (i + 1)) → ↑p ∣ a


/-- 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$.-/

theorem exercise_4_3_25 (I : Ideal (Matrix (Fin 2) (Fin 2) ℝ)) :
  I = ⊥ ∨ I = ⊤ :=

I : Ideal (Matrix (Fin 2) (Fin 2) ℝ)
⊢ I = ⊥ ∨ I = ⊤


/-- 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.-/

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) ⧸ span ({q} : Set (Polynomial $ ZMod p)),
  @card (Polynomial (ZMod p) ⧸ span {q}) is_fin = p ^ n ∧
  IsField (Polynomial $ ZMod p) :=

p n : ℕ
hp : p.Prime
q : (ZMod p)[X]
hq : Irreducible q
hn : q.degree = ↑n
⊢ ∃ is_fin, card ((ZMod p)[X] ⧸ span {q}) = p ^ n ∧ IsField (ZMod p)[X]


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

theorem exercise_4_5_25 {p : ℕ} (hp : Nat.Prime p) :
  Irreducible (∑ i : Finset.range p, X ^ p : Polynomial ℚ) :=

p : ℕ
hp : p.Prime
⊢ Irreducible (∑ i : { x // x ∈ Finset.range p }, X ^ p)


/-- 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]$.-/

theorem exercise_4_6_3 :
  Infinite {a : ℤ | Irreducible (X^7 + 15*X^2 - 30*X + (a : Polynomial ℚ) : Polynomial ℚ)} :=

⊢ Infinite ↑{a | Irreducible (X ^ 7 + 15 * X ^ 2 - 30 * X + ↑a)}


/-- 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$.-/

theorem exercise_5_2_20 {F V ι: Type*} [Infinite F] [Field F]
  [AddCommGroup V] [Module F V] {u : ι → Submodule F V}
  (hu : ∀ i : ι, u i ≠ ⊤) :
  (⋃ i : ι, (u i : Set V)) ≠ ⊤ :=

F : Type u_1
V : Type u_2
ι : Type u_3
inst✝³ : Infinite F
inst✝² : Field F
inst✝¹ : AddCommGroup V
inst✝ : Module F V
u : ι → Submodule F V
hu : ∀ (i : ι), u i ≠ ⊤
⊢ ⋃ i, ↑(u i) ≠ ⊤


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

theorem exercise_5_3_10 : IsAlgebraic ℚ (cos (Real.pi / 180)) :=


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

theorem exercise_5_5_2 : Irreducible (X^3 - 3*X - 1 : Polynomial ℚ) :=


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

theorem exercise_2_12a (f : ℕ → ℕ) (p : ℕ → ℝ) (a : ℝ)
  (hf : Injective f) (hp : Tendsto p atTop (𝓝 a)) :
  Tendsto (λ n => p (f n)) atTop (𝓝 a) :=

f : ℕ → ℕ
p : ℕ → ℝ
a : ℝ
hf : Injective f
hp : Tendsto p atTop (𝓝 a)
⊢ Tendsto (fun n => p (f n)) atTop (𝓝 a)

import Mathlib

open Filter Real Function
open scoped Topology


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

theorem exercise_2_29 (M : Type*) [MetricSpace M]
  (O C : Set (Set M))
  (hO : O = {s | IsOpen s})
  (hC : C = {s | IsClosed s}) :
  ∃ f : O → C, Bijective f :=

M : Type u_1
inst✝ : MetricSpace M
O C : Set (Set M)
hO : O = {s | IsOpen s}
hC : C = {s | IsClosed s}
⊢ ∃ f, Bijective f


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

theorem exercise_2_41 (m : ℕ) {X : Type*} [NormedSpace ℝ ((Fin m) → ℝ)] :
  IsCompact (Metric.closedBall 0 1) :=

m : ℕ
X : Type u_1
inst✝ : NormedSpace ℝ (Fin m → ℝ)
⊢ IsCompact (Metric.closedBall 0 1)


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

theorem exercise_2_57 {X : Type*} [TopologicalSpace X]
  : ∃ (S : Set X), IsConnected S ∧ ¬ IsConnected (interior S) :=

X : Type u_1
inst✝ : TopologicalSpace X
⊢ ∃ S, IsConnected S ∧ ¬IsConnected (interior S)


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

theorem exercise_2_126 {E : Set ℝ}
  (hE : ¬ Set.Countable E) : ∃ (p : ℝ), ClusterPt p (𝓟 E) :=

E : Set ℝ
hE : ¬E.Countable
⊢ ∃ p, ClusterPt p (𝓟 E)


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

theorem exercise_3_4 (n : ℕ) :
  Tendsto (λ n => (sqrt (n + 1) - sqrt n)) atTop (𝓝 0) :=

n : ℕ
⊢ Tendsto (fun n => √(n + 1) - √n) atTop (𝓝 0)


/-- Prove that $\sum 1/k(\log(k))^p$ diverges when $p \leq 1$.-/

theorem exercise_3_63b (p : ℝ) (f : ℕ → ℝ) (hp : p ≤ 1)
  (h : f = λ (k : ℕ) => (1 : ℝ) / (k * (log k) ^ p)) :
  ¬ ∃ l, Tendsto f atTop (𝓝 l) :=

p : ℝ
f : ℕ → ℝ
hp : p ≤ 1
h : f = fun k => 1 / (↑k * (↑k).log ^ p)
⊢ ¬∃ l, Tendsto f atTop (𝓝 l)


/-- 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.-/

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 :=

G : Type
inst✝ : Group G
a b : G
h : a * b = b * a
⊢ ∀ (x y : ↥(Subgroup.closure {x | x = a ∨ x = b})), x * y = y * x

import Mathlib

open Function Fintype Subgroup Ideal Polynomial Submodule Zsqrtd
open scoped BigOperators


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

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

G : Type u_1
inst✝ : Group G
x : G
hx : orderOf x = 2
hx1 : ∀ (y : G), orderOf y = 2 → y = x
⊢ x ∈ center G


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

theorem exercise_2_11_3 {G : Type*} [Group G] [Fintype G](hG : Even (card G)) :
  ∃ x : G, orderOf x = 2 :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
hG : Even (card G)
⊢ ∃ x, orderOf x = 2


/-- 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.-/

theorem exercise_3_5_6 {K V : Type*} [Field K] [AddCommGroup V]
  [Module K V] {S : Set V} (hS : Set.Countable S)
  (hS1 : span K S = ⊤) {ι : Type*} (R : ι → V)
  (hR : LinearIndependent K R) : Countable ι :=

K : Type u_1
V : Type u_2
inst✝² : Field K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
S : Set V
hS : S.Countable
hS1 : Submodule.span K S = ⊤
ι : Type u_3
R : ι → V
hR : LinearIndependent K R
⊢ Countable ι


/-- 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$.-/

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

G : Type u_1
inst✝ : Group G
hG : IsCyclic (G ⧸ center G)
⊢ center G = ⊤


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

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) :
  IsSimpleGroup G → false :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
p q : ℕ
hp : Prime p
hq : Prime q
hG : card G = p ^ 2 * q
⊢ IsSimpleGroup G → false = true


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

theorem exercise_6_8_1 {G : Type*} [Group G]
  (a b : G) : closure ({a, b} : Set G) = Subgroup.closure {b*a*b^2, b*a*b^3} :=

G : Type u_1
inst✝ : Group G
a b : G
⊢ Subgroup.closure {a, b} = Subgroup.closure {b * a * b ^ 2, b * a * b ^ 3}


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

theorem exercise_10_2_4 :
  span ({2} : Set $ Polynomial ℤ) ⊓ (span {X}) =
  span ({2 * X} : Set $ Polynomial ℤ) :=

⊢ Ideal.span {2} ⊓ Ideal.span {X} = Ideal.span {2 * 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.-/

theorem exercise_10_4_6 {R : Type*} [CommRing R]
  [NoZeroDivisors R] (I J : Ideal R) (x : ↑(I ⊓ J)) :
  IsNilpotent ((Ideal.Quotient.mk (I*J)) x) :=

R : Type u_1
inst✝¹ : CommRing R
inst✝ : NoZeroDivisors R
I J : Ideal R
x : ↥(I ⊓ J)
⊢ IsNilpotent ((Ideal.Quotient.mk (I * J)) ↑x)


/-- 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$.-/

theorem exercise_10_7_10 {R : Type*} [Ring R]
  (M : Ideal R) (hM : ∀ (x : R), x ∉ M → IsUnit x)
  (hProper : ∃ x : R, x ∉ M) :
  IsMaximal M ∧ ∀ (N : Ideal R), IsMaximal N → N = M :=

R : Type u_1
inst✝ : Ring R
M : Ideal R
hM : ∀ x ∉ M, IsUnit x
hProper : ∃ x, x ∉ M
⊢ M.IsMaximal ∧ ∀ (N : Ideal R), N.IsMaximal → N = M


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

theorem exercise_11_4_1b {F : Type*} [Field F] [Fintype F] (hF : card F = 2) :
  Irreducible (12 + 6 * X + X ^ 3 : Polynomial F) :=

F : Type u_1
inst✝¹ : Field F
inst✝ : Fintype F
hF : card F = 2
⊢ Irreducible (12 + 6 * X + X ^ 3)


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

theorem exercise_11_4_6b {F : Type*} [Field F] [Fintype F] (hF : card F = 31) :
  Irreducible (X ^ 3 - 9 : Polynomial F) :=

F : Type u_1
inst✝¹ : Field F
inst✝ : Fintype F
hF : card F = 31
⊢ Irreducible (X ^ 3 - 9)


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

theorem exercise_11_4_8 (p : ℕ) (hp : Prime p) (n : ℕ) :
  -- p ∈ ℕ can be written as p ∈ ℚ[X]
  Irreducible (X ^ n - (p : Polynomial ℚ) : Polynomial ℚ) :=

p : ℕ
hp : Prime p
n : ℕ
⊢ Irreducible (X ^ n - ↑p)


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

p : ℕ
hp : p.Prime
h : ∃ r, p = 2 ^ r + 1
⊢ ∃ k, p = 2 ^ 2 ^ k + 1


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

theorem exercise_1_3 {F V : Type*} [AddCommGroup V] [Field F]
  [Module F V] {v : V} : -(-v) = v :=

F : Type u_1
V : Type u_2
inst✝² : AddCommGroup V
inst✝¹ : Field F
inst✝ : Module F V
v : V
⊢ - -v = v

import Mathlib

open Fintype Complex Polynomial LinearMap FiniteDimensional Module Module.End
open scoped BigOperators


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

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

⊢ ∃ U, U ≠ ∅ ∧ (∀ (u v : ℝ × ℝ), u ∈ U ∧ v ∈ U → u + v ∈ U) ∧ (∀ u ∈ U, -u ∈ U) ∧ ∀ (U' : Submodule ℝ (ℝ × ℝ)), U ≠ ↑U'


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

theorem exercise_1_8 {F V : Type*} [AddCommGroup V] [Field F]
  [Module F V] {ι : Type*} (u : ι → Submodule F V) :
  ∃ U : Submodule F V, (⋂ (i : ι), (u i).carrier) = ↑U :=

F : Type u_1
V : Type u_2
inst✝² : AddCommGroup V
inst✝¹ : Field F
inst✝ : Module F V
ι : Type u_3
u : ι → Submodule F V
⊢ ∃ U, ⋂ i, (u i).carrier = ↑U


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

theorem exercise_3_1 {F V : Type*}
  [AddCommGroup V] [Field F] [Module F V] [FiniteDimensional F V]
  (T : V →ₗ[F] V) (hT : finrank F V = 1) :
  ∃ c : F, ∀ v : V, T v = c • v :=

F : Type u_1
V : Type u_2
inst✝³ : AddCommGroup V
inst✝² : Field F
inst✝¹ : Module F V
inst✝ : FiniteDimensional F V
T : V →ₗ[F] V
hT : finrank F V = 1
⊢ ∃ c, ∀ (v : V), T v = c • v


/-- Suppose $p \in \mathcal{P}(\mathbf{C})$ has degree $m$. Prove that $p$ has $m$ distinct roots if and only if $p$ and its derivative $p^{\prime}$ have no roots in common.-/

theorem exercise_4_4 (p : Polynomial ℂ) :
  p.degree = @card (rootSet p ℂ) (rootSetFintype p ℂ) ↔
  Disjoint
  (@card (rootSet (derivative p) ℂ) (rootSetFintype (derivative p) ℂ))
  (@card (rootSet p ℂ) (rootSetFintype p ℂ)) :=

p : ℂ[X]
⊢ p.degree = ↑(card ↑(p.rootSet ℂ)) ↔ Disjoint (card ↑((derivative p).rootSet ℂ)) (card ↑(p.rootSet ℂ))


/-- Suppose that $S, T \in \mathcal{L}(V)$ are such that $S T=T S$. Prove that $\operatorname{null} (T-\lambda I)$ is invariant under $S$ for every $\lambda \in \mathbf{F}$.-/

theorem exercise_5_4 {F V : Type*} [AddCommGroup V] [Field F]
  [Module F V] (S T : V →ₗ[F] V) (hST : S ∘ T = T ∘ S) (c : F):
  Submodule.map S (ker (T - c • LinearMap.id)) = ker (T - c • LinearMap.id) :=

F : Type u_1
V : Type u_2
inst✝² : AddCommGroup V
inst✝¹ : Field F
inst✝ : Module F V
S T : V →ₗ[F] V
hST : ⇑S ∘ ⇑T = ⇑T ∘ ⇑S
c : F
⊢ Submodule.map S (ker (T - c • LinearMap.id)) = ker (T - c • LinearMap.id)


/-- Suppose $T \in \mathcal{L}(V)$ is such that every vector in $V$ is an eigenvector of $T$. Prove that $T$ is a scalar multiple of the identity operator.-/

theorem exercise_5_12 {F V : Type*} [AddCommGroup V] [Field F]
  [Module F V] {S : End F V}
  (hS : ∀ v : V, ∃ c : F, v ∈ eigenspace S c) :
  ∃ c : F, S = c • LinearMap.id :=

F : Type u_1
V : Type u_2
inst✝² : AddCommGroup V
inst✝¹ : Field F
inst✝ : Module F V
S : End F V
hS : ∀ (v : V), ∃ c, v ∈ S.eigenspace c
⊢ ∃ c, S = c • LinearMap.id


/-- Suppose that $T \in \mathcal{L}(V)$ has $\operatorname{dim} V$ distinct eigenvalues and that $S \in \mathcal{L}(V)$ has the same eigenvectors as $T$ (not necessarily with the same eigenvalues). Prove that $S T=T S$.-/

theorem exercise_5_20 {F V : Type*} [AddCommGroup V] [Field F]
  [Module F V] [FiniteDimensional F V] {S T : End F V}
  (h1 : card (T.Eigenvalues) = finrank F V)
  (h2 : ∀ v : V, ∃ c : F, v ∈ eigenspace S c ↔ ∃ c : F, v ∈ eigenspace T c) :
  S * T = T * S :=

F : Type u_1
V : Type u_2
inst✝³ : AddCommGroup V
inst✝² : Field F
inst✝¹ : Module F V
inst✝ : FiniteDimensional F V
S T : End F V
h1 : card T.Eigenvalues = finrank F V
h2 : ∀ (v : V), ∃ c, v ∈ S.eigenspace c ↔ ∃ c, v ∈ T.eigenspace c
⊢ S * T = T * S


/-- Suppose $u, v \in V$. Prove that $\langle u, v\rangle=0$ if and only if $\|u\| \leq\|u+a v\|$ for all $a \in \mathbf{F}$.-/

theorem exercise_6_2 {V : Type*} [NormedAddCommGroup V] [Module ℂ V]
[InnerProductSpace ℂ V] (u v : V) :
  ⟪u, v⟫_ℂ = 0 ↔ ∀ (a : ℂ), ‖u‖  ≤ ‖u + a • v‖ :=

V : Type u_1
inst✝² : NormedAddCommGroup V
inst✝¹ : Module ℂ V
inst✝ : InnerProductSpace ℂ V
u v : V
⊢ ⟪u, v⟫_ℂ = 0 ↔ ∀ (a : ℂ), ‖u‖ ≤ ‖u + a • v‖


/-- Prove that if $V$ is a complex inner-product space, then $\langle u, v\rangle=\frac{\|u+v\|^{2}-\|u-v\|^{2}+\|u+i v\|^{2} i-\|u-i v\|^{2} i}{4}$ for all $u, v \in V$.-/

theorem exercise_6_7 {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] (u v : V) :
  ⟪u, v⟫_ℂ = (‖u + v‖^2 - ‖u - v‖^2 + I*‖u + I•v‖^2 - I*‖u-I•v‖^2) / 4 :=

V : Type u_1
inst✝¹ : NormedAddCommGroup V
inst✝ : InnerProductSpace ℂ V
u v : V
⊢ ⟪u, v⟫_ℂ = (↑‖u + v‖ ^ 2 - ↑‖u - v‖ ^ 2 + I * ↑‖u + I • v‖ ^ 2 - I * ↑‖u - I • v‖ ^ 2) / 4


/-- Suppose $U$ is a subspace of $V$. Prove that $U^{\perp}=\{0\}$ if and only if $U=V$-/

theorem exercise_6_16 {K V : Type*} [RCLike K] [NormedAddCommGroup V] [InnerProductSpace K V]
  {U : Submodule K V} :
  U.orthogonal = ⊥  ↔ U = ⊤ :=

K : Type u_1
V : Type u_2
inst✝² : RCLike K
inst✝¹ : NormedAddCommGroup V
inst✝ : InnerProductSpace K V
U : Submodule K V
⊢ Uᗮ = ⊥ ↔ U = ⊤


/-- Prove that if $T \in \mathcal{L}(V)$ is normal, then $\operatorname{range} T=\operatorname{range} T^{*}.$-/

theorem exercise_7_6 {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V]
  [FiniteDimensional ℂ V] (T : End ℂ V)
  (hT : T * adjoint T = adjoint T * T) :
  range T = range (adjoint T) :=

V : Type u_1
inst✝² : NormedAddCommGroup V
inst✝¹ : InnerProductSpace ℂ V
inst✝ : FiniteDimensional ℂ V
T : End ℂ V
hT : T * adjoint T = adjoint T * T
⊢ range T = range (adjoint T)


/-- Suppose $V$ is a complex inner-product space and $T \in \mathcal{L}(V)$ is a normal operator such that $T^{9}=T^{8}$. Prove that $T$ is self-adjoint and $T^{2}=T$.-/

theorem exercise_7_10 {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V]
  [FiniteDimensional ℂ V] (T : End ℂ V)
  (hT : T * adjoint T = adjoint T * T) (hT1 : T^9 = T^8) :
  IsSelfAdjoint T ∧ T^2 = T :=

V : Type u_1
inst✝² : NormedAddCommGroup V
inst✝¹ : InnerProductSpace ℂ V
inst✝ : FiniteDimensional ℂ V
T : End ℂ V
hT : T * adjoint T = adjoint T * T
hT1 : T ^ 9 = T ^ 8
⊢ IsSelfAdjoint T ∧ T ^ 2 = T


/-- Suppose $T \in \mathcal{L}(V)$ is self-adjoint, $\lambda \in \mathbf{F}$, and $\epsilon>0$. Prove that if there exists $v \in V$ such that $\|v\|=1$ and $\|T v-\lambda v\|<\epsilon,$ then $T$ has an eigenvalue $\lambda^{\prime}$ such that $\left|\lambda-\lambda^{\prime}\right|<\epsilon$.-/

theorem exercise_7_14 {𝕜 V : Type*} [RCLike 𝕜] [NormedAddCommGroup V]
  [InnerProductSpace 𝕜 V] [FiniteDimensional 𝕜 V]
  {T : Module.End 𝕜 V} (hT : IsSelfAdjoint T)
  {l : 𝕜} {ε : ℝ} (he : ε > 0) : ∃ v : V, ‖v‖= 1 ∧ (‖T v - l • v‖ < ε →
  (∃ l' : T.Eigenvalues, ‖l - l'‖ < ε)) :=

𝕜 : Type u_1
V : Type u_2
inst✝³ : RCLike 𝕜
inst✝² : NormedAddCommGroup V
inst✝¹ : InnerProductSpace 𝕜 V
inst✝ : FiniteDimensional 𝕜 V
T : End 𝕜 V
hT : IsSelfAdjoint T
l : 𝕜
ε : ℝ
he : ε > 0
⊢ ∃ v, ‖v‖ = 1 ∧ (‖T v - l • v‖ < ε → ∃ l', ‖l - ↑T l'‖ < ε)


/-- Prove that the addition of residue classes $\mathbb{Z}/n\mathbb{Z}$ is associative.-/

theorem exercise_1_1_3 (n : ℤ) :
  ∀ (a b c : ℤ), (a+b)+c ≡ a+(b+c) [ZMOD n] :=

n : ℤ
⊢ ∀ (a b c : ℤ), a + b + c ≡ a + (b + c) [ZMOD n]

import Mathlib

open Fintype Subgroup Set Polynomial Ideal
open scoped BigOperators


/-- Prove that for all $n>1$ that $\mathbb{Z}/n\mathbb{Z}$ is not a group under multiplication of residue classes.-/

theorem exercise_1_1_5 (n : ℕ) (hn : 1 < n) :
  IsEmpty (Group (ZMod n)) :=

n : ℕ
hn : 1 < n
⊢ IsEmpty (Group (ZMod n))


/-- Let $x$ be an element of $G$. Prove that $x^2=1$ if and only if $|x|$ is either $1$ or $2$.-/

theorem exercise_1_1_16 {G : Type*} [Group G]
  (x : G) (hx : x ^ 2 = 1) :
  orderOf x = 1 ∨ orderOf x = 2 :=

G : Type u_1
inst✝ : Group G
x : G
hx : x ^ 2 = 1
⊢ orderOf x = 1 ∨ orderOf x = 2


/-- Let $x$ and $y$ be elements of $G$. Prove that $xy=yx$ if and only if $y^{-1}xy=x$ if and only if $x^{-1}y^{-1}xy=1$.-/

theorem exercise_1_1_18 {G : Type*} [Group G]
  (x y : G) : (x * y = y * x ↔ y⁻¹ * x * y = x) ↔ (x⁻¹ * y⁻¹ * x * y = 1) :=

G : Type u_1
inst✝ : Group G
x y : G
⊢ (x * y = y * x ↔ y⁻¹ * x * y = x) ↔ x⁻¹ * y⁻¹ * x * y = 1


/-- If $x$ and $g$ are elements of the group $G$, prove that $|x|=\left|g^{-1} x g\right|$.-/

theorem exercise_1_1_22a {G : Type*} [Group G] (x g : G) :
  orderOf x = orderOf (g⁻¹ * x * g) :=

G : Type u_1
inst✝ : Group G
x g : G
⊢ orderOf x = orderOf (g⁻¹ * x * g)


/-- Prove that if $x^{2}=1$ for all $x \in G$ then $G$ is abelian.-/

theorem exercise_1_1_25 {G : Type*} [Group G]
  (h : ∀ x : G, x ^ 2 = 1) : ∀ a b : G, a*b = b*a :=

G : Type u_1
inst✝ : Group G
h : ∀ (x : G), x ^ 2 = 1
⊢ ∀ (a b : G), a * b = b * a


/-- If $x$ is an element of infinite order in $G$, prove that the elements $x^{n}, n \in \mathbb{Z}$ are all distinct.-/

theorem exercise_1_1_34 {G : Type*} [Group G] {x : G}
  (hx_inf : orderOf x = 0) (n m : ℤ) :
  x ^ n ≠ x ^ m :=

G : Type u_1
inst✝ : Group G
x : G
hx_inf : orderOf x = 0
n m : ℤ
⊢ x ^ n ≠ x ^ m


/-- Prove that the multiplicative groups $\mathbb{R}-\{0\}$ and $\mathbb{C}-\{0\}$ are not isomorphic.-/

theorem exercise_1_6_4 :
  IsEmpty (Multiplicative ℝ ≃* Multiplicative ℂ) :=

⊢ IsEmpty (Multiplicative ℝ ≃* Multiplicative ℂ)


/-- Let $G$ be any group. Prove that the map from $G$ to itself defined by $g \mapsto g^{-1}$ is a homomorphism if and only if $G$ is abelian.-/

theorem exercise_1_6_17 {G : Type*} [Group G] (f : G → G)
  (hf : f = λ g => g⁻¹) :
  ∀ x y : G, f x * f y = f (x*y) ↔ ∀ x y : G, x*y = y*x :=

G : Type u_1
inst✝ : Group G
f : G → G
hf : f = fun g => g⁻¹
⊢ ∀ (x y : G), f x * f y = f (x * y) ↔ ∀ (x y : G), x * y = y * x


/-- Prove that $G$ cannot have a subgroup $H$ with $|H|=n-1$, where $n=|G|>2$.-/

theorem exercise_2_1_5 {G : Type*} [Group G] [Fintype G]
  (hG : card G > 2) (H : Subgroup G) [Fintype H] :
  card H ≠ card G - 1 :=

G : Type u_1
inst✝² : Group G
inst✝¹ : Fintype G
hG : card G > 2
H : Subgroup G
inst✝ : Fintype ↥H
⊢ card ↥H ≠ card G - 1


/-- Prove that if $H$ is a subgroup of $G$ then $H$ is generated by the set $H-\{1\}$.-/

theorem exercise_2_4_4 {G : Type*} [Group G] (H : Subgroup G) :
  closure ((H : Set G) \ {1}) = ⊤ :=

G : Type u_1
inst✝ : Group G
H : Subgroup G
⊢ Subgroup.closure (↑H \ {1}) = ⊤


/-- Show that the subgroup of all rotations in a dihedral group is a maximal subgroup.-/

theorem exercise_2_4_16b {n : ℕ} {hn : n ≠ 0}
  {R : Subgroup (DihedralGroup n)}
  (hR : R = Subgroup.closure {DihedralGroup.r 1}) :
  R ≠ ⊤ ∧
  ∀ K : Subgroup (DihedralGroup n), R ≤ K → K = R ∨ K = ⊤ :=

n : ℕ
hn : n ≠ 0
R : Subgroup (DihedralGroup n)
hR : R = Subgroup.closure {DihedralGroup.r 1}
⊢ R ≠ ⊤ ∧ ∀ (K : Subgroup (DihedralGroup n)), R ≤ K → K = R ∨ K = ⊤


/-- Let $A$ be an abelian group and let $B$ be a subgroup of $A$. Prove that $A / B$ is abelian.-/

theorem exercise_3_1_3a {A : Type*} [CommGroup A] (B : Subgroup A) :
  ∀ a b : A ⧸ B, a*b = b*a :=

A : Type u_1
inst✝ : CommGroup A
B : Subgroup A
⊢ ∀ (a b : A ⧸ B), a * b = b * a


/-- Prove that the intersection of an arbitrary nonempty collection of normal subgroups of a group is a normal subgroup (do not assume the collection is countable).-/

theorem exercise_3_1_22b {G : Type*} [Group G] (I : Type*)
  (H : I → Subgroup G) (hH : ∀ i : I, Normal (H i)) :
  Normal (⨅ (i : I), H i) :=

G : Type u_1
inst✝ : Group G
I : Type u_2
H : I → Subgroup G
hH : ∀ (i : I), (H i).Normal
⊢ (⨅ i, H i).Normal


/-- Let $H \leq K \leq G$. Prove that $|G: H|=|G: K| \cdot|K: H|$ (do not assume $G$ is finite).-/

theorem exercise_3_2_11 {G : Type*} [Group G] {H K : Subgroup G}
  (hHK : H ≤ K) :
  H.index = K.index * H.relindex K :=

G : Type u_1
inst✝ : Group G
H K : Subgroup G
hHK : H ≤ K
⊢ H.index = K.index * H.relindex K


/-- Prove that $\mathbb{Q}$ has no proper subgroups of finite index.-/

theorem exercise_3_2_21a (H : AddSubgroup ℚ) (hH : H ≠ ⊤) : H.index = 0 :=

H : AddSubgroup ℚ
hH : H ≠ ⊤
⊢ H.index = 0


/-- Prove that if $G$ is an abelian simple group then $G \cong Z_{p}$ for some prime $p$ (do not assume $G$ is a finite group).-/

theorem exercise_3_4_1 (G : Type*) [CommGroup G] [IsSimpleGroup G] :
    IsCyclic G ∧ ∃ G_fin : Fintype G, Nat.Prime (@card G G_fin) :=

G : Type u_1
inst✝¹ : CommGroup G
inst✝ : IsSimpleGroup G
⊢ IsCyclic G ∧ ∃ G_fin, (card G).Prime


/-- Prove that subgroups of a solvable group are solvable.-/

theorem exercise_3_4_5a {G : Type*} [Group G]
  (H : Subgroup G) [IsSolvable G] : IsSolvable H :=

G : Type u_1
inst✝¹ : Group G
H : Subgroup G
inst✝ : IsSolvable G
⊢ IsSolvable ↥H


/-- Prove that if $H$ is a nontrivial normal subgroup of the solvable group $G$ then there is a nontrivial subgroup $A$ of $H$ with $A \unlhd G$ and $A$ abelian.-/

theorem exercise_3_4_11 {G : Type*} [Group G] [IsSolvable G]
  {H : Subgroup G} (hH : H ≠ ⊥) [H.Normal] :
  ∃ A ≤ H, A.Normal ∧ ∀ a b : A, a*b = b*a :=

G : Type u_1
inst✝² : Group G
inst✝¹ : IsSolvable G
H : Subgroup G
hH : H ≠ ⊥
inst✝ : H.Normal
⊢ ∃ A ≤ H, A.Normal ∧ ∀ (a b : ↥A), a * b = b * a


/-- Let $G$ be a transitive permutation group on the finite set $A$ with $|A|>1$. Show that there is some $\sigma \in G$ such that $\sigma(a) \neq a$ for all $a \in A$.-/

theorem exercise_4_3_26 {α : Type*} [Fintype α] (ha : card α > 1)
  (h_tran : ∀ a b: α, ∃ σ : Equiv.Perm α, σ a = b) :
  ∃ σ : Equiv.Perm α, ∀ a : α, σ a ≠ a :=

α : Type u_1
inst✝ : Fintype α
ha : card α > 1
h_tran : ∀ (a b : α), ∃ σ, σ a = b
⊢ ∃ σ, ∀ (a : α), σ a ≠ a


/-- Let $G$ be a finite group of composite order $n$ with the property that $G$ has a subgroup of order $k$ for each positive integer $k$ dividing $n$. Prove that $G$ is not simple.-/

theorem exercise_4_2_14 {G : Type*} [Fintype G] [Group G]
  (hG : ¬ (card G).Prime) (hG1 : ∀ k : ℕ, k ∣ card G →
  ∃ (H : Subgroup G) (fH : Fintype H), @card H fH = k) :
  ¬ IsSimpleGroup G :=

G : Type u_1
inst✝¹ : Fintype G
inst✝ : Group G
hG : ¬(card G).Prime
hG1 : ∀ (k : ℕ), k ∣ card G → ∃ H fH, card ↥H = k
⊢ ¬IsSimpleGroup G


/-- Prove that characteristic subgroups are normal.-/

theorem exercise_4_4_6a {G : Type*} [Group G] (H : Subgroup G)
  [Characteristic H] : Normal H :=

G : Type u_1
inst✝¹ : Group G
H : Subgroup G
inst✝ : H.Characteristic
⊢ H.Normal


/-- If $H$ is the unique subgroup of a given order in a group $G$ prove $H$ is characteristic in $G$.-/

theorem exercise_4_4_7 {G : Type*} [Group G] {H : Subgroup G} [Fintype H]
  (hH : ∀ (K : Subgroup G) (fK : Fintype K), card H = @card K fK → H = K) :
  H.Characteristic :=

G : Type u_1
inst✝¹ : Group G
H : Subgroup G
inst✝ : Fintype ↥H
hH : ∀ (K : Subgroup G) (fK : Fintype ↥K), card ↥H = card ↥K → H = K
⊢ H.Characteristic


/-- Prove that if $P \in \operatorname{Syl}_{p}(G)$ and $H$ is a subgroup of $G$ containing $P$ then $P \in \operatorname{Syl}_{p}(H)$.-/

theorem exercise_4_5_1a {p : ℕ} {G : Type*} [Group G]
  {P : Subgroup G} (hP : IsPGroup p P) (H : Subgroup G)
  (hH : P ≤ H) : IsPGroup p H :=

p : ℕ
G : Type u_1
inst✝ : Group G
P : Subgroup G
hP : IsPGroup p ↥P
H : Subgroup G
hH : P ≤ H
⊢ IsPGroup p ↥H


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

theorem exercise_4_5_14 {G : Type*} [Group G] [Fintype G]
  (hG : card G = 312) :
  ∃ (p : ℕ) (P : Sylow p G), P.Normal :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
hG : card G = 312
⊢ ∃ p P, (↑P).Normal


/-- Let $|G|=p q r$, where $p, q$ and $r$ are primes with $p<q<r$. Prove that $G$ has a normal Sylow subgroup for either $p, q$ or $r$.-/

theorem exercise_4_5_16 {p q r : ℕ} {G : Type*} [Group G]
  [Fintype G]  (hpqr : p < q ∧ q < r)
  (hpqr1 : p.Prime ∧ q.Prime ∧ r.Prime)(hG : card G = p*q*r) :
  Nonempty (Sylow p G) ∨ Nonempty (Sylow q G) ∨ Nonempty (Sylow r G) :=

p q r : ℕ
G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
hpqr : p < q ∧ q < r
hpqr1 : p.Prime ∧ q.Prime ∧ r.Prime
hG : card G = p * q * r
⊢ Nonempty (Sylow p G) ∨ Nonempty (Sylow q G) ∨ Nonempty (Sylow r G)


/-- Prove that a group of order 200 has a normal Sylow 5-subgroup.-/

theorem exercise_4_5_18 {G : Type*} [Fintype G] [Group G]
  (hG : card G = 200) :
  ∃ N : Sylow 5 G, N.Normal :=

G : Type u_1
inst✝¹ : Fintype G
inst✝ : Group G
hG : card G = 200
⊢ ∃ N, (↑N).Normal


/-- Prove that if $|G|=1365$ then $G$ is not simple.-/

theorem exercise_4_5_20 {G : Type*} [Fintype G] [Group G]
  (hG : card G = 1365) : ¬ IsSimpleGroup G :=

G : Type u_1
inst✝¹ : Fintype G
inst✝ : Group G
hG : card G = 1365
⊢ ¬IsSimpleGroup G


/-- Prove that if $|G|=132$ then $G$ is not simple.-/

theorem exercise_4_5_22 {G : Type*} [Fintype G] [Group G]
  (hG : card G = 132) : ¬ IsSimpleGroup G :=

G : Type u_1
inst✝¹ : Fintype G
inst✝ : Group G
hG : card G = 132
⊢ ¬IsSimpleGroup G


/-- Let $G$ be a group of order 105. Prove that if a Sylow 3-subgroup of $G$ is normal then $G$ is abelian.-/

def exercise_4_5_28 {G : Type*} [Group G] [Fintype G]
  (hG : card G = 105) (P : Sylow 3 G) [hP : P.Normal] :
  CommGroup G :=

G : Type u_1
inst✝¹ : Group G
inst✝ : Fintype G
hG : card G = 105
P : Sylow 3 G
hP : (↑P).Normal
⊢ CommGroup G


/-- Prove that a subgroup $H$ of $G$ is normal if and only if $[G, H] \leq H$.-/

theorem exercise_5_4_2 {G : Type*} [Group G] (H : Subgroup G) :
  H.Normal ↔ ⁅(⊤ : Subgroup G), H⁆ ≤ H :=

G : Type u_1
inst✝ : Group G
H : Subgroup G
⊢ H.Normal ↔ ⁅⊤, H⁆ ≤ H


/-- Prove that if $R$ is an integral domain and $x^{2}=1$ for some $x \in R$ then $x=\pm 1$.-/

theorem exercise_7_1_11 {R : Type*} [Ring R] [IsDomain R]
  {x : R} (hx : x^2 = 1) : x = 1 ∨ x = -1 :=

R : Type u_1
inst✝¹ : Ring R
inst✝ : IsDomain R
x : R
hx : x ^ 2 = 1
⊢ x = 1 ∨ x = -1


/-- A ring $R$ is called a Boolean ring if $a^{2}=a$ for all $a \in R$. Prove that every Boolean ring is commutative.-/

def exercise_7_1_15 {R : Type*} [Ring R] (hR : ∀ a : R, a^2 = a) :
  CommRing R :=

R : Type u_1
inst✝ : Ring R
hR : ∀ (a : R), a ^ 2 = a
⊢ CommRing R


/-- Let $G=\left\{g_{1}, \ldots, g_{n}\right\}$ be a finite group. Prove that the element $N=g_{1}+g_{2}+\ldots+g_{n}$ is in the center of the group ring $R G$.-/

theorem exercise_7_2_12 {R G : Type*} [Ring R] [Group G] [Fintype G] :
  ∑ g : G, MonoidAlgebra.of R G g ∈ center (MonoidAlgebra R G) :=

R : Type u_1
G : Type u_2
inst✝² : Ring R
inst✝¹ : Group G
inst✝ : Fintype G
⊢ ∑ g : G, (MonoidAlgebra.of R G) g ∈ Set.center (MonoidAlgebra R G)


/-- An ideal $N$ is called nilpotent if $N^{n}$ is the zero ideal for some $n \geq 1$. Prove that the ideal $p \mathbb{Z} / p^{m} \mathbb{Z}$ is a nilpotent ideal in the ring $\mathbb{Z} / p^{m} \mathbb{Z}$.-/

theorem exercise_7_3_37 {p m : ℕ} (hp : p.Prime) :
  IsNilpotent (span ({↑p} : Set $ ZMod $ p^m) : Ideal $ ZMod $ p^m) :=

p m : ℕ
hp : p.Prime
⊢ IsNilpotent (span {↑p})


/-- Let $N$ be a positive integer. Let $M$ be an integer relatively prime to $N$ and let $d$ be an integer relatively prime to $\varphi(N)$, where $\varphi$ denotes Euler's $\varphi$-function. Prove that if $M_{1} \equiv M^{d} \pmod N$ then $M \equiv M_{1}^{d^{\prime}} \pmod N$ where $d^{\prime}$ is the inverse of $d \bmod \varphi(N)$: $d d^{\prime} \equiv 1 \pmod {\varphi(N)}$.-/

theorem exercise_8_1_12 {N : ℕ} (hN : N > 0) {M M': ℤ} {d : ℕ}
  (hMN : M.gcd N = 1) (hMd : d.gcd N.totient = 1)
  (hM' : M' ≡ M^d [ZMOD N]) :
  ∃ d' : ℕ, d' * d ≡ 1 [ZMOD N.totient] ∧
  M ≡ M'^d' [ZMOD N] :=

N : ℕ
hN : N > 0
M M' : ℤ
d : ℕ
hMN : M.gcd ↑N = 1
hMd : d.gcd N.totient = 1
hM' : M' ≡ M ^ d [ZMOD ↑N]
⊢ ∃ d', ↑d' * ↑d ≡ 1 [ZMOD ↑N.totient] ∧ M ≡ M' ^ d' [ZMOD ↑N]


/-- Prove that if an integer is the sum of two rational squares, then it is the sum of two integer squares.-/

theorem exercise_8_3_4 {R : Type*} {n : ℤ} {r s : ℚ}
  (h : r^2 + s^2 = n) :
  ∃ a b : ℤ, a^2 + b^2 = n :=

R : Type u_1
n : ℤ
r s : ℚ
h : r ^ 2 + s ^ 2 = ↑n
⊢ ∃ a b, a ^ 2 + b ^ 2 = n


/-- Prove that the quotient ring $\mathbb{Z}[i] /(1+i)$ is a field of order 2.-/

theorem exercise_8_3_6a {R : Type} [Ring R]
  (hR : R = (GaussianInt ⧸ span ({⟨0, 1⟩} : Set GaussianInt))) :
  IsField R ∧ ∃ finR : Fintype R, @card R finR = 2 :=

R : Type
inst✝ : Ring R
hR : R = (GaussianInt ⧸ span {{ re := 0, im := 1 }})
⊢ IsField R ∧ ∃ finR, card R = 2


/-- Prove that $(x, y)$ is not a principal ideal in $\mathbb{Q}[x, y]$.-/

theorem exercise_9_1_6 : ¬ Submodule.IsPrincipal
  (span ({MvPolynomial.X 0, MvPolynomial.X 1} : Set (MvPolynomial (Fin 2) ℚ))) :=

⊢ ¬Submodule.IsPrincipal (span {MvPolynomial.X 0, MvPolynomial.X 1})


/-- Prove that if $f(x)$ and $g(x)$ are polynomials with rational coefficients whose product $f(x) g(x)$ has integer coefficients, then the product of any coefficient of $g(x)$ with any coefficient of $f(x)$ is an integer.-/

theorem exercise_9_3_2 {f g : Polynomial ℚ} (i j : ℕ)
  (hfg : ∀ n : ℕ, ∃ a : ℤ, (f*g).coeff = a) :
  ∃ a : ℤ, f.coeff i * g.coeff j = a :=

f g : ℚ[X]
i j : ℕ
hfg : ℕ → ∃ a, (f * g).coeff = ↑a
⊢ ∃ a, f.coeff i * g.coeff j = ↑a


/-- Prove that $x^6+30x^5-15x^3 + 6x-120$ is irreducible in $\mathbb{Z}[x]$.-/

theorem exercise_9_4_2b : Irreducible
  (X^6 + 30*X^5 - 15*X^3 + 6*X - 120 : Polynomial ℤ) :=


/-- Prove that $\frac{(x+2)^p-2^p}{x}$, where $p$ is an odd prime, is irreducible in $\mathbb{Z}[x]$.-/

theorem exercise_9_4_2d {p : ℕ} (hp : p.Prime ∧ p > 2)
  {f : Polynomial ℤ} (hf : f = (X + 2)^p):
  Irreducible (∑ n in (f.support \ {0}), (f.coeff n : Polynomial ℤ) * X ^ (n-1) :
  Polynomial ℤ) :=

p : ℕ
hp : p.Prime ∧ p > 2
f : ℤ[X]
hf : f = (X + 2) ^ p
⊢ Irreducible (∑ n ∈ f.support \ {0}, ↑(f.coeff n) * X ^ (n - 1))


/-- Prove that $x^2+y^2-1$ is irreducible in $\mathbb{Q}[x,y]$.-/

theorem exercise_9_4_11 :
  Irreducible ((MvPolynomial.X 0)^2 + (MvPolynomial.X 1)^2 - 1 : MvPolynomial (Fin 2) ℚ) :=

⊢ Irreducible (MvPolynomial.X 0 ^ 2 + MvPolynomial.X 1 ^ 2 - 1)


/-- Let $X$ be a topological space; let $A$ be a subset of $X$. Suppose that for each $x \in A$ there is an open set $U$ containing $x$ such that $U \subset A$. Show that $A$ is open in $X$.-/

theorem exercise_13_1 (X : Type*) [TopologicalSpace X] (A : Set X)
  (h1 : ∀ x ∈ A, ∃ U : Set X, x ∈ U ∧ IsOpen U ∧ U ⊆ A) :
  IsOpen A :=

X : Type u_1
inst✝ : TopologicalSpace X
A : Set X
h1 : ∀ x ∈ A, ∃ U, x ∈ U ∧ IsOpen U ∧ U ⊆ A
⊢ IsOpen A

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology


/-- If $\mathcal{T}_\alpha$ is a family of topologies on $X$, show that $\bigcap \mathcal{T}_\alpha$ is a topology on $X$.-/

theorem exercise_13_4a1 (X I : Type*) (T : I → Set (Set X)) (h : ∀ i, is_topology X (T i)) :
  is_topology X (⋂ i : I, T i) :=

X : Type u_1
I : Type u_2
T : I → Set (Set X)
h : ∀ (i : I), is_topology X (T i)
⊢ is_topology X (⋂ i, T i)

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology

def is_topology (X : Type*) (T : Set (Set X)) :=
  univ ∈ T ∧
  (∀ s t, s ∈ T → t ∈ T → s ∩ t ∈ T) ∧
  (∀s, (∀t ∈ s, t ∈ T) → sUnion s ∈ T)


/-- Let $\mathcal{T}_\alpha$ be a family of topologies on $X$. Show that there is a unique smallest topology on $X$ containing all the collections $\mathcal{T}_\alpha$.-/

theorem exercise_13_4b1 (X I : Type*) (T : I → Set (Set X)) (h : ∀ i, is_topology X (T i)) :
  ∃! T', is_topology X T' ∧ (∀ i, T i ⊆ T') ∧
  ∀ T'', is_topology X T'' → (∀ i, T i ⊆ T'') → T'' ⊆ T' :=

X : Type u_1
I : Type u_2
T : I → Set (Set X)
h : ∀ (i : I), is_topology X (T i)
⊢ ∃! T',
    is_topology X T' ∧
      (∀ (i : I), T i ⊆ T') ∧ ∀ (T'' : Set (Set X)), is_topology X T'' → (∀ (i : I), T i ⊆ T'') → T'' ⊆ T'


/-- Show that if $\mathcal{A}$ is a basis for a topology on $X$, then the topology generated by $\mathcal{A}$ equals the intersection of all topologies on $X$ that contain $\mathcal{A}$.-/

theorem exercise_13_5a {X : Type*}
  [TopologicalSpace X] (A : Set (Set X)) (hA : IsTopologicalBasis A) :
  generateFrom A = generateFrom (sInter {T | is_topology X T ∧ A ⊆ T}) :=

X : Type u_1
inst✝ : TopologicalSpace X
A : Set (Set X)
hA : IsTopologicalBasis A
⊢ generateFrom A = generateFrom (⋂₀ {T | is_topology X T ∧ A ⊆ T})


/-- Show that the lower limit topology $\mathbb{R}_l$ and $K$-topology $\mathbb{R}_K$ are not comparable.-/

theorem exercise_13_6 :
  ¬ (∀ U, Rl.IsOpen U → K_topology.IsOpen U) ∧ ¬ (∀ U, K_topology.IsOpen U → Rl.IsOpen U) :=

⊢ (¬∀ (U : Set ℝ), TopologicalSpace.IsOpen U → TopologicalSpace.IsOpen U) ∧
    ¬∀ (U : Set ℝ), TopologicalSpace.IsOpen U → TopologicalSpace.IsOpen U

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology

def lower_limit_topology (X : Type) [Preorder X] :=
  generateFrom {S : Set X | ∃ a b, a < b ∧ S = Ico a b}

def Rl := lower_limit_topology ℝ

def K : Set ℝ := {r | ∃ n : ℕ, r = 1 / n}

def K_topology := generateFrom
  ({S : Set ℝ | ∃ a b, a < b ∧ S = Ioo a b} ∪ {S : Set ℝ | ∃ a b, a < b ∧ S = Ioo a b \ K})


/-- Show that the collection $\{(a,b) \mid a < b, a \text{ and } b \text{ rational}\}$ is a basis that generates a topology different from the lower limit topology on $\mathbb{R}$.-/

theorem exercise_13_8b :
  (generateFrom {S : Set ℝ | ∃ a b : ℚ, a < b ∧ S = Ico ↑a ↑b}).IsOpen ≠
  (lower_limit_topology ℝ).IsOpen :=

⊢ TopologicalSpace.IsOpen ≠ TopologicalSpace.IsOpen

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology

def lower_limit_topology (X : Type) [Preorder X] :=
  generateFrom {S : Set X | ∃ a b, a < b ∧ S = Ico a b}


/-- A map $f: X \rightarrow Y$ is said to be an open map if for every open set $U$ of $X$, the set $f(U)$ is open in $Y$. Show that $\pi_{1}: X \times Y \rightarrow X$ and $\pi_{2}: X \times Y \rightarrow Y$ are open maps.-/

theorem exercise_16_4 {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
  (π₁ : X × Y → X)
  (π₂ : X × Y → Y)
  (h₁ : π₁ = Prod.fst)
  (h₂ : π₂ = Prod.snd) :
  IsOpenMap π₁ ∧ IsOpenMap π₂ :=

X : Type u_1
Y : Type u_2
inst✝¹ : TopologicalSpace X
inst✝ : TopologicalSpace Y
π₁ : X × Y → X
π₂ : X × Y → Y
h₁ : π₁ = Prod.fst
h₂ : π₂ = Prod.snd
⊢ IsOpenMap π₁ ∧ IsOpenMap π₂


/-- Show that if $U$ is open in $X$ and $A$ is closed in $X$, then $U-A$ is open in $X$, and $A-U$ is closed in $X$.-/

theorem exercise_17_4 {X : Type*} [TopologicalSpace X]
  (U A : Set X) (hU : IsOpen U) (hA : IsClosed A) :
  IsOpen (U \ A) ∧ IsClosed (A \ U) :=

X : Type u_1
inst✝ : TopologicalSpace X
U A : Set X
hU : IsOpen U
hA : IsClosed A
⊢ IsOpen (U \ A) ∧ IsClosed (A \ U)


/-- Let $Y$ be an ordered set in the order topology. Let $f, g: X \rightarrow Y$ be continuous. Let $h: X \rightarrow Y$ be the function $h(x)=\min \{f(x), g(x)\}.$ Show that $h$ is continuous.-/

theorem exercise_18_8b {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
  [LinearOrder Y] [OrderTopology Y] {f g : X → Y}
  (hf : Continuous f) (hg : Continuous g) :
  Continuous (λ x => min (f x) (g x)) :=

X : Type u_1
Y : Type u_2
inst✝³ : TopologicalSpace X
inst✝² : TopologicalSpace Y
inst✝¹ : LinearOrder Y
inst✝ : OrderTopology Y
f g : X → Y
hf : Continuous f
hg : Continuous g
⊢ Continuous fun x => min (f x) (g x)


/-- Let $\mathbf{x}_1, \mathbf{x}_2, \ldots$ be a sequence of the points of the product space $\prod X_\alpha$.  Show that this sequence converges to the point $\mathbf{x}$ if and only if the sequence $\pi_\alpha(\mathbf{x}_i)$ converges to $\pi_\alpha(\mathbf{x})$ for each $\alpha$.-/

theorem exercise_19_6a
  {n : ℕ}
  {f : Fin n → Type*} {x : ℕ → Πa, f a}
  (y : Πi, f i)
  [Πa, TopologicalSpace (f a)] :
  Tendsto x atTop (𝓝 y) ↔ ∀ i, Tendsto (λ j => (x j) i) atTop (𝓝 (y i)) :=

n : ℕ
f : Fin n → Type u_1
x : ℕ → (a : Fin n) → f a
y : (i : Fin n) → f i
inst✝ : (a : Fin n) → TopologicalSpace (f a)
⊢ Tendsto x atTop (𝓝 y) ↔ ∀ (i : Fin n), Tendsto (fun j => x j i) atTop (𝓝 (y i))


/-- Define $f_{n}:[0,1] \rightarrow \mathbb{R}$ by the equation $f_{n}(x)=x^{n}$. Show that the sequence $\left(f_{n}(x)\right)$ converges for each $x \in[0,1]$.-/

theorem exercise_21_6a
  (f : ℕ → I → ℝ )
  (h : ∀ x n, f n x = x ^ n) :
  ∀ x, ∃ y, Tendsto (λ n => f n x) atTop (𝓝 y) :=

f : ℕ → ↑I → ℝ
h : ∀ (x : ↑I) (n : ℕ), f n x = ↑x ^ n
⊢ ∀ (x : ↑I), ∃ y, Tendsto (fun n => f n x) atTop (𝓝 y)

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology

abbrev I : Set ℝ := Icc 0 1


/-- Let $X$ be a topological space and let $Y$ be a metric space. Let $f_{n}: X \rightarrow Y$ be a sequence of continuous functions. Let $x_{n}$ be a sequence of points of $X$ converging to $x$. Show that if the sequence $\left(f_{n}\right)$ converges uniformly to $f$, then $\left(f_{n}\left(x_{n}\right)\right)$ converges to $f(x)$.-/

theorem exercise_21_8
  {X : Type*} [TopologicalSpace X] {Y : Type*} [MetricSpace Y]
  {f : ℕ → X → Y} {x : ℕ → X}
  (hf : ∀ n, Continuous (f n))
  (x₀ : X)
  (hx : Tendsto x atTop (𝓝 x₀))
  (f₀ : X → Y)
  (hh : TendstoUniformly f f₀ atTop) :
  Tendsto (λ n => f n (x n)) atTop (𝓝 (f₀ x₀)) :=

X : Type u_1
inst✝¹ : TopologicalSpace X
Y : Type u_2
inst✝ : MetricSpace Y
f : ℕ → X → Y
x : ℕ → X
hf : ∀ (n : ℕ), Continuous (f n)
x₀ : X
hx : Tendsto x atTop (𝓝 x₀)
f₀ : X → Y
hh : TendstoUniformly f f₀ atTop
⊢ Tendsto (fun n => f n (x n)) atTop (𝓝 (f₀ x₀))


/-- If $A \subset X$, a retraction of $X$ onto $A$ is a continuous map $r: X \rightarrow A$ such that $r(a)=a$ for each $a \in A$. Show that a retraction is a quotient map.-/

theorem exercise_22_2b {X : Type*} [TopologicalSpace X]
  {A : Set X} (r : X → A) (hr : Continuous r) (h : ∀ x : A, r x = x) :
  QuotientMap r :=

X : Type u_1
inst✝ : TopologicalSpace X
A : Set X
r : X → ↑A
hr : Continuous r
h : ∀ (x : ↑A), r ↑x = x
⊢ QuotientMap r


/-- Let $\left\{A_{n}\right\}$ be a sequence of connected subspaces of $X$, such that $A_{n} \cap A_{n+1} \neq \varnothing$ for all $n$. Show that $\bigcup A_{n}$ is connected.-/

theorem exercise_23_2 {X : Type*}
  [TopologicalSpace X] {A : ℕ → Set X} (hA : ∀ n, IsConnected (A n))
  (hAn : ∀ n, A n ∩ A (n + 1) ≠ ∅) :
  IsConnected (⋃ n, A n) :=

X : Type u_1
inst✝ : TopologicalSpace X
A : ℕ → Set X
hA : ∀ (n : ℕ), IsConnected (A n)
hAn : ∀ (n : ℕ), A n ∩ A (n + 1) ≠ ∅
⊢ IsConnected (⋃ n, A n)


/-- Show that if $X$ is an infinite set, it is connected in the finite complement topology.-/

theorem exercise_23_4 {X : Type*} [TopologicalSpace X] [CofiniteTopology X]
  (s : Set X) : Infinite s → IsConnected s :=

X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : CofiniteTopology X
s : Set X
⊢ Infinite ↑s → IsConnected s

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology

set_option checkBinderAnnotations false


/-- Let $A$ be a proper subset of $X$, and let $B$ be a proper subset of $Y$. If $X$ and $Y$ are connected, show that $(X \times Y)-(A \times B)$ is connected.-/

theorem exercise_23_9 {X Y : Type*}
  [TopologicalSpace X] [TopologicalSpace Y]
  (A₁ A₂ : Set X)
  (B₁ B₂ : Set Y)
  (hA : A₁ ⊂ A₂)
  (hB : B₁ ⊂ B₂)
  (hA : IsConnected A₂)
  (hB : IsConnected B₂) :
  IsConnected ({x | ∃ a b, x = (a, b) ∧ a ∈ A₂ ∧ b ∈ B₂} \
      {x | ∃ a b, x = (a, b) ∧ a ∈ A₁ ∧ b ∈ B₁}) :=

X : Type u_1
Y : Type u_2
inst✝¹ : TopologicalSpace X
inst✝ : TopologicalSpace Y
A₁ A₂ : Set X
B₁ B₂ : Set Y
hA✝ : A₁ ⊂ A₂
hB✝ : B₁ ⊂ B₂
hA : IsConnected A₂
hB : IsConnected B₂
⊢ IsConnected ({x | ∃ a b, x = (a, b) ∧ a ∈ A₂ ∧ b ∈ B₂} \ {x | ∃ a b, x = (a, b) ∧ a ∈ A₁ ∧ b ∈ B₁})


/-- Let $f: S^{1} \rightarrow \mathbb{R}$ be a continuous map. Show there exists a point $x$ of $S^{1}$ such that $f(x)=f(-x)$.-/

theorem exercise_24_2 {f : (Metric.sphere 0 1 : Set ℝ) → ℝ}
  (hf : Continuous f) : ∃ x, f x = f (-x) :=

f : ↑(Metric.sphere 0 1) → ℝ
hf : Continuous f
⊢ ∃ x, f x = f (-x)


/-- Let $X$ be locally path connected. Show that every connected open set in $X$ is path connected.-/

theorem exercise_25_4 {X : Type*} [TopologicalSpace X]
  [LocPathConnectedSpace X] (U : Set X) (hU : IsOpen U)
  (hcU : IsConnected U) : IsPathConnected U :=

X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : LocPathConnectedSpace X
U : Set X
hU : IsOpen U
hcU : IsConnected U
⊢ IsPathConnected U


/-- Let $X$ be a compact Hausdorff space. Let $\mathcal{A}$ be a collection of closed connected subsets of $X$ that is simply ordered by proper inclusion. Then $Y=\bigcap_{A \in \mathcal{A}} A$ is connected.-/

theorem exercise_26_11
  {X : Type*} [TopologicalSpace X] [CompactSpace X] [T2Space X]
  (A : Set (Set X)) (hA : ∀ (a b : Set X), a ∈ A → b ∈ A → a ⊆ b ∨ b ⊆ a)
  (hA' : ∀ a ∈ A, IsClosed a) (hA'' : ∀ a ∈ A, IsConnected a) :
  IsConnected (⋂₀ A) :=

X : Type u_1
inst✝² : TopologicalSpace X
inst✝¹ : CompactSpace X
inst✝ : T2Space X
A : Set (Set X)
hA : ∀ (a b : Set X), a ∈ A → b ∈ A → a ⊆ b ∨ b ⊆ a
hA' : ∀ a ∈ A, IsClosed a
hA'' : ∀ a ∈ A, IsConnected a
⊢ IsConnected (⋂₀ A)


/-- Show that a connected metric space having more than one point is uncountable.-/

theorem exercise_27_4
  {X : Type*} [MetricSpace X] [ConnectedSpace X] (hX : ∃ x y : X, x ≠ y) :
  ¬ Countable (univ : Set X) :=

X : Type u_1
inst✝¹ : MetricSpace X
inst✝ : ConnectedSpace X
hX : ∃ x y, x ≠ y
⊢ ¬Countable ↑univ


/-- Show that X is countably compact if and only if every nested sequence $C_1 \supset C_2 \supset \cdots$ of closed nonempty sets of X has a nonempty intersection.-/

theorem exercise_28_5
  (X : Type*) [TopologicalSpace X] :
  countably_compact X ↔ ∀ (C : ℕ → Set X), (∀ n, IsClosed (C n)) ∧
  (∀ n, C n ≠ ∅) ∧ (∀ n, C n ⊆ C (n + 1)) → ∃ x, ∀ n, x ∈ C n :=

X : Type u_1
inst✝ : TopologicalSpace X
⊢ countably_compact X ↔
    ∀ (C : ℕ → Set X),
      ((∀ (n : ℕ), IsClosed (C n)) ∧ (∀ (n : ℕ), C n ≠ ∅) ∧ ∀ (n : ℕ), C n ⊆ C (n + 1)) → ∃ x, ∀ (n : ℕ), x ∈ C n

import Mathlib

open Filter Set TopologicalSpace
open scoped Topology

def countably_compact (X : Type*) [TopologicalSpace X] :=
  ∀ U : ℕ → Set X,
  (∀ i, IsOpen (U i)) ∧ ((univ : Set X) ⊆ ⋃ i, U i) →
  (∃ t : Finset ℕ, (univ : Set X) ⊆ ⋃ i ∈ t, U i)


/-- Show that the rationals $\mathbb{Q}$ are not locally compact.-/

theorem exercise_29_1 : ¬ LocallyCompactSpace ℚ :=


/-- Show that if $X$ is a Hausdorff space that is locally compact at the point $x$, then for each neighborhood $U$ of $x$, there is a neighborhood $V$ of $x$ such that $\bar{V}$ is compact and $\bar{V} \subset U$.-/

theorem exercise_29_10 {X : Type*}
  [TopologicalSpace X] [T2Space X] (x : X)
  (hx : ∃ U : Set X, x ∈ U ∧ IsOpen U ∧ (∃ K : Set X, U ⊂ K ∧ IsCompact K))
  (U : Set X) (hU : IsOpen U) (hxU : x ∈ U) :
  ∃ (V : Set X), IsOpen V ∧ x ∈ V ∧ IsCompact (closure V) ∧ closure V ⊆ U :=

X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : T2Space X
x : X
hx : ∃ U, x ∈ U ∧ IsOpen U ∧ ∃ K, U ⊂ K ∧ IsCompact K
U : Set X
hU : IsOpen U
hxU : x ∈ U
⊢ ∃ V, IsOpen V ∧ x ∈ V ∧ IsCompact (closure V) ∧ closure V ⊆ U


/-- Show that if $X$ has a countable dense subset, every collection of disjoint open sets in $X$ is countable.-/

theorem exercise_30_13 {X : Type*} [TopologicalSpace X]
  (h : ∃ (s : Set X), Countable s ∧ Dense s) (U : Set (Set X))
  (hU : ∀ (x y : Set X), x ∈ U → y ∈ U → x ≠ y → x ∩ y = ∅) :
  Countable U :=

X : Type u_1
inst✝ : TopologicalSpace X
h : ∃ s, Countable ↑s ∧ Dense s
U : Set (Set X)
hU : ∀ (x y : Set X), x ∈ U → y ∈ U → x ≠ y → x ∩ y = ∅
⊢ Countable ↑U


/-- Show that if $X$ is normal, every pair of disjoint closed sets have neighborhoods whose closures are disjoint.-/

theorem exercise_31_2 {X : Type*}
  [TopologicalSpace X] [NormalSpace X] {A B : Set X}
  (hA : IsClosed A) (hB : IsClosed B) (hAB : Disjoint A B) :
  ∃ (U V : Set X), IsOpen U ∧ IsOpen V ∧ A ⊆ U ∧ B ⊆ V ∧ closure U ∩ closure V = ∅ :=

X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : NormalSpace X
A B : Set X
hA : IsClosed A
hB : IsClosed B
hAB : Disjoint A B
⊢ ∃ U V, IsOpen U ∧ IsOpen V ∧ A ⊆ U ∧ B ⊆ V ∧ closure U ∩ closure V = ∅


/-- Show that a closed subspace of a normal space is normal.-/

theorem exercise_32_1 {X : Type*} [TopologicalSpace X]
  (hX : NormalSpace X) (A : Set X) (hA : IsClosed A) :
  NormalSpace {x // x ∈ A} :=

X : Type u_1
inst✝ : TopologicalSpace X
hX : NormalSpace X
A : Set X
hA : IsClosed A
⊢ NormalSpace { x // x ∈ A }


/-- Show that if $\prod X_\alpha$ is regular, then so is $X_\alpha$. Assume that each $X_\alpha$ is nonempty.-/

theorem exercise_32_2b
  {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
  (h : ∀ i, Nonempty (X i)) (h2 : RegularSpace (Π i, X i)) :
  ∀ i, RegularSpace (X i) :=

ι : Type u_1
X : ι → Type u_2
inst✝ : (i : ι) → TopologicalSpace (X i)
h : ∀ (i : ι), Nonempty (X i)
h2 : RegularSpace ((i : ι) → X i)
⊢ ∀ (i : ι), RegularSpace (X i)


/-- Show that every locally compact Hausdorff space is regular.-/

theorem exercise_32_3 {X : Type*} [TopologicalSpace X]
  (hX : LocallyCompactSpace X) (hX' : T2Space X) :
  RegularSpace X :=

X : Type u_1
inst✝ : TopologicalSpace X
hX : LocallyCompactSpace X
hX' : T2Space X
⊢ RegularSpace X


/-- Let $X$ be completely regular, let $A$ and $B$ be disjoint closed subsets of $X$. Show that if $A$ is compact, there is a continuous function $f \colon X \rightarrow [0, 1]$ such that $f(A) = \{0\}$ and $f(B) = \{1\}$.-/

theorem exercise_33_8
  (X : Type*) [TopologicalSpace X] [RegularSpace X]
  (h : ∀ x A, IsClosed A ∧ ¬ x ∈ A →
  ∃ (f : X → I), Continuous f ∧ f x = (1 : I) ∧ f '' A = {0})
  (A B : Set X) (hA : IsClosed A) (hB : IsClosed B)
  (hAB : Disjoint A B)
  (hAc : IsCompact A) :
  ∃ (f : X → I), Continuous f ∧ f '' A = {0} ∧ f '' B = {1} :=

X : Type u_1
inst✝¹ : TopologicalSpace X
inst✝ : RegularSpace X
h : ∀ (x : X) (A : Set X), IsClosed A ∧ x ∉ A → ∃ f, Continuous f ∧ f x = 1 ∧ f '' A = {0}
A B : Set X
hA : IsClosed A
hB : IsClosed B
hAB : Disjoint A B
hAc : IsCompact A
⊢ ∃ f, Continuous f ∧ f '' A = {0} ∧ f '' B = {1}


/-- Let $X$ be completely regular. Show that $X$ is connected if and only if the Stone-Čech compactification of $X$ is connected.-/

theorem exercise_38_6 {X : Type*}
  (X : Type*) [TopologicalSpace X] [RegularSpace X]
  (h : ∀ x A, IsClosed A ∧ ¬ x ∈ A →
  ∃ (f : X → I), Continuous f ∧ f x = (1 : I) ∧ f '' A = {0}) :
  IsConnected (univ : Set X) ↔ IsConnected (univ : Set (StoneCech X)) :=

X✝ : Type u_1
X : Type u_2
inst✝¹ : TopologicalSpace X
inst✝ : RegularSpace X
h : ∀ (x : X) (A : Set X), IsClosed A ∧ x ∉ A → ∃ f, Continuous f ∧ f x = 1 ∧ f '' A = {0}
⊢ IsConnected univ ↔ IsConnected univ


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

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

import Mathlib

open Real
open scoped BigOperators


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

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


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

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

l : ℕ → ℝ
hl : ∀ (p n : ℕ), p.Prime → l (p ^ n) = (↑p).log
hl1 : ∀ (m : ℕ), ¬IsPrimePow m → l m = 0
⊢ l = fun n => ∑ d : { x // x ∈ n.divisors }, ↑(ArithmeticFunction.moebius (n / ↑d)) * (↑↑d).log


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

theorem exercise_3_1 : Infinite {p : Nat.Primes // p ≡ -1 [ZMOD 6]} :=


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

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


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

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

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


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

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

p t : ℕ
hp0 : p.Prime
hp1 : p = 4 * t + 3
a : ZMod p
⊢ IsPrimitiveRoot a p ↔ (-a) ^ ((p - 1) / 2) = 1 ∧ ∀ k < (p - 1) / 2, (-a) ^ k ≠ 1


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

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

p a : ℕ
hp : Odd p
⊢ IsPrimitiveRoot a p ↔ ∀ (q : ℕ), q ∣ p - 1 → q.Prime → ¬a ^ (p - 1) ≡ 1 [MOD p]


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

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

p x : ℤ
hp : Prime p
hpx : p ∣ x ^ 4 - x ^ 2 + 1
⊢ p ≡ 1 [ZMOD 12]


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

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

p q : ℕ
inst✝¹ : Fact p.Prime
inst✝ : Fact q.Prime
a : ℤ
ha : a < 0
h0 : ↑p ≡ ↑q [ZMOD 4 * a]
h1 : ¬↑p ∣ a
⊢ legendreSym p a = legendreSym q a


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

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

n : ℕ
hn : ∃ x y z w, x ^ 3 + y ^ 3 = ↑n ∧ z ^ 3 + w ^ 3 = ↑n ∧ x ≠ z ∧ x ≠ w ∧ y ≠ z ∧ y ≠ w
⊢ n ≥ 1729


z : Fin 4 → ℂ
hz0 : ∀ (n : Fin 4), ‖z n‖ < 1
hz1 : ∀ (n : Fin 4), z n ≠ 1
⊢ 3 - z 0 - z 1 - z 2 - z 3 + z 0 * z 1 * z 2 * z 3 ≠ 0

import Mathlib

open scoped BigOperators

open scoped BigOperators


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

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

n : ℕ
hn : n > 0
f : ℕ → ℂ → ℂ
hf : ∀ (n : ℕ), f n = fun z => ∑ i : Fin n, (↑n - ↑↑i) * z ^ ↑i
⊢ ¬∃ z, ‖z‖ ≤ 1 ∧ f n z = 0

import Mathlib

open scoped BigOperators


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

f : ℝ → ℝ
c : ℕ → ℝ
hf : f = fun x => ∑' (i : ℕ), c i * x ^ i
hc : ∀ (n : ℕ), c n = 0 ∨ c n = 1
hf1 : f (2 / 3) = 3 / 2
⊢ Irrational (f (1 / 2))


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


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


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

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

f : ℝ → ℝ
hf : ContDiff ℝ 3 f
⊢ ∃ a, f a * deriv f a * iteratedDeriv 2 f a * iteratedDeriv 3 f a ≥ 0