introvoyz041/TaoAnalysisBench huggingface dataset:
import Mathlib/Tactic
import Mathlib/Analysis/Calculus/Deriv
import Mathlib/Topology/Instances/Real
import Mathlib/Data/Real/Basic
import Mathlib/Data/Set/Intervals/Basic

namespace Chapter10

/-- Proposition 10.2.6 (Local extrema are stationary) / Exercise 10.2.1 -/
theorem IsLocalMinOn.deriv_eq_zero {a b:ℝ} (hab: a < b) {f:ℝ → ℝ} {x₀:ℝ}
  (hx₀: x₀ ∈ Set.Ioo a b) (h: IsLocalMinOn f (.Ioo a b) x₀) {L:ℝ}
  (hderiv: HasDerivWithinAt f L (.Ioo a b) x₀) : L = 0 := by
end Chapter10
import Mathlib
import Analysis.Section_9_6
import Analysis.Tags.Section_9_6

namespace Chapter10

-- <CONTEXT>
theorem IsLocalMaxOn.iff (X:Set ℝ) (f:ℝ → ℝ) (x₀:ℝ) :
  IsLocalMaxOn f X x₀ ↔
  ∃ δ > 0, IsMaxOn f (X ∩ .Ioo (x₀ - δ) (x₀ + δ)) x₀ := by
  sorry

theorem IsLocalMinOn.iff (X:Set ℝ) (f:ℝ → ℝ) (x₀:ℝ) :
  IsLocalMinOn f X x₀ ↔
  ∃ δ > 0, IsMinOn f (X ∩ .Ioo (x₀ - δ) (x₀ + δ)) x₀ := by
  sorry

abbrev f_10_2_3 : ℝ → ℝ := fun x ↦ x^2 - x^4

theorem IsLocalMaxOn.of_restrict {X Y:Set ℝ} (hXY: Y ⊆ X) (f:ℝ → ℝ) (x₀:ℝ)
  (h: IsLocalMaxOn f X x₀) : IsLocalMaxOn f Y x₀ := by
  sorry

theorem IsLocalMinOn.of_restrict {X Y:Set ℝ} (hXY: Y ⊆ X) (f:ℝ → ℝ) (x₀:ℝ)
  (h: IsLocalMinOn f X x₀) : IsLocalMinOn f Y x₀ := by
  sorry

theorem IsMaxOn.deriv_eq_zero_counter : ∃ (a b:ℝ) (hab: a < b) (f:ℝ → ℝ)
  (x₀:ℝ) (hx₀: x₀ ∈ Set.Icc a b) (h: IsMaxOn f (.Icc a b) x₀) (L:ℝ)
  (hderiv: HasDerivWithinAt f L (.Icc a b) x₀), L ≠ 0 := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem IsLocalMinOn.deriv_eq_zero {a b:ℝ} (hab: a < b) {f:ℝ → ℝ} {x₀:ℝ}
  (hx₀: x₀ ∈ Set.Ioo a b) (h: IsLocalMinOn f (.Ioo a b) x₀) {L:ℝ}
  (hderiv: HasDerivWithinAt f L (.Ioo a b) x₀) : L = 0 := by
-- </TARGET_THEOREM>

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

namespace TaoBench

/-- Proposition 10.2.6 (Local extrema are stationary) / Exercise 10.2.1 -/
theorem IsLocalMinOn.deriv_eq_zero {a b : ℝ} (hab : a < b) {f : ℝ → ℝ} {x₀ : ℝ}
  (hx₀ : x₀ ∈ Set.Ioo a b) (h : IsLocalMinOn f (Set.Ioo a b) x₀) {L : ℝ}
  (hderiv : HasDerivWithinAt f L (Set.Ioo a b) x₀) : L = 0 := by
end TaoBench
import Mathlib.Tactic
import Mathlib.Analysis.Calculus.Deriv
import Mathlib.Topology.Instances.Real

namespace Chapter10

/-- Proposition 10.3.1 / Exercise 10.3.1 -/
theorem derivative_of_monotone (X:Set ℝ) {x₀:ℝ} (hx₀: ClusterPt x₀ (.principal (X \ {x₀})))
  {f:ℝ → ℝ} (hmono: Monotone f) (hderiv: DifferentiableWithinAt ℝ f X x₀) :
    derivWithin f X x₀ ≥ 0 := by
