Library Coq.ZArith.Zquot
This file provides results about the Round-Toward-Zero Euclidean
division
Z.quotrem, whose projections are
Z.quot (noted ÷)
and
Z.rem.
This division and
Z.div agree only on positive numbers.
Otherwise,
Z.div performs Round-Toward-Bottom (a.k.a Floor).
This
Z.quot is compatible with the division of usual
programming languages such as Ocaml. In addition, it has nicer
properties with respect to opposite and other usual operations.
The definition of this division is now in file
BinIntDef,
while most of the results about here are now in the main module
BinInt.Z, thanks to the generic "Numbers" layer. Remain here:
- some compatibility notation for old names.
- some extra results with less preconditions (in particular
exploiting the arbitrary value of division by 0).
Particular values taken for a÷0 and (Z.rem a 0).
We avise to not rely on these arbitrary values.
The following results are expressed without the b<>0 condition
whenever possible.
The sign of the remainder is the one of a. Due to the possible
nullity of a, a general result is to be stated in the following form:
This can also be said in a simplier way:
Reformulation of Z.rem_bound_abs in 2 then 4 particular cases.
Order results about Zrem and Zquot
As soon as the divisor is greater or equal than 2,
the division is strictly decreasing.
<= is compatible with a positive division.
With our choice of division, rounding of (a÷b) is always done toward 0:
The previous inequalities between b*(a÷b) and a are exact
iff the modulo is zero.
A modulo cannot grow beyond its starting point.
Some additionnal inequalities about Zdiv.
Relations between usual operations and Zmod and Zdiv
First, a result that used to be always valid with Zdiv,
but must be restricted here.
For instance, now (9+(-5)*2) rem 2 = -1 <> 1 = 9 rem 2
Cancellations.
Operations modulo.
addition and modulo
Generally speaking, unlike with Zdiv, we don't have
(a+b) rem n = (a rem n + b rem n) rem n
for any a and b.
For instance, take (8 + (-10)) rem 3 = -2 whereas
(8 rem 3 + (-10 rem 3)) rem 3 = 1.
Unlike with Zdiv, the following result is true without restrictions.
A last inequality:
Z.rem is related to divisibility (see more in Znumtheory)
Particular case : dividing by 2 is related with parity
Interaction with "historic" Zdiv
They agree at least on positive numbers:
Modulos are null at the same places