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

Commit e74ff76

Browse files
committed
refactor(data/nat/gcd): simplify proof of pow_dvd_pow_iff
1 parent ffb7229 commit e74ff76

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

algebra/ring.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ instance [semiring α] : semiring (with_zero α) :=
3434
..with_zero.mul_zero_class,
3535
..with_zero.monoid }
3636

37+
attribute [refl] dvd_refl
3738
attribute [trans] dvd.trans
3839

3940
section

data/nat/basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ by induction n; simp [*, pow_succ, mul_assoc]
375375
theorem pow_dvd_pow (a : ℕ) {m n : ℕ} (h : m ≤ n) : a^m ∣ a^n :=
376376
by rw [← nat.add_sub_cancel' h, pow_add]; apply dvd_mul_right
377377

378+
theorem pow_dvd_pow_of_dvd {a b : ℕ} (h : a ∣ b) : ∀ n:ℕ, a^n ∣ b^n
379+
| 0 := dvd_refl _
380+
| (n+1) := mul_dvd_mul (pow_dvd_pow_of_dvd n) h
381+
378382
theorem mul_pow (a b n : ℕ) : (a * b) ^ n = a ^ n * b ^ n :=
379383
by induction n; simp [*, nat.pow_succ, mul_comm, mul_assoc, mul_left_comm]
380384

data/nat/gcd.lean

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -301,32 +301,18 @@ or.elim (eq_zero_or_pos (gcd k m))
301301
dvd_of_mul_dvd_mul_left gpos $ by rw [←hd, ←gcd_mul_right]; exact
302302
dvd_gcd (dvd_mul_right _ _) H⟩)
303303

304-
lemma dvd_of_pow_dvd_pow : ∀ {a b n : ℕ}, 0 < n → a ^ n ∣ b ^ n → a ∣ b
305-
| a 0 := λ n hn h, dvd_zero _
306-
| a (b+1) := λ n hn h,
307-
let d := nat.gcd a (b + 1) in
308-
have hd : nat.gcd a (b + 1) = d := rfl,
309-
match d, hd with
310-
| 0 := λ hd, (eq_zero_of_gcd_eq_zero_right hd).symm ▸ dvd_zero _
311-
| 1 := λ hd,
312-
begin
313-
have h₁ : a ^ n = 1 := coprime.eq_one_of_dvd (coprime.pow n n hd) h,
314-
have := pow_dvd_pow a hn,
315-
rw [nat.pow_one, h₁] at this,
316-
exact dvd.trans this (one_dvd _),
317-
end
318-
| (d+2) := λ hd,
319-
have (b+1) / (d+2) < (b+1) := div_lt_self dec_trivial dec_trivial,
320-
have ha : a = (d+2) * (a / (d+2)) :=
321-
by rw [← hd, nat.mul_div_cancel' (gcd_dvd_left _ _)],
322-
have hb : (b+1) = (d+2) * ((b+1) / (d+2)) :=
323-
by rw [← hd, nat.mul_div_cancel' (gcd_dvd_right _ _)],
324-
have a / (d+2) ∣ (b+1) / (d+2) := dvd_of_pow_dvd_pow hn $ dvd_of_mul_dvd_mul_left
325-
(show (d + 2) ^ n > 0, from pos_pow_of_pos _ dec_trivial)
326-
(by rwa [← nat.mul_pow, ← nat.mul_pow, ← ha, ← hb]),
327-
by rw [ha, hb];
328-
exact mul_dvd_mul_left _ this
329-
end
330-
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf psigma.snd⟩]}
304+
theorem pow_dvd_pow_iff {a b n : ℕ} (n0 : 0 < n) : a ^ n ∣ b ^ n ↔ a ∣ b :=
305+
begin
306+
refine ⟨λ h, _, λ h, pow_dvd_pow_of_dvd h _⟩,
307+
cases eq_zero_or_pos (gcd a b) with g0 g0,
308+
{ simp [eq_zero_of_gcd_eq_zero_right g0, dvd_zero] },
309+
rcases exists_coprime g0 with ⟨a', b', co, h₁, h₂⟩,
310+
generalize_hyp : gcd a b = g at g0 h₁ h₂, substs a b,
311+
rw [mul_pow, mul_pow] at h,
312+
replace h := dvd_of_mul_dvd_mul_right (pos_pow_of_pos _ g0) h,
313+
have := pow_dvd_pow a' n0,
314+
rw [pow_one, (co.pow n n).eq_one_of_dvd h] at this,
315+
simp [eq_one_of_dvd_one this]
316+
end
331317

332318
end nat

0 commit comments

Comments
 (0)