Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 0934d7d

Browse files
ChrisHughes24digama0
authored andcommitted
refactor(data/nat/prime): mem_factors_iff_dvd (#272)
1 parent 974987c commit 0934d7d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

data/list/basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,10 @@ theorem prod_erase [decidable_eq α] [comm_monoid α] {a} :
11731173
{ simp [ne.symm, list.erase, prod_erase h, mul_left_comm a b] }
11741174
end
11751175

1176+
lemma dvd_prod [comm_semiring α] {a} {l : list α} (ha : a ∈ l) : a ∣ l.prod :=
1177+
let ⟨s, t, h⟩ := mem_split ha in
1178+
by rw [h, prod_append, prod_cons, mul_left_comm]; exact dvd_mul_right _ _
1179+
11761180
@[simp] theorem sum_const_nat (m n : ℕ) : sum (list.repeat m n) = m * n :=
11771181
by induction n; simp [*, nat.mul_succ]
11781182

data/nat/prime.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ lemma mem_list_primes_of_dvd_prod {p : ℕ} (hp : prime p) :
321321
(λ h, have hl : ∀ p ∈ l, prime p := λ p hlp, h₁ p ((mem_cons_iff _ _ _).2 (or.inr hlp)),
322322
(mem_cons_iff _ _ _).2 (or.inr (mem_list_primes_of_dvd_prod hl h)))
323323

324-
lemma mem_factors_of_dvd {n p : ℕ} (hn : 0 < n) (hp : prime p) (h : p ∣ n) : p ∈ factors n :=
325-
mem_list_primes_of_dvd_prod hp (@mem_factors n) ((prod_factors hn).symm ▸ h)
324+
lemma mem_factors_iff_dvd {n p : ℕ} (hn : 0 < n) (hp : prime p) : p ∈ factors n ↔ p ∣ n :=
325+
⟨λ h, prod_factors hn ▸ list.dvd_prod h,
326+
λ h, mem_list_primes_of_dvd_prod hp (@mem_factors n) ((prod_factors hn).symm ▸ h)⟩
326327

327328
lemma perm_of_prod_eq_prod : ∀ {l₁ l₂ : list ℕ}, prod l₁ = prod l₂ →
328329
(∀ p ∈ l₁, prime p) → (∀ p ∈ l₂, prime p) → l₁ ~ l₂

0 commit comments

Comments
 (0)