Skip to content

bool

def notNot (b : Bool) : not (not b) = b

Double negation: negating a boolean twice gives it back.

def andTrueR (b : Bool) : and b true = b

true is a right identity for and.

def orFalseR (b : Bool) : or b false = b

false is a right identity for or.

def andFalseR (b : Bool) : and b false = false

false is right-absorbing for and: and b false is false.

def andFalseL (b : Bool) : and false b = false

false is left-absorbing for and: and false b is false.

def orTrueR (b : Bool) : or b true = true

true is right-absorbing for or: or b true is true.

def orTrueL (b : Bool) : or true b = true

true is left-absorbing for or: or true b is true.

def deMorganAnd (a : Bool) (b : Bool) : not (and a b) = or (not a) (not b)

De Morgan’s law: not (a and b) = (not a) or (not b).

def deMorganOr (a : Bool) (b : Bool) : not (or a b) = and (not a) (not b)

De Morgan’s law: not (a or b) = (not a) and (not b).

def andIdem (b : Bool) : and b b = b

and is idempotent: and b b is b.

def orIdem (b : Bool) : or b b = b

or is idempotent: or b b is b.

def ite {A : Type} (cond : Bool) (then_val : A) (else_val : A) : A

If-then-else: returns the first value when the condition is true, otherwise the second.

def iteTrue {A : Type} (x : A) (y : A) : ite true x y = x

ite with a true condition returns the then-branch.

def iteFalse {A : Type} (x : A) (y : A) : ite false x y = y

ite with a false condition returns the else-branch.

def trueNeqFalse : Not (true = false)

The constructors true and false are distinct, proved by encode-decode.

def falseNeqTrue : Not (false = true)

The constructors false and true are distinct, proved by encode-decode.

def boolDecEq : DecEq Bool

Decidable equality on Bool, by case analysis on both arguments.

def xorFalseR (a : Bool) : xor a false = a

false is a right identity for xor.

def xorTrueR (a : Bool) : xor a true = not a

xor with true on the right negates: xor a true is not a.

def andOrAbsorb (a : Bool) (b : Bool) : and a (or a b) = a

Absorption law: a and (a or b) = a.

def orAndAbsorb (a : Bool) (b : Bool) : or a (and a b) = a

Absorption law: a or (a and b) = a.

def andDistribOr (a : Bool) (b : Bool) (c : Bool) : and a (or b c) = or (and a b) (and a c)

and distributes over or on the left.

def orDistribAnd (a : Bool) (b : Bool) (c : Bool) : or a (and b c) = and (or a b) (or a c)

or distributes over and on the left.

def boolEq (a : Bool) (b : Bool) : Bool

Boolean equality test: true exactly when both arguments are equal.

def boolEqRefl (a : Bool) : boolEq a a = true

boolEq is reflexive: every boolean equals itself.

def boolEqComm (a : Bool) (b : Bool) : boolEq a b = boolEq b a

boolEq is symmetric in its arguments.

def xorAssoc (a : Bool) (b : Bool) (c : Bool) : xor a (xor b c) = xor (xor a b) c

xor is associative.

def boolRec (C : Type) (ct : C) (cf : C) (b : Bool) : C

Non-dependent recursor for Bool: picks the first value for true, the second for false.

def boolRecTrue (C : Type) (ct : C) (cf : C) : boolRec C ct cf true = ct

boolRec computes to its true case on true.

def boolRecFalse (C : Type) (ct : C) (cf : C) : boolRec C ct cf false = cf

boolRec computes to its false case on false.

def xorNotL (a : Bool) (b : Bool) : xor (not a) b = not (xor a b)

Negating the left argument of xor negates the result.

def xorNotR (a : Bool) (b : Bool) : xor a (not b) = not (xor a b)

Negating the right argument of xor negates the result.

def nand (a : Bool) (b : Bool) : Bool

Boolean NAND: the negation of and.

def nor (a : Bool) (b : Bool) : Bool

Boolean NOR: the negation of or.

def iff (a : Bool) (b : Bool) : Bool

Boolean biconditional: true when each argument implies the other.

def impliesTrue (a : Bool) : implies a true = true

Anything implies true.

def impliesSelf (a : Bool) : implies a a = true

Every boolean implies itself.

def boolCases (b : Bool) : or (boolEq b true) (boolEq b false) = true

Every boolean is either true or false, stated as a boolean test.

def xorNeqBoolEq (a : Bool) (b : Bool) : xor a b = not (boolEq a b)

xor is the negation of boolean equality.

def andDistribXor (a : Bool) (b : Bool) (c : Bool) : and a (xor b c) = xor (and a b) (and a c)

and distributes over xor on the left.

def nandComm (a : Bool) (b : Bool) : nand a b = nand b a

nand is commutative.

