import Mathlib

/-
There exist only injective functions \f:\mathbb{N}\rightarrow\mathbb{N}\ that satisfy:
\a\ \f(f(m)+f(n))=f(f(m))+f(n)\, \b\ \f(1)=2, \f(2)=4\.
-/

variable {f : ℕ → ℕ} (hf_inj : Function.Injective f)

theorem unique_injective_function_satisfying_conditions :
  (∀ m n : ℕ, f (f m + f n) = f (f m) + f n) →
  f 1 = 2 →
  f 2 = 4 →
  ∃! f : ℕ → ℕ, Function.Bijective f ∧ (∀ m n : ℕ, f (f m + f n) = f (f m) + f n) ∧ f 1 = 2 ∧ f 2 = 4 :=


import Mathlib

/-
The characteristic of the ring $\mathbb{Z}_3 \times \mathbb{Z}_3$ is 3.
-/

open ZMod

/-- The ring Z3 is the set of integers modulo 3. -/
def Z3 : Type := ZMod 3

/-- The ring Z3 × Z3 consists of pairs (a, b) where a, b ∈ Z3, with component-wise addition and multiplication. -/
def Z3xZ3 : Type := ZMod 3 × ZMod 3

lemma scalar_multiplication (n : ℕ) (a b : ZMod 3) : n • (a, b) = (n • a, n • b) := sorry

lemma multiple_of_3 (n : ℕ) (a : ZMod 3) : (a ≠ 0 → (n • a = 0 ↔ n % 3 = 0)) := sorry

noncomputable def evalChar := ringChar (ZMod 3 × ZMod 3)

/-- The characteristic of the ring Z3 × Z3 is 3. -/
theorem characteristic_Z3xZ3 : evalChar = 3 :=


import Mathlib

/-
The polynomial \(x^n+x-1\) is divisible by \(x^2-x+1\) if and only if \(n=6i-1\).
Additionally, there exists no \(n\) such that the polynomial \(x^n+x-1\) can be divisible by \(x^3-x+1\).
-/

open Polynomial Complex

variable {R : Type*} [Field R] [Nontrivial R]

variable  (P Q R : Polynomial R) (hP : P = X^n + X - 1) (hQ : Q = X^2 - X + 1) (hR : R = X^3 - X + 1)

theorem polynomial_divisibility_by_quadratic (n : ℕ) :
  ((P ∣ Q) ↔ ∃ i : ℕ, n = 6 * i - 1 )∧ (∀ n : ℕ, ¬ (P ∣ R)) :=


import Mathlib

/-
In a ring R of characteristic 0, if e, g, and f are idempotent elements of R (where an element a is idempotent if a^2=a), and if e+g+f=0, then it follows that e=f=g=0.
-/

variable {R : Type _} [Ring R] [CharZero R]

variable (e g f : R) (he : IsIdempotentElem e) (hg : IsIdempotentElem g) (hf : IsIdempotentElem f) (hsum : e + g + f = 0)

theorem sum_of_idempotents_zero_implies_zero  :
e = 0 ∧ g = 0 ∧ f = 0 :=


import Mathlib

/-
For a polynomial P, the equation \(16P(x^2)=P(2x)^2\) holds if and only if
\(P(x)=16\left(\frac14x\right)^n\) for some \(n\in\mathbb{N}\).
-/

open Polynomial

variable {P : Polynomial ℝ}

theorem polynomial_condition :
(∀ x : ℝ, 16 * eval (x^2) P = (eval (2 * x) P)^2) ↔ ∃ n : ℕ, P = (16 : Polynomial ℝ) * (Polynomial.X /ₘ (4 : Polynomial ℝ))^n :=


import Mathlib

/-
The sum \(\sum_k \binom{n}{\left\lfloor \frac{k}{2} \right\rfloor} x^k\) is equivalent to \((1 + x)(1 + x^2)^n\).
-/

open BigOperators Finset Nat

theorem binomial_sum_equiv_product (n : ℕ) (x : ℝ) :
 ∑ k in range (2 * n + 1), (Nat.choose n (k/2)) * x^k = (1 + x) * (1 + x^2)^n :=


import Mathlib

/-
For any polynomial P(x) of degree n satisfying P(i) = 1/i for i = 1, 2, ..., n+1, P(n+2) is equal to 0
if n is odd and 2/(n+2) if n is even.
-/

open Polynomial

variable {R : Type*} [Field R] [CharZero R] (P : Polynomial R) (n : ℕ)

variable (hP : P.degree = n) (hValues : ∀ i ∈ Finset.range (n + 2), P.eval (i + 1 : R) = 1 / (i + 1 : R))

theorem polynomial_value_based_on_parity:
(n % 2 = 0 → P.eval (n + 2 : R) = 2 / (n + 2 : R)) ∧ (n % 2 ≠ 0 → P.eval (n + 2 : R) = 0) :=


import Mathlib

/-
The integral of \[(x^3 - 3cosx) dx\] is \[\frac{x^4}{4} - 3sinx + C\].
-/

-- Define the function f(x)
noncomputable def f (x : ℝ) : ℝ := x^3 - 3 * Real.cos x

-- Define the integral of f(x)
noncomputable def integralf (x : ℝ) : ℝ := (x^4 / 4) - 3 * Real.sin x

-- Theorem statement

theorem integral_f_eq_integralF_plus_C (x C : ℝ):
  ∫ x , f x = integralf x + C :=


import Mathlib

/-
The integral of \(\displaystyle \int_0^1\frac{8x^2 +6x +5}{x^2 +2x+2 }\,dx\) is equal to \(-5\ln\frac52 - \left(\tan^{-1}2-\frac{\pi}4\right)+8\).
-/

open Real

theorem integral_of_rational_function_eq_given_value :
  let f := fun x => (8 * x^2 + 6 * x + 5) / (x^2 + 2 * x + 2);
  ∫ x in Set.Icc 0 1, f x = -5 * log (5 / 2) - (arctan 2 - π / 4) + 8 :=


import Mathlib

/-
The local maximum of the function f(x)=x^4/4 - x^3/3 - 2x^2 + 4x + 5 on the interval
[-3,3] is 41 / 4  and is attained at x=3, and
the local minimum is -13/3 and it is attained for x=-2.
-/

noncomputable def f (x : ℝ) : ℝ := x^4 / 4 - x^3 / 3 - 2 * x^2 + 4 * x + 5

theorem extrema_on_interval :
  ¬ ((∃ x : ℝ, x ∈ Set.Icc (-3) 3 ∧ (∀ y ∈ Set.Icc (-3) 3, f y ≤ f x) ∧ f x = 41/4 ∧ x = 3) ∧
  (∃ z : ℝ, z ∈ Set.Icc (-3) 3 ∧ (∀ y ∈ Set.Icc (-3) 3, f z ≤ f y) ∧ f z = - 13 / 3 ∧ z = -2)) :=


import Mathlib

/-
The limit of the function \(\displaystyle\lim_{x\to 3}\frac{\cos(2x-6)-1}{x^3-6x^2+9x}\) is -2/3.
-/

open Filter Topology

theorem limit_of_function_at_3 :
Tendsto (fun x : ℝ => (Real.cos (2 * x - 6) - 1) / (x^3 - 6 * x^2 + 9 * x)) (𝓝 3) (𝓝 (-2 / 3)) :=


import Mathlib

/-
The integral of \(\int \frac{1}{x^2+1} \, dx\) is \(\arctan x + C\).
-/

open Real

noncomputable def f (x:ℝ ):ℝ := 1 / (x^2 + 1)

theorem integral_of_inv_sq_plus_one (x C: ℝ) :
  ∫ x , f x  = arctan x + C :=


import Mathlib

