data.nat.squarefreeMathlib.Data.Nat.Squarefree

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)

(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)

(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
@@ -413,7 +413,7 @@ theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n :=
   by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
-  refine' ball_congr fun p hp => _
+  refine' forall₂_congr fun p hp => _
   simp only [hmn.is_prime_pow_dvd_mul (hp.is_prime_pow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
 -/
Diff
@@ -3,9 +3,9 @@ Copyright (c) 2020 Aaron Anderson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
 -/
-import Algebra.Squarefree
+import Algebra.Squarefree.Basic
 import Data.Nat.Factorization.PrimePow
-import Data.Nat.PrimeNormNum
+import Tactic.NormNum.Prime
 import RingTheory.Int.Basic
 
 #align_import data.nat.squarefree from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b"
Diff
@@ -48,11 +48,11 @@ theorem Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree
     n.factorization p ≤ 1 := by
   rcases eq_or_ne n 0 with (rfl | hn')
   · simp
-  rw [multiplicity.squarefree_iff_multiplicity_le_one] at hn 
+  rw [multiplicity.squarefree_iff_multiplicity_le_one] at hn
   by_cases hp : p.prime
   · have := hn p
     simp only [multiplicity_eq_factorization hp hn', Nat.isUnit_iff, hp.ne_one, or_false_iff] at
-      this 
+      this
     exact_mod_cast this
   · rw [factorization_eq_zero_of_non_prime _ hp]
     exact zero_le_one
@@ -85,10 +85,10 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
   by_cases hp : p.prime
   · have h₁ := h _ hp
     rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,
-      hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁ 
+      hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁
     have h₂ := squarefree.factorization_le_one p hn
     have h₃ := squarefree.factorization_le_one p hm
-    rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃ 
+    rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃
     cases h₂
     · rwa [h₂, eq_comm, ← h₁]
     · rw [h₂, h₃.resolve_left]
@@ -119,7 +119,7 @@ theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimeP
   refine' Iff.symm ⟨fun hn => ⟨hn.Squarefree, hn.IsPrimePow⟩, _⟩
   rw [isPrimePow_nat_iff]
   rintro ⟨h, p, k, hp, hk, rfl⟩
-  rw [squarefree_pow_iff hp.ne_one hk.ne'] at h 
+  rw [squarefree_pow_iff hp.ne_one hk.ne'] at h
   rwa [h.2, pow_one]
 #align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime
 -/
@@ -179,7 +179,7 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
   · rw [min_sq_fac_prop, squarefree_iff_prime_squarefree] at H ⊢
     exact fun p pp dp => H p pp ((dvd_div_iff dk).2 (this _ pp dp))
   · obtain ⟨H1, H2, H3⟩ := H
-    simp only [dvd_div_iff dk] at H2 H3 
+    simp only [dvd_div_iff dk] at H2 H3
     exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
 -/
@@ -210,9 +210,9 @@ theorem minSqFacAux_has_prop :
       cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
       · subst me; contradiction
       apply (Nat.eq_or_lt_of_le ml).resolve_left; intro me
-      rw [← me, e] at d ; change 2 * (i + 2) ∣ n' at d 
+      rw [← me, e] at d; change 2 * (i + 2) ∣ n' at d
       have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
-      rw [e] at this ; exact absurd this (by decide)
+      rw [e] at this; exact absurd this (by decide)
     have pk : k ∣ n → Prime k :=
       by
       refine' fun dk => prime_def_min_fac.2 ⟨k2, le_antisymm (min_fac_le k0) _⟩
@@ -245,20 +245,20 @@ theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) :=
 
 #print Nat.minSqFac_prime /-
 theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d := by
-  have := min_sq_fac_has_prop n; rw [h] at this ; exact this.1
+  have := min_sq_fac_has_prop n; rw [h] at this; exact this.1
 #align nat.min_sq_fac_prime Nat.minSqFac_prime
 -/
 
 #print Nat.minSqFac_dvd /-
 theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n := by
-  have := min_sq_fac_has_prop n; rw [h] at this ; exact this.2.1
+  have := min_sq_fac_has_prop n; rw [h] at this; exact this.2.1
 #align nat.min_sq_fac_dvd Nat.minSqFac_dvd
 -/
 
 #print Nat.minSqFac_le_of_dvd /-
 theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) :
     d ≤ m := by
-  have := min_sq_fac_has_prop n; rw [h] at this 
+  have := min_sq_fac_has_prop n; rw [h] at this
   have fd := min_fac_dvd m
   exact
     le_trans (this.2.2 _ (min_fac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md))
@@ -273,7 +273,7 @@ theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :
   constructor <;> intro H
   · cases' n.min_sq_fac with d; · rfl
     cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1
-  · rwa [H] at this 
+  · rwa [H] at this
 #align nat.squarefree_iff_min_sq_fac Nat.squarefree_iff_minSqFac
 -/
 
@@ -302,13 +302,13 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
       use(UniqueFactorizationMonoid.normalizedFactors a).toFinset
       simp only [id.def, Finset.mem_powerset]
       rcases an with ⟨b, rfl⟩
-      rw [mul_ne_zero_iff] at h0 
-      rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq 
+      rw [mul_ne_zero_iff] at h0
+      rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq
       rw [Multiset.toFinset_subset, Multiset.toFinset_val, hsq.dedup, ← associated_iff_eq,
         normalized_factors_mul h0.1 h0.2]
       exact ⟨Multiset.subset_of_le (Multiset.le_add_right _ _), normalized_factors_prod h0.1⟩
     · rintro ⟨s, hs, rfl⟩
-      rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs 
+      rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs
       have hs0 : s.val.prod ≠ 0 :=
         by
         rw [Ne.def, Multiset.prod_eq_zero_iff]
@@ -325,12 +325,12 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
             irreducible_of_normalized_factor x
               (Multiset.mem_of_le (le_trans hs (Multiset.dedup_le _)) hx))
           (normalized_factors_prod hs0)
-      rw [associated_eq_eq, Multiset.rel_eq] at h 
+      rw [associated_eq_eq, Multiset.rel_eq] at h
       rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors hs0, h]
       apply s.nodup
   · intro x hx y hy h
     rw [← Finset.val_inj, ← Multiset.rel_eq, ← associated_eq_eq]
-    rw [← Finset.mem_def, Finset.mem_powerset] at hx hy 
+    rw [← Finset.mem_def, Finset.mem_powerset] at hx hy
     apply UniqueFactorizationMonoid.factors_unique _ _ (associated_iff_eq.2 h)
     · intro z hz
       apply irreducible_of_normalized_factor z
@@ -367,11 +367,11 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
     simpa [S]
   let s := Finset.max' S hSne
   have hs : s ∈ S := Finset.max'_mem S hSne
-  simp only [Finset.sep_def, S, Finset.mem_filter, Finset.mem_range] at hs 
+  simp only [Finset.sep_def, S, Finset.mem_filter, Finset.mem_range] at hs
   obtain ⟨hsn1, ⟨a, hsa⟩, ⟨b, hsb⟩⟩ := hs
-  rw [hsa] at hn 
+  rw [hsa] at hn
   obtain ⟨hlts, hlta⟩ := canonically_ordered_comm_semiring.mul_pos.mp hn
-  rw [hsb] at hsa hn hlts 
+  rw [hsb] at hsa hn hlts
   refine' ⟨a, b, hlta, (pow_pos_iff zero_lt_two).mp hlts, hsa.symm, _⟩
   rintro x ⟨y, hy⟩
   rw [Nat.isUnit_iff]
@@ -454,7 +454,7 @@ theorem squarefree_helper_0 {k} (k0 : 0 < k) {p : ℕ} (pp : Nat.Prime p) (h : b
     bit1 (k + 1) ≤ p ∨ bit1 k = p :=
   by
   rcases lt_or_eq_of_le h with ((hp : _ + 1 ≤ _) | hp)
-  · rw [bit1, bit0_eq_two_mul] at hp ; change 2 * (_ + 1) ≤ _ at hp 
+  · rw [bit1, bit0_eq_two_mul] at hp; change 2 * (_ + 1) ≤ _ at hp
     rw [bit1, bit0_eq_two_mul]
     refine' Or.inl (lt_of_le_of_ne hp _); rintro rfl
     exact Nat.not_prime_mul (by decide) (lt_add_of_pos_left _ k0) pp
@@ -510,7 +510,7 @@ theorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1
   have :=
     (ih p pp (dvd_trans hp md)).trans
       (le_trans (Nat.le_of_dvd (lt_of_lt_of_le (by decide) m2) hp) hm)
-  rw [Nat.le_sqrt] at this 
+  rw [Nat.le_sqrt] at this
   exact not_le_of_lt hd this
 #align tactic.norm_num.squarefree_helper_4 Tactic.NormNum.squarefreeHelper_4
 
Diff
@@ -124,7 +124,7 @@ theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimeP
 #align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime
 -/
 
-/- ./././Mathport/Syntax/Translate/Command.lean:298:8: warning: using_well_founded used, estimated equivalent -/
+/- ./././Mathport/Syntax/Translate/Command.lean:299:8: warning: using_well_founded used, estimated equivalent -/
 #print Nat.minSqFacAux /-
 /-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that
   `p^2 ∣ n`. -/
@@ -143,8 +143,7 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
             this
         if k ∣ n' then some k else min_sq_fac_aux n' (k + 2)
       else min_sq_fac_aux n (k + 2)
-termination_by
-  _ x => WellFounded.wrap (measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k) x
+termination_by x => WellFounded.wrap (measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k) x
 #align nat.min_sq_fac_aux Nat.minSqFacAux
 -/
 
@@ -185,7 +184,7 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
 -/
 
-/- ./././Mathport/Syntax/Translate/Command.lean:298:8: warning: using_well_founded used, estimated equivalent -/
+/- ./././Mathport/Syntax/Translate/Command.lean:299:8: warning: using_well_founded used, estimated equivalent -/
 #print Nat.minSqFacAux_has_prop /-
 theorem minSqFacAux_has_prop :
     ∀ {n : ℕ} (k),
@@ -223,8 +222,7 @@ theorem minSqFacAux_has_prop :
     · specialize IH (n / k) (div_dvd_of_dvd dk) dkk
       exact min_sq_fac_prop_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
     · exact IH n (dvd_refl _) dk
-termination_by
-  _ x => WellFounded.wrap (measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k) x
+termination_by x => WellFounded.wrap (measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k) x
 #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop
 -/
 
Diff
@@ -124,6 +124,7 @@ theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimeP
 #align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime
 -/
 
+/- ./././Mathport/Syntax/Translate/Command.lean:298:8: warning: using_well_founded used, estimated equivalent -/
 #print Nat.minSqFacAux /-
 /-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that
   `p^2 ∣ n`. -/
@@ -142,7 +143,8 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
             this
         if k ∣ n' then some k else min_sq_fac_aux n' (k + 2)
       else min_sq_fac_aux n (k + 2)
-termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
+termination_by
+  _ x => WellFounded.wrap (measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k) x
 #align nat.min_sq_fac_aux Nat.minSqFacAux
 -/
 
@@ -183,6 +185,7 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
 -/
 
+/- ./././Mathport/Syntax/Translate/Command.lean:298:8: warning: using_well_founded used, estimated equivalent -/
 #print Nat.minSqFacAux_has_prop /-
 theorem minSqFacAux_has_prop :
     ∀ {n : ℕ} (k),
@@ -220,7 +223,8 @@ theorem minSqFacAux_has_prop :
     · specialize IH (n / k) (div_dvd_of_dvd dk) dkk
       exact min_sq_fac_prop_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
     · exact IH n (dvd_refl _) dk
-termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
+termination_by
+  _ x => WellFounded.wrap (measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k) x
 #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop
 -/
 
Diff
@@ -43,8 +43,8 @@ theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prim
 #align nat.squarefree_iff_prime_squarefree Nat.squarefree_iff_prime_squarefree
 -/
 
-#print Nat.Squarefree.factorization_le_one /-
-theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :
+#print Squarefree.natFactorization_le_one /-
+theorem Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :
     n.factorization p ≤ 1 := by
   rcases eq_or_ne n 0 with (rfl | hn')
   · simp
@@ -56,7 +56,7 @@ theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n)
     exact_mod_cast this
   · rw [factorization_eq_zero_of_non_prime _ hp]
     exact zero_le_one
-#align nat.squarefree.factorization_le_one Nat.Squarefree.factorization_le_one
+#align nat.squarefree.factorization_le_one Squarefree.natFactorization_le_one
 -/
 
 #print Nat.squarefree_of_factorization_le_one /-
@@ -73,7 +73,7 @@ theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p
 #print Nat.squarefree_iff_factorization_le_one /-
 theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :
     Squarefree n ↔ ∀ p, n.factorization p ≤ 1 :=
-  ⟨fun p hn => Squarefree.factorization_le_one hn p, squarefree_of_factorization_le_one hn⟩
+  ⟨fun p hn => Squarefree.natFactorization_le_one hn p, squarefree_of_factorization_le_one hn⟩
 #align nat.squarefree_iff_factorization_le_one Nat.squarefree_iff_factorization_le_one
 -/
 
Diff
@@ -3,10 +3,10 @@ Copyright (c) 2020 Aaron Anderson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
 -/
-import Mathbin.Algebra.Squarefree
-import Mathbin.Data.Nat.Factorization.PrimePow
-import Mathbin.Data.Nat.PrimeNormNum
-import Mathbin.RingTheory.Int.Basic
+import Algebra.Squarefree
+import Data.Nat.Factorization.PrimePow
+import Data.Nat.PrimeNormNum
+import RingTheory.Int.Basic
 
 #align_import data.nat.squarefree from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b"
 
Diff
@@ -407,7 +407,7 @@ theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefre
 /-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`
 and generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and
 `squarefree.of_mul_right` above for auxiliary lemmas. -/
-theorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :
+theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n :=
   by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
Diff
@@ -512,10 +512,10 @@ theorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1
   exact not_le_of_lt hd this
 #align tactic.norm_num.squarefree_helper_4 Tactic.NormNum.squarefreeHelper_4
 
-theorem not_squarefree_mul (a aa b n : ℕ) (ha : a * a = aa) (hb : aa * b = n) (h₁ : 1 < a) :
+theorem not_squarefree_hMul (a aa b n : ℕ) (ha : a * a = aa) (hb : aa * b = n) (h₁ : 1 < a) :
     ¬Squarefree n := by rw [← hb, ← ha];
   exact fun H => ne_of_gt h₁ (Nat.isUnit_iff.1 <| H _ ⟨_, rfl⟩)
-#align tactic.norm_num.not_squarefree_mul Tactic.NormNum.not_squarefree_mul
+#align tactic.norm_num.not_squarefree_mul Tactic.NormNum.not_squarefree_hMul
 
 /-- Given `e` a natural numeral and `a : nat` with `a^2 ∣ n`, return `⊢ ¬ squarefree e`. -/
 unsafe def prove_non_squarefree (e : expr) (n a : ℕ) : tactic expr := do
@@ -528,7 +528,7 @@ unsafe def prove_non_squarefree (e : expr) (n a : ℕ) : tactic expr := do
   let (c, eaa, pa) ← prove_mul_nat c ea ea
   let (c, e', pb) ← prove_mul_nat c eaa eb
   guard (e' == e)
-  return <| q(@not_squarefree_mul).mk_app [ea, eaa, eb, e, pa, pb, p₁]
+  return <| q(@not_squarefree_hMul).mk_app [ea, eaa, eb, e, pa, pb, p₁]
 #align tactic.norm_num.prove_non_squarefree tactic.norm_num.prove_non_squarefree
 
 /-- Given `en`,`en1 := bit1 en`, `n1` the value of `en1`, `ek`,
Diff
@@ -297,7 +297,7 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
       mem_divisors]
     constructor
     · rintro ⟨⟨an, h0⟩, hsq⟩
-      use (UniqueFactorizationMonoid.normalizedFactors a).toFinset
+      use(UniqueFactorizationMonoid.normalizedFactors a).toFinset
       simp only [id.def, Finset.mem_powerset]
       rcases an with ⟨b, rfl⟩
       rw [mul_ne_zero_iff] at h0 
Diff
@@ -2,17 +2,14 @@
 Copyright (c) 2020 Aaron Anderson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
-
-! This file was ported from Lean 3 source module data.nat.squarefree
-! leanprover-community/mathlib commit 0b7c740e25651db0ba63648fbae9f9d6f941e31b
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathbin.Algebra.Squarefree
 import Mathbin.Data.Nat.Factorization.PrimePow
 import Mathbin.Data.Nat.PrimeNormNum
 import Mathbin.RingTheory.Int.Basic
 
+#align_import data.nat.squarefree from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b"
+
 /-!
 # Lemmas about squarefreeness of natural numbers
 
Diff
@@ -288,6 +288,7 @@ theorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_factors] <;
 
 open UniqueFactorizationMonoid
 
+#print Nat.divisors_filter_squarefree /-
 theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
     (n.divisors.filterₓ Squarefree).val =
       (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x =>
@@ -341,9 +342,11 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
       rw [← Multiset.mem_toFinset]
       apply hy hz
 #align nat.divisors_filter_squarefree Nat.divisors_filter_squarefree
+-/
 
 open scoped BigOperators
 
+#print Nat.sum_divisors_filter_squarefree /-
 theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
     {f : ℕ → α} :
     ∑ i in n.divisors.filterₓ Squarefree, f i =
@@ -352,6 +355,7 @@ theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [A
   rw [Finset.sum_eq_multiset_sum, divisors_filter_squarefree h0, Multiset.map_map,
     Finset.sum_eq_multiset_sum]
 #align nat.sum_divisors_filter_squarefree Nat.sum_divisors_filter_squarefree
+-/
 
 #print Nat.sq_mul_squarefree_of_pos /-
 theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
Diff
@@ -346,7 +346,7 @@ open scoped BigOperators
 
 theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
     {f : ℕ → α} :
-    (∑ i in n.divisors.filterₓ Squarefree, f i) =
+    ∑ i in n.divisors.filterₓ Squarefree, f i =
       ∑ i in (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset, f i.val.Prod :=
   by
   rw [Finset.sum_eq_multiset_sum, divisors_filter_squarefree h0, Multiset.map_map,
Diff
@@ -357,7 +357,7 @@ theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [A
 theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
     ∃ a b : ℕ, 0 < a ∧ 0 < b ∧ b ^ 2 * a = n ∧ Squarefree a :=
   by
-  let S := { s ∈ Finset.range (n + 1) | s ∣ n ∧ ∃ x, s = x ^ 2 }
+  let S := {s ∈ Finset.range (n + 1) | s ∣ n ∧ ∃ x, s = x ^ 2}
   have hSne : S.nonempty := by
     use 1
     have h1 : 0 < n ∧ ∃ x : ℕ, 1 = x ^ 2 := ⟨hn, ⟨1, (one_pow 2).symm⟩⟩
@@ -376,7 +376,8 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   refine' lt_le_antisymm _ (Finset.le_max' S ((b * x) ^ 2) _)
   · simp_rw [S, hsa, Finset.sep_def, Finset.mem_filter, Finset.mem_range]
     refine' ⟨lt_succ_iff.mpr (le_of_dvd hn _), _, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring
-  · convert lt_mul_of_one_lt_right hlts
+  · convert
+      lt_mul_of_one_lt_right hlts
         (one_lt_pow 2 x zero_lt_two (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
     rw [mul_pow]
 #align nat.sq_mul_squarefree_of_pos Nat.sq_mul_squarefree_of_pos
Diff
@@ -51,11 +51,11 @@ theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n)
     n.factorization p ≤ 1 := by
   rcases eq_or_ne n 0 with (rfl | hn')
   · simp
-  rw [multiplicity.squarefree_iff_multiplicity_le_one] at hn
+  rw [multiplicity.squarefree_iff_multiplicity_le_one] at hn 
   by_cases hp : p.prime
   · have := hn p
     simp only [multiplicity_eq_factorization hp hn', Nat.isUnit_iff, hp.ne_one, or_false_iff] at
-      this
+      this 
     exact_mod_cast this
   · rw [factorization_eq_zero_of_non_prime _ hp]
     exact zero_le_one
@@ -88,10 +88,10 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
   by_cases hp : p.prime
   · have h₁ := h _ hp
     rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,
-      hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁
+      hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁ 
     have h₂ := squarefree.factorization_le_one p hn
     have h₃ := squarefree.factorization_le_one p hm
-    rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃
+    rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃ 
     cases h₂
     · rwa [h₂, eq_comm, ← h₁]
     · rw [h₂, h₃.resolve_left]
@@ -122,7 +122,7 @@ theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimeP
   refine' Iff.symm ⟨fun hn => ⟨hn.Squarefree, hn.IsPrimePow⟩, _⟩
   rw [isPrimePow_nat_iff]
   rintro ⟨h, p, k, hp, hk, rfl⟩
-  rw [squarefree_pow_iff hp.ne_one hk.ne'] at h
+  rw [squarefree_pow_iff hp.ne_one hk.ne'] at h 
   rwa [h.2, pow_one]
 #align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime
 -/
@@ -144,8 +144,8 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
               _)
             this
         if k ∣ n' then some k else min_sq_fac_aux n' (k + 2)
-      else min_sq_fac_aux n (k + 2)termination_by'
-  ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
+      else min_sq_fac_aux n (k + 2)
+termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
 #align nat.min_sq_fac_aux Nat.minSqFacAux
 -/
 
@@ -178,10 +178,10 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
     have := (coprime_primes pk pp).2 fun e => by subst e; contradiction
     (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp
   cases' o with d
-  · rw [min_sq_fac_prop, squarefree_iff_prime_squarefree] at H⊢
+  · rw [min_sq_fac_prop, squarefree_iff_prime_squarefree] at H ⊢
     exact fun p pp dp => H p pp ((dvd_div_iff dk).2 (this _ pp dp))
   · obtain ⟨H1, H2, H3⟩ := H
-    simp only [dvd_div_iff dk] at H2 H3
+    simp only [dvd_div_iff dk] at H2 H3 
     exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
 -/
@@ -211,9 +211,9 @@ theorem minSqFacAux_has_prop :
       cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
       · subst me; contradiction
       apply (Nat.eq_or_lt_of_le ml).resolve_left; intro me
-      rw [← me, e] at d; change 2 * (i + 2) ∣ n' at d
+      rw [← me, e] at d ; change 2 * (i + 2) ∣ n' at d 
       have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
-      rw [e] at this; exact absurd this (by decide)
+      rw [e] at this ; exact absurd this (by decide)
     have pk : k ∣ n → Prime k :=
       by
       refine' fun dk => prime_def_min_fac.2 ⟨k2, le_antisymm (min_fac_le k0) _⟩
@@ -222,7 +222,8 @@ theorem minSqFacAux_has_prop :
     · exact ⟨pk dk, (Nat.dvd_div_iff dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩
     · specialize IH (n / k) (div_dvd_of_dvd dk) dkk
       exact min_sq_fac_prop_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
-    · exact IH n (dvd_refl _) dk termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
+    · exact IH n (dvd_refl _) dk
+termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
 #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop
 -/
 
@@ -245,20 +246,20 @@ theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) :=
 
 #print Nat.minSqFac_prime /-
 theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d := by
-  have := min_sq_fac_has_prop n; rw [h] at this; exact this.1
+  have := min_sq_fac_has_prop n; rw [h] at this ; exact this.1
 #align nat.min_sq_fac_prime Nat.minSqFac_prime
 -/
 
 #print Nat.minSqFac_dvd /-
 theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n := by
-  have := min_sq_fac_has_prop n; rw [h] at this; exact this.2.1
+  have := min_sq_fac_has_prop n; rw [h] at this ; exact this.2.1
 #align nat.min_sq_fac_dvd Nat.minSqFac_dvd
 -/
 
 #print Nat.minSqFac_le_of_dvd /-
 theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) :
     d ≤ m := by
-  have := min_sq_fac_has_prop n; rw [h] at this
+  have := min_sq_fac_has_prop n; rw [h] at this 
   have fd := min_fac_dvd m
   exact
     le_trans (this.2.2 _ (min_fac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md))
@@ -273,7 +274,7 @@ theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :
   constructor <;> intro H
   · cases' n.min_sq_fac with d; · rfl
     cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1
-  · rwa [H] at this
+  · rwa [H] at this 
 #align nat.squarefree_iff_min_sq_fac Nat.squarefree_iff_minSqFac
 -/
 
@@ -301,13 +302,13 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
       use (UniqueFactorizationMonoid.normalizedFactors a).toFinset
       simp only [id.def, Finset.mem_powerset]
       rcases an with ⟨b, rfl⟩
-      rw [mul_ne_zero_iff] at h0
-      rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq
+      rw [mul_ne_zero_iff] at h0 
+      rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq 
       rw [Multiset.toFinset_subset, Multiset.toFinset_val, hsq.dedup, ← associated_iff_eq,
         normalized_factors_mul h0.1 h0.2]
       exact ⟨Multiset.subset_of_le (Multiset.le_add_right _ _), normalized_factors_prod h0.1⟩
     · rintro ⟨s, hs, rfl⟩
-      rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs
+      rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs 
       have hs0 : s.val.prod ≠ 0 :=
         by
         rw [Ne.def, Multiset.prod_eq_zero_iff]
@@ -324,12 +325,12 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
             irreducible_of_normalized_factor x
               (Multiset.mem_of_le (le_trans hs (Multiset.dedup_le _)) hx))
           (normalized_factors_prod hs0)
-      rw [associated_eq_eq, Multiset.rel_eq] at h
+      rw [associated_eq_eq, Multiset.rel_eq] at h 
       rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors hs0, h]
       apply s.nodup
   · intro x hx y hy h
     rw [← Finset.val_inj, ← Multiset.rel_eq, ← associated_eq_eq]
-    rw [← Finset.mem_def, Finset.mem_powerset] at hx hy
+    rw [← Finset.mem_def, Finset.mem_powerset] at hx hy 
     apply UniqueFactorizationMonoid.factors_unique _ _ (associated_iff_eq.2 h)
     · intro z hz
       apply irreducible_of_normalized_factor z
@@ -363,11 +364,11 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
     simpa [S]
   let s := Finset.max' S hSne
   have hs : s ∈ S := Finset.max'_mem S hSne
-  simp only [Finset.sep_def, S, Finset.mem_filter, Finset.mem_range] at hs
+  simp only [Finset.sep_def, S, Finset.mem_filter, Finset.mem_range] at hs 
   obtain ⟨hsn1, ⟨a, hsa⟩, ⟨b, hsb⟩⟩ := hs
-  rw [hsa] at hn
+  rw [hsa] at hn 
   obtain ⟨hlts, hlta⟩ := canonically_ordered_comm_semiring.mul_pos.mp hn
-  rw [hsb] at hsa hn hlts
+  rw [hsb] at hsa hn hlts 
   refine' ⟨a, b, hlta, (pow_pos_iff zero_lt_two).mp hlts, hsa.symm, _⟩
   rintro x ⟨y, hy⟩
   rw [Nat.isUnit_iff]
@@ -449,7 +450,7 @@ theorem squarefree_helper_0 {k} (k0 : 0 < k) {p : ℕ} (pp : Nat.Prime p) (h : b
     bit1 (k + 1) ≤ p ∨ bit1 k = p :=
   by
   rcases lt_or_eq_of_le h with ((hp : _ + 1 ≤ _) | hp)
-  · rw [bit1, bit0_eq_two_mul] at hp; change 2 * (_ + 1) ≤ _ at hp
+  · rw [bit1, bit0_eq_two_mul] at hp ; change 2 * (_ + 1) ≤ _ at hp 
     rw [bit1, bit0_eq_two_mul]
     refine' Or.inl (lt_of_le_of_ne hp _); rintro rfl
     exact Nat.not_prime_mul (by decide) (lt_add_of_pos_left _ k0) pp
@@ -505,7 +506,7 @@ theorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1
   have :=
     (ih p pp (dvd_trans hp md)).trans
       (le_trans (Nat.le_of_dvd (lt_of_lt_of_le (by decide) m2) hp) hm)
-  rw [Nat.le_sqrt] at this
+  rw [Nat.le_sqrt] at this 
   exact not_le_of_lt hd this
 #align tactic.norm_num.squarefree_helper_4 Tactic.NormNum.squarefreeHelper_4
 
Diff
@@ -341,7 +341,7 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
       apply hy hz
 #align nat.divisors_filter_squarefree Nat.divisors_filter_squarefree
 
-open BigOperators
+open scoped BigOperators
 
 theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
     {f : ℕ → α} :
Diff
@@ -287,12 +287,6 @@ theorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_factors] <;
 
 open UniqueFactorizationMonoid
 
-/- warning: nat.divisors_filter_squarefree -> Nat.divisors_filter_squarefree is a dubious translation:
-lean 3 declaration is
-  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} (Multiset.{0} Nat) (Finset.val.{0} Nat (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.Squarefree.decidablePred a) (Nat.divisors n))) (Multiset.map.{0, 0} (Finset.{0} Nat) Nat (fun (x : Finset.{0} Nat) => Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat x)) (Finset.val.{0} (Finset.{0} Nat) (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (normalizationMonoidOfUniqueUnits.{0} Nat Nat.cancelCommMonoidWithZero Nat.unique_units) Nat.uniqueFactorizationMonoid n))))))
-but is expected to have type
-  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} (Multiset.{0} Nat) (Finset.val.{0} Nat (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.instDecidablePredNatSquarefreeMonoid a) (Nat.divisors n))) (Multiset.map.{0, 0} (Finset.{0} Nat) Nat (fun (x : Finset.{0} Nat) => Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat x)) (Finset.val.{0} (Finset.{0} Nat) (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (NormalizedGCDMonoid.toNormalizationMonoid.{0} Nat Nat.cancelCommMonoidWithZero instNormalizedGCDMonoidNatCancelCommMonoidWithZero) Nat.instUniqueFactorizationMonoidNatCancelCommMonoidWithZero n))))))
-Case conversion may be inaccurate. Consider using '#align nat.divisors_filter_squarefree Nat.divisors_filter_squarefreeₓ'. -/
 theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
     (n.divisors.filterₓ Squarefree).val =
       (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x =>
@@ -349,12 +343,6 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
 
 open BigOperators
 
-/- warning: nat.sum_divisors_filter_squarefree -> Nat.sum_divisors_filter_squarefree is a dubious translation:
-lean 3 declaration is
-  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (forall {α : Type.{u1}} [_inst_1 : AddCommMonoid.{u1} α] {f : Nat -> α}, Eq.{succ u1} α (Finset.sum.{u1, 0} α Nat _inst_1 (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.Squarefree.decidablePred a) (Nat.divisors n)) (fun (i : Nat) => f i)) (Finset.sum.{u1, 0} α (Finset.{0} Nat) _inst_1 (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (normalizationMonoidOfUniqueUnits.{0} Nat Nat.cancelCommMonoidWithZero Nat.unique_units) Nat.uniqueFactorizationMonoid n))) (fun (i : Finset.{0} Nat) => f (Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat i)))))
-but is expected to have type
-  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (forall {α : Type.{u1}} [_inst_1 : AddCommMonoid.{u1} α] {f : Nat -> α}, Eq.{succ u1} α (Finset.sum.{u1, 0} α Nat _inst_1 (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.instDecidablePredNatSquarefreeMonoid a) (Nat.divisors n)) (fun (i : Nat) => f i)) (Finset.sum.{u1, 0} α (Finset.{0} Nat) _inst_1 (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (NormalizedGCDMonoid.toNormalizationMonoid.{0} Nat Nat.cancelCommMonoidWithZero instNormalizedGCDMonoidNatCancelCommMonoidWithZero) Nat.instUniqueFactorizationMonoidNatCancelCommMonoidWithZero n))) (fun (i : Finset.{0} Nat) => f (Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat i)))))
-Case conversion may be inaccurate. Consider using '#align nat.sum_divisors_filter_squarefree Nat.sum_divisors_filter_squarefreeₓ'. -/
 theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
     {f : ℕ → α} :
     (∑ i in n.divisors.filterₓ Squarefree, f i) =
Diff
@@ -84,10 +84,7 @@ theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :
 theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
     n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) :=
   by
-  refine'
-    ⟨by
-      rintro rfl
-      simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => _⟩
+  refine' ⟨by rintro rfl; simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => _⟩
   by_cases hp : p.prime
   · have h₁ := h _ hp
     rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,
@@ -108,10 +105,7 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
 theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
     Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 :=
   by
-  refine'
-    ⟨fun h => _, by
-      rintro ⟨hn, rfl⟩
-      simpa⟩
+  refine' ⟨fun h => _, by rintro ⟨hn, rfl⟩; simpa⟩
   rcases eq_or_ne n 0 with (rfl | hn₀)
   · simpa [zero_pow hk.bot_lt] using h
   refine' ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => _⟩
@@ -140,9 +134,7 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
   | n, k =>
     if h : n < k * k then none
     else
-      have : Nat.sqrt n + 2 - (k + 2) < Nat.sqrt n + 2 - k :=
-        by
-        rw [Nat.add_sub_add_right]
+      have : Nat.sqrt n + 2 - (k + 2) < Nat.sqrt n + 2 - k := by rw [Nat.add_sub_add_right];
         exact Nat.minFac_lemma n k h
       if k ∣ n then
         let n' := n / k
@@ -183,10 +175,7 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
     (H : MinSqFacProp (n / k) o) : MinSqFacProp n o :=
   by
   have : ∀ p, Prime p → p * p ∣ n → k * (p * p) ∣ n := fun p pp dp =>
-    have :=
-      (coprime_primes pk pp).2 fun e => by
-        subst e
-        contradiction
+    have := (coprime_primes pk pp).2 fun e => by subst e; contradiction
     (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp
   cases' o with d
   · rw [min_sq_fac_prop, squarefree_iff_prime_squarefree] at H⊢
@@ -208,9 +197,7 @@ theorem minSqFacAux_has_prop :
       have := ih p pp (dvd_trans ⟨_, rfl⟩ d)
       have := Nat.mul_le_mul this this
       exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))
-    have k2 : 2 ≤ k := by
-      subst e
-      exact by decide
+    have k2 : 2 ≤ k := by subst e; exact by decide
     have k0 : 0 < k := lt_of_lt_of_le (by decide) k2
     have IH : ∀ n', n' ∣ n → ¬k ∣ n' → min_sq_fac_prop n' (n'.minSqFacAux (k + 2)) :=
       by
@@ -222,15 +209,11 @@ theorem minSqFacAux_has_prop :
         @min_sq_fac_aux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)
           (by simp [e, left_distrib]) fun m m2 d => _
       cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
-      · subst me
-        contradiction
-      apply (Nat.eq_or_lt_of_le ml).resolve_left
-      intro me
-      rw [← me, e] at d
-      change 2 * (i + 2) ∣ n' at d
+      · subst me; contradiction
+      apply (Nat.eq_or_lt_of_le ml).resolve_left; intro me
+      rw [← me, e] at d; change 2 * (i + 2) ∣ n' at d
       have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
-      rw [e] at this
-      exact absurd this (by decide)
+      rw [e] at this; exact absurd this (by decide)
     have pk : k ∣ n → Prime k :=
       by
       refine' fun dk => prime_def_min_fac.2 ⟨k2, le_antisymm (min_fac_le k0) _⟩
@@ -248,39 +231,27 @@ theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) :=
   by
   dsimp only [min_sq_fac]; split_ifs with d2 d4
   · exact ⟨prime_two, (dvd_div_iff d2).1 d4, fun p pp _ => pp.two_le⟩
-  · cases' Nat.eq_zero_or_pos n with n0 n0
-    · subst n0
-      cases d4 (by decide)
+  · cases' Nat.eq_zero_or_pos n with n0 n0; · subst n0; cases d4 (by decide)
     refine' min_sq_fac_prop_div _ prime_two d2 (mt (dvd_div_iff d2).2 d4) _
     refine' min_sq_fac_aux_has_prop 3 (Nat.div_pos (le_of_dvd n0 d2) (by decide)) 0 rfl _
     refine' fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le _)
-    rintro rfl
-    contradiction
-  · cases' Nat.eq_zero_or_pos n with n0 n0
-    · subst n0
-      cases d2 (by decide)
+    rintro rfl; contradiction
+  · cases' Nat.eq_zero_or_pos n with n0 n0; · subst n0; cases d2 (by decide)
     refine' min_sq_fac_aux_has_prop _ n0 0 rfl _
     refine' fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le _)
-    rintro rfl
-    contradiction
+    rintro rfl; contradiction
 #align nat.min_sq_fac_has_prop Nat.minSqFac_has_prop
 -/
 
 #print Nat.minSqFac_prime /-
-theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d :=
-  by
-  have := min_sq_fac_has_prop n
-  rw [h] at this
-  exact this.1
+theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d := by
+  have := min_sq_fac_has_prop n; rw [h] at this; exact this.1
 #align nat.min_sq_fac_prime Nat.minSqFac_prime
 -/
 
 #print Nat.minSqFac_dvd /-
-theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n :=
-  by
-  have := min_sq_fac_has_prop n
-  rw [h] at this
-  exact this.2.1
+theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n := by
+  have := min_sq_fac_has_prop n; rw [h] at this; exact this.2.1
 #align nat.min_sq_fac_dvd Nat.minSqFac_dvd
 -/
 
@@ -300,8 +271,7 @@ theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :
   by
   have := min_sq_fac_has_prop n
   constructor <;> intro H
-  · cases' n.min_sq_fac with d
-    · rfl
+  · cases' n.min_sq_fac with d; · rfl
     cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1
   · rwa [H] at this
 #align nat.squarefree_iff_min_sq_fac Nat.squarefree_iff_minSqFac
@@ -478,8 +448,7 @@ theorem squarefree_bit10 (n : ℕ) (h : SquarefreeHelper n 1) : Squarefree (bit0
     exact Nat.not_two_dvd_bit1 _
   · rw [bit0_eq_two_mul, Nat.mul_div_right _ (by decide : 0 < 2)]
     refine' h (by decide) fun p pp dp => Nat.succ_le_of_lt (lt_of_le_of_ne pp.two_le _)
-    rintro rfl
-    exact Nat.not_two_dvd_bit1 _ dp
+    rintro rfl; exact Nat.not_two_dvd_bit1 _ dp
 #align tactic.norm_num.squarefree_bit10 Tactic.NormNum.squarefree_bit10
 
 theorem squarefree_bit1 (n : ℕ) (h : SquarefreeHelper n 1) : Squarefree (bit1 n) :=
@@ -492,11 +461,9 @@ theorem squarefree_helper_0 {k} (k0 : 0 < k) {p : ℕ} (pp : Nat.Prime p) (h : b
     bit1 (k + 1) ≤ p ∨ bit1 k = p :=
   by
   rcases lt_or_eq_of_le h with ((hp : _ + 1 ≤ _) | hp)
-  · rw [bit1, bit0_eq_two_mul] at hp
-    change 2 * (_ + 1) ≤ _ at hp
+  · rw [bit1, bit0_eq_two_mul] at hp; change 2 * (_ + 1) ≤ _ at hp
     rw [bit1, bit0_eq_two_mul]
-    refine' Or.inl (lt_of_le_of_ne hp _)
-    rintro rfl
+    refine' Or.inl (lt_of_le_of_ne hp _); rintro rfl
     exact Nat.not_prime_mul (by decide) (lt_add_of_pos_left _ k0) pp
   · exact Or.inr hp
 #align tactic.norm_num.squarefree_helper_0 Tactic.NormNum.squarefree_helper_0
@@ -531,24 +498,18 @@ theorem squarefreeHelper_3 (n n' k k' c : ℕ) (e : k + 1 = k') (hn' : bit1 n' *
     by
     refine' Nat.prime_def_minFac.2 ⟨k2, le_antisymm (Nat.minFac_le k0') _⟩
     exact ih _ (Nat.minFac_prime (ne_of_gt k2)) (dvd_trans (Nat.minFac_dvd _) dk)
-  have dkk' : ¬bit1 k ∣ bit1 n' :=
-    by
-    rw [Nat.dvd_iff_mod_eq_zero, hc]
-    exact ne_of_gt c0
+  have dkk' : ¬bit1 k ∣ bit1 n' := by rw [Nat.dvd_iff_mod_eq_zero, hc]; exact ne_of_gt c0
   have dkk : ¬bit1 k * bit1 k ∣ bit1 n := by rwa [← Nat.dvd_div_iff dk, this]
   refine' @Nat.minSqFacProp_div _ _ pk dk dkk none _
-  rw [this]
-  refine' H (Nat.succ_pos _) fun p pp dp => _
+  rw [this]; refine' H (Nat.succ_pos _) fun p pp dp => _
   refine' (squarefree_helper_0 k0 pp (ih p pp <| dvd_trans dp dn')).resolve_right fun e => _
-  subst e
-  contradiction
+  subst e; contradiction
 #align tactic.norm_num.squarefree_helper_3 Tactic.NormNum.squarefreeHelper_3
 
 theorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1 n < k') :
     SquarefreeHelper n k := by
   cases' Nat.eq_zero_or_pos n with h h
-  · subst n
-    exact fun _ _ => squarefree_one
+  · subst n; exact fun _ _ => squarefree_one
   subst e
   refine' fun k0 ih => Irreducible.squarefree (Nat.prime_def_le_sqrt.2 ⟨bit1_lt_bit1.2 h, _⟩)
   intro m m2 hm md
@@ -561,8 +522,7 @@ theorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1
 #align tactic.norm_num.squarefree_helper_4 Tactic.NormNum.squarefreeHelper_4
 
 theorem not_squarefree_mul (a aa b n : ℕ) (ha : a * a = aa) (hb : aa * b = n) (h₁ : 1 < a) :
-    ¬Squarefree n := by
-  rw [← hb, ← ha]
+    ¬Squarefree n := by rw [← hb, ← ha];
   exact fun H => ne_of_gt h₁ (Nat.isUnit_iff.1 <| H _ ⟨_, rfl⟩)
 #align tactic.norm_num.not_squarefree_mul Tactic.NormNum.not_squarefree_mul
 
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
 
 ! This file was ported from Lean 3 source module data.nat.squarefree
-! leanprover-community/mathlib commit 3c1368cac4abd5a5cbe44317ba7e87379d51ed88
+! leanprover-community/mathlib commit 0b7c740e25651db0ba63648fbae9f9d6f941e31b
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -15,6 +15,9 @@ import Mathbin.RingTheory.Int.Basic
 
 /-!
 # Lemmas about squarefreeness of natural numbers
+
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
 A number is squarefree when it is not divisible by any squares except the squares of units.
 
 ## Main Results
Diff
@@ -29,16 +29,21 @@ squarefree, multiplicity
 
 namespace Nat
 
+#print Nat.squarefree_iff_nodup_factors /-
 theorem squarefree_iff_nodup_factors {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔ n.factors.Nodup :=
   by
   rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0, Nat.factors_eq]
   simp
 #align nat.squarefree_iff_nodup_factors Nat.squarefree_iff_nodup_factors
+-/
 
+#print Nat.squarefree_iff_prime_squarefree /-
 theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n :=
   squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩
 #align nat.squarefree_iff_prime_squarefree Nat.squarefree_iff_prime_squarefree
+-/
 
+#print Nat.Squarefree.factorization_le_one /-
 theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :
     n.factorization p ≤ 1 := by
   rcases eq_or_ne n 0 with (rfl | hn')
@@ -52,7 +57,9 @@ theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n)
   · rw [factorization_eq_zero_of_non_prime _ hp]
     exact zero_le_one
 #align nat.squarefree.factorization_le_one Nat.Squarefree.factorization_le_one
+-/
 
+#print Nat.squarefree_of_factorization_le_one /-
 theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) :
     Squarefree n :=
   by
@@ -61,12 +68,16 @@ theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p
   rw [factors_count_eq]
   apply hn'
 #align nat.squarefree_of_factorization_le_one Nat.squarefree_of_factorization_le_one
+-/
 
+#print Nat.squarefree_iff_factorization_le_one /-
 theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :
     Squarefree n ↔ ∀ p, n.factorization p ≤ 1 :=
   ⟨fun p hn => Squarefree.factorization_le_one hn p, squarefree_of_factorization_le_one hn⟩
 #align nat.squarefree_iff_factorization_le_one Nat.squarefree_iff_factorization_le_one
+-/
 
+#print Nat.Squarefree.ext_iff /-
 theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
     n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) :=
   by
@@ -88,7 +99,9 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
       simp only [Nat.one_ne_zero, not_false_iff]
   rw [factorization_eq_zero_of_non_prime _ hp, factorization_eq_zero_of_non_prime _ hp]
 #align nat.squarefree.ext_iff Nat.Squarefree.ext_iff
+-/
 
+#print Nat.squarefree_pow_iff /-
 theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
     Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 :=
   by
@@ -104,7 +117,9 @@ theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
   rw [← sq]
   exact pow_dvd_pow _ this
 #align nat.squarefree_pow_iff Nat.squarefree_pow_iff
+-/
 
+#print Nat.squarefree_and_prime_pow_iff_prime /-
 theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n :=
   by
   refine' Iff.symm ⟨fun hn => ⟨hn.Squarefree, hn.IsPrimePow⟩, _⟩
@@ -113,7 +128,9 @@ theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimeP
   rw [squarefree_pow_iff hp.ne_one hk.ne'] at h
   rwa [h.2, pow_one]
 #align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime
+-/
 
+#print Nat.minSqFacAux /-
 /-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that
   `p^2 ∣ n`. -/
 def minSqFacAux : ℕ → ℕ → Option ℕ
@@ -135,7 +152,9 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
       else min_sq_fac_aux n (k + 2)termination_by'
   ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
 #align nat.min_sq_fac_aux Nat.minSqFacAux
+-/
 
+#print Nat.minSqFac /-
 /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no
   such `p` (that is, `n` is squarefree). See also `squarefree_iff_min_sq_fac`. -/
 def minSqFac (n : ℕ) : Option ℕ :=
@@ -144,7 +163,9 @@ def minSqFac (n : ℕ) : Option ℕ :=
     if 2 ∣ n' then some 2 else minSqFacAux n' 3
   else minSqFacAux n 3
 #align nat.min_sq_fac Nat.minSqFac
+-/
 
+#print Nat.MinSqFacProp /-
 /-- The correctness property of the return value of `min_sq_fac`.
   * If `none`, then `n` is squarefree;
   * If `some d`, then `d` is a minimal square factor of `n` -/
@@ -152,7 +173,9 @@ def MinSqFacProp (n : ℕ) : Option ℕ → Prop
   | none => Squarefree n
   | some d => Prime d ∧ d * d ∣ n ∧ ∀ p, Prime p → p * p ∣ n → d ≤ p
 #align nat.min_sq_fac_prop Nat.MinSqFacProp
+-/
 
+#print Nat.minSqFacProp_div /-
 theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k ∣ n) {o}
     (H : MinSqFacProp (n / k) o) : MinSqFacProp n o :=
   by
@@ -169,7 +192,9 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
     simp only [dvd_div_iff dk] at H2 H3
     exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
+-/
 
+#print Nat.minSqFacAux_has_prop /-
 theorem minSqFacAux_has_prop :
     ∀ {n : ℕ} (k),
       0 < n → ∀ i, k = 2 * i + 3 → (∀ m, Prime m → m ∣ n → k ≤ m) → MinSqFacProp n (minSqFacAux n k)
@@ -213,7 +238,9 @@ theorem minSqFacAux_has_prop :
       exact min_sq_fac_prop_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
     · exact IH n (dvd_refl _) dk termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩
 #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop
+-/
 
+#print Nat.minSqFac_has_prop /-
 theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) :=
   by
   dsimp only [min_sq_fac]; split_ifs with d2 d4
@@ -234,21 +261,27 @@ theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) :=
     rintro rfl
     contradiction
 #align nat.min_sq_fac_has_prop Nat.minSqFac_has_prop
+-/
 
+#print Nat.minSqFac_prime /-
 theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d :=
   by
   have := min_sq_fac_has_prop n
   rw [h] at this
   exact this.1
 #align nat.min_sq_fac_prime Nat.minSqFac_prime
+-/
 
+#print Nat.minSqFac_dvd /-
 theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n :=
   by
   have := min_sq_fac_has_prop n
   rw [h] at this
   exact this.2.1
 #align nat.min_sq_fac_dvd Nat.minSqFac_dvd
+-/
 
+#print Nat.minSqFac_le_of_dvd /-
 theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) :
     d ≤ m := by
   have := min_sq_fac_has_prop n; rw [h] at this
@@ -257,7 +290,9 @@ theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤
     le_trans (this.2.2 _ (min_fac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md))
       (min_fac_le <| lt_of_lt_of_le (by decide) m2)
 #align nat.min_sq_fac_le_of_dvd Nat.minSqFac_le_of_dvd
+-/
 
+#print Nat.squarefree_iff_minSqFac /-
 theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :=
   by
   have := min_sq_fac_has_prop n
@@ -267,15 +302,24 @@ theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :
     cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1
   · rwa [H] at this
 #align nat.squarefree_iff_min_sq_fac Nat.squarefree_iff_minSqFac
+-/
 
 instance : DecidablePred (Squarefree : ℕ → Prop) := fun n =>
   decidable_of_iff' _ squarefree_iff_minSqFac
 
+#print Nat.squarefree_two /-
 theorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_factors] <;> norm_num
 #align nat.squarefree_two Nat.squarefree_two
+-/
 
 open UniqueFactorizationMonoid
 
+/- warning: nat.divisors_filter_squarefree -> Nat.divisors_filter_squarefree is a dubious translation:
+lean 3 declaration is
+  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} (Multiset.{0} Nat) (Finset.val.{0} Nat (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.Squarefree.decidablePred a) (Nat.divisors n))) (Multiset.map.{0, 0} (Finset.{0} Nat) Nat (fun (x : Finset.{0} Nat) => Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat x)) (Finset.val.{0} (Finset.{0} Nat) (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (normalizationMonoidOfUniqueUnits.{0} Nat Nat.cancelCommMonoidWithZero Nat.unique_units) Nat.uniqueFactorizationMonoid n))))))
+but is expected to have type
+  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} (Multiset.{0} Nat) (Finset.val.{0} Nat (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.instDecidablePredNatSquarefreeMonoid a) (Nat.divisors n))) (Multiset.map.{0, 0} (Finset.{0} Nat) Nat (fun (x : Finset.{0} Nat) => Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat x)) (Finset.val.{0} (Finset.{0} Nat) (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (NormalizedGCDMonoid.toNormalizationMonoid.{0} Nat Nat.cancelCommMonoidWithZero instNormalizedGCDMonoidNatCancelCommMonoidWithZero) Nat.instUniqueFactorizationMonoidNatCancelCommMonoidWithZero n))))))
+Case conversion may be inaccurate. Consider using '#align nat.divisors_filter_squarefree Nat.divisors_filter_squarefreeₓ'. -/
 theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
     (n.divisors.filterₓ Squarefree).val =
       (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x =>
@@ -332,6 +376,12 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
 
 open BigOperators
 
+/- warning: nat.sum_divisors_filter_squarefree -> Nat.sum_divisors_filter_squarefree is a dubious translation:
+lean 3 declaration is
+  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (forall {α : Type.{u1}} [_inst_1 : AddCommMonoid.{u1} α] {f : Nat -> α}, Eq.{succ u1} α (Finset.sum.{u1, 0} α Nat _inst_1 (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.Squarefree.decidablePred a) (Nat.divisors n)) (fun (i : Nat) => f i)) (Finset.sum.{u1, 0} α (Finset.{0} Nat) _inst_1 (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (normalizationMonoidOfUniqueUnits.{0} Nat Nat.cancelCommMonoidWithZero Nat.unique_units) Nat.uniqueFactorizationMonoid n))) (fun (i : Finset.{0} Nat) => f (Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat i)))))
+but is expected to have type
+  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (forall {α : Type.{u1}} [_inst_1 : AddCommMonoid.{u1} α] {f : Nat -> α}, Eq.{succ u1} α (Finset.sum.{u1, 0} α Nat _inst_1 (Finset.filter.{0} Nat (Squarefree.{0} Nat Nat.monoid) (fun (a : Nat) => Nat.instDecidablePredNatSquarefreeMonoid a) (Nat.divisors n)) (fun (i : Nat) => f i)) (Finset.sum.{u1, 0} α (Finset.{0} Nat) _inst_1 (Finset.powerset.{0} Nat (Multiset.toFinset.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (UniqueFactorizationMonoid.normalizedFactors.{0} Nat Nat.cancelCommMonoidWithZero (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (NormalizedGCDMonoid.toNormalizationMonoid.{0} Nat Nat.cancelCommMonoidWithZero instNormalizedGCDMonoidNatCancelCommMonoidWithZero) Nat.instUniqueFactorizationMonoidNatCancelCommMonoidWithZero n))) (fun (i : Finset.{0} Nat) => f (Multiset.prod.{0} Nat Nat.commMonoid (Finset.val.{0} Nat i)))))
+Case conversion may be inaccurate. Consider using '#align nat.sum_divisors_filter_squarefree Nat.sum_divisors_filter_squarefreeₓ'. -/
 theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
     {f : ℕ → α} :
     (∑ i in n.divisors.filterₓ Squarefree, f i) =
@@ -341,6 +391,7 @@ theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [A
     Finset.sum_eq_multiset_sum]
 #align nat.sum_divisors_filter_squarefree Nat.sum_divisors_filter_squarefree
 
+#print Nat.sq_mul_squarefree_of_pos /-
 theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
     ∃ a b : ℕ, 0 < a ∧ 0 < b ∧ b ^ 2 * a = n ∧ Squarefree a :=
   by
@@ -367,14 +418,18 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
         (one_lt_pow 2 x zero_lt_two (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
     rw [mul_pow]
 #align nat.sq_mul_squarefree_of_pos Nat.sq_mul_squarefree_of_pos
+-/
 
+#print Nat.sq_mul_squarefree_of_pos' /-
 theorem sq_mul_squarefree_of_pos' {n : ℕ} (h : 0 < n) :
     ∃ a b : ℕ, (b + 1) ^ 2 * (a + 1) = n ∧ Squarefree (a + 1) :=
   by
   obtain ⟨a₁, b₁, ha₁, hb₁, hab₁, hab₂⟩ := sq_mul_squarefree_of_pos h
   refine' ⟨a₁.pred, b₁.pred, _, _⟩ <;> simpa only [add_one, succ_pred_eq_of_pos, ha₁, hb₁]
 #align nat.sq_mul_squarefree_of_pos' Nat.sq_mul_squarefree_of_pos'
+-/
 
+#print Nat.sq_mul_squarefree /-
 theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefree a :=
   by
   cases n
@@ -382,7 +437,9 @@ theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefre
   · obtain ⟨a, b, -, -, h₁, h₂⟩ := sq_mul_squarefree_of_pos (succ_pos n)
     exact ⟨a, b, h₁, h₂⟩
 #align nat.sq_mul_squarefree Nat.sq_mul_squarefree
+-/
 
+#print Nat.squarefree_mul /-
 /-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`
 and generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and
 `squarefree.of_mul_right` above for auxiliary lemmas. -/
@@ -393,6 +450,7 @@ theorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :
   refine' ball_congr fun p hp => _
   simp only [hmn.is_prime_pow_dvd_mul (hp.is_prime_pow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
+-/
 
 end Nat
 
Diff
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
 
 ! This file was ported from Lean 3 source module data.nat.squarefree
-! leanprover-community/mathlib commit 10b4e499f43088dd3bb7b5796184ad5216648ab1
+! leanprover-community/mathlib commit 3c1368cac4abd5a5cbe44317ba7e87379d51ed88
 ! Please do not edit these lines, except to modify the commit id
 ! if you have ported upstream changes.
 -/
@@ -576,7 +576,8 @@ unsafe def prove_squarefree (en : expr) (n : ℕ) : tactic expr :=
 /-- Evaluates the `squarefree` predicate on naturals. -/
 @[norm_num]
 unsafe def eval_squarefree : expr → tactic (expr × expr)
-  | q(Squarefree ($(e) : ℕ)) => do
+  | q(@Squarefree ℕ $(inst) $(e)) => do
+    is_def_eq inst q(Nat.monoid)
     let n ← e.toNat
     match n with
       | 0 => false_intro q(@not_squarefree_zero ℕ _ _)
Diff
@@ -363,8 +363,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   refine' lt_le_antisymm _ (Finset.le_max' S ((b * x) ^ 2) _)
   · simp_rw [S, hsa, Finset.sep_def, Finset.mem_filter, Finset.mem_range]
     refine' ⟨lt_succ_iff.mpr (le_of_dvd hn _), _, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring
-  · convert
-      lt_mul_of_one_lt_right hlts
+  · convert lt_mul_of_one_lt_right hlts
         (one_lt_pow 2 x zero_lt_two (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
     rw [mul_pow]
 #align nat.sq_mul_squarefree_of_pos Nat.sq_mul_squarefree_of_pos

Changes in mathlib4

mathlib3
mathlib4
chore: adapt to multiple goal linter 3 (#12372)

A PR analogous to #12338 and #12361: reformatting proofs following the multiple goals linter of #12339.

Diff
@@ -309,12 +309,12 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
     apply UniqueFactorizationMonoid.factors_unique _ _ (associated_iff_eq.2 h)
     · intro z hz
       apply irreducible_of_normalized_factor z
-      rw [← Multiset.mem_toFinset]
-      apply hx hz
+      · rw [← Multiset.mem_toFinset]
+        apply hx hz
     · intro z hz
       apply irreducible_of_normalized_factor z
-      rw [← Multiset.mem_toFinset]
-      apply hy hz
+      · rw [← Multiset.mem_toFinset]
+        apply hy hz
 #align nat.divisors_filter_squarefree Nat.divisors_filter_squarefree
 
 open BigOperators
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
@@ -272,12 +272,12 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
         x.val.prod := by
   rw [(Finset.nodup _).ext ((Finset.nodup _).map_on _)]
   · intro a
-    simp only [Multiset.mem_filter, id.def, Multiset.mem_map, Finset.filter_val, ← Finset.mem_def,
+    simp only [Multiset.mem_filter, id, Multiset.mem_map, Finset.filter_val, ← Finset.mem_def,
       mem_divisors]
     constructor
     · rintro ⟨⟨an, h0⟩, hsq⟩
       use (UniqueFactorizationMonoid.normalizedFactors a).toFinset
-      simp only [id.def, Finset.mem_powerset]
+      simp only [id, Finset.mem_powerset]
       rcases an with ⟨b, rfl⟩
       rw [mul_ne_zero_iff] at h0
       rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq
chore: remove more bex and ball from lemma names (#11615)

Follow-up to #10816.

Remaining places containing such lemmas are

  • Option.bex_ne_none and Option.ball_ne_none: defined in Lean core
  • Nat.decidableBallLT and Nat.decidableBallLE: defined in Lean core
  • bef_def is still used in a number of places and could be renamed
  • BAll.imp_{left,right}, BEx.imp_{left,right}, BEx.intro and BEx.elim

I only audited the first ~150 lemmas mentioning "ball"; too many lemmas named after Metric.ball/openBall/closedBall.

Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>

Diff
@@ -376,7 +376,7 @@ and generalizes to arbitrary commutative monoids. See `Squarefree.of_mul_left` a
 theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n := by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
-  refine' ball_congr fun p hp => _
+  refine' forall₂_congr fun p hp => _
   simp only [hmn.isPrimePow_dvd_mul (hp.isPrimePow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
 
chore: avoid Ne.def (adaptation for nightly-2024-03-27) (#11801)
Diff
@@ -287,7 +287,7 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
     · rintro ⟨s, hs, rfl⟩
       rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs
       have hs0 : s.val.prod ≠ 0 := by
-        rw [Ne.def, Multiset.prod_eq_zero_iff]
+        rw [Ne, Multiset.prod_eq_zero_iff]
         intro con
         apply
           not_irreducible_zero
chore: Reduce scope of LinearOrderedCommGroupWithZero (#11716)

Reconstitute the file Algebra.Order.Monoid.WithZero from three files:

  • Algebra.Order.Monoid.WithZero.Defs
  • Algebra.Order.Monoid.WithZero.Basic
  • Algebra.Order.WithZero

Avoid importing it in many files. Most uses were just to get le_zero_iff to work on Nat.

Before pre_11716

After post_11716

Diff
@@ -83,7 +83,7 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
       hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁
     have h₂ := hn.natFactorization_le_one p
     have h₃ := hm.natFactorization_le_one p
-    rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃
+    rw [Nat.le_add_one_iff, Nat.le_zero] at h₂ h₃
     cases' h₂ with h₂ h₂
     · rwa [h₂, eq_comm, ← h₁]
     · rw [h₂, h₃.resolve_left]
chore(Data/Nat): Use Std lemmas (#11661)

Move basic Nat lemmas from Data.Nat.Order.Basic and Data.Nat.Pow to Data.Nat.Defs. Most proofs need adapting, but that's easily solved by replacing the general mathlib lemmas by the new Std Nat-specific lemmas and using omega.

Other changes

  • Move the last few lemmas left in Data.Nat.Pow to Algebra.GroupPower.Order
  • Move the deprecated aliases from Data.Nat.Pow to Algebra.GroupPower.Order
  • Move the bit/bit0/bit1 lemmas from Data.Nat.Order.Basic to Data.Nat.Bits
  • Fix some fallout from not importing Data.Nat.Order.Basic anymore
  • Add a few Nat-specific lemmas to help fix the fallout (look for nolint simpNF)
  • Turn Nat.mul_self_le_mul_self_iff and Nat.mul_self_lt_mul_self_iff around (they were misnamed)
  • Make more arguments to Nat.one_lt_pow implicit
Diff
@@ -350,7 +350,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   refine' Nat.lt_le_asymm _ (Finset.le_max' S ((b * x) ^ 2) _)
   -- Porting note: these two goals were in the opposite order in Lean 3
   · convert lt_mul_of_one_lt_right hlts
-      (one_lt_pow 2 x two_ne_zero (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
+      (one_lt_pow two_ne_zero (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
       using 1
     rw [mul_pow]
   · simp_rw [S, hsa, Finset.mem_filter, Finset.mem_range]
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
@@ -353,7 +353,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
       (one_lt_pow 2 x two_ne_zero (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
       using 1
     rw [mul_pow]
-  · simp_rw [hsa, Finset.mem_filter, Finset.mem_range]
+  · simp_rw [S, hsa, Finset.mem_filter, Finset.mem_range]
     refine' ⟨Nat.lt_succ_iff.mpr (le_of_dvd hn _), _, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring
 #align nat.sq_mul_squarefree_of_pos Nat.sq_mul_squarefree_of_pos
 
refactor: optimize proofs with omega (#11093)

I ran tryAtEachStep on all files under Mathlib to find all locations where omega succeeds. For each that was a linarith without an only, I tried replacing it with omega, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow aesops along the way.

Diff
@@ -162,7 +162,6 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
     exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
 
---Porting note: I had to replace two uses of `by decide` by `linarith`.
 theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
     (ih : ∀ m, Prime m → m ∣ n → k ≤ m) : MinSqFacProp n (minSqFacAux n k) := by
   rw [minSqFacAux]
@@ -171,9 +170,7 @@ theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
     have := ih p pp (dvd_trans ⟨_, rfl⟩ d)
     have := Nat.mul_le_mul this this
     exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))
-  have k2 : 2 ≤ k := by
-    subst e
-    linarith
+  have k2 : 2 ≤ k := by omega
   have k0 : 0 < k := lt_of_lt_of_le (by decide) k2
   have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by
     intro n' nd' nk
@@ -192,7 +189,7 @@ theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
     change 2 * (i + 2) ∣ n' at d
     have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
     rw [e] at this
-    exact absurd this (by linarith)
+    exact absurd this (by omega)
   have pk : k ∣ n → Prime k := by
     refine' fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) _⟩
     exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk)
chore: prepare Lean version bump with explicit simp (#10999)

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

Diff
@@ -338,10 +338,10 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   have hSne : S.Nonempty := by
     use 1
     have h1 : 0 < n ∧ ∃ x : ℕ, 1 = x ^ 2 := ⟨hn, ⟨1, (one_pow 2).symm⟩⟩
-    simp [h1]
+    simp [S, h1]
   let s := Finset.max' S hSne
   have hs : s ∈ S := Finset.max'_mem S hSne
-  simp only [Finset.mem_filter, Finset.mem_range] at hs
+  simp only [S, Finset.mem_filter, Finset.mem_range] at hs
   obtain ⟨-, ⟨a, hsa⟩, ⟨b, hsb⟩⟩ := hs
   rw [hsa] at hn
   obtain ⟨hlts, hlta⟩ := CanonicallyOrderedCommSemiring.mul_pos.mp hn
chore: bump dependencies (#10315)

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

Diff
@@ -357,7 +357,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
       using 1
     rw [mul_pow]
   · simp_rw [hsa, Finset.mem_filter, Finset.mem_range]
-    refine' ⟨lt_succ_iff.mpr (le_of_dvd hn _), _, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring
+    refine' ⟨Nat.lt_succ_iff.mpr (le_of_dvd hn _), _, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring
 #align nat.sq_mul_squarefree_of_pos Nat.sq_mul_squarefree_of_pos
 
 theorem sq_mul_squarefree_of_pos' {n : ℕ} (h : 0 < n) :
feat: a polynomial over a perfect field is separable iff it is square-free (#10170)

Yet another small step toward Jordan-Chevalley-Dunford.

This was far more work than expected, partly because of missing API for Squarefree, and partly because the definition IsCoprime is the wrong concept for unique factorization domains.

Diff
@@ -3,7 +3,7 @@ Copyright (c) 2020 Aaron Anderson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
 -/
-import Mathlib.Algebra.Squarefree
+import Mathlib.Algebra.Squarefree.Basic
 import Mathlib.Data.Nat.Factorization.PrimePow
 import Mathlib.RingTheory.Int.Basic
 
chore: move to v4.6.0-rc1, merging adaptations from bump/v4.6.0 (#10176)

Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>

Diff
@@ -126,7 +126,7 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
         lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) k) this
         if k ∣ n' then some k else minSqFacAux n' (k + 2)
       else minSqFacAux n (k + 2)
-termination_by _ n k => sqrt n + 2 - k
+termination_by n k => sqrt n + 2 - k
 #align nat.min_sq_fac_aux Nat.minSqFacAux
 
 /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no
@@ -201,7 +201,7 @@ theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
   · specialize IH (n / k) (div_dvd_of_dvd dk) dkk
     exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
   · exact IH n (dvd_refl _) dk
-termination_by _ => n.sqrt + 2 - k
+termination_by n.sqrt + 2 - k
 #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop
 
 theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by
feat: The support of f ^ n (#9617)

This involves moving lemmas from Algebra.GroupPower.Ring to Algebra.GroupWithZero.Basic and changing some 0 < n assumptions to n ≠ 0.

From LeanAPAP

Diff
@@ -96,7 +96,7 @@ theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
     Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 := by
   refine' ⟨fun h => _, by rintro ⟨hn, rfl⟩; simpa⟩
   rcases eq_or_ne n 0 with (rfl | -)
-  · simp [zero_pow hk.bot_lt] at h
+  · simp [zero_pow hk] at h
   refine' ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => _⟩
   have : 2 ≤ k := k.two_le_iff.mpr ⟨hk, h₁⟩
   apply hn (Nat.isUnit_iff.1 (h _ _))
@@ -346,7 +346,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   rw [hsa] at hn
   obtain ⟨hlts, hlta⟩ := CanonicallyOrderedCommSemiring.mul_pos.mp hn
   rw [hsb] at hsa hn hlts
-  refine' ⟨a, b, hlta, (pow_pos_iff zero_lt_two).mp hlts, hsa.symm, _⟩
+  refine' ⟨a, b, hlta, (pow_pos_iff two_ne_zero).mp hlts, hsa.symm, _⟩
   rintro x ⟨y, hy⟩
   rw [Nat.isUnit_iff]
   by_contra hx
chore: reduce imports (#9830)

This uses the improved shake script from #9772 to reduce imports across mathlib. The corresponding noshake.json file has been added to #9772.

Co-authored-by: Mario Carneiro <di.gama@gmail.com>

Diff
@@ -5,7 +5,6 @@ Authors: Aaron Anderson
 -/
 import Mathlib.Algebra.Squarefree
 import Mathlib.Data.Nat.Factorization.PrimePow
-import Mathlib.Data.Nat.PrimeNormNum
 import Mathlib.RingTheory.Int.Basic
 
 #align_import data.nat.squarefree from "leanprover-community/mathlib"@"3c1368cac4abd5a5cbe44317ba7e87379d51ed88"
chore(*): replace $ with <| (#9319)

See Zulip thread for the discussion.

Diff
@@ -60,7 +60,7 @@ theorem _root_.Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squa
 
 lemma factorization_eq_one_of_squarefree (hn : Squarefree n) (hp : p.Prime) (hpn : p ∣ n) :
     factorization n p = 1 :=
-  (hn.natFactorization_le_one _).antisymm $ (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn
+  (hn.natFactorization_le_one _).antisymm <| (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn
 
 theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) :
     Squarefree n := by
@@ -389,12 +389,12 @@ theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.Copri
 
 theorem squarefree_mul_iff {m n : ℕ} :
     Squarefree (m * n) ↔ m.Coprime n ∧ Squarefree m ∧ Squarefree n :=
-  ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
+  ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul <| coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
 lemma coprime_div_gcd_of_squarefree (hm : Squarefree m) (hn : n ≠ 0) : Coprime (m / gcd m n) n := by
   have : Coprime (m / gcd m n) (gcd m n) :=
-    coprime_of_squarefree_mul $ by simpa [Nat.div_mul_cancel, gcd_dvd_left]
+    coprime_of_squarefree_mul <| by simpa [Nat.div_mul_cancel, gcd_dvd_left]
   simpa [Nat.div_mul_cancel, gcd_dvd_right] using
     (coprime_div_gcd_div_gcd (m := m) (gcd_ne_zero_right hn).bot_lt).mul_right this
 
@@ -414,14 +414,14 @@ lemma primeFactors_div_gcd (hm : Squarefree m) (hn : n ≠ 0) :
     primeFactors (m / m.gcd n) = primeFactors m \ primeFactors n := by
   ext p
   have : m / m.gcd n ≠ 0 :=
-    (Nat.div_ne_zero_iff $ gcd_ne_zero_right hn).2 $ gcd_le_left _ hm.ne_zero.bot_lt
+    (Nat.div_ne_zero_iff <| gcd_ne_zero_right hn).2 <| gcd_le_left _ hm.ne_zero.bot_lt
   simp only [mem_primeFactors, ne_eq, this, not_false_eq_true, and_true, not_and, mem_sdiff,
     hm.ne_zero, hn, dvd_div_iff (gcd_dvd_left _ _)]
-  refine ⟨fun hp ↦ ⟨⟨hp.1, dvd_of_mul_left_dvd hp.2⟩, fun _ hpn ↦ hp.1.not_unit $ hm _ $
+  refine ⟨fun hp ↦ ⟨⟨hp.1, dvd_of_mul_left_dvd hp.2⟩, fun _ hpn ↦ hp.1.not_unit <| hm _ <|
     (mul_dvd_mul_right (dvd_gcd (dvd_of_mul_left_dvd hp.2) hpn) _).trans hp.2⟩, fun hp ↦
       ⟨hp.1.1, Coprime.mul_dvd_of_dvd_of_dvd ?_ (gcd_dvd_left _ _) hp.1.2⟩⟩
   rw [coprime_comm, hp.1.1.coprime_iff_not_dvd]
-  exact fun hpn ↦ hp.2 hp.1.1 $ hpn.trans $ gcd_dvd_right _ _
+  exact fun hpn ↦ hp.2 hp.1.1 <| hpn.trans <| gcd_dvd_right _ _
 
 lemma prod_primeFactors_invOn_squarefree :
     Set.InvOn (fun n : ℕ ↦ (factorization n).support) (fun s ↦ ∏ p in s, p)
@@ -431,7 +431,7 @@ lemma prod_primeFactors_invOn_squarefree :
 theorem prod_primeFactors_sdiff_of_squarefree {n : ℕ} (hn : Squarefree n) {t : Finset ℕ}
     (ht : t ⊆ n.primeFactors) :
     ∏ a in (n.primeFactors \ t), a = n / ∏ a in t, a := by
-  refine symm $ Nat.div_eq_of_eq_mul_left (Finset.prod_pos
+  refine symm <| Nat.div_eq_of_eq_mul_left (Finset.prod_pos
     fun p hp => (prime_of_mem_factors (List.mem_toFinset.mp (ht hp))).pos) ?_
   rw [Finset.prod_sdiff ht, prod_primeFactors_of_squarefree hn]
 
feat: define prodPrimeFactors as an ArithmeticFunction (#6662)

Define the arithmetic function $n \mapsto \prod_{p \mid n} f(p)$. This PR further proves that it's multiplicative and relates it to Dirichlet convolution. Finally it proves two identities that can be applied in a context where you're not working exclusively with ArithmeticFunctions

This construction was mentioned on zulip

Co-authored-by: Arend Mellendijk <FLDutchmann@users.noreply.github.com>

Diff
@@ -428,6 +428,13 @@ lemma prod_primeFactors_invOn_squarefree :
       {s | ∀ p ∈ s, p.Prime} {n | Squarefree n} :=
   ⟨fun _s ↦ primeFactors_prod, fun _n ↦ prod_primeFactors_of_squarefree⟩
 
+theorem prod_primeFactors_sdiff_of_squarefree {n : ℕ} (hn : Squarefree n) {t : Finset ℕ}
+    (ht : t ⊆ n.primeFactors) :
+    ∏ a in (n.primeFactors \ t), a = n / ∏ a in t, a := by
+  refine symm $ Nat.div_eq_of_eq_mul_left (Finset.prod_pos
+    fun p hp => (prime_of_mem_factors (List.mem_toFinset.mp (ht hp))).pos) ?_
+  rw [Finset.prod_sdiff ht, prod_primeFactors_of_squarefree hn]
+
 end Nat
 
 -- Porting note: comment out NormNum tactic, to be moved to another file.
chore: Remove superfluous lemma that uses n.factors.toFinset (#9248)

I added prod_factors_toFinset_of_squarefree before primeFactors existed. I suspect it was missed during the refactor.

Diff
@@ -399,10 +399,8 @@ lemma coprime_div_gcd_of_squarefree (hm : Squarefree m) (hn : n ≠ 0) : Coprime
     (coprime_div_gcd_div_gcd (m := m) (gcd_ne_zero_right hn).bot_lt).mul_right this
 
 lemma prod_primeFactors_of_squarefree (hn : Squarefree n) : ∏ p in n.primeFactors, p = n := by
-  convert factorization_prod_pow_eq_self hn.ne_zero
-  refine prod_congr rfl fun p hp ↦ ?_
-  simp only [support_factorization, toFinset_factors, mem_primeFactors_of_ne_zero hn.ne_zero] at hp
-  simp_rw [factorization_eq_one_of_squarefree hn hp.1 hp.2, pow_one]
+  rw [← toFinset_factors, List.prod_toFinset _ hn.nodup_factors, List.map_id',
+    Nat.prod_factors hn.ne_zero]
 
 lemma primeFactors_prod (hs : ∀ p ∈ s, p.Prime) : primeFactors (∏ p in s, p) = s := by
   have hn : ∏ p in s, p ≠ 0 := prod_ne_zero_iff.2 fun p hp ↦ (hs _ hp).ne_zero
@@ -430,10 +428,6 @@ lemma prod_primeFactors_invOn_squarefree :
       {s | ∀ p ∈ s, p.Prime} {n | Squarefree n} :=
   ⟨fun _s ↦ primeFactors_prod, fun _n ↦ prod_primeFactors_of_squarefree⟩
 
-theorem prod_factors_toFinset_of_squarefree {n : ℕ} (hn : Squarefree n) :
-    ∏ p in n.factors.toFinset, p = n := by
-  rw [List.prod_toFinset _ hn.nodup_factors, List.map_id', Nat.prod_factors hn.ne_zero]
-
 end Nat
 
 -- Porting note: comment out NormNum tactic, to be moved to another file.
chore: remove uses of cases' (#9171)

I literally went through and regex'd some uses of cases', replacing them with rcases; this is meant to be a low effort PR as I hope that tools can do this in the future.

rcases is an easier replacement than cases, though with better tools we could in future do a second pass converting simple rcases added here (and existing ones) to cases.

Diff
@@ -184,7 +184,7 @@ theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
         lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h)
       @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)
         (by simp [e, left_distrib]) fun m m2 d => _
-    cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
+    rcases Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me | ml
     · subst me
       contradiction
     apply (Nat.eq_or_lt_of_le ml).resolve_left
@@ -208,7 +208,7 @@ termination_by _ => n.sqrt + 2 - k
 theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by
   dsimp only [minSqFac]; split_ifs with d2 d4
   · exact ⟨prime_two, (dvd_div_iff d2).1 d4, fun p pp _ => pp.two_le⟩
-  · cases' Nat.eq_zero_or_pos n with n0 n0
+  · rcases Nat.eq_zero_or_pos n with n0 | n0
     · subst n0
       cases d4 (by decide)
     refine' minSqFacProp_div _ prime_two d2 (mt (dvd_div_iff d2).2 d4) _
@@ -216,7 +216,7 @@ theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by
     refine' fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le _)
     rintro rfl
     contradiction
-  · cases' Nat.eq_zero_or_pos n with n0 n0
+  · rcases Nat.eq_zero_or_pos n with n0 | n0
     · subst n0
       cases d2 (by decide)
     refine' minSqFacAux_has_prop _ n0 0 rfl _
@@ -522,7 +522,7 @@ theorem squarefreeHelper_3 (n n' k k' c : ℕ) (e : k + 1 = k') (hn' : bit1 n' *
 
 theorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1 n < k') :
     SquarefreeHelper n k := by
-  cases' Nat.eq_zero_or_pos n with h h
+  rcases Nat.eq_zero_or_pos n with h | h
   · subst n
     exact fun _ _ => squarefree_one
   subst e
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
@@ -354,7 +354,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   refine' Nat.lt_le_asymm _ (Finset.le_max' S ((b * x) ^ 2) _)
   -- Porting note: these two goals were in the opposite order in Lean 3
   · convert lt_mul_of_one_lt_right hlts
-      (one_lt_pow 2 x zero_lt_two (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
+      (one_lt_pow 2 x two_ne_zero (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
       using 1
     rw [mul_pow]
   · simp_rw [hsa, Finset.mem_filter, Finset.mem_range]
chore: bump Std dependency to leanprover/std4#432 (#9094)

This covers these changes in Std: https://github.com/leanprover/std4/compare/6b4cf96c89e53cfcd73350bbcd90333a051ff4f0...[9dd24a34](https://github.com/leanprover-community/mathlib/commit/9dd24a3493cceefa2bede383f21e4ef548990b68)

  • Int.ofNat_natAbs_eq_of_nonneg has become Int.natAbs_of_nonneg (and one argument has become implicit)
  • List.map_id'' and List.map_id' have exchanged names. (Yay naming things using primes!)
  • Some meta functions have moved to Std and can be deleted here.

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

Diff
@@ -432,7 +432,7 @@ lemma prod_primeFactors_invOn_squarefree :
 
 theorem prod_factors_toFinset_of_squarefree {n : ℕ} (hn : Squarefree n) :
     ∏ p in n.factors.toFinset, p = n := by
-  rw [List.prod_toFinset _ hn.nodup_factors, List.map_id'', Nat.prod_factors hn.ne_zero]
+  rw [List.prod_toFinset _ hn.nodup_factors, List.map_id', Nat.prod_factors hn.ne_zero]
 
 end Nat
 
chore: space after (#8178)

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

Diff
@@ -410,7 +410,7 @@ lemma primeFactors_prod (hs : ∀ p ∈ s, p.Prime) : primeFactors (∏ p in s,
   rw [mem_primeFactors_of_ne_zero hn, and_congr_right (fun hp ↦ hp.prime.dvd_finset_prod_iff _)]
   refine' ⟨_, fun hp ↦ ⟨hs _ hp, _, hp, dvd_rfl⟩⟩
   rintro ⟨hp, q, hq, hpq⟩
-  rwa [←((hs _ hq).dvd_iff_eq hp.ne_one).1 hpq]
+  rwa [← ((hs _ hq).dvd_iff_eq hp.ne_one).1 hpq]
 
 lemma primeFactors_div_gcd (hm : Squarefree m) (hn : n ≠ 0) :
     primeFactors (m / m.gcd n) = primeFactors m \ primeFactors n := by
feat: m/gcd m n and n coprime if m squarefree (#8578)
Diff
@@ -392,6 +392,12 @@ theorem squarefree_mul_iff {m n : ℕ} :
   ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
+lemma coprime_div_gcd_of_squarefree (hm : Squarefree m) (hn : n ≠ 0) : Coprime (m / gcd m n) n := by
+  have : Coprime (m / gcd m n) (gcd m n) :=
+    coprime_of_squarefree_mul $ by simpa [Nat.div_mul_cancel, gcd_dvd_left]
+  simpa [Nat.div_mul_cancel, gcd_dvd_right] using
+    (coprime_div_gcd_div_gcd (m := m) (gcd_ne_zero_right hn).bot_lt).mul_right this
+
 lemma prod_primeFactors_of_squarefree (hn : Squarefree n) : ∏ p in n.primeFactors, p = n := by
   convert factorization_prod_pow_eq_self hn.ne_zero
   refine prod_congr rfl fun p hp ↦ ?_
feat: Squarefree lemmas for Nat (#8323)
Diff
@@ -23,6 +23,7 @@ squarefree, multiplicity
 
 -/
 
+open Finset
 
 namespace Nat
 
@@ -37,12 +38,13 @@ theorem Squarefree.nodup_factors {n : ℕ} (hn : Squarefree n) : n.factors.Nodup
   (Nat.squarefree_iff_nodup_factors hn.ne_zero).mp hn
 
 namespace Nat
+variable {s : Finset ℕ} {m n p : ℕ}
 
 theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n :=
   squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩
 #align nat.squarefree_iff_prime_squarefree Nat.squarefree_iff_prime_squarefree
 
-theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :
+theorem _root_.Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :
     n.factorization p ≤ 1 := by
   rcases eq_or_ne n 0 with (rfl | hn')
   · simp
@@ -54,7 +56,11 @@ theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n)
     exact mod_cast this
   · rw [factorization_eq_zero_of_non_prime _ hp]
     exact zero_le_one
-#align nat.squarefree.factorization_le_one Nat.Squarefree.factorization_le_one
+#align nat.squarefree.factorization_le_one Squarefree.natFactorization_le_one
+
+lemma factorization_eq_one_of_squarefree (hn : Squarefree n) (hp : p.Prime) (hpn : p ∣ n) :
+    factorization n p = 1 :=
+  (hn.natFactorization_le_one _).antisymm $ (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn
 
 theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) :
     Squarefree n := by
@@ -66,7 +72,7 @@ theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p
 
 theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :
     Squarefree n ↔ ∀ p, n.factorization p ≤ 1 :=
-  ⟨fun p hn => Squarefree.factorization_le_one hn p, squarefree_of_factorization_le_one hn⟩
+  ⟨fun hn => hn.natFactorization_le_one, squarefree_of_factorization_le_one hn⟩
 #align nat.squarefree_iff_factorization_le_one Nat.squarefree_iff_factorization_le_one
 
 theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
@@ -76,8 +82,8 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
   · have h₁ := h _ hp
     rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,
       hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁
-    have h₂ := Squarefree.factorization_le_one p hn
-    have h₃ := Squarefree.factorization_le_one p hm
+    have h₂ := hn.natFactorization_le_one p
+    have h₃ := hm.natFactorization_le_one p
     rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃
     cases' h₂ with h₂ h₂
     · rwa [h₂, eq_comm, ← h₁]
@@ -386,6 +392,38 @@ theorem squarefree_mul_iff {m n : ℕ} :
   ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
+lemma prod_primeFactors_of_squarefree (hn : Squarefree n) : ∏ p in n.primeFactors, p = n := by
+  convert factorization_prod_pow_eq_self hn.ne_zero
+  refine prod_congr rfl fun p hp ↦ ?_
+  simp only [support_factorization, toFinset_factors, mem_primeFactors_of_ne_zero hn.ne_zero] at hp
+  simp_rw [factorization_eq_one_of_squarefree hn hp.1 hp.2, pow_one]
+
+lemma primeFactors_prod (hs : ∀ p ∈ s, p.Prime) : primeFactors (∏ p in s, p) = s := by
+  have hn : ∏ p in s, p ≠ 0 := prod_ne_zero_iff.2 fun p hp ↦ (hs _ hp).ne_zero
+  ext p
+  rw [mem_primeFactors_of_ne_zero hn, and_congr_right (fun hp ↦ hp.prime.dvd_finset_prod_iff _)]
+  refine' ⟨_, fun hp ↦ ⟨hs _ hp, _, hp, dvd_rfl⟩⟩
+  rintro ⟨hp, q, hq, hpq⟩
+  rwa [←((hs _ hq).dvd_iff_eq hp.ne_one).1 hpq]
+
+lemma primeFactors_div_gcd (hm : Squarefree m) (hn : n ≠ 0) :
+    primeFactors (m / m.gcd n) = primeFactors m \ primeFactors n := by
+  ext p
+  have : m / m.gcd n ≠ 0 :=
+    (Nat.div_ne_zero_iff $ gcd_ne_zero_right hn).2 $ gcd_le_left _ hm.ne_zero.bot_lt
+  simp only [mem_primeFactors, ne_eq, this, not_false_eq_true, and_true, not_and, mem_sdiff,
+    hm.ne_zero, hn, dvd_div_iff (gcd_dvd_left _ _)]
+  refine ⟨fun hp ↦ ⟨⟨hp.1, dvd_of_mul_left_dvd hp.2⟩, fun _ hpn ↦ hp.1.not_unit $ hm _ $
+    (mul_dvd_mul_right (dvd_gcd (dvd_of_mul_left_dvd hp.2) hpn) _).trans hp.2⟩, fun hp ↦
+      ⟨hp.1.1, Coprime.mul_dvd_of_dvd_of_dvd ?_ (gcd_dvd_left _ _) hp.1.2⟩⟩
+  rw [coprime_comm, hp.1.1.coprime_iff_not_dvd]
+  exact fun hpn ↦ hp.2 hp.1.1 $ hpn.trans $ gcd_dvd_right _ _
+
+lemma prod_primeFactors_invOn_squarefree :
+    Set.InvOn (fun n : ℕ ↦ (factorization n).support) (fun s ↦ ∏ p in s, p)
+      {s | ∀ p ∈ s, p.Prime} {n | Squarefree n} :=
+  ⟨fun _s ↦ primeFactors_prod, fun _n ↦ prod_primeFactors_of_squarefree⟩
+
 theorem prod_factors_toFinset_of_squarefree {n : ℕ} (hn : Squarefree n) :
     ∏ p in n.factors.toFinset, p = n := by
   rw [List.prod_toFinset _ hn.nodup_factors, List.map_id'', Nat.prod_factors hn.ne_zero]
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
@@ -51,7 +51,7 @@ theorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n)
   · have := hn p
     simp only [multiplicity_eq_factorization hp hn', Nat.isUnit_iff, hp.ne_one, or_false_iff]
       at this
-    exact_mod_cast this
+    exact mod_cast this
   · rw [factorization_eq_zero_of_non_prime _ hp]
     exact zero_le_one
 #align nat.squarefree.factorization_le_one Nat.Squarefree.factorization_le_one
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
@@ -254,7 +254,7 @@ instance : DecidablePred (Squarefree : ℕ → Prop) := fun _ =>
   decidable_of_iff' _ squarefree_iff_minSqFac
 
 theorem squarefree_two : Squarefree 2 := by
-  rw [squarefree_iff_nodup_factors] <;> norm_num
+  rw [squarefree_iff_nodup_factors] <;> decide
 #align nat.squarefree_two Nat.squarefree_two
 
 theorem divisors_filter_squarefree_of_squarefree {n : ℕ} (hn : Squarefree n) :
fix: patch for std4#194 (more order lemmas for Nat) (#8077)
Diff
@@ -345,7 +345,7 @@ theorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :
   rintro x ⟨y, hy⟩
   rw [Nat.isUnit_iff]
   by_contra hx
-  refine' lt_le_antisymm _ (Finset.le_max' S ((b * x) ^ 2) _)
+  refine' Nat.lt_le_asymm _ (Finset.le_max' S ((b * x) ^ 2) _)
   -- Porting note: these two goals were in the opposite order in Lean 3
   · convert lt_mul_of_one_lt_right hlts
       (one_lt_pow 2 x zero_lt_two (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))
chore: fix some cases in names (#7469)

And fix some names in comments where this revealed issues

Diff
@@ -368,9 +368,9 @@ theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefre
     exact ⟨a, b, h₁, h₂⟩
 #align nat.sq_mul_squarefree Nat.sq_mul_squarefree
 
-/-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`
-and generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and
-`squarefree.of_mul_right` above for auxiliary lemmas. -/
+/-- `Squarefree` is multiplicative. Note that the → direction does not require `hmn`
+and generalizes to arbitrary commutative monoids. See `Squarefree.of_mul_left` and
+`Squarefree.of_mul_right` above for auxiliary lemmas. -/
 theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n := by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
chore: bump to v4.1.0-rc1 (2nd attempt) (#7216)

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

Diff
@@ -371,18 +371,18 @@ theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefre
 /-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`
 and generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and
 `squarefree.of_mul_right` above for auxiliary lemmas. -/
-theorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :
+theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n := by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
   refine' ball_congr fun p hp => _
   simp only [hmn.isPrimePow_dvd_mul (hp.isPrimePow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
 
-theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.coprime n :=
+theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.Coprime n :=
   coprime_of_dvd fun p hp hm hn => squarefree_iff_prime_squarefree.mp h p hp (mul_dvd_mul hm hn)
 
 theorem squarefree_mul_iff {m n : ℕ} :
-    Squarefree (m * n) ↔ m.coprime n ∧ Squarefree m ∧ Squarefree n :=
+    Squarefree (m * n) ↔ m.Coprime n ∧ Squarefree m ∧ Squarefree n :=
   ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
Revert "chore: bump to v4.1.0-rc1 (#7174)" (#7198)

This reverts commit 6f8e8104. Unfortunately this bump was not linted correctly, as CI did not run runLinter Mathlib.

We can unrevert once that's fixed.

Diff
@@ -371,18 +371,18 @@ theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefre
 /-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`
 and generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and
 `squarefree.of_mul_right` above for auxiliary lemmas. -/
-theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
+theorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n := by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
   refine' ball_congr fun p hp => _
   simp only [hmn.isPrimePow_dvd_mul (hp.isPrimePow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
 
-theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.Coprime n :=
+theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.coprime n :=
   coprime_of_dvd fun p hp hm hn => squarefree_iff_prime_squarefree.mp h p hp (mul_dvd_mul hm hn)
 
 theorem squarefree_mul_iff {m n : ℕ} :
-    Squarefree (m * n) ↔ m.Coprime n ∧ Squarefree m ∧ Squarefree n :=
+    Squarefree (m * n) ↔ m.coprime n ∧ Squarefree m ∧ Squarefree n :=
   ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
chore: bump to v4.1.0-rc1 (#7174)

Some changes have already been review and delegated in #6910 and #7148.

The diff that needs looking at is https://github.com/leanprover-community/mathlib4/pull/7174/commits/64d6d07ee18163627c8f517eb31455411921c5ac

The std bump PR was insta-merged already!

Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Diff
@@ -371,18 +371,18 @@ theorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefre
 /-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`
 and generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and
 `squarefree.of_mul_right` above for auxiliary lemmas. -/
-theorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :
+theorem squarefree_mul {m n : ℕ} (hmn : m.Coprime n) :
     Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n := by
   simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]
   refine' ball_congr fun p hp => _
   simp only [hmn.isPrimePow_dvd_mul (hp.isPrimePow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
 
-theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.coprime n :=
+theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.Coprime n :=
   coprime_of_dvd fun p hp hm hn => squarefree_iff_prime_squarefree.mp h p hp (mul_dvd_mul hm hn)
 
 theorem squarefree_mul_iff {m n : ℕ} :
-    Squarefree (m * n) ↔ m.coprime n ∧ Squarefree m ∧ Squarefree n :=
+    Squarefree (m * n) ↔ m.Coprime n ∧ Squarefree m ∧ Squarefree n :=
   ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
chore: tidy various files (#7017)
Diff
@@ -34,7 +34,7 @@ theorem squarefree_iff_nodup_factors {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔
 end Nat
 
 theorem Squarefree.nodup_factors {n : ℕ} (hn : Squarefree n) : n.factors.Nodup :=
-    (Nat.squarefree_iff_nodup_factors hn.ne_zero).mp hn
+  (Nat.squarefree_iff_nodup_factors hn.ne_zero).mp hn
 
 namespace Nat
 
@@ -388,7 +388,7 @@ theorem squarefree_mul_iff {m n : ℕ} :
 
 theorem prod_factors_toFinset_of_squarefree {n : ℕ} (hn : Squarefree n) :
     ∏ p in n.factors.toFinset, p = n := by
-  erw [List.prod_toFinset _ hn.nodup_factors, List.map_id, Nat.prod_factors hn.ne_zero]
+  rw [List.prod_toFinset _ hn.nodup_factors, List.map_id'', Nat.prod_factors hn.ne_zero]
 
 end Nat
 
feat(Data/Nat/Squarefree): Add lemmas about the product of distinct factors of a squarefree Nat (#6344)

These lemmas will be used to develop a basic theory of arithmetic functions $n \mapsto \prod_{p\mid n} f(p)$.

Diff
@@ -31,6 +31,13 @@ theorem squarefree_iff_nodup_factors {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔
   simp
 #align nat.squarefree_iff_nodup_factors Nat.squarefree_iff_nodup_factors
 
+end Nat
+
+theorem Squarefree.nodup_factors {n : ℕ} (hn : Squarefree n) : n.factors.Nodup :=
+    (Nat.squarefree_iff_nodup_factors hn.ne_zero).mp hn
+
+namespace Nat
+
 theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n :=
   squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩
 #align nat.squarefree_iff_prime_squarefree Nat.squarefree_iff_prime_squarefree
@@ -379,6 +386,10 @@ theorem squarefree_mul_iff {m n : ℕ} :
   ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
     fun h => (squarefree_mul h.1).mpr h.2⟩
 
+theorem prod_factors_toFinset_of_squarefree {n : ℕ} (hn : Squarefree n) :
+    ∏ p in n.factors.toFinset, p = n := by
+  erw [List.prod_toFinset _ hn.nodup_factors, List.map_id, Nat.prod_factors hn.ne_zero]
+
 end Nat
 
 -- Porting note: comment out NormNum tactic, to be moved to another file.
chore: remove unused simps (#6632)

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>

Diff
@@ -279,7 +279,6 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
       rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs
       have hs0 : s.val.prod ≠ 0 := by
         rw [Ne.def, Multiset.prod_eq_zero_iff]
-        simp only [exists_prop, id.def, exists_eq_right]
         intro con
         apply
           not_irreducible_zero
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
@@ -311,7 +311,7 @@ theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
 
 open BigOperators
 
-theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
+theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type*} [AddCommMonoid α]
     {f : ℕ → α} :
     ∑ i in n.divisors.filter Squarefree, f i =
       ∑ i in (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset, f i.val.prod := by
fix: remove porting note (#6478)

Remove now-false claim in porting note.

Diff
@@ -246,12 +246,8 @@ theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :
 instance : DecidablePred (Squarefree : ℕ → Prop) := fun _ =>
   decidable_of_iff' _ squarefree_iff_minSqFac
 
---Porting note: norm_num now cannot close the first subgoal
 theorem squarefree_two : Squarefree 2 := by
-  rw [squarefree_iff_nodup_factors]
-  · rw [Nat.factors_prime prime_two]
-    exact List.nodup_singleton 2
-  · norm_num
+  rw [squarefree_iff_nodup_factors] <;> norm_num
 #align nat.squarefree_two Nat.squarefree_two
 
 theorem divisors_filter_squarefree_of_squarefree {n : ℕ} (hn : Squarefree n) :
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,17 +2,14 @@
 Copyright (c) 2020 Aaron Anderson. All rights reserved.
 Released under Apache 2.0 license as described in the file LICENSE.
 Authors: Aaron Anderson
-
-! This file was ported from Lean 3 source module data.nat.squarefree
-! leanprover-community/mathlib commit 3c1368cac4abd5a5cbe44317ba7e87379d51ed88
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
 -/
 import Mathlib.Algebra.Squarefree
 import Mathlib.Data.Nat.Factorization.PrimePow
 import Mathlib.Data.Nat.PrimeNormNum
 import Mathlib.RingTheory.Int.Basic
 
+#align_import data.nat.squarefree from "leanprover-community/mathlib"@"3c1368cac4abd5a5cbe44317ba7e87379d51ed88"
+
 /-!
 # Lemmas about squarefreeness of natural numbers
 A number is squarefree when it is not divisible by any squares except the squares of units.
chore: cleanup whitespace (#5988)

Grepping for [^ .:{-] [^ :] and reviewing the results. Once I started I couldn't stop. :-)

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

Diff
@@ -117,7 +117,7 @@ def minSqFacAux : ℕ → ℕ → Option ℕ
         lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) k) this
         if k ∣ n' then some k else minSqFacAux n' (k + 2)
       else minSqFacAux n (k + 2)
-termination_by  _ n k => sqrt n + 2 - k
+termination_by _ n k => sqrt n + 2 - k
 #align nat.min_sq_fac_aux Nat.minSqFacAux
 
 /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no
feat(Data/Nat/Squarefree): add divisors_filter_squarefree_of_squarefree (#5835)

Add a lemma that helps when applying divisors_filter_squarefree or sum_divisors_filter_squarefree in the case where n is squarefree.

Diff
@@ -257,6 +257,11 @@ theorem squarefree_two : Squarefree 2 := by
   · norm_num
 #align nat.squarefree_two Nat.squarefree_two
 
+theorem divisors_filter_squarefree_of_squarefree {n : ℕ} (hn : Squarefree n) :
+    n.divisors.filter Squarefree = n.divisors :=
+  Finset.ext fun d => ⟨@Finset.filter_subset _ _ _ _ d, fun hd =>
+    Finset.mem_filter.mpr ⟨hd, hn.squarefree_of_dvd (Nat.dvd_of_mem_divisors hd) ⟩⟩
+
 open UniqueFactorizationMonoid
 
 theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :
feat(Data/Nat/Squarefree): add coprime_of_squarefree_mul (#5669)

Add a lemma stating that two natural numbers are coprime if their product is squarefree.

Diff
@@ -374,6 +374,14 @@ theorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :
   simp only [hmn.isPrimePow_dvd_mul (hp.isPrimePow.pow two_ne_zero), not_or]
 #align nat.squarefree_mul Nat.squarefree_mul
 
+theorem coprime_of_squarefree_mul {m n : ℕ} (h : Squarefree (m * n)) : m.coprime n :=
+  coprime_of_dvd fun p hp hm hn => squarefree_iff_prime_squarefree.mp h p hp (mul_dvd_mul hm hn)
+
+theorem squarefree_mul_iff {m n : ℕ} :
+    Squarefree (m * n) ↔ m.coprime n ∧ Squarefree m ∧ Squarefree n :=
+  ⟨fun h => ⟨coprime_of_squarefree_mul h, (squarefree_mul $ coprime_of_squarefree_mul h).mp h⟩,
+    fun h => (squarefree_mul h.1).mpr h.2⟩
+
 end Nat
 
 -- Porting note: comment out NormNum tactic, to be moved to another file.
fix: ∑' precedence (#5615)
  • Also remove most superfluous parentheses around big operators (, and variants).
  • roughly the used regex: ([^a-zA-Zα-ωΑ-Ω'𝓝ℳ₀𝕂ₛ)]) \(([∑∏][^()∑∏]*,[^()∑∏:]*)\) ([⊂⊆=<≤]) replaced by $1 $2 $3
Diff
@@ -315,7 +315,7 @@ open BigOperators
 
 theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]
     {f : ℕ → α} :
-    (∑ i in n.divisors.filter Squarefree, f i) =
+    ∑ i in n.divisors.filter Squarefree, f i =
       ∑ i in (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset, f i.val.prod := by
   rw [Finset.sum_eq_multiset_sum, divisors_filter_squarefree h0, Multiset.map_map,
     Finset.sum_eq_multiset_sum]
chore: remove legacy termination_by' (#5426)

This adds a couple of WellFoundedRelation instances, like for example WellFoundedRelation (WithBot Nat). Longer-term, we should probably add a WellFoundedOrder class for types with a well-founded less-than relation and a [WellFoundOrder α] : WellFoundedRelation α instance (or maybe just [LT α] [IsWellFounded fun a b : α => a < b] : WellFoundedRelation α).

Diff
@@ -154,46 +154,45 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
 #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div
 
 --Porting note: I had to replace two uses of `by decide` by `linarith`.
-theorem minSqFacAux_has_prop :
-    ∀ {n : ℕ} (k),
-      0 < n → ∀ i, k = 2 * i + 3 → (∀ m, Prime m → m ∣ n → k ≤ m) → MinSqFacProp n (minSqFacAux n k)
-  | n, k => fun n0 i e ih => by
-    rw [minSqFacAux]
-    by_cases h : n < k * k <;> simp [h]
-    · refine' squarefree_iff_prime_squarefree.2 fun p pp d => _
-      have := ih p pp (dvd_trans ⟨_, rfl⟩ d)
-      have := Nat.mul_le_mul this this
-      exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))
-    have k2 : 2 ≤ k := by
-      subst e
-      linarith
-    have k0 : 0 < k := lt_of_lt_of_le (by decide) k2
-    have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by
-      intro n' nd' nk
-      have hn' := le_of_dvd n0 nd'
-      refine'
-        have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k :=
-          lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h)
-        @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)
-          (by simp [e, left_distrib]) fun m m2 d => _
-      cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
-      · subst me
-        contradiction
-      apply (Nat.eq_or_lt_of_le ml).resolve_left
-      intro me
-      rw [← me, e] at d
-      change 2 * (i + 2) ∣ n' at d
-      have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
-      rw [e] at this
-      exact absurd this (by linarith)
-    have pk : k ∣ n → Prime k := by
-      refine' fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) _⟩
-      exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk)
-    split_ifs with dk dkk
-    · exact ⟨pk dk, (Nat.dvd_div_iff dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩
-    · specialize IH (n / k) (div_dvd_of_dvd dk) dkk
-      exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
-    · exact IH n (dvd_refl _) dk termination_by' ⟨_, (measure fun ⟨n, k⟩ => Nat.sqrt n + 2 - k).wf⟩
+theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
+    (ih : ∀ m, Prime m → m ∣ n → k ≤ m) : MinSqFacProp n (minSqFacAux n k) := by
+  rw [minSqFacAux]
+  by_cases h : n < k * k <;> simp [h]
+  · refine' squarefree_iff_prime_squarefree.2 fun p pp d => _
+    have := ih p pp (dvd_trans ⟨_, rfl⟩ d)
+    have := Nat.mul_le_mul this this
+    exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))
+  have k2 : 2 ≤ k := by
+    subst e
+    linarith
+  have k0 : 0 < k := lt_of_lt_of_le (by decide) k2
+  have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by
+    intro n' nd' nk
+    have hn' := le_of_dvd n0 nd'
+    refine'
+      have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k :=
+        lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h)
+      @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)
+        (by simp [e, left_distrib]) fun m m2 d => _
+    cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml
+    · subst me
+      contradiction
+    apply (Nat.eq_or_lt_of_le ml).resolve_left
+    intro me
+    rw [← me, e] at d
+    change 2 * (i + 2) ∣ n' at d
+    have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
+    rw [e] at this
+    exact absurd this (by linarith)
+  have pk : k ∣ n → Prime k := by
+    refine' fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) _⟩
+    exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk)
+  split_ifs with dk dkk
+  · exact ⟨pk dk, (Nat.dvd_div_iff dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩
+  · specialize IH (n / k) (div_dvd_of_dvd dk) dkk
+    exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH
+  · exact IH n (dvd_refl _) dk
+termination_by _ => n.sqrt + 2 - k
 #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop
 
 theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by
chore: clean up spacing around at and goals (#5387)

Changes are of the form

  • some_tactic at h⊢ -> some_tactic at h ⊢
  • some_tactic at h -> some_tactic at h
Diff
@@ -146,7 +146,7 @@ theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k 
         contradiction
     (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp
   cases' o with d
-  · rw [MinSqFacProp, squarefree_iff_prime_squarefree] at H⊢
+  · rw [MinSqFacProp, squarefree_iff_prime_squarefree] at H ⊢
     exact fun p pp dp => H p pp ((dvd_div_iff dk).2 (this _ pp dp))
   · obtain ⟨H1, H2, H3⟩ := H
     simp only [dvd_div_iff dk] at H2 H3
chore: tidy various files (#4423)
Diff
@@ -18,7 +18,7 @@ import Mathlib.RingTheory.Int.Basic
 A number is squarefree when it is not divisible by any squares except the squares of units.
 
 ## Main Results
- - `nat.squarefree_iff_nodup_factors`: A positive natural number `x` is squarefree iff
+ - `Nat.squarefree_iff_nodup_factors`: A positive natural number `x` is squarefree iff
   the list `factors x` has no duplicate factors.
 
 ## Tags
@@ -67,10 +67,7 @@ theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :
 
 theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
     n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) := by
-  refine'
-    ⟨by
-      rintro rfl
-      simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => _⟩
+  refine' ⟨by rintro rfl; simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => _⟩
   by_cases hp : p.Prime
   · have h₁ := h _ hp
     rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,
@@ -88,10 +85,7 @@ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
 
 theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
     Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 := by
-  refine'
-    ⟨fun h => _, by
-      rintro ⟨hn, rfl⟩
-      simpa⟩
+  refine' ⟨fun h => _, by rintro ⟨hn, rfl⟩; simpa⟩
   rcases eq_or_ne n 0 with (rfl | -)
   · simp [zero_pow hk.bot_lt] at h
   refine' ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => _⟩
@@ -102,7 +96,7 @@ theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
 #align nat.squarefree_pow_iff Nat.squarefree_pow_iff
 
 theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n := by
-  refine' Iff.symm ⟨fun hn => ⟨hn.squarefree, hn.isPrimePow⟩, _⟩
+  refine' ⟨_, fun hn => ⟨hn.squarefree, hn.isPrimePow⟩⟩
   rw [isPrimePow_nat_iff]
   rintro ⟨h, p, k, hp, hk, rfl⟩
   rw [squarefree_pow_iff hp.ne_one hk.ne'] at h
@@ -127,7 +121,7 @@ termination_by  _ n k => sqrt n + 2 - k
 #align nat.min_sq_fac_aux Nat.minSqFacAux
 
 /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no
-  such `p` (that is, `n` is squarefree). See also `squarefree_iff_min_sq_fac`. -/
+  such `p` (that is, `n` is squarefree). See also `Nat.squarefree_iff_minSqFac`. -/
 def minSqFac (n : ℕ) : Option ℕ :=
   if 2 ∣ n then
     let n' := n / 2
@@ -135,7 +129,7 @@ def minSqFac (n : ℕ) : Option ℕ :=
   else minSqFacAux n 3
 #align nat.min_sq_fac Nat.minSqFac
 
-/-- The correctness property of the return value of `min_sq_fac`.
+/-- The correctness property of the return value of `minSqFac`.
   * If `none`, then `n` is squarefree;
   * If `some d`, then `d` is a minimal square factor of `n` -/
 def MinSqFacProp (n : ℕ) : Option ℕ → Prop
feat: port Data.Nat.Squarefree (#4278)

Co-authored-by: Parcly Taxel <reddeloostw@gmail.com>

Dependencies 8 + 485

486 files ported (98.4%)
200261 lines ported (98.5%)
Show graph

The unported dependencies are