def norComm (a : Bool) (b : Bool) : nor a b = nor b a

nor is commutative.

def impliesAsOr (a : Bool) (b : Bool) : implies a b = or (not a) b

Boolean implication unfolds definitionally to (not a) or b.

def iffRefl (a : Bool) : iff a a = true

iff is reflexive: every boolean is equivalent to itself.

def iffComm (a : Bool) (b : Bool) : iff a b = iff b a

iff is symmetric in its arguments.

def majority (a : Bool) (b : Bool) (c : Bool) : Bool

Majority vote of three booleans: true when at least two of them are true.

def cond {A : Type} (b : Bool) (x : A) (y : A) : A

Conditional expression: the first value when the boolean is true, otherwise the second.

def boolToNat (b : Bool) : Nat

Converts a boolean to a natural number: true to 1 and false to 0.

def condTrueId {A : Type} (x : A) (y : A) : cond true x y = x

cond with true returns its first value.

def condFalseId {A : Type} (x : A) (y : A) : cond false x y = y

cond with false returns its second value.

def condSame {A : Type} (b : Bool) (x : A) : cond b x x = x

cond with identical branches returns that value regardless of the condition.

def all3 (a : Bool) (b : Bool) (c : Bool) : Bool

true when all three booleans are true.

def any3 (a : Bool) (b : Bool) (c : Bool) : Bool

true when at least one of three booleans is true.

def countTrue3 (a : Bool) (b : Bool) (c : Bool) : Nat

Counts how many of three booleans are true.

def allTrue (xs : List Bool) : Bool

true when every boolean in the list is true (the empty list gives true).

def anyTrue (xs : List Bool) : Bool

true when some boolean in the list is true (the empty list gives false).

def allTrueConsTrue (xs : List Bool) : allTrue (cons true xs) = allTrue xs

Prepending true does not change allTrue.

def anyTrueConsFalse (xs : List Bool) : anyTrue (cons false xs) = anyTrue xs

Prepending false does not change anyTrue.

def allTrueConsFalse (xs : List Bool) : allTrue (cons false xs) = false

A list starting with false has allTrue equal to false.

def anyTrueConsTrue (xs : List Bool) : anyTrue (cons true xs) = true

A list starting with true has anyTrue equal to true.

def andComplement (a : Bool) : and a (not a) = false

Complement law: a and (not a) = false.

def orComplement (a : Bool) : or a (not a) = true

Complement law: a or (not a) = true.

def andComplementL (a : Bool) : and (not a) a = false

Complement law with the negation on the left: (not a) and a = false.

def orComplementL (a : Bool) : or (not a) a = true

Complement law with the negation on the left: (not a) or a = true.

def eqBool (a : Bool) (b : Bool) : Bool

Boolean equality test: true exactly when both arguments are equal (same as boolEq).

def eqBoolRefl (a : Bool) : eqBool a a = true

eqBool is reflexive: every boolean equals itself.

def eqBoolComm (a : Bool) (b : Bool) : eqBool a b = eqBool b a

eqBool is symmetric in its arguments.

def eqBoolNotNot (a : Bool) (b : Bool) : eqBool (not a) (not b) = eqBool a b

Negating both arguments does not change eqBool.

def xorIsNotEqBool (a : Bool) (b : Bool) : xor a b = not (eqBool a b)

xor is the negation of eqBool.

def xorCancel (a : Bool) (b : Bool) : xor a (xor a b) = b

xor with the same value twice cancels: a xor (a xor b) = b.

def xorCancelR (a : Bool) (b : Bool) : xor (xor a b) b = a

xor with the same value twice cancels on the right: (a xor b) xor b = a.

def xorFalseL (b : Bool) : xor false b = b

false is a left identity for xor.

def xorTrueL (b : Bool) : xor true b = not b

xor with true on the left negates: xor true b is not b.

def xorNotNot (a : Bool) (b : Bool) : xor (not a) (not b) = xor a b

Negating both arguments does not change xor.

def boolMeet (a : Bool) (b : Bool) : Bool

Lattice meet on Bool, which is and.

def boolJoin (a : Bool) (b : Bool) : Bool

Lattice join on Bool, which is or.

def boolTop : Bool

Top element of the boolean lattice, true.

def boolBot : Bool

Bottom element of the boolean lattice, false.

def boolMeetComm (a : Bool) (b : Bool) : boolMeet a b = boolMeet b a

Lattice meet on Bool is commutative.

def boolJoinComm (a : Bool) (b : Bool) : boolJoin a b = boolJoin b a

Lattice join on Bool is commutative.

def boolMeetAssoc (a : Bool) (b : Bool) (c : Bool) : boolMeet a (boolMeet b c) = boolMeet (boolMeet a b) c

Lattice meet on Bool is associative.

