149 points · by totaldude87 · 6y ago · 147 comments
On the other hand, in the 1960s NASA figured out exactly how many bits of precision they needed to get to the Moon and came up with the 15-bit Apollo Guidance Computer; 14 bits wasn't enough and 16 bits was more than they needed. (The computer supports double precision and triple precision for tasks that needed more.)
The point is that in the 1960s, aerospace systems would carefully consider exactly how many bits they needed and build systems with bizarre numbers of bits like 15 or 27. Now, they use standard systems, which generally have way more accuracy than needed.
The answer the kid is looking for: NASA's most precise representation of pi is more precise than 3.14, but nowhere close to 500 digits like the question suggested. 15 is more than enough for most engineers at NASA, and anything that an astronomer might conceptually want to do would take at most 40 digits of pi to do with almost arbitrary precision. The fact that the current representation is architecturally convenient for modern FPUs is basically immaterial to the person's question, even if that's interesting for people with detailed knowledge about such things.
Ideally the article would talk about what "more than enough" looks like (which it does), but also what minimums look like (which it doesn't), and then mention that they chose that specific size because most computers do two specific sizes really fast and that's the more accurate of the two.
I recently went down a rabbit hole of trying to implement a cosine function from scratch and found that for most applications where I use cosine (low-resolution graphs or 2d games), I need a shockingly low level of precision. Even four decimals was overkill!
For those that are interested, you can read about my adventures with precision and cosine: https://web.eecs.utk.edu/~azh/blog/cosine.html
The Taylor expansion produces approximating polynomials that aren't that good.
For instance, if you were to ask which degree-4 polynomial best approximates cos(x)?, you wouldn't end up with 1-x^2/2 + x^4/24.
In fact, this polynomial is 0.99958 - 0.496393 x^2 + 0.0372093 x^4; it pretty much coincides[2] with cos(x) on the interval (-π/2, π/2); the error is an order of magnitude smaller than with the Taylor polynomial (see [3] vs [4]).
How to do this? Linear algbera[1].
See, the polynomials form a Hilbert space (a vector space with an inner product), where a decent choice of one is
<f(x), g(x>) := \int_π/2^π/2 f(x)g(x) dx
This is Do Gramm-Schmidt on 1, x, x^2, ...; obtain an orthonormal basis, and use the inner product to compute a projection on the first d elements to obtain a best degree-d polynomial approximation. Voila!Linear Algebra saves the day yet again.
[1]https://www.math.tamu.edu/~yvorobet/MATH304-503/Lect4-04web....
[2] https://www.wolframalpha.com/input/?i=plot+0.0372093+x%5E4+-...
[3]https://www.wolframalpha.com/input/?i=plot+abs%281-x%5E2%2F2...
[4]https://www.wolframalpha.com/input/?i=plot+abs%281-x%5E2%2F2...
And if you look at the NASA low-precision number routines, you’ll see that’s exactly what they did.
https://fermatslibrary.com/s/apollo-11-implementation-of-tri...
Here’s a comparison between its relative error vs. a 5th degree Taylor series (if you use high precision arithmetic; I’m sure on the machine itself rounding errors made things a bit choppier). In the worst case for the Taylor series the relative error is about 45 times lower in the optimized polynomial:
bash$ gnuplot -e 'set format x "%.15f"; set format y "%.15f"; set samples 100000; set table "cos.dat"; set xrange [-3*pi/8:3*pi/8]; plot cos(x); f(x) = a + b*x**2 + c*x**4; fit f(x) "cos.dat" using 1:2 via a,b,c'
It then gives you "optimized" values for a/b/c from your template formula, thus resulting in cos(x) ~= 0.999923 + -.498826*x*x + .0391071*x*x*x*x
Which is even more accurate but only to about four decimal places.[0]: https://gist.github.com/mooman219/9698a531c932c08ccefd86ba7c...
https://www.bbcelite.com/explore/articles/deep_dive_pitching...
Sure, if 24 bits were already sufficient, they would not go out of their way to avoid the extra 8 bits. So in that sense you're right of course. But it's not just "Hey, single precision floats are 32 bits, so why don't we just use that!"
Instead, it tries to answer the thrust of the prompt question: given the massive numbers used in spaceflight, is pi calculated to the greatest possible practical accuracy? Going over the history of the 15-digit version would divert from the interesting part of the article (the effect of precision on calculation) and dilute a nice teachable moment.
Though that fact about the Apollo Computer would make an interesting part of a follow-up.
X87 uses an 80bit format with functionally a 63 bit significand (they actually use a 64 mantissa, but for that actually doesn’t gain you anything, and adds many terrible edge cases).
They use double precision values because that presumably provides more precision than they need, but 32 bit float would be woefully inadequate.
They could use more (x87 or software float for instance) but there’s not really an any advantage to the increased precision you get, and there are many downsides.
Also alas, 80bit is a bit of a misnomer - when comparing to the more regular ieee754 representations, it’s actually fp79 :D
https://en.m.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80...
Like, you can compute digit 10billion without knowing any of the previous digits (in hex..)
If this doesnt prove the matrix then I do not know what does ;-)
There are analogies of digits of prime to sort of infinite libraries, kind of an evolving random universe of numbers. But the digits of pi are not a local (fixed-size) function of the previous digits, so the analogy to a physical simulation (or cellular automaton) isn't quite right. But the idea of a cellular automaton with varying locality (in this case increasing radius of interaction) is itself quite interesting to me.
(in this case it's a logarithmic neighborhood and the rule is chaotic for the initial conditions)
I should also note that the straightforward interpretation in this case is that of a temporal neighborhood for a Cellular Automaton! That is, dependence of several states back in time, and 0 space dimensions. You can also think of a 1D CA if you introduce a special state that signals the "expansion" of the digits of pi (which digit we're currently expanding)
This also enlightens me in the bizarre concept of multiple time dimensions. If you start with a 2D field, and use the same technique of keeping track of the current active expanding cells (i.e. "current time"), starting from a single active cell (time 0) in a top-left corner, then you can expand cells across a diagonal, and they depend on previous states in two different directions.
The guy is a mad man. I pity his keyboard.
Would that not mean that we then have just as quick of a way to calculate an arbitrary decimal digit of pi? Hexa and dec feel geometrically close enough for any dec digit to be fully "covered" by a couple calculations of contiguous hexa digits.
Maybe there is something special about a power of two base.
I believe the formula was found by computer search, but my memory could be failing me. The three people the result is named after are all well-known for computer-assisted mathematics, for instance using the PSLQ algorithm [1].
[0]: https://www.ams.org/journals/mcom/1997-66-218/S0025-5718-97-...
[1]: https://en.wikipedia.org/wiki/Integer_relation_algorithm
He had a prototype that would calculate about 100 digits or so. I asked him how he knew it was correct, and he said in high school he was going for the Guinness world record in memorizing Pi, and he simply knew it was correct. (By the time he was ready to break the record, someone else showed up with having memorized a couple thousand places or so, and he gave up.)
We were allotted strict computer time limits on our accounts on the PDP-10. He figured he could get a thousand digits on the remaining time on his account at the end of the year, and set it up to run overnight.
The program calculated the digits, but had some disk error and writing the output file failed. He couldn't rerun it because he had no computer time left, and that was that.
Another personal anecdote is that in a company that shall remain unnamed we used to have a Pi from memory competition every Pi day (3/14). The president of the company always won. I don't recall how many digits he knew but it was some ridiculously high number (hundreds). I much prefer my family tradition of eating pie on Pi days.
atan(1.0) * 4
And if there's no math package on your system already defining PI then that's the value you should use - assuming there aren't legal requirements mandating other values to be used instead.
Is there a counterargument to this? Is there a case where the infinite irrational nature of Pi would be physically realized?
Naturally, I had already memorised the first 12 digits of π years before I found out about that.
I’d be surprised if NASA wasn’t accounting for GR as standard, what with Mercury etc., but for the rest of us, 10 sf should be enough.
[0] https://www.physicsforums.com/threads/what-is-feynmans-exces...
[1] http://www.wolframalpha.com/input/?i=G%2A%28earth%20mass%29%...
I am wondering if there is a physical application that actually would benefit from more than 40 digits.
Lots of values of pi occur in various formulas all of which end up going back to a circle or trig function at some point, (for example fourier transforms, normal distributions, any periodic motion, etc).
The 292 is a pretty big number, so at that point the fractional approximation is very good. 355/113 is good enough for anything you're doing on planet earth.
This is the real answer right here. Rockets have all sorts of uncertainties in them. You have the measurement uncertainty in exact orientation and the measurement uncertainty in the acceleration and thus total thrust delivered, all on top of the physical uncertainty in exactly how powerfully your engine is going to burn, and for how long. Remember, there are physical valves that need to open and close to control propellant flow, and there are chaotic perturbations in the conditions inside the combustion chamber. You simply cannot remotely achieve a perfect delta-v in a perfectly specified direction; there are uncertainties on both.
Just memorize those six digits to get you four digits beyond the three that everybody knows.
But the fraction is weirdly close and that's interesting for other (more academic) reasons, such as explaining why plotting primes in polar coordinates looks like a pattern: https://www.youtube.com/watch?v=EK32jo7i5LQ
Or you can remember 1592 as the year Trinity College in Dublin was founded. You didn't know that? You probably won't forget now.
___
113|355Clearly unacceptable. I'm sure this be fixed in IPv7.
RFC 1606 - A Historical Perspective On The Usage Of IP Version 9
https://tools.ietf.org/html/rfc1606
> Whilst there are still many addresses unallocated the available space has been sharply decreased. The discovery of intelligent life on other solar systems with the parallel discovery of a faster-than-light transport stack is the main cause. This enables real time communication with them, and has made the allocation of world-size address spaces necessary, at the level 3 routing hierarchy. There is still only 1 global (spatial) level 2 galaxy wide network required for this galaxy, although the establishment of permanent space stations in deep space may start to exhaust this. This allows level 1 to be used for inter-galaxy routing. The most pressing problem now is the case of parallel universes. Of course there is the danger of assuming that there is no higher extrapolation than parallel universes...
c90f:daa2:2168:c234:c4c6:628b:80dc:1cd1 I think
I shifted it so the exponent is equal to the number of digits we can fit.
128 bits could indeed only fit the first 39 digits of PI.
And even then you haven't really stored PI, because you haven't stored where the comma is supposed to go.
So we'd be off by about <30 hydrogen atoms instead of <1 :)
Here's the thing about the transcendental numbers, of which Pi is one of, all of them contain information.
All of them (and if someone knows of an exception, please let me know) seem to be able to be generated by functions, iterated functions, where the result of one iteration of the function is fed back into the equation (aka algorithm, aka function, aka "series of repeated steps") for future iterations...
In that respect -- all transcendental numbers -- can be thought of as fractals.
Think of it this way, Nature herself has a way of indexing a whole bunch of fractal algorithms via numbers that have a decimal after the integer component, and an infinite series of digits after that decimal!
Which also seems to imply (via reversal of cause and effect) that infinite information -- can be stored in the proper fractal equation -- although, that's just a personal hypothesis at this point with no real proof to back that claim up...
Anyway, math people out there, feel free to correct me on any or all of this (I claim Socratic ignorance in my reasoning process! <g>) -- but please cite concrete examples to back your specific claim...
You know what someone needs to do?
Look at the number gaps between multiple transcendental numbers... I don't mean like the number gap between pi and phi, or e and phi, or pi and e -- I mean like you take an algorithm for a transcendental, and you bump it (inside of its algorithm) by an integer value of one, then two, etc. If you still get another transcendental, then what is the gap between those transcendentals?
In fact, what is the smallest gap between two transcendentals, and why is this so?
Also, what kind of information -- does that gap represent?
?
Has anybody needed more than 3.14?
These sorts of problems are actually very common in a lot of scientific computing and simulation contexts, which is why many in the scientific computing community look aghast at the rise of FP16 (and even fp32) in machine learning applications. Of course, those algorithms are often of a _very_ different nature from (say) the large-scale linear algebra or PDE solvers we're using, but still it's pretty shocking if you're used to worrying about machine precision!
https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
If you keep your feet on the ground, that's probably enough for most things. But your grandchildren will probably need more, as spaceflight becomes commoditized. A couple of decimal places might mean the difference between landing on Mars, and icy death in the vacuum of space.
Source? If you make that big of an error you're gonna fail your orbital insertion at the other end entirely when going to places like Mars, let alone any farther.
For example: I don't think rockets start on course with a precision of 1e-3, and even if they do, small atmospheric changes will probably cause errors greater than that. I assume the feedback loop of the guidance systems easily smooth over errors this small. So while the theoretical trajectory calculations need more precision, the real world guidance might do not.
Another consideration: Is e.g. the length of the rocket know this precise? If temperature on a day changes over a range of e.g. 10 degrees, the materials might expand and contract more than 1e-3.
Now that's NASA. There are clearly things requiring much smaller errors. My CPU litography being off a factor 1e-3 will not end well.
I meant the quest in my everyday life. If I build a round table for my home, 3.14 will probably serve me well enough on the drawing table. At what point will random Joe Shmoe notice when pi is not exactly 3.14
So I'll reiterate, I want to see a source that NASA uses only 3.14 as the value for pi in making their trajectory calculations. And I want to point out the absurdity of even so much as having this debate in the very comment thread for an article on nasa.gov where NASA itself is saying that they use 3.141592653589793 for pi. We already have as good as a source as we're going to find, and there's a lot more sig figs in it than 3!
The book "Inventing Accuracy" is about missile guidance (which has mostly the same issues) and discusses the various sources of error in detail and the various contributions to the "error budget".
So, a 64-bit double, in other words.
1 in a million gives you an error of roughly 132 feet (40 metres) in the circumference of the Earth. 1 in 100 million brings that down to 1.32 feet (0.4 metres).
1 in 100 million is a mere 8 decimal places (out of the billions of decimal places that we've computed for pi.)
The above, while technically true, is exactly as pointless as it sounds. The error is lower with a 7 than a 6, but if either of them is an acceptable approximation, the difference is irrelevant.
There is only few instruments I have been around in my life that can actually measure this difference. I have 6.5 digit Voltmeter which would almost be able to detect it in certain situations if I somehow contrived the experiment, but not in any practical measurement where I actually had to calculate anything.
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647
I haven't practiced in a while, I hope that's right.
I know this much is correct because that's how much I've memorized.
† https://www.johndcook.com/blog/2018/05/22/best-approximation...
Or you could do what I always did, much to the annoyance of my high-school and college physics teachers, and just write down all my answers in terms of pi and never bother reducing it, since I would always argue that I can keep it exact that way :)