mathlib3 documentation

monlib / other.sonia

Useless and interesting fact(s) on naturals and integers #

Sonia recently asked me: "Is there a way to prove that a number is divisible by 9, by looking at the sum of its digits?" So here is the generalised version of the question.

Main results #

In both of the following results, b is a natural number greater than 1.

theorem int.sum_mod {n : } (x : fin n ) (a : ) :
finset.univ.sum (λ (i : fin n), x i) % a = finset.univ.sum (λ (i : fin n), x i % a) % a

(∑ i, x i) % a = (∑ i, (x i % a)) % a

theorem fin.succ_mod_self {n : } (hn : 1 < n) :
n.succ % n = 1
theorem fin.succ_pow_mod_self {n a : } (ha : 1 < a) :
a.succ ^ n % a = 1

a.succ ^ n % a = 1 when 1 < a

theorem int.mul_nat_succ_pow_mod_nat (a : ) {b n : } (hb : 1 < b) :
a * (b.succ ^ n) % b = a % b
theorem nat_repr_mod_eq_sum_repr_mod {a n : } (x : fin n ) (ha : 1 < a) :
finset.univ.sum (λ (i : fin n), x i * (a.succ) ^ i) % a = finset.univ.sum (λ (i : fin n), x i) % a

(∑ i, (x i * a.succ ^ i)) % a = (∑ i, x i) % a

theorem nat_dvd_repr_iff_nat_dvd_sum_repr {a n : } (x : fin n ) (ha : 1 < a) :
a finset.univ.sum (λ (i : fin n), x i * (a.succ) ^ i) a finset.univ.sum (λ (i : fin n), x i)

a ∣ (∑ i, (x i * a.succ ^ i)) ↔ a ∣ (∑ i, x i) in other words, a number in base a.succ is divisible by a, if and only if the sum of its digits is divisible by a