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 : results about Z.compare
Initial author: Pierre Crégut (CNET, Lannion, France
THIS FILE IS DEPRECATED. It is now almost entirely made of compatibility formulations for results already present in BinInt.Z.
Require Export BinPos BinInt.
Require Import Lt Gt Plus Mult. (* Useless now, for compatibility only *)

Local Open Scope Z_scope.

(***************************)

Comparison on integers


forall n m : Z, (n ?= m) = Gt <-> (m ?= n) = Lt
Proof Z.gt_lt_iff.
n, m:Z

CompOpp (n ?= m) = (m ?= n)
Proof eq_sym (Z.compare_antisym n m).

Transitivity of comparison


forall n m p : Z, (n ?= m) = Lt -> (m ?= p) = Lt -> (n ?= p) = Lt
Proof Z.lt_trans.

forall n m p : Z, (n ?= m) = Gt -> (m ?= p) = Gt -> (n ?= p) = Gt

forall n m p : Z, (n ?= m) = Gt -> (m ?= p) = Gt -> (n ?= p) = Gt
n, m, p:Z

(n ?= m) = Gt -> (m ?= p) = Gt -> (n ?= p) = Gt
n, m, p:Z

n > m -> m > p -> n > p
n, m, p:Z

m < n -> p < m -> p < n
n, m, p:Z
H:m < n
H0:p < m

p < n
now transitivity m. Qed.

Comparison and opposite

n, m:Z

(n ?= m) = (- m ?= - n)
n, m:Z

(n ?= m) = (- m ?= - n)
n, m:Z

(- m ?= - n) = (n ?= m)
apply Z.compare_opp. Qed.

Comparison first-order specification

n, m:Z

(n ?= m) = Gt -> exists h : positive, n + - m = Z.pos h
n, m:Z

(n ?= m) = Gt -> exists h : positive, n + - m = Z.pos h
n, m:Z

(n - m ?= 0) = Gt -> exists h : positive, n + - m = Z.pos h
n, m:Z

(n + - m ?= 0) = Gt -> exists h : positive, n + - m = Z.pos h
n, m:Z
p:positive

(Z.pos p ?= 0) = Gt -> exists h : positive, Z.pos p = Z.pos h
now exists p. Qed.

Comparison and addition

n, m, p:Z

(p + n ?= p + m) = (n ?= m)
n, m, p:Z

(p + n ?= p + m) = (n ?= m)
apply Z.add_compare_mono_l. Qed.
r:comparison
n, m, p, q:Z

(n ?= m) = r -> (p ?= q) = r -> (n + p ?= m + q) = r
r:comparison
n, m, p, q:Z

(n ?= m) = r -> (p ?= q) = r -> (n + p ?= m + q) = r
r:comparison
n, m, p, q:Z

(n - m ?= 0) = r -> (p - q ?= 0) = r -> (n + p - (m + q) ?= 0) = r
r:comparison
n, m, p, q:Z

(n + - m ?= 0) = r -> (p + - q ?= 0) = r -> (n + p + - (m + q) ?= 0) = r
r:comparison
n, m, p, q:Z

(n + - m ?= 0) = r -> (p + - q ?= 0) = r -> (n + p + (- m + - q) ?= 0) = r
r:comparison
n, m, p, q:Z

(n + - m ?= 0) = r -> (p + - q ?= 0) = r -> (n + - m + (p + - q) ?= 0) = r
destruct (n+-m), (p+-q); simpl; intros; now subst. Qed.
n:Z

(Z.succ n ?= n) = Gt
n:Z

(Z.succ n ?= n) = Gt
n:Z

n < Z.succ n
apply Z.lt_succ_diag_r. Qed.
n, m:Z

(n ?= m) = Gt <-> (n ?= m + 1) <> Lt
n, m:Z

(n ?= m) = Gt <-> (n ?= m + 1) <> Lt
n, m:Z

n > m <-> n >= m + 1
n, m:Z

m < n <-> m + 1 <= n
n, m:Z

m + 1 <= n <-> m < n
apply Z.le_succ_l. Qed.

Successor and comparison

n, m:Z

(Z.succ n ?= Z.succ m) = (n ?= m)
n, m:Z

(Z.succ n ?= Z.succ m) = (n ?= m)
n, m:Z

(1 + n ?= 1 + m) = (n ?= m)
apply Z.add_compare_mono_l. Qed.

Multiplication and comparison


forall (p : positive) (n m : Z), (Z.pos p * n ?= Z.pos p * m) = (n ?= m)

forall (p : positive) (n m : Z), (Z.pos p * n ?= Z.pos p * m) = (n ?= m)
intros p [|n|n] [|m|m]; simpl; trivial; now rewrite Pos.mul_compare_mono_l. Qed.
n, m, p:Z

p > 0 -> (n ?= m) = (p * n ?= p * m)
n, m, p:Z

p > 0 -> (n ?= m) = (p * n ?= p * m)
n, m:Z
p:positive
H:Z.pos p > 0

(n ?= m) = (Z.pos p * n ?= Z.pos p * m)
n, m:Z
p:positive
H:Z.pos p > 0

(Z.pos p * n ?= Z.pos p * m) = (n ?= m)
apply Zcompare_mult_compat. Qed.
n, m, p:Z

p > 0 -> (n ?= m) = (n * p ?= m * p)
n, m, p:Z

p > 0 -> (n ?= m) = (n * p ?= m * p)
intros; rewrite 2 (Z.mul_comm _ p); now apply Zmult_compare_compat_l. Qed.

Relating x ?= y to =, , <, or >


forall (c1 c2 c3 : Prop) (n m : Z), (n = m -> c1) -> (n < m -> c2) -> (n > m -> c3) -> match n ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end

forall (c1 c2 c3 : Prop) (n m : Z), (n = m -> c1) -> (n < m -> c2) -> (n > m -> c3) -> match n ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end
c1, c2, c3:Prop
n, m:Z
H:n = m -> c1
H0:n < m -> c2
H1:n > m -> c3

match n ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end
c1, c2, c3:Prop
n, m:Z
H:n = m -> c1
H0:n < m -> c2
H1:n > m -> c3

m < n -> c3
now Z.swap_greater. Qed.

forall (c1 c2 c3 : Prop) (n m : Z), c1 -> n = m -> match n ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end

forall (c1 c2 c3 : Prop) (n m : Z), c1 -> n = m -> match n ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end
c1, c2, c3:Prop
n, m:Z
H:c1
H0:n = m

match n ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end
c1, c2, c3:Prop
m:Z
H:c1

match m ?= m with | Eq => c1 | Lt => c2 | Gt => c3 end
now rewrite Z.compare_refl. Qed.

forall n m : Z, n <= m -> match n ?= m with | Gt => False | _ => True end

forall n m : Z, n <= m -> match n ?= m with | Gt => False | _ => True end
n, m:Z
H:n <= m

match n ?= m with | Gt => False | _ => True end
case Z.compare_spec; trivial; Z.order. Qed.

forall n m : Z, n < m -> match n ?= m with | Lt => True | _ => False end

forall n m : Z, n < m -> match n ?= m with | Lt => True | _ => False end
intros x y H; now rewrite H. Qed.

forall n m : Z, n >= m -> match n ?= m with | Lt => False | _ => True end

forall n m : Z, n >= m -> match n ?= m with | Lt => False | _ => True end
n, m:Z
H:n >= m

match n ?= m with | Lt => False | _ => True end
now case Z.compare_spec. Qed.

forall n m : Z, n > m -> match n ?= m with | Gt => True | _ => False end

forall n m : Z, n > m -> match n ?= m with | Gt => True | _ => False end
intros x y H; now rewrite H. Qed.
Compatibility notations
Notation Zcompare_Eq_eq := Z.compare_eq (only parsing).
Notation Zcompare_Eq_iff_eq := Z.compare_eq_iff (only parsing).
Notation Zabs_non_eq := Z.abs_neq (only parsing).
Notation Zsgn_0 := Z.sgn_null (only parsing).
Notation Zsgn_1 := Z.sgn_pos (only parsing).
Notation Zsgn_m1 := Z.sgn_neg (only parsing).
Not kept: Zcompare_egal_dec