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}destruct n; auto with arith. Defined.n:nat{n = 0} + {0 < n}n, m:nat{n < m} + {n = m} + {m < n}n, m:nat{n < m} + {n = m} + {m < n}n, m:natIHn:forall m0 : nat, {n < m0} + {n = m0} + {m0 < n}{S n < S m} + {S n = S m} + {S m < S n}destruct H; auto with arith. Defined.n, m:natIHn: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}n, m:nat{m > n} + {n = m} + {n > m}now apply lt_eq_lt_dec. Defined.n, m:nat{m > n} + {n = m} + {n > m}n, m:nat{n <= m} + {m < n}n, m:nat{n <= m} + {m < n}m:nat{0 <= m} + {m < 0}n, m:natIHn:forall m0 : nat, {n <= m0} + {m0 < n}{S n <= m} + {m < S n}left; auto with arith.m:nat{0 <= m} + {m < 0}n, m:natIHn:forall m0 : nat, {n <= m0} + {m0 < n}{S n <= m} + {m < S n}n:natIHn:forall m : nat, {n <= m} + {m < n}{S n <= 0} + {0 < S n}n, m:natIHn:forall m0 : nat, {n <= m0} + {m0 < n}{S n <= S m} + {S m < S n}right; auto with arith.n:natIHn:forall m : nat, {n <= m} + {m < n}{S n <= 0} + {0 < S n}elim (IHn m); [left|right]; auto with arith. Defined.n, m:natIHn:forall m0 : nat, {n <= m0} + {m0 < n}{S n <= S m} + {S m < S n}n, m:nat{n <= m} + {S m <= n}exact (le_lt_dec n m). Defined.n, m:nat{n <= m} + {S m <= n}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:natn <= m -> {n < m} + {n = m}n, m:natn <= m -> {n < m} + {n = m}intros; absurd (m < n); auto with arith. Defined.n, m:natH:n <= ml:m < n{n < m} + {n = m}n, m:nat{n <= m} + {~ n <= m}n, m:nat{n <= m} + {~ n <= m}n, m:natl:n <= m{n <= m} + {~ n <= m}n, m:natg:n > m{n <= m} + {~ n <= m}now left.n, m:natl:n <= m{n <= m} + {~ n <= m}n, m:natg:n > m{n <= m} + {~ n <= m}now apply gt_not_le. Defined.n, m:natg:n > m~ n <= mn, 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.n, m:nat{n >= m} + {~ n >= m}
Proofs of decidability
n, m:natdecidable (n <= m)apply Nat.le_decidable. Qed.n, m:natdecidable (n <= m)n, m:natdecidable (n < m)apply Nat.lt_decidable. Qed.n, m:natdecidable (n < m)n, m:natdecidable (n > m)apply Nat.lt_decidable. Qed.n, m:natdecidable (n > m)n, m:natdecidable (n >= m)apply Nat.le_decidable. Qed.n, m:natdecidable (n >= m)n, m:natn <> m -> n < m \/ m < napply Nat.lt_gt_cases. Qed.n, m:natn <> m -> n < m \/ m < nn, m:nat~ n <= m -> n > mapply Nat.nle_gt. Qed.n, m:nat~ n <= m -> n > mn, m:nat~ n > m -> n <= mapply Nat.nlt_ge. Qed.n, m:nat~ n > m -> n <= mn, m:nat~ n >= m -> n < mapply Nat.nle_gt. Qed.n, m:nat~ n >= m -> n < mn, m:nat~ n < m -> n >= mapply 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.n, m:nat~ n < m -> n >= m
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:natn < m <-> (n ?= m) = Ltn, m:natn < m <-> (n ?= m) = Ltapply Nat.compare_lt_iff. Qed.n, m:nat(n ?= m) = Lt <-> n < mn, m:natn > m <-> (n ?= m) = Gtn, m:natn > m <-> (n ?= m) = Gtapply Nat.compare_gt_iff. Qed.n, m:nat(n ?= m) = Gt <-> n > mn, m:natn <= m <-> (n ?= m) <> Gtn, m:natn <= m <-> (n ?= m) <> Gtapply Nat.compare_le_iff. Qed.n, m:nat(n ?= m) <> Gt <-> n <= mn, m:natn >= m <-> (n ?= m) <> Ltn, m:natn >= m <-> (n ?= m) <> Ltapply Nat.compare_ge_iff. Qed.n, m:nat(n ?= m) <> Lt <-> n >= m
Some projections of the above equivalences.
n, m:nat(n ?= m) = Eq -> n = mapply Nat.compare_eq_iff. Qed.n, m:nat(n ?= m) = Eq -> n = mn, m:nat(n ?= m) = Lt -> n < mapply Nat.compare_lt_iff. Qed.n, m:nat(n ?= m) = Lt -> n < mn, m:nat(n ?= m) = Gt -> n > mapply Nat.compare_gt_iff. Qed.n, m:nat(n ?= m) = Gt -> n > m
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 mn, m:nat(n ?= m) = nat_compare_alt n mn, m:natl:n < m(n ?= m) = Ltn, m:nate:n = m(n ?= m) = Eqn, m:natl:m < n(n ?= m) = Gtnow apply Nat.compare_lt_iff.n, m:natl:n < m(n ?= m) = Ltnow apply Nat.compare_eq_iff.n, m:nate:n = m(n ?= m) = Eqnow apply Nat.compare_gt_iff. Qed.n, m:natl:m < n(n ?= m) = Gt
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 < nm, n:nat(n <=? m) = false <-> m < napply Nat.nle_gt. Qed.m, n:nat~ n <= m <-> m < nm, n:natm <= n -> (m <=? n) = trueapply Nat.leb_le. Qed.m, n:natm <= n -> (m <=? n) = truem, n:nat(m <=? n) = true -> m <= napply Nat.leb_le. Qed.m, n:nat(m <=? n) = true -> m <= nm, n:natm < n -> (n <=? m) = falseapply leb_iff_conv. Qed.m, n:natm < n -> (n <=? m) = falsem, n:nat(n <=? m) = false -> m < napply leb_iff_conv. Qed.m, n:nat(n <=? m) = false -> m < nn, m:nat(n <=? m) = true <-> (n ?= m) <> Gtn, m:nat(n <=? m) = true <-> (n ?= m) <> Gtapply Nat.leb_le. Qed.n, m:nat(n <=? m) = true <-> n <= m