l3lab/ntp-mathlib huggingface dataset:
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; 

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
| Finset.card P.parts

Next tactic:
rw [← mul_one P.parts.card]
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
| ↑(Finset.card P.parts * Finset.card P.parts - Finset.card P.parts * 1) * (ε ^ 5 / 25)

Next tactic:
rw [← Nat.mul_sub_left_distrib]
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    rw [← Nat.mul_sub_left_distrib]
  

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
⊢ ∑ x in offDiag P.parts, ↑(edgeDensity G x.1 x.2) ^ 2 + ↑(Finset.card P.parts) ^ 2 * (ε ^ 5 / 4) ≤
    ∑ x in offDiag P.parts, ↑(edgeDensity G x.1 x.2) ^ 2 -
        ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * (ε ^ 5 / 25) +
      ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε * (ε ^ 4 / 3)

Next tactic:
simp_rw [mul_assoc, sub_add_eq_add_sub, add_sub_assoc, ← mul_sub_left_distrib, mul_div_assoc' ε,
    ← pow_succ, show 4 + 1 = 5 by rfl, div_eq_mul_one_div (ε ^ 5), ← mul_sub_left_distrib,
    mul_left_comm _ (ε ^ 5), sq, Nat.cast_mul, mul_assoc, ← mul_assoc (ε ^ 5)]
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    rw [← Nat.mul_sub_left_distrib]
  simp_rw [mul_assoc, sub_add_eq_add_sub, add_sub_assoc, ← mul_sub_left_distrib, mul_div_assoc' ε,
    ← pow_succ, show 4 + 1 = 5 by 

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
⊢ 4 + 1 = 5

Next tactic:
rfl
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    rw [← Nat.mul_sub_left_distrib]
  simp_rw [mul_assoc, sub_add_eq_add_sub, add_sub_assoc, ← mul_sub_left_distrib, mul_div_assoc' ε,
    ← pow_succ, show 4 + 1 = 5 by rfl, div_eq_mul_one_div (ε ^ 5), ← mul_sub_left_distrib,
    mul_left_comm _ (ε ^ 5), sq, Nat.cast_mul, mul_assoc, ← mul_assoc (ε ^ 5)]
  

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
⊢ ∑ x in offDiag P.parts, ↑(edgeDensity G x.1 x.2) * ↑(edgeDensity G x.1 x.2) +
      ε ^ 5 * ↑(Finset.card P.parts) * (↑(Finset.card P.parts) * (1 / 4)) ≤
    ∑ x in offDiag P.parts, ↑(edgeDensity G x.1 x.2) * ↑(edgeDensity G x.1 x.2) +
      ε ^ 5 * ↑(Finset.card P.parts) * (↑(Finset.card P.parts - 1) * (1 / 3 - 1 / 25))

Next tactic:
refine' add_le_add_left (mul_le_mul_of_nonneg_left _ <| by sz_positivity) _
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    rw [← Nat.mul_sub_left_distrib]
  simp_rw [mul_assoc, sub_add_eq_add_sub, add_sub_assoc, ← mul_sub_left_distrib, mul_div_assoc' ε,
    ← pow_succ, show 4 + 1 = 5 by rfl, div_eq_mul_one_div (ε ^ 5), ← mul_sub_left_distrib,
    mul_left_comm _ (ε ^ 5), sq, Nat.cast_mul, mul_assoc, ← mul_assoc (ε ^ 5)]
  refine' add_le_add_left (mul_le_mul_of_nonneg_left _ <| by 

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
⊢ 0 ≤ ε ^ 5 * ↑(Finset.card P.parts)

Next tactic:
sz_positivity
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    rw [← Nat.mul_sub_left_distrib]
  simp_rw [mul_assoc, sub_add_eq_add_sub, add_sub_assoc, ← mul_sub_left_distrib, mul_div_assoc' ε,
    ← pow_succ, show 4 + 1 = 5 by rfl, div_eq_mul_one_div (ε ^ 5), ← mul_sub_left_distrib,
    mul_left_comm _ (ε ^ 5), sq, Nat.cast_mul, mul_assoc, ← mul_assoc (ε ^ 5)]
  refine' add_le_add_left (mul_le_mul_of_nonneg_left _ <| by sz_positivity) _
  

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
⊢ ↑(Finset.card P.parts) * (1 / 4) ≤ ↑(Finset.card P.parts - 1) * (1 / 3 - 1 / 25)

Next tactic:
rw [Nat.cast_sub (P.parts_nonempty <| univ_nonempty.ne_empty).card_pos, mul_sub_right_distrib,
    Nat.cast_one, one_mul, le_sub_comm, ← mul_sub_left_distrib, ←
    div_le_iff (show (0 : ℝ) < 1 / 3 - 1 / 25 - 1 / 4 by norm_num)]
theorem uniform_add_nonuniform_eq_offDiag_pairs [Nonempty α] (hε₁ : ε ≤ 1) (hP₇ : 7 ≤ P.parts.card)
    (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
    (hPG : ¬P.IsUniform G ε) :
    (∑ x in P.parts.offDiag, (G.edgeDensity x.1 x.2 : ℝ) ^ 2 +
      ↑P.parts.card ^ 2 * (ε ^ 5 / 4) : ℝ) / (P.parts.card : ℝ) ^ 2 ≤
    ∑ x in P.parts.offDiag.attach,
      (pairContrib G ε hP x : ℝ) / ((increment hP G ε).parts.card : ℝ) ^ 2 := by
  conv_rhs =>
    rw [← sum_div, card_increment hPα hPG, stepBound, ← Nat.cast_pow, mul_pow, pow_right_comm,
      Nat.cast_mul, mul_comm, ← div_div, show 4 ^ 2 = 16 by norm_num, sum_div]
  rw [← Nat.cast_pow, Nat.cast_pow 16]
  refine' div_le_div_of_le_of_nonneg _ (Nat.cast_nonneg _)
  norm_num
  trans ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
    if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ)
  swap
  · exact sum_le_sum fun i _ => pairContrib_lower_bound i hε₁ hPα hPε
  have :
      ∑ x in P.parts.offDiag.attach, ((G.edgeDensity x.1.1 x.1.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1.1 x.1.2 then (0 : ℝ) else ε ^ 4 / 3 : ℝ) =
      ∑ x in P.parts.offDiag, ((G.edgeDensity x.1 x.2 : ℝ) ^ 2 - ε ^ 5 / ↑25 +
        if G.IsUniform ε x.1 x.2 then (0 : ℝ) else ε ^ 4 / 3) := by
    convert sum_attach (β := ℝ); rfl
  rw [this, sum_add_distrib, sum_sub_distrib, sum_const, nsmul_eq_mul, sum_ite, sum_const_zero,
    zero_add, sum_const, nsmul_eq_mul, ← Finpartition.nonUniforms]
  rw [Finpartition.IsUniform, not_le] at hPG
  refine' le_trans _ (add_le_add_left (mul_le_mul_of_nonneg_right hPG.le <| by positivity) _)
  conv_rhs =>
    enter [1, 2]
    rw [offDiag_card]
    conv => enter [1, 1, 2]; rw [← mul_one P.parts.card]
    rw [← Nat.mul_sub_left_distrib]
  simp_rw [mul_assoc, sub_add_eq_add_sub, add_sub_assoc, ← mul_sub_left_distrib, mul_div_assoc' ε,
    ← pow_succ, show 4 + 1 = 5 by rfl, div_eq_mul_one_div (ε ^ 5), ← mul_sub_left_distrib,
    mul_left_comm _ (ε ^ 5), sq, Nat.cast_mul, mul_assoc, ← mul_assoc (ε ^ 5)]
  refine' add_le_add_left (mul_le_mul_of_nonneg_left _ <| by sz_positivity) _
  rw [Nat.cast_sub (P.parts_nonempty <| univ_nonempty.ne_empty).card_pos, mul_sub_right_distrib,
    Nat.cast_one, one_mul, le_sub_comm, ← mul_sub_left_distrib, ←
    div_le_iff (show (0 : ℝ) < 1 / 3 - 1 / 25 - 1 / 4 by 

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hε₁ : ε ≤ 1
hP₇ : 7 ≤ Finset.card P.parts
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPε : 100 ≤ 4 ^ Finset.card P.parts * ε ^ 5
hPG : ↑(Finset.card P.parts * (Finset.card P.parts - 1)) * ε < ↑(Finset.card (nonUniforms P G ε))
this :
  ∑ x in attach (offDiag P.parts),
      (↑(edgeDensity G (↑x).1 (↑x).2) ^ 2 - ε ^ 5 / 25 +
        if SimpleGraph.IsUniform G ε (↑x).1 (↑x).2 then 0 else ε ^ 4 / 3) =
    ∑ x in offDiag P.parts,
      (↑(edgeDensity G x.1 x.2) ^ 2 - ε ^ 5 / 25 + if SimpleGraph.IsUniform G ε x.1 x.2 then 0 else ε ^ 4 / 3)
⊢ 0 < 1 / 3 - 1 / 25 - 1 / 4

Next tactic:
norm_num
/-- The increment partition has energy greater than the original one by a known fixed amount. -/
theorem energy_increment [Nonempty α] (hP : P.IsEquipartition) (hP₇ : 7 ≤ P.parts.card)
    (hε : ↑100 < ↑4 ^ P.parts.card * ε ^ 5) (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
    (hPG : ¬P.IsUniform G ε) (hε₁ : ε ≤ 1) :
    ↑(P.energy G) + ε ^ 5 / 4 ≤ (increment hP G ε).energy G := by
  

Proof state:
α : Type u_1
inst✝¹ : Fintype α
P : Finpartition univ
hP✝ : IsEquipartition P
G : SimpleGraph α
ε : ℝ
inst✝ : Nonempty α
hP : IsEquipartition P
hP₇ : 7 ≤ Finset.card P.parts
hε : 100 < 4 ^ Finset.card P.parts * ε ^ 5
hPα : Finset.card P.parts * 16 ^ Finset.card P.parts ≤ Fintype.card α
hPG : ¬Finpartition.IsUniform P G ε
hε₁ : ε ≤ 1
⊢ ↑(energy P G) + ε ^ 5 / 4 ≤ ↑(energy (increment hP G ε) G)

Next tactic:
rw [coe_energy]