|
| 1 | +/- |
| 2 | +Copyright (c) 2016 Jeremy Avigad. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Jeremy Avigad |
| 5 | +Ported by: Scott Morrison |
| 6 | +-/ |
| 7 | +import Mathlib.Data.Int.Order.Basic |
| 8 | +import Mathlib.Data.Nat.Cast.Basic |
| 9 | + |
| 10 | +/-! |
| 11 | +# Basic lemmas about the divisibility relation in `ℤ`. |
| 12 | +-/ |
| 13 | + |
| 14 | + |
| 15 | +open Nat |
| 16 | + |
| 17 | +namespace Int |
| 18 | + |
| 19 | +@[norm_cast] |
| 20 | +theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n := |
| 21 | + ⟨fun ⟨a, ae⟩ => |
| 22 | + m.eq_zero_or_pos.elim (fun m0 => by simp [m0] at ae; simp [ae, m0]) fun m0l => by |
| 23 | + cases' |
| 24 | + eq_ofNat_of_zero_le |
| 25 | + (@nonneg_of_mul_nonneg_right ℤ _ m a (by simp [ae.symm]) (by simpa using m0l)) with |
| 26 | + k e |
| 27 | + subst a |
| 28 | + exact ⟨k, Int.ofNat.inj ae⟩, |
| 29 | + fun ⟨k, e⟩ => Dvd.intro k <| by rw [e, Int.ofNat_mul]⟩ |
| 30 | +#align int.coe_nat_dvd Int.coe_nat_dvd |
| 31 | + |
| 32 | +theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.natAbs := by |
| 33 | + rcases natAbs_eq z with (eq | eq) <;> rw [eq] <;> simp [coe_nat_dvd] |
| 34 | +#align int.coe_nat_dvd_left Int.coe_nat_dvd_left |
| 35 | + |
| 36 | +theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.natAbs ∣ n := by |
| 37 | + rcases natAbs_eq z with (eq | eq) <;> rw [eq] <;> simp [coe_nat_dvd] |
| 38 | +#align int.coe_nat_dvd_right Int.coe_nat_dvd_right |
| 39 | + |
| 40 | +#align int.le_of_dvd Int.le_of_dvd |
| 41 | + |
| 42 | +#align int.eq_one_of_dvd_one Int.eq_one_of_dvd_one |
| 43 | + |
| 44 | +#align int.eq_one_of_mul_eq_one_right Int.eq_one_of_mul_eq_one_right |
| 45 | + |
| 46 | +#align int.eq_one_of_mul_eq_one_left Int.eq_one_of_mul_eq_one_left |
| 47 | + |
| 48 | +theorem ofNat_dvd_of_dvd_natAbs {a : ℕ} : ∀ {z : ℤ} (_ : a ∣ z.natAbs), ↑a ∣ z |
| 49 | + | Int.ofNat _, haz => Int.coe_nat_dvd.2 haz |
| 50 | + | -[k+1], haz => by |
| 51 | + change ↑a ∣ -(k + 1 : ℤ) |
| 52 | + apply dvd_neg_of_dvd |
| 53 | + apply Int.coe_nat_dvd.2 |
| 54 | + exact haz |
| 55 | +#align int.of_nat_dvd_of_dvd_nat_abs Int.ofNat_dvd_of_dvd_natAbs |
| 56 | + |
| 57 | +theorem dvd_natAbs_of_ofNat_dvd {a : ℕ} : ∀ {z : ℤ} (_ : ↑a ∣ z), a ∣ z.natAbs |
| 58 | + | Int.ofNat _, haz => Int.coe_nat_dvd.1 (Int.dvd_natAbs.2 haz) |
| 59 | + | -[k+1], haz => |
| 60 | + have haz' : (↑a : ℤ) ∣ (↑(k + 1) : ℤ) := dvd_of_dvd_neg haz |
| 61 | + Int.coe_nat_dvd.1 haz' |
| 62 | +#align int.dvd_nat_abs_of_of_nat_dvd Int.dvd_natAbs_of_ofNat_dvd |
| 63 | + |
| 64 | +#align int.dvd_antisymm Int.dvd_antisymm |
| 65 | + |
| 66 | +end Int |
0 commit comments