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 Le Lt Gt Decidable PeanoNat.

Local Open Scope nat_scope.

Implicit Types m n x y : nat.

n:nat

{n = 0} + {0 < n}
n:nat

{n = 0} + {0 < n}
destruct n; auto with arith. Defined.
n, m:nat

{n < m} + {n = m} + {m < n}
n, m:nat

{n < m} + {n = m} + {m < n}
n, m:nat
IHn:forall m0 : nat, {n < m0} + {n = m0} + {m0 < n}

{S n < S m} + {S n = S m} + {S m < S n}
n, m:nat
IHn:forall m0 : nat, {n < m0} + {n = m0} + {m0 < n}
H:{n < m} + {n = m}

{S n < S m} + {S n = S m} + {S m < S n}
destruct H; auto with arith. Defined.
n, m:nat

{m > n} + {n = m} + {n > m}
n, m:nat

{m > n} + {n = m} + {n > m}
now apply lt_eq_lt_dec. Defined.
n, m:nat

{n <= m} + {m < n}
n, m:nat

{n <= m} + {m < n}
m:nat

{0 <= m} + {m < 0}
n, m:nat
IHn:forall m0 : nat, {n <= m0} + {m0 < n}
{S n <= m} + {m < S n}
m:nat

{0 <= m} + {m < 0}
left; auto with arith.
n, m:nat
IHn:forall m0 : nat, {n <= m0} + {m0 < n}

{S n <= m} + {m < S n}
n:nat
IHn:forall m : nat, {n <= m} + {m < n}

{S n <= 0} + {0 < S n}
n, m:nat
IHn:forall m0 : nat, {n <= m0} + {m0 < n}
{S n <= S m} + {S m < S n}
n:nat
IHn:forall m : nat, {n <= m} + {m < n}

{S n <= 0} + {0 < S n}
right; auto with arith.
n, m:nat
IHn:forall m0 : nat, {n <= m0} + {m0 < n}

{S n <= S m} + {S m < S n}
elim (IHn m); [left|right]; auto with arith. Defined.
n, m:nat

{n <= m} + {S m <= n}
n, m:nat

{n <= m} + {S m <= n}
exact (le_lt_dec n m). Defined.
n, m:nat

{n <= m} + {n >= m}
n, m:nat

{n <= m} + {n >= m}
elim (le_lt_dec n m); auto with arith. Defined.
n, m:nat

{n <= m} + {n > m}
n, m:nat

{n <= m} + {n > m}
exact (le_lt_dec n m). Defined.
n, m:nat

n <= m -> {n < m} + {n = m}
n, m:nat

n <= m -> {n < m} + {n = m}
n, m:nat
H:n <= m
l:m < n

{n < m} + {n = m}
intros; absurd (m < n); auto with arith. Defined.
n, m:nat

{n <= m} + {~ n <= m}
n, m:nat

{n <= m} + {~ n <= m}
n, m:nat
l:n <= m

{n <= m} + {~ n <= m}
n, m:nat
g:n > m
{n <= m} + {~ n <= m}
n, m:nat
l:n <= m

{n <= m} + {~ n <= m}
now left.
n, m:nat
g:n > m

{n <= m} + {~ n <= m}
n, m:nat
g:n > m

~ n <= m
now apply gt_not_le. Defined.
n, m:nat

{n < m} + {~ n < m}
n, m:nat

{n < m} + {~ n < m}
apply le_dec. Defined.
n, m:nat

{n > m} + {~ n > m}
n, m:nat

{n > m} + {~ n > m}
apply lt_dec. Defined.
n, m:nat

{n >= m} + {~ n >= m}
n, m:nat

{n >= m} + {~ n >= m}
apply le_dec. Defined. Register le_gt_dec as num.nat.le_gt_dec.
Proofs of decidability
n, m:nat

decidable (n <= m)
n, m:nat

decidable (n <= m)
apply Nat.le_decidable. Qed.
n, m:nat

decidable (n < m)
n, m:nat

decidable (n < m)
apply Nat.lt_decidable. Qed.
n, m:nat

decidable (n > m)
n, m:nat

decidable (n > m)
apply Nat.lt_decidable. Qed.
n, m:nat

decidable (n >= m)
n, m:nat

decidable (n >= m)
apply Nat.le_decidable. Qed.
n, m:nat

n <> m -> n < m \/ m < n
n, m:nat

n <> m -> n < m \/ m < n
apply Nat.lt_gt_cases. Qed.
n, m:nat

~ n <= m -> n > m
n, m:nat

~ n <= m -> n > m
apply Nat.nle_gt. Qed.
n, m:nat

~ n > m -> n <= m
n, m:nat

~ n > m -> n <= m
apply Nat.nlt_ge. Qed.
n, m:nat

