Library Coq.Numbers.Integer.Abstract.ZDivTrunc
Euclidean Division for integers (Trunc convention)
We use here the convention known as Trunc, or Round-Toward-Zero,
where
a/b is the integer with the largest absolute value to
be between zero and the exact fraction. It can be summarized by:
a = bq+r /\ 0 <= |r| < |b| /\ Sign(r) = Sign(a)
This is the convention of Ocaml and many other systems (C, ASM, ...).
This convention is named "T" in the following paper:
R. Boute, "The Euclidean definition of the functions div and mod",
ACM Transactions on Programming Languages and Systems,
Vol. 14, No.2, pp. 127-144, April 1992.
See files
ZDivFloor and
ZDivEucl for others conventions.
We benefit from what already exists for NZ
Another formulation of the main equation
A few sign rules (simple ones)
Uniqueness theorems
A division by itself returns 1
A division of a small number by a bigger one yields zero.
Same situation, in term of remulo:
Basic values of divisions and modulo.
The sign of a rem b is the one of a (when it's not null)
Operations and absolute value
We have a general bound for absolute values
Order results about rem and quot
A modulo cannot grow beyond its starting point.
As soon as the divisor is strictly greater than 1,
the division is strictly decreasing.
le is compatible with a positive division.
With this choice of division,
rounding of quot is always done toward zero:
For positive numbers, considering S (a÷b) leads to an upper bound for a
Similar results with negative numbers
Inequality mul_quot_le is exact iff the modulo is zero.
Some additionnal inequalities about quot.
A division respects opposite monotonicity for the divisor
Relations between usual operations and rem and quot
Unlike with other division conventions, some results here aren't
always valid, and need to be restricted. For instance
(a+b*c) rem c <> a rem c for
a=9,b=-5,c=2
Cancellations.
Operations modulo.
addition and modulo
Generally speaking, unlike with other conventions, 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.
Conversely, the following results need less restrictions here.
A last inequality: