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 BinInt. Require Import Zeven. Require Import Zorder. Require Import Zcompare. Require Import ZArith_dec. Require Import Sumbool. Local Open Scope Z_scope.
The decidability of equality and order relations over
type Z gives some boolean functions with the adequate specification.
Definition Z_lt_ge_bool (x y:Z) := bool_of_sumbool (Z_lt_ge_dec x y). Definition Z_ge_lt_bool (x y:Z) := bool_of_sumbool (Z_ge_lt_dec x y). Definition Z_le_gt_bool (x y:Z) := bool_of_sumbool (Z_le_gt_dec x y). Definition Z_gt_le_bool (x y:Z) := bool_of_sumbool (Z_gt_le_dec x y). Definition Z_eq_bool (x y:Z) := bool_of_sumbool (Z.eq_dec x y). Definition Z_noteq_bool (x y:Z) := bool_of_sumbool (Z_noteq_dec x y). Definition Zeven_odd_bool (x:Z) := bool_of_sumbool (Zeven_odd_dec x). (**********************************************************************)
Notation Zle_bool := Z.leb (only parsing). Notation Zge_bool := Z.geb (only parsing). Notation Zlt_bool := Z.ltb (only parsing). Notation Zgt_bool := Z.gtb (only parsing).
We now provide a direct Z.eqb that doesn't refer to Z.compare.
The old Zeq_bool is kept for compatibility.
Definition Zeq_bool (x y:Z) := match x ?= y with | Eq => true | _ => false end. Definition Zneq_bool (x y:Z) := match x ?= y with | Eq => false | _ => true end.
Properties in term of if ... then ... else ...
n, m:Zif n <=? m then n <= m else n > mcase Z.leb_spec; now Z.swap_greater. Qed.n, m:Zif n <=? m then n <= m else n > mn, m:Zif n <? m then n < m else n >= mcase Z.ltb_spec; now Z.swap_greater. Qed.n, m:Zif n <? m then n < m else n >= mn, m:Zif n >=? m then n >= m else n < mn, m:Zif n >=? m then n >= m else n < mcase Z.leb_spec; now Z.swap_greater. Qed.n, m:Zif m <=? n then n >= m else n < mn, m:Zif n >? m then n > m else n <= mn, m:Zif n >? m then n > m else n <= mcase Z.ltb_spec; now Z.swap_greater. Qed.n, m:Zif m <? n then n > m else n <= m
Lemmas on Z.leb used in contrib/graphs
n, m:Z(n <=? m) = true -> n <= mapply Z.leb_le. Qed.n, m:Z(n <=? m) = true -> n <= mn, m:Zn <= m -> (n <=? m) = trueapply Z.leb_le. Qed. Notation Zle_bool_refl := Z.leb_refl (only parsing).n, m:Zn <= m -> (n <=? m) = truen, m:Z(n <=? m) = true -> (m <=? n) = true -> n = mn, m:Z(n <=? m) = true -> (m <=? n) = true -> n = mapply Z.le_antisymm. Qed.n, m:Zn <= m -> m <= n -> n = mn, m, p:Z(n <=? m) = true -> (m <=? p) = true -> (n <=? p) = truen, m, p:Z(n <=? m) = true -> (m <=? p) = true -> (n <=? p) = trueapply Z.le_trans. Qed.n, m, p:Zn <= m -> m <= p -> n <= px, y:Z{(x <=? y) = true} + {(y <=? x) = true}x, y:Z{(x <=? y) = true} + {(y <=? x) = true}x, y:ZH:(x <=? y) = true{true = true} + {(y <=? x) = true}x, y:ZH:(x <=? y) = false{false = true} + {(y <=? x) = true}left; trivial.x, y:ZH:(x <=? y) = true{true = true} + {(y <=? x) = true}x, y:ZH:(x <=? y) = false{false = true} + {(y <=? x) = true}x, y:ZH:(x <=? y) = false(y <=? x) = truenow apply Z.leb_le, Z.lt_le_incl. Defined.x, y:ZH:y < x(y <=? x) = truen, m, p, q:Z(n <=? m) = true -> (p <=? q) = true -> (n + p <=? m + q) = truen, m, p, q:Z(n <=? m) = true -> (p <=? q) = true -> (n + p <=? m + q) = trueapply Z.add_le_mono. Qed.n, m, p, q:Zn <= m -> p <= q -> n + p <= m + q(1 <=? 0) = falsereflexivity. Qed.(1 <=? 0) = falsen:Z(n <=? 0) = false -> (1 <=? n) = truen:Z(n <=? 0) = false -> (1 <=? n) = trueapply Z.le_succ_l. Qed.n:Z0 < n -> 1 <= n
Properties in term of iff
n, m:Zn <= m <-> (n <=? m) = truen, m:Zn <= m <-> (n <=? m) = trueapply Z.leb_le. Qed.n, m:Z(n <=? m) = true <-> n <= mn, m:Zn >= m <-> (m <=? n) = truen, m:Zn >= m <-> (m <=? n) = truen, m:Zm <= n <-> (m <=? n) = trueapply Z.leb_le. Qed.n, m:Z(m <=? n) = true <-> m <= nn, m:Zn < m <-> (n <? m) = truen, m:Zn < m <-> (n <? m) = trueapply Z.ltb_lt. Qed.n, m:Z(n <? m) = true <-> n < mn, m:Zn > m <-> (n >? m) = truen, m:Zn > m <-> (n >? m) = truen, m:Zm < n <-> (n >? m) = truen, m:Zm < n <-> (m <? n) = trueapply Z.ltb_lt. Qed.n, m:Z(m <? n) = true <-> m < nn, m:Zn < m <-> (n <=? m - 1) = truen, m:Zn < m <-> (n <=? m - 1) = trueapply Z.lt_le_pred. Qed.n, m:Zn < m <-> n <= m - 1n, m:Zn > m <-> (m <=? n - 1) = truen, m:Zn > m <-> (m <=? n - 1) = truen, m:Zm < n <-> (m <=? n - 1) = trueapply Z.lt_le_pred. Qed.n, m:Zm < n <-> m <= n - 1
Properties of the deprecated Zeq_bool
x, y:Zx = y <-> Zeq_bool x y = truex, y:Zx = y <-> Zeq_bool x y = truex, y:Zx = y <-> match x ?= y with | Eq => true | _ => false end = truedestruct Z.compare; now split. Qed.x, y:Z(x ?= y) = Eq <-> match x ?= y with | Eq => true | _ => false end = truex, y:ZZeq_bool x y = true -> x = yapply Zeq_is_eq_bool. Qed.x, y:ZZeq_bool x y = true -> x = yx, y:ZZeq_bool x y = false -> x <> yrewrite Zeq_is_eq_bool; now destruct Zeq_bool. Qed.x, y:ZZeq_bool x y = false -> x <> yx, y:Zif Zeq_bool x y then x = y else x <> yx, y:Zif Zeq_bool x y then x = y else x <> ydestruct Zeq_bool; auto. Qed.x, y:Z(Zeq_bool x y = true -> x = y) -> (Zeq_bool x y = false -> x <> y) -> if Zeq_bool x y then x = y else x <> y