mathlib documentation

data.int.basic

@[instance]

Equations
@[instance]

Extra instances to short-circuit type class resolution

@[instance]

Equations
@[instance]
def int.ring  :

Equations
@[instance]

Equations
theorem int.abs_eq_nat_abs (a : ) :

theorem int.nat_abs_abs (a : ) :

theorem int.sign_mul_abs (a : ) :
(a.sign) * abs a = a

@[simp]

@[instance]

@[instance]

@[simp]
theorem int.add_def {a b : } :
a.add b = a + b

@[simp]
theorem int.mul_def {a b : } :
a.mul b = a * b

@[simp]
theorem int.coe_nat_mul_neg_succ (m n : ) :
(m) * -[1+ n] = -(m) * (n.succ)

@[simp]
theorem int.neg_succ_mul_coe_nat (m n : ) :
-[1+ m] * n = -((m.succ)) * n

@[simp]
theorem int.neg_succ_mul_neg_succ (m n : ) :
-[1+ m] * -[1+ n] = ((m.succ)) * (n.succ)

@[simp]
theorem int.coe_nat_le {m n : } :
m n m n

@[simp]
theorem int.coe_nat_lt {m n : } :
m < n m < n

@[simp]
theorem int.coe_nat_inj' {m n : } :
m = n m = n

@[simp]
theorem int.coe_nat_pos {n : } :
0 < n 0 < n

@[simp]
theorem int.coe_nat_eq_zero {n : } :
n = 0 n = 0

theorem int.coe_nat_ne_zero {n : } :
n 0 n 0

@[simp]
theorem int.coe_nat_nonneg (n : ) :
0 n

theorem int.coe_nat_ne_zero_iff_pos {n : } :
n 0 0 < n

theorem int.coe_nat_succ_pos (n : ) :
0 < (n.succ)

@[simp]
theorem int.coe_nat_abs (n : ) :

succ and pred

def int.succ  :

Immediate successor of an integer: succ n = n + 1

Equations
def int.pred  :

Immediate predecessor of an integer: pred n = n - 1

Equations
theorem int.pred_succ (a : ) :
a.succ.pred = a

theorem int.succ_pred (a : ) :
a.pred.succ = a

theorem int.neg_succ (a : ) :
-a.succ = (-a).pred

theorem int.succ_neg_succ (a : ) :
(-a.succ).succ = -a

theorem int.neg_pred (a : ) :
-a.pred = (-a).succ

theorem int.pred_neg_pred (a : ) :
(-a.pred).pred = -a

theorem int.pred_nat_succ (n : ) :

theorem int.neg_nat_succ (n : ) :

theorem int.succ_neg_nat_succ (n : ) :

theorem int.lt_succ_self (a : ) :
a < a.succ

theorem int.pred_self_lt (a : ) :
a.pred < a

theorem int.add_one_le_iff {a b : } :
a + 1 b a < b

theorem int.lt_add_one_iff {a b : } :
a < b + 1 a b

theorem int.le_add_one {a b : } :
a ba b + 1

theorem int.sub_one_lt_iff {a b : } :
a - 1 < b a b

theorem int.le_sub_one_iff {a b : } :
a b - 1 a < b

theorem int.induction_on {p : → Prop} (i : ) :
p 0(∀ (i : ), p ip (i + 1))(∀ (i : ), p (-i)p (-i - 1))p i

def int.induction_on' {C : Sort u_1} (z b : ) :
C b(Π (k : ), b kC kC (k + 1))(Π (k : ), k bC kC (k - 1))C 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.

Equations

nat abs

theorem int.nat_abs_add_le (a b : ) :

theorem int.nat_abs_mul (a b : ) :
(a * b).nat_abs = (a.nat_abs) * b.nat_abs

@[simp]
theorem int.nat_abs_mul_self' (a : ) :
((a.nat_abs)) * (a.nat_abs) = a * a

theorem int.neg_succ_of_nat_eq' (m : ) :
-[1+ m] = -m - 1

theorem int.nat_abs_ne_zero_of_ne_zero {z : } :
z 0z.nat_abs 0

@[simp]
theorem int.nat_abs_eq_zero {a : } :
a.nat_abs = 0 a = 0

