(************************************************************************)
(*         *   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)         *)
(************************************************************************)
(** The type [bool] is defined in the prelude as [Inductive bool : Set := true : bool | false : bool] *)
(** Most of the lemmas in this file are trivial after breaking all booleans *)
Ltac destr_bool :=
intros; destruct_all bool; simpl in *; trivial; try discriminate.
(** Interpretation of booleans as propositions *)
Definition Is_true (b:bool) :=
match b with
| true => True
| false => False
end.
(*******************)
(** * Decidability *)
(*******************)
Hint Resolve diff_true_false : bool.
Hint Resolve diff_false_true : bool.
Hint Extern 1 (false <> true) => exact diff_false_true : core.
(**********************)
(** * Order on booleans *)
(**********************)
Definition leb (b1 b2:bool) :=
match b1 with
| true => b2 = true
| false => True
end.
Hint Unfold leb: bool.
(* Infix "<=" := leb : bool_scope. *)
(*************)
(** * Equality *)
(*************)
Definition eqb (b1 b2:bool) : bool :=
match b1, b2 with
| true, true => true
| true, false => false
| false, true => false
| false, false => true
end.
(************************)
(** * A synonym of [if] on [bool] *)
(************************)
Definition ifb (b1 b2 b3:bool) : bool :=
match b1 with
| true => b2
| false => b3
end.
Open Scope bool_scope.
(****************************)
(** * De Morgan laws          *)
(****************************)
(********************************)
(** * Properties of [negb]    *)
(********************************)
Notation negb_elim := negb_involutive (only parsing).
Notation negb_intro := negb_involutive_reverse (only parsing).
(********************************)
(** * Properties of [orb]     *)
(********************************)
Hint Resolve orb_true_intro: bool.
Hint Resolve orb_false_intro: bool.
(** [true] is a zero for [orb] *)
Hint Resolve orb_true_r: bool.
Notation orb_b_true := orb_true_r (only parsing).
Notation orb_true_b := orb_true_l (only parsing).
(** [false] is neutral for [orb] *)
Hint Resolve orb_false_r: bool.
Hint Resolve orb_false_l: bool.
Notation orb_b_false := orb_false_r (only parsing).
Notation orb_false_b := orb_false_l (only parsing).
(** Complementation *)
Hint Resolve orb_negb_r: bool.
Notation orb_neg_b := orb_negb_r (only parsing).
(** Commutativity *)
(** Associativity *)
Hint Resolve orb_comm orb_assoc: bool.
(*******************************)
(** * Properties of [andb]     *)
(*******************************)
(** [false] is a zero for [andb] *)
Notation andb_b_false := andb_false_r (only parsing).
Notation andb_false_b := andb_false_l (only parsing).
(** [true] is neutral for [andb] *)
Notation andb_b_true := andb_true_r (only parsing).
Notation andb_true_b := andb_true_l (only parsing).
Hint Resolve andb_negb_r: bool.
Notation andb_neg_b := andb_negb_r (only parsing).
(** Commutativity *)
(** Associativity *)
Hint Resolve andb_comm andb_assoc: bool.
(*******************************************)
(** * Properties mixing [andb] and [orb] *)
(*******************************************)
(** Distributivity *)
(* Compatibility *)
Notation demorgan1 := andb_orb_distrib_r (only parsing).
Notation demorgan2 := andb_orb_distrib_l (only parsing).
Notation demorgan3 := orb_andb_distrib_r (only parsing).
Notation demorgan4 := orb_andb_distrib_l (only parsing).
(** Absorption *)
(* begin hide *)
(* Compatibility *)
Notation absoption_andb := absorption_andb (only parsing).
Notation absoption_orb := absorption_orb (only parsing).
(* end hide *)
(*********************************)
(** * Properties of [xorb]       *)
(*********************************)
(** [false] is neutral for [xorb] *)
Notation xorb_false := xorb_false_r (only parsing).
Notation false_xorb := xorb_false_l (only parsing).
(** [true] is "complementing" for [xorb] *)
Notation xorb_true := xorb_true_r (only parsing).
Notation true_xorb := xorb_true_l (only parsing).
(** Nilpotency (alternatively: identity is a inverse for [xorb]) *)
(** Commutativity *)
(** Associativity *)
Notation xorb_assoc := xorb_assoc_reverse (only parsing). (* Compatibility *)
(** Lemmas about the [b = true] embedding of [bool] to [Prop] *)
Notation bool_1 := eq_true_iff_eq (only parsing). (* Compatibility *)
Notation bool_3 := eq_true_negb_classical (only parsing). (* Compatibility *)
Notation bool_6 := eq_true_not_negb (only parsing). (* Compatibility *)
Hint Resolve eq_true_not_negb : bool.
(* An interesting lemma for auto but too strong to keep compatibility *)
(* A more specific one that preserves compatibility with old hint bool_3 *)
Hint Resolve absurd_eq_true : core.
(* A specific instance of eq_trans that preserves compatibility with old hint bool_2 *)
Hint Resolve trans_eq_bool : core.
(*****************************************)
(** * Reflection of [bool] into [Prop] *)
(*****************************************)
(** [Is_true] and equality *)
Hint Unfold Is_true: bool.
Notation Is_true_eq_true2 := Is_true_eq_right (only parsing).
Hint Immediate Is_true_eq_right Is_true_eq_left: bool.
(** [Is_true] and connectives *)
Notation orb_prop2 := orb_prop_elim (only parsing).
Hint Resolve andb_prop_intro: bool.
Notation andb_true_intro2 :=
(fun b1 b2 H1 H2 => andb_prop_intro b1 b2 (conj H1 H2))
(only parsing).
Hint Resolve andb_prop_elim: bool.
Notation andb_prop2 := andb_prop_elim (only parsing).

Lemma negb_prop_classical : forall b, ~ Is_true (negb b) -> Is_true b.