/-
The derivative of the function \(f(x)=\cos(x^3)\) is \(f'(x)= -\sin(x^3)\cdot 3x^2\).
-/

open scoped Topology Filter

variable (x : ℝ)

theorem cosX3_derivative : deriv (fun x => Real.cos (x^3)) x = -Real.sin (x^3) * (3 * x^2) :=


import Mathlib

/-
Let \[F(x)=\cos^2 x-\sin^2 x,\] \[G(x)=2\cos^2x,\] \[H(x)=2\sin^2x,\] \[K(x)=\cos (2x).\] Which of the previously defined functions are anti-derivatives of the function \[\varphi(x)=-4\sin x\cdot\cos x.\] \begin{itemize} \item \textbf{(A)} \(F\) only \item \textbf{(B)} \(F\) and \(K\) only \item \textbf{(C)} \(F\), \(G\), and \(K\) only \item \textbf{(D)} \(H\) and \(K\) only \item \textbf{(E)} \(H\) only \end{itemize}
-/

open Real

-- Define the functions
noncomputable def F (x : ℝ) : ℝ := cos x ^ 2 - sin x ^ 2

noncomputable def G (x : ℝ) : ℝ := 2 * cos x ^ 2

noncomputable def H (x : ℝ) : ℝ := 2 * sin x ^ 2

noncomputable def K (x : ℝ) : ℝ := cos (2 * x)

-- Define the function φ
noncomputable def φ (x : ℝ) : ℝ := -4 * sin x * cos x

-- Theorem statement

theorem formal_statement : ∀ x : ℝ, (deriv F x = φ x) ∧ (deriv K x = φ x) ∧ (deriv G x ≠ φ x) ∧ (deriv H x ≠ φ x) :=


import Mathlib

/-
The surface integral \[\iint_G (x^2+y^2+2z)\,dS,\] where \(G\) is the part of the paraboloid \(z=7-x^2-y^2\) that lies above the \(xy\)-plane is equal to \[\frac{957\sqrt{29}-47}{20}\pi.\]
-/

variable {G : Set (ℝ × ℝ × ℝ)} (hG : G = {p : ℝ × ℝ × ℝ | p.2.2 = 7 - p.1^2 - p.2.1^2 ∧ p.2.2 ≥ 0})

theorem paraboloid_integral_value :
∫ (x : ℝ) in Set.Icc (-Real.sqrt 7) (Real.sqrt 7), ∫ (y : ℝ) in Set.Icc (-Real.sqrt (7 - x^2)) (Real.sqrt (7 - x^2)),
(x^2 + y^2 + 2*(7 - x^2 - y^2)) = (957 * Real.sqrt 29 - 47) / 20 * π :=


import Mathlib

/-
The integral of \(\sin^3 x\cos^{6}x\,dx\) is equal to \(-\frac{\cos^7 x}{7} + \frac{\cos^9 x}{9} + C\).
-/

theorem integral_sin_cube_cos_six_power (x : ℝ) :
  ∫ (x : ℝ), Real.sin x ^ 3 * Real.cos x ^ 6 = -(Real.cos x ^ 7 / 7) + Real.cos x ^ 9 / 9 + C :=


import Mathlib

/-
The integral \(\displaystyle \int \frac{1}{\sqrt{81-x^2}}\,dx\)
is equivalent to \(\arcsin\left(\frac{x}{9}\right)+C\).
-/

open Real

theorem integral_of_one_over_sqrt_eighty_one_minus_x_squared (x C : ℝ):
  ∫ x, 1 / sqrt (81 - x^2) = arcsin (x / 9) + C :=


import Mathlib

/-
The derivative of the function \(f(x)=x^3\) at point \(x=4\) equals 48.
-/

open Filter

variable (f : ℝ → ℝ) (x : ℝ)

theorem derivative_of_cube_at_four : deriv (fun x : ℝ => x^3) 4 = 48 :=


import Mathlib

/-
The integral of \(\displaystyle \frac{1}{x^2-9}\,dx\) is equal to \(\frac{1}{6}\ln\left|\frac{x-3}{x+3}\right|+C\).
-/

open Real

theorem integral_of_rational_function_with_log :
  ∀ (x : ℝ), x ≠ 3 ∧ x ≠ -3 →
  (∫ (dx : ℝ), 1 / (x^2 - 9)) = (1 / 6) * log (abs ((x - 3) / (x + 3))) + C :=


import Mathlib

/-
Let $f(x) = \sec^2 x$. The equation of the tangent line to the graph of $f(x)$ at the point $(\pi/3, f(\pi/3))$ is given by $y = 8\sqrt{3}x + 4 - 8\sqrt{3}\pi/3$.
-/

open Real

-- Define `f(x)`: The function `f(x) = sec^2 x`.
noncomputable def f (x : ℝ) : ℝ := (1 / cos x) ^ 2

-- Lemma of `f(π/3)`: The value of `f` at `x = π/3` is `4`.

lemma value_at_pi_over_3 : f (π / 3) = 4 :=


import Mathlib

/-
Let $f(x) = \sec^2 x$. The equation of the tangent line to the graph of $f(x)$ at the point $(\pi/3, f(\pi/3))$ is given by $y = 8\sqrt{3}x + 4 - 8\sqrt{3}\pi/3$.
-/

open Real

-- Define `f(x)`: The function `f(x) = sec^2 x`.
noncomputable def f (x : ℝ) : ℝ := (1 / cos x) ^ 2

-- Lemma of `f(π/3)`: The value of `f` at `x = π/3` is `4`.
axiom value_at_pi_over_3 : f (π / 3) = 4

-- Lemma of `f'(x)`: The derivative of `f(x) = sec^2 x` is `2 sec^2 x tan x`.

lemma derivative_of_f (x : ℝ) : HasDerivAt f (2 * (1 / cos x) ^ 2 * tan x) x :=


import Mathlib

/-
Let $f(x) = \sec^2 x$. The equation of the tangent line to the graph of $f(x)$ at the point $(\pi/3, f(\pi/3))$ is given by $y = 8\sqrt{3}x + 4 - 8\sqrt{3}\pi/3$.
-/

open Real

-- Define `f(x)`: The function `f(x) = sec^2 x`.
noncomputable def f (x : ℝ) : ℝ := (1 / cos x) ^ 2

-- Lemma of `f(π/3)`: The value of `f` at `x = π/3` is `4`.
axiom value_at_pi_over_3 : f (π / 3) = 4

-- Lemma of `f'(x)`: The derivative of `f(x) = sec^2 x` is `2 sec^2 x tan x`.
axiom derivative_of_f (x : ℝ) : HasDerivAt f (2 * (1 / cos x) ^ 2 * tan x) x

-- Lemma of `f'(π/3)`: The value of the derivative at `x = π/3` is `8√3`.

lemma derivative_value_at_pi_over_3 : (2 * (1 / cos (π / 3)) ^ 2 * tan (π / 3)) = 8 * Real.sqrt 3 :=


import Mathlib

/-
Let $f(x) = \sec^2 x$. The equation of the tangent line to the graph of $f(x)$ at the point $(\pi/3, f(\pi/3))$ is given by $y = 8\sqrt{3}x + 4 - 8\sqrt{3}\pi/3$.
-/

open Real

-- Define `f(x)`: The function `f(x) = sec^2 x`.
noncomputable def f (x : ℝ) : ℝ := (1 / cos x) ^ 2

-- Lemma of `f(π/3)`: The value of `f` at `x = π/3` is `4`.
axiom value_at_pi_over_3 : f (π / 3) = 4

-- Lemma of `f'(x)`: The derivative of `f(x) = sec^2 x` is `2 sec^2 x tan x`.
axiom derivative_of_f (x : ℝ) : HasDerivAt f (2 * (1 / cos x) ^ 2 * tan x) x

-- Lemma of `f'(π/3)`: The value of the derivative at `x = π/3` is `8√3`.
axiom derivative_value_at_pi_over_3 : (2 * (1 / cos (π / 3)) ^ 2 * tan (π / 3)) = 8 * Real.sqrt 3

-- Theorem of Tangent Line Equation: The equation of the tangent line to `f(x) = sec^2 x` at `x = π/3` is `y = 8√3 x + 4 - 8√3 π/3`.

theorem tangent_line_equation :
∀ x y : ℝ, y = 8 * Real.sqrt 3 * (x - π / 3) + 4 ↔
y - f (π / 3) = (2 * (1 / cos (π / 3)) ^ 2 * tan (π / 3)) * (x - π / 3) :=


import Mathlib

/-
Let $f(x) = \sec^2 x$. The equation of the tangent line to the graph of $f(x)$ at the point $(\pi/3, f(\pi/3))$ is given by $y = 8\sqrt{3}x + 4 - 8\sqrt{3}\pi/3$.
-/

open Real

-- Define `f(x)`: The function `f(x) = sec^2 x`.
noncomputable def f (x : ℝ) : ℝ := (1 / cos x) ^ 2

-- Lemma of `f(π/3)`: The value of `f` at `x = π/3` is `4`.
axiom value_at_pi_over_3 : f (π / 3) = 4

-- Lemma of `f'(x)`: The derivative of `f(x) = sec^2 x` is `2 sec^2 x tan x`.
axiom derivative_of_f (x : ℝ) : HasDerivAt f (2 * (1 / cos x) ^ 2 * tan x) x

-- Lemma of `f'(π/3)`: The value of the derivative at `x = π/3` is `8√3`.
axiom derivative_value_at_pi_over_3 : (2 * (1 / cos (π / 3)) ^ 2 * tan (π / 3)) = 8 * Real.sqrt 3

-- Theorem of Tangent Line Equation: The equation of the tangent line to `f(x) = sec^2 x` at `x = π/3` is `y = 8√3 x + 4 - 8√3 π/3`.
axiom tangent_line_equation :
∀ x y : ℝ, y = 8 * Real.sqrt 3 * (x - π / 3) + 4 ↔
y - f (π / 3) = (2 * (1 / cos (π / 3)) ^ 2 * tan (π / 3)) * (x - π / 3)

-- Proof that this is indeed the tangent line

theorem is_tangent_line :
  HasDerivAt f (8 * Real.sqrt 3) (π / 3) ∧
  f (π / 3) = 8 * Real.sqrt 3 * (π / 3 - π / 3) + 4 :=


import Mathlib

/-
The value of the integral \[\iiint_D e^{x^2+y^2}\,dV\] where \(D\) is the the region
in bounded by the planes \(y=0\), \(z=0\), \(y=x\),
and the paraboloid \(z=4-x^2-y^2\) is \[\frac{\left(e^4-5\right)\pi}8\].
-/

open MeasureTheory

variable {D : Type} [MeasurableSpace D] [MeasureSpace D]

-- Define the set D as a variable
variable (D : Set (Fin 3 → ℝ))

theorem integral_value_over_region (D : Set (Fin 3 → ℝ))
  (hD : D = {p : Fin 3 → ℝ | p 2 ≥ 0 ∧ p 3 ≥ 0 ∧ p 2 ≤ p 1 ∧ p 3 ≤ 4 - p 1^2 - p 2^2}) :
  let integrand := fun p : Fin 3 → ℝ => Real.exp (p 1^2 + p 2^2)
  ∫ p in D, integrand p = (Real.exp 4 - 5) * π / 8 :=


import Mathlib

/-
Prove that \(\displaystyle \lim_{x\to 0}\frac{1-\cos x}{x^2}=\frac12\).
-/

open Filter Topology

/-- Version 1: Using explicit domain restriction -/
theorem limit_of_cosine_difference_quotient :
  ¬ (Tendsto (fun x => if x ≠ 0 then (1 - Real.cos x) / x^2 else 1/2) (𝓝 0) (𝓝 (1/2)) ) :=


import Mathlib

/-
The limit of the function \(f(x)=\frac{\sin(5x^2)}{x^2}\) as \(x\) approaches 0 is 5.
-/

open Filter Topology Real

theorem limit_of_sin_5x2_over_x2_as_x_approaches_0 :
  Tendsto (fun x => (sin (5 * x^2)) / x^2) (𝓝 0) (𝓝 5) :=


import Mathlib

/-
The integral \(\int \frac{1}{\cos^2 x} \, dx\) equals to \(\tan x + C\).
-/

-- Define the constant C for the integration constant
variable (C : ℝ)

-- Theorem: The indefinite integral of 1/cos^2(x) with respect to x is tan(x) + C.

theorem integral_of_one_over_cos_sq (x : ℝ) :
∫ (x : ℝ), 1 / (Real.cos x ^ 2) = Real.tan x + C :=


import Mathlib

/-
The integral of the function (1/x + x^2) with respect to x from 2 to 8 equals the natural logarithm of 4 plus 168.
-/

open Real

theorem integral_of_function_equals_ln_plus_168 :
(∫ x in Set.Icc 2 8, (1 / x + x^2) : ℝ) = Real.log 4 + 168 :=


import Mathlib

/-
The integral \[ \int_{0}^{\frac{\pi}{2}} \ln{(\sin{x})} \,dx \] is equal to -\frac{\pi}{2} \ln{2}.
-/

open Real

variable (x : ℝ)

theorem integral_ln_sin_pi_over_two :
∫ x in Set.Icc 0 (π / 2), log (sin x) = - (π / 2) * log 2 :=


theorem composite_derivative_at_zero : deriv (fun x => u (v x)) 0 = 42 :=


import Mathlib

/-
The maximal value of the function \(f(x,y,z)=xy+yz+zx\), given that \(x\), \(y\), and \(z\)
are real numbers that satisfy \(x^2+y^2+z^2=1\) is 1, which occurs when \(x=y=z=\frac1{\sqrt 3}\).
-/

variable {x y z : ℝ}

-- Define the function f
def f : ℝ × ℝ × ℝ → ℝ := λ (x, y, z) => x * y + y * z + z * x

theorem max_value_of_function_under_constraint :
  (x^2 + y^2 + z^2 = 1) → f (x, y, z) ≤ 1 ∧ (f (x, y, z) = 1 ↔ x = 1 / Real.sqrt 3 ∧ y = 1 / Real.sqrt 3 ∧ z = 1 / Real.sqrt 3) :=


import Mathlib

/-
The value of the integral \[\int_3^9 (x^2-3) dx,\] is 216 according to the Fundamental Theorem of Calculus.
-/

open Real

-- Define the polynomial function
noncomputable def f (x : ℝ) : ℝ := x^2 - 3

-- Theorem statement

theorem integral_of_polynomial : ∫ x in Set.Icc 3 9, f x = 216 :=


import Mathlib

/-
Let $a_n = \frac{3^n+2^n}{3^{n+1}-2^{n+1}}$ for $n \in \mathbb{N}$. Then,

  $\lim_{n\rightarrow\infty} a_n = \frac{1}{3}$
-/

open Real
open Filter (Tendsto)

variable (n : ℕ)

/-- Define `a_n`: The sequence defined by a_n = (3^n + 2^n) / (3^(n+1) - 2^(n+1)) -/
noncomputable def a_n (n : ℕ) : ℝ := (3^n + 2^n) / (3^(n+1) - 2^(n+1))


import Mathlib

/-
Let $a_n = \frac{3^n+2^n}{3^{n+1}-2^{n+1}}$ for $n \in \mathbb{N}$. Then,

  $\lim_{n\rightarrow\infty} a_n = \frac{1}{3}$
-/

open Real
open Filter (Tendsto)

variable (n : ℕ)

/-- Define `a_n`: The sequence defined by a_n = (3^n + 2^n) / (3^(n+1) - 2^(n+1)) -/
noncomputable def a_n (n : ℕ) : ℝ := (3^n + 2^n) / (3^(n+1) - 2^(n+1))

/-- Lemma 1: Rewrite a_n as (1 + (2/3)^n) / (3 * (1 - (2/3)^(n+1))) -/
axiom sequence_rewrite (n : ℕ) : a_n n = (1 + (2/3)^n) / (3 * (1 - (2/3)^(n+1)))

/-- Lemma 2: As n approaches infinity, (2/3)^n approaches 0 -/
lemma geometric_limit :
  Tendsto (λ n : ℕ => (2/3 : ℝ)^n) Filter.atTop (nhds 0) :=


import Mathlib

/-
Let $a_n = \frac{3^n+2^n}{3^{n+1}-2^{n+1}}$ for $n \in \mathbb{N}$. Then,

  $\lim_{n\rightarrow\infty} a_n = \frac{1}{3}$
-/

open Real
open Filter (Tendsto)

variable (n : ℕ)

/-- Define `a_n`: The sequence defined by a_n = (3^n + 2^n) / (3^(n+1) - 2^(n+1)) -/
noncomputable def a_n (n : ℕ) : ℝ := (3^n + 2^n) / (3^(n+1) - 2^(n+1))

/-- Lemma 1: Rewrite a_n as (1 + (2/3)^n) / (3 * (1 - (2/3)^(n+1))) -/
axiom sequence_rewrite (n : ℕ) : a_n n = (1 + (2/3)^n) / (3 * (1 - (2/3)^(n+1)))

/-- Lemma 2: As n approaches infinity, (2/3)^n approaches 0 -/
axiom geometric_limit :
  Tendsto (λ n : ℕ => (2/3 : ℝ)^n) Filter.atTop (nhds 0)

theorem sequence_limit :
  Filter.Tendsto a_n Filter.atTop (nhds (1/3)) :=


import Mathlib

/-
The limit of the function \(\displaystyle \lim_{x\to +\infty}\frac{\sin\left(2x+x^3\right)}{x+3x^3}\) as x approaches infinity is equal to 0.
-/

open Filter Topology Real

theorem limit_of_sin_fraction_as_x_approaches_infinity :
Tendsto (fun x : ℝ => sin (2 * x + x^3) / (x + 3 * x^3)) atTop (𝓝 0) :=


import Mathlib

/-
The function \(f(x)=\cos(3x+x^2)\) is differentiable for \(x\in\mathbb R\) and its derivative \(f^{\prime}(x)\) is \(-\sin(3x+x^2)\cdot (3+2x)\).
-/

open Real

theorem cosine_derivative_formula (x : ℝ) :
  deriv (fun x => cos (3 * x + x^2)) x = -sin (3 * x + x^2) * (3 + 2 * x) :=


import Mathlib

/-
The derivative of \(f(x)=e^x\) at \(x=e\) is \(e^e\).
-/

open Real

theorem derivative_of_exp_at_e : deriv (fun x => exp x) e = exp e :=


import Mathlib

/-
The partial derivative of the function g(s,t)=f(x(s,t),y(s,t),z(s,t))
with respect to ∂t evaluated at (2,π) is 24π², where:
  f(x,y,z) = x² + y³ + z⁴
  x(s,t) = s·cos(t)
  y(s,t) = s·t
  z(s,t) = s²
-/

open Real
open Function

/-- The main function f(x,y,z) = x² + y³ + z⁴ -/
noncomputable def f (x y z : ℝ) : ℝ := x^2 + y^3 + z^4

/-- x(s,t) = s·cos(t) -/
noncomputable def x (s t : ℝ) : ℝ := s * cos t

/-- y(s,t) = s·t -/
noncomputable def y (s t : ℝ) : ℝ := s * t

/-- z(s,t) = s² -/
noncomputable def z (s : ℝ) : ℝ := s^2

/-- The composite function g(s,t) = f(x(s,t), y(s,t), z(s,t)) -/
noncomputable def g (s t : ℝ) : ℝ :=
  f (x s t) (y s t) (z s)

/-- Partial derivative of g with respect to t -/
noncomputable def partial_t (s t : ℝ) : ℝ :=
  deriv (fun τ => g s τ) t

/-- Main theorem: The partial derivative ∂g/∂t at (2,π) equals 24π² -/
theorem partial_derivative_example :
  partial_t 2 π = 24 * π^2 :=


import Mathlib

open Polynomial Set

/-- Define the parabola as a polynomial x² + 3 -/
noncomputable def parabola_poly : Polynomial ℝ :=
  X^2 + C 3

/-- Convert polynomial to real function -/
noncomputable def parabola_fun (x : ℝ) : ℝ :=
  aeval x parabola_poly

/-- The area under the parabola between x=1 and x=3 is 44/3 -/
theorem area_under_parabola_from_1_to_3 :
  (∫ x in Icc 1 3, parabola_fun x) = 44/3 :=


import Mathlib

/-
The integral of \(\frac{1}{x^2 + 1}\) with respect to \(x\) equals to the arctangent function \(\arctan x + C\).
-/

open Real

theorem integral_of_one_over_x_squared_plus_one (x : ℝ) :
∫ y in Set.Icc 0 x, (1 : ℝ) / (y^2 + 1) = arctan x - arctan 0 :=


import Mathlib

/-
The value of \(f_y(7,1)\) for the function \(f(x,y) = xy^2 + x^2y\) is 63.
-/

-- Define the function f(x, y) = x * y^2 + x^2 * y
noncomputable def f (x y : ℤ) : ℤ := x * y^2 + x^2 * y

-- Theorem statement: The value of f(7, 1) is 56

theorem function_evaluation_example : f 7 1 = 56 :=


import Mathlib

/-
The integral of \(\int_0^a \sqrt{a^2-x^2} \,dx\) is \(\frac{a^2 \pi}{4}\).
-/

open Real

variable {a : ℝ} (ha : 0 < a)

theorem integral_sqrt_a2_minus_x2_eq_a2_pi_div_4 :
∫ x in Set.Icc 0 a, sqrt (a^2 - x^2) = a^2 * π / 4 :=


import Mathlib

/-
The integral of 1 over cos^2x dx is equal to tan x + C.
-/

open intervalIntegral
open Real

theorem integral_of_one_over_cos_squared (x C: ℝ) :
∫ x , 1 / cos x ^ 2 = tan x + C :=


import Mathlib

/-
The composition of the functions \(u(x)=\sin x\) and \(v(x)=x^2\) is \(u(v(x))=\sin(x^2)\).
-/

-- Define the sine function
noncomputable def u (x : ℝ) : ℝ := Real.sin x

-- Define the quadratic function
def v (x : ℝ) : ℝ := x ^ 2

-- Theorem statement for the composition of u and v

theorem composition_of_sine_and_quadratic (x : ℝ) : u (v x) = Real.sin (x ^ 2) :=


import Mathlib

/-
The length of the curve obtained by a moving paint nozzle that rotates around a rotating paraboloid in unit time is given by the integral
(without evaluating) \[\int_0^1\sqrt{1+\left(4+4\pi^2\right)t^2}\,dt.\]
-/

-- Define the integrand function
noncomputable def integrand (t : ℝ) : ℝ := Real.sqrt (1 + (4 + 4 * Real.pi ^ 2) * t ^ 2)

-- Theorem statement

theorem curveLength_integral :
∫ (t : ℝ) in Set.Icc 0 1, integrand t = ∫ (t : ℝ) in Set.Icc 0 1, Real.sqrt (1 + (4 + 4 * Real.pi ^ 2) * t ^ 2) :=


import Mathlib

/-
Let $f(x) = x^3-9x^2+24x$ be a real-valued function defined on $\mathbb{R}$. Then:
  1. $f(x)$ has a local maximum at $x=2$.
  2. $f(x)$ has a local minimum at $x=4$.
  3. These are the only local extrema of $f(x)$ on $\mathbb{R}$.
-/

open Real

variable (x : ℝ)

/-- The cubic polynomial f(x) = x³ - 9x² + 24x -/
noncomputable def f (x : ℝ) : ℝ := x^3 - 9*x^2 + 24*x

/-- The first derivative f'(x) = 3x² - 18x + 24 -/
noncomputable def f_deriv (x : ℝ) : ℝ := 3*x^2 - 18*x + 24

/-- The second derivative f''(x) = 6x - 18 -/
noncomputable def f_second_deriv (x : ℝ) : ℝ := 6*x - 18

/-- Lemma: Critical points are x = 2 and x = 4 -/
lemma critical_points : f_deriv x = 0 ↔ x = 2 ∨ x = 4 :=


import Mathlib

/-
Let $f(x) = x^3-9x^2+24x$ be a real-valued function defined on $\mathbb{R}$. Then:
  1. $f(x)$ has a local maximum at $x=2$.
  2. $f(x)$ has a local minimum at $x=4$.
  3. These are the only local extrema of $f(x)$ on $\mathbb{R}$.
-/

open Real

variable (x : ℝ)

/-- The cubic polynomial f(x) = x³ - 9x² + 24x -/
noncomputable def f (x : ℝ) : ℝ := x^3 - 9*x^2 + 24*x

/-- The first derivative f'(x) = 3x² - 18x + 24 -/
noncomputable def f_deriv (x : ℝ) : ℝ := 3*x^2 - 18*x + 24

/-- The second derivative f''(x) = 6x - 18 -/
noncomputable def f_second_deriv (x : ℝ) : ℝ := 6*x - 18

/-- Lemma: Critical points are x = 2 and x = 4 -/
axiom critical_points : f_deriv x = 0 ↔ x = 2 ∨ x = 4

/-- Lemma: Second derivative test -/
lemma second_derivative_test (x : ℝ) (h : f_deriv x = 0) :
  (x = 2 ∧ f_second_deriv x < 0) ∨ (x = 4 ∧ f_second_deriv x > 0) :=


import Mathlib

/-
Let $f(x) = x^3-9x^2+24x$ be a real-valued function defined on $\mathbb{R}$. Then:
  1. $f(x)$ has a local maximum at $x=2$.
  2. $f(x)$ has a local minimum at $x=4$.
  3. These are the only local extrema of $f(x)$ on $\mathbb{R}$.
-/

open Real

variable (x : ℝ)

/-- The cubic polynomial f(x) = x³ - 9x² + 24x -/
noncomputable def f (x : ℝ) : ℝ := x^3 - 9*x^2 + 24*x

/-- The first derivative f'(x) = 3x² - 18x + 24 -/
noncomputable def f_deriv (x : ℝ) : ℝ := 3*x^2 - 18*x + 24

/-- The second derivative f''(x) = 6x - 18 -/
noncomputable def f_second_deriv (x : ℝ) : ℝ := 6*x - 18

/-- Lemma: Critical points are x = 2 and x = 4 -/
axiom critical_points : f_deriv x = 0 ↔ x = 2 ∨ x = 4

/-- Lemma: Second derivative test -/
axiom second_derivative_test (x : ℝ) (h : f_deriv x = 0) :
  (x = 2 ∧ f_second_deriv x < 0) ∨ (x = 4 ∧ f_second_deriv x > 0)

/-- Theorem: f(x) has a local maximum at x = 2 -/
theorem local_max_at_2 : IsLocalMax f 2 :=


import Mathlib

/-
Let $f(x) = x^3-9x^2+24x$ be a real-valued function defined on $\mathbb{R}$. Then:
  1. $f(x)$ has a local maximum at $x=2$.
  2. $f(x)$ has a local minimum at $x=4$.
  3. These are the only local extrema of $f(x)$ on $\mathbb{R}$.
-/

open Real

variable (x : ℝ)

/-- The cubic polynomial f(x) = x³ - 9x² + 24x -/
noncomputable def f (x : ℝ) : ℝ := x^3 - 9*x^2 + 24*x

/-- The first derivative f'(x) = 3x² - 18x + 24 -/
noncomputable def f_deriv (x : ℝ) : ℝ := 3*x^2 - 18*x + 24

/-- The second derivative f''(x) = 6x - 18 -/
noncomputable def f_second_deriv (x : ℝ) : ℝ := 6*x - 18

/-- Lemma: Critical points are x = 2 and x = 4 -/
axiom critical_points : f_deriv x = 0 ↔ x = 2 ∨ x = 4

/-- Lemma: Second derivative test -/
axiom second_derivative_test (x : ℝ) (h : f_deriv x = 0) :
  (x = 2 ∧ f_second_deriv x < 0) ∨ (x = 4 ∧ f_second_deriv x > 0)

/-- Theorem: f(x) has a local maximum at x = 2 -/
axiom local_max_at_2 : IsLocalMax f 2

/-- Theorem: f(x) has a local minimum at x = 4 -/
theorem local_min_at_4 : IsLocalMin f 4 :=


import Mathlib

/-
Let $f(x) = x^3-9x^2+24x$ be a real-valued function defined on $\mathbb{R}$. Then:
  1. $f(x)$ has a local maximum at $x=2$.
  2. $f(x)$ has a local minimum at $x=4$.
  3. These are the only local extrema of $f(x)$ on $\mathbb{R}$.
-/

open Real

variable (x : ℝ)

/-- The cubic polynomial f(x) = x³ - 9x² + 24x -/
noncomputable def f (x : ℝ) : ℝ := x^3 - 9*x^2 + 24*x

/-- The first derivative f'(x) = 3x² - 18x + 24 -/
noncomputable def f_deriv (x : ℝ) : ℝ := 3*x^2 - 18*x + 24

/-- The second derivative f''(x) = 6x - 18 -/
noncomputable def f_second_deriv (x : ℝ) : ℝ := 6*x - 18

/-- Lemma: Critical points are x = 2 and x = 4 -/
axiom critical_points : f_deriv x = 0 ↔ x = 2 ∨ x = 4

/-- Lemma: Second derivative test -/
axiom second_derivative_test (x : ℝ) (h : f_deriv x = 0) :
  (x = 2 ∧ f_second_deriv x < 0) ∨ (x = 4 ∧ f_second_deriv x > 0)

/-- Theorem: f(x) has a local maximum at x = 2 -/
axiom local_max_at_2 : IsLocalMax f 2

/-- Theorem: f(x) has a local minimum at x = 4 -/
axiom local_min_at_4 : IsLocalMin f 4

/-- Theorem: x = 2 and x = 4 are the only local extrema of f(x) -/
theorem only_local_extrema (x : ℝ) :
IsLocalMax f x ∨ IsLocalMin f x → x = 2 ∨ x = 4 :=


import Mathlib

/-
Let $f(x) = x^3-9x^2+24x$ be a real-valued function defined on $\mathbb{R}$. Then:
  1. $f(x)$ has a local maximum at $x=2$.
  2. $f(x)$ has a local minimum at $x=4$.
  3. These are the only local extrema of $f(x)$ on $\mathbb{R}$.
-/

open Real

variable (x : ℝ)

/-- The cubic polynomial f(x) = x³ - 9x² + 24x -/
noncomputable def f (x : ℝ) : ℝ := x^3 - 9*x^2 + 24*x

/-- The first derivative f'(x) = 3x² - 18x + 24 -/
noncomputable def f_deriv (x : ℝ) : ℝ := 3*x^2 - 18*x + 24

/-- The second derivative f''(x) = 6x - 18 -/
noncomputable def f_second_deriv (x : ℝ) : ℝ := 6*x - 18

/-- Lemma: Critical points are x = 2 and x = 4 -/
axiom critical_points : f_deriv x = 0 ↔ x = 2 ∨ x = 4

/-- Lemma: Second derivative test -/
axiom second_derivative_test (x : ℝ) (h : f_deriv x = 0) :
  (x = 2 ∧ f_second_deriv x < 0) ∨ (x = 4 ∧ f_second_deriv x > 0)

/-- Theorem: f(x) has a local maximum at x = 2 -/
axiom local_max_at_2 : IsLocalMax f 2

/-- Theorem: f(x) has a local minimum at x = 4 -/
axiom local_min_at_4 : IsLocalMin f 4

/-- Theorem: x = 2 and x = 4 are the only local extrema of f(x) -/
axiom only_local_extrema (x : ℝ) :
IsLocalMax f x ∨ IsLocalMin f x → x = 2 ∨ x = 4

/-- Theorem: Local extrema of f(x) -/
theorem local_extrema :
  (∃ x, IsLocalMax f x) ∧ (∃ x, IsLocalMin f x) ∧
(∀ x, IsLocalMax f x ∨ IsLocalMin f x → x = 2 ∨ x = 4) :=


import Mathlib

/-
The integral of \(x^p\) with respect to \(x\) where \(p\) is a real number different from -1, is given by \(\frac{x^{p+1}}{p+1} + C\).
-/

theorem integral_of_power_function (p : ℝ) (hp : p ≠ -1) :
∫ x in Set.Icc 0 1, x^p = (1^(p+1) - 0^(p+1)) / (p+1) :=


import Mathlib

/-
The indefinite integral \(\int \frac{\sin\sqrt{x}}{\sqrt{x}}\,dx\) is equal to \(-2 \cos (\sqrt{x}) + C\).
-/

open Real

theorem sin_sqrt_x_over_sqrt_x_integral (x C: ℝ):
∫ (x : ℝ), sin (sqrt x) / sqrt x = -2 * cos (sqrt x) + C :=


import Mathlib

/-
The points (x,y) on the curve \(x^2+y^2=1\) for which the quantity \(f(x,y)=xy\) is maximal are
\((x,y)\in\left\{\left(\frac1{\sqrt 2},\frac1{\sqrt2}\right),
\left(-\frac1{\sqrt 2},-\frac1{\sqrt 2}\right)\right\}\) and the maximum of \(f\) is \(\frac12\).
-/

open Real

variable (x y : ℝ)

theorem max_xy_on_unit_circle :
  (x^2 + y^2 = 1) → (x * y ≤ 1 / 2) ∧ ((x = 1 / sqrt 2 ∧ y = 1 / sqrt 2) ∨ (x = -1 / sqrt 2 ∧ y = -1 / sqrt 2)) → (x * y = 1 / 2) :=


import Mathlib

/-
The integral \(\displaystyle \int \sin^{10}x\cos x \,dx\) is equal to
\(\frac{\sin^{11} x}{11} + C\), where C is the constant of integration.
-/

open Real

theorem integral_sin_pow_ten_cos (x C: ℝ) :
∫ x , (sin x)^10 * cos x = (sin x)^11 / 11 +C :=


import Mathlib

/-
The derivative of the function \(f(x)=e^{-\frac{x^2}2}\) is \(f^{\prime}(x)=-xe^{-\frac{x^2}2}\).
-/

open Real

theorem derivative_of_exponential_function :
  deriv (fun x => exp (-x^2 / 2)) = fun x => -x * exp (-x^2 / 2) :=


import Mathlib

/-
The limit of the function \(\displaystyle \lim_{x\to0}\frac{ e^{8x}-1}{x}\) is 8.
-/

open Filter Topology

variable (x : ℝ)

theorem limit_of_function : Tendsto (fun x => (Real.exp (8 * x) - 1) / x) (𝓝[Set.Ioi 0] 0) (𝓝 8) :=


import Mathlib

/-
The integral \(\displaystyle \int \sin^3 x\cos^{6}x\,dx\) is equal to -\frac{\cos^9x}9+\frac{\cos^{11}x}{11}+C.
-/

open Real

theorem integral_sin_cube_cos_sixth (x : ℝ) :
  ∫ (x : ℝ), sin x ^ 3 * cos x ^ 6 = -cos x ^ 9 / 9 + cos x ^ 11 / 11 + C :=


import Mathlib

/-
Let $y(t) = 40t - 16t^2$ represent the height in feet of a ball $t$ seconds after being thrown vertically upward with an initial velocity of 40 ft/s. Then the average velocity $v_{avg}$ of the ball over the time interval $[2, 2.5]$ seconds is given by:

    $v_{avg} = \frac{y(2.5) - y(2)}{2.5 - 2} = -32 \text{ ft/s}$
-/

open Real

noncomputable def heightFunction (t : ℝ) : ℝ := 40 * t - 16 * t^2

lemma heightAtTwo : heightFunction 2 = 16 :=


import Mathlib

/-
Let $y(t) = 40t - 16t^2$ represent the height in feet of a ball $t$ seconds after being thrown vertically upward with an initial velocity of 40 ft/s. Then the average velocity $v_{avg}$ of the ball over the time interval $[2, 2.5]$ seconds is given by:

    $v_{avg} = \frac{y(2.5) - y(2)}{2.5 - 2} = -32 \text{ ft/s}$
-/

open Real

noncomputable def heightFunction (t : ℝ) : ℝ := 40 * t - 16 * t^2

axiom heightAtTwo : heightFunction 2 = 16

lemma heightAtTwoPointFive : heightFunction 2.5 = 0 :=


import Mathlib

/-
Let $y(t) = 40t - 16t^2$ represent the height in feet of a ball $t$ seconds after being thrown vertically upward with an initial velocity of 40 ft/s. Then the average velocity $v_{avg}$ of the ball over the time interval $[2, 2.5]$ seconds is given by:

    $v_{avg} = \frac{y(2.5) - y(2)}{2.5 - 2} = -32 \text{ ft/s}$
-/

open Real

noncomputable def heightFunction (t : ℝ) : ℝ := 40 * t - 16 * t^2

axiom heightAtTwo : heightFunction 2 = 16

axiom heightAtTwoPointFive : heightFunction 2.5 = 0

theorem averageVelocity : (heightFunction 2.5 - heightFunction 2) / (2.5 - 2) = -32 :=


import Mathlib

/-
Let $y(t) = 40t - 16t^2$ represent the height in feet of a ball $t$ seconds after being thrown vertically upward with an initial velocity of 40 ft/s. Then the average velocity $v_{avg}$ of the ball over the time interval $[2, 2.5]$ seconds is given by:

    $v_{avg} = \frac{y(2.5) - y(2)}{2.5 - 2} = -32 \text{ ft/s}$
-/

open Real

noncomputable def heightFunction (t : ℝ) : ℝ := 40 * t - 16 * t^2

axiom heightAtTwo : heightFunction 2 = 16

axiom heightAtTwoPointFive : heightFunction 2.5 = 0

axiom averageVelocity : (heightFunction 2.5 - heightFunction 2) / (2.5 - 2) = -32

theorem graphSatisfiesAvgVelocity :
(2.5 - 2) * -32 = heightFunction 2.5 - heightFunction 2 :=


import Mathlib

/-
The limit of the function \[\lim_{x\to 0}\frac{1-(\cos x)^{\sin x}}{x^3}\] is 1/2.
-/

open Filter Topology

theorem limit_of_function_at_zero :
  Tendsto (fun x => (1 - (Real.cos x)^(Real.sin x)) / x^3) (𝓝 0) (𝓝 (1 / 2)) :=


import Mathlib

/-
The integral \(\displaystyle \int \frac{2\sin^3x+\sin^2x\cos x-4\sin x\cos^2x+3\cos^3x}{\left(\sin^2x-\sin x\cos x-2\cos^2x\right)\cos x}\,dx\) is equal to \(\ln\left|\tan x-2\right|-\ln\left|\tan x+1\right|-2\ln\left|\cos x\right|+C\).
-/

-- Define the integral function
noncomputable def integralFunction (x : ℝ) : ℝ :=
  (2 * Real.sin x ^ 3 + Real.sin x ^ 2 * Real.cos x - 4 * Real.sin x * Real.cos x ^ 2 + 3 * Real.cos x ^ 3) / ((Real.sin x ^ 2 - Real.sin x * Real.cos x - 2 * Real.cos x ^ 2) * Real.cos x)

-- Theorem statement

theorem trigonometric_integral_result :
∀ x : ℝ, ∃ C : ℝ, ∫ x, integralFunction x = Real.log (abs (Real.tan x - 2)) - Real.log (abs (Real.tan x + 1)) - 2 * Real.log (abs (Real.cos x)) + C :=


import Mathlib

/-
The evaluated integral of \(\displaystyle \int \sqrt{x -5}\,dx\) is \(\frac{2}{3} (x - 5)^{3/2} + C\).
-/

-- Define the theorem statement

theorem integral_sqrt_x_minus_5 (x : ℝ) :
  ∫ (x : ℝ), Real.sqrt (x - 5) = (2 / 3) * (x - 5) ^ (3 / 2) + C :=


import Mathlib

/-
The indefinite integral \[\int \frac{x}{x^2+1}\,dx\] is equal to \[\frac12\ln(x^2+1)+C.\]
-/

-- Define the function to be integrated
noncomputable def integrand (x : ℝ) : ℝ := x / (x^2 + 1)

-- Theorem statement

theorem integral_of_integrand2 : ∃ F : ℝ → ℝ, ∀ x : ℝ, (deriv F x = integrand x) ∧ F x = (1 / 2) * Real.log (x^2 + 1) + C :=


import Mathlib

/-
For all real numbers x, the cosine function cos(x) can be expressed as the following infinite series:

    $\cos(x) = \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n)!} x^{2n}$

    where this series converges for all x in the interval (-∞, +∞).