theorem int.nat_abs_lt_nat_abs_of_nonneg_of_lt {a b : } :
0 aa < ba.nat_abs < b.nat_abs

theorem int.nat_abs_eq_iff_mul_self_eq {a b : } :
a.nat_abs = b.nat_abs a * a = b * b

theorem int.nat_abs_lt_iff_mul_self_lt {a b : } :
a.nat_abs < b.nat_abs a * a < b * b

theorem int.nat_abs_eq_iff_sq_eq {a b : } :
a.nat_abs = b.nat_abs a ^ 2 = b ^ 2

theorem int.nat_abs_lt_iff_sq_lt {a b : } :
a.nat_abs < b.nat_abs a ^ 2 < b ^ 2

theorem int.nat_abs_le_iff_sq_le {a b : } :
a.nat_abs b.nat_abs a ^ 2 b ^ 2

/

@[simp]
theorem int.of_nat_div (m n : ) :

@[simp]
theorem int.coe_nat_div (m n : ) :
(m / n) = m / n

theorem int.neg_succ_of_nat_div (m : ) {b : } :
0 < b-[1+ m] / b = -(m / b + 1)

@[simp]
theorem int.div_neg (a b : ) :
a / -b = -(a / b)

theorem int.div_of_neg_of_pos {a b : } :
a < 00 < ba / b = -((-a - 1) / b + 1)

theorem int.div_nonneg {a b : } :
0 a0 b0 a / b

theorem int.div_nonpos {a b : } :
0 ab 0a / b 0

theorem int.div_neg' {a b : } :
a < 00 < ba / b < 0

theorem int.zero_div (b : ) :
0 / b = 0

theorem int.div_zero (a : ) :
a / 0 = 0

@[simp]
theorem int.div_one (a : ) :
a / 1 = a

theorem int.div_eq_zero_of_lt {a b : } :
0 aa < ba / b = 0

theorem int.div_eq_zero_of_lt_abs {a b : } :
0 aa < abs ba / b = 0

theorem int.add_mul_div_right (a b : ) {c : } :
c 0(a + b * c) / c = a / c + b

theorem int.add_mul_div_left (a : ) {b : } (c : ) :
b 0(a + b * c) / b = a / b + c

@[simp]
theorem int.mul_div_cancel (a : ) {b : } :
b 0a * b / b = a

@[simp]
theorem int.mul_div_cancel_left {a : } (b : ) :
a 0a * b / a = b

@[simp]
theorem int.div_self {a : } :
a 0a / a = 1

mod

theorem int.of_nat_mod (m n : ) :
m % n = int.of_nat (m % n)

@[simp]
theorem int.coe_nat_mod (m n : ) :
(m % n) = m % n

theorem int.neg_succ_of_nat_mod (m : ) {b : } :
0 < b-[1+ m] % b = b - 1 - m % b

@[simp]
theorem int.mod_neg (a b : ) :
a % -b = a % b

@[simp]
theorem int.mod_abs (a b : ) :
a % abs b = a % b

theorem int.zero_mod (b : ) :
0 % b = 0

theorem int.mod_zero (a : ) :
a % 0 = a

theorem int.mod_one (a : ) :
a % 1 = 0

theorem int.mod_eq_of_lt {a b : } :
0 aa < ba % b = a

theorem int.mod_nonneg (a : ) {b : } :
b 00 a % b

theorem int.mod_lt_of_pos (a : ) {b : } :
0 < ba % b < b

theorem int.mod_lt (a : ) {b : } :
b 0a % b < abs b

theorem int.mod_add_div_aux (m n : ) :
n - (m % n + 1) - ((n) * (m / n) + n) = -[1+ m]

theorem int.mod_add_div (a b : ) :
a % b + b * (a / b) = a

theorem int.mod_def (a b : ) :
a % b = a - b * (a / b)

@[simp]
theorem int.add_mul_mod_self {a b c : } :
(a + b * c) % c = a % c

@[simp]
theorem int.add_mul_mod_self_left (a b c : ) :
(a + b * c) % b = a % b

@[simp]
theorem int.add_mod_self {a b : } :
(a + b) % b = a % b

