Hacker News new | ask | show | jobs
by AndrewDucker 386 days ago
Once you're dealing with irrational numbers you have to understand that all results are approximations.
3 comments

Well, sure, but you should still be able to ask and answer questions like "Is pi + sqrt(2) less than or greater than 4.553?"
It's important to understand that this was a non-trivial question for thousands of years. The ancient Babylonians would have probably believed this to be false (their best known approximation had pi ≈ 25/8, which is too small). The right way to approach this problem from first principles would be to construct some geometrical objects that have these lengths and try to compare them (for example by taking the perimeter of a square inscribing a unit circle and a square inscribed in a unit circle as the upper and lower bounds for pi, though that may not be good enough for this particular problem).

When you're doing something like pi + sqrt(2) ≈ 3.14159 + 1.41421 = 4.5558, you're taking known good approximations of these two real numbers and adding them up. The heavy lifting was done over thousands of years to produce these good approximations. It's not the arithmetic on the decimal representations that's doing the heavyh lifting, it's the algorithms needed to produce these good approximations in the first place that are the magic here.

And it would be just as easy to compute this if I told you that pi ≈ 314159/100000, and sqrt(2) ≈ 141421/100000, so that their sum is 455580/100000, which is clearly larger than 4553/1000.

> their best known approximation had pi ≈ 25/8, which is too small

I'm curious if they had a better one that we don't know of yet—their best known approximation of sqrt(2) is significantly more accurate.

When you have those sorts of problems the best way is to approach them using inequalities.

   3.1415<pi<3.1416 and 1.4142<sqrt(2)<1.4143, => 4.5557<pi + sqrt(2)<4.5559
   => 4.553 < 4.5557 < pi + sqrt(2) => 4.553 < pi + sqrt(2)
Finite decimal representations being of course the most convenient notation for inequalities like this.
In that case you know how many decimal places you want to expand them to, in order to compare.
Note that "expanding them to some number of decimal places" gives a somewhat misleading idea about how this works. What you're actually doing is computing a good enough approximation of pi, and expressing that as a decimal. But this is not the same kind of simple process that naturally gives decimals as it is for a rational fraction. Instead, you have to find some series with rational elements which converges to pi, and then compute enough terms of that series that you have a good enough approximation of pi for your purpose. Ideally, since you're interested in an inequality, you'd pick a series which is monotoniclaly increasing or decreasing, so that you know that computing more terms can't put you below or above the target number after you've reached a conclusion. But there is no canonical answer, there are numerous series which converge to pi that you could use, and they would givw you different decimal expansions as you are computing them.
Less approximations and more representations of complex things at times. (Just my opinion)

I prefer comparing it to complex numbers where I can't have "i" apples but I can calculate the phase difference between 2 power supplies in a circuit using such notation.

Nobody really cares about the 3rd decimal place when taking about a speeding car at a turn but they do when talking about electrons in an accelerator, so accuracy and precision always feel mucky to talk about when dealing with irrationals (again my opinion).

Well, 3.141 is an approximation of pi, not a representation of it, insomuch as you use it in an arithmetic expression. Of course, you can write 3.141... to just represent pi, but you can't eaisly use that in an arithmetic expression. For example, I can't tell you from "mechanical" operations if 3.141... - 3.1417 > 0, I have to lookup how big pi actually is.
Not really. Like the sibling comment said - you simply keep the symbolic values. I.e. instead of 4.442882938158... you write π√2, just like you would ⅚ and not 0,8333... in both cases you preserve the exact values. Decimal (or any other numbering system, really) approximations are only useful when you never want to do any further arithmetic with the result.
> Decimal (or any other numbering system, really) approximations are only useful when you never want to do any further arithmetic with the result.

What? The opposite is the case. Anything you want to do something with, you can only measure inaccurately; arithmetic doesn't have any use if you can't apply it to inaccurate measurements. That's what we use it for!

So I take it you never wrote any numerical simulations or did symbolic calculations then?

Catastrophic cancellation and other failures are serious issues to consider when doing numerical analysis and can often be avoided completely by using symbolic calculation instead. You can easily end up with wrong results, especially when composing calculations. This would make it difficult to, for example, match your theoretical model against actual measurement results; particularly if the model includes expressions that don't have closed-form solutions.