-/

open Real

variable (x : ℝ)

/-- The Taylor series expansion of cos(x) -/
noncomputable def cos_taylor_series (x : ℝ) : ℝ := ∑' (n : ℕ), ((-1 : ℝ)^n / (2 * n).factorial) * x^(2 * n)

/-- Proof that the Taylor series of cos(x) converges for all real numbers x -/
lemma cos_taylor_series_converges (x : ℝ) : HasSum (λ n : ℕ => ((-1 : ℝ)^n / (2 * n).factorial) * x^(2 * n)) (cos x) :=


import Mathlib

/-
For all real numbers x, the cosine function cos(x) can be expressed as the following infinite series:

    $\cos(x) = \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n)!} x^{2n}$

    where this series converges for all x in the interval (-∞, +∞).
-/

open Real

variable (x : ℝ)

/-- The Taylor series expansion of cos(x) -/
noncomputable def cos_taylor_series (x : ℝ) : ℝ := ∑' (n : ℕ), ((-1 : ℝ)^n / (2 * n).factorial) * x^(2 * n)

/-- Proof that the Taylor series of cos(x) converges for all real numbers x -/
axiom cos_taylor_series_converges (x : ℝ) : HasSum (λ n : ℕ => ((-1 : ℝ)^n / (2 * n).factorial) * x^(2 * n)) (cos x)