end Chapter10
import Mathlib

namespace Chapter10

-- <CONTEXT>
theorem derivative_of_antitone (X:Set ℝ) {x₀:ℝ} (hx₀: ClusterPt x₀ (.principal (X \ {x₀})))
  {f:ℝ → ℝ} (hmono: Antitone f) (hderiv: DifferentiableWithinAt ℝ f X x₀) :
    derivWithin f X x₀ ≤ 0 := by
  sorry

theorem strictAnti_of_negative_derivative {a b:ℝ} (hab: a < b) {f:ℝ → ℝ}
  (hderiv: DifferentiableOn ℝ f (.Icc a b)) (hneg: ∀ x ∈ Set.Ioo a b, derivWithin f (.Icc a b) x < 0) :
    StrictAntiOn f (.Icc a b) := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem derivative_of_monotone (X:Set ℝ) {x₀:ℝ} (hx₀: ClusterPt x₀ (.principal (X \ {x₀})))
  {f:ℝ → ℝ} (hmono: Monotone f) (hderiv: DifferentiableWithinAt ℝ f X x₀) :
    derivWithin f X x₀ ≥ 0 := by
-- </TARGET_THEOREM>

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

namespace TaoBench

/-- Proposition 10.3.1 / Exercise 10.3.1 -/
theorem derivative_of_monotone (X : Set ℝ) {x₀ : ℝ}
  (hx₀ : ClusterPt x₀ (.principal (X \ {x₀})))
  {f : ℝ → ℝ} (hmono : Monotone f)
  (hderiv : DifferentiableWithinAt ℝ f X x₀) :
    derivWithin f X x₀ ≥ 0 := by
end TaoBench
import Mathlib.Analysis.Calculus.Deriv

namespace Chapter10

/-- Exercise 10.2.6 -/
theorem lipschitz_bound {M a b:ℝ} (hM: M > 0) (hab: a < b) {f:ℝ → ℝ}
  (hcont: ContinuousOn f (.Icc a b))
  (hderiv: DifferentiableOn ℝ f (.Ioo a b))
  (hlip: ∀ x ∈ Set.Ioo a b, |derivWithin f (.Ioo a b) x| ≤ M)
  {x y:ℝ} (hx: x ∈ Set.Ioo a b) (hy: y ∈ Set.Ioo a b) :
  |f x - f y| ≤ M * |x - y| := by
end Chapter10
import Mathlib
import Analysis.Section_9_6
import Analysis.Tags.Section_9_6

namespace Chapter10

-- <CONTEXT>
theorem IsLocalMaxOn.iff (X:Set ℝ) (f:ℝ → ℝ) (x₀:ℝ) :
  IsLocalMaxOn f X x₀ ↔
  ∃ δ > 0, IsMaxOn f (X ∩ .Ioo (x₀ - δ) (x₀ + δ)) x₀ := by
  sorry

theorem IsLocalMinOn.iff (X:Set ℝ) (f:ℝ → ℝ) (x₀:ℝ) :
  IsLocalMinOn f X x₀ ↔
  ∃ δ > 0, IsMinOn f (X ∩ .Ioo (x₀ - δ) (x₀ + δ)) x₀ := by
  sorry

abbrev f_10_2_3 : ℝ → ℝ := fun x ↦ x^2 - x^4

theorem IsLocalMaxOn.of_restrict {X Y:Set ℝ} (hXY: Y ⊆ X) (f:ℝ → ℝ) (x₀:ℝ)
  (h: IsLocalMaxOn f X x₀) : IsLocalMaxOn f Y x₀ := by
  sorry

theorem IsLocalMinOn.of_restrict {X Y:Set ℝ} (hXY: Y ⊆ X) (f:ℝ → ℝ) (x₀:ℝ)
  (h: IsLocalMinOn f X x₀) : IsLocalMinOn f Y x₀ := by
  sorry

