Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(* -*- coding: utf-8 -*- *)
(************************************************************************)
(* * 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) *)
(************************************************************************)
Binary Integers (Pierre Crégut, CNET, Lannion, France)
Require Export Arith_base. Require Import BinPos BinInt BinNat Pnat Nnat. Local Open Scope Z_scope.
Conversions between integers and natural numbers
Seven sections:
- chains of conversions (combining two conversions)
- module N2Z : from N to Z
- module Z2N : from Z to N (negative numbers rounded to 0)
- module Zabs2N : from Z to N (via the absolute value)
- module Nat2Z : from nat to Z
- module Z2Nat : from Z to nat (negative numbers rounded to 0)
- module Zabs2Nat : from Z to nat (via the absolute value)
When combining successive conversions, we have the following
commutative diagram:
---> Nat ---- | ^ | | | v Pos ---------> Z | | ^ | v | ----> N -----
n:natZ.of_N (N.of_nat n) = Z.of_nat nnow destruct n. Qed.n:natZ.of_N (N.of_nat n) = Z.of_nat nn:NZ.of_nat (N.to_nat n) = Z.of_N nn:NZ.of_nat (N.to_nat n) = Z.of_N np:positiveZ.of_nat (N.to_nat (N.pos p)) = Z.of_N (N.pos p)p:positiveZ.of_nat (Pos.to_nat p) = Z.pos pp:positivem:natH:Pos.to_nat p = S mZ.of_nat (Pos.to_nat p) = Z.pos pp:positivem:natH:Pos.to_nat p = S mZ.of_nat (S m) = Z.pos pp:positivem:natH:Pos.to_nat p = S mZ.pos (Pos.of_succ_nat m) = Z.pos pnow apply SuccNat2Pos.inv. Qed.p:positivem:natH:Pos.to_nat p = S mPos.of_succ_nat m = pp:positiveZ.of_nat (Pos.to_nat p) = Z.pos pp:positiveZ.of_nat (Pos.to_nat p) = Z.pos pp:positiven:natH:Pos.to_nat p = S nZ.of_nat (Pos.to_nat p) = Z.pos pp:positiven:natH:Pos.to_nat p = S nZ.of_nat (S n) = Z.pos pp:positiven:natH:Pos.to_nat p = S nZ.pos (Pos.of_succ_nat n) = Z.pos pnow apply SuccNat2Pos.inv. Qed.p:positiven:natH:Pos.to_nat p = S nPos.of_succ_nat n = pp:positiveZ.of_N (N.pos p) = Z.pos preflexivity. Qed.p:positiveZ.of_N (N.pos p) = Z.pos pp:positiveN.to_nat (N.pos p) = Pos.to_nat preflexivity. Qed.p:positiveN.to_nat (N.pos p) = Pos.to_nat pp:positiveN.of_nat (Pos.to_nat p) = N.pos pp:positiveN.of_nat (Pos.to_nat p) = N.pos pp:positiven:natH:Pos.to_nat p = S nN.of_nat (Pos.to_nat p) = N.pos pp:positiven:natH:Pos.to_nat p = S nN.of_nat (S n) = N.pos pp:positiven:natH:Pos.to_nat p = S nN.pos (Pos.of_succ_nat n) = N.pos pnow apply SuccNat2Pos.inv. Qed.p:positiven:natH:Pos.to_nat p = S nPos.of_succ_nat n = pn:ZN.to_nat (Z.to_N n) = Z.to_nat nnow destruct n. Qed.n:ZN.to_nat (Z.to_N n) = Z.to_nat nn:ZN.of_nat (Z.to_nat n) = Z.to_N nn:ZN.of_nat (Z.to_nat n) = Z.to_N napply positive_nat_N. Qed.p:positiveN.of_nat (Pos.to_nat p) = N.pos pn:ZN.to_nat (Z.abs_N n) = Z.abs_nat nnow destruct n. Qed.n:ZN.to_nat (Z.abs_N n) = Z.abs_nat nn:ZN.of_nat (Z.abs_nat n) = Z.abs_N ndestruct n; simpl; trivial; apply positive_nat_N. Qed.n:ZN.of_nat (Z.abs_nat n) = Z.abs_N n
Module N2Z.
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.
n:NZ.to_N (Z.of_N n) = nnow destruct n. Qed.n:NZ.to_N (Z.of_N n) = n
Z.of_N is hence injective
n, m:NZ.of_N n = Z.of_N m -> n = mdestruct n, m; simpl; congruence. Qed.n, m:NZ.of_N n = Z.of_N m -> n = mn, m:NZ.of_N n = Z.of_N m <-> n = mn, m:NZ.of_N n = Z.of_N m <-> n = mn, m:NZ.of_N n = Z.of_N m -> n = mn, m:Nn = m -> Z.of_N n = Z.of_N mintros; now f_equal. Qed.n, m:Nn = m -> Z.of_N n = Z.of_N m
Z.of_N produce non-negative integers
n:N0 <= Z.of_N nnow destruct n. Qed.n:N0 <= Z.of_N n
Z.of_N, basic equations
Z.of_N 0 = 0reflexivity. Qed.Z.of_N 0 = 0p:positiveZ.of_N (N.pos p) = Z.pos preflexivity. Qed.p:positiveZ.of_N (N.pos p) = Z.pos p
Z.of_N and usual operations.
n, m:N(Z.of_N n ?= Z.of_N m) = (n ?= m)%Nnow destruct n, m. Qed.n, m:N(Z.of_N n ?= Z.of_N m) = (n ?= m)%Nn, m:N(n <= m)%N <-> Z.of_N n <= Z.of_N mn, m:N(n <= m)%N <-> Z.of_N n <= Z.of_N mnow rewrite inj_compare. Qed.n, m:N(n <= m)%N <-> (Z.of_N n ?= Z.of_N m) <> Gtn, m:N(n < m)%N <-> Z.of_N n < Z.of_N mn, m:N(n < m)%N <-> Z.of_N n < Z.of_N mnow rewrite inj_compare. Qed.n, m:N(n < m)%N <-> (Z.of_N n ?= Z.of_N m) = Ltn, m:N(n >= m)%N <-> Z.of_N n >= Z.of_N mn, m:N(n >= m)%N <-> Z.of_N n >= Z.of_N mnow rewrite inj_compare. Qed.n, m:N(n >= m)%N <-> (Z.of_N n ?= Z.of_N m) <> Ltn, m:N(n > m)%N <-> Z.of_N n > Z.of_N mn, m:N(n > m)%N <-> Z.of_N n > Z.of_N mnow rewrite inj_compare. Qed.n, m:N(n > m)%N <-> (Z.of_N n ?= Z.of_N m) = Gtz:ZZ.of_N (Z.abs_N z) = Z.abs znow destruct z. Qed.z:ZZ.of_N (Z.abs_N z) = Z.abs zn, m:NZ.of_N (n + m) = Z.of_N n + Z.of_N mnow destruct n, m. Qed.n, m:NZ.of_N (n + m) = Z.of_N n + Z.of_N mn, m:NZ.of_N (n * m) = Z.of_N n * Z.of_N mnow destruct n, m. Qed.n, m:NZ.of_N (n * m) = Z.of_N n * Z.of_N mn, m:NZ.of_N (n - m) = Z.max 0 (Z.of_N n - Z.of_N m)n, m:NZ.of_N (n - m) = Z.max 0 (Z.of_N n - Z.of_N m)n, m:positiveZ.of_N match Pos.sub_mask n m with | Pos.IsPos p => N.pos p | _ => 0 end = Z.max 0 (Z.pos_sub n m)n, m:positiveZ.of_N match Pos.sub_mask n m with | Pos.IsPos p => N.pos p | _ => 0 end = Z.max 0 match Pos.mask2cmp (Pos.sub_mask n m) with | Eq => 0 | Lt => Z.neg (m - n) | Gt => Z.pos (n - m) endnow destruct (Pos.sub_mask n m). Qed.n, m:positiveZ.of_N match Pos.sub_mask n m with | Pos.IsPos p => N.pos p | _ => 0 end = Z.max 0 match Pos.mask2cmp (Pos.sub_mask n m) with | Eq => 0 | Lt => Z.neg match Pos.sub_mask m n with | Pos.IsPos z => z | _ => 1 end | Gt => Z.pos match Pos.sub_mask n m with | Pos.IsPos z => z | _ => 1 end endn, m:N(m <= n)%N -> Z.of_N (n - m) = Z.of_N n - Z.of_N mn, m:N(m <= n)%N -> Z.of_N (n - m) = Z.of_N n - Z.of_N mn, m:NH:(m <= n)%NZ.of_N (n - m) = Z.of_N n - Z.of_N mn, m:NH:(m <= n)%NZ.max 0 (Z.of_N n - Z.of_N m) = Z.of_N n - Z.of_N mn, m:NH:(m ?= n)%N <> GtZ.max 0 (Z.of_N n - Z.of_N m) = Z.of_N n - Z.of_N mdestruct (Z.of_N n - Z.of_N m); trivial; now destruct H. Qed.n, m:NH:CompOpp (Z.of_N n - Z.of_N m ?= 0) <> GtZ.max 0 (Z.of_N n - Z.of_N m) = Z.of_N n - Z.of_N mn:NZ.of_N (N.succ n) = Z.succ (Z.of_N n)n:NZ.of_N (N.succ n) = Z.succ (Z.of_N n)Z.of_N (N.succ 0) = Z.succ (Z.of_N 0)p:positiveZ.of_N (N.succ (N.pos p)) = Z.succ (Z.of_N (N.pos p))p:positiveZ.of_N (N.succ (N.pos p)) = Z.succ (Z.of_N (N.pos p))now rewrite Pos.add_1_r. Qed.p:positiveZ.pos (Pos.succ p) = Z.pos (p + 1)n:NZ.of_N (N.pred n) = Z.max 0 (Z.pred (Z.of_N n))n:NZ.of_N (N.pred n) = Z.max 0 (Z.pred (Z.of_N n))now rewrite N.pred_sub, inj_sub_max. Qed.n:NZ.of_N (N.pred n) = Z.max 0 (Z.of_N n + -1)n:N(0 < n)%N -> Z.of_N (N.pred n) = Z.pred (Z.of_N n)n:N(0 < n)%N -> Z.of_N (N.pred n) = Z.pred (Z.of_N n)n:NH:(0 < n)%NZ.of_N (N.pred n) = Z.pred (Z.of_N n)n:NH:(0 < n)%NZ.of_N (N.pred n) = Z.of_N n + -1now apply N.le_succ_l in H. Qed.n:NH:(0 < n)%N(1 <= n)%Nn, m:NZ.of_N (N.min n m) = Z.min (Z.of_N n) (Z.of_N m)n, m:NZ.of_N (N.min n m) = Z.min (Z.of_N n) (Z.of_N m)n, m:NZ.of_N match (n ?= m)%N with | Gt => m | _ => n end = match Z.of_N n ?= Z.of_N m with | Gt => Z.of_N m | _ => Z.of_N n endnow case N.compare. Qed.n, m:NZ.of_N match (n ?= m)%N with | Gt => m | _ => n end = match (n ?= m)%N with | Gt => Z.of_N m | _ => Z.of_N n endn, m:NZ.of_N (N.max n m) = Z.max (Z.of_N n) (Z.of_N m)n, m:NZ.of_N (N.max n m) = Z.max (Z.of_N n) (Z.of_N m)n, m:NZ.of_N match (n ?= m)%N with | Gt => n | _ => m end = match Z.of_N n ?= Z.of_N m with | Lt => Z.of_N m | _ => Z.of_N n endcase N.compare_spec; intros; subst; trivial. Qed.n, m:NZ.of_N match (n ?= m)%N with | Gt => n | _ => m end = match (n ?= m)%N with | Lt => Z.of_N m | _ => Z.of_N n endn, m:NZ.of_N (n / m) = Z.of_N n / Z.of_N mn, m:NZ.of_N (n / m) = Z.of_N n / Z.of_N mn:NZ.of_N (n / 0) = Z.of_N n / Z.of_N 0n:Nm:positiveZ.of_N (n / N.pos m) = Z.of_N n / Z.of_N (N.pos m)n:Nm:positiveZ.of_N (n / N.pos m) = Z.of_N n / Z.of_N (N.pos m)n:Nm:positive0 <= Z.of_N (n mod N.pos m) < Z.of_N (N.pos m)n:Nm:positiveZ.of_N n = Z.of_N (N.pos m) * Z.of_N (n / N.pos m) + Z.of_N (n mod N.pos m)n:Nm:positive0 <= Z.of_N (n mod N.pos m)n:Nm:positiveZ.of_N (n mod N.pos m) < Z.of_N (N.pos m)n:Nm:positiveZ.of_N n = Z.of_N (N.pos m) * Z.of_N (n / N.pos m) + Z.of_N (n mod N.pos m)n:Nm:positiveZ.of_N (n mod N.pos m) < Z.of_N (N.pos m)n:Nm:positiveZ.of_N n = Z.of_N (N.pos m) * Z.of_N (n / N.pos m) + Z.of_N (n mod N.pos m)n:Nm:positive(n mod N.pos m < N.pos m)%Nn:Nm:positiveZ.of_N n = Z.of_N (N.pos m) * Z.of_N (n / N.pos m) + Z.of_N (n mod N.pos m)n:Nm:positiveZ.of_N n = Z.of_N (N.pos m) * Z.of_N (n / N.pos m) + Z.of_N (n mod N.pos m)n:Nm:positiveZ.of_N n = Z.of_N (N.pos m * (n / N.pos m) + n mod N.pos m)now apply N.div_mod. Qed.n:Nm:positiven = (N.pos m * (n / N.pos m) + n mod N.pos m)%Nn, m:Nm <> 0%N -> Z.of_N (n mod m) = Z.of_N n mod Z.of_N mn, m:Nm <> 0%N -> Z.of_N (n mod m) = Z.of_N n mod Z.of_N mn, m:NHm:m <> 0%NZ.of_N (n mod m) = Z.of_N n mod Z.of_N mn, m:NHm:m <> 0%N0 <= Z.of_N (n mod m) < Z.of_N mn, m:NHm:m <> 0%NZ.of_N n = Z.of_N m * Z.of_N (n / m) + Z.of_N (n mod m)n, m:NHm:m <> 0%N0 <= Z.of_N (n mod m)n, m:NHm:m <> 0%NZ.of_N (n mod m) < Z.of_N mn, m:NHm:m <> 0%NZ.of_N n = Z.of_N m * Z.of_N (n / m) + Z.of_N (n mod m)n, m:NHm:m <> 0%NZ.of_N (n mod m) < Z.of_N mn, m:NHm:m <> 0%NZ.of_N n = Z.of_N m * Z.of_N (n / m) + Z.of_N (n mod m)n, m:NHm:m <> 0%N(n mod m < m)%Nn, m:NHm:m <> 0%NZ.of_N n = Z.of_N m * Z.of_N (n / m) + Z.of_N (n mod m)n, m:NHm:m <> 0%NZ.of_N n = Z.of_N m * Z.of_N (n / m) + Z.of_N (n mod m)n, m:NHm:m <> 0%NZ.of_N n = Z.of_N (m * (n / m) + n mod m)now apply N.div_mod. Qed.n, m:NHm:m <> 0%Nn = (m * (n / m) + n mod m)%Nn, m:NZ.of_N (n / m) = Z.of_N n ÷ Z.of_N mn, m:NZ.of_N (n / m) = Z.of_N n ÷ Z.of_N mn:NZ.of_N (n / 0) = Z.of_N n ÷ Z.of_N 0n:Np:positiveZ.of_N (n / N.pos p) = Z.of_N n ÷ Z.of_N (N.pos p)now destruct n.n:NZ.of_N (n / 0) = Z.of_N n ÷ Z.of_N 0n:Np:positiveZ.of_N (n / N.pos p) = Z.of_N n ÷ Z.of_N (N.pos p)n:Np:positive0 <= Z.of_N nn:Np:positive0 < Z.of_N (N.pos p)easy. Qed.n:Np:positive0 < Z.of_N (N.pos p)n, m:NZ.of_N (n mod m) = Z.rem (Z.of_N n) (Z.of_N m)n, m:NZ.of_N (n mod m) = Z.rem (Z.of_N n) (Z.of_N m)n:NZ.of_N (n mod 0) = Z.rem (Z.of_N n) (Z.of_N 0)n:Np:positiveZ.of_N (n mod N.pos p) = Z.rem (Z.of_N n) (Z.of_N (N.pos p))now destruct n.n:NZ.of_N (n mod 0) = Z.rem (Z.of_N n) (Z.of_N 0)n:Np:positiveZ.of_N (n mod N.pos p) = Z.rem (Z.of_N n) (Z.of_N (N.pos p))n:Np:positiveN.pos p <> 0%Nn:Np:positive0 <= Z.of_N nn:Np:positive0 < Z.of_N (N.pos p)n:Np:positive0 <= Z.of_N nn:Np:positive0 < Z.of_N (N.pos p)easy. Qed.n:Np:positive0 < Z.of_N (N.pos p)n:NZ.of_N (N.div2 n) = Z.div2 (Z.of_N n)n:NZ.of_N (N.div2 n) = Z.div2 (Z.of_N n)now destruct p. Qed.p:positiveZ.of_N (N.div2 (N.pos p)) = Z.div2 (Z.of_N (N.pos p))n:NZ.of_N (N.div2 n) = Z.quot2 (Z.of_N n)n:NZ.of_N (N.div2 n) = Z.quot2 (Z.of_N n)now destruct p. Qed.p:positiveZ.of_N (N.div2 (N.pos p)) = Z.quot2 (Z.of_N (N.pos p))n, m:NZ.of_N (n ^ m) = Z.of_N n ^ Z.of_N mn, m:NZ.of_N (n ^ m) = Z.of_N n ^ Z.of_N mp:positiveZ.of_N (0 ^ N.pos p) = Z.of_N 0 ^ Z.of_N (N.pos p)p, p0:positiveZ.of_N (N.pos p ^ N.pos p0) = Z.of_N (N.pos p) ^ Z.of_N (N.pos p0)apply Pos2Z.inj_pow. Qed.p, p0:positiveZ.of_N (N.pos p ^ N.pos p0) = Z.of_N (N.pos p) ^ Z.of_N (N.pos p0)a, n:NZ.testbit (Z.of_N a) (Z.of_N n) = N.testbit a napply Z.testbit_of_N. Qed. End N2Z. Module Z2N.a, n:NZ.testbit (Z.of_N a) (Z.of_N n) = N.testbit a n
Z.to_N is a bijection between non-negative Z and N,
with Pos.of_N as reciprocal.
See N2Z.id above for the dual equation.
n:Z0 <= n -> Z.of_N (Z.to_N n) = ndestruct n; (now destruct 1) || trivial. Qed.n:Z0 <= n -> Z.of_N (Z.to_N n) = n
Z.to_N is hence injective for non-negative integers.
n, m:Z0 <= n -> 0 <= m -> Z.to_N n = Z.to_N m -> n = mn, m:Z0 <= n -> 0 <= m -> Z.to_N n = Z.to_N m -> n = mn, m:ZH:0 <= nH0:0 <= mH1:Z.to_N n = Z.to_N mn = mnow f_equal. Qed.n, m:ZH:0 <= nH0:0 <= mH1:Z.to_N n = Z.to_N mZ.of_N (Z.to_N n) = Z.of_N (Z.to_N m)n, m:Z0 <= n -> 0 <= m -> Z.to_N n = Z.to_N m <-> n = mn, m:Z0 <= n -> 0 <= m -> Z.to_N n = Z.to_N m <-> n = mn, m:ZH:0 <= nH0:0 <= mZ.to_N n = Z.to_N m <-> n = mn, m:ZH:0 <= nH0:0 <= mZ.to_N n = Z.to_N m -> n = mn, m:ZH:0 <= nH0:0 <= mn = m -> Z.to_N n = Z.to_N mintros; now subst. Qed.n, m:ZH:0 <= nH0:0 <= mn = m -> Z.to_N n = Z.to_N m
Z.to_N, basic equations
Z.to_N 0 = 0%Nreflexivity. Qed.Z.to_N 0 = 0%Nn:positiveZ.to_N (Z.pos n) = N.pos nreflexivity. Qed.n:positiveZ.to_N (Z.pos n) = N.pos nn:positiveZ.to_N (Z.neg n) = 0%Nreflexivity. Qed.n:positiveZ.to_N (Z.neg n) = 0%N
Z.to_N and operations
n, m:Z0 <= n -> 0 <= m -> Z.to_N (n + m) = (Z.to_N n + Z.to_N m)%Ndestruct n, m; trivial; (now destruct 1) || (now destruct 2). Qed.n, m:Z0 <= n -> 0 <= m -> Z.to_N (n + m) = (Z.to_N n + Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (n * m) = (Z.to_N n * Z.to_N m)%Ndestruct n, m; trivial; (now destruct 1) || (now destruct 2). Qed.n, m:Z0 <= n -> 0 <= m -> Z.to_N (n * m) = (Z.to_N n * Z.to_N m)%Nn:Z0 <= n -> Z.to_N (Z.succ n) = N.succ (Z.to_N n)n:Z0 <= n -> Z.to_N (Z.succ n) = N.succ (Z.to_N n)n:Z0 <= n -> Z.to_N (n + 1) = N.succ (Z.to_N n)n:ZH:0 <= nZ.to_N (n + 1) = N.succ (Z.to_N n)apply N.add_1_r. Qed.n:ZH:0 <= n(Z.to_N n + Z.to_N 1)%N = N.succ (Z.to_N n)n, m:Z0 <= m -> Z.to_N (n - m) = (Z.to_N n - Z.to_N m)%Nn, m:Z0 <= m -> Z.to_N (n - m) = (Z.to_N n - Z.to_N m)%Nn, m:positive0 <= Z.pos m -> Z.to_N (Z.pos n - Z.pos m) = (Z.to_N (Z.pos n) - Z.to_N (Z.pos m))%Nn, m:positiveZ.to_N (Z.pos n - Z.pos m) = (Z.to_N (Z.pos n) - Z.to_N (Z.pos m))%Nn, m:positiveZ.to_N (Z.pos_sub n m) = match Pos.sub_mask n m with | Pos.IsPos p => N.pos p | _ => 0%N endn, m:positiveZ.to_N match Pos.mask2cmp (Pos.sub_mask n m) with | Eq => 0 | Lt => Z.neg (m - n) | Gt => Z.pos (n - m) end = match Pos.sub_mask n m with | Pos.IsPos p => N.pos p | _ => 0%N endnow destruct (Pos.sub_mask n m). Qed.n, m:positiveZ.to_N match Pos.mask2cmp (Pos.sub_mask n m) with | Eq => 0 | Lt => Z.neg match Pos.sub_mask m n with | Pos.IsPos z => z | _ => 1 end | Gt => Z.pos match Pos.sub_mask n m with | Pos.IsPos z => z | _ => 1 end end = match Pos.sub_mask n m with | Pos.IsPos p => N.pos p | _ => 0%N endn:ZZ.to_N (Z.pred n) = N.pred (Z.to_N n)n:ZZ.to_N (Z.pred n) = N.pred (Z.to_N n)n:ZZ.to_N (n + -1) = N.pred (Z.to_N n)now apply (inj_sub n 1). Qed.n:ZZ.to_N (n + -1) = (Z.to_N n - 1)%Nn, m:Z0 <= n -> 0 <= m -> (Z.to_N n ?= Z.to_N m)%N = (n ?= m)n, m:Z0 <= n -> 0 <= m -> (Z.to_N n ?= Z.to_N m)%N = (n ?= m)now rewrite <- N2Z.inj_compare, !id. Qed.n, m:ZHn:0 <= nHm:0 <= m(Z.to_N n ?= Z.to_N m)%N = (n ?= m)n, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.to_N n <= Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.to_N n <= Z.to_N m)%Nn, m:ZHn:0 <= nHm:0 <= mn <= m <-> (Z.to_N n <= Z.to_N m)%Nnow rewrite inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) <> Gt <-> (Z.to_N n ?= Z.to_N m)%N <> Gtn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.to_N n < Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.to_N n < Z.to_N m)%Nn, m:ZHn:0 <= nHm:0 <= mn < m <-> (Z.to_N n < Z.to_N m)%Nnow rewrite inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) = Lt <-> (Z.to_N n ?= Z.to_N m)%N = Ltn, m:ZZ.to_N (Z.min n m) = N.min (Z.to_N n) (Z.to_N m)destruct n, m; simpl; trivial; unfold Z.min, N.min; simpl; now case Pos.compare. Qed.n, m:ZZ.to_N (Z.min n m) = N.min (Z.to_N n) (Z.to_N m)n, m:ZZ.to_N (Z.max n m) = N.max (Z.to_N n) (Z.to_N m)n, m:ZZ.to_N (Z.max n m) = N.max (Z.to_N n) (Z.to_N m)p, p0:positiveZ.to_N match (p ?= p0)%positive with | Lt => Z.pos p0 | _ => Z.pos p end = match (p ?= p0)%positive with | Gt => N.pos p | _ => N.pos p0 endp, p0:positiveZ.to_N match CompOpp (p ?= p0)%positive with | Lt => Z.neg p0 | _ => Z.neg p end = 0%Nnow case Pos.compare. Qed.p, p0:positiveZ.to_N match CompOpp (p ?= p0)%positive with | Lt => Z.neg p0 | _ => Z.neg p end = 0%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (n / m) = (Z.to_N n / Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (n / m) = (Z.to_N n / Z.to_N m)%Np, p0:positiveZ.to_N (Z.pos p / Z.pos p0) = (Z.to_N (Z.pos p) / Z.to_N (Z.pos p0))%Np, p0:positiveZ.to_N (Z.pos p / Z.pos p0) = (N.pos p / N.pos p0)%Np, p0:positiveZ.to_N (Z.pos p / Z.pos p0) = Z.to_N (Z.of_N (N.pos p / N.pos p0))now rewrite N2Z.inj_div. Qed.p, p0:positiveZ.pos p / Z.pos p0 = Z.of_N (N.pos p / N.pos p0)n, m:Z0 <= n -> 0 < m -> Z.to_N (n mod m) = (Z.to_N n mod Z.to_N m)%Nn, m:Z0 <= n -> 0 < m -> Z.to_N (n mod m) = (Z.to_N n mod Z.to_N m)%Np, p0:positiveZ.to_N (Z.pos p mod Z.pos p0) = (Z.to_N (Z.pos p) mod Z.to_N (Z.pos p0))%Np, p0:positiveZ.to_N (Z.pos p mod Z.pos p0) = (N.pos p mod N.pos p0)%Np, p0:positiveZ.to_N (Z.pos p mod Z.pos p0) = Z.to_N (Z.of_N (N.pos p mod N.pos p0))now rewrite N2Z.inj_mod. Qed.p, p0:positiveZ.pos p mod Z.pos p0 = Z.of_N (N.pos p mod N.pos p0)n, m:Z0 <= n -> 0 <= m -> Z.to_N (n ÷ m) = (Z.to_N n / Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (n ÷ m) = (Z.to_N n / Z.to_N m)%Nn:Z0 <= n -> 0 <= 0 -> Z.to_N (n ÷ 0) = (Z.to_N n / Z.to_N 0)%Nn:Zp:positive0 <= n -> 0 <= Z.pos p -> Z.to_N (n ÷ Z.pos p) = (Z.to_N n / Z.to_N (Z.pos p))%Nn:Zp:positive0 <= n -> 0 <= Z.neg p -> Z.to_N (n ÷ Z.neg p) = (Z.to_N n / Z.to_N (Z.neg p))%Nnow destruct n.n:Z0 <= n -> 0 <= 0 -> Z.to_N (n ÷ 0) = (Z.to_N n / Z.to_N 0)%Nn:Zp:positive0 <= n -> 0 <= Z.pos p -> Z.to_N (n ÷ Z.pos p) = (Z.to_N n / Z.to_N (Z.pos p))%Nnow rewrite Z.quot_div_nonneg, inj_div.n:Zp:positiveH:0 <= nH0:0 <= Z.pos pZ.to_N (n ÷ Z.pos p) = (Z.to_N n / Z.to_N (Z.pos p))%Nnow destruct 2. Qed.n:Zp:positive0 <= n -> 0 <= Z.neg p -> Z.to_N (n ÷ Z.neg p) = (Z.to_N n / Z.to_N (Z.neg p))%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (Z.rem n m) = (Z.to_N n mod Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (Z.rem n m) = (Z.to_N n mod Z.to_N m)%Nn:Z0 <= n -> 0 <= 0 -> Z.to_N (Z.rem n 0) = (Z.to_N n mod Z.to_N 0)%Nn:Zp:positive0 <= n -> 0 <= Z.pos p -> Z.to_N (Z.rem n (Z.pos p)) = (Z.to_N n mod Z.to_N (Z.pos p))%Nn:Zp:positive0 <= n -> 0 <= Z.neg p -> Z.to_N (Z.rem n (Z.neg p)) = (Z.to_N n mod Z.to_N (Z.neg p))%Nnow destruct n.n:Z0 <= n -> 0 <= 0 -> Z.to_N (Z.rem n 0) = (Z.to_N n mod Z.to_N 0)%Nn:Zp:positive0 <= n -> 0 <= Z.pos p -> Z.to_N (Z.rem n (Z.pos p)) = (Z.to_N n mod Z.to_N (Z.pos p))%Nnow rewrite Z.rem_mod_nonneg, inj_mod.n:Zp:positiveH:0 <= nH0:0 <= Z.pos pZ.to_N (Z.rem n (Z.pos p)) = (Z.to_N n mod Z.to_N (Z.pos p))%Nnow destruct 2. Qed.n:Zp:positive0 <= n -> 0 <= Z.neg p -> Z.to_N (Z.rem n (Z.neg p)) = (Z.to_N n mod Z.to_N (Z.neg p))%Nn:ZZ.to_N (Z.div2 n) = N.div2 (Z.to_N n)n:ZZ.to_N (Z.div2 n) = N.div2 (Z.to_N n)now destruct p. Qed.p:positiveZ.to_N (Z.div2 (Z.pos p)) = N.div2 (Z.to_N (Z.pos p))n:ZZ.to_N (Z.quot2 n) = N.div2 (Z.to_N n)destruct n as [|p|p]; trivial; now destruct p. Qed.n:ZZ.to_N (Z.quot2 n) = N.div2 (Z.to_N n)n, m:Z0 <= n -> 0 <= m -> Z.to_N (n ^ m) = (Z.to_N n ^ Z.to_N m)%Nn, m:Z0 <= n -> 0 <= m -> Z.to_N (n ^ m) = (Z.to_N n ^ Z.to_N m)%Nn:Z0 <= n -> 0 <= 0 -> Z.to_N (n ^ 0) = (Z.to_N n ^ Z.to_N 0)%Nn:Zp:positive0 <= n -> 0 <= Z.pos p -> Z.to_N (n ^ Z.pos p) = (Z.to_N n ^ Z.to_N (Z.pos p))%Nn:Zp:positive0 <= n -> 0 <= Z.neg p -> Z.to_N (n ^ Z.neg p) = (Z.to_N n ^ Z.to_N (Z.neg p))%Ntrivial.n:Z0 <= n -> 0 <= 0 -> Z.to_N (n ^ 0) = (Z.to_N n ^ Z.to_N 0)%Nn:Zp:positive0 <= n -> 0 <= Z.pos p -> Z.to_N (n ^ Z.pos p) = (Z.to_N n ^ Z.to_N (Z.pos p))%Nnow rewrite <- (N2Z.id (_ ^ _)), N2Z.inj_pow, id.n:Zp:positiveH:0 <= nH0:0 <= Z.pos pZ.to_N (n ^ Z.pos p) = (Z.to_N n ^ Z.to_N (Z.pos p))%Nnow destruct 2. Qed.n:Zp:positive0 <= n -> 0 <= Z.neg p -> Z.to_N (n ^ Z.neg p) = (Z.to_N n ^ Z.to_N (Z.neg p))%Na:Nn:Z0 <= n -> Z.testbit (Z.of_N a) n = N.testbit a (Z.to_N n)apply Z.testbit_of_N'. Qed. End Z2N. Module Zabs2N.a:Nn:Z0 <= n -> Z.testbit (Z.of_N a) n = N.testbit a (Z.to_N n)
Results about Z.abs_N, converting absolute values of Z integers
to N.
n:ZZ.abs_N n = Z.to_N (Z.abs n)now destruct n. Qed.n:ZZ.abs_N n = Z.to_N (Z.abs n)n:Z0 <= n -> Z.abs_N n = Z.to_N ndestruct n; trivial; now destruct 1. Qed.n:Z0 <= n -> Z.abs_N n = Z.to_N nn:ZZ.of_N (Z.abs_N n) = Z.abs nnow destruct n. Qed.n:ZZ.of_N (Z.abs_N n) = Z.abs nn:NZ.abs_N (Z.of_N n) = nnow destruct n. Qed.n:NZ.abs_N (Z.of_N n) = n
Z.abs_N, basic equations
Z.abs_N 0 = 0%Nreflexivity. Qed.Z.abs_N 0 = 0%Np:positiveZ.abs_N (Z.pos p) = N.pos preflexivity. Qed.p:positiveZ.abs_N (Z.pos p) = N.pos pp:positiveZ.abs_N (Z.neg p) = N.pos preflexivity. Qed.p:positiveZ.abs_N (Z.neg p) = N.pos p
Z.abs_N and usual operations, with non-negative integers
n:ZZ.abs_N (- n) = Z.abs_N nnow destruct n. Qed.n:ZZ.abs_N (- n) = Z.abs_N nn:Z0 <= n -> Z.abs_N (Z.succ n) = N.succ (Z.abs_N n)n:Z0 <= n -> Z.abs_N (Z.succ n) = N.succ (Z.abs_N n)n:ZH:0 <= nZ.abs_N (Z.succ n) = N.succ (Z.abs_N n)n:ZH:0 <= nZ.to_N (Z.succ n) = N.succ (Z.to_N n)n:ZH:0 <= n0 <= Z.succ nnow apply Z.le_le_succ_r. Qed.n:ZH:0 <= n0 <= Z.succ nn, m:Z0 <= n -> 0 <= m -> Z.abs_N (n + m) = (Z.abs_N n + Z.abs_N m)%Nn, m:Z0 <= n -> 0 <= m -> Z.abs_N (n + m) = (Z.abs_N n + Z.abs_N m)%Nn, m:ZH:0 <= nH0:0 <= mZ.abs_N (n + m) = (Z.abs_N n + Z.abs_N m)%Nn, m:ZH:0 <= nH0:0 <= mZ.to_N (n + m) = (Z.to_N n + Z.to_N m)%Nn, m:ZH:0 <= nH0:0 <= m0 <= n + mnow apply Z.add_nonneg_nonneg. Qed.n, m:ZH:0 <= nH0:0 <= m0 <= n + mn, m:ZZ.abs_N (n * m) = (Z.abs_N n * Z.abs_N m)%Nnow destruct n, m. Qed.n, m:ZZ.abs_N (n * m) = (Z.abs_N n * Z.abs_N m)%Nn, m:Z0 <= m <= n -> Z.abs_N (n - m) = (Z.abs_N n - Z.abs_N m)%Nn, m:Z0 <= m <= n -> Z.abs_N (n - m) = (Z.abs_N n - Z.abs_N m)%Nn, m:ZHn:0 <= mH:m <= nZ.abs_N (n - m) = (Z.abs_N n - Z.abs_N m)%Nn, m:ZHn:0 <= mH:m <= nZ.to_N (n - m) = (Z.to_N n - Z.to_N m)%Nn, m:ZHn:0 <= mH:m <= n0 <= nn, m:ZHn:0 <= mH:m <= n0 <= n - mn, m:ZHn:0 <= mH:m <= n0 <= nn, m:ZHn:0 <= mH:m <= n0 <= n - mnow apply Z.le_0_sub. Qed.n, m:ZHn:0 <= mH:m <= n0 <= n - mn:Z0 < n -> Z.abs_N (Z.pred n) = N.pred (Z.abs_N n)n:Z0 < n -> Z.abs_N (Z.pred n) = N.pred (Z.abs_N n)n:ZH:0 < nZ.abs_N (Z.pred n) = N.pred (Z.abs_N n)n:ZH:0 < nZ.to_N (Z.pred n) = N.pred (Z.to_N n)n:ZH:0 < n0 <= nn:ZH:0 < n0 <= Z.pred nn:ZH:0 < n0 <= nn:ZH:0 < n0 <= Z.pred nn:ZH:0 < n0 <= Z.pred nnow rewrite Z.succ_pred. Qed.n:ZH:0 < n0 < Z.succ (Z.pred n)n, m:Z0 <= n -> 0 <= m -> (Z.abs_N n ?= Z.abs_N m)%N = (n ?= m)n, m:Z0 <= n -> 0 <= m -> (Z.abs_N n ?= Z.abs_N m)%N = (n ?= m)n, m:ZH:0 <= nH0:0 <= m(Z.abs_N n ?= Z.abs_N m)%N = (n ?= m)now apply Z2N.inj_compare. Qed.n, m:ZH:0 <= nH0:0 <= m(Z.to_N n ?= Z.to_N m)%N = (n ?= m)n, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.abs_N n <= Z.abs_N m)%Nn, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.abs_N n <= Z.abs_N m)%Nn, m:ZHn:0 <= nHm:0 <= mn <= m <-> (Z.abs_N n <= Z.abs_N m)%Nnow rewrite inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) <> Gt <-> (Z.abs_N n ?= Z.abs_N m)%N <> Gtn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.abs_N n < Z.abs_N m)%Nn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.abs_N n < Z.abs_N m)%Nn, m:ZHn:0 <= nHm:0 <= mn < m <-> (Z.abs_N n < Z.abs_N m)%Nnow rewrite inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) = Lt <-> (Z.abs_N n ?= Z.abs_N m)%N = Ltn, m:Z0 <= n -> 0 <= m -> Z.abs_N (Z.min n m) = N.min (Z.abs_N n) (Z.abs_N m)n, m:Z0 <= n -> 0 <= m -> Z.abs_N (Z.min n m) = N.min (Z.abs_N n) (Z.abs_N m)n, m:ZH:0 <= nH0:0 <= mZ.abs_N (Z.min n m) = N.min (Z.abs_N n) (Z.abs_N m)n, m:ZH:0 <= nH0:0 <= mZ.to_N (Z.min n m) = N.min (Z.to_N n) (Z.to_N m)n, m:ZH:0 <= nH0:0 <= m0 <= Z.min n mnow apply Z.min_glb. Qed.n, m:ZH:0 <= nH0:0 <= m0 <= Z.min n mn, m:Z0 <= n -> 0 <= m -> Z.abs_N (Z.max n m) = N.max (Z.abs_N n) (Z.abs_N m)n, m:Z0 <= n -> 0 <= m -> Z.abs_N (Z.max n m) = N.max (Z.abs_N n) (Z.abs_N m)n, m:ZH:0 <= nH0:0 <= mZ.abs_N (Z.max n m) = N.max (Z.abs_N n) (Z.abs_N m)n, m:ZH:0 <= nH0:0 <= mZ.to_N (Z.max n m) = N.max (Z.to_N n) (Z.to_N m)n, m:ZH:0 <= nH0:0 <= m0 <= Z.max n mn, m:ZH:0 <= nH0:0 <= m0 <= Z.max n mapply Z.le_max_l. Qed.n, m:ZH:0 <= nH0:0 <= mn <= Z.max n mn, m:ZZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Nn, m:ZZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Nn, m:Zforall p q : positive, Z.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%Nn, m:ZH:forall p q : positive, Z.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%NZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Nn, m:Zp, q:positiveZ.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%Nn, m:ZH:forall p q : positive, Z.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%NZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Nn, m:Zp, q:positiveZ.to_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%Nn, m:Zp, q:positive0 <= Z.pos p ÷ Z.pos qn, m:ZH:forall p q : positive, Z.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%NZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Nn, m:Zp, q:positive0 <= Z.pos p ÷ Z.pos qn, m:ZH:forall p q : positive, Z.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%NZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Nn, m:ZH:forall p q : positive, Z.abs_N (Z.pos p ÷ Z.pos q) = (N.pos p / N.pos q)%NZ.abs_N (n ÷ m) = (Z.abs_N n / Z.abs_N m)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.pos p ÷ Z.pos p0) = (N.pos p / N.pos p0)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.pos p ÷ Z.neg p0) = (N.pos p / N.pos p0)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.neg p ÷ Z.pos p0) = (N.pos p / N.pos p0)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.neg p ÷ Z.neg p0) = (N.pos p / N.pos p0)%Ntrivial.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.pos p ÷ Z.pos p0) = (N.pos p / N.pos p0)%Nnow rewrite <- Pos2Z.opp_pos, Z.quot_opp_r, inj_opp.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.pos p ÷ Z.neg p0) = (N.pos p / N.pos p0)%Nnow rewrite <- Pos2Z.opp_pos, Z.quot_opp_l, inj_opp.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.neg p ÷ Z.pos p0) = (N.pos p / N.pos p0)%Nnow rewrite <- 2 Pos2Z.opp_pos, Z.quot_opp_opp. Qed.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.pos p1 ÷ Z.pos q) = (N.pos p1 / N.pos q)%NZ.abs_N (Z.neg p ÷ Z.neg p0) = (N.pos p / N.pos p0)%Nn, m:ZZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Nn, m:ZZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Nn, m:Zforall p q : positive, Z.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%Nn, m:ZH:forall p q : positive, Z.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%NZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Nn, m:Zp, q:positiveZ.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%Nn, m:ZH:forall p q : positive, Z.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%NZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Nn, m:Zp, q:positiveZ.to_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%Nn, m:Zp, q:positive0 <= Z.rem (Z.pos p) (Z.pos q)n, m:ZH:forall p q : positive, Z.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%NZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Nn, m:Zp, q:positive0 <= Z.rem (Z.pos p) (Z.pos q)n, m:ZH:forall p q : positive, Z.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%NZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Nn, m:ZH:forall p q : positive, Z.abs_N (Z.rem (Z.pos p) (Z.pos q)) = (N.pos p mod N.pos q)%NZ.abs_N (Z.rem n m) = (Z.abs_N n mod Z.abs_N m)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.pos p) (Z.pos p0)) = (N.pos p mod N.pos p0)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.pos p) (Z.neg p0)) = (N.pos p mod N.pos p0)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.neg p) (Z.pos p0)) = (N.pos p mod N.pos p0)%Np, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.neg p) (Z.neg p0)) = (N.pos p mod N.pos p0)%Ntrivial.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.pos p) (Z.pos p0)) = (N.pos p mod N.pos p0)%Nnow rewrite <- Pos2Z.opp_pos, Z.rem_opp_r.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.pos p) (Z.neg p0)) = (N.pos p mod N.pos p0)%Nnow rewrite <- Pos2Z.opp_pos, Z.rem_opp_l, inj_opp.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.neg p) (Z.pos p0)) = (N.pos p mod N.pos p0)%Nnow rewrite <- 2 Pos2Z.opp_pos, Z.rem_opp_opp, inj_opp. Qed.p, p0:positiveH:forall p1 q : positive, Z.abs_N (Z.rem (Z.pos p1) (Z.pos q)) = (N.pos p1 mod N.pos q)%NZ.abs_N (Z.rem (Z.neg p) (Z.neg p0)) = (N.pos p mod N.pos p0)%Nn, m:Z0 <= m -> Z.abs_N (n ^ m) = (Z.abs_N n ^ Z.abs_N m)%Nn, m:Z0 <= m -> Z.abs_N (n ^ m) = (Z.abs_N n ^ Z.abs_N m)%Nn, m:ZHm:0 <= mZ.abs_N (n ^ m) = (Z.abs_N n ^ Z.abs_N m)%Nn, m:ZHm:0 <= m(Z.abs_N n ^ Z.to_N m)%N = (Z.abs_N n ^ Z.abs_N m)%Nn, m:ZHm:0 <= m0 <= Z.abs nn, m:ZHm:0 <= mZ.to_N m = Z.abs_N mn, m:ZHm:0 <= m0 <= Z.abs napply Z.abs_nonneg. Qed.n, m:ZHm:0 <= m0 <= Z.abs n
Z.abs_N and usual operations, statements with Z.abs
n:ZZ.abs_N (Z.succ (Z.abs n)) = N.succ (Z.abs_N n)destruct n; simpl; trivial; now rewrite Pos.add_1_r. Qed.n:ZZ.abs_N (Z.succ (Z.abs n)) = N.succ (Z.abs_N n)n, m:ZZ.abs_N (Z.abs n + Z.abs m) = (Z.abs_N n + Z.abs_N m)%Nnow destruct n, m. Qed.n, m:ZZ.abs_N (Z.abs n + Z.abs m) = (Z.abs_N n + Z.abs_N m)%Nn, m:ZZ.abs_N (Z.abs n * Z.abs m) = (Z.abs_N n * Z.abs_N m)%Nnow destruct n, m. Qed. End Zabs2N.n, m:ZZ.abs_N (Z.abs n * Z.abs m) = (Z.abs_N n * Z.abs_N m)%N
Module Nat2Z.
Z.of_nat, basic equations
Z.of_nat 0 = 0reflexivity. Qed.Z.of_nat 0 = 0n:natZ.of_nat (S n) = Z.succ (Z.of_nat n)n:natZ.of_nat (S n) = Z.succ (Z.of_nat n)Z.of_nat 1 = Z.succ (Z.of_nat 0)n:natZ.of_nat (S (S n)) = Z.succ (Z.of_nat (S n))n:natZ.of_nat (S (S n)) = Z.succ (Z.of_nat (S n))apply Pos2Z.inj_succ. Qed. Register inj_succ as num.Nat2Z.inj_succ.n:natZ.pos (Pos.succ (Pos.of_succ_nat n)) = Z.pos (Pos.of_succ_nat n + 1)
Z.of_N produce non-negative integers
n:nat0 <= Z.of_nat nnow induction n. Qed.n:nat0 <= Z.of_nat n
Z.of_nat is a bijection between nat and non-negative Z,
with Z.to_nat (or Z.abs_nat) as reciprocal.
See Z2Nat.id below for the dual equation.
n:natZ.to_nat (Z.of_nat n) = nnow rewrite <- nat_N_Z, <- Z_N_nat, N2Z.id, Nat2N.id. Qed.n:natZ.to_nat (Z.of_nat n) = n
Z.of_nat is hence injective
n, m:natZ.of_nat n = Z.of_nat m -> n = mn, m:natZ.of_nat n = Z.of_nat m -> n = mnow rewrite <- (id n), <- (id m), H. Qed.n, m:natH:Z.of_nat n = Z.of_nat mn = mn, m:natZ.of_nat n = Z.of_nat m <-> n = mn, m:natZ.of_nat n = Z.of_nat m <-> n = mn, m:natZ.of_nat n = Z.of_nat m -> n = mn, m:natn = m -> Z.of_nat n = Z.of_nat mintros; now f_equal. Qed.n, m:natn = m -> Z.of_nat n = Z.of_nat m
Z.of_nat and usual operations
n, m:nat(Z.of_nat n ?= Z.of_nat m) = (n ?= m)%natnow rewrite <-!nat_N_Z, N2Z.inj_compare, <- Nat2N.inj_compare. Qed.n, m:nat(Z.of_nat n ?= Z.of_nat m) = (n ?= m)%natn, m:nat(n <= m)%nat <-> Z.of_nat n <= Z.of_nat mn, m:nat(n <= m)%nat <-> Z.of_nat n <= Z.of_nat mnow rewrite inj_compare, nat_compare_le. Qed.n, m:nat(n <= m)%nat <-> (Z.of_nat n ?= Z.of_nat m) <> Gtn, m:nat(n < m)%nat <-> Z.of_nat n < Z.of_nat mn, m:nat(n < m)%nat <-> Z.of_nat n < Z.of_nat mnow rewrite inj_compare, nat_compare_lt. Qed.n, m:nat(n < m)%nat <-> (Z.of_nat n ?= Z.of_nat m) = Ltn, m:nat(n >= m)%nat <-> Z.of_nat n >= Z.of_nat mn, m:nat(n >= m)%nat <-> Z.of_nat n >= Z.of_nat mnow rewrite inj_compare, nat_compare_ge. Qed.n, m:nat(n >= m)%nat <-> (Z.of_nat n ?= Z.of_nat m) <> Ltn, m:nat(n > m)%nat <-> Z.of_nat n > Z.of_nat mn, m:nat(n > m)%nat <-> Z.of_nat n > Z.of_nat mnow rewrite inj_compare, nat_compare_gt. Qed.n, m:nat(n > m)%nat <-> (Z.of_nat n ?= Z.of_nat m) = Gtz:ZZ.of_nat (Z.abs_nat z) = Z.abs zdestruct z; simpl; trivial; destruct (Pos2Nat.is_succ p) as (n,H); rewrite H; simpl; f_equal; now apply SuccNat2Pos.inv. Qed.z:ZZ.of_nat (Z.abs_nat z) = Z.abs zn, m:natZ.of_nat (n + m) = Z.of_nat n + Z.of_nat mnow rewrite <- !nat_N_Z, Nat2N.inj_add, N2Z.inj_add. Qed. Register inj_add as num.Nat2Z.inj_add.n, m:natZ.of_nat (n + m) = Z.of_nat n + Z.of_nat mn, m:natZ.of_nat (n * m) = Z.of_nat n * Z.of_nat mnow rewrite <- !nat_N_Z, Nat2N.inj_mul, N2Z.inj_mul. Qed. Register inj_mul as num.Nat2Z.inj_mul.n, m:natZ.of_nat (n * m) = Z.of_nat n * Z.of_nat mn, m:natZ.of_nat (n - m) = Z.max 0 (Z.of_nat n - Z.of_nat m)now rewrite <- !nat_N_Z, Nat2N.inj_sub, N2Z.inj_sub_max. Qed.n, m:natZ.of_nat (n - m) = Z.max 0 (Z.of_nat n - Z.of_nat m)n, m:nat(m <= n)%nat -> Z.of_nat (n - m) = Z.of_nat n - Z.of_nat mn, m:nat(m <= n)%nat -> Z.of_nat (n - m) = Z.of_nat n - Z.of_nat mn, m:nat(N.of_nat m ?= N.of_nat n)%N <> Gt -> Z.of_nat (n - m) = Z.of_nat n - Z.of_nat mnow rewrite <- !nat_N_Z, Nat2N.inj_sub, N2Z.inj_sub. Qed. Register inj_sub as num.Nat2Z.inj_sub.n, m:natH:(N.of_nat m ?= N.of_nat n)%N <> GtZ.of_nat (n - m) = Z.of_nat n - Z.of_nat mn:natZ.of_nat (Nat.pred n) = Z.max 0 (Z.pred (Z.of_nat n))now rewrite <- !nat_N_Z, Nat2N.inj_pred, N2Z.inj_pred_max. Qed.n:natZ.of_nat (Nat.pred n) = Z.max 0 (Z.pred (Z.of_nat n))n:nat(0 < n)%nat -> Z.of_nat (Nat.pred n) = Z.pred (Z.of_nat n)n:nat(0 < n)%nat -> Z.of_nat (Nat.pred n) = Z.pred (Z.of_nat n)n:nat(N.of_nat 0 ?= N.of_nat n)%N = Lt -> Z.of_nat (Nat.pred n) = Z.pred (Z.of_nat n)now rewrite <- !nat_N_Z, Nat2N.inj_pred, N2Z.inj_pred. Qed.n:natH:(N.of_nat 0 ?= N.of_nat n)%N = LtZ.of_nat (Nat.pred n) = Z.pred (Z.of_nat n)n, m:natZ.of_nat (Nat.min n m) = Z.min (Z.of_nat n) (Z.of_nat m)now rewrite <- !nat_N_Z, Nat2N.inj_min, N2Z.inj_min. Qed.n, m:natZ.of_nat (Nat.min n m) = Z.min (Z.of_nat n) (Z.of_nat m)n, m:natZ.of_nat (Nat.max n m) = Z.max (Z.of_nat n) (Z.of_nat m)now rewrite <- !nat_N_Z, Nat2N.inj_max, N2Z.inj_max. Qed. End Nat2Z. Module Z2Nat.n, m:natZ.of_nat (Nat.max n m) = Z.max (Z.of_nat n) (Z.of_nat m)
Z.to_nat is a bijection between non-negative Z and nat,
with Pos.of_nat as reciprocal.
See nat2Z.id above for the dual equation.
n:Z0 <= n -> Z.of_nat (Z.to_nat n) = nn:Z0 <= n -> Z.of_nat (Z.to_nat n) = nnow rewrite <- Z_N_nat, <- nat_N_Z, N2Nat.id, Z2N.id. Qed.n:ZH:0 <= nZ.of_nat (Z.to_nat n) = n
Z.to_nat is hence injective for non-negative integers.
n, m:Z0 <= n -> 0 <= m -> Z.to_nat n = Z.to_nat m -> n = mn, m:Z0 <= n -> 0 <= m -> Z.to_nat n = Z.to_nat m -> n = mn, m:ZH:0 <= nH0:0 <= mH1:Z.to_nat n = Z.to_nat mn = mnow f_equal. Qed.n, m:ZH:0 <= nH0:0 <= mH1:Z.to_nat n = Z.to_nat mZ.of_nat (Z.to_nat n) = Z.of_nat (Z.to_nat m)n, m:Z0 <= n -> 0 <= m -> Z.to_nat n = Z.to_nat m <-> n = mn, m:Z0 <= n -> 0 <= m -> Z.to_nat n = Z.to_nat m <-> n = mn, m:ZH:0 <= nH0:0 <= mZ.to_nat n = Z.to_nat m <-> n = mn, m:ZH:0 <= nH0:0 <= mZ.to_nat n = Z.to_nat m -> n = mn, m:ZH:0 <= nH0:0 <= mn = m -> Z.to_nat n = Z.to_nat mintros; now subst. Qed.n, m:ZH:0 <= nH0:0 <= mn = m -> Z.to_nat n = Z.to_nat m
Z.to_nat, basic equations
Z.to_nat 0 = 0%natreflexivity. Qed.Z.to_nat 0 = 0%natn:positiveZ.to_nat (Z.pos n) = Pos.to_nat nreflexivity. Qed.n:positiveZ.to_nat (Z.pos n) = Pos.to_nat nn:positiveZ.to_nat (Z.neg n) = 0%natreflexivity. Qed.n:positiveZ.to_nat (Z.neg n) = 0%nat
Z.to_nat and operations
n, m:Z0 <= n -> 0 <= m -> Z.to_nat (n + m) = (Z.to_nat n + Z.to_nat m)%natn, m:Z0 <= n -> 0 <= m -> Z.to_nat (n + m) = (Z.to_nat n + Z.to_nat m)%natnow rewrite <- !Z_N_nat, Z2N.inj_add, N2Nat.inj_add. Qed.n, m:ZH:0 <= nH0:0 <= mZ.to_nat (n + m) = (Z.to_nat n + Z.to_nat m)%natn, m:Z0 <= n -> 0 <= m -> Z.to_nat (n * m) = (Z.to_nat n * Z.to_nat m)%natn, m:Z0 <= n -> 0 <= m -> Z.to_nat (n * m) = (Z.to_nat n * Z.to_nat m)%natnow rewrite <- !Z_N_nat, Z2N.inj_mul, N2Nat.inj_mul. Qed.n, m:ZH:0 <= nH0:0 <= mZ.to_nat (n * m) = (Z.to_nat n * Z.to_nat m)%natn:Z0 <= n -> Z.to_nat (Z.succ n) = S (Z.to_nat n)n:Z0 <= n -> Z.to_nat (Z.succ n) = S (Z.to_nat n)now rewrite <- !Z_N_nat, Z2N.inj_succ, N2Nat.inj_succ. Qed.n:ZH:0 <= nZ.to_nat (Z.succ n) = S (Z.to_nat n)n, m:Z0 <= m -> Z.to_nat (n - m) = (Z.to_nat n - Z.to_nat m)%natn, m:Z0 <= m -> Z.to_nat (n - m) = (Z.to_nat n - Z.to_nat m)%natnow rewrite <- !Z_N_nat, Z2N.inj_sub, N2Nat.inj_sub. Qed.n, m:ZH:0 <= mZ.to_nat (n - m) = (Z.to_nat n - Z.to_nat m)%natn:ZZ.to_nat (Z.pred n) = Nat.pred (Z.to_nat n)now rewrite <- !Z_N_nat, Z2N.inj_pred, N2Nat.inj_pred. Qed.n:ZZ.to_nat (Z.pred n) = Nat.pred (Z.to_nat n)n, m:Z0 <= n -> 0 <= m -> (Z.to_nat n ?= Z.to_nat m)%nat = (n ?= m)n, m:Z0 <= n -> 0 <= m -> (Z.to_nat n ?= Z.to_nat m)%nat = (n ?= m)now rewrite <- Nat2Z.inj_compare, !id. Qed.n, m:ZHn:0 <= nHm:0 <= m(Z.to_nat n ?= Z.to_nat m)%nat = (n ?= m)n, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.to_nat n <= Z.to_nat m)%natn, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.to_nat n <= Z.to_nat m)%natn, m:ZHn:0 <= nHm:0 <= mn <= m <-> (Z.to_nat n <= Z.to_nat m)%natnow rewrite nat_compare_le, inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) <> Gt <-> (Z.to_nat n <= Z.to_nat m)%natn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.to_nat n < Z.to_nat m)%natn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.to_nat n < Z.to_nat m)%natn, m:ZHn:0 <= nHm:0 <= mn < m <-> (Z.to_nat n < Z.to_nat m)%natnow rewrite nat_compare_lt, inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) = Lt <-> (Z.to_nat n < Z.to_nat m)%natn, m:ZZ.to_nat (Z.min n m) = Nat.min (Z.to_nat n) (Z.to_nat m)now rewrite <- !Z_N_nat, Z2N.inj_min, N2Nat.inj_min. Qed.n, m:ZZ.to_nat (Z.min n m) = Nat.min (Z.to_nat n) (Z.to_nat m)n, m:ZZ.to_nat (Z.max n m) = Nat.max (Z.to_nat n) (Z.to_nat m)now rewrite <- !Z_N_nat, Z2N.inj_max, N2Nat.inj_max. Qed. End Z2Nat. Module Zabs2Nat.n, m:ZZ.to_nat (Z.max n m) = Nat.max (Z.to_nat n) (Z.to_nat m)
Results about Z.abs_nat, converting absolute values of Z integers
to nat.
n:ZZ.abs_nat n = Z.to_nat (Z.abs n)now destruct n. Qed.n:ZZ.abs_nat n = Z.to_nat (Z.abs n)n:Z0 <= n -> Z.abs_nat n = Z.to_nat ndestruct n; trivial; now destruct 1. Qed.n:Z0 <= n -> Z.abs_nat n = Z.to_nat nn:ZZ.of_nat (Z.abs_nat n) = Z.abs nn:ZZ.of_nat (Z.abs_nat n) = Z.abs napply Zabs2N.id_abs. Qed.n:ZZ.of_N (Z.abs_N n) = Z.abs nn:natZ.abs_nat (Z.of_nat n) = nnow rewrite <-Zabs_N_nat, <-nat_N_Z, Zabs2N.id, Nat2N.id. Qed.n:natZ.abs_nat (Z.of_nat n) = n
Z.abs_nat, basic equations
Z.abs_nat 0 = 0%natreflexivity. Qed.Z.abs_nat 0 = 0%natp:positiveZ.abs_nat (Z.pos p) = Pos.to_nat preflexivity. Qed.p:positiveZ.abs_nat (Z.pos p) = Pos.to_nat pp:positiveZ.abs_nat (Z.neg p) = Pos.to_nat preflexivity. Qed.p:positiveZ.abs_nat (Z.neg p) = Pos.to_nat p
Z.abs_nat and usual operations, with non-negative integers
n:Z0 <= n -> Z.abs_nat (Z.succ n) = S (Z.abs_nat n)n:Z0 <= n -> Z.abs_nat (Z.succ n) = S (Z.abs_nat n)now rewrite <- !Zabs_N_nat, Zabs2N.inj_succ, N2Nat.inj_succ. Qed.n:ZH:0 <= nZ.abs_nat (Z.succ n) = S (Z.abs_nat n)n, m:Z0 <= n -> 0 <= m -> Z.abs_nat (n + m) = (Z.abs_nat n + Z.abs_nat m)%natn, m:Z0 <= n -> 0 <= m -> Z.abs_nat (n + m) = (Z.abs_nat n + Z.abs_nat m)%natnow rewrite <- !Zabs_N_nat, Zabs2N.inj_add, N2Nat.inj_add. Qed.n, m:ZH:0 <= nH0:0 <= mZ.abs_nat (n + m) = (Z.abs_nat n + Z.abs_nat m)%natn, m:ZZ.abs_nat (n * m) = (Z.abs_nat n * Z.abs_nat m)%natdestruct n, m; simpl; trivial using Pos2Nat.inj_mul. Qed.n, m:ZZ.abs_nat (n * m) = (Z.abs_nat n * Z.abs_nat m)%natn, m:Z0 <= m <= n -> Z.abs_nat (n - m) = (Z.abs_nat n - Z.abs_nat m)%natn, m:Z0 <= m <= n -> Z.abs_nat (n - m) = (Z.abs_nat n - Z.abs_nat m)%natnow rewrite <- !Zabs_N_nat, Zabs2N.inj_sub, N2Nat.inj_sub. Qed.n, m:ZH:0 <= m <= nZ.abs_nat (n - m) = (Z.abs_nat n - Z.abs_nat m)%natn:Z0 < n -> Z.abs_nat (Z.pred n) = Nat.pred (Z.abs_nat n)n:Z0 < n -> Z.abs_nat (Z.pred n) = Nat.pred (Z.abs_nat n)now rewrite <- !Zabs_N_nat, Zabs2N.inj_pred, N2Nat.inj_pred. Qed.n:ZH:0 < nZ.abs_nat (Z.pred n) = Nat.pred (Z.abs_nat n)n, m:Z0 <= n -> 0 <= m -> (Z.abs_nat n ?= Z.abs_nat m)%nat = (n ?= m)n, m:Z0 <= n -> 0 <= m -> (Z.abs_nat n ?= Z.abs_nat m)%nat = (n ?= m)now rewrite <- !Zabs_N_nat, <- N2Nat.inj_compare, Zabs2N.inj_compare. Qed.n, m:ZH:0 <= nH0:0 <= m(Z.abs_nat n ?= Z.abs_nat m)%nat = (n ?= m)n, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.abs_nat n <= Z.abs_nat m)%natn, m:Z0 <= n -> 0 <= m -> n <= m <-> (Z.abs_nat n <= Z.abs_nat m)%natn, m:ZHn:0 <= nHm:0 <= mn <= m <-> (Z.abs_nat n <= Z.abs_nat m)%natnow rewrite nat_compare_le, inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) <> Gt <-> (Z.abs_nat n <= Z.abs_nat m)%natn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.abs_nat n < Z.abs_nat m)%natn, m:Z0 <= n -> 0 <= m -> n < m <-> (Z.abs_nat n < Z.abs_nat m)%natn, m:ZHn:0 <= nHm:0 <= mn < m <-> (Z.abs_nat n < Z.abs_nat m)%natnow rewrite nat_compare_lt, inj_compare. Qed.n, m:ZHn:0 <= nHm:0 <= m(n ?= m) = Lt <-> (Z.abs_nat n < Z.abs_nat m)%natn, m:Z0 <= n -> 0 <= m -> Z.abs_nat (Z.min n m) = Nat.min (Z.abs_nat n) (Z.abs_nat m)n, m:Z0 <= n -> 0 <= m -> Z.abs_nat (Z.min n m) = Nat.min (Z.abs_nat n) (Z.abs_nat m)now rewrite <- !Zabs_N_nat, Zabs2N.inj_min, N2Nat.inj_min. Qed.n, m:ZH:0 <= nH0:0 <= mZ.abs_nat (Z.min n m) = Nat.min (Z.abs_nat n) (Z.abs_nat m)n, m:Z0 <= n -> 0 <= m -> Z.abs_nat (Z.max n m) = Nat.max (Z.abs_nat n) (Z.abs_nat m)n, m:Z0 <= n -> 0 <= m -> Z.abs_nat (Z.max n m) = Nat.max (Z.abs_nat n) (Z.abs_nat m)now rewrite <- !Zabs_N_nat, Zabs2N.inj_max, N2Nat.inj_max. Qed.n, m:ZH:0 <= nH0:0 <= mZ.abs_nat (Z.max n m) = Nat.max (Z.abs_nat n) (Z.abs_nat m)
Z.abs_nat and usual operations, statements with Z.abs
n:ZZ.abs_nat (Z.succ (Z.abs n)) = S (Z.abs_nat n)now rewrite <- !Zabs_N_nat, Zabs2N.inj_succ_abs, N2Nat.inj_succ. Qed.n:ZZ.abs_nat (Z.succ (Z.abs n)) = S (Z.abs_nat n)n, m:ZZ.abs_nat (Z.abs n + Z.abs m) = (Z.abs_nat n + Z.abs_nat m)%natnow rewrite <- !Zabs_N_nat, Zabs2N.inj_add_abs, N2Nat.inj_add. Qed.n, m:ZZ.abs_nat (Z.abs n + Z.abs m) = (Z.abs_nat n + Z.abs_nat m)%natn, m:ZZ.abs_nat (Z.abs n * Z.abs m) = (Z.abs_nat n * Z.abs_nat m)%natnow rewrite <- !Zabs_N_nat, Zabs2N.inj_mul_abs, N2Nat.inj_mul. Qed. End Zabs2Nat.n, m:ZZ.abs_nat (Z.abs n * Z.abs m) = (Z.abs_nat n * Z.abs_nat m)%nat
Compatibility
Definition neq (x y:nat) := x <> y.n, m:natneq n m -> Zne (Z.of_nat n) (Z.of_nat m)n, m:natneq n m -> Zne (Z.of_nat n) (Z.of_nat m)now apply H, Nat2Z.inj. Qed.n, m:natH:neq n mH':Z.of_nat n = Z.of_nat mFalseProof (Nat2Z.inj_succ n).n:natZ.pos (Pos.of_succ_nat n) = Z.succ (Z.of_nat n)
For these one, used in omega, a Definition is necessary
Definition inj_eq := (f_equal Z.of_nat). Definition inj_le n m := proj1 (Nat2Z.inj_le n m). Definition inj_lt n m := proj1 (Nat2Z.inj_lt n m). Definition inj_ge n m := proj1 (Nat2Z.inj_ge n m). Definition inj_gt n m := proj1 (Nat2Z.inj_gt n m). Register neq as plugins.omega.neq. Register inj_eq as plugins.omega.inj_eq. Register inj_neq as plugins.omega.inj_neq. Register inj_le as plugins.omega.inj_le. Register inj_lt as plugins.omega.inj_lt. Register inj_ge as plugins.omega.inj_ge. Register inj_gt as plugins.omega.inj_gt.
For the others, a Notation is fine
Notation inj_0 := Nat2Z.inj_0 (only parsing). Notation inj_S := Nat2Z.inj_succ (only parsing). Notation inj_compare := Nat2Z.inj_compare (only parsing). Notation inj_eq_rev := Nat2Z.inj (only parsing). Notation inj_eq_iff := (fun n m => iff_sym (Nat2Z.inj_iff n m)) (only parsing). Notation inj_le_iff := Nat2Z.inj_le (only parsing). Notation inj_lt_iff := Nat2Z.inj_lt (only parsing). Notation inj_ge_iff := Nat2Z.inj_ge (only parsing). Notation inj_gt_iff := Nat2Z.inj_gt (only parsing). Notation inj_le_rev := (fun n m => proj2 (Nat2Z.inj_le n m)) (only parsing). Notation inj_lt_rev := (fun n m => proj2 (Nat2Z.inj_lt n m)) (only parsing). Notation inj_ge_rev := (fun n m => proj2 (Nat2Z.inj_ge n m)) (only parsing). Notation inj_gt_rev := (fun n m => proj2 (Nat2Z.inj_gt n m)) (only parsing). Notation inj_plus := Nat2Z.inj_add (only parsing). Notation inj_mult := Nat2Z.inj_mul (only parsing). Notation inj_minus1 := Nat2Z.inj_sub (only parsing). Notation inj_minus := Nat2Z.inj_sub_max (only parsing). Notation inj_min := Nat2Z.inj_min (only parsing). Notation inj_max := Nat2Z.inj_max (only parsing). Notation Z_of_nat_of_P := positive_nat_Z (only parsing). Notation Zpos_eq_Z_of_nat_o_nat_of_P := (fun p => eq_sym (positive_nat_Z p)) (only parsing). Notation Z_of_nat_of_N := N_nat_Z (only parsing). Notation Z_of_N_of_nat := nat_N_Z (only parsing). Notation Z_of_N_eq := (f_equal Z.of_N) (only parsing). Notation Z_of_N_eq_rev := N2Z.inj (only parsing). Notation Z_of_N_eq_iff := (fun n m => iff_sym (N2Z.inj_iff n m)) (only parsing). Notation Z_of_N_compare := N2Z.inj_compare (only parsing). Notation Z_of_N_le_iff := N2Z.inj_le (only parsing). Notation Z_of_N_lt_iff := N2Z.inj_lt (only parsing). Notation Z_of_N_ge_iff := N2Z.inj_ge (only parsing). Notation Z_of_N_gt_iff := N2Z.inj_gt (only parsing). Notation Z_of_N_le := (fun n m => proj1 (N2Z.inj_le n m)) (only parsing). Notation Z_of_N_lt := (fun n m => proj1 (N2Z.inj_lt n m)) (only parsing). Notation Z_of_N_ge := (fun n m => proj1 (N2Z.inj_ge n m)) (only parsing). Notation Z_of_N_gt := (fun n m => proj1 (N2Z.inj_gt n m)) (only parsing). Notation Z_of_N_le_rev := (fun n m => proj2 (N2Z.inj_le n m)) (only parsing). Notation Z_of_N_lt_rev := (fun n m => proj2 (N2Z.inj_lt n m)) (only parsing). Notation Z_of_N_ge_rev := (fun n m => proj2 (N2Z.inj_ge n m)) (only parsing). Notation Z_of_N_gt_rev := (fun n m => proj2 (N2Z.inj_gt n m)) (only parsing). Notation Z_of_N_pos := N2Z.inj_pos (only parsing). Notation Z_of_N_abs := N2Z.inj_abs_N (only parsing). Notation Z_of_N_le_0 := N2Z.is_nonneg (only parsing). Notation Z_of_N_plus := N2Z.inj_add (only parsing). Notation Z_of_N_mult := N2Z.inj_mul (only parsing). Notation Z_of_N_minus := N2Z.inj_sub_max (only parsing). Notation Z_of_N_succ := N2Z.inj_succ (only parsing). Notation Z_of_N_min := N2Z.inj_min (only parsing). Notation Z_of_N_max := N2Z.inj_max (only parsing). Notation Zabs_of_N := Zabs2N.id (only parsing). Notation Zabs_N_succ_abs := Zabs2N.inj_succ_abs (only parsing). Notation Zabs_N_succ := Zabs2N.inj_succ (only parsing). Notation Zabs_N_plus_abs := Zabs2N.inj_add_abs (only parsing). Notation Zabs_N_plus := Zabs2N.inj_add (only parsing). Notation Zabs_N_mult_abs := Zabs2N.inj_mul_abs (only parsing). Notation Zabs_N_mult := Zabs2N.inj_mul (only parsing).forall n m : nat, (m > n)%nat -> Z.of_nat (n - m) = 0forall n m : nat, (m > n)%nat -> Z.of_nat (n - m) = 0rewrite not_le_minus_0; auto with arith. Qed. Register inj_minus2 as plugins.omega.inj_minus2.n, m:natH:(m > n)%natZ.of_nat (n - m) = 0