(* Copyright 2001, 2009 Luc Rutten  This file is part of ModRed.  ModRed is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  ModRed is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License along with ModRed.  If not, see <http://www.gnu.org/licenses/>. *)
(* Preparations for fast modular reduction lemmas. *)
(* Coq 8.2 *)
Open Scope Z_scope.
Definition in_Z_ (m x : Z) := 0 <= x < m.
Definition Z_ (m : Z) := sig (in_Z_ m).
Coercion Z_from_Z_ (m : Z) (x : Z_ m) := proj1_sig (P := in_Z_ m) x.
Notation _Z := (Z_from_Z_ _).
Definition in_Zpls (x : Z) := 0 < x.
Definition Zpls := sig in_Zpls.
Coercion Zpls_ (x : Zpls) := proj1_sig (P := in_Zpls) x.

(* Specifications: *)
Lemma le_0__Z : forall (n : Z) (i : Z_ n), 0 <= i.
intros n i. case i. unfold in_Z_. simpl. tauto. Qed.
Lemma lt_z__Z : forall (n : Z) (i : Z_ n), i < n.
intros n i. case i. unfold in_Z_. simpl. tauto. Qed.
Lemma Zmod_le_0_z : forall x m : Z, 0 < m -> 0 <= x mod m.
intros x m H. elim (Z_mod_lt x m); omega. Qed.
Lemma Zmod_lt_z_m : forall x m : Z, 0 < m -> x mod m < m.
intros x m H. elim (Z_mod_lt x m); omega. Qed.
Lemma Zdiv_small_0 : forall x m : Z, 0 <= x -> x < m -> x / m = 0.
intros x m H H0. cut (m * (x / m) + x mod m < m). intro H1. cut (m * (x / m) < m).