Logic Symbols for Programmers

Truth

Symbol English Boolean
“True” 1

It’s true!

Falsity

Symbol English Boolean
“False” 0

It’s not true! (i.e. false)

Conjunction (∧)

Symbol Syntax English Boolean
𝑃∧𝑄 “𝑃 and 𝑄” &&

Conjunction () works more or less exactly like its boolean operator counterpart (&&). No real surprises here:

𝑃 𝑄 𝑃∧𝑄

Disjunction (∨)

Symbol Syntax English Boolean
𝑃∨𝑄 “𝑃 or 𝑄” ||

Disjunction () works more or less exactly like its boolean operator counterpart (||). No real surprises here:

𝑃 𝑄 𝑃∧𝑄

Negation (¬)

Symbol Syntax English Boolean
¬ ¬𝑃 “not 𝑃” !

Negation (¬) works more or less exactly like its boolean operator counterpart (!). No real surprises here:

𝑃 ¬𝑃

Implication (→)

Sym Syn Eng Bool
𝑃→𝑄 “𝑃 implies 𝑄” if … then …

Here’s where our programmer intuition first starts to break down. A quick look at the truth table below might leave us scratching our heads the first few times we refer to it. We might get how ⊥→⊥ could be ⊤, but how on earth does ⊥→⊤ end up ⊤?!

When coming from an imperative programming background, the important thing to grasp about implication is that it does not specify an “else” clause. In particular, we are not saying “if 𝑃, then 𝑄, else ¬𝑄”. We’re only making a claim about the state of 𝑄 if 𝑃 is ⊤. If 𝑃 is ⊥, 𝑄 can be whatever it pleases.

To put this into an example, say we have two statements 𝑁 and 𝑀 where 𝑁 is “it is nighttime” an 𝑀 is “the moon is visible”. A complete rendering of 𝑁→𝑀 might be something like, “If it is nighttime, the moon is visible — but if not, the moon either may, or may not be visible.”

𝑃 𝑄 𝑃→𝑄

Biconditional (↔)

Symbol Syntax English Boolean
𝑃↔𝑄 “𝑃 iff 𝑄” ==

If we think of the biconditional () as a boolean equivalence operator (==) our intuition will actually serve us pretty well as far as what the outcomes of the truth table will be.

But in logic, the biconditional is making a claim we seldom think through when simply checking equality in a program. 𝑃↔𝑄 is actually saying “𝑃 if, and only if, 𝑄” (usually abbreviated to “𝑃 iff 𝑄”).

So, in a way, the biconditional is kind of like an “exclusive implies”. If 𝑃 is ⊤ then 𝑄 must be ⊤, sure. But also, if 𝑃 is ⊥ then 𝑄 must be ⊥, too.

This ends up with the same results as testing equality, of course. But when trying to craft propositions, I find it easier to reason about when I say “if, and only if” in my head. YMMV.

𝑃 𝑄 𝑃↔𝑄

U.S. Logic Keyboard Layout

I’ve made a keyboard layout for macOS that makes some of these symbols easier to type. You can download it here:

U.S. Logic v1.0.0

Simply unzip and move the resulting bundle to ~/Library/Keyboard Layouts. Then select it as an Input Source in Keyboard Settings (you might need to log out and in before it shows up in the list).

The whole thing is just XML, so you can inspect it or modify it to your heart’s desire.

Key mappings:

Key Combo Symbol
⌥T
⌥⇧T
⌥V
⌥⇧V
⌥.
⌥,
⌥L ¬ (already the Mac default)
⌥I + any letter Mathematical Italic