/-- The cosine function can be expressed as the infinite series -/
theorem cos_infinite_series (x : ℝ) : cos x = cos_taylor_series x :=


import Mathlib

/-
The integral \[\int_{-1}^1 \frac{x^2}{1+x^2}\,dx\] is equal to \[2-\frac{\pi}2.\]
-/

open Real
open MeasureTheory

theorem integral_of_rational_function_over_interval :
∫ x in Set.Icc (-1) 1, (x^2 / (1 + x^2)) = 2 - π / 2 :=


import Mathlib

/-
The integral \[\int_0^{\frac{\pi}2} x\sin x\,dx.\] is equal to 1.
-/

open Real Set Filter

variable {f : ℝ → ℝ}

theorem integral_x_sin_x_pi_over_2 :
∫ x in Icc 0 (π / 2), x * sin x = 1 :=


import Mathlib

/-
The integral of \(\displaystyle \int_0^{\frac{\pi}4}\frac{ 3\sin x +2 \cos x}{ 4\sin x+ 3\cos x} \,dx\) is equal to \(\frac{1}{50} \ln 2 -\frac{1}{25} \ln \frac{7}{3} + \frac{9\pi}{50}\).
-/

open Real

variable (x : ℝ)

theorem integral_of_trig_rational_function :
∫ x in Set.Icc 0 (π / 4), (3 * sin x + 2 * cos x) / (4 * sin x + 3 * cos x) =
    (1 / 50) * log 2 - (1 / 25) * log (7 / 3) + (9 * π) / 50 :=


import Mathlib

/-
The integral of \(\sec x\,dx=\int\frac1{\cos x}\,dx\) equals to \ln\left|\sec x+\tan x\right|+C.
-/

-- Define the theorem statement

theorem sec_integral (x : ℝ) :
  ∫ t in Set.Icc 0 x, (1 / Real.cos t) = Real.log (abs (1 / Real.cos x + Real.sin x / Real.cos x)) + C :=


import Mathlib

/-
The integral of 4/(x^2 -7x +12) from 100 to 200 is equal to 4 * log(196/96) - 4 * log(197/97).
-/

open Real Filter

variable {a b : ℝ} (h_a : a = 100) (h_b : b = 200)

theorem integral_of_rational_function :
∫ x in a..b, (4 : ℝ) / (x^2 - 7*x + 12) = 4 * log (196 / 96) - 4 * log (197 / 97) :=


import Mathlib

/-
The function \(f(x) = x + 2\sin x\) attains its minimum at \( x = \frac{4\pi}{3} \) on the interval \(\left[\frac{\pi}{2}, 200\right]\).
-/

open Real

/-- The function f(x) = x + 2sin(x) -/
noncomputable def f (x : ℝ) : ℝ := x + 2 * sin x

theorem minimum_attainment_of_function :
  ∀ x ∈ Set.Icc (π / 2) 200, f (4 * π / 3) ≤ f x :=


import Mathlib

/-
If \(f(x)=2^x\) and \(g(x)=5\cdot x-6\), then the function \(h(x)=f(g(x))=2^{5x-6}\) results in \(h(3)=2^{5\cdot 3-6}=2^{9}=512\), and function \(m(x)=g(f(x))=5\cdot 2^x-6\) results in \(m(3)=5\cdot 2^3-6=5\cdot 8-6=34\).
-/

/-- The exponential function with base a, f(x) = a^x -/
noncomputable def f (a : ℝ) (x : ℝ) : ℝ := a^x

/-- The linear function g(x) = mx + b -/
noncomputable def g (m b : ℝ) (x : ℝ) : ℝ := m * x + b

/-- The composition h(x) = f(g(x)) = a^(mx + b) -/
noncomputable def h (a m b : ℝ) (x : ℝ) : ℝ := f a (g m b x)

/-- The composition m(x) = g(f(x)) = m * a^x + b -/
noncomputable def m_comp (a m b : ℝ) (x : ℝ) : ℝ := g m b (f a x)

/-- Specific example where a = 2, m = 5, b = -6, and x = 3 -/
theorem specific_example :
  h 2 5 (-6) 3 = 512 ∧ m_comp 2 5 (-6) 3 = 34 :=


import Mathlib

/-
The maximum value of \[\int_0^1 \left(x^2f(x)-xf^2(x)\right)\,dx\] over all continuous functions \(f:[0,1]\to\mathbb R\) is \(\frac{1}{16}\).
-/

open Filter Topology

variable {f : ℝ → ℝ} (hf : Continuous f)

theorem max_integral_value :
IsMaxOn (fun f => ∫ x in Set.Icc 0 1, (x^2 * f x - x * f x^2)) {f | Continuous f} f →
(∫ x in Set.Icc 0 1, (x^2 * f x - x * f x^2)) = 1/16 :=


import Mathlib

/-
Let $f(x) = \frac{x+1}{\sqrt{5x^2+35}}$ be a function defined on $\mathbb{R}$. Then $f(x)$ is concave up on the intervals $(-\infty, \frac{21-\sqrt{497}}{4})$ and $(\frac{21+\sqrt{497}}{4}, \infty)$.
-/

open Real

variable (x : ℝ)

/-- The function f(x) = (x + 1) / sqrt(5x^2 + 35) -/
noncomputable def f (x : ℝ) : ℝ := (x + 1) / sqrt (5 * x^2 + 35)

/-- The first derivative of f(x) -/
lemma f_deriv (x : ℝ) : deriv f x = (35 - 5 * x^2) / ((5 * x^2 + 35) * sqrt (5 * x^2 + 35)) :=


import Mathlib

/-
Let $f(x) = \frac{x+1}{\sqrt{5x^2+35}}$ be a function defined on $\mathbb{R}$. Then $f(x)$ is concave up on the intervals $(-\infty, \frac{21-\sqrt{497}}{4})$ and $(\frac{21+\sqrt{497}}{4}, \infty)$.
-/

open Real

variable (x : ℝ)

/-- The function f(x) = (x + 1) / sqrt(5x^2 + 35) -/
noncomputable def f (x : ℝ) : ℝ := (x + 1) / sqrt (5 * x^2 + 35)

/-- The first derivative of f(x) -/
axiom f_deriv (x : ℝ) : deriv f x = (35 - 5 * x^2) / ((5 * x^2 + 35) * sqrt (5 * x^2 + 35))

/-- The second derivative of f(x) -/
lemma f_second_deriv (x : ℝ) : deriv (deriv f) x = (50 * x^2 - 525 * x - 175) / ((5 * x^2 + 35)^(5/2)) :=


import Mathlib

/-
Let $f(x) = \frac{x+1}{\sqrt{5x^2+35}}$ be a function defined on $\mathbb{R}$. Then $f(x)$ is concave up on the intervals $(-\infty, \frac{21-\sqrt{497}}{4})$ and $(\frac{21+\sqrt{497}}{4}, \infty)$.
-/

open Real

variable (x : ℝ)

/-- The function f(x) = (x + 1) / sqrt(5x^2 + 35) -/
noncomputable def f (x : ℝ) : ℝ := (x + 1) / sqrt (5 * x^2 + 35)

/-- The first derivative of f(x) -/
axiom f_deriv (x : ℝ) : deriv f x = (35 - 5 * x^2) / ((5 * x^2 + 35) * sqrt (5 * x^2 + 35))

/-- The second derivative of f(x) -/
axiom f_second_deriv (x : ℝ) : deriv (deriv f) x = (50 * x^2 - 525 * x - 175) / ((5 * x^2 + 35)^(5/2))

/-- The critical points of f''(x) -/
lemma critical_points : ∃ a b : ℝ, a < b ∧
  a = (21 - sqrt 497) / 4 ∧
  b = (21 + sqrt 497) / 4 ∧
  ∀ x, deriv (deriv f) x = 0 ↔ x = a ∨ x = b :=


import Mathlib

/-
Let $f(x) = \frac{x+1}{\sqrt{5x^2+35}}$ be a function defined on $\mathbb{R}$. Then $f(x)$ is concave up on the intervals $(-\infty, \frac{21-\sqrt{497}}{4})$ and $(\frac{21+\sqrt{497}}{4}, \infty)$.
-/

open Real

variable (x : ℝ)

/-- The function f(x) = (x + 1) / sqrt(5x^2 + 35) -/
noncomputable def f (x : ℝ) : ℝ := (x + 1) / sqrt (5 * x^2 + 35)

/-- The first derivative of f(x) -/
axiom f_deriv (x : ℝ) : deriv f x = (35 - 5 * x^2) / ((5 * x^2 + 35) * sqrt (5 * x^2 + 35))

/-- The second derivative of f(x) -/
axiom f_second_deriv (x : ℝ) : deriv (deriv f) x = (50 * x^2 - 525 * x - 175) / ((5 * x^2 + 35)^(5/2))

/-- The critical points of f''(x) -/
axiom critical_points : ∃ a b : ℝ, a < b ∧
  a = (21 - sqrt 497) / 4 ∧
  b = (21 + sqrt 497) / 4 ∧
  ∀ x, deriv (deriv f) x = 0 ↔ x = a ∨ x = b

/-- f(x) is concave up on the intervals (-∞, (21 - √497)/4) and ((21 + √497)/4, ∞) -/
theorem concave_up_intervals : ∃ a b : ℝ, a < b ∧
  (∀ x < a, deriv (deriv f) x > 0) ∧
  (∀ x > b, deriv (deriv f) x > 0) ∧
  a = (21 - sqrt 497) / 4 ∧
  b = (21 + sqrt 497) / 4 :=


import Mathlib

/-
The critical values of the function \( f(x) = 2x^3 - 3x^2 - 36x + 18 \) are \( x = -2 \) and \( x = 3 \).
-/

open Polynomial

/-- The cubic polynomial f(x) = 2x³ - 3x² - 36x + 18 -/
noncomputable def f_poly : Polynomial ℝ :=
  2 * X^3 - 3 * X^2 - 36 * X + 18

/-- Convert polynomial to function -/
noncomputable def f (x : ℝ) : ℝ := f_poly.eval x

/-- The derivative polynomial -/
noncomputable def f_deriv_poly : Polynomial ℝ :=
  (2 * 3) * X^2 - (3 * 2) * X - 36

/-- The derivative as a function -/
noncomputable def f_deriv (x : ℝ) : ℝ := f_deriv_poly.eval x

/-- The critical values of f(x) are x = -2 and x = 3 -/
def critical_values_of_cubic (x : ℝ) : Prop :=
  f_deriv x = 0 ↔ x = -2 ∨ x = 3

/-- Verification of the critical values -/
theorem verify_critical_values :
  ∀ x, critical_values_of_cubic x :=


import Mathlib

/-
The integral \[\iint_{R}f(x,y)\,dxdy,\] where \(f(x,y)=11-2x-3y^2\) and \(R\) is the rectangle \([1,3]\times[-2,5]\) is equal to -168.
-/

open Set Filter MeasureTheory

variable (f : ℝ → ℝ → ℝ) (R : Set (ℝ × ℝ))

theorem integral_over_rectangle_equals_minus_168 :
  let f := fun x y => 11 - 2 * x - 3 * y^2
  let R := Icc (1 : ℝ) (3 : ℝ) ×ˢ Icc (-2 : ℝ) (5 : ℝ)
  ∫ x in Icc (1 : ℝ) (3 : ℝ), ∫ y in Icc (-2 : ℝ) (5 : ℝ), f x y = -168 :=