@[simp]
theorem int.add_mod_self_left {a b : } :
(a + b) % a = b % a

@[simp]
theorem int.mod_add_mod (m n k : ) :
(m % n + k) % n = (m + k) % n

@[simp]
theorem int.add_mod_mod (m n k : ) :
(m + n % k) % k = (m + n) % k

theorem int.add_mod (a b n : ) :
(a + b) % n = (a % n + b % n) % n

theorem int.add_mod_eq_add_mod_right {m n k : } (i : ) :
m % n = k % n(m + i) % n = (k + i) % n

theorem int.add_mod_eq_add_mod_left {m n k : } (i : ) :
m % n = k % n(i + m) % n = (i + k) % n

theorem int.mod_add_cancel_right {m n k : } (i : ) :
(m + i) % n = (k + i) % n m % n = k % n

theorem int.mod_add_cancel_left {m n k i : } :
(i + m) % n = (i + k) % n m % n = k % n

theorem int.mod_sub_cancel_right {m n k : } (i : ) :
(m - i) % n = (k - i) % n m % n = k % n

theorem int.mod_eq_mod_iff_mod_sub_eq_zero {m n k : } :
m % n = k % n (m - k) % n = 0

@[simp]
theorem int.mul_mod_left (a b : ) :
a * b % b = 0

@[simp]
theorem int.mul_mod_right (a b : ) :
a * b % a = 0

theorem int.mul_mod (a b n : ) :
a * b % n = (a % n) * (b % n) % n

theorem int.mod_self {a : } :
a % a = 0

@[simp]
theorem int.mod_mod_of_dvd (n : ) {m k : } :
m kn % k % m = n % m

@[simp]
theorem int.mod_mod (a b : ) :
a % b % b = a % b

theorem int.sub_mod (a b n : ) :
(a - b) % n = (a % n - b % n) % n

properties of / and %

@[simp]
theorem int.mul_div_mul_of_pos {a : } (b c : ) :
0 < aa * b / a * c = b / c

@[simp]
theorem int.mul_div_mul_of_pos_left (a : ) {b : } (c : ) :
0 < ba * b / c * b = a / c

@[simp]
theorem int.mul_mod_mul_of_pos {a : } (b c : ) :
0 < aa * b % a * c = a * (b % c)

theorem int.lt_div_add_one_mul_self (a : ) {b : } :
0 < ba < (a / b + 1) * b

theorem int.abs_div_le_abs (a b : ) :
abs (a / b) abs a

theorem int.div_le_self {a : } (b : ) :
0 aa / b a

theorem int.mul_div_cancel_of_mod_eq_zero {a b : } :
a % b = 0b * (a / b) = a

theorem int.div_mul_cancel_of_mod_eq_zero {a b : } :
a % b = 0(a / b) * b = a

theorem int.mod_two_eq_zero_or_one (n : ) :
n % 2 = 0 n % 2 = 1

dvd

theorem int.coe_nat_dvd {m n : } :
m n m n

theorem int.coe_nat_dvd_left {n : } {z : } :

theorem int.coe_nat_dvd_right {n : } {z : } :

theorem int.dvd_antisymm {a b : } :
0 a0 ba bb aa = b

theorem int.dvd_of_mod_eq_zero {a b : } :
b % a = 0a b

theorem int.mod_eq_zero_of_dvd {a b : } :
a bb % a = 0

theorem int.dvd_iff_mod_eq_zero (a b : ) :
a b b % a = 0

theorem int.dvd_sub_of_mod_eq {a b c : } :
a % b = cb a - c

If a % b = c then b divides a - c.

theorem int.nat_abs_dvd {a b : } :
(a.nat_abs) b a b

theorem int.dvd_nat_abs {a b : } :
a (b.nat_abs) a b

theorem int.div_mul_cancel {a b : } :
b a(a / b) * b = a

theorem int.mul_div_cancel' {a b : } :
a ba * (b / a) = b

theorem int.mul_div_assoc (a : ) {b c : } :
c ba * b / c = a * (b / c)

theorem int.div_dvd_div {a b c : } :
a bb cb / a c / a

theorem int.eq_mul_of_div_eq_right {a b c : } :
b aa / b = ca = b * c

