logoalt Hacker News

seizethecheese • today at 4:18 AM • 5 replies • view on HN

These math proofs are so insanely over my head, but I really want to understand them. I tried Jane Street's socratic tutor skill (https://github.com/janestreet/agent_skills/blob/master/socra...) against this pdf and here's what I got:

- Matrix multiplication is multiplying pairs of numbers together then summing them (you probably know this already)

- Without any optimization, this process is o(n^3)

- You can make this faster if you share a multiplication or sum across multiple places

- By sharing sums / multiplication operations the maximum efficiency is o(n^2.25)

I studied Economics, not CS so I'm a bit hazy on what big o actually means, to be honest.


Replies

triCoder • today at 5:35 AM

I can help explain big O, it's a super weird concept:

Let's say you want to know the speed of an algorithm. That's a hard thing to do. First, there's the problem that it's different speeds on different computers. Then there's the problem that speed will be relative to the size of the thing you are processing. Then, there's the issue that what you really want is easy ways to compare algorithms, so you don't really want the exact speed of an algorithm but a quick estimate. Finally, you want to make it mathematically provable.

Big O is so weird because of the last two. If you want a quick estimate, you probably want it to be handwavy. But if you want it mathematically provable, then you don't. It feels like these two should be impossible to fit together. But Big O makes it work by putting algorithms into different buckets. If two algorithms are in the same bucket, you handwave minor differences in speed. But which bucket that it's in is mathematically provable.

The way Big O works is that you build an equation of how long it takes given some input with size n, then you take the largest term and you ignore any constant multipliers and smaller terms, with precise mathematical terminology that lets you do so. So the run time of some algorithm is 3 * n^2 + n, then it would be O(n^2), as that is the largest term.

The perfect place to see this in action is in sorting algorithms. They tend to fall into three main buckets - O(n^2) for slow algorithms that are easy to create, O(n lg n) for fast algorithms that are optimal, and O(n) for super fast algorithms that only work if the data you are sorting has particular properties. So simply by knowing which of these three buckets your sorting algorithm is in, I can tell if you are using a bad algorithm, using a good one, or making assumptions about your data that may or may not be true.

➕ show 4 replies
verandaguy • today at 4:46 AM

On your last point: when talking about algorithms in the abstract, we still use similar structures to those used in programming; loops and branches (if/else) are the most critical in many of the common complexity analysis cases (big-O, little-O, big-Theta).

Big-O specifically refers to the worst-case time or space complexity of an algorithm. Assume that your algorithm operates on an input of n elements. Then:

- A straight iteration over every element (`for item in items: print(item)`) runs in linear time: O(n) for n elements.

- If your algorithm has a nested loop, and each of the loops has a bound which is either literally n, or derived from n, this is quadratic time (O(n^2)). For example, this naïve search for duplicates:

    for item in items:
        for dupe_candidate in items:
            if item == dupe_candidate:
                print(f"{item} is a dupe!")
This extends into higher powers (O(n^3), O(n^4), etc)) with deeper nesting of loops, and if inner loops are dependent upon other input parameters, you can use a separate variable for that (O(n^m) for example).

- There are also cases where algorithms run in sub-linear time. Two very common cases for that are logarithmic time (O(log(m, n)), which often comes up in algorithms over height-balanced search trees of arity m, and constant time (O(1)), which means that regardless of the input size, the algorithm will run in the same amount of time (which sounds great, until you realize that for large enough values of 1 this is actually really slow -- so you often see these constant-time algorithms find niche applications at large scales where even a very large 1 is still small).

From a math perspective, this is really just modelling a function's behaviour over a given input range, as well as when it tends towards infinity. Understanding your algorithm's time and space complexity as well as the input domain are a very common first step towards identifying the data structures and algorithms which will make up your application.

➕ show 1 reply
zahlman • today at 3:18 PM

All of the big-O notation (and variants) is a way to measure how the demands of a task grow as the input size grows. We care about this because if one program simply does a task twice as fast as another, or one has a bit less startup time than the other, then we could always make up that difference with a faster computer. That is, if the two algorithms are in the same "complexity class" then the problem size doesn't matter and the performance just depends on our hardware. But if one of them uses an algorithm with a lower complexity, then we can — in principle — always make that program come out ahead, regardless of the hardware, by simply making the problem bigger.

Of course, that's at a hand-wavy, theoretical level. We assume that a bunch of smaller pieces simply take a set amount of time (for example, in this matrix multiplication result, we don't care about how long it takes to multiply really big numbers together compared to small ones, mainly because a really big matrix doesn't necessarily have bigger numbers in it than a small one). And we don't care, when we do these proofs, about whether the algorithms are practical. (In fact it's common in the real world that we use a "slow" algorithm because the "faster" one requires impossibly large problem sizes to show its benefit; maybe we'd have to wait past the end of the heat death of the Universe even in the best case). And most importantly, we have to be able to measure the size of the problem in a consistent way. (For matrix multiplication, we choose n as either dimension of a square matrix. This is arguably non-standard, since it means we have n^2 elements of input data!)

We use this notation to mean that we're throwing away constant factors. For example, "show the first million bytes of a file" is O(1): no matter how long the file gets, we just ignore everything after the first million bytes, so it takes the same amount of time for those longer files. And similarly it doesn't matter how much work is involved in "showing" a byte, nor my choice of "million" for the problem description (since it isn't coupled to n). But "show the first half of a file" is O(n): the longer the file gets, the more we have to show, and the amount we have to show is proportional to that input size.

Anyway, with our standard definitions, the obvious way to multiply matrices needs on the order of n^3 operations. That means that the number of operations we have to do, grows as the cube of the matrix side length. This is the textbook algorithm you would have learned in high school, and it's pretty straightforward to find that o(n^3) result: there are exactly n^2 values in the result, and for each of them, we take a column and a row, match up and multiply each pair (n of them), and add those results (n-1 additions to do; of course the bigger n gets, the less the 1 matters).

On the other hand, we could set an a priori theoretical minimum complexity of n^2, because there's that much output data: we have to compute each value in the result somehow, and computing a value involves stating it (which takes at least a specific constant amount of time no matter what).

Progress on this problem has generally involved finding better algorithms that reduce that exponent from 3, towards 2 (i.e. through non-integer values). In early October, OpenAI showed (to my understanding) that there must be a way to get it arbitrarily close to 2.25, then other mathematicians figured out the way. Now OpenAI has (apparently) shown that we can reach 2.25 exactly, and also that we cannot do any better than that.

amomchilov • today at 4:47 AM

“Big o notation” are the search terms you’re looking for.

It’s a notation for quantifying the complexity of algorithms, by how the number of operations needed scales with the size of the input (often “n”). For example, greeting every person when you enter a room is O(n), because the number of greetings increases linearly with the number of people in the room. But having every person in a room greet every other person in a room is O(n^2), as the number of greetings scales quadratically with the number of people.

➕ show 1 reply
liamlaverty • today at 11:58 AM

I've found asking for "a Bartosz Ciechanowski style explainer for..." and tasking it with a big model on high settings usually produces something that can teach you concepts.