Experimental new series: Foundations of QAnal

I may or may not stick with this. I am having horrible writer’s block trying to write this all out in a LaTeX PDF, Erlang, my videos, or in my Revelations. So I’m trying the blog medium. The blog has the “fire and forget” property. So we’ll see.

QAnal is my fork of mathematics. QAnal is short for “rational analysis”.

The impetus for this was about a year or so ago. I wanted to do a video explaining Gaussian elimination and neural networks with some code (still haven’t done that hundreds of videos later). I got the sense that both ideas were intrinsically very simple, just poorly explained. Mostly because those explaining the ideas didn’t really understand them.

Problem number 1: CIA floats

The first thing I realized was why nobody gives code examples of Gaussian elimination: CIA floats. Gaussian elimination is a very mathematically (and computationally) straightforward algorithm. But it requires a lot of division. Something that computers are weirdly bad at.

1> (1/10) + (2/10) =:= (3/10).
false

So I went to implement rational number arithmetic in Erlang, and then write a matrix data structure over the rational numbers.

Implementing rationals is easy in a language that has built-in bignum arithmetic like Erlang or Scheme. Scheme actually has built-in rationals

scheme@(guile-user)> (equal? (+ (/ 1 10) (/ 2 10)) (/ 3 10))
$1 = #t

(“Rational” just means fraction with integers. Rational = ratio.)

But doing this in a language that doesn’t have built-in bignum arithmetic means you have to implement bignums yourself (or face overflow/underflow issues). And that’s a task beyond the capacity of almost anyone writing a math explainer (most of whom would struggle writing “hello world”).

So, as someone explaining Gaussian elimination, you have three options:

  1. use floats and lose the ability to do even basic reasoning about your program
  2. go into the cave (which the CIA claims doesn’t exist) and slay the angry fire-breathing math dragon
  3. not give a code example

Well, option 3 is clearly the best one of those three

Problem number 2: CIA reals

Problem number 2: a lot of mathematics depends on a leaky abstraction called the “real numbers” (which are fake, and which I may or may not explain at some point). CIA floats exist as a band-aid abstraction in computing to deal with mathematics centered around CIA reals.

Interestingly, the term “real number” emerged to distinguish them from “imaginary numbers”. In hindsight, imaginary numbers are real and real numbers are fake. Summary: the CIA is retarded


Example: the square root of two

Let me give you a really really simple example.


What is x? Well if you remember high school trigonometry, then you know the answer is the square root of 2?

This is the Pythagorean Theorem. The first theorem ever, and easily the most important theorem in mathematics.


Well, there’s a problem. As even the Ancient Greeks knew, there is no rational number with has the property that its square is two.

The argument is really simple. Let me lay it out.

  1. Every fraction can be reduced. I will make this argument formally in a couple of posts. You can watch my Math for Programmers Playlist if you are impatient. The beginning bit of this series will match that playlist pretty closely.

    But take it on faith for now. A fraction is reduced precisely when the top and bottom of the fraction contain no common factor. There is a canonical procedure for reducing a fraction called the Euclidean algorithm (which we’ll talk about soonish).

    In particular, the canonical (reduced) form of any fraction has the property that the top and bottom of the fraction are not both even. Examples:

    scheme@(guile-user)> (/ 54 30)
    $1 = 9/5
    scheme@(guile-user)> (/ 2 6)
    $2 = 1/3
    scheme@(guile-user)> (/ 2 4)
    $3 = 1/2
  2. OK. So let’s assume I have a rational number (/ a b) which has the following two properties:
    • the square of (/ a b) is 2
    • a and b are not both even

    I will derive a contradiction.

  3. The following function evaluates to true for any integers a and b (provided b is not zero, in which case it crashes).
    (define (check a b)
      (equal? (expt (/ a b) 2)
              (/ (expt a 2)
                 (expt b 2))))

    Let’s try it

    scheme@(guile-user) [2]> (define (check a b) (equal? (expt (/ a b) 2) (/ (expt a 2) (expt b 2))))
    scheme@(guile-user) [2]> (check 2 4)
    $5 = #t
    scheme@(guile-user) [2]> (check 2 5)
    $6 = #t
    scheme@(guile-user) [2]> (check 8482 2919)
    $7 = #t

    This is a direct consequence of the rule for multiplying fractions:

    times({q, TL, BL}, {q, TR, BR}) ->
        q(TL * TR,
          BL * BR).
  4. If
    (equal? (/ (expt a 2)
               (expt b 2))
            2)

    then it is also true that

    (equal? (expt a 2)
            (* 2 (expt b 2)))

    This is just algebra.

  5. This is saying that (expt a 2) is 2 times another integer, which means that (expt a 2) is even.
  6. Even integers have even squares and odd integers have odd squares (exercise: prove it! hint: write out a mod 2 multiplication table).
  7. Therefore a itself is even; that is, there exists another integer x such that (equal? a (* 2 x))
  8. Some algebra
    ; substitution:
    (equal? (expt (* 2 x) 2)
            (* 2 (expt b 2)))
    ; commutative property of integer multiplication:
    (equal? (* 4 (expt x 2))
            (* 2 (expt b 2)))
    ; divide both sides by 2
    (equal? (* 2 (expt x 2))
            (expt b 2))
  9. By the same chain of reasoning as above, b must also be even.
  10. We’ve proven now that, supposing there exists a fraction (/ a b) whose square is 2, then it must be the case that both a and b are even.
  11. Therefore (/ a b) cannot be reduced, which is absurd, because we have an algorithm which reduces every fraction.

