Skip to content

Commit a541d53

Browse files
committed
chore(Data/Nat/Factorization/Defs): golf factorization_le_iff_dvd and prod_pow_factorization_eq_self (leanprover-community#34426)
1 parent f468b6a commit a541d53

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

Mathlib/Data/Nat/Factorization/Defs.lean

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,12 @@ theorem factorization_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
160160

161161
theorem factorization_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :
162162
d.factorization ≤ n.factorization ↔ d ∣ n := by
163-
constructor
164-
· intro hdn
165-
set K := n.factorization - d.factorization with hK
166-
use K.prod (· ^ ·)
167-
rw [← factorization_prod_pow_eq_self hn, ← factorization_prod_pow_eq_self hd,
168-
← Finsupp.prod_add_index' pow_zero pow_add, hK, add_tsub_cancel_of_le hdn]
169-
· rintro ⟨c, rfl⟩
170-
rw [factorization_mul hd (right_ne_zero_of_mul hn)]
171-
simp
163+
refine ⟨fun hdn ↦ ?_, fun ⟨c, h⟩ ↦ ?_⟩
164+
· rw [← factorization_prod_pow_eq_self hn, ← factorization_prod_pow_eq_self hd]
165+
exact prod_dvd_prod_of_subset_of_dvd (support_mono hdn) fun a _ ↦ pow_dvd_pow a (hdn a)
166+
· subst h
167+
rw [factorization_mul hd <| right_ne_zero_of_mul hn]
168+
apply self_le_add_right
172169

173170
/-- For any `p : ℕ` and any function `g : α → ℕ` that's non-zero on `S : Finset α`,
174171
the power of `p` in `S.prod g` equals the sum over `x ∈ S` of the powers of `p` in `g x`.
@@ -226,13 +223,9 @@ lemma factorization_minFac_ne_zero {n : ℕ} (hn : 1 < n) :
226223
the product `∏ (a : ℕ) ∈ f.support, a ^ f a`. -/
227224
theorem prod_pow_factorization_eq_self {f : ℕ →₀ ℕ} (hf : ∀ p : ℕ, p ∈ f.support → Prime p) :
228225
(f.prod (· ^ ·)).factorization = f := by
229-
have h : ∀ x : ℕ, x ∈ f.support → x ^ f x ≠ 0 := fun p hp =>
230-
pow_ne_zero _ (Prime.ne_zero (hf p hp))
231-
simp only [Finsupp.prod, factorization_prod h]
232-
conv =>
233-
rhs
234-
rw [(sum_single f).symm]
235-
exact sum_congr rfl fun p hp => Prime.factorization_pow (hf p hp)
226+
rw [Finsupp.prod, factorization_prod (pow_ne_zero _ <| hf · · |>.ne_zero),
227+
sum_congr rfl (hf · · |>.factorization_pow)]
228+
exact sum_single f
236229

237230
/-- The equiv between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/
238231
def factorizationEquiv : ℕ+ ≃ { f : ℕ →₀ ℕ | ∀ p ∈ f.support, Prime p } where

0 commit comments

Comments
 (0)