0

I have two operands and I want to calculate the result of an arithmetic operation (add, sub, mul, div, pow, sqrt, ln...) to S significant figures. How many significant figures do I need in the operands to achieve this result without rounding of the least significant digit?

For example, let's consider a context of "always accurate to 2 significant figures".

0.123 * 0.456 = 0.056088, rounded to 0.056 (2 s.f).

If we keep using that result for future calculations within this context, we'll get rounding errors because we've lost data along the way. My question is: could I avoid rounding errors in the current context by calculating the result to precision + x?

For example, with the same context (always accurate to 2 s.f), we can calculate to 4 s.f:

0.123 * 0.456 = 0.056088, rounded to 0.05609. Could I now use this result without losing accuracy along the way? Or would the rounding inevitable cause inaccuracy?

1 Answers1

1

There is no answer. Subtraction makes it easy to see. If you want to subtract $1.0000000-0.9999999$ to two significant figures you need to carry a lot of figures. For multiplication and division the problem comes from the fact that a chance of $1$ in the third place is a chance of $1\%$ in $1.00$ but $0.1\%$ in $9.99$. The fractional error is maintained with multiplication and division. Functions like pow and log are also problematic.

Added: even worse, $\frac 1x-\frac 2{x+1}+\frac 1{x+2}$ is about $\frac 2{x^3}$ for large $x$. If $x \approx 1000$ you need to keep $11$ places to get $2$ places out at the end. We can keep going like this.

Ross Millikan
  • 383,099
  • 1
    Wikipedia states to "keep as many digits as is practical (at least 1 more than implied by the precision of the final result) until the end of calculation to avoid cumulative rounding errors." https://graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf

    Is that wrong?

    – rtheunissen Dec 09 '18 at 17:26
  • What if you use something like MAX(op1.precision, op2.precision) + 1? In the case you mentioned, that would be MAX(8, 7) + 1, ie. calculated to 9 significant figures to avoid cumulative rounding errors. – rtheunissen Dec 09 '18 at 17:29
  • I can design even more pathological cases that break that. $\ln x$ for $x$ near zero will be hard. More extra places is better because errors become rarer, but you can’t eliminate them – Ross Millikan Dec 09 '18 at 17:35
  • If that rule works for +,-,*,/,%, and a different rule is required for ln, that would be acceptable. If such a rule is possible, I would like to find out what it is. – rtheunissen Dec 09 '18 at 17:38
  • See my added example, that just uses arithmetic and points the way to make it as bad as you want. – Ross Millikan Dec 09 '18 at 17:48
  • Knowing $a$ and $b$ up to an error of at most $\varepsilon$, the difference $a-b$ is known up to an error of at most $2\varepsilon$. So if you round $a,b$ to $3$ significant figures ($\varepsilon=10^{-3}/2$) then rounding the correct $a-b$ to $2$ decimals and rounding the difference of the rounded values to $2$ decimals will give the same result, right? – Christoph Dec 09 '18 at 18:00
  • @Christoph: no, look at my first example. The problem is that $a-b$ can be much smaller in magnitude than either $a$ or $b$, so $\frac \varepsilon{a-b}$ can be very large. If you round $a$ and $b$ to three or four decimals the difference comes out $0$, which is a huge fractional error. – Ross Millikan Dec 09 '18 at 18:20
  • I misunderstood "significant figures" as "decimal places in an expression without a factor $10^k$", sorry. – Christoph Dec 09 '18 at 18:25
  • 1
    @Christoph: you are correct for absolute error, but OP asked about maintaining significant figures. – Ross Millikan Dec 09 '18 at 18:25
  • 1
    @RossMillikan we're not "rounding to decimal places", we're rounding to significant figures. Magnitude doesn't matter. – rtheunissen Dec 09 '18 at 18:38
  • 1
    @rtheunissen: yes, I believe my examples have followed that. One problem is that addition and subtraction maintain absolute error while multiplication and division maintain relative error. Keeping one extra place for multiplication and division works very well but in addition and subtraction you can get the cancellation I am showing. – Ross Millikan Dec 09 '18 at 18:58
  • The answer to the example when x is 1000 is 2.0e-9, which you can achieve by using 7 significant figures (I think). Knowing that 1001 has 4 significant figures, what about using twice the precision for addition and subtraction? Seems a bit arbitrary though. – rtheunissen Dec 09 '18 at 19:14
  • No, that won't work. The fact that it is cubic in $x$ means you would need three times the number of digits in this computation. $10^n+1 $ has $n+1$ significant digits and we need $3n+$ a few to get a sensible answer out. If we make a version that goes as $x^{-4}$ you would need four times as many and so on. – Ross Millikan Dec 09 '18 at 19:41