Mathlib.Data.Int.Init
75 declarations. Mathlib docs · Source
Basic operations on the integers
This file contains some basic lemmas about integers.
See note [foundational algebra order theory].
This file should not depend on anything defined in Mathlib (except for notation), so that it can be upstreamed to Batteries easily.
succ and pred
mul
natAbs
/
mod
properties of / and %
dvd
/ and ordering
sign
toNat
theorem Int.inductionOn'.pos.match_1.congr_eq_2 E1 #
∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n : ℕ),
x = n.succ →
(match x with
| 0 => h_1 ()
| n.succ => h_2 n) ≍
h_2 n
theorem Int.inductionOn'.neg.hcongr_5 E1 #
∀ (motive motive' : ℤ → Sort u_1),
motive = motive' →
∀ (b b' : ℤ),
b = b' →
∀ (zero : motive b) (zero' : motive' b'),
zero ≍ zero' →
∀ (pred : (k : ℤ) → k ≤ b → motive k → motive (k - 1))
(pred' : (k : ℤ) → k ≤ b' → motive' k → motive' (k - 1)),
pred ≍ pred' →
∀ (n n' : ℕ), n = n' → Int.inductionOn'.neg b zero pred n ≍ Int.inductionOn'.neg b' zero' pred' n'
theorem Int.inductionOn'.pos.match_1.congr_eq_1 E1 #
∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
x = 0 →
(match x with
| 0 => h_1 ()
| n.succ => h_2 n) ≍
h_1 ()
theorem Int.neg_eq_neg E1 #
∀ {a b : ℤ}, -a = -b → a = b
def Int.succ E1 #
ℤ → ℤ
Immediate successor of an integer: succ n = n + 1
def Int.pred E1 #
ℤ → ℤ
Immediate predecessor of an integer: pred n = n - 1
theorem Int.pred_succ E1 #
∀ (a : ℤ), a.succ.pred = a
theorem Int.succ_pred E1 #
∀ (a : ℤ), a.pred.succ = a
theorem Int.neg_succ E1 #
∀ (a : ℤ), -a.succ = (-a).pred
theorem Int.succ_neg_succ E1 #
∀ (a : ℤ), (-a.succ).succ = -a
theorem Int.neg_pred E1 #
∀ (a : ℤ), -a.pred = (-a).succ
theorem Int.pred_neg_pred E1 #
∀ (a : ℤ), (-a.pred).pred = -a
theorem Int.pred_nat_succ E1 #
∀ (n : ℕ), (↑n.succ).pred = ↑n
theorem Int.neg_nat_succ E1 #
∀ (n : ℕ), -↑n.succ = (-↑n).pred
theorem Int.succ_neg_natCast_succ E1 #
∀ (n : ℕ), (-↑n.succ).succ = -↑n
theorem Int.natCast_pred_of_pos E1 #
∀ {n : ℕ}, 0 < n → ↑(n - 1) = ↑n - 1
theorem Int.lt_succ_self E1 #
∀ (a : ℤ), a < a.succ
theorem Int.pred_self_lt E1 #
∀ (a : ℤ), a.pred < a
theorem Int.induction_on E1 #
∀ {motive : ℤ → Prop} (i : ℤ),
motive 0 → (∀ (i : ℕ), motive ↑i → motive (↑i + 1)) → (∀ (i : ℕ), motive (-↑i) → motive (-↑i - 1)) → motive i
Induction on integers: prove a proposition p i by proving the base case p 0,
the upwards induction step p i → p (i + 1) and the downwards induction step p (-i) → p (-i - 1).
It is used as the default induction principle for the induction tactic.
def Int.inductionOn' E1 #
{motive : ℤ → Sort u_1} →
(z b : ℤ) →
motive b → ((k : ℤ) → b ≤ k → motive k → motive (k + 1)) → ((k : ℤ) → k ≤ b → motive k → motive (k - 1)) → motive z
Inductively define a function on ℤ by defining it at b, for the succ of a number greater
than b, and the pred of a number less than b.
def Int.inductionOn'.pos E1 #
{motive : ℤ → Sort u_1} → (b : ℤ) → motive b → ((k : ℤ) → b ≤ k → motive k → motive (k + 1)) → (n : ℕ) → motive (b + ↑n)
The positive case of Int.inductionOn'.
def Int.inductionOn'.neg E1 #
{motive : ℤ → Sort u_1} →
(b : ℤ) → motive b → ((k : ℤ) → k ≤ b → motive k → motive (k - 1)) → (n : ℕ) → motive (b + Int.negSucc n)
The negative case of Int.inductionOn'.
theorem Int.inductionOn'_self E1 #
∀ {motive : ℤ → Sort u_1} {b : ℤ} {zero : motive b} {succ : (k : ℤ) → b ≤ k → motive k → motive (k + 1)}
{pred : (k : ℤ) → k ≤ b → motive k → motive (k - 1)}, Int.inductionOn' b b zero succ pred = zero
theorem Int.inductionOn'_add_one E1 #
∀ {motive : ℤ → Sort u_1} {z b : ℤ} {zero : motive b} {succ : (k : ℤ) → b ≤ k → motive k → motive (k + 1)}
{pred : (k : ℤ) → k ≤ b → motive k → motive (k - 1)} (hz : b ≤ z),
Int.inductionOn' (z + 1) b zero succ pred = succ z hz (Int.inductionOn' z b zero succ pred)
theorem Int.inductionOn'_sub_one E1 #
∀ {motive : ℤ → Sort u_1} {z b : ℤ} {zero : motive b} {succ : (k : ℤ) → b ≤ k → motive k → motive (k + 1)}
{pred : (k : ℤ) → k ≤ b → motive k → motive (k - 1)} (hz : z ≤ b),
Int.inductionOn' (z - 1) b zero succ pred = pred z hz (Int.inductionOn' z b zero succ pred)
def Int.negInduction E1 #
{motive : ℤ → Sort u_1} → ((n : ℕ) → motive ↑n) → (((n : ℕ) → motive ↑n) → (n : ℕ) → motive (-↑n)) → (n : ℤ) → motive n
Inductively define a function on ℤ by defining it on ℕ and extending it from n to -n.
def Int.leInduction E1 #
{m : ℤ} →
{motive : (n : ℤ) → m ≤ n → Sort u_1} →
motive m ⋯ → ((n : ℤ) → (hmn : m ≤ n) → motive n hmn → motive (n + 1) ⋯) → (n : ℤ) → (hmn : m ≤ n) → motive n hmn
See Int.inductionOn' for an induction in both directions.
theorem Int.leInduction_base E1 #
∀ {m : ℤ} {motive : (n : ℤ) → m ≤ n → Sort u_1} (base : motive m ⋯)
(succ : (n : ℤ) → (hmn : m ≤ n) → motive n hmn → motive (n + 1) ⋯), Int.leInduction base succ m ⋯ = base
theorem Int.leInduction_add_one E1 #
∀ {m : ℤ} {motive : (n : ℤ) → m ≤ n → Sort u_1} (base : motive m ⋯)
(succ : (n : ℤ) → (hmn : m ≤ n) → motive n hmn → motive (n + 1) ⋯) (n : ℤ) (hmn : m ≤ n),
Int.leInduction base succ (n + 1) ⋯ = succ n hmn (Int.leInduction base succ n hmn)
def Int.leInductionDown E1 #
{m : ℤ} →
{motive : (n : ℤ) → n ≤ m → Sort u_1} →
motive m ⋯ → ((n : ℤ) → (hnm : n ≤ m) → motive n hnm → motive (n - 1) ⋯) → (n : ℤ) → (hnm : n ≤ m) → motive n hnm
See Int.inductionOn' for an induction in both directions.
theorem Int.leInductionDown_base E1 #
∀ {m : ℤ} {motive : (n : ℤ) → n ≤ m → Sort u_1} (base : motive m ⋯)
(pred : (n : ℤ) → (hnm : n ≤ m) → motive n hnm → motive (n - 1) ⋯), Int.leInductionDown base pred m ⋯ = base
theorem Int.leInductionDown_sub_one E1 #
∀ {m : ℤ} {motive : (n : ℤ) → n ≤ m → Sort u_1} (base : motive m ⋯)
(pred : (n : ℤ) → (hnm : n ≤ m) → motive n hnm → motive (n - 1) ⋯) (n : ℤ) (hnm : n ≤ m),
Int.leInductionDown base pred (n - 1) ⋯ = pred n hnm (Int.leInductionDown base pred n hnm)
def Int.strongRec E1 #
{m : ℤ} →
{motive : ℤ → Sort u_1} →
((n : ℤ) → n < m → motive n) → ((n : ℤ) → n ≥ m → ((k : ℤ) → k < n → motive k) → motive n) → (n : ℤ) → motive n
A strong recursor for Int that specifies explicit values for integers below a threshold,
and is analogous to Nat.strongRec for integers on or above the threshold.
theorem Int.strongRec_of_lt E1 #
∀ {m n : ℤ} {motive : ℤ → Sort u_1} {lt : (n : ℤ) → n < m → motive n}
{ge : (n : ℤ) → n ≥ m → ((k : ℤ) → k < n → motive k) → motive n} (hn : n < m), Int.strongRec lt ge n = lt n hn
theorem Int.natAbs_sq E1 #
∀ (a : ℤ), ↑a.natAbs ^ 2 = a ^ 2
Alias of Int.natAbs_pow_two.
theorem Int.sign_mul_self_eq_natAbs E1 #
∀ (a : ℤ), a.sign * a = ↑a.natAbs
theorem Int.natCast_div E1 #
∀ (m n : ℕ), ↑(m / n) = ↑m / ↑n
theorem Int.ediv_of_neg_of_pos E1 #
∀ {a b : ℤ}, a < 0 → 0 < b → a.ediv b = -((-a - 1) / b + 1)
theorem Int.natCast_mod E0 #
∀ (m n : ℕ), ↑(m % n) = ↑m % ↑n
theorem Int.div_le_iff_of_dvd_of_pos E1 #
∀ {a b c : ℤ}, 0 < b → b ∣ a → (a / b ≤ c ↔ a ≤ b * c)
theorem Int.div_le_iff_of_dvd_of_neg E1 #
∀ {a b c : ℤ}, b < 0 → b ∣ a → (a / b ≤ c ↔ b * c ≤ a)
theorem Int.div_lt_iff_of_dvd_of_pos E1 #
∀ {a b c : ℤ}, 0 < b → b ∣ a → (a / b < c ↔ a < b * c)
theorem Int.div_lt_iff_of_dvd_of_neg E1 #
∀ {a b c : ℤ}, b < 0 → b ∣ a → (a / b < c ↔ b * c < a)
theorem Int.le_div_iff_of_dvd_of_pos E1 #
∀ {a b c : ℤ}, 0 < c → c ∣ b → (a ≤ b / c ↔ c * a ≤ b)
theorem Int.le_div_iff_of_dvd_of_neg E1 #
∀ {a b c : ℤ}, c < 0 → c ∣ b → (a ≤ b / c ↔ b ≤ c * a)
theorem Int.lt_div_iff_of_dvd_of_pos E1 #
∀ {a b c : ℤ}, 0 < c → c ∣ b → (a < b / c ↔ c * a < b)
theorem Int.lt_div_iff_of_dvd_of_neg E1 #
∀ {a b c : ℤ}, c < 0 → c ∣ b → (a < b / c ↔ b < c * a)
theorem Int.div_le_div_iff_of_dvd_of_pos_of_pos E1 #
∀ {a b c d : ℤ}, 0 < b → 0 < d → b ∣ a → d ∣ c → (a / b ≤ c / d ↔ d * a ≤ c * b)
theorem Int.div_le_div_iff_of_dvd_of_pos_of_neg E1 #
∀ {a b c d : ℤ}, 0 < b → d < 0 → b ∣ a → d ∣ c → (a / b ≤ c / d ↔ c * b ≤ d * a)
theorem Int.div_le_div_iff_of_dvd_of_neg_of_pos E1 #
∀ {a b c d : ℤ}, b < 0 → 0 < d → b ∣ a → d ∣ c → (a / b ≤ c / d ↔ c * b ≤ d * a)
theorem Int.div_le_div_iff_of_dvd_of_neg_of_neg E1 #
∀ {a b c d : ℤ}, b < 0 → d < 0 → b ∣ a → d ∣ c → (a / b ≤ c / d ↔ d * a ≤ c * b)
theorem Int.div_lt_div_iff_of_dvd_of_pos E1 #
∀ {a b c d : ℤ}, 0 < b → 0 < d → b ∣ a → d ∣ c → (a / b < c / d ↔ d * a < c * b)
theorem Int.div_lt_div_iff_of_dvd_of_pos_of_neg E1 #
∀ {a b c d : ℤ}, 0 < b → d < 0 → b ∣ a → d ∣ c → (a / b < c / d ↔ c * b < d * a)
theorem Int.div_lt_div_iff_of_dvd_of_neg_of_pos E1 #
∀ {a b c d : ℤ}, b < 0 → 0 < d → b ∣ a → d ∣ c → (a / b < c / d ↔ c * b < d * a)
theorem Int.div_lt_div_iff_of_dvd_of_neg_of_neg E1 #
∀ {a b c d : ℤ}, b < 0 → d < 0 → b ∣ a → d ∣ c → (a / b < c / d ↔ d * a < c * b)
theorem Int.emod_two_eq_zero_or_one E1 #
∀ (n : ℤ), n % 2 = 0 ∨ n % 2 = 1
theorem Int.dvd_mul_of_div_dvd E1 #
∀ {a b c : ℤ}, b ∣ a → a / b ∣ c → a ∣ b * c
theorem Int.div_dvd_iff_dvd_mul E1 #
∀ {a b c : ℤ}, b ∣ a → b ≠ 0 → (a / b ∣ c ↔ a ∣ b * c)
theorem Int.mul_dvd_of_dvd_div E1 #
∀ {a b c : ℤ}, c ∣ b → a ∣ b / c → c * a ∣ b
theorem Int.dvd_div_of_mul_dvd E1 #
∀ {a b c : ℤ}, a * b ∣ c → b ∣ c / a
theorem Int.dvd_div_iff_mul_dvd E1 #
∀ {a b c : ℤ}, c ∣ b → (a ∣ b / c ↔ c * a ∣ b)
theorem Int.exists_lt_and_lt_iff_not_dvd E1 #
∀ {n : ℤ} (m : ℤ), 0 < n → ((∃ k, n * k < m ∧ m < n * (k + 1)) ↔ ¬n ∣ m)
If n > 0 then m is not divisible by n iff it is between n * k and n * (k + 1)
for some k.
theorem Int.ofNat_add_negSucc_of_ge E1 #
∀ {m n : ℕ}, n.succ ≤ m → Int.ofNat m + Int.negSucc n = Int.ofNat (m - n.succ)
theorem Int.le_iff_pos_of_dvd E1 #
∀ {a b : ℤ}, 0 < a → a ∣ b → (a ≤ b ↔ 0 < b)
theorem Int.le_add_iff_lt_of_dvd_sub E1 #
∀ {a b c : ℤ}, 0 < a → a ∣ c - b → (a + b ≤ c ↔ b < c)
theorem Int.sign_add_eq_of_sign_eq E0 #
∀ {m n : ℤ}, m.sign = n.sign → (m + n).sign = n.sign
theorem Int.toNat_pred_coe_of_pos E0 #
∀ {i : ℤ}, 0 < i → ↑(i.toNat - 1) = i - 1
theorem Int.toNat_lt_of_ne_zero E1 #
∀ {m : ℤ} {n : ℕ}, n ≠ 0 → (m.toNat < n ↔ m < ↑n)
def Int.natMod E1 #
ℤ → ℤ → ℕ
The modulus of an integer by another as a natural. Uses the E-rounding convention.
theorem Int.natMod_lt E1 #
∀ {m : ℤ} {n : ℕ}, n ≠ 0 → m.natMod ↑n < n
theorem Int.pow_eq E0 #
∀ (m : ℤ) (n : ℕ), m.pow n = m ^ n
For use in Mathlib/Tactic/NormNum/Pow.lean
theorem Int.gcd_ofNat_negSucc E0 #
∀ (m n : ℕ), (↑m).gcd (Int.negSucc n) = m.gcd (n + 1)
theorem Int.gcd_negSucc_ofNat E0 #
∀ (m n : ℕ), (Int.negSucc m).gcd ↑n = (m + 1).gcd n
theorem Int.gcd_negSucc_negSucc E0 #
∀ (m n : ℕ), (Int.negSucc m).gcd (Int.negSucc n) = (m + 1).gcd (n + 1)
theorem Int.gcd_right_comm E1 #
∀ (a b c : ℤ), (↑(a.gcd b)).gcd c = (↑(a.gcd c)).gcd b