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

(*******************)


forall b1 b2 : bool, {b1 = b2} + {b1 <> b2}

forall b1 b2 : bool, {b1 = b2} + {b1 <> b2}
decide equality. Defined. (*********************)

Discrimination

(*********************)


true <> false

true <> false
discriminate. Qed. Hint Resolve diff_true_false : bool.

false <> true

false <> true
discriminate. Qed. Hint Resolve diff_false_true : bool. Hint Extern 1 (false <> true) => exact diff_false_true : core.

forall b : bool, b = true -> b = false -> False

forall b : bool, b = true -> b = false -> False
destr_bool. Qed.

forall b : bool, b <> true -> b = false

forall b : bool, b <> true -> b = false
destr_bool; intuition. Qed.

forall b : bool, b <> false -> b = true

forall b : bool, b <> false -> b = true
destr_bool; intuition. Qed.

forall b : bool, b <> true <-> b = false

forall b : bool, b <> true <-> b = false
destr_bool; intuition. Qed.

forall b : bool, b <> false <-> b = true

forall b : bool, b <> false <-> b = true
destr_bool; intuition. Qed. (**********************)

Order on booleans

(**********************)

Definition leb (b1 b2:bool) :=
  match b1 with
    | true => b2 = true
    | false => True
  end.
Hint Unfold leb: bool.


forall b1 b2 : bool, leb b1 b2 <-> implb b1 b2 = true

