Library Stdlib.NArith.Nnat


From Stdlib Require Import BinPos BinNat PeanoNat Pnat.

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.

Lemma id a : N.of_nat (N.to_nat a) = a.

N.to_nat is hence injective
Interaction of this translation and usual operations.

Conversions from nat to N


Module Nat2N.

N.of_nat is an bijection between nat and N, with N.to_nat as reciprocal. See N2Nat.id above for the dual equation.

Lemma id n : N.to_nat (N.of_nat n) = n.

#[global] Hint Rewrite id : Nnat.
Ltac nat2N := apply N2Nat.inj; now autorewrite with Nnat.

N.of_nat is hence injective
Interaction of this translation and usual operations.

Lemma inj_double n : N.of_nat (2*n) = N.double (N.of_nat n).

Lemma inj_succ_double n : N.of_nat (S (2*n)) = N.succ_double (N.of_nat n).

Lemma inj_succ n : N.of_nat (S n) = N.succ (N.of_nat n).

Lemma inj_pred n : N.of_nat (Nat.pred n) = N.pred (N.of_nat n).

Lemma inj_add n n' : N.of_nat (n+n') = (N.of_nat n + N.of_nat n')%N.

Lemma inj_sub n n' : N.of_nat (n-n') = (N.of_nat n - N.of_nat n')%N.

Lemma inj_mul n n' : N.of_nat (n*n') = (N.of_nat n * N.of_nat n')%N.

Lemma inj_div2 n : N.of_nat (Nat.div2 n) = N.div2 (N.of_nat n).

Lemma inj_compare n n' :
  (n ?= n') = (N.of_nat n ?= N.of_nat n')%N.

Lemma inj_div n n' :
  N.of_nat (n / n') = (N.of_nat n / N.of_nat n')%N.

Lemma inj_mod n n' :
  N.of_nat (n mod n') = (N.of_nat n mod N.of_nat n')%N.

Lemma inj_pow n n' :
  N.of_nat (n ^ n') = (N.of_nat n ^ N.of_nat n')%N.

Lemma inj_min n n' :
  N.of_nat (Nat.min n n') = N.min (N.of_nat n) (N.of_nat n').

Lemma inj_max n n' :
  N.of_nat (Nat.max n n') = N.max (N.of_nat n) (N.of_nat n').

Lemma inj_iter n {A} (f:A->A) (x:A) :
  Nat.iter n f x = N.iter (N.of_nat n) f x.

End Nat2N.

#[global] Hint Rewrite Nat2N.id : Nnat.

Compatibility notations