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.
(************************************************************************)
(*         *   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)         *)
(************************************************************************)

Require Import Sumbool.

Require Import BinInt.
Require Import Zorder.
Require Import Zcompare.
Local Open Scope Z_scope.

(* begin hide *)
(* Trivial, to deprecate? *)

forall r : comparison, {r = Eq} + {r = Lt} + {r = Gt}

forall r : comparison, {r = Eq} + {r = Lt} + {r = Gt}
induction r; auto. Defined. (* end hide *)
P:Type
n, m:Z

((n ?= m) = Eq -> P) -> ((n ?= m) = Lt -> P) -> ((n ?= m) = Gt -> P) -> P
P:Type
n, m:Z

((n ?= m) = Eq -> P) -> ((n ?= m) = Lt -> P) -> ((n ?= m) = Gt -> P) -> P
P:Type
n, m:Z
H1:(n ?= m) = Eq -> P
H2:(n ?= m) = Lt -> P
H3:(n ?= m) = Gt -> P

P
destruct (n ?= m); auto. Defined.
P:Set
n, m:Z

((n ?= m) = Eq -> P) -> ((n ?= m) = Lt -> P) -> ((n ?= m) = Gt -> P) -> P
P:Set
n, m:Z

((n ?= m) = Eq -> P) -> ((n ?= m) = Lt -> P) -> ((n ?= m) = Gt -> P) -> P
apply Zcompare_rect. Defined. Section decidability. Variables x y : Z.

Decidability of order on binary integers

  
x, y:Z

{x < y} + {~ x < y}
x, y:Z

{x < y} + {~ x < y}
unfold Z.lt; case Z.compare; (now left) || (now right). Defined.
x, y:Z

{x <= y} + {~ x <= y}
x, y:Z

{x <= y} + {~ x <= y}
unfold Z.le; case Z.compare; (now left) || (right; tauto). Defined.
x, y:Z

{x > y} + {~ x > y}
x, y:Z

{x > y} + {~ x > y}
unfold Z.gt; case Z.compare; (now left) || (now right). Defined.
x, y:Z

{x >= y} + {~ x >= y}
x, y:Z

{x >= y} + {~ x >= y}
unfold Z.ge; case Z.compare; (now left) || (right; tauto). Defined.
x, y:Z

{x < y} + {x >= y}
x, y:Z

{x < y} + {x >= y}
exact Z_lt_dec. Defined.
x, y:Z

{x < y} + {y <= x}
x, y:Z

{x < y} + {y <= x}
x, y:Z

x < y -> {x < y} + {y <= x}
x, y:Z
x >= y -> {x < y} + {y <= x}
x, y:Z

x < y -> {x < y} + {y <= x}
now left.
x, y:Z

x >= y -> {x < y} + {y <= x}
right; now apply Z.ge_le. Defined.
x, y:Z

{x <= y} + {x > y}
x, y:Z

{x <= y} + {x > y}
x, y:Z

~ x <= y -> {x <= y} + {x > y}
x, y:Z
b:~ x <= y

{x <= y} + {x > y}
x, y:Z
b:~ x <= y

x > y
x, y:Z
b:~ x <= y

y < x
now apply Z.nle_gt. Defined.
x, y:Z

{x > y} + {x <= y}
x, y:Z

{x > y} + {x <= y}
exact Z_gt_dec. Defined.
x, y:Z

{x >= y} + {x < y}
x, y:Z

{x >= y} + {x < y}
x, y:Z

~ x >= y -> {x >= y} + {x < y}
x, y:Z
b:~ x >= y

{x >= y} + {x < y}
x, y:Z
b:~ x >= y

x < y
x, y:Z
b:~ y <= x

x < y
now apply Z.lt_nge. Defined.
x, y:Z

x <= y -> {x < y} + {x = y}
x, y:Z

x <= y -> {x < y} + {x = y}
x, y:Z
H:x <= y

{x < y} + {x = y}
x, y:Z
H:x <= y