forall b1 b2 : bool, leb b1 b2 <-> implb b1 b2 = true
destr_bool; intuition. Qed. (* 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.


forall (P : bool -> Prop) (b1 b2 : bool), eqb b1 b2 = true -> P b1 -> P b2

forall (P : bool -> Prop) (b1 b2 : bool), eqb b1 b2 = true -> P b1 -> P b2
destr_bool. Qed.

forall b : bool, eqb b b = true

forall b : bool, eqb b b = true
destr_bool. Qed.

forall a b : bool, eqb a b = true -> a = b

forall a b : bool, eqb a b = true -> a = b
destr_bool. Qed.

forall a b : bool, eqb a b = true <-> a = b

forall a b : bool, eqb a b = true <-> a = b
destr_bool; intuition. Qed.

forall a b : bool, eqb a b = false <-> a <> b

forall a b : bool, eqb a b = false <-> a <> b
destr_bool; intuition. Qed. (************************)

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

(****************************)


forall b1 b2 : bool, negb (b1 || b2) = negb b1 && negb b2

forall b1 b2 : bool, negb (b1 || b2) = negb b1 && negb b2
destr_bool. Qed.

forall b1 b2 : bool, negb (b1 && b2) = negb b1 || negb b2

forall b1 b2 : bool, negb (b1 && b2) = negb b1 || negb b2
destr_bool. Qed. (********************************)

Properties of negb

(********************************)


forall b : bool, negb (negb b) = b

forall b : bool, negb (negb b) = b
destr_bool. Qed.

forall b : bool, b = negb (negb b)

forall b : bool, b = negb (negb b)
destr_bool. Qed. Notation negb_elim := negb_involutive (only parsing). Notation negb_intro := negb_involutive_reverse (only parsing).

forall b b' : bool, b' = negb b -> b = negb b'

forall b b' : bool, b' = negb b -> b = negb b'
destr_bool. Qed.

forall b : bool, negb b <> b

forall b : bool, negb b <> b
destr_bool. Qed.

forall b : bool, eqb (negb b) b = false

forall b : bool, eqb (negb b) b = false
destr_bool. Qed.

forall b : bool, eqb b (negb b) = false

forall b : bool, eqb b (negb b) = false
destr_bool. Qed.

forall (A : Type) (b : bool) (x y : A), (if negb b then x else y) = (if b then y else x)

forall (A : Type) (b : bool) (x y : A), (if negb b then x else y) = (if b then y else x)
destr_bool. Qed.

forall b : bool, negb b = true <-> b = false

forall b : bool, negb b = true <-> b = false
destr_bool; intuition. Qed.

forall b : bool, negb b = false <-> b = true

forall b : bool, negb b = false <-> b = true
destr_bool; intuition. Qed. (********************************)

Properties of orb

(********************************)


forall b1 b2 : bool, b1 || b2 = true <-> b1 = true \/ b2 = true

forall b1 b2 : bool, b1 || b2 = true <-> b1 = true \/ b2 = true
destr_bool; intuition. Qed.

forall b1 b2 : bool, b1 || b2 = false <-> b1 = false /\ b2 = false

forall b1 b2 : bool, b1 || b2 = false <-> b1 = false /\ b2 = false
destr_bool; intuition. Qed.

forall b1 b2 : bool, b1 || b2 = true -> {b1 = true} + {b2 = true}

forall b1 b2 : bool, b1 || b2 = true -> {b1 = true} + {b2 = true}
destruct b1; simpl; auto. Defined.

forall a b : bool, a || b = true -> a = true \/ b = true

forall a b : bool, a || b = true -> a = true \/ b = true
intros; apply orb_true_iff; trivial. Qed.

forall b1 b2 : bool, b1 = true \/ b2 = true -> b1 || b2 = true

forall b1 b2 : bool, b1 = true \/ b2 = true -> b1 || b2 = true
intros; apply orb_true_iff; trivial. Qed. Hint Resolve orb_true_intro: bool.

forall b1 b2 : bool, b1 = false -> b2 = false -> b1 || b2 = false

forall b1 b2 : bool, b1 = false -> b2 = false -> b1 || b2 = false
b1, b2:bool
H:b1 = false
H0:b2 = false

b1 || b2 = false

false || false = false
reflexivity. Qed. Hint Resolve orb_false_intro: bool.

forall b1 b2 : bool, b1 || b2 = false -> b1 = false /\ b2 = false

forall b1 b2 : bool, b1 || b2 = false -> b1 = false /\ b2 = false
b1, b2:bool
H:b1 || b2 = false

b1 = false /\ b2 = false
apply orb_false_iff; trivial. Qed.

forall b : bool, b || b = b

forall b : bool, b || b = b
destr_bool. Qed.
true is a zero for orb

forall b : bool, b || true = true

forall b : bool, b || true = true
destr_bool. Qed. Hint Resolve orb_true_r: bool.

forall b : bool, true || b = true

forall b : bool, true || b = true
reflexivity. Qed. Notation orb_b_true := orb_true_r (only parsing). Notation orb_true_b := orb_true_l (only parsing).
false is neutral for orb

forall b : bool, b || false = b

forall b : bool, b || false = b
destr_bool. Qed. Hint Resolve orb_false_r: bool.

forall b : bool, false || b = b

forall b : bool, false || b = b
destr_bool. Qed. 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

forall b : bool, b || negb b = true

forall b : bool, b || negb b = true
destr_bool. Qed. Hint Resolve orb_negb_r: bool. Notation orb_neg_b := orb_negb_r (only parsing).
Commutativity

forall b1 b2 : bool, b1 || b2 = b2 || b1

forall b1 b2 : bool, b1 || b2 = b2 || b1
destr_bool. Qed.
Associativity

forall b1 b2 b3 : bool, b1 || (b2 || b3) = b1 || b2 || b3

forall b1 b2 b3 : bool, b1 || (b2 || b3) = b1 || b2 || b3
destr_bool. Qed. Hint Resolve orb_comm orb_assoc: bool. (*******************************)

Properties of andb

(*******************************)


forall b1 b2 : bool, b1 && b2 = true <-> b1 = true /\ b2 = true

forall b1 b2 : bool, b1 && b2 = true <-> b1 = true /\ b2 = true
destr_bool; intuition. Qed.

forall b1 b2 : bool, b1 && b2 = false <-> b1 = false \/ b2 = false

forall b1 b2 : bool, b1 && b2 = false <-> b1 = false \/ b2 = false
destr_bool; intuition. Qed.

forall a b : bool, true = a && b -> true = a /\ true = b

forall a b : bool, true = a && b -> true = a /\ true = b
H:true = true

true = true /\ true = true
auto. Defined.

forall b1 b2 : bool, b1 = false -> b1 && b2 = false

forall b1 b2 : bool, b1 = false -> b1 && b2 = false
b1, b2:bool
H:b1 = false

b1 && b2 = false
b1, b2:bool
H:b1 = false

b1 = false \/ b2 = false
auto. Qed.

forall b1 b2 : bool, b2 = false -> b1 && b2 = false

forall b1 b2 : bool, b2 = false -> b1 && b2 = false
b1, b2:bool
H:b2 = false

b1 && b2 = false
b1, b2:bool
H:b2 = false

b1 = false \/ b2 = false
auto. Qed.
false is a zero for andb

forall b : bool, b && false = false

forall b : bool, b && false = false
destr_bool. Qed.

forall b : bool, false && b = false

forall b : bool, false && b = false
reflexivity. Qed. Notation andb_b_false := andb_false_r (only parsing). Notation andb_false_b := andb_false_l (only parsing).

forall b : bool, b && b = b

forall b : bool, b && b = b
destr_bool. Qed.
true is neutral for andb

forall b : bool, b && true = b

forall b : bool, b && true = b
destr_bool. Qed.

forall b : bool, true && b = b

forall b : bool, true && b = b
reflexivity. Qed. Notation andb_b_true := andb_true_r (only parsing). Notation andb_true_b := andb_true_l (only parsing).

forall b1 b2 : bool, b1 && b2 = false -> {b1 = false} + {b2 = false}

forall b1 b2 : bool, b1 && b2 = false -> {b1 = false} + {b2 = false}
destruct b1; simpl; auto. Defined. Hint Resolve andb_false_elim: bool.
Complementation

forall b : bool, b && negb b = false

forall b : bool, b && negb b = false
destr_bool. Qed. Hint Resolve andb_negb_r: bool. Notation andb_neg_b := andb_negb_r (only parsing).
Commutativity

forall b1 b2 : bool, b1 && b2 = b2 && b1

forall b1 b2 : bool, b1 && b2 = b2 && b1
destr_bool. Qed.
Associativity

forall b1 b2 b3 : bool, b1 && (b2 && b3) = b1 && b2 && b3

forall b1 b2 b3 : bool, b1 && (b2 && b3) = b1 && b2 && b3
destr_bool. Qed. Hint Resolve andb_comm andb_assoc: bool. (*******************************************)

Properties mixing andb and orb

(*******************************************)
Distributivity

forall b1 b2 b3 : bool, b1 && (b2 || b3) = b1 && b2 || b1 && b3

forall b1 b2 b3 : bool, b1 && (b2 || b3) = b1 && b2 || b1 && b3
destr_bool. Qed.

forall b1 b2 b3 : bool, (b1 || b2) && b3 = b1 && b3 || b2 && b3

forall b1 b2 b3 : bool, (b1 || b2) && b3 = b1 && b3 || b2 && b3
destr_bool. Qed.

forall b1 b2 b3 : bool, b1 || b2 && b3 = (b1 || b2) && (b1 || b3)

forall b1 b2 b3 : bool, b1 || b2 && b3 = (b1 || b2) && (b1 || b3)
destr_bool. Qed.

forall b1 b2 b3 : bool, b1 && b2 || b3 = (b1 || b3) && (b2 || b3)

forall b1 b2 b3 : bool, b1 && b2 || b3 = (b1 || b3) && (b2 || b3)
destr_bool. Qed. (* 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

forall b1 b2 : bool, b1 && (b1 || b2) = b1

forall b1 b2 : bool, b1 && (b1 || b2) = b1
destr_bool. Qed.

forall b1 b2 : bool, b1 || b1 && b2 = b1

forall b1 b2 : bool, b1 || b1 && b2 = b1
destr_bool. Qed. (* 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

forall b : bool, xorb b false = b

forall b : bool, xorb b false = b
destr_bool. Qed.

forall b : bool, xorb false b = b

forall b : bool, xorb false b = b
destr_bool. Qed. Notation xorb_false := xorb_false_r (only parsing). Notation false_xorb := xorb_false_l (only parsing).
true is "complementing" for xorb

forall b : bool, xorb b true = negb b

forall b : bool, xorb b true = negb b
reflexivity. Qed.

forall b : bool, xorb true b = negb b

forall b : bool, xorb true b = negb b
reflexivity. Qed. Notation xorb_true := xorb_true_r (only parsing). Notation true_xorb := xorb_true_l (only parsing).
Nilpotency (alternatively: identity is a inverse for xorb)

forall b : bool, xorb b b = false

forall b : bool, xorb b b = false
destr_bool. Qed.
Commutativity

forall b b' : bool, xorb b b' = xorb b' b

forall b b' : bool, xorb b b' = xorb b' b
destr_bool. Qed.
Associativity

forall b b' b'' : bool, xorb (xorb b b') b'' = xorb b (xorb b' b'')

forall b b' b'' : bool, xorb (xorb b b') b'' = xorb b (xorb b' b'')
destr_bool. Qed. Notation xorb_assoc := xorb_assoc_reverse (only parsing). (* Compatibility *)

forall b b' : bool, xorb b b' = false -> b = b'

forall b b' : bool, xorb b b' = false -> b = b'
destr_bool. Qed.

forall b b' b'' : bool, xorb b b' = b'' -> b' = xorb b b''

forall b b' b'' : bool, xorb b b' = b'' -> b' = xorb b b''
destr_bool. Qed.

forall b b' b'' : bool, xorb b b' = b'' -> b = xorb b'' b'

forall b b' b'' : bool, xorb b b' = b'' -> b = xorb b'' b'
destr_bool. Qed.

forall b b' b'' : bool, b = xorb b' b'' -> xorb b' b = b''

forall b b' b'' : bool, b = xorb b' b'' -> xorb b' b = b''
destr_bool. Qed.

forall b b' b'' : bool, b = xorb b' b'' -> xorb b b'' = b'

forall b b' b'' : bool, b = xorb b' b'' -> xorb b b'' = b'
destr_bool. Qed.

forall b b' : bool, negb (xorb b b') = xorb (negb b) b'

forall b b' : bool, negb (xorb b b') = xorb (negb b) b'
destruct b,b'; trivial. Qed.

forall b b' : bool, negb (xorb b b') = xorb b (negb b')

forall b b' : bool, negb (xorb b b') = xorb b (negb b')
destruct b,b'; trivial. Qed.

forall b b' : bool, xorb (negb b) (negb b') = xorb b b'