~ n >= m -> n < m
n, m:nat

~ n >= m -> n < m
apply Nat.nle_gt. Qed.
n, m:nat

~ n < m -> n >= m
n, m:nat

~ n < m -> n >= m
apply Nat.nlt_ge. Qed. Register dec_le as num.nat.dec_le. Register dec_lt as num.nat.dec_lt. Register dec_ge as num.nat.dec_ge. Register dec_gt as num.nat.dec_gt. Register not_eq as num.nat.not_eq. Register not_le as num.nat.not_le. Register not_lt as num.nat.not_lt. Register not_ge as num.nat.not_ge. Register not_gt as num.nat.not_gt.
A ternary comparison function in the spirit of Z.compare. See now Nat.compare and its properties. In scope nat_scope, the notation for Nat.compare is "?="
Notation nat_compare_S := Nat.compare_succ (only parsing).

n, m:nat

n < m <-> (n ?= m) = Lt
n, m:nat

n < m <-> (n ?= m) = Lt
n, m:nat

(n ?= m) = Lt <-> n < m
apply Nat.compare_lt_iff. Qed.
n, m:nat

n > m <-> (n ?= m) = Gt
n, m:nat

n > m <-> (n ?= m) = Gt
n, m:nat

(n ?= m) = Gt <-> n > m
apply Nat.compare_gt_iff. Qed.
n, m:nat

n <= m <-> (n ?= m) <> Gt
n, m:nat

n <= m <-> (n ?= m) <> Gt
n, m:nat

(n ?= m) <> Gt <-> n <= m
apply Nat.compare_le_iff. Qed.
n, m:nat

n >= m <-> (n ?= m) <> Lt
n, m:nat

n >= m <-> (n ?= m) <> Lt
n, m:nat

(n ?= m) <> Lt <-> n >= m
apply Nat.compare_ge_iff. Qed.
Some projections of the above equivalences.
n, m:nat

(n ?= m) = Eq -> n = m
n, m:nat

(n ?= m) = Eq -> n = m
apply Nat.compare_eq_iff. Qed.
n, m:nat

(n ?= m) = Lt -> n < m
n, m:nat

(n ?= m) = Lt -> n < m
apply Nat.compare_lt_iff. Qed.
n, m:nat

(n ?= m) = Gt -> n > m
n, m:nat

(n ?= m) = Gt -> n > m
apply Nat.compare_gt_iff. Qed.
A previous definition of nat_compare in terms of lt_eq_lt_dec. The new version avoids the creation of proof parts.
Definition nat_compare_alt (n m:nat) :=
  match lt_eq_lt_dec n m with
    | inleft (left _) => Lt
    | inleft (right _) => Eq
    | inright _ => Gt
  end.

n, m:nat

(n ?= m) = nat_compare_alt n m
n, m:nat

(n ?= m) = nat_compare_alt n m
n, m:nat
l:n < m

(n ?= m) = Lt
n, m:nat
e:n = m
(n ?= m) = Eq
n, m:nat
l:m < n
(n ?= m) = Gt
n, m:nat
l:n < m

(n ?= m) = Lt
now apply Nat.compare_lt_iff.
n, m:nat
e:n = m

(n ?= m) = Eq
now apply Nat.compare_eq_iff.
n, m:nat
l:m < n

(n ?= m) = Gt
now apply Nat.compare_gt_iff. Qed.
A boolean version of le over nat. See now Nat.leb and its properties. In scope nat_scope, the notation for Nat.leb is "<=?"
Notation leb := Nat.leb (only parsing).

Notation leb_iff := Nat.leb_le (only parsing).

m, n:nat

(n <=? m) = false <-> m < n
m, n:nat

(n <=? m) = false <-> m < n
m, n:nat

~ n <= m <-> m < n
apply Nat.nle_gt. Qed.
m, n:nat

m <= n -> (m <=? n) = true
m, n:nat

m <= n -> (m <=? n) = true
apply Nat.leb_le. Qed.
m, n:nat

(m <=? n) = true -> m <= n
m, n:nat

(m <=? n) = true -> m <= n
apply Nat.leb_le. Qed.
m, n:nat

m < n -> (n <=? m) = false
m, n:nat

m < n -> (n <=? m) = false
apply leb_iff_conv. Qed.
m, n:nat

(n <=? m) = false -> m < n
m, n:nat

(n <=? m) = false -> m < n
apply leb_iff_conv. Qed.
n, m:nat

(n <=? m) = true <-> (n ?= m) <> Gt
n, m:nat

(n <=? m) = true <-> (n ?= m) <> Gt
n, m:nat

(n <=? m) = true <-> n <= m
apply Nat.leb_le. Qed.