theorem IsMaxOn.deriv_eq_zero_counter : ∃ (a b:ℝ) (hab: a < b) (f:ℝ → ℝ)
  (x₀:ℝ) (hx₀: x₀ ∈ Set.Icc a b) (h: IsMaxOn f (.Icc a b) x₀) (L:ℝ)
  (hderiv: HasDerivWithinAt f L (.Icc a b) x₀), L ≠ 0 := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem lipschitz_bound {M a b:ℝ} (hM: M > 0) (hab: a < b) {f:ℝ → ℝ}
  (hcont: ContinuousOn f (.Icc a b))
  (hderiv: DifferentiableOn ℝ f (.Ioo a b))
  (hlip: ∀ x ∈ Set.Ioo a b, |derivWithin f (.Ioo a b) x| ≤ M)
  {x y:ℝ} (hx: x ∈ Set.Ioo a b) (hy: y ∈ Set.Ioo a b) :
  |f x - f y| ≤ M * |x - y| := by
-- </TARGET_THEOREM>

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

namespace TaoBench

/-- Exercise 10.2.6 (Tao, Analysis I).

If a real function is continuous on `[a, b]`, differentiable on `(a, b)`, and its
derivative on `(a, b)` is bounded in absolute value by `M > 0`, then it is
Lipschitz with constant `M` on `(a, b)`. -/
theorem lipschitz_bound
  {M a b : ℝ} (hM : M > 0) (hab : a < b) {f : ℝ → ℝ}
  (hcont : ContinuousOn f (Icc a b))
  (hderiv : DifferentiableOn ℝ f (Ioo a b))
  (hlip : ∀ x ∈ Ioo a b, |derivWithin f (Ioo a b) x| ≤ M)
  {x y : ℝ} (hx : x ∈ Ioo a b) (hy : y ∈ Ioo a b) :
  |f x - f y| ≤ M * |x - y| := by
end TaoBench
import Mathlib.Tactic
import Mathlib.Analysis.Calculus.Deriv

namespace Chapter10

/-- Proposition 10.3.3 / Exercise 10.3.4 -/
theorem strictMono_of_positive_derivative {a b:ℝ} (hab: a < b) {f:ℝ → ℝ}
  (hderiv: DifferentiableOn ℝ f (.Icc a b)) (hpos: ∀ x ∈ Set.Ioo a b, derivWithin f (.Icc a b) x > 0) :
    StrictMonoOn f (.Icc a b) := by
end Chapter10
import Mathlib

namespace Chapter10

-- <CONTEXT>
theorem derivative_of_antitone (X:Set ℝ) {x₀:ℝ} (hx₀: ClusterPt x₀ (.principal (X \ {x₀})))
  {f:ℝ → ℝ} (hmono: Antitone f) (hderiv: DifferentiableWithinAt ℝ f X x₀) :
    derivWithin f X x₀ ≤ 0 := by
  sorry

theorem strictAnti_of_negative_derivative {a b:ℝ} (hab: a < b) {f:ℝ → ℝ}
  (hderiv: DifferentiableOn ℝ f (.Icc a b)) (hneg: ∀ x ∈ Set.Ioo a b, derivWithin f (.Icc a b) x < 0) :
    StrictAntiOn f (.Icc a b) := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem strictMono_of_positive_derivative {a b:ℝ} (hab: a < b) {f:ℝ → ℝ}
  (hderiv: DifferentiableOn ℝ f (.Icc a b)) (hpos: ∀ x ∈ Set.Ioo a b, derivWithin f (.Icc a b) x > 0) :
    StrictMonoOn f (.Icc a b) := by
-- </TARGET_THEOREM>

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

namespace TaoBench

/-- Proposition 10.3.3 / Exercise 10.3.4 -/
theorem strictMono_of_positive_derivative {a b : ℝ} (hab : a < b) {f : ℝ → ℝ}
    (hderiv : DifferentiableOn ℝ f (Set.Icc a b))
    (hpos : ∀ x ∈ Set.Ioo a b, derivWithin f (Set.Icc a b) x > 0) :
    StrictMonoOn f (Set.Icc a b) := by
end TaoBench
import Mathlib.Data.Real.Basic
import Mathlib.Data.Set.Intervals.Basic
import Mathlib.Topology.Instances.Real
import Mathlib.Topology.Algebra.Bornology

namespace Chapter11

inductive BoundedInterval where
  | Ioo (a b:ℝ) : BoundedInterval
  | Icc (a b:ℝ) : BoundedInterval
  | Ioc (a b:ℝ) : BoundedInterval
  | Ico (a b:ℝ) : BoundedInterval