forall b b' : bool, xorb (negb b) (negb b') = xorb b b'
destruct b,b'; trivial. Qed.
Lemmas about the b = true embedding of bool to Prop

forall b1 b2 : bool, b1 = b2 <-> (b1 = true <-> b2 = true)

forall b1 b2 : bool, b1 = b2 <-> (b1 = true <-> b2 = true)
destr_bool; intuition. Qed.

forall b1 b2 : bool, b1 = true <-> b2 = true -> b1 = b2

forall b1 b2 : bool, b1 = true <-> b2 = true -> b1 = b2
apply eq_iff_eq_true. Qed. Notation bool_1 := eq_true_iff_eq (only parsing). (* Compatibility *)

forall b : bool, negb b <> true -> b = true

forall b : bool, negb b <> true -> b = true
destr_bool; intuition. Qed. Notation bool_3 := eq_true_negb_classical (only parsing). (* Compatibility *)

forall b : bool, b <> true -> negb b = true

forall b : bool, b <> true -> negb b = true
destr_bool; intuition. Qed. 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 *)

forall b b' : bool, False -> b = b'

forall b b' : bool, False -> b = b'
contradiction. Qed. (* A more specific one that preserves compatibility with old hint bool_3 *)

forall b : bool, False -> b = true

forall b : bool, False -> b = true
contradiction. Qed. Hint Resolve absurd_eq_true : core. (* A specific instance of eq_trans that preserves compatibility with old hint bool_2 *)

