Quick Insight: Intuitive Meaning of Division

While working on some math colorizations I ran across some interpretations of division.

Multiplication can be repeated addition, scaling, rotating (via imaginary numbers), and more.

What about division? Let's take a look.

The permutation formula lets us pick 3 items out of 10, in a specific order. To order 3 items from 10, we have 10 options for the first choice, 9 options for the second, and 8 for the third, giving us 10 _ 9 _ 8 = 720 possibilities.

But how is this process written in most math books?

\displaystyle{P(10, 3) =\frac{10!}{(10 - 3)!} = 720}

What's going on?

Well, we just want a portion of the factorial. 10! gives the full sequence (10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1), but we want to stop it after we hit 8. That means we divide by 7!. The only part that's not removed is 10 _ 9 * 8.

In this case, division is acting like a brake/boundary/filter that stops the factorial from running hog-wild. (They get out of control, you know.)

permutation formula colorized

Ah! If writing a software program, you wouldn't actually compute 10!, 7! and do a division. What if we needed 3 choices from 1000 options? (1000 factorial has 2568 digits and will make your computer cry. I told you this would happen!)

If we realize the role of division as a boundary marker, we can just compute 1000 _ 999 _ 998 = 997,002,000 and call it a day.

Let's keep going.

Suppose we don't care about the order of the items we pick: ABC is the same as CBA. What to do?

Well, we can apply another division! This time, we don't want a boundary, but want to merge/consolidate/group up similar items. Everything that looks like ABC (e.g., ACB, BAC, BCA, CAB, CBA) should be counted once.

With 3 items there are 3! rearrangements, so the final count is 720/3! = 720/6 = 120 choices.

As a formula:

combination formula colorized

Neat, right? The division in the permutation formula acts as a boundary, and the division in the combination formula is a type of "group up". I imagine the variations being merged into a single option:

The words we pick frame how we think about an equation. "Divide" implies we're splitting things apart. If we know alternate meanings (repeated subtraction, boundaries, consolidation), we may pick a better description. Saying "divide by k!" doesn't have the same intuition as "consolidate the reorderings".

I think math concepts are fundamentally simple but their written description may not be. (Ever try to describe how to put on a shirt?) The goal is finding the words to make the idea click.

Happy math.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Quick Insight: Subtracting Negative Numbers

A math teacher recently asked how to explain the concept of subtracting negative numbers to her class. Why is 8 - (-6) = 14 the same as 8 + 6 = 14?

I've long internalized negatives as "opposite" and subtraction as "opposite of addition" so in my head, I had a notion of "opposite of opposite of addition" which simplifies down to "addition".

But that inner verbalization was still pretty abstract. After thinking of a better intuition, here was my reply:

Great question! I had to think about it for a bit. Addition and subtraction are related, but slightly different, than positive and negative numbers.

Imagine going on a walk. You're facing forward, and take 8 steps forward. This is really:

0 + 8

0 is your starting point. The "+" means "facing forward" and "8" means "8 steps in the direction you're facing". Ok.

Now, let's say we want to keep facing forward and take 6 more steps. That'd be:

8 + 6 = 14

Which gives us 14 steps from our starting point. What if we had faced backwards and took 6 steps?

8 - 6 = 2

Which means we're pretty close to our starting point, just 2 steps away. What if we had faced backwards but walked backwards 6 steps?

8 - (-6) = 14