open BoundedInterval

@[coe]
def BoundedInterval.toSet (I: BoundedInterval) : Set ℝ := match I with
  | Ioo a b => .Ioo a b
  | Icc a b => .Icc a b
  | Ioc a b => .Ioc a b
  | Ico a b => .Ico a b

instance BoundedInterval.inst_coeSet : Coe BoundedInterval (Set ℝ) where
  coe := toSet

/-- Lemma 11.1.4 / Exercise 11.1.1 -/
theorem Bornology.IsBounded.of_boundedInterval (I: BoundedInterval) : Bornology.IsBounded (I:Set ℝ) := by
end Chapter11
import Mathlib

namespace Chapter11

-- <CONTEXT>
inductive BoundedInterval where
  | Ioo (a b:ℝ) : BoundedInterval
  | Icc (a b:ℝ) : BoundedInterval
  | Ioc (a b:ℝ) : BoundedInterval
  | Ico (a b:ℝ) : BoundedInterval

open BoundedInterval

@[coe]
def BoundedInterval.toSet (I: BoundedInterval) : Set ℝ := match I with
  | Ioo a b => .Ioo a b
  | Icc a b => .Icc a b
  | Ioc a b => .Ioc a b
  | Ico a b => .Ico a b

instance BoundedInterval.inst_coeSet : Coe BoundedInterval (Set ℝ) where
  coe := toSet

instance BoundedInterval.instEmpty : EmptyCollection BoundedInterval where
  emptyCollection := Ioo 0 0

@[simp]
theorem BoundedInterval.coe_empty : ((∅ : BoundedInterval):Set ℝ) = ∅ := by
  sorry

open Classical in
noncomputable instance BoundedInterval.decidableEq : DecidableEq BoundedInterval := instDecidableEqOfLawfulBEq

@[simp]
theorem BoundedInterval.set_Ioo (a b:ℝ) : (Ioo a b : Set ℝ) = .Ioo a b := by
  sorry

@[simp]
theorem BoundedInterval.set_Icc (a b:ℝ) : (Icc a b : Set ℝ) = .Icc a b := by
  sorry

@[simp]
theorem BoundedInterval.set_Ioc (a b:ℝ) : (Ioc a b : Set ℝ) = .Ioc a b := by
  sorry

@[simp]
theorem BoundedInterval.set_Ico (a b:ℝ) : (Ico a b : Set ℝ) = .Ico a b := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem Bornology.IsBounded.of_boundedInterval (I: BoundedInterval) : Bornology.IsBounded (I:Set ℝ) := by
-- </TARGET_THEOREM>

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

namespace TaoBench
theorem Bornology.IsBounded.of_boundedInterval
    (s : Set ℝ)
    (hs :
      (∃ a b : ℝ, s = Ioo a b) ∨
      (∃ a b : ℝ, s = Icc a b) ∨
      (∃ a b : ℝ, s = Ioc a b) ∨
      (∃ a b : ℝ, s = Ico a b)) :
    Bornology.IsBounded s := by
end TaoBench
import Mathlib.Data.Real.Basic
import Mathlib.Data.Set.Lattice
import Mathlib.Data.Set.Intervals.Basic

namespace Chapter11

inductive BoundedInterval where
  | Ioo (a b:ℝ) : BoundedInterval
  | Icc (a b:ℝ) : BoundedInterval
  | Ioc (a b:ℝ) : BoundedInterval
  | Ico (a b:ℝ) : BoundedInterval

@[coe]
def BoundedInterval.toSet (I: BoundedInterval) : Set ℝ := match I with
  | Ioo a b => .Ioo a b
  | Icc a b => .Icc a b
  | Ioc a b => .Ioc a b
  | Ico a b => .Ico a b

instance BoundedInterval.inst_coeSet : Coe BoundedInterval (Set ℝ) where
  coe := toSet

/-- Corollary 11.1.6 / Exercise 11.1.2 -/
theorem BoundedInterval.inter (I J: BoundedInterval) : ∃ K : BoundedInterval, (I:Set ℝ) ∩ (J:Set ℝ) = (K:Set ℝ) := by
end Chapter11
import Mathlib