theorem int.div_eq_of_eq_mul_right {a b c : } :
b 0a = b * ca / b = c

theorem int.eq_div_of_mul_eq_right {a b c : } :
a 0a * b = cb = c / a

theorem int.div_eq_iff_eq_mul_right {a b c : } :
b 0b a(a / b = c a = b * c)

theorem int.div_eq_iff_eq_mul_left {a b c : } :
b 0b a(a / b = c a = c * b)

theorem int.eq_mul_of_div_eq_left {a b c : } :
b aa / b = ca = c * b

theorem int.div_eq_of_eq_mul_left {a b c : } :
b 0a = c * ba / b = c

theorem int.neg_div_of_dvd {a b : } :
b a-a / b = -(a / b)

theorem int.add_div_of_dvd {a b c : } :
c ac b(a + b) / c = a / c + b / c

theorem int.div_sign (a b : ) :
a / b.sign = a * b.sign

@[simp]
theorem int.sign_mul (a b : ) :
(a * b).sign = (a.sign) * b.sign

theorem int.sign_eq_div_abs (a : ) :
a.sign = a / abs a

theorem int.mul_sign (i : ) :
i * i.sign = (i.nat_abs)

theorem int.le_of_dvd {a b : } :
0 < ba ba b

theorem int.eq_one_of_dvd_one {a : } :
0 aa 1a = 1

theorem int.eq_one_of_mul_eq_one_right {a b : } :
0 aa * b = 1a = 1

theorem int.eq_one_of_mul_eq_one_left {a b : } :
0 ba * b = 1b = 1

theorem int.of_nat_dvd_of_dvd_nat_abs {a : } {z : } :
a z.nat_absa z

theorem int.dvd_nat_abs_of_of_nat_dvd {a : } {z : } :
a za z.nat_abs

theorem int.pow_dvd_of_le_of_pow_dvd {p m n : } {k : } :
m n(p ^ n) k(p ^ m) k

theorem int.dvd_of_pow_dvd {p k : } {m : } :
1 k(p ^ k) mp m

theorem int.exists_lt_and_lt_iff_not_dvd (m : ) {n : } :
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.

/ and ordering

theorem int.div_mul_le (a : ) {b : } :
b 0(a / b) * b a

theorem int.div_le_of_le_mul {a b c : } :
0 < ca b * ca / c b

theorem int.mul_lt_of_lt_div {a b c : } :
0 < ca < b / ca * c < b

theorem int.mul_le_of_le_div {a b c : } :
0 < ca b / ca * c b

theorem int.le_div_of_mul_le {a b c : } :
0 < ca * c ba b / c

theorem int.le_div_iff_mul_le {a b c : } :
0 < c(a b / c a * c b)

theorem int.div_le_div {a b c : } :
0 < ca ba / c b / c

theorem int.div_lt_of_lt_mul {a b c : } :
0 < ca < b * ca / c < b

theorem int.lt_mul_of_div_lt {a b c : } :
0 < ca / c < ba < b * c

theorem int.div_lt_iff_lt_mul {a b c : } :
0 < c(a / c < b a < b * c)

theorem int.le_mul_of_div_le {a b c : } :
0 bb aa / b ca c * b

theorem int.lt_div_of_mul_lt {a b c : } :
0 bb ca * b < ca < c / b

theorem int.lt_div_iff_mul_lt {a b : } (c : ) :
0 < cc b(a < b / c a * c < b)

theorem int.div_pos_of_pos_of_dvd {a b : } :
0 < a0 bb a0 < a / b

theorem int.div_eq_div_of_mul_eq_mul {a b c d : } :
d cb 0d 0a * d = b * ca / b = c / d

theorem int.eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : } :
b 0b cb * a = c * da = (c / b) * d

theorem int.eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a b : } :
a bb.nat_abs < a.nat_absb = 0

If an integer with larger absolute value divides an integer, it is zero.

theorem int.eq_zero_of_dvd_of_nonneg_of_lt {a b : } :
0 aa < bb aa = 0

theorem int.eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a b c : } :
a % b = c(a - c).nat_abs < b.nat_absa = c

If two integers are congruent to a sufficiently large modulus, they are equal.

