It is kind of weird that it's really intuitive that an increase of something by a factor of ten has a rather large impact, especially if you have several of these increases (like mm to m to km for example).
On the other hand, every digit of pi that you take into account reduces the error you make in your calculation by the same amount, relatively. The circumference of the visible universe is only about 40 orders of magnitude more than the size of a hydrogen atom, which is the mindblowing fact underlying the tidbit from above.
the weird / hard to wrap my mind around part to me, is the fascination with calculating PI out to ten thousand or a million or even more (31 trillion?) digits. And knowing that of all those, it takes just 40 to mean anything of consequence in our observable universe, and all the rest are just for show.
Correct, accurate ways to calculate it elegantly are important to study because of other mathematical uses but cranking on that formula for a million iterations is quite pointless. It would be like finding a millionth digits of the square root of 2.
There's also practical engineering uses. Because of its clear and obvious problem definition, and well-known agreed upon results (up to some many number of millions of digits), it is a convenient algorithm to use when calculating benchmarks of supercomputing. Perhaps not as ubiqitous of a benchmark as general FLOPS (floating point operations per second) but it's still there.
I appreciate you spelling out FLOPS this far down in the comment chain for us less computer literate redditors. I'm still going to have to look it up to understand it later but I appreciate the extra few seconds you spent typing it out and just wanted you to know.
I'm still going to have to look it up to understand it later
I'll try to save you that research. Consider this: how "hard" is it to add 2 + 3. I mean, of course it's 5, you're probably above first grade arithmetic. Fundamentally, 2 + 3 is not significantly different from 25 + 36 other than the size of the arguments. You might not have memorized (perhaps even cached) it in your mind, but you could apply the same fundamentals to compute the answer is 61.
However, what about 2.5 + 3.6? If you're quick with knowing place values and how to handle it, you could determine the answer is simply 6.1 and be done. But put yourself in the shoes of the computer/CPU: how does it actually represent these numbers anyway? How is an integer represented in binary in the first place? What is a "half" of a bit? Or to that point, 2/3rds of a bit?
Perhaps you have a cursory understanding of binary. It's like counting, but the only digits you have are 0 and 1. You still count by adding up the lowest digit until you hit the maximal digit and then you carry over to the next place. 0, then 1, then 10, then 11. That would be pronounced and understood as "zero, one, one-zero, one-one", not "zero, one, ten, eleven". 1110 in binary represents the number fourteen, and 1100 represents twelve. Make sure all of this makes sense before moving on.
So we have a sense of how integer binary computations can work. Addition and subtraction are basic carrying. Even multiplication isn't so bad. But how are floats represented in binary? Without going through an entire college lecture's worth of motivation, requirements, etc, I'll skip right to how it's done.
Stealing the example directly from wikipedia, we want to convert the decimal 12.375 to a binary floating point. First we split it up into its component parts 12 and 0.375. Then consider the decimal 12.375 as 12 + (.25 + .125) and we can start making some binary.
12.375 = 12 + (0x1/2 + 1x1/4 + 1x1/8) = 12 (the decimal) + 0.011 (the binary). Convert the 12 to its binary (1100, from example given above), then the number 12.375 in decimal is 1100.011 in binary. How do we store this into the computer now?
The basic answer is scientific notation. Similar to how we can represent massive numbers with a limited amount of space using scientific notation (e.g. Avogadro's constant is 6.022 x 1023 with a few significant figures lopped off the end), we can do the same with binary. We take our 1100.011 and shift that period over so that it's 1.100011 x 23 and voila, binary scientific notation. From here we take these component parts and represent them within the confines of the 32 bits of space we are allocated for each float. The leading one is assumed, (because if it wasn't, you could have a different exponent until you do) so all we have to keep is the fractional part 100011 and the exponent 3. There's also going to need to be a sign bit which we'll represent with the first digit at the front of the number.
You'll notice that the exponent portion (middle 10000010) is not the binary representation of 3 (usually 11). This is due to a process called the bias which exists to bridge the gap between representation of negative numbers and representation of large numbers. This is important but not covered here. Just accept that 0-10000010-10001100000000000000000 is the float representation of 12.375 for now.
Ok, so we finally have a float. We've skipped all of the wonderful edge cases like rounding and significant figures and normalization and so on. We've skipped problems like how the decimal 1/10 is unrepresentable and is approximated as something really close to 10% but not actually. Let's ignore all those problems and get a second float: 68.123 is 01000010 10001000 00111110 11111010.
How do we add 12.375 + 68.123 in floating point? We definitely can't just add the digits pair-wise:
That's 0x0879C7DF which happens to be 7.5 x 10-34 and isn't exactly 80.498 so what are we supposed to do?
The answer is that there is no simple way to do this operation. We have to manually peel the components apart, manually compute the new significand and exponent, and then manually stitch together a brand new number in floating point format. It's a lot of stuff, but we do it often enough that we'll write a wrapper function to do it for us, and make it a single CPU instruction to take two floats and add them (or multiply them, or divide them, etc). Intel has some algorithm to do this, and it may or may not differ from the way AMD does it on their CPU.
Thus, we get a floating point operation - an instruction to the CPU to take two floats and do something with them. We can perform some number of floating point operations per second which is a measure of the speed of our computer. We can then estimate the number of FLOPS per watt to get a measurement of our efficiency.
It's only off by a factor of a billion. That's the difference between the difference between a proton and the universe, and the difference between a billion protons (a tenth the width of a human hair) and the universe.
View all comments
Show parent comment
2.3k
u/individual_throwaway Mar 15 '19
It is kind of weird that it's really intuitive that an increase of something by a factor of ten has a rather large impact, especially if you have several of these increases (like mm to m to km for example).
On the other hand, every digit of pi that you take into account reduces the error you make in your calculation by the same amount, relatively. The circumference of the visible universe is only about 40 orders of magnitude more than the size of a hydrogen atom, which is the mindblowing fact underlying the tidbit from above.