namespace Chapter11

-- <CONTEXT>
inductive BoundedInterval where
  | Ioo (a b:ℝ) : BoundedInterval
  | Icc (a b:ℝ) : BoundedInterval
  | Ioc (a b:ℝ) : BoundedInterval
  | Ico (a b:ℝ) : BoundedInterval

open BoundedInterval

@[coe]
def BoundedInterval.toSet (I: BoundedInterval) : Set ℝ := match I with
  | Ioo a b => .Ioo a b
  | Icc a b => .Icc a b
  | Ioc a b => .Ioc a b
  | Ico a b => .Ico a b

instance BoundedInterval.inst_coeSet : Coe BoundedInterval (Set ℝ) where
  coe := toSet

instance BoundedInterval.instEmpty : EmptyCollection BoundedInterval where
  emptyCollection := Ioo 0 0

@[simp]
theorem BoundedInterval.coe_empty : ((∅ : BoundedInterval):Set ℝ) = ∅ := by
  sorry

open Classical in
noncomputable instance BoundedInterval.decidableEq : DecidableEq BoundedInterval := instDecidableEqOfLawfulBEq

@[simp]
theorem BoundedInterval.set_Ioo (a b:ℝ) : (Ioo a b : Set ℝ) = .Ioo a b := by
  sorry

@[simp]
theorem BoundedInterval.set_Icc (a b:ℝ) : (Icc a b : Set ℝ) = .Icc a b := by
  sorry

@[simp]
theorem BoundedInterval.set_Ioc (a b:ℝ) : (Ioc a b : Set ℝ) = .Ioc a b := by
  sorry

@[simp]
theorem BoundedInterval.set_Ico (a b:ℝ) : (Ico a b : Set ℝ) = .Ico a b := by
  sorry

theorem BoundedInterval.ordConnected_iff (X:Set ℝ) : Bornology.IsBounded X ∧ X.OrdConnected ↔ ∃ I: BoundedInterval, X = I := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem BoundedInterval.inter (I J: BoundedInterval) : ∃ K : BoundedInterval, (I:Set ℝ) ∩ (J:Set ℝ) = (K:Set ℝ) := by
-- </TARGET_THEOREM>

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

namespace TaoBench

/-- Corollary 11.1.6 / Exercise 11.1.2 (Mathlib-only formulation).

If `I` and `J` are (possibly empty) bounded intervals of one of the four
standard types `Ioo`, `Icc`, `Ioc`, `Ico`, then their intersection is again
an interval of one of these four types. -/
theorem BoundedInterval.inter
    (I J : Set ℝ)
    (hI : ∃ a b : ℝ,
      I = Ioo a b ∨ I = Icc a b ∨ I = Ioc a b ∨ I = Ico a b)
    (hJ : ∃ a b : ℝ,
      J = Ioo a b ∨ J = Icc a b ∨ J = Ioc a b ∨ J = Ico a b) :
    ∃ a b : ℝ,
      I ∩ J = Ioo a b ∨ I ∩ J = Icc a b ∨ I ∩ J = Ioc a b ∨ I ∩ J = Ico a b := by
end TaoBench
import Mathlib.Tactic
import Mathlib.Data.Real.Basic

namespace Chapter11

inductive BoundedInterval where
  | Ioo (a b:ℝ) : BoundedInterval
  | Icc (a b:ℝ) : BoundedInterval
  | Ioc (a b:ℝ) : BoundedInterval
  | Ico (a b:ℝ) : BoundedInterval

open BoundedInterval

@[coe]
def BoundedInterval.toSet (I: BoundedInterval) : Set ℝ := match I with
  | Ioo a b => .Ioo a b
  | Icc a b => .Icc a b
  | Ioc a b => .Ioc a b
  | Ico a b => .Ico a b

instance BoundedInterval.inst_coeSet : Coe BoundedInterval (Set ℝ) where
  coe := toSet

open Classical in
/-- This is to make Finsets of BoundedIntervals work properly -/
noncomputable instance BoundedInterval.decidableEq : DecidableEq BoundedInterval := instDecidableEqOfLawfulBEq

@[simp]
 theorem BoundedInterval.set_Ioo (a b:ℝ) : (Ioo a b : Set ℝ) = .Ioo a b := by rfl