forall x y z : bool, x = y -> y = z -> x = z

forall x y z : bool, x = y -> y = z -> x = z
apply eq_trans. Qed. Hint Resolve trans_eq_bool : core. (*****************************************)

Reflection of bool into Prop

(*****************************************)
Is_true and equality
Hint Unfold Is_true: bool.


forall x : bool, Is_true x -> x = true

forall x : bool, Is_true x -> x = true
destr_bool; tauto. Qed.

forall x : bool, x = true -> Is_true x

forall x : bool, x = true -> Is_true x
intros; subst; auto with bool. Qed.

forall x : bool, true = x -> Is_true x

forall x : bool, true = x -> Is_true x
intros; subst; auto with bool. Qed. Notation Is_true_eq_true2 := Is_true_eq_right (only parsing). Hint Immediate Is_true_eq_right Is_true_eq_left: bool.

forall x : bool, Is_true (eqb x x)

forall x : bool, Is_true (eqb x x)
destr_bool. Qed.

forall x y : bool, Is_true (eqb x y) -> x = y

forall x y : bool, Is_true (eqb x y) -> x = y
destr_bool; tauto. Qed.
Is_true and connectives

forall a b : bool, Is_true (a || b) -> Is_true a \/ Is_true b

forall a b : bool, Is_true (a || b) -> Is_true a \/ Is_true b
destr_bool; tauto. Qed. Notation orb_prop2 := orb_prop_elim (only parsing).

forall a b : bool, Is_true a \/ Is_true b -> Is_true (a || b)

forall a b : bool, Is_true a \/ Is_true b -> Is_true (a || b)
destr_bool; tauto. Qed.

