LN 6: The Integers, The Booleans' Infinite In-laws
Standard: Numbers
In this lecture we use the integer type to investigate the larger, hidden world of operators on types. We cover associativity, commutativity, identity, and closure for the integers.
Last time we explored the Boolean Type through George Boole's historical discovery. We expanded on reducibility โ how different systems can solve the same problem โ and used that insight to visualize logical operations with Venn Diagrams.
Today's Agenda
Operator Syntax โ Types tell us what operators mean
Operator Notation โ Many ways to write the same operation
The Big Reveal โ Addition isn't about numbers!
Operator Syntax and Types
So far, our type judgments look like this:
$$a : A$$
But operators are functions, not just values. Addition takes two inputs and produces an output:
$$+ : (\mathbb{N}, \mathbb{N}) \to \mathbb{N}$$
This reads: "the + operator takes two natural numbers and returns a natural number."
Type Signatures for Operators
We can capture the behavior of all our operators this way:
Operator
Type Signature
Conjunction
Disjunction
Negation
Implication
Remember: Boole discovered that arithmetic on 0 and 1 represents logic! So arithmetic operators can work on Booleans too:
Fractions use vertical layout. Exponents use superscript. Integrals wrap around their argument. These aren't infix, prefix, or postfix โ they're custom notations designed for clarity.
Juxtaposition
Sometimes operators are so common we omit the symbol entirely:
Written
Meaning
(multiplication)
(conjunction)
(function application)
Unary Operators
Operators with one argument also have multiple notations. Negation alone has six common forms:
$$\lnot A \quad \sim A \quad !A \quad \bar{A} \quad A' \quad A^c$$
Type signature:
Ternary Operators
What about three arguments? The conditional operator is a classic example:
If the condition is true, return the consequence; otherwise, return the alternative.
# Python's version reads like English:
x = 1if condition else2
๐ก Key Insight: Syntax is flexible! The type tells us what an operator does. The notation is just how we choose to write it. Different fields use different notations because they clarify different things.
Addition isn't about numbers...
The previous lecture was to expand your understanding of mathematics to include the idea that completely separate systems of reasoning can be used to solve the same problem.
The previous part of this lecture was to show you it's very common to make new and useful ways to visualize different things.
So now we embark on the journey of showing you that this leads to an amazing conclusion!
It turns out that addition isn't about numbers at all! Let's find out why!
The Number Line: Your First Addition System
Remember the number line from grade school? Before you ever learned algebra, you learned to add by moving along a line.
Let's revisit that, but this time we'll hide the numbers to reveal what's really happening:
1 + 4 = 5 on a number line
Now let's see the same operation without any numbers visible:
Addition without numbers โ just movement!
Let's try another example: 2 + 3 = 5
2 + 3 = 5 on a number line
And again without numbers:
Same operation, no numbers โ still works!
What do you notice? Addition on the number line is really about movement and direction:
Start somewhere
Move in a direction
Your destination is the "sum"
The numbers are just labels for positions โ the actual operation is combining movements.
๐ก Key Insight: Addition is about movement/direction, not values. The number line taught us this as children, but we forgot it when we learned algebra!
Addition as Chain Building
Here's another way to visualize addition that has nothing to do with arithmetic.
What is "1"? A single node:
Loading graph...
What is "4"? Four separate nodes:
Loading graph...
What is "1 + 4"? Connect them into a chain!
Loading graph...
The result "5" is just the length of the combined chain!
Let's try another example: 2 + 3 = 5
What is "2"? Two nodes:
Loading graph...
What is "3"? Three nodes:
Loading graph...
What is "2 + 3"? Connect them into a chain!
Loading graph...
Again, the result "5" is the length of the combined chain โ no numbers needed!
๐ก Key Insight: Addition is about combining/concatenating โ linking things together. No arithmetic required!
String Concatenation: Addition Without Numbers
You've been doing "addition" with strings this whole time:
"Hello" + " " + "World"# => "Hello World"
There are no numbers here, yet the + operator feels natural. Why?
Because string concatenation combines things, just like:
Number line hops combine movements
Graph chains combine nodes
Numbers combine quantities
Remember our type signature from earlier?
+ : (String, String) -> String
The + operator is overloaded to work on strings because concatenation shares something fundamental with addition...
But what exactly do they share? Let's find out!
What Makes Addition... Addition?
We've seen addition in three different systems:
Number line โ combining movements
Graphs โ combining chains
Strings โ combining text
They all feel like addition, but they look completely different. What do they have in common?
The answer comes from Abstract Algebra, and it will change how you think about mathematics forever.
The Commutative Property
Let's test our systems:
Numbers:1 + 4 = 4 + 1 = 5 โ
Number Line: Does it matter if we hop +1 then +4, or hop +4 then +1?
1 + 4: hop 1, then hop 4
4 + 1: hop 4, then hop 1 โ same destination!
Both paths land at position 5! The number line is commutative. โ
Graph Chains: Does it matter which chain we connect first?
Loading graph...
Whether we connect "1 node to 4 nodes" or "4 nodes to 1 node", we get the same 5-node chain. โ
Both give "abc"! String concatenation IS associative. โ
The Big Reveal
Here's what Abstract Algebra tells us:
An operation that is both commutative AND associative behaves like addition.
This is the mathematical definition of "addition-like" behavior. The name of the operation doesn't matter. The symbol doesn't matter. Only these properties matter!
System
Commutative?
Associative?
"Addition"?
Number addition
โ
โ
Yes
Number line hops
โ
โ
Yes
Graph chain building
โ
โ
Yes
String concatenation
โ
โ
No!
String concatenation uses the + symbol, but it's not mathematically addition because it's not commutative!
The Mind-Bending Examples
If addition is defined by commutativity and associativity, what about other operations?
Multiplication:
Commutative? a ร b = b ร a โ
Associative? (a ร b) ร c = a ร (b ร c) โ
Wait... is multiplication also "addition"?!
Yes! Multiplication satisfies both properties โ it's structurally "additive"!
Boolean AND (โง):
Commutative? A โง B = B โง A โ
Associative? (A โง B) โง C = A โง (B โง C) โ
Boolean OR (โจ):
Commutative? A โจ B = B โจ A โ
Associative? (A โจ B) โจ C = A โจ (B โจ C) โ
AND and OR are both "addition" too!
๐คฏ Mind-Blown Moment: Multiplication (ร) is mathematically "addition" even though it uses a different symbol. String concatenation (+) is NOT mathematically "addition" even though it uses the + symbol!
The symbol is just syntax. The PROPERTIES define the true nature of an operation.
This feels wrong because we were taught these are "different" operations. But Abstract Algebra reveals they share the same fundamental structure! We just gave them different names based on what they operate on, not based on their mathematical behavior.
The String Concatenation Trap
Let's really drive this home.
We programmers have been using + for strings forever:
greeting = "Hello" + " " + "World"
But here's the uncomfortable truth:
Operation
Symbol
Commutative
Associative
Mathematically "Addition"?
Multiplication
ร
Yes
Yes
YES
Boolean AND
โง
Yes
Yes
YES
Boolean OR
โจ
Yes
Yes
YES
String concat
+
No
Yes
NO
The operation that looks most like addition (uses +) is the one that isn't addition!
This is a perfect example of syntax misleading us. Programmers borrowed the + notation because concatenation feels like adding, but it doesn't satisfy the mathematical requirements.
๐ Formal Term: String concatenation forms a monoid (associative with identity), but not an abelian group (which requires commutativity). Addition, multiplication, AND, and OR all form abelian groups over their domains!
More Algebraic Properties
Commutativity and associativity are just the beginning. Let's explore two more fundamental properties that help characterize operations.
The Identity Property
Every "addition-like" operation has an identity โ something that "does nothing":
System
Operation
Identity Element
Example
Natural numbers
Addition
0
5 + 0 = 5
Natural numbers
Multiplication
1
5 ร 1 = 5
Number line
Hops
0-hop (stay in place)
position + 0 = position
Graphs
Chain building
Empty chain
chain โ โ = chain
Strings
Concatenation
"" (empty string)
"hello" + "" = "hello"
Booleans
OR (โจ)
False
A โจ False = A
Booleans
AND (โง)
True
A โง True = A
Notice something interesting:
Addition's identity is 0
Multiplication's identity is 1
AND's identity is True
OR's identity is False
The identity depends on the operation, not the type!
๐ก Key Insight: Even string concatenation has an identity (the empty string). Having an identity doesn't make something "addition" โ you also need commutativity!
The Closure Property
You've already seen this pattern! Look at our type signatures:
The input types match the output type โ the operation never "escapes" to a different type.
But what about subtraction on naturals?
- : (Natural, Natural) -> ???
What's 3 - 5? It's -2, which is NOT a natural number! Subtraction on naturals is NOT closed โ the output type doesn't match the input type. We'd have to write:
- : (Natural, Natural) -> Integer โ Not closed!
Type
Operation
Type Signature
Closed?
Natural
Addition
(Natural, Natural) -> Natural
โ
Natural
Subtraction
(Natural, Natural) -> Integer
โ
Integer
Subtraction
(Integer, Integer) -> Integer
โ
String
Concatenation
(String, String) -> String
โ
Boolean
AND
(Boolean, Boolean) -> Boolean
โ
Boolean
OR
(Boolean, Boolean) -> Boolean
โ
Why does closure matter?
If an operation isn't closed, you can "escape" the type! Subtraction on naturals can produce integers, which aren't naturals. This is why mathematicians invented integers โ to make subtraction closed!
๐ Set Theory Note: In set theory, this is called being "closed over a set" โ same idea, different vocabulary. When you take a course on set theory, you'll see closure defined in terms of sets rather than types, but the concept is identical.
The Complete Picture
Let's put it all together with our comprehensive summary:
System
Operation
Symbol
Commutative
Associative
Identity
Closed
"Addition"?
Natural Numbers
Addition
+
Yes
Yes
0
Yes
Yes
Natural Numbers
Multiplication
ร
Yes
Yes
1
Yes
Yes!
Number Line
Hops
โ
Yes
Yes
0-hop
Yes
Yes
Graphs
Chain Building
โ
Yes
Yes
Empty
Yes
Yes
Strings
Concatenation
+
No
Yes
""
Yes
No!
Booleans
Disjunction (OR)
โจ
Yes
Yes
False
Yes
Yes!
Booleans
Conjunction (AND)
โง
Yes
Yes
True
Yes
Yes!
The Surprising Truth:
Multiplication (ร) IS mathematically "addition" โ despite its different name and symbol
String concatenation (+) is NOT mathematically "addition" โ despite using the + symbol
AND and OR are both mathematically "addition" โ they're just addition over different domains!
The Bigger Picture: Group Theory
What we've been exploring is the foundation of Group Theory, a branch of Abstract Algebra that studies these structural properties.
You don't need to memorize these, but notice:
String concatenation is a monoid (no commutativity)
Addition, multiplication, AND, OR are all abelian groups (fully "additive")
๐ฎ Looking Ahead: These properties will return when you study:
Linear Algebra โ Vector addition forms an abelian group
Cryptography โ Security relies on group theory
Programming Language Theory โ Type systems use algebraic structures
Category Theory โ The "algebra of composition"
The seemingly simple question "what is addition?" leads to some of the deepest mathematics in existence!
๐ Lecture Notes
Key Definitions:
Commutative Property โ Order doesn't matter: a โ b = b โ a
Associative Property โ Grouping doesn't matter: (a โ b) โ c = a โ (b โ c)
Identity Element โ An element e that leaves others unchanged: a โ e = a
Closure โ Output type matches input types: โ : (A, A) โ A
The "Addition" Test:
An operation is mathematically "addition" if it satisfies:
Commutativity โ
Associativity โ
Operation
Symbol
Commutative
Associative
"Addition"?
Number addition
+
โ
โ
Yes
Multiplication
ร
โ
โ
Yes
Boolean AND
โง
โ
โ
Yes
Boolean OR
โจ
โ
โ
Yes
String concat
+
โ
โ
No
The Key Insight:
The symbol doesn't define the operation โ the properties do:
Multiplication uses ร but IS mathematically "addition"
String concatenation uses + but is NOT mathematically "addition"