@[simp]
 theorem BoundedInterval.set_Icc (a b:ℝ) : (Icc a b : Set ℝ) = .Icc a b := by rfl
@[simp]
 theorem BoundedInterval.set_Ioc (a b:ℝ) : (Ioc a b : Set ℝ) = .Ioc a b := by rfl
@[simp]
 theorem BoundedInterval.set_Ico (a b:ℝ) : (Ico a b : Set ℝ) = .Ico a b := by rfl

instance BoundedInterval.instMembership : Membership ℝ BoundedInterval where
  mem I x := x ∈ (I:Set ℝ)

@[simp] theorem BoundedInterval.mem_iff (I: BoundedInterval) (x:ℝ) :
  x ∈ I ↔ x ∈ (I:Set ℝ) := by rfl

instance BoundedInterval.instSubset : HasSubset BoundedInterval where
  Subset I J := ∀ x, x ∈ I → x ∈ J

@[simp] theorem BoundedInterval.subset_iff (I J: BoundedInterval) :
  I ⊆ J ↔ (I:Set ℝ) ⊆ (J:Set ℝ) := by rfl

@[ext]
structure Partition (I: BoundedInterval) where
  intervals : Finset BoundedInterval
  exists_unique (x:ℝ) (hx : x ∈ I) : ∃! J, J ∈ intervals ∧ x ∈ J
  contains (J : BoundedInterval) (hJ : J ∈ intervals) : J ⊆ I

instance Partition.instMembership (I: BoundedInterval) : Membership BoundedInterval (Partition I) where
  mem P J := J ∈ P.intervals

/-- Definition 11.1.14 (Finer and coarser partitions) -/
instance Partition.instLE (I: BoundedInterval) : LE (Partition I) where
  le P P' := ∀ J ∈ P'.intervals, ∃ K ∈ P, J ⊆ K

-- Auxiliary: provide Max instance so ⊔ parses. This is only to enable parsing of the target theorem.
noncomputable instance Aux_Partition.instMax (I: BoundedInterval) : Max (Partition I) where
  max P P' := P