import Mathlib

/-
The limit of the function \(\displaystyle \lim_{x\to 0}\frac{\sin\left(3x+x^2\right)}{5x+2x^2}\) equals to \(\frac{3}{5}\).
-/

open Filter Topology

theorem limit_of_function_at_zero :
Tendsto (fun x => Real.sin (3 * x + x^2) / (5 * x + 2 * x^2)) (𝓝 0) (𝓝 (3 / 5)) :=


import Mathlib

/-
The limit of the function \(f(x)=\frac{ 3^{x}-1}{x}\) as \(x\) approaches 0 is \(\ln 3\).
-/

open Filter Topology

theorem limit_of_function_as_x_approaches_zero :
  Tendsto (fun x => (3^x - 1) / x) (𝓝[≠] 0) (𝓝 (Real.log 3)) :=


import Mathlib

/-
The integral \(\displaystyle \int \frac{x}{\sqrt{49-x^2}}\,dx\) evaluates to \(-\sqrt{49-x^2}+C.\)
-/

-- Define the function as noncomputable
noncomputable def f (x : ℝ) : ℝ := x / Real.sqrt (49 - x^2)

-- Theorem statement

theorem integral_f_eq (x C : ℝ):  ∫  x, f x = -Real.sqrt (49 - x^2) + C :=


import Mathlib

/-
The indefinite integral of cos(5x) with respect to x is 1/5 sin(5x) + C.
-/

theorem cos_5x_indefinite_integral {f : ℝ → ℝ}
    (hf : Continuous f)
    (h_diff : ∀ x, DifferentiableAt ℝ f x)
    (h_deriv : ∀ x, deriv f x = (1 / 5 : ℝ) * Real.sin (5 * x)) :
    ∃ C, ∀ x, f x = (1 / 5 : ℝ) * Real.sin (5 * x) + C :=


import Mathlib

/- For the equation cos(2x) - √3 sin(2x) = √2, there exist exactly four solutions
   in the interval [0, 2π), namely x = 0, x = π/3, x = π, and x = 4π/3. -/

/-- The left side of the equation cos(2x) - √3 sin(2x) = √2 -/
noncomputable def equation (x : ℝ) : ℝ :=
  Real.cos (2 * x) - Real.sqrt 3 * Real.sin (2 * x)

/-- The equation can be rewritten as 2cos(2x + π/3) = √2 -/
lemma simplified_equation (x : ℝ) :
  equation x = 2 * Real.cos (2 * x + Real.pi / 3) - Real.sqrt 2 :=


import Mathlib

/- For the equation cos(2x) - √3 sin(2x) = √2, there exist exactly four solutions
   in the interval [0, 2π), namely x = 0, x = π/3, x = π, and x = 4π/3. -/

/-- The left side of the equation cos(2x) - √3 sin(2x) = √2 -/
noncomputable def equation (x : ℝ) : ℝ :=
  Real.cos (2 * x) - Real.sqrt 3 * Real.sin (2 * x)

/-- The equation can be rewritten as 2cos(2x + π/3) = √2 -/
axiom simplified_equation (x : ℝ) :
  equation x = 2 * Real.cos (2 * x + Real.pi / 3) - Real.sqrt 2

/-- The set of solutions in [0, 2π) -/
noncomputable def solution_set : Finset ℝ :=
  {0, Real.pi / 3, Real.pi, 4 * Real.pi / 3}

/-- Verify each solution lies in [0, 2π) -/
lemma solutions_in_interval :
  ∀ x ∈ solution_set, x ∈ Set.Ico 0 (2 * Real.pi) :=


import Mathlib

/- For the equation cos(2x) - √3 sin(2x) = √2, there exist exactly four solutions
   in the interval [0, 2π), namely x = 0, x = π/3, x = π, and x = 4π/3. -/

/-- The left side of the equation cos(2x) - √3 sin(2x) = √2 -/
noncomputable def equation (x : ℝ) : ℝ :=
  Real.cos (2 * x) - Real.sqrt 3 * Real.sin (2 * x)

/-- The equation can be rewritten as 2cos(2x + π/3) = √2 -/
axiom simplified_equation (x : ℝ) :
  equation x = 2 * Real.cos (2 * x + Real.pi / 3) - Real.sqrt 2

/-- The set of solutions in [0, 2π) -/
noncomputable def solution_set : Finset ℝ :=
  {0, Real.pi / 3, Real.pi, 4 * Real.pi / 3}

/-- Verify each solution lies in [0, 2π) -/
axiom solutions_in_interval :
  ∀ x ∈ solution_set, x ∈ Set.Ico 0 (2 * Real.pi)

/-- Verify each solution satisfies the equation -/
lemma solutions_satisfy_equation :
  ∀ x ∈ solution_set, equation x = 0 :=


import Mathlib

/- For the equation cos(2x) - √3 sin(2x) = √2, there exist exactly four solutions
   in the interval [0, 2π), namely x = 0, x = π/3, x = π, and x = 4π/3. -/

/-- The left side of the equation cos(2x) - √3 sin(2x) = √2 -/
noncomputable def equation (x : ℝ) : ℝ :=
  Real.cos (2 * x) - Real.sqrt 3 * Real.sin (2 * x)

/-- The equation can be rewritten as 2cos(2x + π/3) = √2 -/
axiom simplified_equation (x : ℝ) :
  equation x = 2 * Real.cos (2 * x + Real.pi / 3) - Real.sqrt 2

/-- The set of solutions in [0, 2π) -/
noncomputable def solution_set : Finset ℝ :=
  {0, Real.pi / 3, Real.pi, 4 * Real.pi / 3}

/-- Verify each solution lies in [0, 2π) -/
axiom solutions_in_interval :
  ∀ x ∈ solution_set, x ∈ Set.Ico 0 (2 * Real.pi)

/-- Verify each solution satisfies the equation -/
axiom solutions_satisfy_equation :
  ∀ x ∈ solution_set, equation x = 0

/-- Any solution in [0, 2π) must be one of our four solutions -/
lemma all_solutions_found (x : ℝ) (h : x ∈ Set.Ico 0 (2 * Real.pi)) :
  equation x = 0 → x ∈ solution_set :=


import Mathlib

/- For the equation cos(2x) - √3 sin(2x) = √2, there exist exactly four solutions
   in the interval [0, 2π), namely x = 0, x = π/3, x = π, and x = 4π/3. -/

/-- The left side of the equation cos(2x) - √3 sin(2x) = √2 -/
noncomputable def equation (x : ℝ) : ℝ :=
  Real.cos (2 * x) - Real.sqrt 3 * Real.sin (2 * x)

/-- The equation can be rewritten as 2cos(2x + π/3) = √2 -/
axiom simplified_equation (x : ℝ) :
  equation x = 2 * Real.cos (2 * x + Real.pi / 3) - Real.sqrt 2

/-- The set of solutions in [0, 2π) -/
noncomputable def solution_set : Finset ℝ :=
  {0, Real.pi / 3, Real.pi, 4 * Real.pi / 3}

/-- Verify each solution lies in [0, 2π) -/
axiom solutions_in_interval :
  ∀ x ∈ solution_set, x ∈ Set.Ico 0 (2 * Real.pi)

/-- Verify each solution satisfies the equation -/
axiom solutions_satisfy_equation :
  ∀ x ∈ solution_set, equation x = 0

/-- Any solution in [0, 2π) must be one of our four solutions -/
axiom all_solutions_found (x : ℝ) (h : x ∈ Set.Ico 0 (2 * Real.pi)) :
  equation x = 0 → x ∈ solution_set

/-- There are exactly four solutions in [0, 2π) -/
theorem exactly_four_solutions :
  ∃! (s : Finset ℝ), s.card = 4 ∧
    (∀ x ∈ s, x ∈ Set.Ico 0 (2 * Real.pi) ∧ equation x = 0) ∧
    (∀ x, x ∈ Set.Ico 0 (2 * Real.pi) ∧ equation x = 0 → x ∈ s) :=


import Mathlib

/-
The derivative of the function g(x) = cos(x) is g'(x) = -sin(x).
-/

theorem cos_derivative : deriv (fun x => Real.cos x) = fun x => -Real.sin x :=


import Mathlib

/-
The indefinite integral \[\int_1^5 x\ln x\,dx\] is equivalent to \[\frac{25\ln 5-12}2. \]
-/

open Real
open MeasureTheory

theorem integral_x_ln_x_over_interval :
∫ x in Set.Icc 1 5, x * log x = (25 * log 5 - 12) / 2 :=


import Mathlib

/-
The integral \(\displaystyle \int \sqrt[3]{\cos x}\cdot \sin^3x\,dx\) can be evaluated as \(-\frac34 \cos^{\frac43}x+\frac{3}{10}\cos^{\frac{10}3}x+C\), by substituting \(u=\cos x\) and integring term by term.
-/

open Real

theorem integral_of_cube_root_cos_sin_cube (x : ℝ) :
∫ x in Set.Icc 0 x, (cos x)^(1/3 : ℝ) * (sin x)^3 =
  - (3/4) * (cos x)^(4/3 : ℝ) + (3/10) * (cos x)^(10/3 : ℝ) + C :=


import Mathlib

/-
The integral \[\iiint_S z\,dxdydz,\] where \(S\) is a triangular prism bounded by the planes \(x=0\), \(y=0\), \(z=0\), \(x=5\), and \(y+z=1\), is equal to \(\frac{5}{6}\).
-/

open MeasureTheory
open Real

variable {S : Set (ℝ × ℝ × ℝ)}

theorem integral_over_triangular_prism :(∫⁻ (p : ℝ × ℝ × ℝ) in {p : ℝ × ℝ × ℝ | p.1 ∈ Set.Icc 0 5 ∧ p.2.1 ∈ Set.Icc 0 1 ∧
  p.2.2 ∈ Set.Icc 0 1 ∧ p.2.1 + p.2.2 ≤ 1}, ENNReal.ofReal p.2.2) = 5 / 6 :=


import Mathlib

/-
Let $f$ be a function defined by $f(x)=\frac{\sqrt{-1-x}}{\log _{\frac{1}{2}}(x)}$. Then the domain of $f$ is the empty set, i.e., $\text{Dom}(f) = \emptyset$.
-/

open Real Set

/-- The function f(x) = √(-1-x) / log₁/₂(x) -/
noncomputable def f (x : ℝ) : ℝ :=
sqrt (-1 - x) / logb (1/2) x

/-- The domain of f is empty -/
def Dom : Set ℝ := {x | -1 - x ≥ 0 ∧ x > 0}


import Mathlib

/-
For any real number $x$, the inequality $2.3 < -\log(x) < 5.4$ is satisfied if and only if $x \in \left(10^{-5.4}, 10^{-2.3}\right)$.
-/

open Real

variable (x : ℝ)

/-- The logarithmic inequality: 2.3 < -log 10 x < 5.4 -/
def log_inequality (x : ℝ) : Prop := 2.3 < -logb 10 x ∧ -logb 10 x < 5.4

/-- The interval (10^-5.4, 10^-2.3) -/
def target_interval : Set ℝ := Set.Ioo (10^(-5.4 : ℝ)) (10^(-2.3 : ℝ))

lemma log_inequality_of_in_interval (h : x ∈ target_interval) : log_inequality x :=


import Mathlib

/-
For any real number $x$, the inequality $2.3 < -\log(x) < 5.4$ is satisfied if and only if $x \in \left(10^{-5.4}, 10^{-2.3}\right)$.
-/

open Real

variable (x : ℝ)

/-- The logarithmic inequality: 2.3 < -log 10 x < 5.4 -/
def log_inequality (x : ℝ) : Prop := 2.3 < -logb 10 x ∧ -logb 10 x < 5.4

/-- The interval (10^-5.4, 10^-2.3) -/
def target_interval : Set ℝ := Set.Ioo (10^(-5.4 : ℝ)) (10^(-2.3 : ℝ))

axiom log_inequality_of_in_interval (h : x ∈ target_interval) : log_inequality x

lemma in_interval_of_log_inequality (h : log_inequality x) : x ∈ target_interval :=


import Mathlib

/-
For any real number $x$, the inequality $2.3 < -\log(x) < 5.4$ is satisfied if and only if $x \in \left(10^{-5.4}, 10^{-2.3}\right)$.
-/

open Real

variable (x : ℝ)

/-- The logarithmic inequality: 2.3 < -log 10 x < 5.4 -/
def log_inequality (x : ℝ) : Prop := 2.3 < -logb 10 x ∧ -logb 10 x < 5.4

/-- The interval (10^-5.4, 10^-2.3) -/
def target_interval : Set ℝ := Set.Ioo (10^(-5.4 : ℝ)) (10^(-2.3 : ℝ))

axiom log_inequality_of_in_interval (h : x ∈ target_interval) : log_inequality x

axiom in_interval_of_log_inequality (h : log_inequality x) : x ∈ target_interval

/-- The inequality 2.3 < -log 10 x < 5.4 is satisfied if and only if x ∈ (10^-5.4, 10^-2.3). -/
theorem log_inequality_iff : log_inequality x ↔ x ∈ target_interval :=


import Mathlib

/-
Let $f: (-1, 1) \to \mathbb{R}$ be a function such that $\lim_{x \to 0} f(x) = 0$. If $f$ is differentiable at $x = 0$ with $f'(0) = m$, then $\lim_{x \to 0} \frac{f(x)}{x} = m$.
-/

open Filter Set Function
open scoped Topology

variable (f : ℝ → ℝ) (m : ℝ)

-- Define the open interval (-1, 1)
def open_unit_interval : Set ℝ := Ioo (-1) 1

-- Theorem

theorem main_theorem (hf : ContinuousOn f open_unit_interval)
  (h_lim : Tendsto f (𝓝[≠] 0) (𝓝 0))
  (h_diff : DifferentiableAt ℝ f 0)
  (h_deriv : deriv f 0 = m) :
  Tendsto (λ x => f x / x) (𝓝[≠] 0) (𝓝 m) :=


import Mathlib

/-
Let $f: (-1, 1) \to \mathbb{R}$ be a function such that $\lim_{x \to 0} f(x) = 0$. If $f$ is differentiable at $x = 0$ with $f'(0) = m$, then $\lim_{x \to 0} \frac{f(x)}{x} = m$.
-/

open Filter Set Function
open scoped Topology

variable (f : ℝ → ℝ)
variable (m : ℝ)

-- Define the open interval (-1, 1)
def open_unit_interval : Set ℝ := Ioo (-1) 1

-- Theorem
axiom main_theorem (hf : ContinuousOn f open_unit_interval)
  (h_lim : Tendsto f (𝓝[≠] 0) (𝓝 0))
  (h_diff : DifferentiableAt ℝ f 0)
  (h_deriv : deriv f 0 = m) :
  Tendsto (λ x => f x / x) (𝓝[≠] 0) (𝓝 m)

-- Corollary: If f(0) = 0, then the limit of f(x)/x as x approaches 0 equals f'(0)

theorem limit_quotient_eq_deriv (hf : ContinuousOn f open_unit_interval)
  (h_zero : f 0 = 0)
  (h_diff : DifferentiableAt ℝ f 0) :
  Tendsto (λ x => f x / x) (𝓝[≠] 0) (𝓝 (deriv f 0)) :=