@[simp]
theorem int.neg_add_neg (m n : ) :
-[1+ m] + -[1+ n] = -[1+ (m + n).succ]

to_nat

theorem int.to_nat_eq_max (a : ) :
(a.to_nat) = max a 0

@[simp]
theorem int.to_nat_zero  :
0.to_nat = 0

@[simp]
theorem int.to_nat_one  :
1.to_nat = 1

@[simp]
theorem int.to_nat_of_nonneg {a : } :
0 a(a.to_nat) = a

@[simp]
theorem int.to_nat_sub_of_le (a b : ) :
b a((a + -b).to_nat) = a + -b

@[simp]
theorem int.to_nat_coe_nat (n : ) :

@[simp]
theorem int.to_nat_coe_nat_add_one {n : } :
(n + 1).to_nat = n + 1

theorem int.le_to_nat (a : ) :

@[simp]
theorem int.to_nat_le {a : } {n : } :

@[simp]
theorem int.lt_to_nat {n : } {a : } :
n < a.to_nat n < a

theorem int.to_nat_le_to_nat {a b : } :
a ba.to_nat b.to_nat

theorem int.to_nat_lt_to_nat {a b : } :
0 < b(a.to_nat < b.to_nat a < b)

theorem int.lt_of_to_nat_lt {a b : } :
a.to_nat < b.to_nata < b

theorem int.to_nat_add {a b : } :
0 a0 b(a + b).to_nat = a.to_nat + b.to_nat

theorem int.to_nat_add_one {a : } :
0 a(a + 1).to_nat = a.to_nat + 1

def int.to_nat'  :

If n : ℕ, then int.to_nat' n = some n, if n : ℤ is negative, then int.to_nat' n = none.

Equations
theorem int.mem_to_nat' (a : ) (n : ) :

theorem int.to_nat_zero_of_neg {z : } :
z < 0z.to_nat = 0

units

@[simp]
theorem int.units_nat_abs (u : units ) :

theorem int.units_eq_one_or (u : units ) :
u = 1 u = -1

bitwise ops

@[simp]
theorem int.bodd_zero  :

@[simp]
theorem int.bodd_one  :

theorem int.bodd_two  :

@[simp]
theorem int.bodd_coe (n : ) :

@[simp]
theorem int.bodd_sub_nat_nat (m n : ) :

@[simp]
theorem int.bodd_neg_of_nat (n : ) :

@[simp]
theorem int.bodd_neg (n : ) :
(-n).bodd = n.bodd

@[simp]
theorem int.bodd_add (m n : ) :
(m + n).bodd = bxor m.bodd n.bodd

@[simp]
theorem int.bodd_mul (m n : ) :
(m * n).bodd = m.bodd && n.bodd

theorem int.bodd_add_div2 (n : ) :
cond n.bodd 1 0 + 2 * n.div2 = n

theorem int.div2_val (n : ) :
n.div2 = n / 2

theorem int.bit0_val (n : ) :
bit0 n = 2 * n

theorem int.bit1_val (n : ) :
bit1 n = 2 * n + 1

theorem int.bit_val (b : bool) (n : ) :
int.bit b n = 2 * n + cond b 1 0

theorem int.bit_decomp (n : ) :

def int.bit_cases_on {C : Sort u} (n : ) :
(Π (b : bool) (n : ), C (int.bit b n))C n

Defines a function from conditionally, if it is defined for odd and even integers separately using bit.

Equations
@[simp]
theorem int.bit_zero  :

@[simp]
theorem int.bit_coe_nat (b : bool) (n : ) :

@[simp]
theorem int.bit_neg_succ (b : bool) (n : ) :

@[simp]
theorem int.bodd_bit (b : bool) (n : ) :
(int.bit b n).bodd = b

@[simp]
theorem int.bodd_bit0 (n : ) :

@[simp]
theorem int.bodd_bit1 (n : ) :

@[simp]
theorem int.div2_bit (b : bool) (n : ) :
(int.bit b n).div2 = n

theorem int.bit0_ne_bit1 (m n : ) :

theorem int.bit1_ne_bit0 (m n : ) :