(x ?= y) = Eq -> {x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Lt -> {x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y
H0:(x ?= y) = Eq

{x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Lt -> {x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y
H0:(x ?= y) = Eq

x = y
x, y:Z
H:x <= y
(x ?= y) = Lt -> {x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y

(x ?= y) = Lt -> {x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y
H0:(x ?= y) = Lt

{x < y} + {x = y}
x, y:Z
H:x <= y
(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y
H0:(x ?= y) = Lt

x < y
x, y:Z
H:x <= y
(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y

(x ?= y) = Gt -> {x < y} + {x = y}
x, y:Z
H:x <= y
H1:(x ?= y) = Gt

{x < y} + {x = y}
absurd (x > y); auto with arith. Defined. End decidability.

Cotransitivity of order on binary integers


forall n m : Z, n < m -> forall p : Z, {n < p} + {p < m}

forall n m : Z, n < m -> forall p : Z, {n < p} + {p < m}
x, y:Z
H:x < y
z:Z

{x < z} + {z < y}
x, y:Z
H:x < y
z:Z

x < z -> {x < z} + {z < y}
x, y:Z
H:x < y
z:Z
x >= z -> {x < z} + {z < y}
x, y:Z
H:x < y
z:Z
l:x < z

{x < z} + {z < y}
x, y:Z
H:x < y
z:Z
x >= z -> {x < z} + {z < y}
x, y:Z
H:x < y
z:Z
l:x < z

x < z
x, y:Z
H:x < y
z:Z
x >= z -> {x < z} + {z < y}
x, y:Z
H:x < y
z:Z

x >= z -> {x < z} + {z < y}
x, y:Z
H:x < y
z:Z
g:x >= z

{x < z} + {z < y}
x, y:Z
H:x < y
z:Z
g:x >= z

z < y
x, y:Z
H:x < y
z:Z
g:x >= z

z <= x
x, y:Z
H:x < y
z:Z
g:x >= z
x < y
x, y:Z
H:x < y
z:Z
g:x >= z

x >= z
x, y:Z
H:x < y
z:Z
g:x >= z
x < y
x, y:Z
H:x < y
z:Z
g:x >= z

x < y
assumption. Defined.

forall n m : Z, 0 < n + m -> {0 < n} + {0 < m}

forall n m : Z, 0 < n + m -> {0 < n} + {0 < m}
x, y:Z
H:0 < x + y

{0 < x} + {0 < y}
x, y:Z
H:0 < x + y

0 < x -> {0 < x} + {0 < y}
x, y:Z
H:0 < x + y
x < x + y -> {0 < x} + {0 < y}
x, y:Z
H:0 < x + y

0 < x -> {0 < x} + {0 < y}
now left.
x, y:Z
H:0 < x + y

x < x + y -> {0 < x} + {0 < y}
x, y:Z
H:0 < x + y
l:x < x + y

0 < y
x, y:Z
H:0 < x + y
l:x < x + y

x + 0 < x + y
now rewrite Z.add_0_r. Defined.

forall n m : Z, n + m < 0 -> {n < 0} + {m < 0}

forall n m : Z, n + m < 0 -> {n < 0} + {m < 0}
intros x y H; case (Zlt_cotrans (x + y) 0 H x); intro Hxy; [ right; apply Z.add_lt_mono_l with (p := x); rewrite Z.add_0_r | left ]; assumption. Defined.

forall n m : Z, n <> m -> {n < m} + {m < n}

forall n m : Z, n <> m -> {n < m} + {m < n}
x, y:Z
H:x <> y

{x < y} + {y < x}
x, y:Z
H:x <> y

x < y -> {x < y} + {y < x}
x, y:Z
H:x <> y
x >= y -> {x < y} + {y < x}
x, y:Z
H:x <> y
l:x < y

{x < y} + {y < x}
x, y:Z
H:x <> y
x >= y -> {x < y} + {y < x}
x, y:Z
H:x <> y
l:x < y

x < y
x, y:Z
H:x <> y
x >= y -> {x < y} + {y < x}
x, y:Z
H:x <> y

x >= y -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y

{x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y

y <= x -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x

{x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x

y < x -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
y = x -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
l:y < x

{x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
y = x -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
l:y < x

y < x
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
y = x -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x

y = x -> {x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
e:y = x

{x < y} + {y < x}
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
e:y = x

False
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
e:y = x

x = y
x, y:Z
H:x <> y
H0:x >= y
H1:y <= x
e:y = x

y = x
assumption. Defined.

forall n m : Z, {n < m} + {n > m} + {n = m}

forall n m : Z, {n < m} + {n > m} + {n = m}
x, y:Z

{x < y} + {x > y} + {x = y}
x, y:Z

x < y -> {x < y} + {x > y} + {x = y}
x, y:Z
x >= y -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x < y

{x < y} + {x > y} + {x = y}
x, y:Z
x >= y -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x < y

{x < y} + {x > y}
x, y:Z
x >= y -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x < y

x < y
x, y:Z
x >= y -> {x < y} + {x > y} + {x = y}
x, y:Z

x >= y -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y

{x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y

y <= x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x

{x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x

y < x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
y = x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
H1:y < x

{x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
y = x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
H1:y < x

{x < y} + {x > y}
x, y:Z
H:x >= y
H0:y <= x
y = x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
H1:y < x

x > y
x, y:Z
H:x >= y
H0:y <= x
y = x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
H1:y < x

y < x
x, y:Z
H:x >= y
H0:y <= x
y = x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x

y = x -> {x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
e:y = x

{x < y} + {x > y} + {x = y}
x, y:Z
H:x >= y
H0:y <= x
e:y = x

x = y
x, y:Z
H:x >= y
H0:y <= x
e:y = x

y = x
assumption. Defined.

forall n m : Z, {n < m} + {m < n} + {n = m}

forall n m : Z, {n < m} + {m < n} + {n = m}
x, y:Z

{x < y} + {y < x} + {x = y}
case (Z.eq_dec x y); intro H; [ right; assumption | left; apply (not_Zeq_inf _ _ H) ]. Defined. (* begin hide *) (* To deprecate ? *)

forall x : Z, {x = 0} + {x <> 0}

forall x : Z, {x = 0} + {x <> 0}
exact (fun x:Z => Z.eq_dec x 0). Defined.

forall x : Z, {x <> 0} + {x = 0}
Proof (fun x => sumbool_not _ _ (Z_zerop x)).

forall x y : Z, {x <> y} + {x = y}
Proof (fun x y => sumbool_not _ _ (Z.eq_dec x y)). (* end hide *)