import Mathlib

/-
For all real numbers x, the inequality $\frac{1-\ln (x)}{x^{2}}<0$ is satisfied if and only if x ∈ (e, ∞), where e is Euler's number.
-/

open Real

-- Theorem: The inequality (1 - ln(x)) / x^2 < 0 holds if and only if x ∈ (e, ∞)

theorem inequality_solution (x : ℝ) : (1 - log x) / x^2 < 0 ↔ x > exp 1 :=


import Mathlib

/-
The only real number values for \(a, b, c, d\) that satisfy the condition \(a^2+b^2+c^2+d^2=a(b+c+d)\), are when \(a = b = c = d = 0\).
-/

variable (a b c d : ℝ) (h : a^2 + b^2 + c^2 + d^2 = a * (b + c + d))

theorem sum_of_squares_and_product_implies_zero :
  a = 0 ∧ b = 0 ∧ c = 0 ∧ d = 0 :=


import Mathlib

/-
The series $\sum_{n=1}^{\infty} \frac{n}{n^{2}+1}$ is divergent.
-/

open Real NNReal

-- Define a comparison series that is known to diverge
noncomputable def comparison_series (n : ℕ+) : ℝ≥0 := 1 / (2 * n)

-- Define `general_term`: The general term of the series
noncomputable def general_term (n : ℕ+) : ℝ≥0 := (n : ℝ≥0) / ((n : ℝ≥0)^2 + 1)

-- Lemma: For all n ≥ 1, general_term n ≤ comparison_series n

lemma upper_bound (n : ℕ+) : general_term n ≤ comparison_series n :=


import Mathlib

/-
The series $\sum_{n=1}^{\infty} \frac{n}{n^{2}+1}$ is divergent.
-/

open Real NNReal

-- Define a comparison series that is known to diverge
noncomputable def comparison_series (n : ℕ+) : ℝ≥0 := 1 / (2 * n)

-- Define `general_term`: The general term of the series
noncomputable def general_term (n : ℕ+) : ℝ≥0 := (n : ℝ≥0) / ((n : ℝ≥0)^2 + 1)

-- Lemma: For all n ≥ 1, general_term n ≤ comparison_series n
axiom upper_bound (n : ℕ+) : general_term n ≤ comparison_series n

-- Lemma: Comparison test for non-negative real series

lemma comparison_test {a b : ℕ+ → ℝ≥0} (h : ∀ n, a n ≤ b n) (hb : ¬ Summable b) :
    ¬ Summable a :=


import Mathlib

/-
The series $\sum_{n=1}^{\infty} \frac{n}{n^{2}+1}$ is divergent.
-/

open Real NNReal

-- Define a comparison series that is known to diverge
noncomputable def comparison_series (n : ℕ+) : ℝ≥0 := 1 / (2 * n)

-- Define `general_term`: The general term of the series
noncomputable def general_term (n : ℕ+) : ℝ≥0 := (n : ℝ≥0) / ((n : ℝ≥0)^2 + 1)

-- Lemma: For all n ≥ 1, general_term n ≤ comparison_series n
axiom upper_bound (n : ℕ+) : general_term n ≤ comparison_series n

-- Lemma: Comparison test for non-negative real series
axiom comparison_test {a b : ℕ+ → ℝ≥0} (h : ∀ n, a n ≤ b n) (hb : ¬ Summable b) :
    ¬ Summable a

-- Lemma: The comparison series diverges

lemma comparison_series_diverges : ¬ Summable comparison_series :=


import Mathlib

/-
The series $\sum_{n=1}^{\infty} \frac{n}{n^{2}+1}$ is divergent.
-/

open Real NNReal

-- Define a comparison series that is known to diverge
noncomputable def comparison_series (n : ℕ+) : ℝ≥0 := 1 / (2 * n)

-- Define `general_term`: The general term of the series
noncomputable def general_term (n : ℕ+) : ℝ≥0 := (n : ℝ≥0) / ((n : ℝ≥0)^2 + 1)

-- Lemma: For all n ≥ 1, general_term n ≤ comparison_series n
axiom upper_bound (n : ℕ+) : general_term n ≤ comparison_series n

-- Lemma: Comparison test for non-negative real series
axiom comparison_test {a b : ℕ+ → ℝ≥0} (h : ∀ n, a n ≤ b n) (hb : ¬ Summable b) :
    ¬ Summable a

-- Lemma: The comparison series diverges
axiom comparison_series_diverges : ¬ Summable comparison_series

-- Theorem: The series ∑ (n : ℕ+), general_term n diverges

theorem series_diverges : ¬ Summable general_term :=


import Mathlib

/-
Let $f:[0,8] \rightarrow \mathbb{R}$ be defined by $f(x)=\sqrt[3]{8x-x^2}$. Then there exists a point $c \in (0,8)$ such that $f'(c) = 0$. Moreover, this point is specifically $c = 4$.
-/

open Real

variable (x : ℝ)

-- Define `f`: The function f is defined as f(x) = (8x - x^2)^(1/3)
noncomputable def f (x : ℝ) : ℝ := (8 * x - x^2)^(1/3 : ℝ)

-- Prove `derivative_f`: The derivative of f is given by f'(x) = (1/3) * (8x - x^2)^(-2/3) * (8 - 2x)

lemma derivative_f : ∀ x ∈ Set.Ioo 0 8, HasDerivAt f ((1/3 : ℝ) * (8 * x - x^2)^(-2/3 : ℝ) * (8 - 2 * x)) x :=


import Mathlib

/-
Let $f:[0,8] \rightarrow \mathbb{R}$ be defined by $f(x)=\sqrt[3]{8x-x^2}$. Then there exists a point $c \in (0,8)$ such that $f'(c) = 0$. Moreover, this point is specifically $c = 4$.
-/

open Real

variable (x : ℝ)

-- Define `f`: The function f is defined as f(x) = (8x - x^2)^(1/3)
noncomputable def f (x : ℝ) : ℝ := (8 * x - x^2)^(1/3 : ℝ)

-- Prove `derivative_f`: The derivative of f is given by f'(x) = (1/3) * (8x - x^2)^(-2/3) * (8 - 2x)
axiom derivative_f : ∀ x ∈ Set.Ioo 0 8, HasDerivAt f ((1/3 : ℝ) * (8 * x - x^2)^(-2/3 : ℝ) * (8 - 2 * x)) x

-- Prove that f is continuous on [0,8]

lemma f_continuous : ContinuousOn f (Set.Icc 0 8) :=


import Mathlib

/-
Let $f:[0,8] \rightarrow \mathbb{R}$ be defined by $f(x)=\sqrt[3]{8x-x^2}$. Then there exists a point $c \in (0,8)$ such that $f'(c) = 0$. Moreover, this point is specifically $c = 4$.
-/

open Real

variable (x : ℝ)

-- Define `f`: The function f is defined as f(x) = (8x - x^2)^(1/3)
noncomputable def f (x : ℝ) : ℝ := (8 * x - x^2)^(1/3 : ℝ)

-- Prove `derivative_f`: The derivative of f is given by f'(x) = (1/3) * (8x - x^2)^(-2/3) * (8 - 2x)
axiom derivative_f : ∀ x ∈ Set.Ioo 0 8, HasDerivAt f ((1/3 : ℝ) * (8 * x - x^2)^(-2/3 : ℝ) * (8 - 2 * x)) x

-- Prove that f is continuous on [0,8]
axiom f_continuous : ContinuousOn f (Set.Icc 0 8)

-- Prove that f is differentiable on (0,8)

lemma f_differentiable : DifferentiableOn ℝ f (Set.Ioo 0 8) :=


import Mathlib

/-
Let $f:[0,8] \rightarrow \mathbb{R}$ be defined by $f(x)=\sqrt[3]{8x-x^2}$. Then there exists a point $c \in (0,8)$ such that $f'(c) = 0$. Moreover, this point is specifically $c = 4$.
-/

open Real

variable (x : ℝ)

-- Define `f`: The function f is defined as f(x) = (8x - x^2)^(1/3)
noncomputable def f (x : ℝ) : ℝ := (8 * x - x^2)^(1/3 : ℝ)

-- Prove `derivative_f`: The derivative of f is given by f'(x) = (1/3) * (8x - x^2)^(-2/3) * (8 - 2x)
axiom derivative_f : ∀ x ∈ Set.Ioo 0 8, HasDerivAt f ((1/3 : ℝ) * (8 * x - x^2)^(-2/3 : ℝ) * (8 - 2 * x)) x

-- Prove that f is continuous on [0,8]
axiom f_continuous : ContinuousOn f (Set.Icc 0 8)

-- Prove that f is differentiable on (0,8)
axiom f_differentiable : DifferentiableOn ℝ f (Set.Ioo 0 8)

-- Prove `critical_point`: The critical point of f is found by solving 8 - 2x = 0, yielding x = 4

lemma critical_point : ∃! c, c ∈ Set.Ioo 0 8 ∧ HasDerivAt f 0 c :=


import Mathlib

/-
Let $f:[0,8] \rightarrow \mathbb{R}$ be defined by $f(x)=\sqrt[3]{8x-x^2}$. Then there exists a point $c \in (0,8)$ such that $f'(c) = 0$. Moreover, this point is specifically $c = 4$.
-/

open Real

variable (x : ℝ)

-- Define `f`: The function f is defined as f(x) = (8x - x^2)^(1/3)
noncomputable def f (x : ℝ) : ℝ := (8 * x - x^2)^(1/3 : ℝ)

-- Prove `derivative_f`: The derivative of f is given by f'(x) = (1/3) * (8x - x^2)^(-2/3) * (8 - 2x)
axiom derivative_f : ∀ x ∈ Set.Ioo 0 8, HasDerivAt f ((1/3 : ℝ) * (8 * x - x^2)^(-2/3 : ℝ) * (8 - 2 * x)) x

-- Prove that f is continuous on [0,8]
axiom f_continuous : ContinuousOn f (Set.Icc 0 8)

-- Prove that f is differentiable on (0,8)
axiom f_differentiable : DifferentiableOn ℝ f (Set.Ioo 0 8)

-- Prove `critical_point`: The critical point of f is found by solving 8 - 2x = 0, yielding x = 4
axiom critical_point : ∃! c, c ∈ Set.Ioo 0 8 ∧ HasDerivAt f 0 c

/-- By Rolle's theorem, there exists a unique point c ∈ (0,8) such that f'(c) = 0, specifically c = 4 -/
theorem rolle_theorem_application : ∃! c, c ∈ Set.Ioo 0 8 ∧ HasDerivAt f 0 c ∧ c = 4 :=


import Mathlib

/-
For the function $f(x)=\ln(x^2+1)$, the domain is the set of all real numbers, i.e., $\text{Dom}(f) = \mathbb{R} = (-\infty, \infty)$.
-/

open Real Set

-- Define the function f(x) = ln(x^2 + 1)
noncomputable def f (x : ℝ) : ℝ := log (x^2 + 1)

-- Lemma: x^2 + 1 is always positive for all real numbers x

lemma positivity_of_square_plus_one (x : ℝ) : 0 < x^2 + 1 :=


import Mathlib

/-
For the function $f(x)=\ln(x^2+1)$, the domain is the set of all real numbers, i.e., $\text{Dom}(f) = \mathbb{R} = (-\infty, \infty)$.
-/

open Real Set

-- Define the function f(x) = ln(x^2 + 1)
noncomputable def f (x : ℝ) : ℝ := log (x^2 + 1)

-- Lemma: x^2 + 1 is always positive for all real numbers x
axiom positivity_of_square_plus_one (x : ℝ) : 0 < x^2 + 1

-- Theorem: The domain of f(x) = ln(x^2 + 1) is the set of all real numbers

theorem domain_of_f_is_reals : ∀ x : ℝ, x ∈ univ :=


import Mathlib

/-
For the function $f(x)=\ln(x^2+1)$, the domain is the set of all real numbers, i.e., $\text{Dom}(f) = \mathbb{R} = (-\infty, \infty)$.
-/

open Real Set

-- Define the function f(x) = ln(x^2 + 1)
noncomputable def f (x : ℝ) : ℝ := log (x^2 + 1)

-- Lemma: x^2 + 1 is always positive for all real numbers x
axiom positivity_of_square_plus_one (x : ℝ) : 0 < x^2 + 1

-- Theorem: The domain of f(x) = ln(x^2 + 1) is the set of all real numbers
axiom domain_of_f_is_reals : ∀ x : ℝ, x ∈ univ

-- Corollary: f(x) is well-defined for all real numbers

theorem f_well_defined :
  ∀ x : ℝ, ∃! y : ℝ, y = Real.log (x^2 + 1) :=


import Mathlib

/-
Let $f: D \to \mathbb{R}$ be a function and $X \subseteq D$. If there exists a constant $M > 0$ such that $|f(x)| \leq M$ for all $x \in X$, then $f$ is bounded on $X$.
-/

variable {D : Type*} {f : D → ℝ} {X : Set D}

def BoundedOn (f : D → ℝ) (X : Set D) : Prop :=
  BddAbove (f '' X) ∧ BddBelow (f '' X)

theorem bounded_function_on_subset :
  (∃ M > 0, ∀ x ∈ X, |f x| ≤ M) → BoundedOn f X :=


import Mathlib

/-
Let $f$ be a function defined in a punctured neighborhood of $x_0$. If $\lim_{x \rightarrow x_0} f(x) = A$ and $A > 0$, then there exists $\delta > 0$ such that for all $x$ satisfying $0 < |x - x_0| < \delta$, we have $f(x) > 0$.
-/

open Filter Topology

variable {X Y : Type} [MetricSpace X] [MetricSpace Y] [LinearOrderedField Y]
variable {f : X → Y} {x₀ : X} {A : Y}

/-- Theorem: If the limit of f(x) as x approaches x₀ is A and A > 0, then f(x) > 0 in some punctured neighborhood of x₀. -/
theorem limit_positive_implies_function_positive (h : Tendsto f (𝓝 x₀) (𝓝 A)) (hA : A > (0 : Y)) :
∃ δ > (0 : ℝ), ∀ x, 0 < dist x x₀ ∧ dist x x₀ < δ → 0 < f x :=


import Mathlib

/-
Let $f: (a,b) \rightarrow \mathbb{R}$ be a function differentiable on the open interval $(a,b)$. For any two points $x_1, x_2 \in (a,b)$, there exists a point $\xi$ between $x_1$ and $x_2$ such that $f(x_1) - f(x_2) = (x_1 - x_2)f'(\xi)$.
-/

open Set

variable {a b : ℝ} {f : ℝ → ℝ}

/-- Theorem: If `f` is differentiable on `(a, b)`, then for any `x₁, x₂ ∈ (a, b)`, there exists `ξ` between `x₁` and `x₂` such that `f(x₁) - f(x₂) = (x₁ - x₂) f'(ξ)`. -/
theorem mean_value_theorem_for_differences (hf : DifferentiableOn ℝ f (Ioo a b))
  {x₁ x₂ : ℝ} (hx₁ : x₁ ∈ Ioo a b) (hx₂ : x₂ ∈ Ioo a b) :
  ∃ ξ ∈ Ioo (min x₁ x₂) (max x₁ x₂), f x₁ - f x₂ = (x₁ - x₂) * deriv f ξ :=


