Library Stdlib.Numbers.Natural.Abstract.NDiv
Properties of Euclidean Division
We benefit from what already exists for NZ
Module Import Private_NZDiv := Nop <+ NZDivProp N N NP.
Ltac auto' := try rewrite <- neq_0_lt_0; auto using le_0_l.
Ltac auto' := try rewrite <- neq_0_lt_0; auto using le_0_l.
Let's now state again theorems, but without useless hypothesis.
Another formulation of the main equation
Uniqueness theorems
Theorem div_mod_unique :
forall b q1 q2 r1 r2, r1<b -> r2<b ->
b*q1+r1 == b*q2+r2 -> q1 == q2 /\ r1 == r2.
Theorem div_unique:
forall a b q r, r<b -> a == b*q + r -> q == a/b.
Theorem mod_unique:
forall a b q r, r<b -> a == b*q + r -> r == a mod b.
Theorem div_unique_exact: forall a b q, b~=0 -> a == b*q -> q == a/b.
A division by itself returns 1
A division of a small number by a bigger one yields zero.
Same situation, in term of modulo:
Lemma div_0_l: forall a, a~=0 -> 0/a == 0.
Lemma mod_0_l: forall a, a~=0 -> 0 mod a == 0.
Lemma div_1_r: forall a, a/1 == a.
Lemma mod_1_r: forall a, a mod 1 == 0.
Lemma div_1_l: forall a, 1<a -> 1/a == 0.
Lemma mod_1_l: forall a, 1<a -> 1 mod a == 1.
Lemma div_mul : forall a b, b~=0 -> (a*b)/b == a.
Lemma mod_mul : forall a b, b~=0 -> (a*b) mod b == 0.
Theorem mod_le: forall a b, b~=0 -> a mod b <= a.
Lemma div_str_pos : forall a b, 0<b<=a -> 0 < a/b.
Lemma div_small_iff : forall a b, b~=0 -> (a/b==0 <-> a<b).
Lemma mod_small_iff : forall a b, b~=0 -> (a mod b == a <-> a<b).
Lemma div_str_pos_iff : forall a b, b~=0 -> (0<a/b <-> b<=a).
As soon as the divisor is strictly greater than 1,
the division is strictly decreasing.
le is compatible with a positive division.
Lemma div_le_mono : forall a b c, c~=0 -> a<=b -> a/c <= b/c.
Lemma mul_div_le : forall a b, b~=0 -> b*(a/b) <= a.
Lemma mul_succ_div_gt: forall a b, b~=0 -> a < b*(S (a/b)).
The previous inequality is exact iff the modulo is zero.
Some additional inequalities about div.
Theorem div_lt_upper_bound:
forall a b q, b~=0 -> a < b*q -> a/b < q.
Theorem div_le_upper_bound:
forall a b q, b~=0 -> a <= b*q -> a/b <= q.
Theorem div_le_lower_bound:
forall a b q, b~=0 -> b*q <= a -> q <= a/b.
A division respects opposite monotonicity for the divisor
Lemma mod_add : forall a b c, c~=0 ->
(a + b * c) mod c == a mod c.
Lemma div_add : forall a b c, c~=0 ->
(a + b * c) / c == a / c + b.
Lemma div_add_l: forall a b c, b~=0 ->
(a * b + c) / b == a + c / b.
Cancellations.
Lemma div_mul_cancel_r : forall a b c, b~=0 -> c~=0 ->
(a*c)/(b*c) == a/b.
Lemma div_mul_cancel_l : forall a b c, b~=0 -> c~=0 ->
(c*a)/(c*b) == a/b.
Lemma mul_mod_distr_r: forall a b c, b~=0 -> c~=0 ->
(a*c) mod (b*c) == (a mod b) * c.
Lemma mul_mod_distr_l: forall a b c, b~=0 -> c~=0 ->
(c*a) mod (c*b) == c * (a mod b).
Operations modulo.
Theorem mod_mod: forall a n, n~=0 ->
(a mod n) mod n == a mod n.
Lemma mul_mod_idemp_l : forall a b n, n~=0 ->
((a mod n)*b) mod n == (a*b) mod n.
Lemma mul_mod_idemp_r : forall a b n, n~=0 ->
(a*(b mod n)) mod n == (a*b) mod n.
Theorem mul_mod: forall a b n, n~=0 ->
(a * b) mod n == ((a mod n) * (b mod n)) mod n.
Lemma add_mod_idemp_l : forall a b n, n~=0 ->
((a mod n)+b) mod n == (a+b) mod n.
Lemma add_mod_idemp_r : forall a b n, n~=0 ->
(a+(b mod n)) mod n == (a+b) mod n.
Theorem add_mod: forall a b n, n~=0 ->
(a+b) mod n == (a mod n + b mod n) mod n.
Lemma div_div : forall a b c, b~=0 -> c~=0 ->
(a/b)/c == a/(b*c).
Lemma mod_mul_r : forall a b c, b~=0 -> c~=0 ->
a mod (b*c) == a mod b + b*((a/b) mod c).
Lemma add_mul_mod_distr_l : forall a b c d, b~=0 -> 0<=d<c ->
(c*a+d) mod (c*b) == c*(a mod b)+d.
Lemma add_mul_mod_distr_r : forall a b c d, b~=0 -> 0<=d<c ->
(a*c+d) mod (b*c) == (a mod b)*c+d.
A last inequality:
mod is related to divisibility