forall b1 b2 : bool, Is_true b1 /\ Is_true b2 -> Is_true (b1 && b2)

forall b1 b2 : bool, Is_true b1 /\ Is_true b2 -> Is_true (b1 && b2)
destr_bool; tauto. Qed. 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).

forall a b : bool, Is_true (a && b) -> Is_true a /\ Is_true b

forall a b : bool, Is_true (a && b) -> Is_true a /\ Is_true b
destr_bool; auto. Qed. Hint Resolve andb_prop_elim: bool. Notation andb_prop2 := andb_prop_elim (only parsing).

forall b1 b2 : bool, Is_true b1 <-> Is_true b2 -> b1 = b2

forall b1 b2 : bool, Is_true b1 <-> Is_true b2 -> b1 = b2
destr_bool; tauto. Qed.

forall b1 b2 : bool, b1 = b2 -> Is_true b1 <-> Is_true b2

forall b1 b2 : bool, b1 = b2 -> Is_true b1 <-> Is_true b2
destr_bool; tauto. Qed.

forall b : bool, Is_true (negb b) -> ~ Is_true b

forall b : bool, Is_true (negb b) -> ~ Is_true b
destr_bool; tauto. Qed.

forall b : bool, ~ Is_true b -> Is_true (negb b)

forall b : bool, ~ Is_true b -> Is_true (negb b)
destr_bool; tauto. Qed.

forall b : bool, ~ Is_true (negb b) -> Is_true b

forall b : bool, ~ Is_true (negb b) -> Is_true b
destr_bool; tauto. Qed.

forall b : bool, Is_true b -> ~ Is_true (negb b)

forall b : bool, Is_true b -> ~ Is_true (negb b)
destr_bool; tauto. Qed.
Rewrite rules about andb, orb and if (used in romega)

forall (A : Type) (a a' : A) (b b' : bool), (if b && b' then a else a') = (if b then if b' then a else a' else a')

forall (A : Type) (a a' : A) (b b' : bool), (if b && b' then a else a') = (if b then if b' then a else a' else a')
destr_bool. Qed.

forall (A : Type) (a a' : A) (b : bool), (if negb b then a else a') = (if b then a' else a)

forall (A : Type) (a a' : A) (b : bool), (if negb b then a else a') = (if b then a' else a)
destr_bool. Qed. (*****************************************)

Alternative versions of andb and orb

with lazy behavior (for vm_compute)
(*****************************************)

Declare Scope lazy_bool_scope.

Notation "a &&& b" := (if a then b else false)
 (at level 40, left associativity) : lazy_bool_scope.
Notation "a ||| b" := (if a then true else b)
 (at level 50, left associativity) : lazy_bool_scope.

Local Open Scope lazy_bool_scope.


forall a b : bool, a && b = a &&& b

forall a b : bool, a && b = a &&& b
reflexivity. Qed.

forall a b : bool, a || b = a ||| b

forall a b : bool, a || b = a ||| b
reflexivity. Qed. (*****************************************)

Reflect: a specialized inductive type for

relating propositions and booleans, as popularized by the Ssreflect library.
(*****************************************)

Inductive reflect (P : Prop) : bool -> Set :=
  | ReflectT : P -> reflect P true
  | ReflectF : ~ P -> reflect P false.
Hint Constructors reflect : bool.
Interest: a case on a reflect lemma or hyp performs clever unification, and leave the goal in a convenient shape (a bit like case_eq).
Relation with iff :

forall (P : Prop) (b : bool), reflect P b -> P <-> b = true

forall (P : Prop) (b : bool), reflect P b -> P <-> b = true
destruct 1; intuition; discriminate. Qed.

forall (P : Prop) (b : bool), P <-> b = true -> reflect P b

forall (P : Prop) (b : bool), P <-> b = true -> reflect P b
destr_bool; intuition. Defined.
It would be nice to join reflect_iff and iff_reflect in a unique iff statement, but this isn't allowed since iff is in Prop.
Reflect implies decidability of the proposition

forall (P : Prop) (b : bool), reflect P b -> {P} + {~ P}

forall (P : Prop) (b : bool), reflect P b -> {P} + {~ P}
destruct 1; auto. Defined.
Reciprocally, from a decidability, we could state a reflect as soon as we have a bool_of_sumbool.
For instance, we could state the correctness of Bool.eqb via reflect:
b, b':bool

reflect (b = b') (eqb b b')
b, b':bool

reflect (b = b') (eqb b b')
destruct b, b'; now constructor. Defined.