import Mathlib

/-
Let ${x_n}$ be a convergent sequence of real numbers. If $\lim_{n \to \infty}(x_n + \sin x_n) = 0$, then $\lim_{n \to \infty} x_n = 0$.
-/

open Topology Metric Filter

variable {x : ℕ → ℝ}

theorem abs_sin_le_one (x : ℝ) : |Real.sin x| ≤ 1 :=


import Mathlib

/-
Let ${x_n}$ be a convergent sequence of real numbers. If $\lim_{n \to \infty}(x_n + \sin x_n) = 0$, then $\lim_{n \to \infty} x_n = 0$.
-/

open Topology Metric Filter

variable {x : ℕ → ℝ}

axiom abs_sin_le_one (x : ℝ) : |Real.sin x| ≤ 1

theorem convergent_seq_bounded {x : ℕ → ℝ} (hx : ∃ L, Tendsto x atTop (𝓝 L)) :
  ∃ M, ∀ n, |x n| ≤ M :=


import Mathlib

/-
Let ${x_n}$ be a convergent sequence of real numbers. If $\lim_{n \to \infty}(x_n + \sin x_n) = 0$, then $\lim_{n \to \infty} x_n = 0$.
-/

open Topology Metric Filter

variable {x : ℕ → ℝ}

axiom abs_sin_le_one (x : ℝ) : |Real.sin x| ≤ 1

axiom convergent_seq_bounded {x : ℕ → ℝ} (hx : ∃ L, Tendsto x atTop (𝓝 L)) :
  ∃ M, ∀ n, |x n| ≤ M

theorem convergent_sum_sin_zero (hx : ∃ L, Tendsto x atTop (𝓝 L))
(h : Tendsto (λ n => x n + Real.sin (x n)) atTop (𝓝 0)) :
  Tendsto x atTop (𝓝 0) :=


import Mathlib

/-
For real numbers $x > 0$, the inequality $\ln(x^2) \leq (\ln(x))^2$ holds if and only if $x \in (0,1] \cup [e^2, \infty)$.
-/

open Real

-- Assuming these lemmas are not available in the imported libraries, define them

lemma log_le_zero_iff (x : ℝ) (hx : x > 0) : log x ≤ 0 ↔ x ≤ 1 :=


import Mathlib

/-
For real numbers $x > 0$, the inequality $\ln(x^2) \leq (\ln(x))^2$ holds if and only if $x \in (0,1] \cup [e^2, \infty)$.
-/

open Real

-- Assuming these lemmas are not available in the imported libraries, define them
axiom log_le_zero_iff (x : ℝ) (hx : x > 0) : log x ≤ 0 ↔ x ≤ 1

lemma two_le_log_iff (x : ℝ) (hx : x > 0) : 2 ≤ log x ↔ exp 2 ≤ x :=


import Mathlib

/-
For real numbers $x > 0$, the inequality $\ln(x^2) \leq (\ln(x))^2$ holds if and only if $x \in (0,1] \cup [e^2, \infty)$.
-/

open Real

-- Assuming these lemmas are not available in the imported libraries, define them
axiom log_le_zero_iff (x : ℝ) (hx : x > 0) : log x ≤ 0 ↔ x ≤ 1

axiom two_le_log_iff (x : ℝ) (hx : x > 0) : 2 ≤ log x ↔ exp 2 ≤ x

/-- The inequality `ln(x^2) ≤ (ln(x))^2` holds if and only if `x ∈ (0,1] ∪ [e^2, ∞)`. -/
theorem log_square_le_square_log (x : ℝ) (hx : x > 0) :
    log (x^2) ≤ (log x)^2 ↔ x ∈ Set.Ioo 0 1 ∪ Set.Ici (exp 2) :=


import Mathlib

/-
Let $f: [a,b] \rightarrow \mathbb{R}$ be a function that is continuous on $[a,b]$ and differentiable on $(a,b)$. If $f(a) = f(b)$, then there exists at least one point $\xi \in (a,b)$ such that $f'(\xi) = 0$.
-/

variable {a b : ℝ}

/-- Application of Rolle's Theorem: If f is continuous on [a,b], differentiable on (a,b),
    and f(a) = f(b), then there exists c ∈ (a,b) such that f'(c) = 0. -/
theorem rolles_theorem_application (hab : a < b)
    {f : ℝ → ℝ}
    (h_cont : ContinuousOn f (Set.Icc a b))
    (h_diff : DifferentiableOn ℝ f (Set.Ioo a b))
    (h_eq : f a = f b) :
  ∃ c ∈ Set.Ioo a b, deriv f c = 0 :=


import Mathlib

/-
The polynomial \(f(x)=x^6-2x^5+x^4-2x^3+x^2-2x+1\) has exactly four zeros of modulus 1.
-/

open Polynomial
open Complex

variable (f : Polynomial ℂ) (hf : f = (C 1 - C 2 * X + C 1 * X^2 - C 2 * X^3 + C 1 * X^4 - C 2 * X^5 + C 1 * X^6))

theorem exactly_four_roots_of_modulus_one :
 (Multiset.card (f.roots.filter fun z => ‖z‖ = 1)) = 4 :=


import Mathlib

/-
Let $i$ be the imaginary unit such that $i^2 = -1$. Then $(1+i)^{10} = 32i$.
-/

open Complex Real

-- Simplify e^(i 5π/2) using exponential function periodicity

lemma exponent_simplification : exp (I * (5 * π / 2)) = exp (I * (π / 2)) :=


import Mathlib

/-
Let $i$ be the imaginary unit such that $i^2 = -1$. Then $(1+i)^{10} = 32i$.
-/

open Complex Real

-- Simplify e^(i 5π/2) using exponential function periodicity
axiom exponent_simplification : exp (I * (5 * π / 2)) = exp (I * (π / 2))

-- Prove e^(i π/2) = i

lemma final_simplification : exp (I * (π / 2)) = I :=


import Mathlib

/-
Let $i$ be the imaginary unit such that $i^2 = -1$. Then $(1+i)^{10} = 32i$.
-/

open Complex Real

-- Simplify e^(i 5π/2) using exponential function periodicity
axiom exponent_simplification : exp (I * (5 * π / 2)) = exp (I * (π / 2))

-- Prove e^(i π/2) = i
axiom final_simplification : exp (I * (π / 2)) = I


import Mathlib

/-
Let $f: \mathbb{C} \rightarrow \mathbb{C}$ be an entire function. If $|f(z)| \geq 1$ for all $z \in \mathbb{C}$, then $f$ is constant.
-/

open Complex

/-- A function f is entire if it is analytic on the entire complex plane ℂ. -/
def Entire (f : ℂ → ℂ) : Prop := AnalyticOn ℂ f Set.univ

/-- If f is an entire function such that |f(z)| ≥ 1 for all z ∈ ℂ, then g(z) = 1/f(z) is entire and |g(z)| ≤ 1. -/
lemma bounded_reciprocal_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  Entire (fun z => 1 / f z) ∧ ∀ z, abs (1 / f z) ≤ 1 :=


import Mathlib

/-
Let $f: \mathbb{C} \rightarrow \mathbb{C}$ be an entire function. If $|f(z)| \geq 1$ for all $z \in \mathbb{C}$, then $f$ is constant.
-/

open Complex

/-- A function f is entire if it is analytic on the entire complex plane ℂ. -/
def Entire (f : ℂ → ℂ) : Prop := AnalyticOn ℂ f Set.univ

/-- If f is an entire function such that |f(z)| ≥ 1 for all z ∈ ℂ, then g(z) = 1/f(z) is entire and |g(z)| ≤ 1. -/
axiom bounded_reciprocal_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  Entire (fun z => 1 / f z) ∧ ∀ z, abs (1 / f z) ≤ 1

/-- Liouville's Theorem: Any bounded entire function must be constant. -/
lemma liouville_theorem (g : ℂ → ℂ) (hg : Entire g) (hbounded : ∃ C, ∀ z, abs (g z) ≤ C) :
  ∃ c : ℂ, ∀ z, g z = c :=


import Mathlib

/-
Let $f: \mathbb{C} \rightarrow \mathbb{C}$ be an entire function. If $|f(z)| \geq 1$ for all $z \in \mathbb{C}$, then $f$ is constant.
-/

open Complex

/-- A function f is entire if it is analytic on the entire complex plane ℂ. -/
def Entire (f : ℂ → ℂ) : Prop := AnalyticOn ℂ f Set.univ

/-- If f is an entire function such that |f(z)| ≥ 1 for all z ∈ ℂ, then g(z) = 1/f(z) is entire and |g(z)| ≤ 1. -/
axiom bounded_reciprocal_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  Entire (fun z => 1 / f z) ∧ ∀ z, abs (1 / f z) ≤ 1

/-- Liouville's Theorem: Any bounded entire function must be constant. -/
axiom liouville_theorem (g : ℂ → ℂ) (hg : Entire g) (hbounded : ∃ C, ∀ z, abs (g z) ≤ C) :
  ∃ c : ℂ, ∀ z, g z = c

/-- If g(z) = 1/f(z) is constant, then f(z) is constant. -/
lemma constant_reciprocal_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  ∃ c : ℂ, ∀ z, f z = 1 / c :=


import Mathlib

/-
Let $f: \mathbb{C} \rightarrow \mathbb{C}$ be an entire function. If $|f(z)| \geq 1$ for all $z \in \mathbb{C}$, then $f$ is constant.
-/

open Complex

/-- A function f is entire if it is analytic on the entire complex plane ℂ. -/
def Entire (f : ℂ → ℂ) : Prop := AnalyticOn ℂ f Set.univ

/-- If f is an entire function such that |f(z)| ≥ 1 for all z ∈ ℂ, then g(z) = 1/f(z) is entire and |g(z)| ≤ 1. -/
axiom bounded_reciprocal_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  Entire (fun z => 1 / f z) ∧ ∀ z, abs (1 / f z) ≤ 1

/-- Liouville's Theorem: Any bounded entire function must be constant. -/
axiom liouville_theorem (g : ℂ → ℂ) (hg : Entire g) (hbounded : ∃ C, ∀ z, abs (g z) ≤ C) :
  ∃ c : ℂ, ∀ z, g z = c

/-- If g(z) = 1/f(z) is constant, then f(z) is constant. -/
axiom constant_reciprocal_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  ∃ c : ℂ, ∀ z, f z = 1 / c

/-- If f is an entire function such that |f(z)| ≥ 1 for all z ∈ ℂ, then f is constant. -/
theorem constant_entire_function (f : ℂ → ℂ) (hf : Entire f) (h : ∀ z, 1 ≤ abs (f z)) :
  ∃ c : ℂ, ∀ z, f z = c :=


import Mathlib

/-
For the imaginary unit $i$, where $i^2 = -1$, the following equality holds:

    $i^{73} = i$
-/

open Complex


import Mathlib

/-
For the imaginary unit $i$, where $i^2 = -1$, the following equality holds:

    $i^{73} = i$
-/

open Complex

axiom i_pow_73 : I ^ 73 = I

theorem i_pow_mod_4 (n : ℕ) : I ^ n = I ^ (n % 4) :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
lemma f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v)) :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
lemma f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u) :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
axiom f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u)

/-- The partial derivative of g with respect to x -/
lemma partial_g_x (x y : ℝ) :
  deriv (fun x => g x y) x = (4 * x - 2 * y) * exp (-y) :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
axiom f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u)

/-- The partial derivative of g with respect to x -/
axiom partial_g_x (x y : ℝ) :
  deriv (fun x => g x y) x = (4 * x - 2 * y) * exp (-y)

/-- The expression for g -/
lemma g_expression (x y : ℝ) :
  g x y = (x^2 + (y - x)^2) * exp (-y) :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
axiom f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u)

/-- The partial derivative of g with respect to x -/
axiom partial_g_x (x y : ℝ) :
  deriv (fun x => g x y) x = (4 * x - 2 * y) * exp (-y)

/-- The expression for g -/
axiom g_expression (x y : ℝ) :
  g x y = (x^2 + (y - x)^2) * exp (-y)

/-- The critical points of f -/
lemma critical_points (u v : ℝ) :
  deriv (fun u => f u v) u = 0 ∧ deriv (fun v => f u v) v = 0 ↔ u = 0 ∧ v = 0 :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
axiom f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u)

/-- The partial derivative of g with respect to x -/
axiom partial_g_x (x y : ℝ) :
  deriv (fun x => g x y) x = (4 * x - 2 * y) * exp (-y)

/-- The expression for g -/
axiom g_expression (x y : ℝ) :
  g x y = (x^2 + (y - x)^2) * exp (-y)

/-- The critical points of f -/
axiom critical_points (u v : ℝ) :
  deriv (fun u => f u v) u = 0 ∧ deriv (fun v => f u v) v = 0 ↔ u = 0 ∧ v = 0

/-- f has a global minimum at (0,0) -/
lemma f_global_minimum :
  IsMinOn (fun p => f p.1 p.2) Set.univ (0, 0) :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
axiom f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u)

/-- The partial derivative of g with respect to x -/
axiom partial_g_x (x y : ℝ) :
  deriv (fun x => g x y) x = (4 * x - 2 * y) * exp (-y)

/-- The expression for g -/
axiom g_expression (x y : ℝ) :
  g x y = (x^2 + (y - x)^2) * exp (-y)

/-- The critical points of f -/
axiom critical_points (u v : ℝ) :
  deriv (fun u => f u v) u = 0 ∧ deriv (fun v => f u v) v = 0 ↔ u = 0 ∧ v = 0

/-- f has a global minimum at (0,0) -/
axiom f_global_minimum :
  IsMinOn (fun p => f p.1 p.2) Set.univ (0, 0)

/-- The global minimum of f is unique -/
lemma f_unique_minimum (u v : ℝ) :
  f u v = 0 ↔ u = 0 ∧ v = 0 :=


import Mathlib

/-
Let f(u,v) be a differentiable function satisfying the following conditions:

  1. $\frac{\partial f(u, v)}{\partial u} - \frac{\partial f(u, v)}{\partial v} = 2(u-v)e^{-(u+v)}$
  2. $f(u,0) = u^2e^{-u}$

  Then:

  a) For $g(x,y) = f(x,y-x)$, $\frac{\partial g(x,y)}{\partial x} = (4x-2y)e^{-y}$

  b) The expression for $f(u,v)$ is given by $f(u,v) = (u^2+v^2)e^{-(u+v)}$

  c) The function $f(u,v)$ has a unique global minimum at $(0,0)$ with $f(0,0) = 0$
-/

open Real

variable {u v x y : ℝ}

/-- The function f satisfying the given partial derivative condition -/
noncomputable def f (u v : ℝ) : ℝ := (u^2 + v^2) * exp (-(u + v))

/-- The function g defined in terms of f -/
noncomputable def g (x y : ℝ) : ℝ := f x (y - x)

/-- The partial derivative condition for f -/
axiom f_partial_condition (u v : ℝ) :
  deriv (fun u => f u v) u - deriv (fun v => f u v) v = 2 * (u - v) * exp (-(u+v))

