introvoyz041/TaoAnalysisBench huggingface dataset:
import Mathlib.Tactic
import Mathlib.Analysis.SpecialFunctions.Pow.Real

/-!
Self-contained snippet extracted for Chapter 6.7 target theorem.
-/

namespace Chapter6

/-- Real-valued sequences (Section 6.1.3). -/
@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

@[coe]
abbrev Sequence.ofNatFun (a : ℕ → ℝ) : Sequence :=
  { m := 0
    seq n := if n ≥ 0 then a n.toNat else 0
    vanish := by simp_all }

instance Sequence.instCoe : Coe (ℕ → ℝ) Sequence where
  coe := Sequence.ofNatFun

abbrev Sequence.mk' (m : ℤ) (a : { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

/-- Start a sequence from a later index (Section 6.1.3). -/
abbrev Sequence.from (a : Sequence) (m₁ : ℤ) : Sequence :=
  Sequence.mk' (max a.m m₁) (fun n : { n // n ≥ max a.m m₁ } ↦ a n)

end Chapter6

/-- Real distance-based closeness (Section 6.1.1–6.1.2). -/
abbrev Real.Close (ε x y : ℝ) : Prop := dist x y ≤ ε

/-- CloseSeq (Section 6.1.5). -/
abbrev Real.CloseSeq (ε : ℝ) (a : Chapter6.Sequence) (L : ℝ) : Prop :=
  ∀ n ≥ a.m, ε.Close (a n) L

/-- EventuallyClose (Section 6.1.5). -/
abbrev Real.EventuallyClose (ε : ℝ) (a : Chapter6.Sequence) (L : ℝ) : Prop :=
  ∃ N ≥ a.m, ε.CloseSeq (a.from N) L

namespace Chapter6

/-- TendsTo (Section 6.1.5). -/
abbrev Sequence.TendsTo (a : Sequence) (L : ℝ) : Prop :=
  ∀ ε > (0 : ℝ), ε.EventuallyClose a L

/-- Convergent sequences (Section 6.1.8). -/
abbrev Sequence.Convergent (a : Sequence) : Prop := ∃ L, a.TendsTo L

open Classical in
/-- Limit of a sequence (junk value 0 if nonconvergent) (Section 6.1.8). -/
noncomputable abbrev lim (a : Sequence) : ℝ :=
  if h : a.Convergent then h.choose else 0

namespace Real

/-- Existence of rational approximants to a real limit (Section 6.7).
This is copied with proof elided, as allowed. -/
 theorem eq_lim_of_rat (α : ℝ) : ∃ q : ℕ → ℚ, ((fun n ↦ (q n : ℝ)) : Sequence).TendsTo α := by
  sorry

/-- Definition 6.7.2: exponentiation to a real exponent via limits of rational powers. -/
noncomputable abbrev rpow (x : ℝ) (α : ℝ) : ℝ :=
  lim ((fun n ↦ x ^ ((eq_lim_of_rat α).choose n : ℝ)) : Sequence)

/-- Proposition 6.7.3(b) / Exercise 6.7.1. -/
 theorem ratPow_ratPow {x : ℝ} (hx : x > 0) (q r : ℝ) :
    rpow (rpow x q) r = rpow x (q * r) := by
end Real

end Chapter6
import Mathlib
import Analysis.Section_5_epilogue
import Analysis.Tags.Section_5_epilogue
import Analysis.Section_6_6
import Analysis.Tags.Section_6_6

namespace Chapter6

-- <CONTEXT>
@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

@[coe]
abbrev Sequence.ofNatFun (a : ℕ → ℝ) : Sequence :=
  { m := 0
    seq n := if n ≥ 0 then a n.toNat else 0
    vanish := by simp_all }

instance Sequence.instCoe : Coe (ℕ → ℝ) Sequence where
  coe := Sequence.ofNatFun

abbrev Sequence.mk' (m : ℤ) (a : { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

