← Starting Henceforth

Episode 3

Why the maths looks backwards

Postfix, and why the stack is the parentheses.

2:03 · Vivaldi · Allegro (RV 293 i)

Watch here · code in the app

Henceforth is the real terminal — one purchase ($9.99) for iPhone, iPad and Mac. Type the commands below into the app as you watch.

Code along

Tap to copy, then type it into Henceforth.

What you’ll learn

  • You write the numbers first, then the operation — 2 3 + . That's reverse Polish (postfix).
  • The stack remembers as you go, so 2 3 + 4 * nests without any brackets.
  • Because the last two numbers already sit on the stack, Fibonacci is one little word: : next-fib tuck + ;.
Transcript
  • you already know how to add.
  • watch how this little machine wants it.
  • you put the numbers down first —
  • two, then three.
  • then you say: add.
  • five. the plus reached back and grabbed the two.
  • numbers first, then the operation —
  • that's reverse polish.
  • and it stacks up — no brackets.
  • two plus three is five —
  • then five times four.
  • twenty. the stack just remembers.
  • now — one that's a headache in most languages.
  • the fibonacci numbers — each one the last two, added.
  • python needs a loop and two boxes to hold them.
  • but our two numbers already sit on the stack.
  • so it's one little word.
  • take the pair, make the next one.
  • start it with two ones.
  • now nudge it forward — again and again.
  • and it just keeps climbing —
  • a hundred and forty-four — the twelfth.
  • fibonacci. in one little word.
  • clear the pair —
  • and the school way? watch it break.
  • no — the plus went looking for two numbers,
  • and found nothing behind it.
  • numbers first. that's the whole trick.
  • henceforth.