Introductory remark: I take it (from Mathematica's online documentation), that Precision
is effectively the number of significant digits, as seen by the system.
- For literals, precision is set using backquotes, e.g.
2.501`1
, which yields a3.
. CallingPrecision
on this result gives1
, as expected. On the other hand, there is
Round
, which, well, rounds according to the unbiased next-to-even-scheme, e.g.:$\quad \quad $
Round[{2.501, 3.501, 2.401, 3.401, 2.5, 3.5, 2.4, 3.4}]
gives the integers
$\quad \quad $
{3, 4, 2, 3, 2, 4, 2, 3}
But:
$\quad \quad ${2.501`1, 3.501`1, 2.401`1, 3.401`1, 2.5`1, 3.5`1, 2.4`1, 3.4`1}
yields an unexpected difference at the 5th position:
$\quad \quad ${3., 4., 2., 3., 3., 4., 2., 3.}
So, specifying a precision explicitly (which should be a number of significant digits, according to documentation), gives different results than rounding the same literals to the same number of significant digits.
While the explicit precision statement `
does show the number rounded, its method is not next-to-nearest-even, but the biased next-to-larger-absolute (i.e. "up-from-0.5").
My question therefore is:
Did I miss some of the intricacies of the assorted norms or should Mathematica round the same, regardless of how the number of significant digits is specified (Round
or `1 (* or more, according to magnitude before the decimal separator *)
)?
Further findings
2.5`1*2.`1
results in a displayed 0
with Precision
yielding not 1
, as expected, but 0.69897
. Checking further using
{#, Round[#], Accuracy[#], Precision[#]}&/@{2.5`1, 2.`1, 2.5`1+2.`1, 2.5`1*2.`1}
which leads to
$$ \begin{array}{cccc} \bf input& \bf output& \bf Round&\bf Accuracy&\bf Precision\\ 2.5`1& 2. & 2 & 0.60206 & 1. \\ 2.`1& 2. & 2 & 0.69897 & 1. \\ 2.5`1+2.`1& 4. & 4 & 0.346787 & 1. \\ 2.5`1*2.`1& 0. & 5 & 0. & 0.69897 \\ \end{array} $$
adds to my confusion about the semantics of significant digits in Mathematica.
Reference: NumericalPrecision
Extension/Background for the Question
The reason for me asking this question is, that I wanted to implement calculations with Mathematica, which obey the rule, that any (final) results shall be displayed with the minimum number of significant digits of all values/measurements used as input.
After consulting the documentation, I thought, that setting an input value's precision explicitly would have been the key to this.
Now, however, I am at a loss, since
- the rounding behavior of the frontend differs from
Round
- arithmetic operations like multiplications change the precision of the result in forseeable, but practically less usable ways.
Obviously, I will have to turn to the hard way and track the number of significant digits myself and round as appropriate using
Round
.
Round
is using guard digits, so the ones ending.501`1
will round up whereas the ones with.5`1
will round to even. $\endgroup$Round[]
respects the rounding rules "nearest-to-even" of IEEE 754 (used quite everywhere), while the backtick (aka Precision) does not, albeit in the same application. It looks like a bug to me, since significance is dealt with differently with respect to rounding. $\endgroup$2.5`1
as a3.
. The value is still2.5`1.
. One might still consider it a bug (or at least inconsistent), and typesetting is important (for printing reports, say). $\endgroup$