abbrev Sequence.from (a : Sequence) (m₁ : ℤ) : Sequence :=
  Sequence.mk' (max a.m m₁) (fun n : { n // n ≥ max a.m m₁ } ↦ a n)

abbrev _root_.Real.Close (ε x y : ℝ) : Prop := dist x y ≤ ε

abbrev _root_.Real.CloseSeq (ε : ℝ) (a : Sequence) (L : ℝ) : Prop :=
  ∀ n ≥ a.m, ε.Close (a n) L

abbrev _root_.Real.EventuallyClose (ε : ℝ) (a : Sequence) (L : ℝ) : Prop :=
  ∃ N ≥ a.m, ε.CloseSeq (a.from N) L

abbrev Sequence.TendsTo (a : Sequence) (L : ℝ) : Prop :=
  ∀ ε > (0 : ℝ), ε.EventuallyClose a L

abbrev Sequence.Convergent (a : Sequence) : Prop := ∃ L, a.TendsTo L

open Classical in
noncomputable abbrev lim (a : Sequence) : ℝ :=
  if h : a.Convergent then h.choose else 0

open Sequence Real

lemma ratPow_continuous {x α : ℝ} (hx : x > 0) {q : ℕ → ℚ}
    (hq : ((fun n ↦ (q n : ℝ)) : Sequence).TendsTo α) :
    ((fun n ↦ x ^ (q n : ℝ)) : Sequence).Convergent := by
  sorry