def boolJoinAssoc (a : Bool) (b : Bool) (c : Bool) : boolJoin a (boolJoin b c) = boolJoin (boolJoin a b) c

Lattice join on Bool is associative.

def boolMeetTop (a : Bool) : boolMeet a boolTop = a

Top is an identity for meet.

def boolMeetBot (a : Bool) : boolMeet a boolBot = boolBot

Bottom is absorbing for meet.

def boolJoinBot (a : Bool) : boolJoin a boolBot = a

Bottom is an identity for join.

def boolJoinTop (a : Bool) : boolJoin a boolTop = boolTop

Top is absorbing for join.

def boolMeetIdem (a : Bool) : boolMeet a a = a

Lattice meet on Bool is idempotent.

def boolJoinIdem (a : Bool) : boolJoin a a = a

Lattice join on Bool is idempotent.

def boolMeetAbsorb (a : Bool) (b : Bool) : boolMeet a (boolJoin a b) = a

Lattice absorption: meet a (join a b) = a.

def boolJoinAbsorb (a : Bool) (b : Bool) : boolJoin a (boolMeet a b) = a

Lattice absorption: join a (meet a b) = a.

def nandSelf (a : Bool) : nand a a = not a

nand of a value with itself is its negation.

def norSelf (a : Bool) : nor a a = not a

nor of a value with itself is its negation.

def nandTrueL (b : Bool) : nand true b = not b

nand true b is not b.

def nandFalseL (b : Bool) : nand false b = true

nand false b is true.

def norFalseL (b : Bool) : nor false b = not b

nor false b is not b.

def norTrueL (b : Bool) : nor true b = false

nor true b is false.

def nandTrueR (a : Bool) : nand a true = not a

nand a true is not a.

def nandFalseR (a : Bool) : nand a false = true

nand a false is true.

def norFalseR (a : Bool) : nor a false = not a

nor a false is not a.

def norTrueR (a : Bool) : nor a true = false

nor a true is false.

def doubleNand (a : Bool) (b : Bool) : nand (nand a b) (nand a b) = and a b

and expressed with NAND alone: nand (nand a b) (nand a b) = a and b.

def notInjective (a : Bool) (b : Bool) (p : not a = not b) : a = b

not is injective: equal negations imply equal booleans.

def iteSame {A : Type} (b : Bool) (x : A) : ite b x x = x

ite with identical branches returns that value regardless of the condition.

def iteIsCond {A : Type} (b : Bool) (x : A) (y : A) : ite b x y = cond b x y

ite and cond compute the same result.

def iteNot {A : Type} (b : Bool) (x : A) (y : A) : ite (not b) x y = ite b y x

Negating the condition of ite swaps its branches.

def notAndTrue (a : Bool) : not (and a true) = not a

not (a and true) = not a.

def notAndFalse (a : Bool) : not (and a false) = true

not (a and false) = true.

def notOrTrue (a : Bool) : not (or a true) = false

not (a or true) = false.

def notOrFalse (a : Bool) : not (or a false) = not a

not (a or false) = not a.

def meetDistribXor (a : Bool) (b : Bool) (c : Bool) : boolMeet a (xor b c) = xor (boolMeet a b) (boolMeet a c)

Lattice meet on Bool distributes over xor.

def nandAsDeMorgan (a : Bool) (b : Bool) : nand a b = or (not a) (not b)

nand equals (not a) or (not b), by De Morgan.

def norAsDeMorgan (a : Bool) (b : Bool) : nor a b = and (not a) (not b)

nor equals (not a) and (not b), by De Morgan.

def impliesFalseL (b : Bool) : implies false b = true

false implies anything.

def iffIsEqBool (a : Bool) (b : Bool) : iff a b = eqBool a b

iff agrees with eqBool.

def boolToNatAnd (a : Bool) (b : Bool) : boolToNat (and a b) = boolToNat (ite a b false)

boolToNat of and a b equals boolToNat of ite a b false.

def boolToNatNotNot (a : Bool) : boolToNat (not (not a)) = boolToNat a

Double negation does not change boolToNat.

def boolMeetDistribJoin (a : Bool) (b : Bool) (c : Bool) : boolMeet a (boolJoin b c) = boolJoin (boolMeet a b) (boolMeet a c)

Lattice meet on Bool distributes over join.

def boolJoinDistribMeet (a : Bool) (b : Bool) (c : Bool) : boolJoin a (boolMeet b c) = boolMeet (boolJoin a b) (boolJoin a c)

Lattice join on Bool distributes over meet.

def boolMeetComplement (a : Bool) : boolMeet a (not a) = boolBot

Lattice complement: the meet of a value and its negation is bottom.

def boolJoinComplement (a : Bool) : boolJoin a (not a) = boolTop

Lattice complement: the join of a value and its negation is top.