This argument traces back (in different verbiage) to about 600 BC, to the school of the Pythagoreans, in Ancient Greece. This fact deeply troubled the Greeks, because it upset their weird perfectionist aesthetic. Legend has it that when Hippasus leaked the terrible secret—in modern verbiage—that the square root of 2 is irrational, the Pythagoreans took him out into the ocean and drowned him.

But what is x?

The CIA’s answer is that x is an “irrational” number, which is just simply called the square root of 2.

QAnal’s answer is that you’re asking the wrong question. I will convince you that my answer is right.

The idea of QAnal

Let’s get back to the plot. I realized almost immediately that if one backpropagates the following constraints 1. no floats 2. no real numbers 3. no infinite processes —which are intrinsic to computing—back into mathematics, then a lot of stuff breaks, but things end up simplifying quite dramatically.

There’s an entire barely explored world of deeply interesting mathematics here, which is simpler, very basic, and makes infinitely more sense than the CIA’s mathematics.

What we get in QAnal, crucially, is mathematics that is computable. The CIA’s version of mathematics is barely computable.

QAnal’s notation ends up being a lot better. Our logic becomes a lot more clear. Everything is just cleaner and saner. There’s no waffling. Everything is super concrete and super clear. It’s just better.

Programmers out there: how many times have you

  • written 200 lines of code in a stream of consciousness that you thought made perfect sense
  • went to compile it
  • found it didn’t compile, or if it did compile, it doesn’t work
  • realize that the whole approach you’re taking to the problem is fundamentally wrong
  • throw out your code and start over

A lot right? Like that can be a monthly occurrence.

Well. Mathematics has been stuck on the first bullet point for the last 23 centuries. It’s a miracle that it works even a little bit.

Enough’s enough.

I’ve spent basically the last year going down a rabbit hole of learning this entire new world of mathematics. And being a bit miffed that this new, beautiful way of thinking isn’t standard.

I owe a major major debt of gratitude to Norman Wildberger. He realized these problems about 20 years ago, and has done a massive amount of work in developing what I call QAnal. In particular

  • he developed Rational Trigonometry, which doesn’t involve length or angle (two major sources of irrationality)
  • he developed Algebraic Calculus, which doesn’t involve limits (another source of irrationality)
  • he developed WF Algebra, which is a phenomenally beautiful and simple formalization of logic.
  • he developed Chromogeometry, which is just simply fascinating
  • he developed Universal Hyperbolic Geometry, which I have only looked at a little bit but looks amazing

We will learn about all of these at some point down the line.

QAnal is genuinely simpler and genuinely easier. And it’s not close. It’s a world of difference.

Angry Dragon Problems

So. The basic premise is that the CIA has lost its way. It has started relying on joggerlicious abstractions (chiefly, the “real numbers”).

The CIA’s approach has the net effect of introducing angry dragon problems. This is where you introduce a simplifying assumption at the beginning, and you end up paying for it with massive uncontrollable chaotic sprawling complexity down the line.

I’m going to write a post about angry dragon problems at some point. OOP versus functional programming is a great example. For now I’ll leave you with this gif.


Conclusion

What I’m going to do for now is stick to my original premises:

  • clarity of explanation is the most important thing
  • “rigor” is secondary to clarity, although it is nice if you can have it
  • lot of code examples
  • a lot of articles that are small, somewhat self-contained, and have a story to them
  • don’t be too rigid in the structure. putting out content that people can discover and make sense of is far more important than having the content be exactly correct. mistakes will be made no matter what, so don’t be afraid to make them.
  • try not to bite off more than I can chew

Mini-outline

Planned-ish:

  • integers and the euclidean algorithm
  • rational number arithmetic
  • matrix arithmetic
  • gaussian elimination, determinants, and invertibility

Fuzzier:

  • wf algebra
  • complex numbers
  • basic projective geometry
  • rational trigonometry
  • algebraic calculus (PreAnal)
  • chromogeometry
  • quaternions
  • dihedral geometry

Eventually:

  • dual numbers, automatic differentiation, and neural networks
  • differential geometry
  • algebraic topology
  • universal geometry
  • number theory
  • cryptography
  • information theory

Let’s get going!

Further reading and references

Wildberger
Podcasts
Git Repos
Playlists
Books

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.