l3lab/ntp-mathlib huggingface dataset:
theorem hundred_lt_pow_initialBound_mul {ε : ℝ} (hε : 0 < ε) (l : ℕ) :
    100 < ↑4 ^ initialBound ε l * ε ^ 5 := by
  rw [← rpow_nat_cast 4, ← div_lt_iff (pow_pos hε 5), lt_rpow_iff_log_lt _ zero_lt_four, ←
    div_lt_iff, initialBound, Nat.cast_max, Nat.cast_max]
  · push_cast
    exact lt_max_of_lt_right (lt_max_of_lt_right <| Nat.lt_floor_add_one _)
  · exact log_pos (by norm_num)
  · 

Proof state:
α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Fintype α
P : Finpartition univ
u : Finset α
ε✝ : ℝ
l✝ : ℕ
ε : ℝ
hε : 0 < ε
l : ℕ
⊢ 0 < 100 / ε ^ 5

Next tactic:
exact div_pos (by norm_num) (pow_pos hε 5)
theorem hundred_lt_pow_initialBound_mul {ε : ℝ} (hε : 0 < ε) (l : ℕ) :
    100 < ↑4 ^ initialBound ε l * ε ^ 5 := by
  rw [← rpow_nat_cast 4, ← div_lt_iff (pow_pos hε 5), lt_rpow_iff_log_lt _ zero_lt_four, ←
    div_lt_iff, initialBound, Nat.cast_max, Nat.cast_max]
  · push_cast
    exact lt_max_of_lt_right (lt_max_of_lt_right <| Nat.lt_floor_add_one _)
  · exact log_pos (by norm_num)
  · exact div_pos (by 

Proof state:
α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Fintype α
P : Finpartition univ
u : Finset α
ε✝ : ℝ
l✝ : ℕ
ε : ℝ
hε : 0 < ε
l : ℕ
⊢ 0 < 100

Next tactic:
norm_num
theorem initialBound_le_bound : initialBound ε l ≤ bound ε l :=
  (id_le_iterate_of_id_le le_stepBound _ _).trans <| Nat.le_mul_of_pos_right <| by 

Proof state:
α : Type u_1
inst✝¹ : DecidableEq α
inst✝ : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
⊢ 0 < 16 ^ stepBound^[⌊4 / ε ^ 5⌋₊] (initialBound ε l)

Next tactic:
positivity
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  

Proof state:
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
⊢ d + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤ (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · 

Proof state:
case inl
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 = ↑(Finset.card s)
⊢ d + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤ (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
⊢ d + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤ (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
⊢ d + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤ (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by 

Proof state:
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
⊢ |x| ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|

Next tactic:
rwa [abs_of_nonneg hx]
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
⊢ d + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤ (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    

Proof state:
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
⊢ x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2

Next tactic:
apply h₁.trans
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    

Proof state:
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
⊢ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2 ≤
    ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2

Next tactic:
rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2
⊢ d + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤ (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
apply (add_le_add_right ht _).trans
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
  apply (add_le_add_right ht _).trans
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2
⊢ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2 + ↑(Finset.card s) / ↑(Finset.card t) * x ^ 2 ≤
    (∑ i in t, f i ^ 2) / ↑(Finset.card t)

Next tactic:
rw [← mul_div_right_comm, le_div_iff htcard, add_mul, div_mul_cancel _ htcard.ne']
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
  apply (add_le_add_right ht _).trans
  rw [← mul_div_right_comm, le_div_iff htcard, add_mul, div_mul_cancel _ htcard.ne']
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2
⊢ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2 * ↑(Finset.card t) + ↑(Finset.card s) * x ^ 2 ≤ ∑ i in t, f i ^ 2

Next tactic:
have h₃ := mul_sq_le_sum_sq hst (fun i => (f i - (∑ j in t, f j) / t.card)) h₂ hscard.ne'
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
  apply (add_le_add_right ht _).trans
  rw [← mul_div_right_comm, le_div_iff htcard, add_mul, div_mul_cancel _ htcard.ne']
  have h₃ := mul_sq_le_sum_sq hst (fun i => (f i - (∑ j in t, f j) / t.card)) h₂ hscard.ne'
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2
h₃ : ↑(Finset.card s) * x ^ 2 ≤ ∑ i in t, (fun i => f i - (∑ j in t, f j) / ↑(Finset.card t)) i ^ 2
⊢ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2 * ↑(Finset.card t) + ↑(Finset.card s) * x ^ 2 ≤ ∑ i in t, f i ^ 2

Next tactic:
apply (add_le_add_left h₃ _).trans
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
  apply (add_le_add_right ht _).trans
  rw [← mul_div_right_comm, le_div_iff htcard, add_mul, div_mul_cancel _ htcard.ne']
  have h₃ := mul_sq_le_sum_sq hst (fun i => (f i - (∑ j in t, f j) / t.card)) h₂ hscard.ne'
  apply (add_le_add_left h₃ _).trans
  -- Porting note: was
  -- `simp [← mul_div_right_comm _ (t.card : 𝕜), sub_div' _ _ _ htcard.ne', ← sum_div, ← add_div,`
  -- `  mul_pow, div_le_iff (sq_pos_of_ne_zero _ htcard.ne'), sub_sq, sum_add_distrib, ← sum_mul,`
  -- `  ← mul_sum]`
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2
h₃ : ↑(Finset.card s) * x ^ 2 ≤ ∑ i in t, (fun i => f i - (∑ j in t, f j) / ↑(Finset.card t)) i ^ 2
⊢ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2 * ↑(Finset.card t) +
      ∑ i in t, (fun i => f i - (∑ j in t, f j) / ↑(Finset.card t)) i ^ 2 ≤
    ∑ i in t, f i ^ 2

Next tactic:
simp_rw [sub_div' _ _ _ htcard.ne']
theorem add_div_le_sum_sq_div_card (hst : s ⊆ t) (f : ι → 𝕜) (d : 𝕜) (hx : 0 ≤ x)
    (hs : x ≤ |(∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card|)
    (ht : d ≤ ((∑ i in t, f i) / t.card) ^ 2) :
    d + s.card / t.card * x ^ 2 ≤ (∑ i in t, f i ^ 2) / t.card := by
  obtain hscard | hscard := (s.card.cast_nonneg : (0 : 𝕜) ≤ s.card).eq_or_lt
  · simpa [← hscard] using ht.trans sum_div_card_sq_le_sum_sq_div_card
  have htcard : (0 : 𝕜) < t.card := hscard.trans_le (Nat.cast_le.2 (card_le_of_subset hst))
  have h₁ : x ^ 2 ≤ ((∑ i in s, f i) / s.card - (∑ i in t, f i) / t.card) ^ 2 :=
    sq_le_sq.2 (by rwa [abs_of_nonneg hx])
  have h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / t.card)) / s.card) ^ 2 := by
    apply h₁.trans
    rw [sum_sub_distrib, sum_const, nsmul_eq_mul, sub_div, mul_div_cancel_left _ hscard.ne']
  apply (add_le_add_right ht _).trans
  rw [← mul_div_right_comm, le_div_iff htcard, add_mul, div_mul_cancel _ htcard.ne']
  have h₃ := mul_sq_le_sum_sq hst (fun i => (f i - (∑ j in t, f j) / t.card)) h₂ hscard.ne'
  apply (add_le_add_left h₃ _).trans
  -- Porting note: was
  -- `simp [← mul_div_right_comm _ (t.card : 𝕜), sub_div' _ _ _ htcard.ne', ← sum_div, ← add_div,`
  -- `  mul_pow, div_le_iff (sq_pos_of_ne_zero _ htcard.ne'), sub_sq, sum_add_distrib, ← sum_mul,`
  -- `  ← mul_sum]`
  simp_rw [sub_div' _ _ _ htcard.ne']
  

Proof state:
case inr
α : Type u_1
inst✝³ : DecidableEq α
inst✝² : Fintype α
P : Finpartition univ
u : Finset α
ε : ℝ
l : ℕ
ι : Type u_2
𝕜 : Type u_3
inst✝¹ : LinearOrderedField 𝕜
r : ι → ι → Prop
inst✝ : DecidableRel r
s t : Finset ι
x : 𝕜
hst : s ⊆ t
f : ι → 𝕜
d : 𝕜
hx : 0 ≤ x
hs : x ≤ |(∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)|
ht : d ≤ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2
hscard : 0 < ↑(Finset.card s)
htcard : 0 < ↑(Finset.card t)
h₁ : x ^ 2 ≤ ((∑ i in s, f i) / ↑(Finset.card s) - (∑ i in t, f i) / ↑(Finset.card t)) ^ 2
h₂ : x ^ 2 ≤ ((∑ i in s, (f i - (∑ j in t, f j) / ↑(Finset.card t))) / ↑(Finset.card s)) ^ 2
h₃ : ↑(Finset.card s) * x ^ 2 ≤ ∑ i in t, (fun i => f i - (∑ j in t, f j) / ↑(Finset.card t)) i ^ 2
⊢ ((∑ i in t, f i) / ↑(Finset.card t)) ^ 2 * ↑(Finset.card t) +
      ∑ x in t, ((f x * ↑(Finset.card t) - ∑ i in t, f i) / ↑(Finset.card t)) ^ 2 ≤
    ∑ i in t, f i ^ 2

Next tactic:
conv_lhs => enter [2, 2, x]; rw [div_pow]