lemma ratPow_lim_uniq {x α : ℝ} (hx : x > 0) {q q' : ℕ → ℚ}
    (hq : ((fun n ↦ (q n : ℝ)) : Sequence).TendsTo α)
    (hq' : ((fun n ↦ (q' n : ℝ)) : Sequence).TendsTo α) :
    lim ((fun n ↦ x ^ (q n : ℝ)) : Sequence) = lim ((fun n ↦ x ^ (q' n : ℝ)) : Sequence) := by
  sorry

theorem Real.eq_lim_of_rat (α : ℝ) : ∃ q : ℕ → ℚ, ((fun n ↦ (q n : ℝ)) : Sequence).TendsTo α := by
  sorry

noncomputable abbrev Real.rpow (x : ℝ) (α : ℝ) : ℝ := lim ((fun n ↦ x ^ ((eq_lim_of_rat α).choose n : ℝ)) : Sequence)

lemma Real.rpow_eq_lim_ratPow {x α : ℝ} (hx : x > 0) {q : ℕ → ℚ}
    (hq : ((fun n ↦ (q n : ℝ)) : Sequence).TendsTo α) :
    rpow x α = lim ((fun n ↦ x ^ (q n : ℝ)) : Sequence) := by
  sorry

lemma Real.ratPow_tendsto_rpow {x α : ℝ} (hx : x > 0) {q : ℕ → ℚ}
    (hq : ((fun n ↦ (q n : ℝ)) : Sequence).TendsTo α) :
    ((fun n ↦ x ^ (q n : ℝ)) : Sequence).TendsTo (rpow x α) := by
  sorry

lemma Real.rpow_of_rat_eq_ratPow {x : ℝ} (hx : x > 0) {q : ℚ} :
    rpow x (q : ℝ) = x ^ (q : ℝ) := by
  sorry

theorem Real.ratPow_add {x : ℝ} (hx : x > 0) (q r : ℝ) : rpow x (q + r) = rpow x q * rpow x r := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem Real.ratPow_ratPow {x : ℝ} (hx : x > 0) (q r : ℝ) :
    rpow (rpow x q) r = rpow x (q * r) := by
-- </TARGET_THEOREM>

end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem ratPow_ratPow {x : ℝ} (hx : x > 0) (q r : ℝ) :
    Real.rpow (Real.rpow x q) r = Real.rpow x (q * r) := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem Sequence.IsCauchy.convergent {u : ℕ → ℝ}
    (h : ∃ L : ℝ, Tendsto u atTop (𝓝 L)) :
    CauchySeq u := by
end TaoBench
import Mathlib.Tactic
import Mathlib.Topology.MetricSpace.Basic
import Mathlib.Order.Monotone.Basic

/-!
Self-contained extraction for Chapter 6 sequences and the target theorem from Section 6.6.
-/

/- Definition 6.1.1 (Distance / ε-close on ℝ). -/
abbrev Real.Close (ε x y : ℝ) : Prop := dist x y ≤ ε

/-- Definition 6.1.2 (ε-close). -/
theorem Real.close_def (ε x y : ℝ) : ε.Close x y ↔ dist x y ≤ ε := by rfl

namespace Chapter6

/--
  Definition 6.1.3 (Sequence). This is similar to the Chapter 5 sequence, except that now the
  sequence is real-valued. As with Chapter 5, we start sequences from 0 by default.
-/
@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

/-- Sequences can be thought of as functions from ℤ to ℝ. -/
instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

@[coe]
abbrev Sequence.ofNatFun (a:ℕ → ℝ) : Sequence :=
 {
    m := 0
    seq n := if n ≥ 0 then a n.toNat else 0
    vanish := by simp_all
 }

/-- Functions from ℕ to ℝ can be thought of as sequences. -/
instance Sequence.instCoe : Coe (ℕ → ℝ) Sequence where
  coe := ofNatFun

abbrev Sequence.mk' (m:ℤ) (a: { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

lemma Sequence.eval_mk {n m:ℤ} (a: { n // n ≥ m } → ℝ) (h: n ≥ m) :
    (Sequence.mk' m a) n = a ⟨ n, h ⟩ := by simp [h]

@[simp]
lemma Sequence.eval_coe (n:ℕ) (a: ℕ → ℝ) : (a:Sequence) n = a n := by simp

/--
  a.from n₁ starts `a:Sequence` from `n₁`.  It is intended for use when `n₁ ≥ n₀`, but returns
  the "junk" value of the original sequence `a` otherwise.
-/
abbrev Sequence.from (a:Sequence) (m₁:ℤ) : Sequence := mk' (max a.m m₁) (a ↑·)

lemma Sequence.from_eval (a:Sequence) {m₁ n:ℤ} (hn: n ≥ m₁) :
  (a.from m₁) n = a n := by
  simp [hn]; intros; symm; solve_by_elim [a.vanish]

end Chapter6

/-- Definition 6.1.5 -/
abbrev Real.CloseSeq (ε: ℝ) (a: Chapter6.Sequence) (L:ℝ) : Prop := ∀ n ≥ a.m, ε.Close (a n) L

/-- Definition 6.1.5 -/
theorem Real.closeSeq_def (ε: ℝ) (a: Chapter6.Sequence) (L:ℝ) :
  ε.CloseSeq a L ↔ ∀ n ≥ a.m, dist (a n) L ≤ ε := by rfl

/-- Definition 6.1.5 -/
abbrev Real.EventuallyClose (ε: ℝ) (a: Chapter6.Sequence) (L:ℝ) : Prop :=
  ∃ N ≥ a.m, ε.CloseSeq (a.from N) L

/-- Definition 6.1.5 -/
theorem Real.eventuallyClose_def (ε: ℝ) (a: Chapter6.Sequence) (L:ℝ) :
  ε.EventuallyClose a L ↔ ∃ N, (N ≥ a.m) ∧ ε.CloseSeq (a.from N) L := by rfl

namespace Chapter6

abbrev Sequence.TendsTo (a:Sequence) (L:ℝ) : Prop :=
  ∀ ε > (0:ℝ), ε.EventuallyClose a L

theorem Sequence.tendsTo_def (a:Sequence) (L:ℝ) :
  a.TendsTo L ↔ ∀ ε > (0:ℝ), ε.EventuallyClose a L := by rfl

end Chapter6

namespace Chapter6

/-- Definition 6.6.1 -/
abbrev Sequence.subseq (a b: ℕ → ℝ) : Prop := ∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, b n = a (f n)

/-- Proposition 6.6.5 / Exercise 6.6.4 -/
theorem Sequence.convergent_iff_subseq (a:ℕ → ℝ) (L:ℝ) :
    (a:Sequence).TendsTo L ↔ ∀ b:ℕ → ℝ, Sequence.subseq a b → (b:Sequence).TendsTo L := by
end Chapter6
import Mathlib
import Analysis.Section_6_5
import Analysis.Tags.Section_6_5

namespace Chapter6

-- <CONTEXT>
abbrev _root_.Real.Close (ε x y : ℝ) : Prop := dist x y ≤ ε

@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

@[coe]
abbrev Sequence.ofNatFun (a:ℕ → ℝ) : Sequence :=
 {
    m := 0
    seq n := if n ≥ 0 then a n.toNat else 0
    vanish := by simp_all
 }

instance Sequence.instCoe : Coe (ℕ → ℝ) Sequence where
  coe := ofNatFun

abbrev Sequence.mk' (m:ℤ) (a: { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

abbrev Sequence.from (a:Sequence) (m₁:ℤ) : Sequence := mk' (max a.m m₁) (a ↑·)

abbrev _root_.Real.CloseSeq (ε: ℝ) (a: _root_.Chapter6.Sequence) (L:ℝ) : Prop := ∀ n ≥ a.m, ε.Close (a n) L

abbrev _root_.Real.EventuallyClose (ε: ℝ) (a: _root_.Chapter6.Sequence) (L:ℝ) : Prop :=
  ∃ N ≥ a.m, ε.CloseSeq (a.from N) L

abbrev Sequence.TendsTo (a:Sequence) (L:ℝ) : Prop :=
  ∀ ε > (0:ℝ), ε.EventuallyClose a L

abbrev Sequence.subseq (a b: ℕ → ℝ) : Prop := ∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, b n = a (f n)
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem Sequence.convergent_iff_subseq (a:ℕ → ℝ) (L:ℝ) :
    (a:Sequence).TendsTo L ↔ ∀ b:ℕ → ℝ, Sequence.subseq a b → (b:Sequence).TendsTo L := by
-- </TARGET_THEOREM>

end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

/-- Proposition 6.6.5 / Exercise 6.6.4 (Mathlib formulation).
A real sequence `a : ℕ → ℝ` converges to `L` if and only if every subsequence
(obtained by composing with a strictly increasing `f : ℕ → ℕ`) also converges to `L`. -/
theorem Chapter6.Sequence.convergent_iff_subseq (a : ℕ → ℝ) (L : ℝ) :
    Tendsto a atTop (𝓝 L) ↔
      ∀ b : ℕ → ℝ,
        (∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, b n = a (f n)) →
          Tendsto b atTop (𝓝 L) :=
  by
end TaoBench
import Mathlib.Tactic
import Mathlib/Topology/Instances/Real

/-!
Self-contained snippet extracted for Chapter 6.3 target theorem.
-/

namespace Chapter6

/-- Definition 6.1.3 (Sequence over ℝ). -/
@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

/-- Sequences can be thought of as functions from ℤ to ℝ. -/
instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

abbrev Sequence.mk' (m:ℤ) (a: { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

/-- Start a sequence from a later index. -/
abbrev Sequence.from (a:Sequence) (m₁:ℤ) : Sequence := mk' (max a.m m₁) (a ↑·)

end Chapter6

/-- Definition 6.1.5 (ε-close to a limit along a sequence). -/
abbrev Real.CloseSeq (ε: ℝ) (a: Chapter6.Sequence) (L:ℝ) : Prop := ∀ n ≥ a.m, dist (a n) L ≤ ε

/-- Definition 6.1.5 (eventually ε-close to a limit). -/
abbrev Real.EventuallyClose (ε: ℝ) (a: Chapter6.Sequence) (L:ℝ) : Prop :=
  ∃ N ≥ a.m, ε.CloseSeq (a.from N) L

namespace Chapter6

/-- Definition 6.1.5/6.1.8: TendsTo and Convergent. -/
abbrev Sequence.TendsTo (a:Sequence) (L:ℝ) : Prop :=
  ∀ ε > (0:ℝ), ε.EventuallyClose a L

abbrev Sequence.Convergent (a:Sequence) : Prop := ∃ L, a.TendsTo L

/-- Bounded-above and monotone sequence (Section 6.3). -/
abbrev Sequence.BddAboveBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≤ M

abbrev Sequence.BddAbove (a:Sequence) : Prop := ∃ M, a.BddAboveBy M

abbrev Sequence.IsMonotone (a:Sequence) : Prop := ∀ n ≥ a.m, a (n+1) ≥ a n

/-- Proposition 6.3.8 / Exercise 6.3.3 -/
theorem Sequence.convergent_of_monotone {a:Sequence} (hbound: a.BddAbove) (hmono: a.IsMonotone) :
    a.Convergent := by
end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

/-- A real sequence which is eventually bounded above and eventually monotone
(non-decreasing) is convergent, in the ε–N sense. This is the Mathlib-style
reformulation of Tao's Proposition 6.3.8 / Exercise 6.3.3. -/
theorem Sequence.convergent_of_monotone
    (a : ℕ → ℝ)
    (hbound : ∃ M : ℝ, ∃ N₀ : ℕ, ∀ n ≥ N₀, a n ≤ M)
    (hmono  : ∃ N₁ : ℕ, ∀ n ≥ N₁, a (n+1) ≥ a n) :
    ∃ L : ℝ, ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, dist (a n) L ≤ ε := by
end TaoBench
import Mathlib.Data.Real.Basic
import Mathlib.Order.Monotone

namespace Chapter6

/-- Definition 6.6.1 -/
abbrev Sequence.subseq (a b: ℕ → ℝ) : Prop := ∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, b n = a (f n)

/- Exercise 6.6.2 -/
def Sequence.exist_subseq_of_subseq :
  Decidable (∃ a b : ℕ → ℝ, a ≠ b ∧ Sequence.subseq a b ∧ Sequence.subseq b a) := by
end Chapter6
import Mathlib
import Analysis.Section_6_5
import Analysis.Tags.Section_6_5

namespace Chapter6

-- <CONTEXT>
abbrev Sequence.subseq (a b: ℕ → ℝ) : Prop := ∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, b n = a (f n)
-- </CONTEXT>
-- <TARGET_THEOREM>
def Sequence.exist_subseq_of_subseq :
  Decidable (∃ a b : ℕ → ℝ, a ≠ b ∧ Sequence.subseq a b ∧ Sequence.subseq b a) := by
-- </TARGET_THEOREM>

end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
def Sequence.exist_subseq_of_subseq :
  Decidable
    (∃ a b : ℕ → ℝ,
      a ≠ b ∧
        (∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, b n = a (f n)) ∧
        (∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, a n = b (f n))) := by
end TaoBench
import Mathlib.Data.Real.EReal

namespace Chapter6

/--
  Definition 6.1.3 (Sequence). This is similar to the Chapter 5 sequence, except that now the
  sequence is real-valued. As with Chapter 5, we start sequences from 0 by default.
-/
@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

/-- Sequences can be thought of as functions from ℤ to ℝ. -/
instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

/-- Definition 6.3.1 -/
noncomputable abbrev Sequence.sup (a:Sequence) : EReal := sSup { x | ∃ n ≥ a.m, x = a n }

/-- Definition 6.3.1 -/
noncomputable abbrev Sequence.inf (a:Sequence) : EReal := sInf { x | ∃ n ≥ a.m, x = a n }

/-- Proposition 6.3.6 (Least upper bound property) / Exercise 6.3.2 -/
theorem Sequence.exists_between_lt_sup {a:Sequence} {y:EReal} (h: y < a.sup ) :
    ∃ n ≥ a.m, y < a n ∧ a n ≤ a.sup := by
end Chapter6
import Mathlib
import Analysis.Section_6_1
import Analysis.Tags.Section_6_1
import Analysis.Section_6_2
import Analysis.Tags.Section_6_2

namespace Chapter6

-- <CONTEXT>
abbrev _root_.EReal.IsFinite (x:EReal) : Prop := ∃ (y:Real), y = x

@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

abbrev Sequence.BoundedBy (a:Sequence) (M:ℝ) : Prop :=
  ∀ n, |a n| ≤ M

abbrev Sequence.IsBounded (a:Sequence) : Prop := ∃ M ≥ 0, a.BoundedBy M

noncomputable abbrev Sequence.sup (a:Sequence) : EReal := sSup { x | ∃ n ≥ a.m, x = a n }

noncomputable abbrev Sequence.inf (a:Sequence) : EReal := sInf { x | ∃ n ≥ a.m, x = a n }

abbrev Sequence.BddAboveBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≤ M

abbrev Sequence.BddAbove (a:Sequence) : Prop := ∃ M, a.BddAboveBy M

abbrev Sequence.BddBelowBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≥ M

abbrev Sequence.BddBelow (a:Sequence) : Prop := ∃ M, a.BddBelowBy M

theorem Sequence.bounded_iff (a:Sequence) : a.IsBounded ↔ a.BddAbove ∧ a.BddBelow := by
  sorry

theorem Sequence.sup_of_bounded {a:Sequence} (h: a.IsBounded) : a.sup.IsFinite := by
  sorry

theorem Sequence.inf_of_bounded {a:Sequence} (h: a.IsBounded) : a.inf.IsFinite := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem Sequence.exists_between_lt_sup {a:Sequence} {y:EReal} (h: y < a.sup ) :
    ∃ n ≥ a.m, y < a n ∧ a n ≤ a.sup := by
-- </TARGET_THEOREM>

end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem Sequence.exists_between_lt_sup
    {a : ℤ → ℝ} {m : ℤ} {y : EReal}
    (h : y < sSup {x : EReal | ∃ n ≥ m, x = a n}) :
    ∃ n ≥ m, y < a n ∧ a n ≤ sSup {x : EReal | ∃ n ≥ m, x = a n} := by
end TaoBench
import Mathlib.Tactic
import Mathlib.Data.Real.EReal
import Mathlib.Topology.Instances.Real

/-!
Self-contained slice for Chapter 6, Section 6.4 target theorem
-*/

abbrev Real.Close (ε x y : ℝ) : Prop := dist x y ≤ ε

namespace Chapter6

@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

/-- Sequences can be thought of as functions from ℤ to ℝ. -/
instance Sequence.instCoeFun : CoeFun Sequence (fun _ ↦ ℤ → ℝ) where
  coe a := a.seq

abbrev Sequence.mk' (m:ℤ) (a: { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

/--
  a.from n₁ starts `a:Sequence` from `n₁`.  It is intended for use when `n₁ ≥ n₀`, but returns
  the "junk" value of the original sequence `a` otherwise.
-/
abbrev Sequence.from (a:Sequence) (m₁:ℤ) : Sequence := mk' (max a.m m₁) (a ↑·)

end Chapter6

abbrev Real.Adherent (ε:ℝ) (a:Chapter6.Sequence) (x:ℝ) := ∃ n ≥ a.m, ε.Close (a n) x

abbrev Real.ContinuallyAdherent (ε:ℝ) (a:Chapter6.Sequence) (x:ℝ) :=
  ∀ N ≥ a.m, ε.Adherent (a.from N) x

namespace Chapter6

open EReal

abbrev Sequence.BddAboveBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≤ M

abbrev Sequence.BddAbove (a:Sequence) : Prop := ∃ M, a.BddAboveBy M

abbrev Sequence.BddBelowBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≥ M

abbrev Sequence.BddBelow (a:Sequence) : Prop := ∃ M, a.BddBelowBy M

abbrev Sequence.LimitPoint (a:Sequence) (x:ℝ) : Prop :=
  ∀ ε > (0:ℝ), ε.ContinuallyAdherent a x

/-- This definition is needed for Exercises 6.4.8 and 6.4.9. -/
abbrev Sequence.ExtendedLimitPoint (a:Sequence) (x:EReal) : Prop := if x = ⊤ then ¬ a.BddAbove else if x = ⊥ then ¬ a.BddBelow else a.LimitPoint x.toReal

/-- Exercise 6.4.9 -/
theorem Sequence.exists_three_limit_points :
  ∃ a:Sequence, ∀ L:EReal, a.ExtendedLimitPoint L ↔ L = ⊥ ∨ L = 0 ∨ L = ⊤ := by
end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

namespace Chapter6

namespace Sequence

/-- There exists a real sequence whose extended limit points (in `EReal`) are
exactly `⊥`, `0`, and `⊤`.

Here an extended limit point `L : EReal` of a sequence `a : ℕ → ℝ` means:
* if `L = ⊤`, then `a` is not bounded above;
* if `L = ⊥`, then `a` is not bounded below;
* if `L` is finite, then for every `ε > 0` and every `N` there exists `n ≥ N`
  with `dist (a n) (EReal.toReal L) ≤ ε`. -/
theorem exists_three_limit_points :
  ∃ a : ℕ → ℝ,
    ∀ L : EReal,
      (if L = ⊤ then
          ¬ ∃ M : ℝ, ∀ n : ℕ, a n ≤ M
        else if L = ⊥ then
          ¬ ∃ M : ℝ, ∀ n : ℕ, M ≤ a n
        else
          ∀ ε > (0 : ℝ),
            ∀ N : ℕ, ∃ n ≥ N, dist (a n) (EReal.toReal L) ≤ ε)
      ↔
      L = ⊥ ∨ L = 0 ∨ L = ⊤ := by
end Sequence

end Chapter6

end TaoBench
import Mathlib.Tactic
import Mathlib.Data.Real.EReal
import Mathlib.Topology.Instances.Real

/-!
Self-contained slice for Chapter 6.4 target theorem
-/

abbrev Real.Close (ε x y : ℝ) : Prop := dist x y ≤ ε

namespace Chapter6

@[ext]
structure Sequence where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

instance : CoeFun Sequence (fun _ => ℤ → ℝ) where
  coe a := a.seq

abbrev Sequence.mk' (m:ℤ) (a: { n // n ≥ m } → ℝ) : Sequence where
  m := m
  seq n := if h : n ≥ m then a ⟨n, h⟩ else 0
  vanish := by simp_all

/-- start a sequence from index `m₁` (junk values before that) -/
abbrev Sequence.from (a:Sequence) (m₁:ℤ) : Sequence := mk' (max a.m m₁) (a ↑·)

end Chapter6

abbrev Real.Adherent (ε:ℝ) (a:Chapter6.Sequence) (x:ℝ) := ∃ n ≥ a.m, ε.Close (a n) x

abbrev Real.ContinuallyAdherent (ε:ℝ) (a:Chapter6.Sequence) (x:ℝ) :=
  ∀ N ≥ a.m, ε.Adherent (a.from N) x

namespace Chapter6

abbrev Sequence.LimitPoint (a:Sequence) (x:ℝ) : Prop :=
  ∀ ε > (0:ℝ), ε.ContinuallyAdherent a x

noncomputable abbrev Sequence.inf (a:Sequence) : EReal :=
  sInf { x | ∃ n ≥ a.m, x = a n }

noncomputable abbrev Sequence.lowerseq (a:Sequence) : ℤ → EReal := fun N ↦ (a.from N).inf

noncomputable abbrev Sequence.liminf (a:Sequence) : EReal :=
  sSup { x | ∃ N ≥ a.m, x = a.lowerseq N }

abbrev Sequence.BddAboveBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≤ M

abbrev Sequence.BddAbove (a:Sequence) : Prop := ∃ M, a.BddAboveBy M

abbrev Sequence.BddBelowBy (a:Sequence) (M:ℝ) : Prop := ∀ n ≥ a.m, a n ≥ M

abbrev Sequence.BddBelow (a:Sequence) : Prop := ∃ M, a.BddBelowBy M

/-- This definition is needed for Exercises 6.4.8 and 6.4.9. -/
abbrev Sequence.ExtendedLimitPoint (a:Sequence) (x:EReal) : Prop :=
  if x = ⊤ then ¬ a.BddAbove else if x = ⊥ then ¬ a.BddBelow else a.LimitPoint x.toReal

/-- Exercise 6.4.8 -/
theorem Sequence.extended_limit_point_of_liminf (a:Sequence) : a.ExtendedLimitPoint a.liminf := by
end Chapter6
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

namespace Sequence

/-- Mathlib translation of Tao's `Sequence.extended_limit_point_of_liminf`.

For a real sequence `u : ℕ → ℝ`, let
`L := Filter.liminf (fun n : ℕ => (u n : EReal)) atTop`.

The statement `a.ExtendedLimitPoint a.liminf` in Tao's setting becomes:

* If `L = ⊤`, then `u` is not bounded above.
* If `L = ⊥`, then `u` is not bounded below.
* If `L` is finite, then `L.toReal` is a limit point of `u`
  in the sense that every tail of `u` comes arbitrarily close to `L.toReal`. -/
theorem extended_limit_point_of_liminf (u : ℕ → ℝ) :
  (if
      Filter.liminf (fun n : ℕ => (u n : EReal)) (Filter.atTop : Filter ℕ)
        = (⊤ : EReal)
    then
      ¬ ∃ M : ℝ, ∀ n : ℕ, u n ≤ M
    else
      if
        Filter.liminf (fun n : ℕ => (u n : EReal)) (Filter.atTop : Filter ℕ)
          = (⊥ : EReal)
      then
        ¬ ∃ M : ℝ, ∀ n : ℕ, u n ≥ M
      else
        ∀ ε > (0 : ℝ), ∀ N : ℕ, ∃ n ≥ N,
          dist (u n)
               (EReal.toReal
                 (Filter.liminf (fun n : ℕ => (u n : EReal))
                   (Filter.atTop : Filter ℕ)))
            ≤ ε
  ) := by
end Sequence

end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

/--
Mathlib-only version of Tao's Exercise 6.4.8:

For a real sequence `u : ℕ → ℝ`, let `L` be its extended-real limsup
`Filter.limsup (fun n ↦ (u n : EReal)) atTop`. Then `L` is an
“extended limit point” of `u` in Tao's sense: if `L = +∞` then `u` is
not bounded above; if `L = -∞` then `u` is not bounded below; and if
`L` is finite then the real number underlying `L` is a limit point of
`u` in the usual ε–N sense.
-/
theorem Sequence.extended_limit_point_of_limsup (u : ℕ → ℝ) :
  (let L : EReal :=
    Filter.limsup (fun n : ℕ => (u n : EReal)) (Filter.atTop : Filter ℕ);
    if hL : L = ⊤ then
      -- case `L = +∞`: `u` is not bounded above
      ¬ ∃ M : ℝ, ∀ n : ℕ, u n ≤ M
    else if hL' : L = ⊥ then
      -- case `L = -∞`: `u` is not bounded below
      ¬ ∃ M : ℝ, ∀ n : ℕ, u n ≥ M
    else
      -- finite case: `L.toReal` is a limit point of `u`
      ∀ ε > (0 : ℝ), ∀ N : ℕ, ∃ n ≥ N, dist (u n) L.toReal ≤ ε) := by
end TaoBench