Ah! The addition/subtraction tells us which way to face, and the positive/negative tells us if our steps will be forward or backward (regardless of the way we're facing).

positive and negative number addition

In a sense, the addition/subtraction acts as a verb ("face forward" or "face backward"), and the positive/negative acts as an adjective ("regular steps" or "backwards steps"). Or maybe it's an adverb, modifying how we walk (walk forwardly, walk backwardly). You get the idea.

For older students, "subtracting a negative" can be seen as "cancelling a debt". If I have a debt of \$30, and someone "subtracts it", I've effectively gained \$30. In general, if you remove a disadvantage, you have improved your situation -- a positive.

These explanations are a bit abstract, the walking one is more fun to try directly. I actually walked around while thinking through the intuition. (If you're adventurous, you might start thinking about taking side steps, or jumping, and how that would be represented.)

Happy math.

Appendix

When doing simple arithmetic, we only track the final location, not orientation. Facing backwards and walking backwards might have us looking at 0 while we advance forward. But mathematically, our endpoint is the same: 8 - (-6) = 8 + 6 = 14.

If we care about the way we're facing, we need a more complex math object (a vector) to keep track of our orientation as well as position ("14, facing forward" vs. "14, facing backward"). Perhaps we'd use a line integral, moving along a path and tracking the direction we face as we go.

A fitting analogy leads to questions about what else is possible.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Intuition For The Golden Ratio

Summary: The Golden Ratio is special because it perfectly balances addition and multiplication.

The Golden Ratio (1.618...) is often presented with an air of mysticism as "the perfect proportion". Setting aside whether we can find the Golden Ratio in the leaves of a nearby houseplant, what makes it special from a math perspective?

Well, let's try to make a pattern that's as balanced (symmetric) as possible.

A quick guess is something like 1, 1, 1, 1, 1. Every item is identical, but it's not very interesting -- it's a song where every word is the same. Does it rhyme? Yeah. Do I care? Not really.

Ok, let's try 1, 2, 3, 4, 5. There's a symmetry in the relationship that every element is one more than the previous. But if we skip around to random elements, there's no real connection: what do 3, 8, and 17 have in common?

Ok, fine. What about 1, 2, 4, 8, 16? Each element is twice the previous, and all the numbers are clean powers of two. But... what about addition? Can we create new elements in our pattern from the previous ones?

  • 1 + 2 = 3 [not quite 4...]
  • 1 + 2 + 4 = 7 [not quite 8...]
  • 1 + 2 + 4 + 8 = 15 [not quite 16...]

Argh. We can concoct a rule for addition ("Every element is the sum of all previous elements... plus an extra 1"), but that's not clean and you know it. Let's figure this out.

Symmetry Between Addition and Multiplication

Our goal is a pattern that's connected with both addition and multiplication. No varying number of additions, no cute "+1" on the end. Just a clean, simple relationship.

First off, we need to make every item connected by multiplication. We need powers:

1 x x^2 x^3 x^4

Whatever number the pattern uses (x), everything will be a power of it (just like 1, 2, 4, 8, although that sequence wasn't symmetric enough).

Next, we need an "addition symmetry" that connects the items. Every element should be buildable from the previous ones without extra rules. Throwing a few ideas against the wall:

  • Can we have 1 + x = x? If we subtract x from both sides, that leads to 1 = 0. Uh oh, we're breaking math.
  • How about 1 + 1 = x? Maybe we can allow multiple copies of everything. But that's just another way of getting x=2, you sneak.
  • How about 1 + x = 1? Ack, that just implies x = 0. 0, 0, 0, 0 is symmetric but not interesting.

Hrm. The next addition pattern that might make sense is 1 + x = x^2. If we follow this idea, here's what happens:

golden ratio symmetry of addition and multiplication

A few notes:

  • Starting from a single connection 1 + x = x^2, we can multiply through by x and get x + x^2 = x^3. Every element is made from the previous two.
  • $x^0$ is another way to write 1. Makes the pattern easier to see, I think.
  • Everything in the pattern grid is just our original pattern, shifted a bit. Neat.

Ok. That's the goal for the pattern, let's try to solve it.

\displaystyle{(1 + x) = x^2 }

\displaystyle{x^2 - x - 1 = 0}

We can find the "x" that makes this relationship true using the quadratic formula:

\displaystyle{ x=\frac{-b + \sqrt {b^2-4ac}}{2a}\quad\text{and}\quad x=\frac{-b - \sqrt {b^2-4ac}}{2a} }

Plugging in a=1, b=-1, and c=-1, we get:

\displaystyle{ x=\frac{1 + \sqrt {1+4}}{2}\quad\text{and}\quad x=\frac{1 - \sqrt {1+4}}{2} }

We only want a positive solution (the new part can't be negative), so we have

\displaystyle{ x=\frac{1 + \sqrt {1+4}}{2}\quad\text = \frac{1 + \sqrt {5}}{2} = 1.618... = \phi }

We label the solution Phi ($\phi$).

You can see it happening below. There are slight differences as the decimals go on -- computers have fixed precision.

Visualize the Intuition

Many descriptions of the Golden Ratio describe splitting a whole into parts, each of which is in the golden ratio:

Intuition For The Golden Ratio

I prefer the "growth factor" scenario, where we start with a single item (1.0) and evolve it, while keeping it linked to its ancestors with both arithmetic and multiplication. Just describing a ratio doesn't call out the symmetry we're able to achieve.

Visually, I see a growing blob, like this:

golden ratio addition and multiplication circle diagram

As we scale by Phi each time (1.618) we get:

  • Addition symmetry: Each element is the sum of the previous two
  • Multiplication symmetry: Each element is a scaled version of the previous
  • Growth symmetry: Addition and multiplication change the pattern identically

Aha! That's a nice combo if I ever saw one. The "growing blob" can represent the length of a line, a 2d shape, an angle -- which can lead to interesting patterns:

Intuition For The Golden Ratio

The key relationship is we move from one blob to the next, such that multiplication and addition have the same effect:

golden ratio scaling factor

We've described the Golden Ratio with different phrasing: the scaling factor (f) must equal the original (1) plus the previous item (1/f). We divide by our growth factor to find the previous element given the current one.

Solving $f = 1 + \frac{1}{f}$ yields the Golden Ratio as before.

Is the Golden Ratio Everywhere?

The Golden Ratio tends to be oversold in its occurrences. While it may appear occasionally in nature, buildings, and portraits, if you draw lines thick enough many things have a ratio of about 1.5 to 1.

I think the deeper intuition comes from realizing we've made addition and multiplication symmetric.

The Fibonacci sequence is built from having every piece built from the two before:

Using a certain formula, we can jump to a Fibonacci number by repeated scaling (exponents) instead of laboriously adding the parts. And maybe we'd come to expect the Golden Ratio here, since it's the scaling factor that allows two parts to add to the next item in the sequence. (The specifics of dividing by $\sqrt 5$ are because we need to adjust based on the starting pieces.)

Rather than hunting for examples of the Golden Ratio in the produce aisle, let's soak in the beauty of balancing the forces of multiplication and addition.

Happy math.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Different Interpretations for the Number Zero

Zero graduated from a placeholder for absentee digits to its own concept. Here's a few more interpretations of zero:

  • The void: Utter emptiness, the absence of any activity
  • The neutral zone: A cancellation between positive and negative influences

Mathematically, we can write:

\displaystyle{ 0 = 1 - 1}

And to a calculator, these are the same. Are they? There's a suspicion nothing (0) and complete cancellation (1 - 1) aren't quite identical.

Physics

In physics, there's the notion of a stable and unstable equilibrium. Take two pencils. Lay one on the table, balance the other on its tip.

They're both 'balanced'. There's zero motion. Yet one is a precarious position, carefully opposing the pull of gravity, while the other lays peacefully.

Lie on the floor for 10 minutes. Hold the plank pose for 10 minutes. From a physics perspective, no work was done (nothing moved), but your quivering arms tell a different story.

Algebra

In algebra, we constantly factor equations to find roots.

Why? In short, we want to find the "neutral zones" where all forces balance.

Factoring

\displaystyle{f(x) = x^2 + 2x + 3}

means "Is there a value where x^2, 2x, and 3 cancel each other out?". We arrange the scenario so the neutral zone is where we want to be (such as having no error, or having competing goals align).

There is often a "trivial solution", where we can plug in x=0 and all inputs disappear (lying the pencil on the table... or just taking it away!). However, we're more interested in finding a "neutral zone", where multiple, existing forces balance.

Programming

Programming languages distinguish "void/undefined/null" (a value is not set) and "having a value of emptiness".

var i; // i is undefined
i = 0; // i is now set to 4 bytes of "nothingness"

If we imagine data storage as a light switch, we have

  • 1: switch is on
  • 0: switch is off
  • null: there is no switch (or spoon)

By itself, var i is just a name or pointer, but it's not yet referring to anything (not even nothingness). It's not that Gazasdasrb means "nonsense", it's that Gazasdasrb has no meaning at all.

Division By Zero

Many math explanations say you "can't divide by zero". It's not that you can't, it's that it's undefined. What does division by zero mean? What does Gazasdasrb mean?

If we pick a specific value for the result of a division by zero (let's say 3/0 = 15) then we immediately have contradictions (this means 15 * 0 = 3).

We avoid this trouble by saying division by zero is "undefined", or "we haven't got around to picking a value, nyah". In some games, the only winning move is not to play.

(Sometimes we define a value for strange expressions (such as $0^0 = 1$), if it's useful and doesn't lead to contradictions.)

Calculus

Calculus dances with the concept of zero. Beyond the study of limits and infinitesimals, we are curious about the meaning of "zero change".

When I say a function isn't changing ("the derivative is zero"), it's usually not enough information. Are we not changing because we're at a minimum, a maximum, or precariously balanced between a hill and ravine?

calculus-graph-zero

There are tricks, like the second-derivative test, to see what type of "zero change" we have.

In Society

Society sets many goals for itself. Here's one: reduce littering. Given our "multiple zero" interpretation, we could accomplish this with:

  • A robot army that picks up thousands of pieces of litter each day (1000 drops - 1000 cleanups)
  • Teaching people not to litter (0 drops)

It's the same result -- clean streets -- but what strategy do we prefer?

In general, any negative influence (unemployment, crime, pollution, etc.) can be seen through the lens of prevention or cure, an absence vs. meticulous cancellation. The reading is 0 in both cases, and it's up to us to make the distinction. (Sir, unfrozen Caveman Og is asking about Wooly Mammoth attacks again. Should we sell him more repellent?)

Philosophy

In Eastern philosophy there's the notion of non-doing or Wu Wei. Our brains think of "non doing" as sitting lazily on the couch. But maybe it's another type of zero. (Again, hold a plank for 10 minutes and tell me nothing happened.)

Exploring Ideas with Math

This essay is quick armchair philosophy from an equation. The words "something comes from nothing" aren't convincing. But if I write $0 = 1 - 1$, boom, an idea snaps into place. How did 5 symbols convince you in seconds? Isn't that amazing?

Calculations are nice, but not the end goal of math education. Intuition means you're comfortable thinking, daydreaming, and exploring a concept with math as a guidepost. Now imagine having this comfort with the notions of shape, change, and chance (geometry, calculus, statistics).

Let's learn to sing with math, baby.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Surprising Patterns in the Square Numbers (1, 4, 9, 16…)

A quick puzzle for you — look at the first few square numbers:

1, 4, 9, 16, 25, 36, 49…

And now find the difference between consecutive squares:

1 to 4   = 3
4 to 9   = 5
9 to 16  = 7
16 to 25 = 9
25 to 36 = 11
…

Huh? The odd numbers are sandwiched between the squares?

Strange, but true. Take some time to figure out why — even better, find a reason that would work on a nine-year-old. Go on, I’ll be here.

Exploring Patterns

We can explain this pattern in a few ways. But the goal is to find a convincing explanation, where we slap our forehands with “ah, that’s why!”. Let’s jump into three explanations, starting with the most intuitive, and see how they help explain the others.

Geometer’s Delight

It’s easy to forget that square numbers are, well… square! Try drawing them with pebbles

Square numbers 1 4 and 9

Notice anything? How do we get from one square number to the next? Well, we pull out each side (right and bottom) and fill in the corner:

growing the square numbers

While at 4 (2×2), we can jump to 9 (3×3) with an extension: we add 2 (right) + 2 (bottom) + 1 (corner) = 5. And yep, 2×2 + 5 = 3×3. And when we’re at 3, we get to the next square by pulling out the sides and filling in the corner: Indeed, 3×3 + 3 + 3 + 1 = 16.

Each time, the change is 2 more than before, since we have another side in each direction (right and bottom).

Another neat property: the jump to the next square is always odd since we change by “2n + 1″ (2n must be even, so 2n + 1 is odd). Because the change is odd, it means the squares must cycle even, odd, even, odd…

And wait! That makes sense because the integers themselves cycle even, odd, even odd… after all, a square keeps the “evenness” of the root number (even * even = even, odd * odd = odd).

Funny how much insight is hiding inside a simple pattern. (I call this technique “geometry” but that’s probably not correct — it’s just visualizing numbers).

An Algebraist’s Epiphany

Drawing squares with pebbles? What is this, ancient Greece? No, the modern student might argue this:

  • We have two consecutive numbers, n and (n+1)
  • Their squares are n2 and (n+1)2
  • The difference is (n+1)2 – n2 = (n2+ 2n + 1) – n2 = 2n + 1

For example, if n=2, then n2=4. And the difference to the next square is thus (2n + 1) = 5.

Indeed, we found the same geometric formula. But is an algebraic manipulation satisfying? To me, it’s a bit sterile and doesn’t have that same “aha!” forehead slap. But, it’s another tool, and when we combine it with the geometry the insight gets deeper.

Calculus Madness

Calculus students may think: “Dear fellows, we’re examining the curious sequence of the squares, f(x) = x^2. The derivative shall reveal the difference between successive elements”.

And deriving f(x) = x^2 we get:

\displaystyle{\frac{d}{dx}x^{2}=2x}

Close, but not quite! Where is the missing +1?

Let’s step back. Calculus explores smooth, continuous changes — not the “jumpy” sequence we’ve taken from 22 to 32 (how’d we skip from 2 to 3 without visiting 2.5 or 2.00001 first?).

But don’t lose hope. Calculus has algebraic roots, and the +1 is hidden. Let’s dust off the definition of the derivative:

\displaystyle{f'(x)=\lim_{dx\to 0}{f(x+dx)-f(x)\over dx}}

Forget about the limits for now — focus on what it means (the feeling, the love, the connection!). The derivative is telling us “compare the before and after, and divide by the change you put in”. If we compare the “before and after” for f(x) = x^2, and call our change “dx” we get:

\displaystyle{\frac{(x+dx)^2 - x^2}{dx} = \frac{(x^2+2x \cdot dx + dx^2) - x^2}{dx} = \frac{2x \cdot dx + dx^2}{dx}}

\displaystyle{= 2x + dx}

Now we’re getting somewhere. The derivative is deep, but focus on the big picture — it’s telling us the “bang for the buck” when we change our position from “x” to “x + dx”. For each unit of “dx” we go, our result will change by 2x + dx.

For example, if we pick a “dx” of 1 (like moving from 3 to 4), the derivative says “Ok, for every unit you go, the output changes by 2x + dx (2x + 1, in this case), where x is your original starting position and dx is the total amount you moved”. Let’s try it out:

Going from 32 to 42 would mean:

  • x = 3, dx = 1
  • change per unit input: 2x + dx = 6 + 1 = 7
  • amount of change: dx = 1
  • expected change: 7 * 1 = 7
  • actual change: 42 – 32 = 16 – 9 = 7

We predicted a change of 7, and got a change of 7 — it worked! And we can change “dx” as much as we like. Let’s jump from 32 to 52:

  • x = 3, dx = 2
  • change per unit input: 2x + dx = 6 + 2 = 8
  • number of changes: dx = 2
  • total expected change: 8 * 2 = 16
  • actual change: 52 – 32 = 25 – 9 = 16

Whoa! The equation worked (I was surprised too). Not only can we jump a boring “+1″ from 32 to 42, we could even go from 32 to 102 if we wanted!

Sure, we could have figured that out with algebra — but with our calculus hat, we started thinking about arbitrary amounts of change, not just +1. We took our rate and scaled it out, just like distance = rate * time (going 50mph doesn’t mean you can only travel for 1 hour, right? Why should 2x + dx only apply for one interval?).

My pedant-o-meter is buzzing, so remember the giant caveat: Calculus is about the micro scale. The derivative “wants” us to explore changes that happen over tiny intervals (we went from 3 to 4 without visiting 3.000000001 first!). But don’t be bullied — we got the idea of exploring an arbitrary interval “dx”, and dagnabbit, we ran with it. We’ll save tiny increments for another day.

Lessons Learned

Exploring the squares gave me several insights:

square numbers in geometry, algebra and calculus

  • Seemingly simple patterns (1, 4, 9, 16…) can be examined with several tools, to get new insights for each. I had completely forgotten that the ideas behind calculus (x going to x + dx) could help investigate discrete sequences.
  • It’s all too easy to sandbox a mathematical tool, like geometry, and think it can’t shed light into higher levels (the geometric pictures really help the algebra, especially the +1, pop). Even with calculus, we’re used to relegating it to tiny changes — why not let dx stay large?
  • Analogies work on multiple levels. It’s clear that the squares and the odds are intertwined — starting with one set, you can figure out the other. Calculus expands this relationship, letting us jump back and forth between the integral and derivative.

As we learn new techniques, don’t forget to apply them to the lessons of old. Happy math.

Appendix: The Cubes!

I can’t help myself: we studied the squares, now how about the cubes?

1, 8, 27, 64…

How do they change? Imagine growing a cube (made of pebbles!) to a larger and larger size — how does the volume change?

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Fun With Modular Arithmetic

A reader recently suggested I write about modular arithmetic (aka “taking the remainder”). I hadn’t given it much thought, but realized the modulo is extremely powerful: it should be in our mental toolbox next to addition and multiplication.

Instead of hitting you in the face with formulas, let’s explore an idea we’ve been subtly exposed to for years. There’s a nice article on modular arithmetic that inspired this post.

Odd, Even and Threeven

Shortly after discovering whole numbers (1, 2, 3, 4, 5…) we realized they fall into two groups:

  • Even: divisible by 2 (0, 2, 4, 6..)
  • Odd: not divisible by 2 (1, 3, 5, 7…)

Why’s this distinction important? It’s the beginning of abstraction — we’re noticing the properties of a number (like being even or odd) and not just the number itself (“37”).

This is huge — it lets us explore math at a deeper level and find relationships between types of numbers, not specific ones. For example, we can make rules like this:

  • Even x Even = Even
  • Odd x Odd = Odd
  • Even x Odd = Even

These rules are general — they work at the property level. (Intuitively, I have a chemical analogy that “evenness” is a molecule some numbers have, and cannot be removed by multiplication.)

But even/odd is a very specific property: division by 2. What about the number 3? How about this:

  • “Threeven” means a number is divisbile by 3 (0, 3, 6, 9…)
  • “Throdd” means you are not divisible by 3 (1, 2, 4, 5, 7, 8…)

Weird, but workable. You’ll notice a few things: there’s two types of throdd. A number like “4” is 1 away from being threeven (remainder 1), while the number 5 is two away (remainder 2).

Being “threeven” is just another property of a number. Perhaps not as immediately useful as even/odd, but it’s there: we can make rules like “threeven x threeven = threeven” and so on.

But it’s getting crazy. We can’t make new words all the time.

Enter the Modulo

The modulo operation (abbreviated “mod”, or “%” in many programming languages) is the remainder when dividing. For example, “5 mod 3 = 2” which means 2 is the remainder when you divide 5 by 3.

Converting everyday terms to math, an “even number” is one where it’s “0 mod 2” — that is, it has a remainder of 0 when divided by 2. An odd number is “1 mod 2” (has remainder 1).

Why’s this cool? Well, our “odd/even” rules become this:

  • Even x Even = 0 x 0 = 0 [even]
  • Odd x Odd = 1 x 1 = 1 [odd]
  • Even x Odd = 0 x 1 = 0 [even]

Cool, huh? Pretty easy to work out — we converted “properties” into actual equations and found some new facts.

What’s even x even x odd x odd? Well, it’s 0 x 0 x 1 x 1 = 0. In fact, you can see if there’s an even being multiplied anywhere the entire result is going to be zero… I mean even :).

Clock Math

The sneaky thing about modular math is we’ve already been using it for keeping time — sometimes called “clock arithmetic”.

For example: it’s 7:00 (am/pm doesn’t matter). Where will the hour hand be in 7 hours?

Hrm. 7 + 7 = 14, but we can’t show “14:00” on a clock. So it must be 2. We do this reasoning intuitively, and in math terms:

  • (7 + 7) mod 12 = (14) mod 12 = 2 mod 12 [2 is the remainder when 14 is divided by 12]

The equation “14 mod 12 = 2 mod 12” means, “14 o’clock” and “2 o’clock” look the same on a 12-hour clock. They are congruent, indicated by a triple-equals sign: 14 ≡ 2 mod 12.

Another example: it’s 8:00. Where will the big hand be in 25 hours?

Instead of adding 25 to 8, you might realize that 25 hours is just “1 day + 1 hour”. So, the clock will end up 1 hour ahead, at 9:00.

  • (8 + 25) mod 12 ≡ (8) mod 12 + (25) mod 12 ≡ (8) mod 12 + (1) mod 12 ≡ 9 mod 12

You intuitively converted 25 to 1, and added that to 8.

Fun Property: Math just works

Using clocks as an analogy, we can figure out whether the rules of modular arithmetic “just work” (they do).

Addition/Subtraction

Let’s say two times look the same on our clock (“2:00” and “14:00”). If we add the same “x” hours to both, what happens?

Well, they change to the same amount on the clock! 2:00 + 5 hours ≡ 14:00 + 5 hours — both will show 7:00.

Why? Well, we never cared about the excess “12:00” that the 14 was carrying around. We can just add 5 to the 2 remainder that both have, and they advance the same. For all congruent numbers (2 and 14), adding and subtracting has the same result.

Multiplication

It’s harder to see whether multiplication stays the same. If 14 ≡ 2 (mod 12), can we multiply both sides and get the same result?

Let’s see — what happens when we multiply by 3?

Well, 2:00 * 3 ≡ 6:00. But what’s “14:00” * 3?

Remember, 14 = 12 + 2. So, we can say

  • 14 * 3 = (12 + 2) * 3 = (12 * 3) + (2 * 3) mod 12

The first part (12 * 3) can be ignored! The “12 hour overflow” that 14 is carrying around just gets repeated a few times. But who cares? We ignore the overflow anyway.

When multiplying, it’s only the remainder that matters, which is the same 2 hours for 14:00 and 2:00. Intuitively, this is how I see that multiplication doesn’t change relationships with modular math (you can multiply both sides of a modular relationship and get the same result). See the above link for more rigorous proofs — these are my intuitive pencil lines.

Uses Of Modular Arithmetic

Now the fun part — why is modular arithmetic useful?

Simple time calculations

We do this intuitively, but it’s nice to give it a name. You have a flight arriving at 3pm. It’s getting delayed 14 hours. What time will it land?

Well, 14 ≡ 2 mod 12. So I think of it as “2 hours and an am/pm switch”, so I know it will be “3 + 2 = 5am”.

This is a bit more involved than a plain modulo operator, but the principle is the same.

Putting Items In Random Groups

Suppose you have people who bought movie tickets, with a confirmation number. You want to divide them into 2 groups.

What do you do? “Odds over here, evens over there”. You don’t need to know how many tickets were issued (first half, second half), everyone can figure out their group instantly (without contacting a central authority), and the scheme works as more people buy tickets.

Need 3 groups? Divide by 3 and take the remainder (aka mod 3). You’ll have groups “0”, “1” and “2”.

In programming, taking the modulo is how you can fit items into a hash table: if your table has N entries, convert the item key to a number, do mod N, and put the item in that bucket (perhaps keeping a linked list there). As your hash table grows in size, you can recompute the modulo for the keys.

Picking A Random Item

I use the modulo in real life. Really. We have 4 people playing a game and need to pick someone to go first. Play the mod N mini-game! Give people numbers 0, 1, 2, and 3.

Now everyone goes “one, two, three, shoot!” and puts out a random number of fingers. Add them up and divide by 4 — whoever gets the remainder exactly goes first. (For example: if the sum of fingers is 11, whoever had “3” gets to go first, since 11 mod 4 = 3).

It’s fast and it works.

Running Tasks On A Cycle

Suppose tasks need to happen on a certain schedule:

  • Task A runs 3x/hour
  • Task B runs 6x/hour
  • Task C runs 1x/hour

How do you store this information and make a schedule? One way:

  • Have a timer running every minute (keep track of the minute as “n”)
  • 3x / hour means once every 60/3 = 20 minutes. So task A runs whenever “n % 20 == 0”
  • Task B runs whenever “n % 10 == 0”
  • Task C runs whenever “n % 60 == 0”

Oh, you need task C1 which runs 1x per hour, but not the same time as task C? Sure, have it run when “n mod 60 == 1” (still once per hour, but not the same as C1).

Mentally I see a cycle I want to “hit” at various intervals, so I insert a mod. The neat thing is that the hits can overlap independently. It’s a bit like XOR in that regard (each XOR can be layered — but that’s another article!).

Similarly, when programming you can print every 100th log item by doing: if (n % 100 == 0){ print… }.

It’s a very flexible, simple way to have items run on a schedule. In fact, it’s the way to answer the FizzBuzz sanity check. If you don’t have the modulo operation in your batbelt the question becomes much more tricky.

Finding Properties Of Numbers

Suppose I told you this:

  • a = (47 * 2 * 3)

What can you deduce quickly? Well, “a” must be even, since it’s equal to something which involves multiplication by 2.

If I also told you:

  • a = (39 * 7)

You’d balk. Not because you “know” the two products are different, but because one is clearly even, and the other is odd. There’s a problem: a can’t be the same number in both since the properties don’t match up.

Things like “even”, “threeven” and “mod n” are properties that are more general than individual numbers, and which we can check for consistency. So we can use modulo to figure out whether numbers are consistent, without knowing what they are!

If I tell you this:

  • 3a + 5b = 8
  • 3a + b = 2

Can these equations be solved with the integers? Let’s see:

  • 3a + 5b = 8… let’s “mod 3 it”: 0 + 2b ≡ 2 mod 3, or b ≡ 1 mod 3
  • 3a + b = 2… let’s “mod 3 it”: 0 + b ≡ 2 mod 3), or b ≡ 2 mod 3

A contradication, good fellows! B can’t be both “1 mod 3” and “2 mod 3” — it’s as absurd as being even and odd at the same time!

But there’s one gotcha: numbers like “1.5” are neither even nor odd — they aren’t integers! The modular properties apply to integers, so what we can say is that b cannot be an integer.

Because, in fact, we can solve that equation:

  • (3a + 5b) – (3a +b) = 8 – 2
  • 4b = 6
  • b = 1.5
  • 3a + 1.5 = 2, so 3a = 0.5, and a = 1/6

Don’t get seduced by the power of modulo! Know its limits: it applies to integers.

Cryptography

Playing with numbers has very important uses in cryptography. It’s too much to cover here, but modulo is used in Diffie-Hellman Key Exchange — used in setting up SSL connections to encrypt web traffic.

Plain English

Geeks love to use technical words in regular contexts. You might hear “X is the same as Y modulo Z” which means roughly “Ignoring Z, X and Y are the same.”

For example:

  • b and B are identical, modulo capitalization
  • The iTouch and iPad are identical, modulo size ;)

Onward and Upward

It’s strange thinking about the “utility” of the modulo operator — it’s like someone asking why exponents are useful. In everyday life, not very, but it’s a tool to understand patterns in the world, and create your own.

In general, I see a few general use cases:

  • Range reducer: take an input, mod N, and you have a number from 0 to N-1.
  • Group assigner: take an input, mod N, and you have it tagged as a group from 0 to N-1. This group can be agreed upon by any number of parties — for example, different servers that know N = 20 can agree what group ID=57 belongs to.
  • Property deducer: treat numbers according to properties (even, threeven, and so on) and work out principles derived at the property level

I’m sure there’s dozens more uses I’ve missed — feel free to comment below. Happy math!

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Learning How to Count (Avoiding The Fencepost Problem)

Counting isn't easy. Suppose your boss wants you to work from 8am to 11am, and mop floors 8 to 11. Simple - it's one floor per hour, right?

Nope! There are 4 floors to mop (8, 9, 10 and 11) but only 3 hours to work (8-9, 9-10, and 10-11).

Whoa -- we count floors and hours differently? You bet. And somehow, if the boss said "Mop floors 8 to 11 on April 8th to 11th" everything would be ok.

Today let's unravel this counting mystery.

Basic Counting

Numbers help us know "how many". Take a numbered list of houses:

counting numbered houses

There's 52 houses there. Don't count each one: the addresses count for us! The numbers label the houses one by one, just as we'd do. We can just read the last item: "1 to 52" is 52 houses.

Examples:

  • Employee ID cards from 1 to 3493. There are 3493 employees.
  • Days of the month from 1 to 31. There are 31 days in that month.

What Does Subtraction Mean?

We often see numbers as points on a line:

number line

These points can be houses, floors, or plain integers. Whatever they are, they're labeled so we can count them easily. 1 to 10 means ten items.

But what about a range like 8 to 11? How many items are there?

number line distance of 3 but 4 numbers

We'd probably try subtraction: 11 - 8 = 3, right? But here's the key:

  • Subtraction is a span between numbers, not a count

The equation 11 - 8 = 3 means there are 3 "spans" between 8 and 11, but four numbers in that range!

A span is a distance measure, like time from 8am and 11am (3 hours) or the distance between 8 and 11 inches (3 inches).

But when counting floors, we aren't asking for the distance between floors 8 to 11 (which is in fact 3 floors or 30 feet, assuming 10 feet per floor). We want a count of how many items the range "8 to 11" includes!

Working With Spans and Counts

Realizing there are two types of counting was a big mental shift. We have two possible choices when "counting" from a to b:

  • Distance from a to b: b - a [regular subtraction]
  • Number of items from a to b: b - a + 1 (span touches extra element)

Ok, the formulas work. But why does a count need an extra element?

Well, the shortest span (distance 1) actually touches two numbers:

single span, two items

A span is a line segment with a start and end; a span of distance 1 covers 2 points. As we grow the span, we gobble up more points and are always "one ahead".

additional span

Here's another way to think about it. A span of 3 means we start with an item (#8) and count out 3 more (#9, #10, #11). So, a span of N includes 1 original item and N new items, for a total of N + 1 items.

I like seeing new viewpoints; use what works for you.

The Fencepost Problem

The confusion between spans and counts is commonly called the fencepost problem. Are you counting the posts (points) or the distance between them (fence spans)?

The question goes like this:

You're building a fence 100 feet long, with posts every 10 feet. How many posts do you need?

Here's how to think about it with our new mental model:

Hrm, we want a fence 100 feet long. Ok: that's a span of ten, 10-foot segments. But we want the number of posts: how many posts do those ten segments touch? Well, a span always touches an extra point, so ten segments means 11 posts.

11 fenceposts it is. But the problem isn't natural for me - I have to think about spans vs points. I'd double-check with a smaller example - a fence that is 10 feet long needs 2 posts, so yes, we need an "extra post".

A few more examples:

  • Working Days: I worked April 8th to April 11th. How many days did I work? Well, that's a span of 3 (11-8), but we "touch" 4 days: April 8, 9, 10, 11. So I worked 4 days.
  • Hours: Hours are like spans. Working from 8 to 11 means you are covering the spans 8-9, 9-10, and 10-11. 8 to 11 means a "timespan" of 3 hours.
  • Seconds: I start a race, and the start time at 12:01:08 (12 hours, 1 minute, 8 seconds). It ends at 12:01:11. How long did it go? 11 - 8 = 3 seconds. (Short race)

Interesting, eh? Some units of time are measured with spans (hours, seconds) and others are items to be counted (days).

The measuring type depends on the context. We see shorter units of time as "instants" and want the duration between those instants, not the "number" of instants we touched.

We see days as a large fuzzy blob covering a time period (9am-5am) -- and we want to know how many blobs we covered. Saying you worked April 8 to April 9th implies you worked a timespan of 9am-5pm on two days.

The counting type depends on the context - but at least you know why we count them differently.

Final Thoughts

Counting isn't simple. The fencepost problem and other "off by one" boundary errors are notoriously common. But don't just remember a special trick, like "sometimes I need to add 1". Remember there are two ways to measure something:

  • Are we measuring a difference (distance, time)? Then do regular subtraction to get a span.
  • Are we counting items? Then subtract and add 1 (b - a + 1) - we want the number of items the span touches.

It's not easy to recognize the difference - we're used to having one way to measure. Try a simple example (a fence 10 feet long) to test if you've got a count or span.

I've run into the fencepost problem many times, but the articles I read just told me how to fix it. No, no, no - why does it happen?

It turns out we often use the same approach for two different types of counting. And while the right method may not be obvious, at least we know to try both approaches. Happy math.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Rethinking Arithmetic: A Visual Guide

Arithmetic gives us tools to smoosh, slide and stretch numbers. These transformations are handy: sometimes there’s things in the real world we want to smoosh, slide and stretch in the same way.

Why’s this important?

Seeing arithmetic as a type of transformation prepares you to make sense of seemingly-weird concepts, like the square root of -1, and visualize problems in a new way. Let’s take a look.

Addition

Addition is simple, yet it can mean several things:

  • Accumulate: Count up similar quantities (often for tangible items).
  • Slide: Shifting a number along a scale (for less tangible things, like temperature).
  • Combine: Make a new quantity out of two different ones (like notes in a music chord).

Addition viewed as accumulate, slide or combine

What’s the right meaning? It depends on the context. When adding apples, we count up similar items (3 apples + 4 apples = 7 apples). When measuring temperature, we add heat to move along a scale (3 degrees + 4 degrees = 7 degrees).

When adding vectors, a combination makes the most sense: 3 blocks east + 4 blocks north = 5 blocks in a new direction (“as the crow flies” distance). In this case, you must track the component parts, keeping “North” and “East” separate. When adding apples, you can combine everything: once you have 7, you don’t care that it was once 3 and 4.

A single operation (addition) can take on several intuitive meanings. This list isn’t exhaustive — they are the interactions I’ve noticed, and I’m sure you have others.

Multiplication

Multiplication can also be interpreted in several ways:

  • Repetition: Performing multiple additions.
  • Scaling: Making a number grow or shrink all at once.

Multiplication viewed as repetition or scaling

Context determines our meaning. With apples, “4x” means turning an order of 2 apples into an order of 8 (4 groups of 2). With photo software, “4x” means expanding a 2-inch photo to be 8 inches long. Each meaning is different: you’d be annoyed if I gave you a giant, 5-lb apple or 4 separate photos.

In a narrow sense, multiplication is “repeated addition”. Sure. But that’s not always the easiest interpretation — care to “repeatedly add” 7.3 times?

Negatives and Inverses

Negatives and inverses both represent the idea of “reverse” or “opposite”. But that’s ambiguous: What’s the opposite of multiplying by two?

Negative and inverse multiplication

“Opposite” can mean a few things:

  • Multiply by 1/2: Turn a profit of 1 into a profit of 1/2 (“unscale” it)
  • Multiply by -2: Turn a profit of 1 into a loss of 2 (flip it)

Yet again, our context determines meaning. When a company “reverses a gain” it implies a loss, aka multiplying by a negative. When we “reverse a zoom” in photo software, we want to shrink the photo (not mirror-image it), so we multiply by 1/2. Context, context, context (tired of that word yet?).

When adding, there’s only one type of opposite: the reverse of +8 is -8. But the trick is to know that -8 really means “0-8″ or even “0 + (-8)”: you’re moving backwards relative to some reference point. Moving “in reverse” means different things depending if your original direction was East or North.

What’s in an equation?

Equations ask questions. When you see

\displaystyle{x^2 = 9}

It’s more than just a plug and chug problem. Think about the question like this:

\displaystyle{1 * x^2 = 9}

What transformation (“times x”), when applied twice, will turn 1 into 9?

Visual diagram of squares, 3 and -3

We have two answers:

  • Scale by 3 (times 3): Do it twice and you’ll get 9: 1 * 3 * 3 = 9
  • Scale by 3 and flip (times -3): Done twice, you get 9 also: 1 * -3 * -3 = 9

Nifty. I included “1″ to show what is being transformed. Sure, it’s optional, but it’s not something we think about. What is the “times 3″ acting on?

Stepping back this way, we can see arithmetic as a method to push, pull, tug and squeeze one number into another. We’ve managed to turn one large transformation (“times 9″) into two equal, smaller ones (“times -3″ or “times 3″).

Real-World Example: Random Numbers

Enough theory — let’s show this mindset in action. Most programming languages offer a random() function that gives a number from 0 to 1. But what if you want something from 5-10?

The question is: how do I transform my range of 0-1 into a range from 5-10?

Diagram of scaling random numbers to new ranges

Arithmetic to the rescue!

  • First, you stretch 0-1 into 0-5 by multiplying by 5
  • Next, slide 0-5 to 5-10 by adding 5
  • And tada. You have a range from 5-10.

Try it out below. You start with a number “r” and transform it into the proper range.

By the way, this range could be the ages 18-65, the years 1960-2007, or the temperatures 30F – 80F for use in your simulation (everyone runs simulations, right?). No matter your range, you can start with the “0 to 1″ building block and modify it.

Sure, you can figure this out without a diagram, but sometimes it’s nice to visualize what’s happening. Our brain is a vision-processing supercomputer, so let’s use its strengths.

What’s next?

This post introduces the idea that arithmetic is a transformation. You bend numbers into other ones, and each transformation has a meaning. Some fit a situation better than others: use the one you like most.

The goal isn’t to turn multiplication into a cumbersome diagramming process. It’s a technique, a mindset, a new weapon to use against seemingly complex operations.

When studying linear algebra (matrices), you can view multiplication as a type of transformation (scaling, rotating, skewing), instead of a bunch of operations that change a matrix around. This approach will help when we cover imaginary numbers, that foul beast which has befuddled many students.

Little insights help bigger ideas click. Happy math.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

A Quirky Introduction To Number Systems

Everyone’s got quirks. Me, I like finding new ways to think about problems, and I’ve started seeing numbers in a new way. Today I’m bringing you along for the ride.

And why do you care?

  • You’ll see math as one of several approaches. We’re still improving our number system.
  • You’ll start noticing core relationships and apply them to diverse areas
  • You’ll have a way to approach “weird” concepts like division by zero and imaginary numbers.

Math is Software For Your Brain

Though our favorite encyclopedia describes math as “the body of knowledge centered on such concepts as quantity, structure, space, and change” I think there’s more to it than that.

Math is software for your brain:

  • Your brain is a raw computer.
  • You learn new math (install “Counting 1.0” and “Algebra XY Pro”) and suddenly you can solve new types of problems.
  • Sometimes math has bugs. “Roman Numerals I” was ok, but Decimals 2.0 was a much-needed upgrade. But we still have a few issues, like dividing by zero.

    It’s a strange analogy, but I’m a bit strange, so I think it works out.

But Math Has Its Limits

Quick quiz: Can you multiply two Roman numerals? No cheating, no converting to decimal: I’m talking about “IX times XXXIV”. Ready, set, multiply!

Having fun yet? It’s CCCVI.

Does this horrendous experience mean multiplication is “hard”? Or are we thinking about multiplication in the wrong way, using the wrong mental software?

If you upgrade your brain from “Roman Numerals I” to “Decimals 2.0”, you’ll find that 9 times 34 is a much easier question: after some work you’d get 306. Same problem + different mental software = drastic difference.

Painting With Notepad

Yes, you could squeeze multiplication into Roman Numerals. But it’s neither fun nor easy, and don’t get me started on long division.

Our difficulties are often due to our approach, not the concept.

Think of it like trying to draw in Notepad. It’s a nice tool, and you can even “type” the Mona Lisa, but the software just wasn’t built with images in mind.

mona lisa ascii data

Similarly, Roman Numerals were built when we were still learning to count — zero wasn’t even invented yet! Math is a software system that gets better over time, and Roman Numerals were due for an upgrade.

But before we get too high-and-mighty, realize our current number system is a patchwork of new features and bug fixes, used to improve our understanding of the universe.

And when we hit difficulties (What’s 1/0? The square root of -1?) we need to wonder if we’re hitting universal “laws” or walls of our own making. Like the Romans trying to multiply, let alone do fractions, my money’s on the latter.

From Ug to Infinity

Our number system developed over time. We started counting on our fingers, moved to unary (lines in the sand), Roman Numerals (shortcuts for large numbers) and Arabic Numerals (the decimal system) with the invention of zero.

Along the way we found “bugs” in our number system and had to invent new ways around it. Again, the bug was in our thinking (our mental software).

Ugware

Ugware is the counting system devised by Ug the caveman: counting on your fingers and toes. Ug’s bug was that he was limited to 20 items!

The fix was to abstract the need for physical objects: you don’t need 20 cows to count 20 cows. You can make 20 lines in the sand. Or take shortcuts like C for 100.

Unary and Roman Numerals

Having numbers represented abstractly let us do cool things like add and subtract, even fairly large numbers. I + II = III. X + XX = XXX. Not bad.

But there was still a few “bugs” — what is III – III?

Zero

What a fantastic, beautiful invention: using the symbol 0 to represent nothingness! It’s a mind-bending and useful idea: we can keep track of “no” cows at all!

This development led to our familiar positional number system: 204 means two “hundreds”, zero “tens” and four ones.

Integer division and multiplication became possible in ways the Romans (and Ug) had never imagined. You could work out 1234 × 5678 if given enough time. What a great feature!

Negatives

But zero didn’t solve everything; subtraction still had problems. What happens when we take 5 from 3? One solution is to throw up our hands and say “it’s a bug and it’s undefined”, but we’ll do better.

We can think about the problem differently, and entertain the possibility that a number can be “negative” — a number that is less than nothing! (Pretty mind-bending, no?).

There are many interpretations (a lack of cows, a debt of cows) and negatives were invented to handle this “bug” in subtraction. Of course, it took a few thousand years to accept this new feature — negative numbers were still controversial in the 1700s!

Rational Numbers

Division introduced bugs as well. 8/4 is fine, but what is 3/4? It’s a bug!

The fix is to find a way to represent “numbers between numbers”. 3/4 is really 75/100, or “0.75”.

We invented the decimal point to handle the crazy idea of a number more than zero but less than one. Wow! Pretty wild, but we included these crazy types of numbers to make our mental software better. Lo and behold, fractions have their uses. The average family can have 2.3 kids and we know what it means.

Irrationals Make Greeks Angry

Here we are, minding our own business when we see a right triangle:

The sides are 1 and 1. And there, staring us square in the face, is the square root of 2. It taunts us, asking to be written down. We can’t — it’s an infinite, non-repeating decimal number that can’t be expressed as a fraction! And yet it’s right there on paper.

It’s more than a conundrum — it’s madness! The guy who discovered irrationals got thrown off a boat.

Luckily, irrationals are at least “algebraic” in that they are the solution to some algebra equation. We can consider $\sqrt{2}$ as shorthand for “the solution to the equation $x^2 = 2$”. We often forget $\sqrt{9}$ is really both 3 and -3, don’t we? Convention implies the positive root.

Complex Numbers

Now some a smart aleck asks, “Ok bub, what number is the solution to the equation x^2 = -1?”.

What to do? Declare this to be impossible and non-sensical, just like zero, fractions, rationals and irrationals were once “impossible and non-sensical”? Or do we accept that maybe, just maybe, our human understanding of the universe is not complete and we have more to learn. You know where my money lies.

Imaginary numbers are just as “realistic” as other numbers (or equally contrived, depending on your viewpoint). But, we don’t have an intuition for them because they’re often “explained”: Oh, you don’t have an Electrical Engineering degree? Didn’t learn about complex impedance? No intuitive imaginary numbers for you!

I’ve been thinking about these numbers and plan to address this issue. But not yet — have patience.

Why .9999… = 1, and why you should care

Our number system is a way of thinking, but it still has a few gaps. We’re not quite sure how to deal with infinity and infinitely small numbers.

Here’s a brain-buster for you:

You: What’s 1/3?

Me: Um, .33 repeating.

You: Ok. What’s 1/3 + 1/3?

Me: 2/3 You: Sure, but do it in decimals.

Me: Um, .33 repeating plus .33 would be… .666 repeating.

You: Great. Now what’s 1/3 + 1/3 + 1/3, in decimal?

Me: Uh… .33 repeating plus .33 repeating plus .33 repeating… is .99 repeating.

You: But doesn’t 1/3 + 1/3 + 1/3 = 1? So .99 repeating = 1.

Me: What manner of trickery is this? (Pushes you off blog).

Try that argument on a kid (or adult) — it’s fun to see people’s reactions. Clearly, 1/3 + 1/3 + 1/3 = 1, but somehow when we try to “add it in decimal” the result seems a bit strange. Again, is the strangeness due to the concept, or our thinking?

What is .33 repeating, anyway? Is it a monkey writing 3’s until the end of time? Is it a number beyond our notation that we’re hopelessly trying to approximate, like the square root of 2? If we simply switch to base 3, the problem goes away: 1/3 = .1 in base 3, so .1 + .1 + .1 = 1 (again, in base 3).

And why do you care? It may be time for a number system upgrade. Discussing infinity with our current numbers is like drawing in notepad. It’s crude and feels “tacked on” (like saying 1/0 = infinity. What about 2/0 or 0/0?).

Mathematicians are working on new number systems where infinity is built-in, but there’s still unsolved problems about how to “count” infinity.

Let’s seek the “a ha!” insights that made zero, fractions and negative numbers understandable, not just the results of manipulating equations. We’ve been able to overcome every previous mathematical roadblock.

Going Forward

The goals of this article were simple:

  • Show how math is like mental software that improves over time
  • Explain that “nonsense” like zero or negative numbers can start as a paradox and become intuitive as we adapt our approach.
  • Today, we still have trouble with ideas like infinity (or at least I do). It’s ok to admit it.

    This is a way to think about math; combine it with your own understanding. Don’t stand in a daze, unable to add because you’re unsure what 1/3 really means.

Insights deepen our understanding, but sometimes only emerge with use. Newton didn’t have a “formal” understanding of infinitesimals when he invented calculus, but it seemed to work fine for him (equations got solved). I don’t advocate plug-and-chug, but for certain ideas you need to hammer away before the insights come.

But enough philosophy. Upcoming articles will show real, concrete ways to think about arithmetic and complex numbers, which can aid the “mechanical” understanding we have today. Happy math.

PS. If you’re curious, there’s more on .999… and division by zero on wikipedia.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Another Look at Prime Numbers

Primes are numeric celebrities: they're used in movies, security codes, puzzles, and are even the subject of forlorn looks from university professors.

But mathematicians delight in finding the first 20 billion primes, rather than giving simple examples of why primes are useful and how they relate to what we know. Somebody else can discover the largest prime -- today let's share intuitive insights about why primes rock:

  • Primes are building blocks of all numbers. And just like in chemistry, knowing the chemical structure of a material helps understand and predict its properties.

  • Primes have special properties like being difficult to determine (yes, even being difficult can be a positive trait). These properties have applications in cryptography, cycles, and seeing how other numbers multiply together.

So what are prime numbers again?

A basic tenet of math is that any number can be written as the multiplication of primes. For example:

  • 9 = 3 * 3 = 32
  • 12 = 2 * 2 * 3 = 22 3
  • 100 = 4 * 25 = 2 * 2 * 5 * 5 = 22 52

And primes are numbers that can't be divided further, like 3, 5, 7, or 23. Even the number 2 is prime, if you think about it. And the number 1?

Well, 1 is special and isn't considered prime, since things get crazy because 1 = 1 * 1 * 1... and so on. Even mathematicians take shortcuts sometimes, and leave 1 out of the discussion.

Rewriting a number into primes is called prime decomposition, math speak for "find the factors". Primes seem simple, right?

Well, not really. It turns out that

  • Primes are infinite and we'll never run out (see proof).
  • Primes don't have a pattern we can decipher
  • Primes show up in strange places, like quantum mechanics
  • Prime decomposition is hard. So far, trial-and-error is the best way to break a number into primes. And that's slow.

God, nature, or the flying spaghetti monster -- whatever determined the primes, it made a whole lot of 'em and distributed them in a quirky way.

Analogy: Prime Numbers and Chemical Formulas

Prime numbers are like atoms. We can rewrite any number into a "chemical formula" that shows its parts. In chemistry, we can say a water molecule is really H20:

  • Water = H20 = two hydrogens and one oxygen

And for a number, we can break it into primes

  • 12 = 2 * 2 * 3 = 22 3 = two "2s" and one "3"

Neat relationship, right? In chemistry the "exponent" happens to go underneath -- I'd really prefer exponents above, but the American Chemical Society hasn't replied to my letters.

Why is this interesting? Well, when chemists arranged their basic elements into the periodic table, new insights emerged:

  • New elements were predicted by the gaps in the table
  • Elements in the same row or column shared certain properties
  • Trends (like increasing reactivity) emerged as you moved around the table

Not bad for reorganizing existing data, eh? Similarly, we can imagine putting the primes (numerical "elements") into a table. But there's a problem.

Nobody knows what the table looks like! Primes are infinite and although we've tried for centuries to find a pattern, we can't. We have no idea where the gaps are or when the next prime is coming. (That's not quite true -- there's interesting hypotheses and conjectures, but the riddle is not solved).

But we won't cry about it, breaking our pencil and sobbing home. You and I are going to make use of the primes even though we don't know every detail.

Organic Chemistry and Functional Groups

I'm no chemistry expert, but I can see a relationship to the primes. Chemical elements have properties based on their location in the periodic table of the elements:

  • Atoms in group 8A (Neon, Argon) are the noble gases. They don't react and won't blow up in your face.
  • Atoms in group 4A (Carbon, Silicon) bond well. They're great building blocks for other elements.
  • Atoms in group 1 (Sodium, Potassium, etc.) are very reactive. Drop 'em in water and see them explode.

And in organic chemistry there's an idea of a functional group: several atoms can determine the class of the entire molecule. For example:

  • Alcohols are a certain carbon-hydrogen chain with an OH group at the end.
  • Methanol, ethanol, and other alcohols share similar properties because of this OH functional group.

Those are the basics, if I didn't mess it up. Now let's see what happens when we treat numbers like chemicals.

First Example: Guessing Evenness

In general, an organic chemical contains carbon (not quite, but it's a good starting point). No matter what elements you mix together, if you never add any carbon then you can't create an organic compound.

"Evenness" works the same way. A number is even if it has a 2 in its prime decomposition -- i.e., 2 was used to make the number. There could be a single 2 or fifty; if you have a single 2, you are even, and that's that. If you don't have a 2, you're odd.

Now, remember those math questions that ask how odd and even numbers multiply?

  • Even times odd is ... (even or odd?)
  • Even times even is ... (even or odd?)
  • Odd times odd is ... (even or odd?)

How would you solve this? Guess? Try a few examples? ("Let's see, 3 times 2 is.. 6, but 3 times 3 is 9... so...").

Here's one way to think about it. Multiplication is combining the "prime formulas" for the numbers. Since even numbers contain a "2" somewhere, we can guess that:

  • Even times odd is even. We started with a 2. It doesn't matter what else we put in.
  • Even times even is even. We started with a 2 and put in another for good measure.
  • Odd times odd is odd. We never put in a 2 the whole time, so we stay odd.

Pretty cool, eh? And since 2 is prime, we know we can't "manufacture" a 2 by combining other numbers together.

Thank you prime chemistry, for giving us another way to think about this problem. Now you can even answer questions like this:

  • What's odd * odd * odd * odd * even?

It's even, since we mixed in a 2 at the end.

Another Example: Ending with 0

I've read your mind: you want another chemical example, this time with functional groups.

Suppose a number has a "2*5" functional group -- it has one or more 2s and one or more 5s. For example:

  • 10 = 2 * 5
  • 40 = 2 * 2 * 2 * 5
  • 90 = 3 * 3 * 2 * 5

Notice a pattern? If a number has a 2 * 5 "functional group", it ends in 0.

Why? Well, 2 * 5 = 10. So having 2 * 2 * 2 * 5 is really like having (2 * 2) * 10. Any whole number multiplied by 10 ends in 0. In general,

  • (some other primes) * (2 * 5) = a number ending in 0

So just by looking at the "prime formula" you can determine that the number ends with a 0. You never had to do the multiplication out.

And Another Example: Sum of Digits

What's that? You want another example with functional groups? If you insist.

Let's think about numbers with the "3*3" functional group. A number could have 400 threes, but as long as there's at least 2 we're interested. If a number has (3*3) it means

  • It is divisible by 9
  • The sum of the digits is divisible by 9 (we can prove this later -- take my word for now).

Here's an example:

  • 18 = 2 * 3 * 3. It has the (3*3) functional group. The sum of the digits is 1 + 8 = 9, which is divisible by 9.
  • Take a strange number like 31 * 3 * 3 = 279. It has a (3*3) functional group, and the sum of digits is 2 + 7 + 9 = 18. 18 is divisible by 9, so the property holds.

Again, this is pretty cool. We know something about the sum of digits just by finding a certain functional group in the prime decomposition of the number.

Primes in the Real World

Primes have properties that come in useful.

1. Large numbers are hard to factor. We essentially resort to trial-and-error when doing prime decomposition: one method is to keep trying to divide it by other numbers, up to its square root. The fact that primes and prime decompositions are "secret" can be a good thing for cryptography -- we'll get into this later.

2. Primes don't play well with other numbers. Prime numbers don't "overlap" with the regular numbers: they intersect at the last possible moment. For example, 4 and 6 "overlap" at 12, which is pretty early. Their first "required" overlap is at 4 * 6 = 24.

Primes, however, intersect at the last possible moment. 5 and 7, for example, only coincide at 35 (5*7). There's no intermediate value where they both show up.

You'd think a lack of rhythm would be a bad thing, but in nature it can be an advantage.

The cicada insect sprouts from the ground every 13 or 17 years. This means it has a smaller chance of "overlapping" with a predator's cycle, which could be at a more common 2 or 4-year cycle.

3. Primes are prime everywhere.

The movie "Contact" used primes as a universally understood sequence. It's a non-trivial sequence (2, 3, 5, 7, 11, 13) that would be hard to generate by accident (1, 0, 1, 0 could be made by a swinging pendulum, for example).

And prime numbers are prime in any number system. "1/3" is only a repeating fraction in base 10 (.33333), and you could even argue that pi (3.14159...) is not irrational in base "pi". But everyone can agree that certain numbers are prime and can't be divided. You can even transmit primes in a unary number system that lacks a decimal point:

II
III
IIIII
IIIIIII

So, primes are an infinite, non-repeating, universally-understood sequence, and a good choice for transmitting a message.

Conclusion

Don't hate the primes because they're different -- see how their properties can be useful. "Not fitting in" is a great if it means you don't overlap with a predator, right? Being hard to factor is great if you're making a secret message, right? For a long time primes were considered a purely theoretical curiosity, but lo and behold, we've found situations where they apply.

And that's a large part of math, in my opinion: seeing how strange properties can be useful or relate to the real-world. Math gives us rules, often for games we don't yet play. Our job is to find situations where we want to follow those rules.

There's much more I'd like to say in upcoming posts. If you want to dive into primes, check out Music of the primes which is a decent introduction to the issue of the primes, and motivated me to think about this topic.

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.

Techniques for Adding the Numbers 1 to 100

There’s a popular story that Gauss, mathematician extraordinaire, had a lazy teacher. The so-called educator wanted to keep the kids busy so he could take a nap; he asked the class to add the numbers 1 to 100.

Gauss approached with his answer: 5050. So soon? The teacher suspected a cheat, but no. Manual addition was for suckers, and Gauss found a formula to sidestep the problem:

\displaystyle{\text{Sum from 1 to n} = \frac{n(n+1)}{2}}

\displaystyle{\text{Sum from 1 to 100} = \frac{100(100+1)}{2} = (50)(101) = 5050}

Let’s share a few explanations of this result and really understand it intuitively. For these examples we’ll add 1 to 10, and then see how it applies for 1 to 100 (or 1 to any number).

Technique 1: Pair Numbers

Pairing numbers is a common approach to this problem. Instead of writing all the numbers in a single column, let’s wrap the numbers around, like this:

1  2  3  4  5
10 9  8  7  6

An interesting pattern emerges: the sum of each column is 11. As the top row increases, the bottom row decreases, so the sum stays the same.

Because 1 is paired with 10 (our n), we can say that each column has (n+1). And how many pairs do we have? Well, we have 2 equal rows, we must have n/2 pairs.

\displaystyle{\text{Number of pairs * Sum of each pair} = (\frac{n}{2})(n+1) = \frac{n(n+1)}{2}}

which is the formula above.

Wait — what about an odd number of items?

Ah, I’m glad you brought it up. What if we are adding up the numbers 1 to 9? We don’t have an even number of items to pair up. Many explanations will just give the explanation above and leave it at that. I won’t.

Let’s add the numbers 1 to 9, but instead of starting from 1, let’s count from 0 instead:

0  1  2  3  4
9  8  7  6  5

By counting from 0, we get an “extra item” (10 in total) so we can have an even number of rows. However, our formula will look a bit different.

Notice that each column has a sum of n (not n+1, like before), since 0 and 9 are grouped. And instead of having exactly n items in 2 rows (for n/2 pairs total), we have n + 1 items in 2 rows (for (n + 1)/2 pairs total). If you plug these numbers in you get:

\displaystyle{\text{Number of pairs * Sum of each pair} = (\frac{n + 1}{2})(n) = \frac{n(n+1)}{2}}

which is the same formula as before. It always bugged me that the same formula worked for both odd and even numbers – won’t you get a fraction? Yep, you get the same formula, but for different reasons.

Technique 2: Use Two Rows

The above method works, but you handle odd and even numbers differently. Isn’t there a better way? Yes.

Instead of looping the numbers around, let’s write them in two rows:

1  2  3  4  5  6  7  8  9  10
10 9  8  7  6  5  4  3  2  1

Notice that we have 10 pairs, and each pair adds up to 10+1.

The total of all the numbers above is

\displaystyle{\text{Total = pairs * sum of each pair} = n(n + 1)}

But we only want the sum of one row, not both. So we divide the formula above by 2 and get:

\displaystyle{\frac{n(n + 1)}{2}}

Now this is cool (as cool as rows of numbers can be). It works for an odd or even number of items the same!

Technique 3: Make a Rectangle

I recently stumbled upon another explanation, a fresh approach to the old pairing explanation. Different explanations work better for different people, and I tend to like this one better.

Instead of writing out numbers, pretend we have beans. We want to add 1 bean to 2 beans to 3 beans… all the way up to 5 beans.

x
x x
x x x
x x x x
x x x x x

Sure, we could go to 10 or 100 beans, but with 5 you get the idea. How do we count the number of beans in our pyramid?

Well, the sum is clearly 1 + 2 + 3 + 4 + 5. But let’s look at it a different way. Let’s say we mirror our pyramid (I’ll use “o” for the mirrored beans), and then topple it over:

x                 o      x o o o o o
x x             o o      x x o o o o
x x x         o o o  =>  x x x o o o
x x x x     o o o o      x x x x o o
x x x x x o o o o o      x x x x x o

Cool, huh? In case you’re wondering whether it “really” lines up, it does. Take a look at the bottom row of the regular pyramid, with 5′x (and 1 o). The next row of the pyramid has 1 less x (4 total) and 1 more o (2 total) to fill the gap. Just like the pairing, one side is increasing, and the other is decreasing.

Now for the explanation: How many beans do we have total? Well, that’s just the area of the rectangle.

We have n rows (we didn’t change the number of rows in the pyramid), and our collection is (n + 1) units wide, since 1 “o” is paired up with all the “x”s.

\displaystyle{\text{Area} = \text{height} \cdot \text{width} = n(n+1)}

Notice that this time, we don’t care about n being odd or even – the total area formula works out just fine. If n is odd, we’ll have an even number of items (n+1) in each row.

But of course, we don’t want the total area (the number of x’s and o’s), we just want the number of x’s. Since we doubled the x’s to get the o’s, the x’s by themselves are just half of the total area:

\displaystyle{\text{Number of x's} = \frac{Area}{2} = \frac{n(n + 1)}{2}}

And we’re back to our original formula. Again, the number of x’s in the pyramid = 1 + 2 + 3 + 4 + 5, or the sum from 1 to n.

Technique 4: Average it out

We all know that

average = sum / number of items

which we can rewrite to

sum = average * number of items

So let’s figure out the sum. If we have 100 numbers (1…100), then we clearly have 100 items. That was easy.

To get the average, notice that the numbers are all equally distributed. For every big number, there’s a small number on the other end. Let’s look at a small set:

1 2 3

The average is 2. 2 is already in the middle, and 1 and 3 “cancel out” so their average is 2.

For an even number of items

1 2 3 4

the average is between 2 and 3 – it’s 2.5. Even though we have a fractional average, this is ok — since we have an even number of items, when we multiply the average by the count that ugly fraction will disappear.

Notice in both cases, 1 is on one side of the average and N is equally far away on the other. So, we can say the average of the entire set is actually just the average of 1 and n: (1 + n)/2.

Putting this into our formula

\displaystyle{\text{sum = average * count } = \frac{(1 + n)}{2} \cdot n = \frac{n(n + 1)}{2}}

And voila! We have a fourth way of thinking about our formula.

So why is this useful?

Three reasons:

1) Adding up numbers quickly can be useful for estimation. Notice that the formula expands to this:

\displaystyle{\frac{n(n+1)}{2} = \frac{n^2}{2} + \frac{n}{2} }

Let’s say you want to add the numbers from 1 to 1000: suppose you get 1 additional visitor to your site each day – how many total visitors will you have after 1000 days? Since thousand squared = 1 million, we get million / 2 + 1000/2 = 500,500.

2) This concept of adding numbers 1 to N shows up in other places, like figuring out the probability for the birthday paradox. Having a firm grasp of this formula will help your understanding in many areas.

3) Most importantly, this example shows there are many ways to understand a formula. Maybe you like the pairing method, maybe you prefer the rectangle technique, or maybe there’s another explanation that works for you. Don’t give up when you don’t understand — try to find another explanation that works. Happy math.

By the way, there are more details about the history of this story and the technique Gauss may have used.

Variations

Instead of 1 to n, how about 5 to n?

Start with the regular formula (1 + 2 + 3 + … + n = n * (n + 1) / 2) and subtract off the part you don’t want (1 + 2 + 3 + 4 = 4 * (4 + 1) / 2 = 10).

Sum for 5 + 6 + 7 + 8 + … n = [n * (n + 1) / 2] – 10

And for any starting number a:

Sum from a to n = [n * (n + 1) / 2] – [(a - 1) * a / 2]

We want to get rid of every number from 1 up to a – 1.

How about even numbers, like 2 + 4 + 6 + 8 + … + n?

Just double the regular formula. To add evens from 2 to 50, find 1 + 2 + 3 + 4 … + 25 and double it:

Sum of 2 + 4 + 6 + … + n = 2 * (1 + 2 + 3 + … + n/2) = 2 * n/2 * (n/2 + 1) / 2 = n/2 * (n/2 + 1)

So, to get the evens from 2 to 50 you’d do 25 * (25 + 1) = 650

How about odd numbers, like 1 + 3 + 5 + 7 + … + n?

That’s the same as the even formula, except each number is 1 less than its counterpart (we have 1 instead of 2, 3 instead of 4, and so on). We get the next biggest even number (n + 1) and take off the extra (n + 1)/2 “-1″ items:

Sum of 1 + 3 + 5 + 7 +  … + n = [(n + 1)/2 * ((n + 1)/2 + 1)] – [(n + 1) / 2]

To add 1 + 3 + 5 + … 13, get the next biggest even (n + 1 = 14) and do

[14/2 * (14/2 + 1)] – 7 = 7 * 8 – 7 = 56 – 7 = 49

Combinations: evens and offset

Let’s say you want the evens from 50 + 52 + 54 + 56 + … 100. Find all the evens

2 + 4 + 6 + … + 100 = 50 * 51

and subtract off the ones you don’t want

2 + 4 + 6 + … 48 = 24 * 25

So, the sum from 50 + 52 + … 100 = (50 * 51) – (24 * 25) = 1950

Phew! Hope this helps.

Ruby nerds: you can check this using

(50..100).select {|x| x % 2 == 0 }.inject(:+)
1950

Javascript geeks, do this:

[...Array(51).keys()].map(x => x + 50).filter(x => x % 2 == 0).reduce((x, y) => x + y)
1950

// Note: There are 51 numbers from 50-100, inclusive. Fencepost!

Join 450k Monthly Readers

Enjoy the article? There's plenty more to help you build a lasting, intuitive understanding of math. Join the newsletter for bonus content and the latest updates.