How to avoid cumulative rounding errors when calculating a result to a specific number of significant...












0












$begingroup$


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?










share|cite|improve this question











$endgroup$












  • $begingroup$
    You might be interested in propagation of uncertainty
    $endgroup$
    – Christoph
    Dec 9 '18 at 18:13
















0












$begingroup$


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?










share|cite|improve this question











$endgroup$












  • $begingroup$
    You might be interested in propagation of uncertainty
    $endgroup$
    – Christoph
    Dec 9 '18 at 18:13














0












0








0





$begingroup$


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?










share|cite|improve this question











$endgroup$




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?







rounding-error significant-figures






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 9 '18 at 17:34







rtheunissen

















asked Dec 9 '18 at 17:13









rtheunissenrtheunissen

589




589












  • $begingroup$
    You might be interested in propagation of uncertainty
    $endgroup$
    – Christoph
    Dec 9 '18 at 18:13


















  • $begingroup$
    You might be interested in propagation of uncertainty
    $endgroup$
    – Christoph
    Dec 9 '18 at 18:13
















$begingroup$
You might be interested in propagation of uncertainty
$endgroup$
– Christoph
Dec 9 '18 at 18:13




$begingroup$
You might be interested in propagation of uncertainty
$endgroup$
– Christoph
Dec 9 '18 at 18:13










1 Answer
1






active

oldest

votes


















1












$begingroup$

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.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:26










  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:29










  • $begingroup$
    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
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 17:35












  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:38








  • 1




    $begingroup$
    @Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 18:25











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3032627%2fhow-to-avoid-cumulative-rounding-errors-when-calculating-a-result-to-a-specific%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1












$begingroup$

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.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:26










  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:29










  • $begingroup$
    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
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 17:35












  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:38








  • 1




    $begingroup$
    @Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 18:25
















1












$begingroup$

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.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:26










  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:29










  • $begingroup$
    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
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 17:35












  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:38








  • 1




    $begingroup$
    @Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 18:25














1












1








1





$begingroup$

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.






share|cite|improve this answer











$endgroup$



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.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Dec 9 '18 at 17:47

























answered Dec 9 '18 at 17:23









Ross MillikanRoss Millikan

293k23197371




293k23197371












  • $begingroup$
    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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:26










  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:29










  • $begingroup$
    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
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 17:35












  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:38








  • 1




    $begingroup$
    @Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 18:25


















  • $begingroup$
    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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:26










  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:29










  • $begingroup$
    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
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 17:35












  • $begingroup$
    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.
    $endgroup$
    – rtheunissen
    Dec 9 '18 at 17:38








  • 1




    $begingroup$
    @Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
    $endgroup$
    – Ross Millikan
    Dec 9 '18 at 18:25
















$begingroup$
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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
$endgroup$
– rtheunissen
Dec 9 '18 at 17:26




$begingroup$
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." graylab.jhu.edu/courses/540.202/docs/Significant_Figures.pdf Is that wrong?
$endgroup$
– rtheunissen
Dec 9 '18 at 17:26












$begingroup$
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.
$endgroup$
– rtheunissen
Dec 9 '18 at 17:29




$begingroup$
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.
$endgroup$
– rtheunissen
Dec 9 '18 at 17:29












$begingroup$
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
$endgroup$
– Ross Millikan
Dec 9 '18 at 17:35






$begingroup$
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
$endgroup$
– Ross Millikan
Dec 9 '18 at 17:35














$begingroup$
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.
$endgroup$
– rtheunissen
Dec 9 '18 at 17:38






$begingroup$
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.
$endgroup$
– rtheunissen
Dec 9 '18 at 17:38






1




1




$begingroup$
@Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
$endgroup$
– Ross Millikan
Dec 9 '18 at 18:25




$begingroup$
@Christoph: you are correct for absolute error, but OP asked about maintaining significant figures.
$endgroup$
– Ross Millikan
Dec 9 '18 at 18:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3032627%2fhow-to-avoid-cumulative-rounding-errors-when-calculating-a-result-to-a-specific%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sphinx de Gizeh

Dijon

Guerrita