combinatorics.simple_graph.regularity.chunkMathlib.Combinatorics.SimpleGraph.Regularity.Chunk

This file has been ported!

Changes since the initial port

The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.

Changes in mathlib3

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(no changes)

(last sync)

Changes in mathlib3port

mathlib3
mathlib3port
Diff
@@ -186,7 +186,7 @@ private theorem one_sub_eps_mul_card_nonuniform_witness_le_card_star (hV : V ∈
       by
       refine' sub_le_sub_left _ _
       have : (2 : ℝ) ^ P.parts.card = 2 ^ (P.parts.card - 1) * 2 := by
-        rw [← pow_succ', tsub_add_cancel_of_le (succ_le_iff.2 hP₁)]
+        rw [← pow_succ, tsub_add_cancel_of_le (succ_le_iff.2 hP₁)]
       rw [← mul_div_right_comm, this, mul_right_comm _ (2 : ℝ), mul_assoc, le_div_iff]
       refine' mul_le_mul_of_nonneg_left _ (by positivity)
       exact
@@ -271,7 +271,7 @@ private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
     1 - ε ^ 5 / 50 ≤ (m / (m + 1)) ^ 2 :=
   by
   have : (m : ℝ) / (m + 1) = 1 - 1 / (m + 1) := by
-    rw [one_sub_div coe_m_add_one_pos.ne', add_sub_cancel]
+    rw [one_sub_div coe_m_add_one_pos.ne', add_sub_cancel_right]
   rw [this, sub_sq, one_pow, mul_one]
   refine' le_trans _ (le_add_of_nonneg_right <| sq_nonneg _)
   rw [sub_le_sub_iff_left, ← le_div_iff' (show (0 : ℝ) < 2 by norm_num), div_div,
Diff
@@ -116,7 +116,7 @@ private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (
     by
     intro x hx
     rw [← bUnion_filter_atomise hX (G.nonuniform_witness_subset h₂), star, mem_sdiff, mem_bUnion] at
-      hx 
+      hx
     simp only [not_exists, mem_bUnion, and_imp, filter_congr_decidable, exists_prop, mem_filter,
       not_and, mem_sdiff, id.def, mem_sdiff] at hx ⊢
     obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx
@@ -139,7 +139,7 @@ private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (
   rw [sum_const]
   refine' mul_le_mul_right' _ _
   have t := card_filter_atomise_le_two_pow hX
-  rw [filter_congr_decidable] at t 
+  rw [filter_congr_decidable] at t
   refine' t.trans (pow_le_pow_right (by norm_num) <| tsub_le_tsub_right _ _)
   exact card_image_le.trans (card_le_of_subset <| filter_subset _ _)
 
@@ -220,8 +220,8 @@ theorem card_chunk (hm : m ≠ 0) : (chunk hP G ε hU).parts.card = 4 ^ P.parts.
 
 #print SzemerediRegularity.card_eq_of_mem_parts_chunk /-
 theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
-    s.card = m ∨ s.card = m + 1 := by unfold chunk at hs ;
-  split_ifs at hs  <;> exact card_eq_of_mem_parts_equitabilise hs
+    s.card = m ∨ s.card = m + 1 := by unfold chunk at hs;
+  split_ifs at hs <;> exact card_eq_of_mem_parts_equitabilise hs
 #align szemeredi_regularity.card_eq_of_mem_parts_chunk SzemerediRegularity.card_eq_of_mem_parts_chunk
 -/
 
@@ -393,7 +393,7 @@ private theorem average_density_near_total_density [Nonempty α]
       ε ^ 5 / 50
     by
     apply this.trans
-    exact div_le_div_of_le_left (by positivity) (by norm_num) (by norm_num)
+    exact div_le_div_of_nonneg_left (by positivity) (by norm_num) (by norm_num)
   rw [sub_le_iff_le_add, ← sub_le_iff_le_add']
   apply density_sub_eps_le_sum_density_div_card hPα hPε hA hB
 
@@ -409,8 +409,8 @@ private theorem edge_density_chunk_aux [Nonempty α]
   · refine' (sub_nonpos_of_le <| (sq_le _ _).trans <| hGε.trans _).trans (sq_nonneg _)
     · exact_mod_cast G.edge_density_nonneg _ _
     · exact_mod_cast G.edge_density_le_one _ _
-    · exact div_le_div_of_le_left (by positivity) (by norm_num) (by norm_num)
-  rw [← sub_nonneg] at hGε 
+    · exact div_le_div_of_nonneg_left (by positivity) (by norm_num) (by norm_num)
+  rw [← sub_nonneg] at hGε
   have :
     ↑(G.edge_density U V) - ε ^ 5 / 50 ≤
       (∑ ab in (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts, G.edge_density ab.1 ab.2) /
@@ -459,7 +459,7 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
     4 / 5 * ε = (1 - 1 / 10) * (1 - 9⁻¹) * ε := by norm_num
     _ ≤ (1 - ε / 10) * (1 - m⁻¹) * ((G.nonuniform_witness ε U V).card / U.card) :=
       (mul_le_mul
-        (mul_le_mul (sub_le_sub_left (div_le_div_of_le_of_nonneg hε₁ <| by norm_num) _)
+        (mul_le_mul (sub_le_sub_left (div_le_div_of_nonneg_right hε₁ <| by norm_num) _)
           (sub_le_sub_left
             (inv_le_inv_of_le (by norm_num) <| by
               exact_mod_cast show 9 ≤ 100 by norm_num.trans (hundred_le_m hPα hPε hε₁))
@@ -477,7 +477,8 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
       (mul_le_mul_of_nonneg_right card_bUnion_star_le_m_add_one_card_star_mul (by positivity))
     _ ≤ (star hP G ε hU V).card * (m + 1) * ((1 - m⁻¹) / (4 ^ P.parts.card * m)) :=
       (mul_le_mul_of_nonneg_left
-        (div_le_div_of_le_left hm (by positivity) <| pow_mul_m_le_card_part hP hU) (by positivity))
+        (div_le_div_of_nonneg_left hm (by positivity) <| pow_mul_m_le_card_part hP hU)
+        (by positivity))
     _ ≤ (star hP G ε hU V).card / 4 ^ P.parts.card :=
       by
       rw [mul_assoc, mul_comm ((4 : ℝ) ^ P.parts.card), ← div_div, ← mul_div_assoc, ← mul_comm_div]
@@ -525,14 +526,14 @@ private theorem edge_density_star_not_uniform [Nonempty α]
     have :=
       average_density_near_total_density hPα hPε hε₁ (subset.refl (chunk hP G ε hU).parts)
         (subset.refl (chunk hP G ε hV).parts)
-    simp_rw [← sup_eq_bUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this 
-    norm_num at this 
+    simp_rw [← sup_eq_bUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this
+    norm_num at this
     exact this
   have hε' : ε ^ 5 ≤ ε := by
     simpa using pow_le_pow_of_le_one (by positivity) hε₁ (show 1 ≤ 5 by norm_num)
-  have hpr' : |p - r| ≤ ε / 49 := hpr.trans (div_le_div_of_le_of_nonneg hε' <| by norm_num)
-  have hqt' : |q - t| ≤ ε / 49 := hqt.trans (div_le_div_of_le_of_nonneg hε' <| by norm_num)
-  rw [abs_sub_le_iff] at hrs hpr' hqt' 
+  have hpr' : |p - r| ≤ ε / 49 := hpr.trans (div_le_div_of_nonneg_right hε' <| by norm_num)
+  have hqt' : |q - t| ≤ ε / 49 := hqt.trans (div_le_div_of_nonneg_right hε' <| by norm_num)
+  rw [abs_sub_le_iff] at hrs hpr' hqt'
   rw [le_abs] at hst ⊢
   cases hst
   left; linarith
@@ -585,8 +586,8 @@ theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^
         add_div_le_sum_sq_div_card t (fun x => (G.edge_density x.1 x.2 : ℝ))
           (G.edge_density U V ^ 2 - ε ^ 5 / 25) (show 0 ≤ 3 / 4 * ε by linarith) _ _
       · simp_rw [card_product, card_chunk (m_pos hPα).ne', ← mul_pow, cast_pow, mul_pow, div_pow, ←
-          mul_assoc] at this 
-        norm_num at this 
+          mul_assoc] at this
+        norm_num at this
         exact this
       · simp_rw [card_product, card_chunk (m_pos hPα).ne', ← mul_pow]
         norm_num
Diff
@@ -140,7 +140,7 @@ private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (
   refine' mul_le_mul_right' _ _
   have t := card_filter_atomise_le_two_pow hX
   rw [filter_congr_decidable] at t 
-  refine' t.trans (pow_le_pow (by norm_num) <| tsub_le_tsub_right _ _)
+  refine' t.trans (pow_le_pow_right (by norm_num) <| tsub_le_tsub_right _ _)
   exact card_image_le.trans (card_le_of_subset <| filter_subset _ _)
 
 private theorem one_sub_eps_mul_card_nonuniform_witness_le_card_star (hV : V ∈ P.parts)
@@ -292,7 +292,7 @@ private theorem m_add_one_div_m_le_one_add [Nonempty α]
     by
     rw [add_le_add_iff_left, ← one_div_div (100 : ℝ)]
     exact one_div_le_one_div_of_le (by positivity) (hundred_div_ε_pow_five_le_m hPα hPε)
-  refine' (pow_le_pow_of_le_left _ this 2).trans _
+  refine' (pow_le_pow_left _ this 2).trans _
   · positivity
   rw [add_sq, one_pow, add_assoc, add_le_add_iff_left, mul_one, ← le_sub_iff_add_le',
     div_eq_mul_one_div _ (49 : ℝ), mul_div_left_comm (2 : ℝ), ← mul_sub_left_distrib, div_pow,
@@ -425,7 +425,7 @@ private theorem edge_density_chunk_aux [Nonempty α]
     · rw [bUnion_parts, bUnion_parts]
     · rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← cast_mul, ← mul_pow, cast_pow]
       norm_cast
-  refine' le_trans _ (pow_le_pow_of_le_left hGε this 2)
+  refine' le_trans _ (pow_le_pow_left hGε this 2)
   rw [sub_sq, sub_add, sub_le_sub_iff_left]
   refine' (sub_le_self _ <| sq_nonneg <| ε ^ 5 / 50).trans _
   rw [mul_right_comm, mul_div_left_comm, div_eq_mul_inv (ε ^ 5),
Diff
@@ -3,9 +3,9 @@ Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yaël Dillies, Bhavik Mehta
 -/
-import Mathbin.Combinatorics.SimpleGraph.Regularity.Bound
-import Mathbin.Combinatorics.SimpleGraph.Regularity.Equitabilise
-import Mathbin.Combinatorics.SimpleGraph.Regularity.Uniform
+import Combinatorics.SimpleGraph.Regularity.Bound
+import Combinatorics.SimpleGraph.Regularity.Equitabilise
+import Combinatorics.SimpleGraph.Regularity.Uniform
 
 #align_import combinatorics.simple_graph.regularity.chunk from "leanprover-community/mathlib"@"08b63ab58a6ec1157ebeafcbbe6c7a3fb3c9f6d5"
 
Diff
@@ -2,16 +2,13 @@
 Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yaël Dillies, Bhavik Mehta
-
-! This file was ported from Lean 3 source module combinatorics.simple_graph.regularity.chunk
-! leanprover-community/mathlib commit 08b63ab58a6ec1157ebeafcbbe6c7a3fb3c9f6d5
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Combinatorics.SimpleGraph.Regularity.Bound
 import Mathbin.Combinatorics.SimpleGraph.Regularity.Equitabilise
 import Mathbin.Combinatorics.SimpleGraph.Regularity.Uniform
 
+#align_import combinatorics.simple_graph.regularity.chunk from "leanprover-community/mathlib"@"08b63ab58a6ec1157ebeafcbbe6c7a3fb3c9f6d5"
+
 /-!
 # Chunk of the increment partition for Szemerédi Regularity Lemma
 
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yaël Dillies, Bhavik Mehta
 
 ! This file was ported from Lean 3 source module combinatorics.simple_graph.regularity.chunk
-! leanprover-community/mathlib commit bf7ef0e83e5b7e6c1169e97f055e58a2e4e9d52d
+! leanprover-community/mathlib commit 08b63ab58a6ec1157ebeafcbbe6c7a3fb3c9f6d5
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -15,6 +15,9 @@ import Mathbin.Combinatorics.SimpleGraph.Regularity.Uniform
 /-!
 # Chunk of the increment partition for Szemerédi Regularity Lemma
 
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
 In the proof of Szemerédi Regularity Lemma, we need to partition each part of a starting partition
 to increase the energy. This file defines those partitions of parts and shows that they locally
 increase the energy.
Diff
@@ -46,7 +46,7 @@ open scoped BigOperators Classical
 
 attribute [local positivity] tactic.positivity_szemeredi_regularity
 
-namespace SzemerediRegularity
+namespace szemeredi_regularity
 
 variable {α : Type _} [Fintype α] {P : Finpartition (univ : Finset α)} (hP : P.IsEquipartition)
   (G : SimpleGraph α) (ε : ℝ) {U : Finset α} (hU : U ∈ P.parts) (V : Finset α)
@@ -617,5 +617,5 @@ theorem edgeDensity_chunk_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.pa
 #align szemeredi_regularity.edge_density_chunk_uniform SzemerediRegularity.edgeDensity_chunk_uniform
 -/
 
-end SzemerediRegularity
+end szemeredi_regularity
 
Diff
@@ -61,13 +61,16 @@ contained in the corresponding witness of non-uniformity.
 -/
 
 
+#print SzemerediRegularity.chunk /-
 /-- The portion of `szemeredi_regularity.increment` which partitions `U`. -/
 noncomputable def chunk : Finpartition U :=
   if hUcard : U.card = m * 4 ^ P.parts.card + (card α / P.parts.card - m * 4 ^ P.parts.card) then
     (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₁ hUcard
   else (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₂ hP hU hUcard
 #align szemeredi_regularity.chunk SzemerediRegularity.chunk
+-/
 
+#print SzemerediRegularity.star /-
 -- `hP` and `hU` are used to get that `U` has size
 -- `m * 4 ^ P.parts.card + a or m * 4 ^ P.parts.card + a + 1`
 /-- The portion of `szemeredi_regularity.chunk` which is contained in the witness of non uniformity
@@ -75,6 +78,7 @@ of `U` and `V`. -/
 noncomputable def star (V : Finset α) : Finset (Finset α) :=
   (chunk hP G ε hU).parts.filterₓ (· ⊆ G.nonuniformWitness ε U V)
 #align szemeredi_regularity.star SzemerediRegularity.star
+-/
 
 /-!
 ### Density estimates
@@ -83,16 +87,20 @@ We estimate the density between parts of `chunk`.
 -/
 
 
+#print SzemerediRegularity.biUnion_star_subset_nonuniformWitness /-
 theorem biUnion_star_subset_nonuniformWitness :
     (star hP G ε hU V).biUnion id ⊆ G.nonuniformWitness ε U V :=
   biUnion_subset_iff_forall_subset.2 fun A hA => (mem_filter.1 hA).2
 #align szemeredi_regularity.bUnion_star_subset_nonuniform_witness SzemerediRegularity.biUnion_star_subset_nonuniformWitness
+-/
 
 variable {hP G ε hU V} {𝒜 : Finset (Finset α)} {s : Finset α}
 
+#print SzemerediRegularity.star_subset_chunk /-
 theorem star_subset_chunk : star hP G ε hU V ⊆ (chunk hP G ε hU).parts :=
   filter_subset _ _
 #align szemeredi_regularity.star_subset_chunk SzemerediRegularity.star_subset_chunk
+-/
 
 private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (hUV : U ≠ V)
     (h₂ : ¬G.IsUniform ε U V) :
@@ -199,6 +207,7 @@ variable {hP G ε U hU V}
 /-! ### `chunk` -/
 
 
+#print SzemerediRegularity.card_chunk /-
 theorem card_chunk (hm : m ≠ 0) : (chunk hP G ε hU).parts.card = 4 ^ P.parts.card :=
   by
   unfold chunk
@@ -207,26 +216,35 @@ theorem card_chunk (hm : m ≠ 0) : (chunk hP G ε hU).parts.card = 4 ^ P.parts.
     exact le_of_lt a_add_one_le_four_pow_parts_card
   · rw [card_parts_equitabilise _ _ hm, tsub_add_cancel_of_le a_add_one_le_four_pow_parts_card]
 #align szemeredi_regularity.card_chunk SzemerediRegularity.card_chunk
+-/
 
+#print SzemerediRegularity.card_eq_of_mem_parts_chunk /-
 theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
     s.card = m ∨ s.card = m + 1 := by unfold chunk at hs ;
   split_ifs at hs  <;> exact card_eq_of_mem_parts_equitabilise hs
 #align szemeredi_regularity.card_eq_of_mem_parts_chunk SzemerediRegularity.card_eq_of_mem_parts_chunk
+-/
 
+#print SzemerediRegularity.m_le_card_of_mem_chunk_parts /-
 theorem m_le_card_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : m ≤ s.card :=
   (card_eq_of_mem_parts_chunk hs).elim ge_of_eq fun i => by simp [i]
 #align szemeredi_regularity.m_le_card_of_mem_chunk_parts SzemerediRegularity.m_le_card_of_mem_chunk_parts
+-/
 
+#print SzemerediRegularity.card_le_m_add_one_of_mem_chunk_parts /-
 theorem card_le_m_add_one_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : s.card ≤ m + 1 :=
   (card_eq_of_mem_parts_chunk hs).elim (fun i => by simp [i]) fun i => i.le
 #align szemeredi_regularity.card_le_m_add_one_of_mem_chunk_parts SzemerediRegularity.card_le_m_add_one_of_mem_chunk_parts
+-/
 
+#print SzemerediRegularity.card_biUnion_star_le_m_add_one_card_star_mul /-
 theorem card_biUnion_star_le_m_add_one_card_star_mul :
     (((star hP G ε hU V).biUnion id).card : ℝ) ≤ (star hP G ε hU V).card * (m + 1) := by
   exact_mod_cast
     card_bUnion_le_card_mul _ _ _ fun s hs =>
       card_le_m_add_one_of_mem_chunk_parts <| star_subset_chunk hs
 #align szemeredi_regularity.card_bUnion_star_le_m_add_one_card_star_mul SzemerediRegularity.card_biUnion_star_le_m_add_one_card_star_mul
+-/
 
 private theorem le_sum_card_subset_chunk_parts (h𝒜 : 𝒜 ⊆ (chunk hP G ε hU).parts) (hs : s ∈ 𝒜) :
     (𝒜.card : ℝ) * s.card * (m / (m + 1)) ≤ (𝒜.sup id).card :=
@@ -520,6 +538,7 @@ private theorem edge_density_star_not_uniform [Nonempty α]
   left; linarith
   right; linarith
 
+#print SzemerediRegularity.edgeDensity_chunk_not_uniform /-
 /-- Lower bound on the edge densities between non-uniform parts of `szemeredi_regularity.increment`.
 -/
 theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
@@ -578,7 +597,9 @@ theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^
         norm_num
         exact hP
 #align szemeredi_regularity.edge_density_chunk_not_uniform SzemerediRegularity.edgeDensity_chunk_not_uniform
+-/
 
+#print SzemerediRegularity.edgeDensity_chunk_uniform /-
 /-- Lower bound on the edge densities between parts of `szemeredi_regularity.increment`. This is the
 blanket lower bound used the uniform parts. -/
 theorem edgeDensity_chunk_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
@@ -594,6 +615,7 @@ theorem edgeDensity_chunk_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.pa
         cast_mul, ← mul_pow] <;>
     norm_cast
 #align szemeredi_regularity.edge_density_chunk_uniform SzemerediRegularity.edgeDensity_chunk_uniform
+-/
 
 end SzemerediRegularity
 
Diff
@@ -51,7 +51,6 @@ namespace SzemerediRegularity
 variable {α : Type _} [Fintype α] {P : Finpartition (univ : Finset α)} (hP : P.IsEquipartition)
   (G : SimpleGraph α) (ε : ℝ) {U : Finset α} (hU : U ∈ P.parts) (V : Finset α)
 
--- mathport name: exprm
 local notation "m" => (card α / stepBound P.parts.card : ℕ)
 
 /-!
Diff
@@ -166,9 +166,7 @@ private theorem one_sub_eps_mul_card_nonuniform_witness_le_card_star (hV : V ∈
             (mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (by positivity) hε₁ <| le_succ _)
               (by positivity))
           _ = (2 ^ 2) ^ P.parts.card * ε ^ (2 * 2) := by norm_num
-          
       _ = 2 ^ P.parts.card * (ε * (ε / 10)) := by rw [mul_div_assoc, sq, mul_div_assoc]
-      
   calc
     (1 - ε / 10) * (G.nonuniform_witness ε U V).card ≤
         (1 - 2 ^ P.parts.card * m / (U.card * ε)) * (G.nonuniform_witness ε U V).card :=
@@ -196,7 +194,6 @@ private theorem one_sub_eps_mul_card_nonuniform_witness_le_card_star (hV : V ∈
         cast_sub (card_le_of_subset <| bUnion_star_subset_nonuniform_witness hP G ε hU V), ←
         card_sdiff (bUnion_star_subset_nonuniform_witness hP G ε hU V), cast_le]
       exact card_nonuniform_witness_sdiff_bUnion_star hV hUV hunif
-    
 
 variable {hP G ε U hU V}
 
@@ -472,7 +469,6 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
       rw [mul_div_assoc', div_le_one hm, ← one_div, one_sub_div hm.ne', mul_div_assoc',
         div_le_iff hm]
       linarith
-    
 
 /-!
 ### Final bounds
@@ -582,7 +578,6 @@ theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^
         rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← mul_pow]
         norm_num
         exact hP
-    
 #align szemeredi_regularity.edge_density_chunk_not_uniform SzemerediRegularity.edgeDensity_chunk_not_uniform
 
 /-- Lower bound on the edge densities between parts of `szemeredi_regularity.increment`. This is the
Diff
@@ -214,7 +214,7 @@ theorem card_chunk (hm : m ≠ 0) : (chunk hP G ε hU).parts.card = 4 ^ P.parts.
 
 theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
     s.card = m ∨ s.card = m + 1 := by unfold chunk at hs ;
-  split_ifs  at hs  <;> exact card_eq_of_mem_parts_equitabilise hs
+  split_ifs at hs  <;> exact card_eq_of_mem_parts_equitabilise hs
 #align szemeredi_regularity.card_eq_of_mem_parts_chunk SzemerediRegularity.card_eq_of_mem_parts_chunk
 
 theorem m_le_card_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : m ≤ s.card :=
@@ -424,7 +424,8 @@ private theorem abs_density_star_sub_density_le_eps (hPε : 100 ≤ 4 ^ P.parts.
           G.edgeDensity (G.nonuniformWitness ε U V) (G.nonuniformWitness ε V U)| ≤
       ε / 5 :=
   by
-  convert abs_edge_density_sub_edge_density_le_two_mul G.adj
+  convert
+    abs_edge_density_sub_edge_density_le_two_mul G.adj
       (bUnion_star_subset_nonuniform_witness hP G ε hU V)
       (bUnion_star_subset_nonuniform_witness hP G ε hV U) (by positivity)
       (one_sub_eps_mul_card_nonuniform_witness_le_card_star hV hUV' hUV hPε hε₁)
Diff
@@ -109,9 +109,9 @@ private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (
     by
     intro x hx
     rw [← bUnion_filter_atomise hX (G.nonuniform_witness_subset h₂), star, mem_sdiff, mem_bUnion] at
-      hx
+      hx 
     simp only [not_exists, mem_bUnion, and_imp, filter_congr_decidable, exists_prop, mem_filter,
-      not_and, mem_sdiff, id.def, mem_sdiff] at hx⊢
+      not_and, mem_sdiff, id.def, mem_sdiff] at hx ⊢
     obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx
     exact ⟨B, hB₁, hB₂, fun A hA AB => hx A hA <| AB.trans hB₁.2.1⟩
   apply (card_le_of_subset q).trans (card_bUnion_le.trans _)
@@ -132,7 +132,7 @@ private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (
   rw [sum_const]
   refine' mul_le_mul_right' _ _
   have t := card_filter_atomise_le_two_pow hX
-  rw [filter_congr_decidable] at t
+  rw [filter_congr_decidable] at t 
   refine' t.trans (pow_le_pow (by norm_num) <| tsub_le_tsub_right _ _)
   exact card_image_le.trans (card_le_of_subset <| filter_subset _ _)
 
@@ -213,8 +213,8 @@ theorem card_chunk (hm : m ≠ 0) : (chunk hP G ε hU).parts.card = 4 ^ P.parts.
 #align szemeredi_regularity.card_chunk SzemerediRegularity.card_chunk
 
 theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
-    s.card = m ∨ s.card = m + 1 := by unfold chunk at hs;
-  split_ifs  at hs <;> exact card_eq_of_mem_parts_equitabilise hs
+    s.card = m ∨ s.card = m + 1 := by unfold chunk at hs ;
+  split_ifs  at hs  <;> exact card_eq_of_mem_parts_equitabilise hs
 #align szemeredi_regularity.card_eq_of_mem_parts_chunk SzemerediRegularity.card_eq_of_mem_parts_chunk
 
 theorem m_le_card_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : m ≤ s.card :=
@@ -321,7 +321,7 @@ private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
     apply le_sum_card_subset_chunk_parts hB hy
     positivity
   refine' mul_pos (mul_pos _ _) (mul_pos _ _) <;> rw [cast_pos, Finset.card_pos]
-  exacts[⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
+  exacts [⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
 
 private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -359,7 +359,7 @@ private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
     · exact ⟨_, hx, nonempty_of_mem_parts _ (hA hx)⟩
     · exact ⟨_, hy, nonempty_of_mem_parts _ (hB hy)⟩
   refine' mul_pos (mul_pos _ _) (mul_pos _ _) <;> rw [cast_pos, Finset.card_pos]
-  exacts[⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
+  exacts [⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
 
 private theorem average_density_near_total_density [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -396,7 +396,7 @@ private theorem edge_density_chunk_aux [Nonempty α]
     · exact_mod_cast G.edge_density_nonneg _ _
     · exact_mod_cast G.edge_density_le_one _ _
     · exact div_le_div_of_le_left (by positivity) (by norm_num) (by norm_num)
-  rw [← sub_nonneg] at hGε
+  rw [← sub_nonneg] at hGε 
   have :
     ↑(G.edge_density U V) - ε ^ 5 / 50 ≤
       (∑ ab in (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts, G.edge_density ab.1 ab.2) /
@@ -511,15 +511,15 @@ private theorem edge_density_star_not_uniform [Nonempty α]
     have :=
       average_density_near_total_density hPα hPε hε₁ (subset.refl (chunk hP G ε hU).parts)
         (subset.refl (chunk hP G ε hV).parts)
-    simp_rw [← sup_eq_bUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this
-    norm_num at this
+    simp_rw [← sup_eq_bUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this 
+    norm_num at this 
     exact this
   have hε' : ε ^ 5 ≤ ε := by
     simpa using pow_le_pow_of_le_one (by positivity) hε₁ (show 1 ≤ 5 by norm_num)
   have hpr' : |p - r| ≤ ε / 49 := hpr.trans (div_le_div_of_le_of_nonneg hε' <| by norm_num)
   have hqt' : |q - t| ≤ ε / 49 := hqt.trans (div_le_div_of_le_of_nonneg hε' <| by norm_num)
-  rw [abs_sub_le_iff] at hrs hpr' hqt'
-  rw [le_abs] at hst⊢
+  rw [abs_sub_le_iff] at hrs hpr' hqt' 
+  rw [le_abs] at hst ⊢
   cases hst
   left; linarith
   right; linarith
@@ -570,8 +570,8 @@ theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^
         add_div_le_sum_sq_div_card t (fun x => (G.edge_density x.1 x.2 : ℝ))
           (G.edge_density U V ^ 2 - ε ^ 5 / 25) (show 0 ≤ 3 / 4 * ε by linarith) _ _
       · simp_rw [card_product, card_chunk (m_pos hPα).ne', ← mul_pow, cast_pow, mul_pow, div_pow, ←
-          mul_assoc] at this
-        norm_num at this
+          mul_assoc] at this 
+        norm_num at this 
         exact this
       · simp_rw [card_product, card_chunk (m_pos hPα).ne', ← mul_pow]
         norm_num
Diff
@@ -42,7 +42,7 @@ Once ported to mathlib4, this file will be a great golfing ground for Heather's
 
 open Finpartition Finset Fintype Rel Nat
 
-open BigOperators Classical
+open scoped BigOperators Classical
 
 attribute [local positivity] tactic.positivity_szemeredi_regularity
 
Diff
@@ -213,8 +213,7 @@ theorem card_chunk (hm : m ≠ 0) : (chunk hP G ε hU).parts.card = 4 ^ P.parts.
 #align szemeredi_regularity.card_chunk SzemerediRegularity.card_chunk
 
 theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
-    s.card = m ∨ s.card = m + 1 := by
-  unfold chunk at hs
+    s.card = m ∨ s.card = m + 1 := by unfold chunk at hs;
   split_ifs  at hs <;> exact card_eq_of_mem_parts_equitabilise hs
 #align szemeredi_regularity.card_eq_of_mem_parts_chunk SzemerediRegularity.card_eq_of_mem_parts_chunk
 
@@ -522,10 +521,8 @@ private theorem edge_density_star_not_uniform [Nonempty α]
   rw [abs_sub_le_iff] at hrs hpr' hqt'
   rw [le_abs] at hst⊢
   cases hst
-  left
-  linarith
-  right
-  linarith
+  left; linarith
+  right; linarith
 
 /-- Lower bound on the edge densities between non-uniform parts of `szemeredi_regularity.increment`.
 -/
Diff
@@ -135,7 +135,6 @@ private theorem card_nonuniform_witness_sdiff_bUnion_star (hV : V ∈ P.parts) (
   rw [filter_congr_decidable] at t
   refine' t.trans (pow_le_pow (by norm_num) <| tsub_le_tsub_right _ _)
   exact card_image_le.trans (card_le_of_subset <| filter_subset _ _)
-#align szemeredi_regularity.card_nonuniform_witness_sdiff_bUnion_star szemeredi_regularity.card_nonuniform_witness_sdiff_bUnion_star
 
 private theorem one_sub_eps_mul_card_nonuniform_witness_le_card_star (hV : V ∈ P.parts)
     (hUV : U ≠ V) (hunif : ¬G.IsUniform ε U V) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -198,7 +197,6 @@ private theorem one_sub_eps_mul_card_nonuniform_witness_le_card_star (hV : V ∈
         card_sdiff (bUnion_star_subset_nonuniform_witness hP G ε hU V), cast_le]
       exact card_nonuniform_witness_sdiff_bUnion_star hV hUV hunif
     
-#align szemeredi_regularity.one_sub_eps_mul_card_nonuniform_witness_le_card_star szemeredi_regularity.one_sub_eps_mul_card_nonuniform_witness_le_card_star
 
 variable {hP G ε U hU V}
 
@@ -243,7 +241,6 @@ private theorem le_sum_card_subset_chunk_parts (h𝒜 : 𝒜 ⊆ (chunk hP G ε
   · rw [← (of_subset _ h𝒜 rfl).sum_card_parts, of_subset_parts, ← cast_mul, cast_le]
     exact card_nsmul_le_sum _ _ _ fun x hx => m_le_card_of_mem_chunk_parts <| h𝒜 hx
   · exact_mod_cast card_le_m_add_one_of_mem_chunk_parts (h𝒜 hs)
-#align szemeredi_regularity.le_sum_card_subset_chunk_parts szemeredi_regularity.le_sum_card_subset_chunk_parts
 
 private theorem sum_card_subset_chunk_parts_le (m_pos : (0 : ℝ) < m)
     (h𝒜 : 𝒜 ⊆ (chunk hP G ε hU).parts) (hs : s ∈ 𝒜) :
@@ -255,7 +252,6 @@ private theorem sum_card_subset_chunk_parts_le (m_pos : (0 : ℝ) < m)
     refine' card_bUnion_le_card_mul _ _ _ fun x hx => _
     apply card_le_m_add_one_of_mem_chunk_parts (h𝒜 hx)
   · exact_mod_cast m_le_card_of_mem_chunk_parts (h𝒜 hs)
-#align szemeredi_regularity.sum_card_subset_chunk_parts_le szemeredi_regularity.sum_card_subset_chunk_parts_le
 
 private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5) :
@@ -271,7 +267,6 @@ private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
   norm_num
   apply hundred_div_ε_pow_five_le_m hPα hPε
   positivity
-#align szemeredi_regularity.one_sub_le_m_div_m_add_one_sq szemeredi_regularity.one_sub_le_m_div_m_add_one_sq
 
 private theorem m_add_one_div_m_le_one_add [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -291,7 +286,6 @@ private theorem m_add_one_div_m_le_one_add [Nonempty α]
     div_le_iff (show (0 : ℝ) < 100 ^ 2 by norm_num), mul_assoc, sq]
   refine' mul_le_mul_of_nonneg_left _ (by positivity)
   exact (pow_le_one 5 (by positivity) hε₁).trans (by norm_num)
-#align szemeredi_regularity.m_add_one_div_m_le_one_add szemeredi_regularity.m_add_one_div_m_le_one_add
 
 private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -329,7 +323,6 @@ private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
     positivity
   refine' mul_pos (mul_pos _ _) (mul_pos _ _) <;> rw [cast_pos, Finset.card_pos]
   exacts[⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
-#align szemeredi_regularity.density_sub_eps_le_sum_density_div_card szemeredi_regularity.density_sub_eps_le_sum_density_div_card
 
 private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -368,7 +361,6 @@ private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
     · exact ⟨_, hy, nonempty_of_mem_parts _ (hB hy)⟩
   refine' mul_pos (mul_pos _ _) (mul_pos _ _) <;> rw [cast_pos, Finset.card_pos]
   exacts[⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
-#align szemeredi_regularity.sum_density_div_card_le_density_add_eps szemeredi_regularity.sum_density_div_card_le_density_add_eps
 
 private theorem average_density_near_total_density [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -391,7 +383,6 @@ private theorem average_density_near_total_density [Nonempty α]
     exact div_le_div_of_le_left (by positivity) (by norm_num) (by norm_num)
   rw [sub_le_iff_le_add, ← sub_le_iff_le_add']
   apply density_sub_eps_le_sum_density_div_card hPα hPε hA hB
-#align szemeredi_regularity.average_density_near_total_density szemeredi_regularity.average_density_near_total_density
 
 private theorem edge_density_chunk_aux [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
@@ -427,7 +418,6 @@ private theorem edge_density_chunk_aux [Nonempty α]
   rw [mul_right_comm, mul_div_left_comm, div_eq_mul_inv (ε ^ 5),
     show (2 : ℝ) / 50 = 25⁻¹ by norm_num]
   exact mul_le_of_le_one_right (by positivity) (by exact_mod_cast G.edge_density_le_one _ _)
-#align szemeredi_regularity.edge_density_chunk_aux szemeredi_regularity.edge_density_chunk_aux
 
 private theorem abs_density_star_sub_density_le_eps (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5)
     (hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} (hUV' : U ≠ V) (hUV : ¬G.IsUniform ε U V) :
@@ -442,7 +432,6 @@ private theorem abs_density_star_sub_density_le_eps (hPε : 100 ≤ 4 ^ P.parts.
       (one_sub_eps_mul_card_nonuniform_witness_le_card_star hU hUV'.symm (fun hVU => hUV hVU.symm)
         hPε hε₁)
   linarith
-#align szemeredi_regularity.abs_density_star_sub_density_le_eps szemeredi_regularity.abs_density_star_sub_density_le_eps
 
 private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
     (hPε : 100 ≤ 4 ^ P.parts.card * ε ^ 5) (hε₁ : ε ≤ 1) (hU : U ∈ P.parts) (hV : V ∈ P.parts)
@@ -484,7 +473,6 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
         div_le_iff hm]
       linarith
     
-#align szemeredi_regularity.eps_le_card_star_div szemeredi_regularity.eps_le_card_star_div
 
 /-!
 ### Final bounds
@@ -538,7 +526,6 @@ private theorem edge_density_star_not_uniform [Nonempty α]
   linarith
   right
   linarith
-#align szemeredi_regularity.edge_density_star_not_uniform szemeredi_regularity.edge_density_star_not_uniform
 
 /-- Lower bound on the edge densities between non-uniform parts of `szemeredi_regularity.increment`.
 -/
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yaël Dillies, Bhavik Mehta
 
 ! This file was ported from Lean 3 source module combinatorics.simple_graph.regularity.chunk
-! leanprover-community/mathlib commit f51de8769c34652d82d1c8e5f8f18f8374782bed
+! leanprover-community/mathlib commit bf7ef0e83e5b7e6c1169e97f055e58a2e4e9d52d
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -33,6 +33,10 @@ This entire file is internal to the proof of Szemerédi Regularity Lemma.
 
 Once ported to mathlib4, this file will be a great golfing ground for Heather's new tactic
 `rel_congr`.
+
+## References
+
+[Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp]
 -/
 
 
@@ -60,9 +64,9 @@ contained in the corresponding witness of non-uniformity.
 
 /-- The portion of `szemeredi_regularity.increment` which partitions `U`. -/
 noncomputable def chunk : Finpartition U :=
-  dite (U.card = m * 4 ^ P.parts.card + (card α / P.parts.card - m * 4 ^ P.parts.card))
-    (fun hUcard => (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₁ hUcard)
-    fun hUcard => (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₂ hP hU hUcard
+  if hUcard : U.card = m * 4 ^ P.parts.card + (card α / P.parts.card - m * 4 ^ P.parts.card) then
+    (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₁ hUcard
+  else (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₂ hP hU hUcard
 #align szemeredi_regularity.chunk SzemerediRegularity.chunk
 
 -- `hP` and `hU` are used to get that `U` has size

Changes in mathlib4

mathlib3
mathlib4
chore: make argument to sq_pos_of_ne_zero/sq_pos_iff implicit (#12288)

This matches our general policy and zpow_two_pos_of_ne_zero.

Also define sq_pos_of_ne_zero as an alias.

Diff
@@ -142,7 +142,7 @@ private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈
       _ ≤ ↑2 ^ P.parts.card * ε ^ 2 / 10 := by
         refine' (one_le_sq_iff <| by positivity).1 _
         rw [div_pow, mul_pow, pow_right_comm, ← pow_mul ε,
-          one_le_div (sq_pos_of_ne_zero (10 : ℝ) <| by norm_num)]
+          one_le_div (sq_pos_of_ne_zero <| by norm_num)]
         calc
           (↑10 ^ 2) = 100 := by norm_num
           _ ≤ ↑4 ^ P.parts.card * ε ^ 5 := hPε
chore: avoid id.def (adaptation for nightly-2024-03-27) (#11829)

Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com>

Diff
@@ -103,7 +103,7 @@ private theorem card_nonuniformWitness_sdiff_biUnion_star (hV : V ∈ P.parts) (
     rw [← biUnion_filter_atomise hX (G.nonuniformWitness_subset h₂), star, mem_sdiff,
       mem_biUnion] at hx
     simp only [not_exists, mem_biUnion, and_imp, exists_prop, mem_filter,
-      not_and, mem_sdiff, id.def, mem_sdiff] at hx ⊢
+      not_and, mem_sdiff, id, mem_sdiff] at hx ⊢
     obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx
     exact ⟨B, hB₁, hB₂, fun A hA AB => hx A hA <| AB.trans hB₁.2.1⟩
   apply (card_le_card q).trans (card_biUnion_le.trans _)
chore: superfluous parentheses part 2 (#12131)

Co-authored-by: Moritz Firsching <firsching@google.com>

Diff
@@ -138,7 +138,7 @@ private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈
           ((2 : ℝ) * 2) ^ P.parts.card * m / U.card := by
         rw [mul_pow, ← mul_div_assoc, mul_assoc]
       _ = ↑4 ^ P.parts.card * m / U.card := by norm_num
-      _ ≤ 1 := (div_le_one_of_le (pow_mul_m_le_card_part hP hU) (cast_nonneg _))
+      _ ≤ 1 := div_le_one_of_le (pow_mul_m_le_card_part hP hU) (cast_nonneg _)
       _ ≤ ↑2 ^ P.parts.card * ε ^ 2 / 10 := by
         refine' (one_le_sq_iff <| by positivity).1 _
         rw [div_pow, mul_pow, pow_right_comm, ← pow_mul ε,
change the order of operation in zsmulRec and nsmulRec (#11451)

We change the following field in the definition of an additive commutative monoid:

 nsmul_succ : ∀ (n : ℕ) (x : G),
-  AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
+  AddMonoid.nsmul (n + 1) x = AddMonoid.nsmul n x + x

where the latter is more natural

We adjust the definitions of ^ in monoids, groups, etc. Originally there was a warning comment about why this natural order was preferred

use x * npowRec n x and not npowRec n x * x in the definition to make sure that definitional unfolding of npowRec is blocked, to avoid deep recursion issues.

but it seems to no longer apply.

Remarks on the PR :

  • pow_succ and pow_succ' have switched their meanings.
  • Most of the time, the proofs were adjusted by priming/unpriming one lemma, or exchanging left and right; a few proofs were more complicated to adjust.
  • In particular, [Mathlib/NumberTheory/RamificationInertia.lean] used Ideal.IsPrime.mul_mem_pow which is defined in [Mathlib/RingTheory/DedekindDomain/Ideal.lean]. Changing the order of operation forced me to add the symmetric lemma Ideal.IsPrime.mem_pow_mul.
  • the docstring for Cauchy condensation test in [Mathlib/Analysis/PSeries.lean] was mathematically incorrect, I added the mention that the function is antitone.
Diff
@@ -161,7 +161,7 @@ private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈
     _ ≤ (G.nonuniformWitness ε U V).card - ↑2 ^ (P.parts.card - 1) * m := by
       refine' sub_le_sub_left _ _
       have : (2 : ℝ) ^ P.parts.card = ↑2 ^ (P.parts.card - 1) * 2 := by
-        rw [← _root_.pow_succ', tsub_add_cancel_of_le (succ_le_iff.2 hP₁)]
+        rw [← _root_.pow_succ, tsub_add_cancel_of_le (succ_le_iff.2 hP₁)]
       rw [← mul_div_right_comm, this, mul_right_comm _ (2 : ℝ), mul_assoc, le_div_iff]
       refine' mul_le_mul_of_nonneg_left _ (by positivity)
       exact (G.le_card_nonuniformWitness hunif).trans
chore: Rename mul-div cancellation lemmas (#11530)

Lemma names around cancellation of multiplication and division are a mess.

This PR renames a handful of them according to the following table (each big row contains the multiplicative statement, then the three rows contain the GroupWithZero lemma name, the Group lemma, the AddGroup lemma name).

| Statement | New name | Old name | |

Diff
@@ -227,7 +227,7 @@ private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5) :
     ↑1 - ε ^ 5 / ↑50 ≤ (m / (m + 1 : ℝ)) ^ 2 := by
   have : (m : ℝ) / (m + 1) = 1 - 1 / (m + 1) := by
-    rw [one_sub_div coe_m_add_one_pos.ne', add_sub_cancel]
+    rw [one_sub_div coe_m_add_one_pos.ne', add_sub_cancel_right]
   rw [this, sub_sq, one_pow, mul_one]
   refine' le_trans _ (le_add_of_nonneg_right <| sq_nonneg _)
   rw [sub_le_sub_iff_left, ← le_div_iff' (show (0 : ℝ) < 2 by norm_num), div_div,
chore: Rename monotonicity of / lemmas (#10634)

The new names and argument orders match the corresponding * lemmas, which I already took care of in a previous PR.

From LeanAPAP

Diff
@@ -356,7 +356,7 @@ private theorem edgeDensity_chunk_aux [Nonempty α]
   · refine' (sub_nonpos_of_le <| (sq_le _ _).trans <| hGε.trans _).trans (sq_nonneg _)
     · exact mod_cast G.edgeDensity_nonneg _ _
     · exact mod_cast G.edgeDensity_le_one _ _
-    · exact div_le_div_of_le_left (by sz_positivity) (by norm_num) (by norm_num)
+    · exact div_le_div_of_nonneg_left (by sz_positivity) (by norm_num) (by norm_num)
   rw [← sub_nonneg] at hGε
   have : ↑(G.edgeDensity U V) - ε ^ 5 / ↑50 ≤
       (∑ ab in (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
@@ -393,15 +393,14 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
   have hm : (0 : ℝ) ≤ 1 - (↑m)⁻¹ := sub_nonneg_of_le (inv_le_one <| one_le_m_coe hPα)
   have hε : 0 ≤ 1 - ε / 10 :=
     sub_nonneg_of_le (div_le_one_of_le (hε₁.trans <| by norm_num) <| by norm_num)
+  have hε₀ : 0 < ε := by sz_positivity
   calc
     4 / 5 * ε = (1 - 1 / 10) * (1 - 9⁻¹) * ε := by norm_num
-    _ ≤ (1 - ε / 10) * (1 - (↑m)⁻¹) * ((G.nonuniformWitness ε U V).card / U.card) :=
-      (mul_le_mul (mul_le_mul (sub_le_sub_left (div_le_div_of_le (by norm_num) hε₁) _)
-        (sub_le_sub_left (inv_le_inv_of_le (by norm_num) <|
-          mod_cast (show 9 ≤ 100 by norm_num).trans
-            (hundred_le_m hPα hPε hε₁)) _) (by norm_num) hε)
-        ((le_div_iff' <| (@cast_pos ℝ _ _ _).2 (P.nonempty_of_mem_parts hU).card_pos).2 <|
-          G.le_card_nonuniformWitness hunif) (by sz_positivity) (by positivity))
+    _ ≤ (1 - ε / 10) * (1 - (↑m)⁻¹) * ((G.nonuniformWitness ε U V).card / U.card) := by
+        gcongr
+        exacts [mod_cast (show 9 ≤ 100 by norm_num).trans (hundred_le_m hPα hPε hε₁),
+          (le_div_iff' <| cast_pos.2 (P.nonempty_of_mem_parts hU).card_pos).2 <|
+           G.le_card_nonuniformWitness hunif]
     _ = (1 - ε / 10) * (G.nonuniformWitness ε U V).card * ((1 - (↑m)⁻¹) / U.card) := by
       rw [mul_assoc, mul_assoc, mul_div_left_comm]
     _ ≤ ((star hP G ε hU V).biUnion id).card * ((1 - (↑m)⁻¹) / U.card) :=
@@ -410,7 +409,7 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
     _ ≤ (star hP G ε hU V).card * (m + 1) * ((1 - (↑m)⁻¹) / U.card) :=
       (mul_le_mul_of_nonneg_right card_biUnion_star_le_m_add_one_card_star_mul (by positivity))
     _ ≤ (star hP G ε hU V).card * (m + ↑1) * ((↑1 - (↑m)⁻¹) / (↑4 ^ P.parts.card * m)) :=
-      (mul_le_mul_of_nonneg_left (div_le_div_of_le_left hm (by sz_positivity) <|
+      (mul_le_mul_of_nonneg_left (div_le_div_of_nonneg_left hm (by sz_positivity) <|
         pow_mul_m_le_card_part hP hU) (by positivity))
     _ ≤ (star hP G ε hU V).card / ↑4 ^ P.parts.card := by
       rw [mul_assoc, mul_comm ((4 : ℝ) ^ P.parts.card), ← div_div, ← mul_div_assoc, ← mul_comm_div]
@@ -462,9 +461,7 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
     exact this
   have hε' : ε ^ 5 ≤ ε := by
     simpa using pow_le_pow_of_le_one (by sz_positivity) hε₁ (show 1 ≤ 5 by norm_num)
-  have hpr' : |p - r| ≤ ε / 49 := hpr.trans (div_le_div_of_le (by norm_num) hε')
-  have hqt' : |q - t| ≤ ε / 49 := hqt.trans (div_le_div_of_le (by norm_num) hε')
-  rw [abs_sub_le_iff] at hrs hpr' hqt'
+  rw [abs_sub_le_iff] at hrs hpr hqt
   rw [le_abs] at hst ⊢
   cases hst
   left; linarith
chore: move Mathlib to v4.7.0-rc1 (#11162)

This is a very large PR, but it has been reviewed piecemeal already in PRs to the bump/v4.7.0 branch as we update to intermediate nightlies.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Kyle Miller <kmill31415@gmail.com> Co-authored-by: damiano <adomani@gmail.com>

Diff
@@ -233,7 +233,7 @@ private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
   rw [sub_le_sub_iff_left, ← le_div_iff' (show (0 : ℝ) < 2 by norm_num), div_div,
     one_div_le coe_m_add_one_pos, one_div_div]
   refine' le_trans _ (le_add_of_nonneg_right zero_le_one)
-  norm_num
+  set_option tactic.skipAssignedInstances false in norm_num
   apply hundred_div_ε_pow_five_le_m hPα hPε
   sz_positivity
 
@@ -458,7 +458,7 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
     have := average_density_near_total_density hPα hPε hε₁
       (Subset.refl (chunk hP G ε hU).parts) (Subset.refl (chunk hP G ε hV).parts)
     simp_rw [← sup_eq_biUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this
-    norm_num at this
+    set_option tactic.skipAssignedInstances false in norm_num at this
     exact this
   have hε' : ε ^ 5 ≤ ε := by
     simpa using pow_le_pow_of_le_one (by sz_positivity) hε₁ (show 1 ≤ 5 by norm_num)
@@ -470,6 +470,7 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
   left; linarith
   right; linarith
 
+set_option tactic.skipAssignedInstances false in
 /-- Lower bound on the edge densities between non-uniform parts of `SzemerediRegularity.increment`.
 -/
 theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
chore: Rename Finpartition.supParts (#10223)

This should be Finpartition.sup_parts according to the naming convention

Diff
@@ -457,7 +457,7 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
   have hqt : |q - t| ≤ ε ^ 5 / 49 := by
     have := average_density_near_total_density hPα hPε hε₁
       (Subset.refl (chunk hP G ε hU).parts) (Subset.refl (chunk hP G ε hV).parts)
-    simp_rw [← sup_eq_biUnion, supParts, card_chunk (m_pos hPα).ne', cast_pow] at this
+    simp_rw [← sup_eq_biUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this
     norm_num at this
     exact this
   have hε' : ε ^ 5 ≤ ε := by
chore(*): minor golfs, mostly using gcongr (#9577)
Diff
@@ -342,7 +342,7 @@ private theorem average_density_near_total_density [Nonempty α]
   suffices (G.edgeDensity (A.biUnion id) (B.biUnion id) : ℝ) -
       (∑ ab in A.product B, (G.edgeDensity ab.1 ab.2 : ℝ)) / (A.card * B.card) ≤ ε ^ 5 / 50 by
     apply this.trans
-    exact div_le_div_of_le_left (by sz_positivity) (by norm_num) (by norm_num)
+    gcongr <;> [sz_positivity; norm_num]
   rw [sub_le_iff_le_add, ← sub_le_iff_le_add']
   apply density_sub_eps_le_sum_density_div_card hPα hPε hA hB
 
feat: deprecate div_le_div_of_le_of_nonneg (#9399)

This was noticed in the discussion around #9393.

Diff
@@ -396,7 +396,7 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
   calc
     4 / 5 * ε = (1 - 1 / 10) * (1 - 9⁻¹) * ε := by norm_num
     _ ≤ (1 - ε / 10) * (1 - (↑m)⁻¹) * ((G.nonuniformWitness ε U V).card / U.card) :=
-      (mul_le_mul (mul_le_mul (sub_le_sub_left (div_le_div_of_le_of_nonneg hε₁ <| by norm_num) _)
+      (mul_le_mul (mul_le_mul (sub_le_sub_left (div_le_div_of_le (by norm_num) hε₁) _)
         (sub_le_sub_left (inv_le_inv_of_le (by norm_num) <|
           mod_cast (show 9 ≤ 100 by norm_num).trans
             (hundred_le_m hPα hPε hε₁)) _) (by norm_num) hε)
@@ -462,8 +462,8 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
     exact this
   have hε' : ε ^ 5 ≤ ε := by
     simpa using pow_le_pow_of_le_one (by sz_positivity) hε₁ (show 1 ≤ 5 by norm_num)
-  have hpr' : |p - r| ≤ ε / 49 := hpr.trans (div_le_div_of_le_of_nonneg hε' <| by norm_num)
-  have hqt' : |q - t| ≤ ε / 49 := hqt.trans (div_le_div_of_le_of_nonneg hε' <| by norm_num)
+  have hpr' : |p - r| ≤ ε / 49 := hpr.trans (div_le_div_of_le (by norm_num) hε')
+  have hqt' : |q - t| ≤ ε / 49 := hqt.trans (div_le_div_of_le (by norm_num) hε')
   rw [abs_sub_le_iff] at hrs hpr' hqt'
   rw [le_abs] at hst ⊢
   cases hst
chore: Improve Finset lemma names (#8894)

Change a few lemma names that have historically bothered me.

  • Finset.card_le_of_subsetFinset.card_le_card
  • Multiset.card_le_of_leMultiset.card_le_card
  • Multiset.card_lt_of_ltMultiset.card_lt_card
  • Set.ncard_le_of_subsetSet.ncard_le_ncard
  • Finset.image_filterFinset.filter_image
  • CompleteLattice.finset_sup_compact_of_compactCompleteLattice.isCompactElement_finset_sup
Diff
@@ -106,7 +106,7 @@ private theorem card_nonuniformWitness_sdiff_biUnion_star (hV : V ∈ P.parts) (
       not_and, mem_sdiff, id.def, mem_sdiff] at hx ⊢
     obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx
     exact ⟨B, hB₁, hB₂, fun A hA AB => hx A hA <| AB.trans hB₁.2.1⟩
-  apply (card_le_of_subset q).trans (card_biUnion_le.trans _)
+  apply (card_le_card q).trans (card_biUnion_le.trans _)
   trans ∑ _i in (atomise U <| P.nonuniformWitnesses G ε U).parts.filter fun B =>
     B ⊆ G.nonuniformWitness ε U V ∧ B.Nonempty, m
   · suffices ∀ B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts,
@@ -121,7 +121,7 @@ private theorem card_nonuniformWitness_sdiff_biUnion_star (hV : V ∈ P.parts) (
   refine' mul_le_mul_right' _ _
   have t := card_filter_atomise_le_two_pow (s := U) hX
   refine' t.trans (pow_le_pow_right (by norm_num) <| tsub_le_tsub_right _ _)
-  exact card_image_le.trans (card_le_of_subset <| filter_subset _ _)
+  exact card_image_le.trans (card_le_card <| filter_subset _ _)
 
 private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈ P.parts)
     (hUV : U ≠ V) (hunif : ¬G.IsUniform ε U V) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
@@ -170,7 +170,7 @@ private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈
       sz_positivity
     _ ≤ ((star hP G ε hU V).biUnion id).card := by
       rw [sub_le_comm, ←
-        cast_sub (card_le_of_subset <| biUnion_star_subset_nonuniformWitness hP G ε hU V), ←
+        cast_sub (card_le_card <| biUnion_star_subset_nonuniformWitness hP G ε hU V), ←
         card_sdiff (biUnion_star_subset_nonuniformWitness hP G ε hU V)]
       exact mod_cast card_nonuniformWitness_sdiff_biUnion_star hV hUV hunif
 
chore: Rename pow monotonicity lemmas (#9095)

The names for lemmas about monotonicity of (a ^ ·) and (· ^ n) were a mess. This PR tidies up everything related by following the naming convention for (a * ·) and (· * b). Namely, (a ^ ·) is pow_right and (· ^ n) is pow_left in lemma names. All lemma renames follow the corresponding multiplication lemma names closely.

Renames

Algebra.GroupPower.Order

  • pow_monopow_right_mono
  • pow_le_powpow_le_pow_right
  • pow_le_pow_of_le_leftpow_le_pow_left
  • pow_lt_pow_of_lt_leftpow_lt_pow_left
  • strictMonoOn_powpow_left_strictMonoOn
  • pow_strictMono_rightpow_right_strictMono
  • pow_lt_powpow_lt_pow_right
  • pow_lt_pow_iffpow_lt_pow_iff_right
  • pow_le_pow_iffpow_le_pow_iff_right
  • self_lt_powlt_self_pow
  • strictAnti_powpow_right_strictAnti
  • pow_lt_pow_iff_of_lt_onepow_lt_pow_iff_right_of_lt_one
  • pow_lt_pow_of_lt_onepow_lt_pow_right_of_lt_one
  • lt_of_pow_lt_powlt_of_pow_lt_pow_left
  • le_of_pow_le_powle_of_pow_le_pow_left
  • pow_lt_pow₀pow_lt_pow_right₀

Algebra.GroupPower.CovariantClass

  • pow_le_pow_of_le_left'pow_le_pow_left'
  • nsmul_le_nsmul_of_le_rightnsmul_le_nsmul_right
  • pow_lt_pow'pow_lt_pow_right'
  • nsmul_lt_nsmulnsmul_lt_nsmul_left
  • pow_strictMono_leftpow_right_strictMono'
  • nsmul_strictMono_rightnsmul_left_strictMono
  • StrictMono.pow_right'StrictMono.pow_const
  • StrictMono.nsmul_leftStrictMono.const_nsmul
  • pow_strictMono_right'pow_left_strictMono
  • nsmul_strictMono_leftnsmul_right_strictMono
  • Monotone.pow_rightMonotone.pow_const
  • Monotone.nsmul_leftMonotone.const_nsmul
  • lt_of_pow_lt_pow'lt_of_pow_lt_pow_left'
  • lt_of_nsmul_lt_nsmullt_of_nsmul_lt_nsmul_right
  • pow_le_pow'pow_le_pow_right'
  • nsmul_le_nsmulnsmul_le_nsmul_left
  • pow_le_pow_of_le_one'pow_le_pow_right_of_le_one'
  • nsmul_le_nsmul_of_nonposnsmul_le_nsmul_left_of_nonpos
  • le_of_pow_le_pow'le_of_pow_le_pow_left'
  • le_of_nsmul_le_nsmul'le_of_nsmul_le_nsmul_right'
  • pow_le_pow_iff'pow_le_pow_iff_right'
  • nsmul_le_nsmul_iffnsmul_le_nsmul_iff_left
  • pow_lt_pow_iff'pow_lt_pow_iff_right'
  • nsmul_lt_nsmul_iffnsmul_lt_nsmul_iff_left

Data.Nat.Pow

  • Nat.pow_lt_pow_of_lt_leftNat.pow_lt_pow_left
  • Nat.pow_le_iff_le_leftNat.pow_le_pow_iff_left
  • Nat.pow_lt_iff_lt_leftNat.pow_lt_pow_iff_left

Lemmas added

  • pow_le_pow_iff_left
  • pow_lt_pow_iff_left
  • pow_right_injective
  • pow_right_inj
  • Nat.pow_le_pow_left to have the correct name since Nat.pow_le_pow_of_le_left is in Std.
  • Nat.pow_le_pow_right to have the correct name since Nat.pow_le_pow_of_le_right is in Std.

Lemmas removed

  • self_le_pow was a duplicate of le_self_pow.
  • Nat.pow_lt_pow_of_lt_right is defeq to pow_lt_pow_right.
  • Nat.pow_right_strictMono is defeq to pow_right_strictMono.
  • Nat.pow_le_iff_le_right is defeq to pow_le_pow_iff_right.
  • Nat.pow_lt_iff_lt_right is defeq to pow_lt_pow_iff_right.

Other changes

  • A bunch of proofs have been golfed.
  • Some lemma assumptions have been turned from 0 < n or 1 ≤ n to n ≠ 0.
  • A few Nat lemmas have been protected.
  • One docstring has been fixed.
Diff
@@ -120,7 +120,7 @@ private theorem card_nonuniformWitness_sdiff_biUnion_star (hV : V ∈ P.parts) (
   rw [sum_const]
   refine' mul_le_mul_right' _ _
   have t := card_filter_atomise_le_two_pow (s := U) hX
-  refine' t.trans (pow_le_pow (by norm_num) <| tsub_le_tsub_right _ _)
+  refine' t.trans (pow_le_pow_right (by norm_num) <| tsub_le_tsub_right _ _)
   exact card_image_le.trans (card_le_of_subset <| filter_subset _ _)
 
 private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈ P.parts)
@@ -245,7 +245,7 @@ private theorem m_add_one_div_m_le_one_add [Nonempty α]
   have : ↑1 + ↑1 / (m : ℝ) ≤ ↑1 + ε ^ 5 / 100 := by
     rw [add_le_add_iff_left, ← one_div_div (100 : ℝ)]
     exact one_div_le_one_div_of_le (by sz_positivity) (hundred_div_ε_pow_five_le_m hPα hPε)
-  refine' (pow_le_pow_of_le_left _ this 2).trans _
+  refine' (pow_le_pow_left _ this 2).trans _
   · positivity
   rw [add_sq, one_pow, add_assoc, add_le_add_iff_left, mul_one, ← le_sub_iff_add_le',
     div_eq_mul_one_div _ (49 : ℝ), mul_div_left_comm (2 : ℝ), ← mul_sub_left_distrib, div_pow,
@@ -367,7 +367,7 @@ private theorem edgeDensity_chunk_aux [Nonempty α]
     · rw [biUnion_parts, biUnion_parts]
     · rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← cast_mul, ← mul_pow, cast_pow]
       norm_cast
-  refine' le_trans _ (pow_le_pow_of_le_left hGε this 2)
+  refine' le_trans _ (pow_le_pow_left hGε this 2)
   rw [sub_sq, sub_add, sub_le_sub_iff_left]
   refine' (sub_le_self _ <| sq_nonneg <| ε ^ 5 / 50).trans _
   rw [mul_right_comm, mul_div_left_comm, div_eq_mul_inv (ε ^ 5),
chore: replace exact_mod_cast tactic with mod_cast elaborator where possible (#8404)

We still have the exact_mod_cast tactic, used in a few places, which somehow (?) works a little bit harder to prevent the expected type influencing the elaboration of the term. I would like to get to the bottom of this, and it will be easier once the only usages of exact_mod_cast are the ones that don't work using the term elaborator by itself.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -172,7 +172,7 @@ private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈
       rw [sub_le_comm, ←
         cast_sub (card_le_of_subset <| biUnion_star_subset_nonuniformWitness hP G ε hU V), ←
         card_sdiff (biUnion_star_subset_nonuniformWitness hP G ε hU V)]
-      exact_mod_cast card_nonuniformWitness_sdiff_biUnion_star hV hUV hunif
+      exact mod_cast card_nonuniformWitness_sdiff_biUnion_star hV hUV hunif
 
 /-! ### `chunk` -/
 
@@ -200,8 +200,8 @@ theorem card_le_m_add_one_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).part
 #align szemeredi_regularity.card_le_m_add_one_of_mem_chunk_parts SzemerediRegularity.card_le_m_add_one_of_mem_chunk_parts
 
 theorem card_biUnion_star_le_m_add_one_card_star_mul :
-    (((star hP G ε hU V).biUnion id).card : ℝ) ≤ (star hP G ε hU V).card * (m + 1) := by
-  exact_mod_cast card_biUnion_le_card_mul _ _ _ fun s hs =>
+    (((star hP G ε hU V).biUnion id).card : ℝ) ≤ (star hP G ε hU V).card * (m + 1) :=
+  mod_cast card_biUnion_le_card_mul _ _ _ fun _ hs =>
     card_le_m_add_one_of_mem_chunk_parts <| star_subset_chunk hs
 #align szemeredi_regularity.card_bUnion_star_le_m_add_one_card_star_mul SzemerediRegularity.card_biUnion_star_le_m_add_one_card_star_mul
 
@@ -211,7 +211,7 @@ private theorem le_sum_card_subset_chunk_parts (h𝒜 : 𝒜 ⊆ (chunk hP G ε
   refine' mul_le_mul _ _ (cast_nonneg _) (cast_nonneg _)
   · rw [← (ofSubset _ h𝒜 rfl).sum_card_parts, ofSubset_parts, ← cast_mul, cast_le]
     exact card_nsmul_le_sum _ _ _ fun x hx => m_le_card_of_mem_chunk_parts <| h𝒜 hx
-  · exact_mod_cast card_le_m_add_one_of_mem_chunk_parts (h𝒜 hs)
+  · exact mod_cast card_le_m_add_one_of_mem_chunk_parts (h𝒜 hs)
 
 private theorem sum_card_subset_chunk_parts_le (m_pos : (0 : ℝ) < m)
     (h𝒜 : 𝒜 ⊆ (chunk hP G ε hU).parts) (hs : s ∈ 𝒜) :
@@ -221,7 +221,7 @@ private theorem sum_card_subset_chunk_parts_le (m_pos : (0 : ℝ) < m)
   · norm_cast
     refine' card_biUnion_le_card_mul _ _ _ fun x hx => _
     apply card_le_m_add_one_of_mem_chunk_parts (h𝒜 hx)
-  · exact_mod_cast m_le_card_of_mem_chunk_parts (h𝒜 hs)
+  · exact mod_cast m_le_card_of_mem_chunk_parts (h𝒜 hs)
 
 private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
     (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α) (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5) :
@@ -263,7 +263,7 @@ private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
       (↑1 - ε ^ 5 / 50) * G.edgeDensity (A.biUnion id) (B.biUnion id) := by
     rw [sub_mul, one_mul, sub_le_sub_iff_left]
     refine' mul_le_of_le_one_right (by sz_positivity) _
-    exact_mod_cast G.edgeDensity_le_one _ _
+    exact mod_cast G.edgeDensity_le_one _ _
   refine' this.trans _
   conv_rhs => -- Porting note: LHS and RHS need separate treatment to get the desired form
     simp only [SimpleGraph.edgeDensity_def, sum_div, Rat.cast_div, div_div]
@@ -282,7 +282,7 @@ private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
     rw [div_mul_eq_mul_div, ← mul_assoc, mul_assoc]
     refine' div_le_one_of_le _ (by positivity)
     refine' (mul_le_mul_of_nonneg_right (one_sub_le_m_div_m_add_one_sq hPα hPε) _).trans _
-    · exact_mod_cast _root_.zero_le _
+    · exact mod_cast _root_.zero_le _
     rw [sq, mul_mul_mul_comm, mul_comm ((m : ℝ) / _), mul_comm ((m : ℝ) / _)]
     refine' mul_le_mul _ _ _ (cast_nonneg _)
     apply le_sum_card_subset_chunk_parts hA hx
@@ -301,7 +301,7 @@ private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
       G.edgeDensity (A.biUnion id) (B.biUnion id) + ε ^ 5 / 49 := by
     rw [add_mul, one_mul, add_le_add_iff_left]
     refine' mul_le_of_le_one_right (by sz_positivity) _
-    exact_mod_cast G.edgeDensity_le_one _ _
+    exact mod_cast G.edgeDensity_le_one _ _
   refine' le_trans _ this
   conv_lhs => -- Porting note: LHS and RHS need separate treatment to get the desired form
     simp only [SimpleGraph.edgeDensity, edgeDensity, sum_div, Rat.cast_div, div_div]
@@ -321,7 +321,7 @@ private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
     · rw [sq, mul_mul_mul_comm, mul_comm (_ / (m : ℝ)), mul_comm (_ / (m : ℝ))]
       exact mul_le_mul (sum_card_subset_chunk_parts_le (by sz_positivity) hA hx)
         (sum_card_subset_chunk_parts_le (by sz_positivity) hB hy) (by positivity) (by positivity)
-    · exact_mod_cast _root_.zero_le _
+    · exact mod_cast _root_.zero_le _
     rw [← cast_mul, cast_pos]
     apply mul_pos <;> rw [Finset.card_pos, sup_eq_biUnion, biUnion_nonempty]
     · exact ⟨_, hx, nonempty_of_mem_parts _ (hA hx)⟩
@@ -354,8 +354,8 @@ private theorem edgeDensity_chunk_aux [Nonempty α]
       (G.edgeDensity ab.1 ab.2 : ℝ)) / ↑16 ^ P.parts.card) ^ 2 := by
   obtain hGε | hGε := le_total (G.edgeDensity U V : ℝ) (ε ^ 5 / 50)
   · refine' (sub_nonpos_of_le <| (sq_le _ _).trans <| hGε.trans _).trans (sq_nonneg _)
-    · exact_mod_cast G.edgeDensity_nonneg _ _
-    · exact_mod_cast G.edgeDensity_le_one _ _
+    · exact mod_cast G.edgeDensity_nonneg _ _
+    · exact mod_cast G.edgeDensity_le_one _ _
     · exact div_le_div_of_le_left (by sz_positivity) (by norm_num) (by norm_num)
   rw [← sub_nonneg] at hGε
   have : ↑(G.edgeDensity U V) - ε ^ 5 / ↑50 ≤
@@ -372,7 +372,7 @@ private theorem edgeDensity_chunk_aux [Nonempty α]
   refine' (sub_le_self _ <| sq_nonneg <| ε ^ 5 / 50).trans _
   rw [mul_right_comm, mul_div_left_comm, div_eq_mul_inv (ε ^ 5),
     show (2 : ℝ) / 50 = 25⁻¹ by norm_num]
-  exact mul_le_of_le_one_right (by sz_positivity) (by exact_mod_cast G.edgeDensity_le_one _ _)
+  exact mul_le_of_le_one_right (by sz_positivity) (mod_cast G.edgeDensity_le_one _ _)
 
 private theorem abs_density_star_sub_density_le_eps (hPε : ↑100 ≤ ↑4 ^ P.parts.card * ε ^ 5)
     (hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} (hUV' : U ≠ V) (hUV : ¬G.IsUniform ε U V) :
@@ -397,8 +397,8 @@ private theorem eps_le_card_star_div [Nonempty α] (hPα : P.parts.card * 16 ^ P
     4 / 5 * ε = (1 - 1 / 10) * (1 - 9⁻¹) * ε := by norm_num
     _ ≤ (1 - ε / 10) * (1 - (↑m)⁻¹) * ((G.nonuniformWitness ε U V).card / U.card) :=
       (mul_le_mul (mul_le_mul (sub_le_sub_left (div_le_div_of_le_of_nonneg hε₁ <| by norm_num) _)
-        (sub_le_sub_left (inv_le_inv_of_le (by norm_num) <| by
-          exact_mod_cast (show 9 ≤ 100 by norm_num).trans
+        (sub_le_sub_left (inv_le_inv_of_le (by norm_num) <|
+          mod_cast (show 9 ≤ 100 by norm_num).trans
             (hundred_le_m hPα hPε hε₁)) _) (by norm_num) hε)
         ((le_div_iff' <| (@cast_pos ℝ _ _ _).2 (P.nonempty_of_mem_parts hU).card_pos).2 <|
           G.le_card_nonuniformWitness hunif) (by sz_positivity) (by positivity))
@@ -449,9 +449,9 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
   set t : ℝ := ↑(G.edgeDensity U V)
   have hrs : |r - s| ≤ ε / 5 := abs_density_star_sub_density_le_eps hPε hε₁ hUVne hUV
   have hst : ε ≤ |s - t| := by
-    -- After leanprover/lean4#2734, we need to do the zeta reduction before `norm_cast`.
+    -- After leanprover/lean4#2734, we need to do the zeta reduction before `mod_cast`.
     unfold_let s t
-    exact_mod_cast G.nonuniformWitness_spec hUVne hUV
+    exact mod_cast G.nonuniformWitness_spec hUVne hUV
   have hpr : |p - r| ≤ ε ^ 5 / 49 :=
     average_density_near_total_density hPα hPε hε₁ star_subset_chunk star_subset_chunk
   have hqt : |q - t| ≤ ε ^ 5 / 49 := by
chore: bump to v4.3.0-rc2 (#8366)

PR contents

This is the supremum of

along with some minor fixes from failures on nightly-testing as Mathlib master is merged into it.

Note that some PRs for changes that are already compatible with the current toolchain and will be necessary have already been split out: #8380.

I am hopeful that in future we will be able to progressively merge adaptation PRs into a bump/v4.X.0 branch, so we never end up with a "big merge" like this. However one of these adaptation PRs (#8056) predates my new scheme for combined CI, and it wasn't possible to keep that PR viable in the meantime.

Lean PRs involved in this bump

In particular this includes adjustments for the Lean PRs

leanprover/lean4#2778

We can get rid of all the

local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue [lean4#2220](https://github.com/leanprover/lean4/pull/2220)

macros across Mathlib (and in any projects that want to write natural number powers of reals).

leanprover/lean4#2722

Changes the default behaviour of simp to (config := {decide := false}). This makes simp (and consequentially norm_num) less powerful, but also more consistent, and less likely to blow up in long failures. This requires a variety of changes: changing some previously by simp or norm_num to decide or rfl, or adding (config := {decide := true}).

leanprover/lean4#2783

This changed the behaviour of simp so that simp [f] will only unfold "fully applied" occurrences of f. The old behaviour can be recovered with simp (config := { unfoldPartialApp := true }). We may in future add a syntax for this, e.g. simp [!f]; please provide feedback! In the meantime, we have made the following changes:

  • switching to using explicit lemmas that have the intended level of application
  • (config := { unfoldPartialApp := true }) in some places, to recover the old behaviour
  • Using @[eqns] to manually adjust the equation lemmas for a particular definition, recovering the old behaviour just for that definition. See #8371, where we do this for Function.comp and Function.flip.

This change in Lean may require further changes down the line (e.g. adding the !f syntax, and/or upstreaming the special treatment for Function.comp and Function.flip, and/or removing this special treatment). Please keep an open and skeptical mind about these changes!

Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Mauricio Collares <mauricio@collares.org>

Diff
@@ -39,8 +39,6 @@ Once ported to mathlib4, this file will be a great golfing ground for Heather's
 
 open Finpartition Finset Fintype Rel Nat
 
-local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue lean4#2220
-
 open scoped BigOperators Classical SzemerediRegularity.Positivity
 
 namespace SzemerediRegularity
chore: bump toolchain to v4.3.0-rc1 (#8051)

This incorporates changes from

  • #7845
  • #7847
  • #7853
  • #7872 (was never actually made to work, but the diffs in nightly-testing are unexciting: we need to fully qualify a few names)

They can all be closed when this is merged.

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -450,7 +450,10 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
   set s : ℝ := ↑(G.edgeDensity (G.nonuniformWitness ε U V) (G.nonuniformWitness ε V U))
   set t : ℝ := ↑(G.edgeDensity U V)
   have hrs : |r - s| ≤ ε / 5 := abs_density_star_sub_density_le_eps hPε hε₁ hUVne hUV
-  have hst : ε ≤ |s - t| := by exact_mod_cast G.nonuniformWitness_spec hUVne hUV
+  have hst : ε ≤ |s - t| := by
+    -- After leanprover/lean4#2734, we need to do the zeta reduction before `norm_cast`.
+    unfold_let s t
+    exact_mod_cast G.nonuniformWitness_spec hUVne hUV
   have hpr : |p - r| ≤ ε ^ 5 / 49 :=
     average_density_near_total_density hPα hPε hε₁ star_subset_chunk star_subset_chunk
   have hqt : |q - t| ≤ ε ^ 5 / 49 := by
feat: have notation3 use elaborator when generating matchers, add support for pi/lambda (#6833)

notation3 was generating matchers directly from syntax, which included a half-baked implementation of a term elaborator. This switches to elaborating the term and then generating matchers from the elaborated term. This

  1. is more robust and consistent, since it uses the main elaborator and one can make use of other notations
  2. has the nice side effect of adding term info to expansions in the notation3 command
  3. can unfortunately generate matchers that are more restrictive than before since they also match against elaborated features such as implicit arguments.

We now also generate matchers for expansions that have pi types and lambda expressions.

Diff
@@ -48,8 +48,7 @@ namespace SzemerediRegularity
 variable {α : Type*} [Fintype α] {P : Finpartition (univ : Finset α)} (hP : P.IsEquipartition)
   (G : SimpleGraph α) (ε : ℝ) {U : Finset α} (hU : U ∈ P.parts) (V : Finset α)
 
-local notation3 (prettyPrint := false)
-  "m" => (card α / stepBound P.parts.card : ℕ)
+local notation3 "m" => (card α / stepBound P.parts.card : ℕ)
 
 /-!
 ### Definitions
chore: speed up edgeDensity_chunk_not_uniform (#7088)
Diff
@@ -470,7 +470,6 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
   left; linarith
   right; linarith
 
-set_option maxHeartbeats 300000 in
 /-- Lower bound on the edge densities between non-uniform parts of `SzemerediRegularity.increment`.
 -/
 theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
@@ -491,7 +490,11 @@ theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^
       rw [show (16 : ℝ) = ↑4 ^ 2 by norm_num, pow_right_comm, sq ((4 : ℝ) ^ _), ←
         _root_.div_mul_div_comm, mul_assoc]
       have : 0 < ε := by sz_positivity
-      have UVl := mul_le_mul Ul Vl (by positivity) (by positivity)
+      have UVl := mul_le_mul Ul Vl (by positivity) ?_
+      swap
+      · -- This seems faster than `exact div_nonneg (by positivity) (by positivity)` and *much*
+        -- (tens of seconds) faster than `positivity` on its own.
+        apply div_nonneg <;> positivity
       refine' le_trans _ (mul_le_mul_of_nonneg_right UVl _)
       · norm_num
         nlinarith
chore: update/remove heart beat bumps (#6860)

We clean up heart beat bumps after #6474.

Diff
@@ -470,7 +470,7 @@ private theorem edgeDensity_star_not_uniform [Nonempty α]
   left; linarith
   right; linarith
 
-set_option maxHeartbeats 350000 in
+set_option maxHeartbeats 300000 in
 /-- Lower bound on the edge densities between non-uniform parts of `SzemerediRegularity.increment`.
 -/
 theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : P.parts.card * 16 ^ P.parts.card ≤ card α)
chore: banish Type _ and Sort _ (#6499)

We remove all possible occurences of Type _ and Sort _ in favor of Type* and Sort*.

This has nice performance benefits.

Diff
@@ -45,7 +45,7 @@ open scoped BigOperators Classical SzemerediRegularity.Positivity
 
 namespace SzemerediRegularity
 
-variable {α : Type _} [Fintype α] {P : Finpartition (univ : Finset α)} (hP : P.IsEquipartition)
+variable {α : Type*} [Fintype α] {P : Finpartition (univ : Finset α)} (hP : P.IsEquipartition)
   (G : SimpleGraph α) (ε : ℝ) {U : Finset α} (hU : U ∈ P.parts) (V : Finset α)
 
 local notation3 (prettyPrint := false)
chore: regularize HPow.hPow porting notes (#6465)
Diff
@@ -39,7 +39,7 @@ Once ported to mathlib4, this file will be a great golfing ground for Heather's
 
 open Finpartition Finset Fintype Rel Nat
 
-local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue #2220
+local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue lean4#2220
 
 open scoped BigOperators Classical SzemerediRegularity.Positivity
 
chore: script to replace headers with #align_import statements (#5979)

Open in Gitpod

Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -2,16 +2,13 @@
 Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Yaël Dillies, Bhavik Mehta
-
-! This file was ported from Lean 3 source module combinatorics.simple_graph.regularity.chunk
-! leanprover-community/mathlib commit bf7ef0e83e5b7e6c1169e97f055e58a2e4e9d52d
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Combinatorics.SimpleGraph.Regularity.Bound
 import Mathlib.Combinatorics.SimpleGraph.Regularity.Equitabilise
 import Mathlib.Combinatorics.SimpleGraph.Regularity.Uniform
 
+#align_import combinatorics.simple_graph.regularity.chunk from "leanprover-community/mathlib"@"bf7ef0e83e5b7e6c1169e97f055e58a2e4e9d52d"
+
 /-!
 # Chunk of the increment partition for Szemerédi Regularity Lemma
 
feat: port Combinatorics.SimpleGraph.Regularity.Chunk (#5474)

Dependencies 12 + 771

772 files ported (98.5%)
337520 lines ported (98.4%)
Show graph

The unported dependencies are

The following 1 dependencies have changed in mathlib3 since they were ported, which may complicate porting this file