/-- Lemma 11.1.8 / Exercise 11.1.4 -/
theorem BoundedInterval.le_max {I: BoundedInterval} (P P': Partition I) :
  P ≤ P ⊔ P' ∧ P' ≤ P ⊔ P' := by
end Chapter11
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem BoundedInterval.le_max {α : Type*} [SemilatticeSup α] (x y : α) :
  x ≤ x ⊔ y ∧ y ≤ x ⊔ y := by
end TaoBench
import Mathlib.Tactic
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Finset.Interval

namespace Chapter7

open BigOperators

/--
  Definition 7.2.1 (Formal infinite series). This is similar to Chapter 6 sequence, but is
  manipulated differently. As with Chapter 5, we will start series from 0 by default.
-/
@[ext]
structure Series where
  m : ℤ
  seq : ℤ → ℝ
  vanish : ∀ n < m, seq n = 0

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

/-- Definition 7.2.2 (Convergence of series) -/
abbrev Series.partial (s : Series) (N:ℤ) : ℝ := ∑ n ∈ Finset.Icc s.m N, s.seq n

abbrev Series.convergesTo (s : Series) (L:ℝ) : Prop := Filter.atTop.Tendsto (s.partial) (nhds L)

abbrev Series.converges (s : Series) : Prop := ∃ L, s.convergesTo L

end Chapter7

/-- Exercise 11.6.5, moved to Section 11.9 -/
theorem Chapter7.Series.converges_qseries' (p:ℝ) :
  (mk' (m := 1) fun n ↦ 1 / (n:ℝ) ^ p : Series).converges ↔ (p>1) := by
import Mathlib

-- <CONTEXT>
open BigOperators

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

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

abbrev Chapter7.Series.partial (s : Chapter7.Series) (N:ℤ) : ℝ := ∑ n ∈ Finset.Icc s.m N, s.seq n

abbrev Chapter7.Series.convergesTo (s : Chapter7.Series) (L:ℝ) : Prop := Filter.atTop.Tendsto (s.partial) (nhds L)

abbrev Chapter7.Series.converges (s : Chapter7.Series) : Prop := ∃ L, s.convergesTo L

abbrev Chapter7.Series.abs (s:Chapter7.Series) : Chapter7.Series := mk' (m:=s.m) (fun n ↦ |s.seq n|)

abbrev Chapter7.Series.absConverges (s:Chapter7.Series) : Prop := s.abs.converges

theorem Chapter7.Series.converges_qseries'' (p:ℝ) : (mk' (m := 1) fun n ↦ 1 / (n:ℝ) ^ p : Series).absConverges ↔ (p>1) := by
  sorry
-- </CONTEXT>
-- <TARGET_THEOREM>
theorem Chapter7.Series.converges_qseries' (p:ℝ) :
    (mk' (m := 1) fun n ↦ 1 / (n:ℝ) ^ p : Series).converges ↔ (p>1) := by
-- </TARGET_THEOREM>
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem Chapter7.Series.converges_qseries' (p : ℝ) :
    Summable (fun n : ℕ => 1 / (n.succ : ℝ) ^ p) ↔ p > 1 := by
end TaoBench
import Mathlib.Data.Real.Basic

namespace Chapter11

inductive BoundedInterval where
  | Ioo (a b:ℝ) : BoundedInterval
  | Icc (a b:ℝ) : BoundedInterval
  | Ioc (a b:ℝ) : BoundedInterval
  | Ico (a b:ℝ) : BoundedInterval

open BoundedInterval

@[coe]
def BoundedInterval.toSet (I: BoundedInterval) : Set ℝ := match I with
  | Ioo a b => .Ioo a b
  | Icc a b => .Icc a b
  | Ioc a b => .Ioc a b
  | Ico a b => .Ico a b

instance BoundedInterval.inst_coeSet : Coe BoundedInterval (Set ℝ) where
  coe := toSet

instance BoundedInterval.instMembership : Membership ℝ BoundedInterval where
  mem I x := x ∈ (I:Set ℝ)

instance BoundedInterval.instSubset : HasSubset BoundedInterval where
  Subset I J := ∀ x, x ∈ I → x ∈ J

@[ext]
structure Partition (I: BoundedInterval) where
  intervals : Finset BoundedInterval
  exists_unique (x:ℝ) (hx : x ∈ I) : ∃! J, J ∈ intervals ∧ x ∈ J
  contains (J : BoundedInterval) (hJ : J ∈ intervals) : J ⊆ I

instance Partition.instMembership (I: BoundedInterval) : Membership BoundedInterval (Partition I) where
  mem P J := J ∈ P.intervals

/-- Definition 11.2.1 -/
abbrev Constant {X Y:Type} (f: X → Y) : Prop := ∃ c, ∀ x, f x = c

abbrev ConstantOn (f: ℝ → ℝ) (X: Set ℝ) : Prop := Constant (fun x : X ↦ f ↑x)

/-- Definition 11.2.3 (Piecewise constant functions I) -/
abbrev PiecewiseConstantWith (f:ℝ → ℝ) {I: BoundedInterval} (P: Partition I) : Prop := ∀ J ∈ P, ConstantOn f (J:Set ℝ)

/-- Definition 11.2.5 (Piecewise constant functions I) -/
abbrev PiecewiseConstantOn (f:ℝ → ℝ) (I: BoundedInterval) : Prop := ∃ P : Partition I, PiecewiseConstantWith f P

/-- Example 11.2.6 -/
theorem ConstantOn.piecewiseConstantOn {f:ℝ → ℝ} {I: BoundedInterval} (h: ConstantOn f (I:Set ℝ)) :
  PiecewiseConstantOn f I := by
end Chapter11
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem ConstantOn.piecewiseConstantOn
    {f : ℝ → ℝ}
    {I : Set ℝ}
    (hI : ∃ a b : ℝ,
      I = Ioo a b ∨ I = Icc a b ∨ I = Ioc a b ∨ I = Ico a b)
    (hconst : ∃ c : ℝ, ∀ x ∈ I, f x = c) :
    ∃ (P : Finset (Set ℝ)),
      (∀ J ∈ P, J ⊆ I) ∧
      (∀ x ∈ I, ∃! J, J ∈ P ∧ x ∈ J) ∧
      (∀ J ∈ P, ∃ a b : ℝ,
        J = Ioo a b ∨ J = Icc a b ∨ J = Ioc a b ∨ J = Ico a b) ∧
      (∀ J ∈ P, ∃ c : ℝ, ∀ x ∈ J, f x = c) := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem DifferentiableOn.of_F_11_9_2' {q : ℚ}
    (hq : (q : ℝ) ∈ Set.Icc (0 : ℝ) 1) :
    ¬ DifferentiableWithinAt ℝ
        (fun x : ℝ =>
          let q_9_8_5 : ℕ ≃ ℚ := nonempty_equiv_of_countable.some
          let g_9_8_5 : ℚ → ℝ :=
            fun q ↦ (2 : ℝ) ^ (-(q_9_8_5.symm q : ℤ))
          let f_9_8_5 : ℝ → ℝ :=
            fun x ↦ ∑' r : { r : ℚ // (r : ℚ) < x }, g_9_8_5 r
          ∫ t in (0 : ℝ)..x, f_9_8_5 t)
        (Set.Icc (0 : ℝ) 1)
        (q : ℝ) := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem Exercise_11_10_3 {a b : ℝ} (hab : a < b) {f : ℝ → ℝ}
    (hf : IntervalIntegrable f MeasureTheory.volume a b) :
    IntervalIntegrable (fun x ↦ f (-x)) MeasureTheory.volume (-b) (-a) ∧
      intervalIntegral (fun x ↦ f (-x)) (-b) (-a) =
        -intervalIntegral f a b := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

/-- Exercise 11.6.4 (Mathlib formulation).

There exists a function `f : ℝ → ℝ` which is nonnegative on `[0, ∞)`, whose
(infinite) sum over `ℝ` is summable, but for which the integrals over the
intervals `[0, N]` are not uniformly bounded above as `N → ∞`. -/
theorem Exercise_11_6_4a :
  ∃ (f : ℝ → ℝ) (hnon : ∀ x ≥ 0, 0 ≤ f x),
    Summable f ∧
    ¬ ∃ M, ∀ N ≥ 0, ∫ x in 0..N, f x ≤ M := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench

/-- Translation of Tao's Exercise 11.9.3 using Mathlib's interval integral.

For a monotone function `f` on `[a,b]`, differentiability (within `[a,b]`)
of the map `x ↦ ∫ t in a..x, f t` at `x₀` is equivalent to continuity
(within `[a,b]`) of `f` at `x₀`. -/
theorem Exercise_11_9_3
    {a b x₀ : ℝ}
    (hab : a < b) (hx₀ : x₀ ∈ Icc a b)
    {f : ℝ → ℝ} (hf : MonotoneOn f (Icc a b)) :
    DifferentiableWithinAt ℝ (fun x ↦ ∫ t in a..x, f t) (Icc a b) x₀ ↔
    ContinuousWithinAt f (Icc a b) x₀ := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem IntegrableOn.add {f g : ℝ → ℝ} {a b : ℝ}
    (hf : MeasureTheory.IntegrableOn f (Set.Icc a b))
    (hg : MeasureTheory.IntegrableOn g (Set.Icc a b)) :
    MeasureTheory.IntegrableOn (f + g) (Set.Icc a b) ∧
      (∫ x in Set.Icc a b, (f x + g x)) =
        (∫ x in Set.Icc a b, f x) + (∫ x in Set.Icc a b, g x) := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem IntegrableOn.const
  (c : ℝ) (a b : ℝ) (s : Set ℝ)
  (hs : s = Set.Ioo a b ∨ s = Set.Ioc a b ∨ s = Set.Ico a b ∨ s = Set.Icc a b) :
  MeasureTheory.IntegrableOn (fun _ : ℝ => c) s ∧
  (∫ x in s, c) = c * max (b - a) 0 := by
end TaoBench
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat Topology Rat Set Filter

namespace TaoBench
theorem IntegrableOn.const'
    {f : ℝ → ℝ} {I : Set ℝ} {a b c : ℝ}
    (hI : I = Icc a b ∨ I = Ioc a b ∨ I = Ico a b ∨ I = Ioo a b)
    (hf : ∀ x ∈ I, f x = c) :
    MeasureTheory.IntegrableOn f I ∧
      ∫ x in I, f x = c * max (b - a) 0 := by
end TaoBench