# How are Accuracy and Precision related Mathematica for a given operation?

The common understanding for Accuracy and Precision in English language is given by this figure. Inspired by this question I have a follow up question relating Accuracy and Precision in Mathematica and Wolfram language.

How do we understand the relationship between Accuracy and Precision in the following example?

Accuracy[
SetPrecision[
SetAccuracy[
12.3
, 20], 15]
]

13.9101

Precision[
SetAccuracy[
SetPrecision[
12.3
, 20], 15]
]

16.0899


Where is this 13.9101 and 16.0899 coming from, exactly.

Given an operation, such as Subtract, Plus or Times.

How do we predict the Accuracy and Precision of the outcome?

Precision[
Times[
SetPrecision[10, 3] ,
SetPrecision[1, 7]
]]

2.99996

Precision[
Plus[
SetPrecision[10, 3] ,
SetPrecision[1, 7]
]]

3.04139

Accuracy[
Plus[
SetAccuracy[10, 3] ,
SetAccuracy[1, 7]
]]

2.99996

Accuracy[
Times[
SetAccuracy[10, 3] ,
SetAccuracy[1, 7]
]]

2.99957

• Given an approximate number nonzero number x with an uncertainty dx, then according to the docs, Accuracy[x], Precision[x] and dx are related as follows: Accuracy is -Log[10,dx] and Precision is -Log[10,dx/x]. Propagated error is computed according to the usual rules, I think. Sep 19 '17 at 17:52
• Look up RealExponent. Accuracy and Precision are not independent, and their relationship depends on the size of the number. Since they are not independent, it makes no sense to stack them as you suggest in your comment above. Sep 19 '17 at 17:57
• The uncertainty dx is the same, whether determined from Accuracy or Precision, no? Sep 19 '17 at 18:00
• Ah, perhaps I should have said "Given a number x with a given precision, then the accuracy, precision and uncertainty dx are related as follows...." In the internal representation of nonzero real numbers, it is the precision that is stored or specified. Sep 19 '17 at 18:07

## Precision is the principal representation of numerical error

Except for numbers that are equal to zero, error in arbitrary-precision numbers is stored internally as its precision. For numbers equal to zero, the accuracy is stored, because the precision turns out to be undefined (even if Precision[zero] is defined). One way to view zeros are as a form of Underflow[] for arbitrary precision numbers, which I will explain below.

For a nonzero number $x$ with precision $p$, the error bound $dx>0$ and accuracy $a$, as defined by Precision and Accuracy, are related as follows: $$p = - \log_{10} |dx / x| \,, \quad a = - \log_{10} dx\,.\tag{1}$$ An arbitrary-precision number $x$ represents a real number $x^*$ in the interval $$x - dx < x^* < x + dx\,.$$

## Accuracy and Precision are related though RealExponent

The relation between Accuracy and Precision is given by

RealExponent[x] + Accuracy[x] == Precision[x]


Therefore, as RealExponent[12.3]-> 1.08991 then Accuracy[SetPrecision[12.3, 15]] must be 15 - 1.08991 -> 13.9101

Similarly, Precision[SetAccuracy[12.3, 15]] is 15 + 1.08991 -> 16.0899.

## Operations

To get the Accuracy after an operation, we just need to distribute the errors.

The error of Times[a, b] is

ExpandAll[(a + δa) (b + δb) - a b]

 b δa + a δb + δa δb


where Accuracy[a] -> -Log10[δa].

## Numerical example

y = SetAccuracy[10, 3];
z = SetAccuracy[1, 7];
Accuracy[y z]

2.99957

N[-Log10[
b δa + a δb + δa δb
]] /. {
a -> y,
b -> z,
δa -> Power[10, -3],
δb -> Power[10, -7]
}

 2.99957
`