(** * Conversions between [Z] and [N] *)
(** [Z.of_N] is a bijection between [N] and non-negative [Z], with [Z.to_N] (or [Z.abs_N]) as reciprocal. See [Z2N.id] below for the dual equation. *)

(* Specifications: *)
Lemma id n : Z.to_N (Z.of_N n) = n.
(** [Z.of_N] is hence injective *)
Lemma inj n m : Z.of_N n = Z.of_N m -> n = m.
Lemma inj_iff n m : Z.of_N n = Z.of_N m <-> n = m.
(** [Z.of_N] produce non-negative integers *)
Lemma is_nonneg n : 0 <= Z.of_N n.
(** [Z.of_N], basic equations *)
Lemma inj_0 : Z.of_N 0 = 0.
Lemma inj_pos p : Z.of_N (Npos p) = Zpos p.
(** [Z.of_N] and usual operations. *)
Lemma inj_compare n m : (Z.of_N n ?= Z.of_N m) = (n ?= m)%N.
Lemma inj_le n m : (n<=m)%N <-> Z.of_N n <= Z.of_N m.
Lemma inj_lt n m : (n<m)%N <-> Z.of_N n < Z.of_N m.
Lemma inj_ge n m : (n>=m)%N <-> Z.of_N n >= Z.of_N m.
Lemma inj_gt n m : (n>m)%N <-> Z.of_N n > Z.of_N m.
Lemma inj_abs_N z : Z.of_N (Z.abs_N z) = Z.abs z.
Lemma inj_add n m : Z.of_N (n+m) = Z.of_N n + Z.of_N m.
Lemma inj_mul n m : Z.of_N (n*m) = Z.of_N n * Z.of_N m.
Lemma inj_sub_max n m : Z.of_N (n-m) = Z.max 0 (Z.of_N n - Z.of_N m).
Lemma inj_sub n m : (m<=n)%N -> Z.of_N (n-m) = Z.of_N n - Z.of_N m.
Lemma inj_succ n : Z.of_N (N.succ n) = Z.succ (Z.of_N n).
Lemma inj_pred_max n : Z.of_N (N.pred n) = Z.max 0 (Z.pred (Z.of_N n)).
Lemma inj_pred n : (0<n)%N -> Z.of_N (N.pred n) = Z.pred (Z.of_N n).
Lemma inj_min n m : Z.of_N (N.min n m) = Z.min (Z.of_N n) (Z.of_N m).
Lemma inj_max n m : Z.of_N (N.max n m) = Z.max (Z.of_N n) (Z.of_N m).
Lemma inj_div n m : Z.of_N (n/m) = Z.of_N n / Z.of_N m.
Lemma inj_mod n m : Z.of_N (n mod m) = (Z.of_N n) mod (Z.of_N m).
Lemma inj_quot n m : Z.of_N (n/m) = Z.of_N n ÷ Z.of_N m.
Lemma inj_rem n m : Z.of_N (n mod m) = Z.rem (Z.of_N n) (Z.of_N m).
Lemma inj_div2 n : Z.of_N (N.div2 n) = Z.div2 (Z.of_N n).
Lemma inj_quot2 n : Z.of_N (N.div2 n) = Z.quot2 (Z.of_N n).
Lemma inj_pow n m : Z.of_N (n^m) = (Z.of_N n)^(Z.of_N m).
Lemma inj_testbit a n :
Z.testbit (Z.of_N a) (Z.of_N n) = N.testbit a n.