vars.io

Introduction to Boolean Logic


A boolean value means a value can only take on one of two possibilities, commonly written as ,⊥, ⊤ or 0,10, 1 or false,true.

A proposition is any expression which can be reduced to a boolean value. For example, the question of whether 3=33 = 3 or 343 ≤ 4 can be reduced to the boolean value true. When it’s clearer to do so, we might also prefer to write a proposition in plain English, such as by asking whether 33 is a natural number.

Boolean logic is the study of labeling propositions, circuits, and other objects as either true or false, and then asking questions about all the things you’ve just labeled. In this cold way of thinking, true and false are merely names. To the mathematician, true might refer to whether a proposition is consistent with the rules they care about; to an engineer, true might refer to the state of a circuit or a bit of information. To these professions, logic is merely an accounting machine for manipulating information.

If we think about all the possible boolean functions which consume only one input, there will be 22=42^2 = 4 possible functions. Additionally, for 22-input boolean functions, there are n=4n = 4 unique boolean pairs and thus 2n=162^n = 16 possible functions.

More generally, for boolean functions accepting nn inputs, there are 22n2^{2^n} possible boolean functions.

Of these, NOT, OR, AND, and XOR are the most well known and they’re widely implemented in programming languages

namemathjavascriptjuliapython
NOT¬¬!!not
OR⎮⎮⎮⎮or
AND&&&&and
XOR^^^

Note that NOT is a 1-input boolean function, but is listed here due to its popularity.

Logical NOT (¬A¬A)

Logical NOT consumes only one input AA and it’s written as ¬A¬A.

AA¬A¬A
0011
1100

NOT is useful for transforming a proposition to an opposing, contradictory one. For example, if P(n)P(n) is the proposition that nn is natural, then ¬P(n)¬P(n) asks if nn isn’t natural.

Logical OR, AND, and XOR

AABB
0000000000
1100110011
0011110011
1111111100

Implication

Let AA and BB be propositions. There are times when knowing AA is true also means knowing BB is true. For example, knowing xx is a natural also means knowing xx is an integer, although the reverse isn’t always true.

Logical implication is a binary operator 𝗕×𝗕𝗕𝗕 × 𝗕 → 𝗕 represented by the relations table below.

AABB
000011
001111
110000
111111

One way of thinking about ABA → B is as a discussion on what kinds of evidence we would accept for knowing that BB is true. If we have ABA → B then we can use the truthiness of AA to prove BB. Otherwise, we can just directly prove BB even if AA turns out to be false. Both are acceptable ways to prove BB.

Implication Causality

When we say AA implies BB, this doesn’t mean that AA causes BB. For example, let’s say that proposition AA asks if a light switch is turned on, and proposition BB asks if black holes exist

Since the proposition about black holes is always true, we then have enough to say that AA implies BB, but that doesn’t mean we think AA causes BB. Instead we say that whenever we observe AA we also observe BB.

Universal Functions

NOR ()(↓) and NAND ()(↑) are notable because they’re the only functions that can individually rebuild all 1616 possible boolean functions.

AABB
00001111
00110011
11000011
11110000

De Morgan’s laws

¬(AB)(¬A)(¬B)(A ↓ B) ¬(A ∨ B) ⟷ (¬A) ∧ (¬B) \tag{A ↓ B}
¬(AB)(¬A)(¬B)(A ↑ B) ¬(A ∧ B) ⟷ (¬A) ∨ (¬B) \tag{A ↑ B}

The One Axiom

Let a,b,ca, b, c be booleans, and let be the NAND function. All of boolean algebra can be summarized with a single axiom:

((ab)c)(a((ac)a))=c ((a ↑ b) ↑ c) ↑ (a ↑ ((a ↑ c) ↑ a)) = c

In 2002, Stephen Wolfram, and separately William McCune and colleagues, independently curated and published this axiom from among over a dozen competing aesthetic choices.

Boolean Field

XOR and AND individually form groups and together they form the smallest field with only two elements, written as F2F_2 or GF(2)GF(2). Finite fields are also known as Galois Fields, named after famed mathematician Évariste Galois.

aba+bmod2 a ⊕ b ⟷ a + b \mod2
aba×bmod2 a ∧ b ⟷ a \operatorname{×} b \mod2

Note the multiplicative group of a field excludes 00 or else multiplication wouldn’t be invertible.

We can see that the functions are equivalent from the truth table below.

aabb++××
000000000000
001111110000
110011110000
111100001111

Logical Functions represented in F2F_2

nameexpressionpolynomial
NOT¬a¬aa+1a + 1
ANDaba ∧ babab
ORaba ∨ bab+a+bab + a + b
XORaba ⊕ ba+ba + b
IMPLYaba → bab+a+1ab + a + 1
NANDaba ↑ bab+1ab + 1
NORaba ↓ bab+a+b+1ab + a + b + 1

Higher Order Boolean Logic

The collection of sixteen 2-arity functions closed over the booleans are altogether known as zeroeth order boolean logic.

First order boolean logic allows you to look over “many” boolean propositions and say whether none, some, or all of the propositions are true, and so people often say that first order logic “quantifies” over sets.

Second order boolean logic is somewhat controversial. While first order logic allows you to discuss some or all of the objects you care about, it cannot discuss all the relations your objects may have among each other.

So far with zero-order logic we’ve only been evaluating two boolean arguments at a time, but what if we wanted to evaluate many at a time? For example, let’s say I have a set below:

S={0,1,2,3,4,5} S = \{ 0, 1, 2, 3, 4, 5 \}

All ()(∀) of the naturals

x,yN:x+y=y+x ∀x, y ∈ ℕ: x + y = y + x

This statement reads “for all xx and yy from N we have x+y=y+xx + y = y + x“.

Some ()(∃) of the naturals

x,yN:x+y<100 ∃x, y ∈ ℕ: x + y < 100

This reads as “there exists an xx and yy from N such that x+y<100x + y < 100“.

None ()(∄) of the naturals

The first statement can be read as “there exists no xx and yy from N such that x+y=0.5x + y = 0.5”. The second statement can be read as “for all xx and yy from N we have x+y0.5x + y ≠ 0.5“.

x,yN:x+y=0.5 ∄x, y ∈ ℕ: x + y = 0.5
x,yN:x+y0.5 ∀x, y ∈ ℕ: x + y ≠ 0.5

Saying “never true” is equivalent to saying “always false”.

There is a unique (!)(∃!) natural

!nN:n+n=0 ∃!n ∈ ℕ : n + n = 0

This statement can be read as “there exists a unique element nn from N such that n+n=0n + n = 0“.