(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Local Open Scope Z_scope.
(** 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). *)
Notation Ndiv_Zquot := N2Z.inj_quot (only parsing).
Notation Nmod_Zrem := N2Z.inj_rem (only parsing).
Notation Z_quot_rem_eq := Z.quot_rem' (only parsing).
Notation Zrem_lt := Z.rem_bound_abs (only parsing).
Notation Z_quot_mult := Z.quot_mul (only parsing).
(** Particular values taken for [a÷0] and [(Z.rem a 0)]. We avise to not rely on these arbitrary values. *)
(** This can also be said in a simpler way: *)
(** Reformulation of [Z.rem_bound_abs] in 2 then 4 particular cases. *)
(** * Unicity results *)
Definition Remainder a b r :=
(0 <= a /\ 0 <= r < Z.abs b) \/ (a <= 0 /\ -Z.abs b < r <= 0).
Definition Remainder_alt a b r :=
Z.abs r < Z.abs b /\ 0 <= r * a.
(** * Order results about Zrem and Zquot *)
(* Division of positive numbers is positive. *)
(** * 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 *)
(** Operations modulo. *)
(** A last inequality: *)
(** Particular case : dividing by 2 is related with parity *)
(** * Interaction with "historic" Zdiv *)
(** They agree at least on positive numbers: *)

Theorem Zrem_Zmod_pos : forall a b, 0 <= a -> 0 < b ->
Z.rem a b = a mod b.