Module docstring
{"# Basic operations on the integers
This file builds on Data.Int.Init by adding basic lemmas on integers.
depending on Mathlib definitions.
","### nat abs ","### dvd "}
{"# Basic operations on the integers
This file builds on Data.Int.Init by adding basic lemmas on integers.
depending on Mathlib definitions.
","### nat abs ","### dvd "}
Int.instNontrivial
instance
: Nontrivial ℤ
instance instNontrivial : Nontrivial ℤ := ⟨⟨0, 1, Int.zero_ne_one⟩⟩
Int.ofNat_injective
theorem
: Function.Injective ofNat
@[simp] lemma ofNat_injective : Function.Injective ofNat := @Int.ofNat.inj
Int.inductionOn'_add_one
theorem
(hz : b ≤ z) : (z + 1).inductionOn' b H0 Hs Hp = Hs z hz (z.inductionOn' b H0 Hs Hp)
lemma inductionOn'_add_one (hz : b ≤ z) :
(z + 1).inductionOn' b H0 Hs Hp = Hs z hz (z.inductionOn' b H0 Hs Hp) := by
apply cast_eq_iff_heq.mpr
lift z - b to ℕ using Int.sub_nonneg.mpr hz with zb hzb
rw [show z + 1 - b = zb + 1 by omega]
have : b + zb = z := by omega
subst this
convert cast_heq _ _
rw [Int.inductionOn', cast_eq_iff_heq, ← hzb]
Int.strongRec_of_ge
theorem
: ∀ hn : m ≤ n, m.strongRec lt ge n = ge n hn fun k _ ↦ m.strongRec lt ge k
lemma strongRec_of_ge :
∀ hn : m ≤ n, m.strongRec lt ge n = ge n hn fun k _ ↦ m.strongRec lt ge k := by
refine m.strongRec (fun n hnm hmn ↦ (Int.not_lt.mpr hmn hnm).elim) (fun n _ ih hn ↦ ?_) n
rw [Int.strongRec, dif_neg (Int.not_lt.mpr hn)]
congr; revert ih
refine n.inductionOn' m (fun _ ↦ ?_) (fun k hmk ih' ih ↦ ?_) (fun k hkm ih' _ ↦ ?_) <;> ext l hl
· rw [inductionOn'_self, strongRec_of_lt hl]
· rw [inductionOn'_add_one hmk]; split_ifs with hlm
· rw [strongRec_of_lt hlm]
· rw [ih' fun l hl ↦ ih l (Int.lt_trans hl k.lt_succ), ih _ hl]
· rw [inductionOn'_sub_one hkm, ih']
exact fun l hlk hml ↦ (Int.not_lt.mpr hkm <| Int.lt_of_le_of_lt hml hlk).elim
Int.natAbs_surjective
theorem
: natAbs.Surjective
lemma natAbs_surjective : natAbs.Surjective := fun n => ⟨n, natAbs_natCast n⟩
Int.pow_right_injective
theorem
(h : 1 < a.natAbs) : ((a ^ ·) : ℕ → ℤ).Injective
lemma pow_right_injective (h : 1 < a.natAbs) : ((a ^ ·) : ℕ → ℤ).Injective := by
refine (?_ : (natAbsnatAbs ∘ (a ^ · : ℕ → ℤ)).Injective).of_comp
convert Nat.pow_right_injective h using 2
rw [Function.comp_apply, natAbs_pow]
Int.natCast_dvd_natCast
theorem
{m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n
@[norm_cast] lemma natCast_dvd_natCast {m n : ℕ} : (↑m : ℤ) ∣ ↑n(↑m : ℤ) ∣ ↑n ↔ m ∣ n where
mp := by
rintro ⟨a, h⟩
obtain rfl | hm := m.eq_zero_or_pos
· simpa using h
have ha : 0 ≤ a := Int.not_lt.1 fun ha ↦ by
simpa [← h, Int.not_lt.2 (Int.natCast_nonneg _)]
using Int.mul_neg_of_pos_of_neg (natCast_pos.2 hm) ha
lift a to ℕ using ha
norm_cast at h
exact ⟨a, h⟩
mpr := by rintro ⟨a, rfl⟩; simp [Int.dvd_mul_right]
Int.ofNat_dvd_natCast
theorem
{x y : ℕ} : (ofNat(x) : ℤ) ∣ (y : ℤ) ↔ OfNat.ofNat x ∣ y
@[norm_cast] theorem ofNat_dvd_natCast {x y : ℕ} : (ofNat(x) : ℤ) ∣ (y : ℤ)(ofNat(x) : ℤ) ∣ (y : ℤ) ↔ OfNat.ofNat x ∣ y :=
natCast_dvd_natCast
Int.natCast_dvd_ofNat
theorem
{x y : ℕ} : (x : ℤ) ∣ (ofNat(y) : ℤ) ↔ x ∣ OfNat.ofNat y
@[norm_cast] theorem natCast_dvd_ofNat {x y : ℕ} : (x : ℤ) ∣ (ofNat(y) : ℤ)(x : ℤ) ∣ (ofNat(y) : ℤ) ↔ x ∣ OfNat.ofNat y :=
natCast_dvd_natCast
Int.natCast_dvd
theorem
{m : ℕ} : (m : ℤ) ∣ n ↔ m ∣ n.natAbs
lemma natCast_dvd {m : ℕ} : (m : ℤ) ∣ n(m : ℤ) ∣ n ↔ m ∣ n.natAbs := by
obtain hn | hn := natAbs_eq n <;> rw [hn] <;> simp [← natCast_dvd_natCast, Int.dvd_neg]
Int.dvd_natCast
theorem
{n : ℕ} : m ∣ (n : ℤ) ↔ m.natAbs ∣ n
lemma dvd_natCast {n : ℕ} : m ∣ (n : ℤ)m ∣ (n : ℤ) ↔ m.natAbs ∣ n := by
obtain hn | hn := natAbs_eq m <;> rw [hn] <;> simp [← natCast_dvd_natCast, Int.neg_dvd]
Int.natAbs_le_of_dvd_ne_zero
theorem
(hmn : m ∣ n) (hn : n ≠ 0) : natAbs m ≤ natAbs n