/-- The initial condition for f -/
axiom f_initial_condition (u : ℝ) :
  f u 0 = u^2 * exp (-u)

/-- The partial derivative of g with respect to x -/
axiom partial_g_x (x y : ℝ) :
  deriv (fun x => g x y) x = (4 * x - 2 * y) * exp (-y)

/-- The expression for g -/
axiom g_expression (x y : ℝ) :
  g x y = (x^2 + (y - x)^2) * exp (-y)

/-- The critical points of f -/
axiom critical_points (u v : ℝ) :
  deriv (fun u => f u v) u = 0 ∧ deriv (fun v => f u v) v = 0 ↔ u = 0 ∧ v = 0

/-- f has a global minimum at (0,0) -/
axiom f_global_minimum :
  IsMinOn (fun p => f p.1 p.2) Set.univ (0, 0)

/-- The global minimum of f is unique -/
axiom f_unique_minimum (u v : ℝ) :
  f u v = 0 ↔ u = 0 ∧ v = 0

/-- The value of f at its global minimum -/
theorem f_min_value : f 0 0 = 0 :=


import Mathlib

/-
Let $\{b_n\}$ be a sequence of positive real numbers converging to $\frac{1}{2}$. Then the series $\sum_{n=1}^{\infty} \frac{b_n^n \cos n \pi}{n}$ is absolutely convergent.
-/

open Real BigOperators Filter Topology

variable (b : ℕ → ℝ)

-- Use standard Mathlib definition for sequence convergence
def sequence_converges (a : ℕ → ℝ) (L : ℝ) : Prop :=
  Tendsto a atTop (nhds L)

/-- The series Σ(b_n^n * cos(nπ))/n is absolutely convergent when b_n converges to 1/2. -/
lemma series_convergence' {b : ℕ → ℝ} (h_pos : ∀ n, b n > 0)
  (h_lim : Tendsto b atTop (𝓝 (1/2))): Summable (fun n => |b n^n * cos (n * π) / n|) :=


import Mathlib

/-
Let $\{b_n\}$ be a sequence of positive real numbers converging to $\frac{1}{2}$. Then the series $\sum_{n=1}^{\infty} \frac{b_n^n \cos n \pi}{n}$ is absolutely convergent.
-/

open Real BigOperators Filter Topology

variable (b : ℕ → ℝ)

-- Use standard Mathlib definition for sequence convergence
def sequence_converges (a : ℕ → ℝ) (L : ℝ) : Prop :=
  Tendsto a atTop (nhds L)

/-- The series Σ(b_n^n * cos(nπ))/n is absolutely convergent when b_n converges to 1/2. -/
axiom series_convergence' {b : ℕ → ℝ} (h_pos : ∀ n, b n > 0)
  (h_lim : Tendsto b atTop (𝓝 (1/2))): Summable (fun n => |b n^n * cos (n * π) / n|)

-- Explicit statement about the series sum

theorem series_sum_exists (h : sequence_converges b (1/2)) :
  ∃ S : ℝ, Tendsto (λ n : ℕ => ∑ i in Finset.range n, |b i^i * cos (i * π) / i|) atTop (nhds S) :=


import Mathlib
/-
Let X be a random variable following a Poisson distribution with parameter λ. If P{X>0} = 1-e^(-1), then:
  (a) λ = 1
  (b) P{X ≤ 1} = 2e^(-1)
  (c) cov(X, X^2) = 3
-/
open Real MeasureTheory ProbabilityTheory

variable (lambda : NNReal)

noncomputable def poisson_pmf : ℕ → ℝ :=
 poissonPMFReal lambda

lemma lambda_eq_1 (h : 1 - exp (-1) = 1 - exp (-(lambda : ℝ))) : lambda = 1 :=


import Mathlib
/-
Let X be a random variable following a Poisson distribution with parameter λ. If P{X>0} = 1-e^(-1), then:
  (a) λ = 1
  (b) P{X ≤ 1} = 2e^(-1)
  (c) cov(X, X^2) = 3
-/
open Real MeasureTheory ProbabilityTheory

variable (lambda : NNReal)

noncomputable def poisson_pmf : ℕ → ℝ :=
 poissonPMFReal lambda

axiom lambda_eq_1 (h : 1 - exp (-1) = 1 - exp (-(lambda : ℝ))) : lambda = 1

theorem P_X_leq_1 : poisson_pmf lambda 0 + poisson_pmf lambda 1 = 2 * exp (-(lambda : ℝ)) :=


import Mathlib
/-
Let X be a random variable following a Poisson distribution with parameter λ. If P{X>0} = 1-e^(-1), then:
  (a) λ = 1
  (b) P{X ≤ 1} = 2e^(-1)
  (c) cov(X, X^2) = 3
-/
open Real MeasureTheory ProbabilityTheory

variable (lambda : NNReal)

noncomputable def poisson_pmf : ℕ → ℝ :=
 poissonPMFReal lambda

axiom lambda_eq_1 (h : 1 - exp (-1) = 1 - exp (-(lambda : ℝ))) : lambda = 1

axiom P_X_leq_1 : poisson_pmf lambda 0 + poisson_pmf lambda 1 = 2 * exp (-(lambda : ℝ))

theorem E_X (h : Summable (fun (k : ℕ) => k * poissonPMFReal lambda k)) :
  ∑' k, k * poissonPMFReal lambda k = lambda :=


import Mathlib
/-
Let X be a random variable following a Poisson distribution with parameter λ. If P{X>0} = 1-e^(-1), then:
  (a) λ = 1
  (b) P{X ≤ 1} = 2e^(-1)
  (c) cov(X, X^2) = 3
-/
open Real MeasureTheory ProbabilityTheory

variable (lambda : NNReal)

noncomputable def poisson_pmf : ℕ → ℝ :=
 poissonPMFReal lambda

axiom lambda_eq_1 (h : 1 - exp (-1) = 1 - exp (-(lambda : ℝ))) : lambda = 1

axiom P_X_leq_1 : poisson_pmf lambda 0 + poisson_pmf lambda 1 = 2 * exp (-(lambda : ℝ))

axiom E_X (h : Summable (fun (k : ℕ) => k * poissonPMFReal lambda k)) :
  ∑' k, k * poissonPMFReal lambda k = lambda

theorem cov_X_X2 (h0 : lambda = 1)
  (h1 : Summable fun k => k * k^2 * poissonPMFReal lambda k)
  (h2 : Summable fun k => k * poissonPMFReal lambda k)
  (h3 : Summable fun k => k^2 * poissonPMFReal lambda k) :
  (∑' k, k * k^2 * poissonPMFReal lambda k) -
  (∑' k, k * poissonPMFReal lambda k) * (∑' k, k^2 * poissonPMFReal lambda k) = 3 :=


import Mathlib

/-
Let $A = [a_{ij}]$ be a $3 \times 3$ Markov transition matrix given by
  $$A = \begin{bmatrix}
  0.1 & 0.3 & 0.7 \\
  0.1 & 0.3 & 0.2 \\
  0.8 & 0.4 & 0.1
  \end{bmatrix}$$
  representing a random walk on three locations. If the initial state vector is $X_0 = [0, 1, 0]^T$, then the probability of being in the second location after three steps is given by the second component of the vector $X_3 = A^3 X_0$, which equals 0.18.
-/

open Matrix

/-- The Markov transition matrix A -/
def A : Matrix (Fin 3) (Fin 3) ℝ :=
  ![![0.1, 0.3, 0.7], ![0.1, 0.3, 0.2], ![0.8, 0.4, 0.1]]

/-- The initial state vector X0 -/
def X0 : Matrix (Fin 3) (Fin 1) ℝ :=
  ![![0], ![1], ![0]]


import Mathlib

/-
Let $A = [a_{ij}]$ be a $3 \times 3$ Markov transition matrix given by
  $$A = \begin{bmatrix}
  0.1 & 0.3 & 0.7 \\
  0.1 & 0.3 & 0.2 \\
  0.8 & 0.4 & 0.1
  \end{bmatrix}$$
  representing a random walk on three locations. If the initial state vector is $X_0 = [0, 1, 0]^T$, then the probability of being in the second location after three steps is given by the second component of the vector $X_3 = A^3 X_0$, which equals 0.18.
-/

open Matrix

/-- The Markov transition matrix A -/
def A : Matrix (Fin 3) (Fin 3) ℝ :=
  ![![0.1, 0.3, 0.7], ![0.1, 0.3, 0.2], ![0.8, 0.4, 0.1]]

/-- The initial state vector X0 -/
def X0 : Matrix (Fin 3) (Fin 1) ℝ :=
  ![![0], ![1], ![0]]

/-- A^2 is computed as A * A -/
axiom A_squared : A * A = ![![0.6, 0.4, 0.2], ![0.2, 0.2, 0.15], ![0.2, 0.4, 0.65]]


import Mathlib

/-
Let $A = [a_{ij}]$ be a $3 \times 3$ Markov transition matrix given by
  $$A = \begin{bmatrix}
  0.1 & 0.3 & 0.7 \\
  0.1 & 0.3 & 0.2 \\
  0.8 & 0.4 & 0.1
  \end{bmatrix}$$
  representing a random walk on three locations. If the initial state vector is $X_0 = [0, 1, 0]^T$, then the probability of being in the second location after three steps is given by the second component of the vector $X_3 = A^3 X_0$, which equals 0.18.
-/

open Matrix

/-- The Markov transition matrix A -/
def A : Matrix (Fin 3) (Fin 3) ℝ :=
  ![![0.1, 0.3, 0.7], ![0.1, 0.3, 0.2], ![0.8, 0.4, 0.1]]

/-- The initial state vector X0 -/
def X0 : Matrix (Fin 3) (Fin 1) ℝ :=
  ![![0], ![1], ![0]]

/-- A^2 is computed as A * A -/
axiom A_squared : A * A = ![![0.6, 0.4, 0.2], ![0.2, 0.2, 0.15], ![0.2, 0.4, 0.65]]

/-- A^3 is computed as A * A^2 -/
axiom A_cubed : A * (A * A) = ![![0.26, 0.38, 0.52], ![0.16, 0.18, 0.195], ![0.58, 0.44, 0.285]]


import Mathlib

/-
Let $A = [a_{ij}]$ be a $3 \times 3$ Markov transition matrix given by
  $$A = \begin{bmatrix}
  0.1 & 0.3 & 0.7 \\
  0.1 & 0.3 & 0.2 \\
  0.8 & 0.4 & 0.1
  \end{bmatrix}$$
  representing a random walk on three locations. If the initial state vector is $X_0 = [0, 1, 0]^T$, then the probability of being in the second location after three steps is given by the second component of the vector $X_3 = A^3 X_0$, which equals 0.18.
-/

open Matrix

/-- The Markov transition matrix A -/
def A : Matrix (Fin 3) (Fin 3) ℝ :=
  ![![0.1, 0.3, 0.7], ![0.1, 0.3, 0.2], ![0.8, 0.4, 0.1]]

/-- The initial state vector X0 -/
def X0 : Matrix (Fin 3) (Fin 1) ℝ :=
  ![![0], ![1], ![0]]

/-- A^2 is computed as A * A -/
axiom A_squared : A * A = ![![0.6, 0.4, 0.2], ![0.2, 0.2, 0.15], ![0.2, 0.4, 0.65]]

/-- A^3 is computed as A * A^2 -/
axiom A_cubed : A * (A * A) = ![![0.26, 0.38, 0.52], ![0.16, 0.18, 0.195], ![0.58, 0.44, 0.285]]

/-- X3 is computed as A^3 * X0 -/
axiom X3 : A * (A * (A * X0)) = ![![0.38], ![0.18], ![0.44]]

/-- The probability of being in the second location after three steps is 0.18 -/
theorem probability_location_2 : (A * (A * (A * X0))) 1 0 = 0.18 :=


import Mathlib

/-
In a sequential shooting scenario where two shooters A and B independently take turns, with A shooting first, if the probability of A hitting the target on any given shot is $p_A = 0.3$ and the probability of B hitting the target is $p_B = 0.4$, then the probability $P(A)$ that A is the first to hit the target is given by:

  $P(A) = \frac{p_A}{1 - (1-p_A)(1-p_B)} = \frac{15}{29}$
-/

open MeasureTheory ProbabilityTheory

/-- The probability that shooter A hits the target on any given shot. -/
noncomputable def p_A : NNReal := 3 / 10

/-- The probability that shooter B hits the target on any given shot. -/
noncomputable def p_B : NNReal := 4 / 10

/-- Formula for the probability that shooter A is the first to hit the target
    in a sequential, independent shooting scenario. -/
noncomputable def prob_A_first_hit {α : Type} [MeasurableSpace α] (μ : Measure α)
  (A : Set α) (B : Set α) : NNReal :=
  (μ (A)).toNNReal / (1 - (1 - (μ (A)).toNNReal) * (1 - (μ (B)).toNNReal))

/-- Theorem: Given p_A = 0.3 and p_B = 0.4, the probability that shooter A
    is the first to hit the target in a sequential, independent shooting scenario is 15/29. -/
theorem prob_A_first_hit_value {α : Type} [MeasurableSpace α]
    (μ : Measure α) (A : Set α) (B : Set α)
  (hIndep : IndepSet A B μ) (hA : μ (A) = p_A) (hB : μ (B) = p_B) :
  prob_A_first_hit μ A B  = 15 / 29 :=


import Mathlib

/-
In a sequential shooting scenario where two shooters A and B independently take turns, with A shooting first, if the probability of A hitting the target on any given shot is $p_A = 0.3$ and the probability of B hitting the target is $p_B = 0.4$, then the probability $P(A)$ that A is the first to hit the target is given by:

  $P(A) = \frac{p_A}{1 - (1-p_A)(1-p_B)} = \frac{15}{29}$
-/

open MeasureTheory ProbabilityTheory

/-- The probability that shooter A hits the target on any given shot. -/
noncomputable def p_A : NNReal := 3 / 10

/-- The probability that shooter B hits the target on any given shot. -/
noncomputable def p_B : NNReal := 4 / 10

/-- Formula for the probability that shooter A is the first to hit the target
    in a sequential, independent shooting scenario. -/
noncomputable def prob_A_first_hit {α : Type} [MeasurableSpace α] (μ : Measure α)
(A : Set α) (B : Set α) : NNReal :=
(μ (A)).toNNReal / (1 - (1 - (μ (A)).toNNReal) * (1 - (μ (B)).toNNReal))

/-- Theorem: Given p_A = 0.3 and p_B = 0.4, the probability that shooter A
    is the first to hit the target in a sequential, independent shooting scenario is 15/29. -/
axiom prob_A_first_hit_value {α : Type} [MeasurableSpace α]
    (μ : Measure α) (A : Set α) (B : Set α) (hA : μ (A) = p_A) (hB : μ (B) = p_B) :
  prob_A_first_hit μ A B  = 15 / 29  -- Replace with actual proof

/-- Theorem: The probability of A hitting first is greater than 1/2. -/
theorem A_hits_first_more_likely {α : Type} [MeasurableSpace α]
    (μ : Measure α) (A : Set α) (B : Set α)
    (hIndep : IndepSet A B μ) (hA : μ (A) = p_A) (hB : μ (B) = p_B) :
    prob_A_first_hit μ A B > 1 / 2 :=