theorem int.bit1_ne_zero (m : ) :
bit1 m 0

@[simp]
theorem int.test_bit_zero (b : bool) (n : ) :
(int.bit b n).test_bit 0 = b

@[simp]
theorem int.test_bit_succ (m : ) (b : bool) (n : ) :

theorem int.bitwise_diff  :
int.bitwise (λ (a b : bool), a && !b) = int.ldiff

@[simp]
theorem int.bitwise_bit (f : boolboolbool) (a : bool) (m : ) (b : bool) (n : ) :
int.bitwise f (int.bit a m) (int.bit b n) = int.bit (f a b) (int.bitwise f m n)

@[simp]
theorem int.lor_bit (a : bool) (m : ) (b : bool) (n : ) :
(int.bit a m).lor (int.bit b n) = int.bit (a || b) (m.lor n)

@[simp]
theorem int.land_bit (a : bool) (m : ) (b : bool) (n : ) :
(int.bit a m).land (int.bit b n) = int.bit (a && b) (m.land n)

@[simp]
theorem int.ldiff_bit (a : bool) (m : ) (b : bool) (n : ) :
(int.bit a m).ldiff (int.bit b n) = int.bit (a && !b) (m.ldiff n)

@[simp]
theorem int.lxor_bit (a : bool) (m : ) (b : bool) (n : ) :
(int.bit a m).lxor (int.bit b n) = int.bit (bxor a b) (m.lxor n)

@[simp]
theorem int.lnot_bit (b : bool) (n : ) :
(int.bit b n).lnot = int.bit (!b) n.lnot

@[simp]
theorem int.test_bit_bitwise (f : boolboolbool) (m n : ) (k : ) :
(int.bitwise f m n).test_bit k = f (m.test_bit k) (n.test_bit k)

@[simp]
theorem int.test_bit_lor (m n : ) (k : ) :
(m.lor n).test_bit k = m.test_bit k || n.test_bit k

@[simp]
theorem int.test_bit_land (m n : ) (k : ) :
(m.land n).test_bit k = m.test_bit k && n.test_bit k

@[simp]
theorem int.test_bit_ldiff (m n : ) (k : ) :

@[simp]
theorem int.test_bit_lxor (m n : ) (k : ) :
(m.lxor n).test_bit k = bxor (m.test_bit k) (n.test_bit k)

@[simp]
theorem int.test_bit_lnot (n : ) (k : ) :

theorem int.shiftl_add (m : ) (n : ) (k : ) :
m.shiftl (n + k) = (m.shiftl n).shiftl k

theorem int.shiftl_sub (m : ) (n : ) (k : ) :
m.shiftl (n - k) = (m.shiftl n).shiftr k

@[simp]
theorem int.shiftl_neg (m n : ) :
m.shiftl (-n) = m.shiftr n

@[simp]
theorem int.shiftr_neg (m n : ) :
m.shiftr (-n) = m.shiftl n

@[simp]
theorem int.shiftl_coe_nat (m n : ) :

@[simp]
theorem int.shiftr_coe_nat (m n : ) :

@[simp]

@[simp]
theorem int.shiftr_neg_succ (m n : ) :

theorem int.shiftr_add (m : ) (n k : ) :

theorem int.shiftl_eq_mul_pow (m : ) (n : ) :
m.shiftl n = m * (2 ^ n)

theorem int.shiftr_eq_div_pow (m : ) (n : ) :
m.shiftr n = m / (2 ^ n)

theorem int.one_shiftl (n : ) :
1.shiftl n = (2 ^ n)

@[simp]
theorem int.zero_shiftl (n : ) :
0.shiftl n = 0

@[simp]
theorem int.zero_shiftr (n : ) :
0.shiftr n = 0

Least upper bound property for integers

theorem int.exists_least_of_bdd {P : → Prop} :
(∃ (b : ), ∀ (z : ), P zb z)(∃ (z : ), P z)(∃ (lb : ), P lb ∀ (z : ), P zlb z)

theorem int.exists_greatest_of_bdd {P : → Prop} :
(∃ (b : ), ∀ (z : ), P zz b)(∃ (z : ), P z)(∃ (ub : ), P ub ∀ (z : ), P zz ub)