(************************************************************************)
(*         *      The Rocq Prover / The Rocq Development Team           *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \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)         *)
(************************************************************************)
(** * Conversions from [N] to [nat] *)
Module N2Nat.
(** [N.to_nat] is a bijection between [N] and [nat], with [N.of_nat] as reciprocal. See [Nat2N.id] below for the dual equation. *)

(* Specifications: *)
Lemma id a : N.of_nat (N.to_nat a) = a.
(** [N.to_nat] is hence injective *)
Lemma inj a a' : N.to_nat a = N.to_nat a' -> a = a'.
Lemma inj_iff a a' : N.to_nat a = N.to_nat a' <-> a = a'.
(** Interaction of this translation and usual operations. *)
Lemma inj_0 : N.to_nat 0 = 0.
Lemma inj_succ_double a : N.to_nat (N.succ_double a) = S (2*(N.to_nat a)).
Lemma inj_succ a : N.to_nat (N.succ a) = S (N.to_nat a).
Lemma inj_add a a' :
N.to_nat (a + a') = N.to_nat a + N.to_nat a'.
Lemma inj_mul a a' :
N.to_nat (a * a') = N.to_nat a * N.to_nat a'.
Lemma inj_sub a a' :
N.to_nat (a - a') = N.to_nat a - N.to_nat a'.
Lemma inj_pred a : N.to_nat (N.pred a) = Nat.pred (N.to_nat a).
Lemma inj_div2 a : N.to_nat (N.div2 a) = Nat.div2 (N.to_nat a).
Lemma inj_compare a a' :
(a ?= a')%N = (N.to_nat a ?= N.to_nat a').
Lemma inj_div n m :
N.to_nat (n / m) = N.to_nat n / N.to_nat m.
Lemma inj_mod a a' :
N.to_nat (a mod a') = N.to_nat a mod N.to_nat a'.
Lemma inj_pow a a' :
N.to_nat (a ^ a') = N.to_nat a ^ N.to_nat a'.
Lemma inj_max a a' :
N.to_nat (N.max a a') = Nat.max (N.to_nat a) (N.to_nat a').
Lemma inj_min a a' :
N.to_nat (N.min a a') = Nat.min (N.to_nat a) (N.to_nat a').
Lemma inj_iter a {A} (f:A->A) (x:A) :
N.iter a f x = Nat.iter (N.to_nat a) f x.