theorem simpAndTrue (b : Bool) : and true b = b

true is a left identity for and, proved with simp.

theorem simpOrFalse (b : Bool) : or false b = b

false is a left identity for or, proved with simp.

data Empty_Bool

An empty type used as the target of trueNeqFalseTac.

theorem trueNeqFalseTac (h : true = false) : Empty_Bool

A proof of true = false yields an element of the empty type Empty_Bool, proved with discriminate.

def natToBool (n : Nat) : Bool

Converts a natural number to a boolean: zero to false, any successor to true.

def bool3and (a : Bool) (b : Bool) (c : Bool) : Bool

Three-way conjunction, grouped as (a and b) and c.

def bool3or (a : Bool) (b : Bool) (c : Bool) : Bool

Three-way disjunction, grouped as (a or b) or c.

def conditional {A : Type} (b : Bool) (t : A) (f : A) : A

If-then-else as a function: the first value when the boolean is true, otherwise the second.

def natToBoolBoolToNat (b : Bool) : natToBool (boolToNat b) = b

Converting a boolean to a number and back returns the original boolean.

def natToBoolSucc (n : Nat) : natToBool (succ n) = true

Every successor converts to true.

def bool3andIsAnd (a : Bool) (b : Bool) (c : Bool) : bool3and a b c = and (and a b) c

bool3and unfolds to (a and b) and c.

def bool3andFalseL (b : Bool) (c : Bool) : bool3and false b c = false

bool3and with false first is false.

def bool3andTrueL (b : Bool) (c : Bool) : bool3and true b c = and b c

bool3and with true first is the and of the other two.

def bool3andFalseM (a : Bool) (c : Bool) : bool3and a false c = false

bool3and with false in the middle is false.

def bool3andFalseR (a : Bool) (b : Bool) : bool3and a b false = false

bool3and with false last is false.

def bool3orIsOr (a : Bool) (b : Bool) (c : Bool) : bool3or a b c = or (or a b) c

bool3or unfolds to (a or b) or c.

def bool3orTrueL (b : Bool) (c : Bool) : bool3or true b c = true

bool3or with true first is true.

def bool3orFalseL (b : Bool) (c : Bool) : bool3or false b c = or b c

bool3or with false first is the or of the other two.

def bool3orTrueM (a : Bool) (c : Bool) : bool3or a true c = true

bool3or with true in the middle is true.

def bool3orTrueR (a : Bool) (b : Bool) : bool3or a b true = true

bool3or with true last is true.

def majorityIdem12 (a : Bool) (b : Bool) : majority a a b = a

When the first two votes agree, majority returns that vote.

def majorityIdem13 (a : Bool) (b : Bool) : majority a b a = a

When the first and third votes agree, majority returns that vote.

def majorityAllSame (a : Bool) : majority a a a = a

majority of three equal votes is that vote.

def conditionalTrue {A : Type} (t : A) (f : A) : conditional true t f = t

conditional with true returns its first value.

def conditionalFalse {A : Type} (t : A) (f : A) : conditional false t f = f

conditional with false returns its second value.

def conditionalSame {A : Type} (b : Bool) (x : A) : conditional b x x = x

conditional with identical branches returns that value regardless of the condition.

def conditionalNot {A : Type} (b : Bool) (x : A) (y : A) : conditional (not b) x y = conditional b y x

Negating the condition of conditional swaps its branches.

def conditionalIsIte {A : Type} (b : Bool) (x : A) (y : A) : conditional b x y = ite b x y

conditional and ite compute the same result.

def natToBoolAdd (m : Nat) : natToBool (add (succ zero) m) = true

One plus any natural number converts to true.

def boolToNatOr (a : Bool) (b : Bool) : boolToNat (or a b) = boolToNat (ite a true b)

boolToNat of or a b equals boolToNat of ite a true b.

def boolToNatNot (b : Bool) : add (boolToNat b) (boolToNat (not b)) = succ zero

A boolean and its negation contribute exactly one true between them: their boolToNat values sum to 1.

def bool3andAssoc (a : Bool) (b : Bool) (c : Bool) : and a (and b c) = and (and a b) c

and is associative.

def bool3orAssoc (a : Bool) (b : Bool) (c : Bool) : or a (or b c) = or (or a b) c

or is associative.

def notXorSelf (a : Bool) (b : Bool) : not (xor a b) = eqBool a b

The negation of xor is eqBool.

def notBool3and (a : Bool) (b : Bool) (c : Bool) : not (bool3and a b c) = bool3or (not a) (not b) (not c)

De Morgan for three: the negation of bool3and is bool3or of the negations.

def notBool3or (a : Bool) (b : Bool) (c : Bool) : not (bool3or a b c) = bool3and (not a) (not b) (not c)

De Morgan for three: the negation of bool3or is bool3and of the negations.