Function Repository Resource:

EffectivePrecision

Source Notebook

Get the effective precision of an expression

Contributed by: Daniel Lichtblau

ResourceFunction["EffectivePrecision"][expr]

gives the precision of the expression expr, which is a list, equation or similar comprised of numeric subexpressions.

Details and Options

ResourceFunction["EffectivePrecision"] determines the effective numeric precision of an expression, ignoring heads that are not numeric functions, List, equation or inequality heads, and some related heads.

Examples

Basic Examples (2) 

A list with an explicit machine number has effective precision of MachinePrecision:

In[1]:=
ResourceFunction["EffectivePrecision"][{x, 1.}]
Out[1]=

If a machine number appears in an expression with a head that is neither a list, equation, inequality, nor a numeric function, then the effective precision is infinite:

In[2]:=
ResourceFunction["EffectivePrecision"][x[1.]]
Out[2]=

Scope (2) 

EffectivePrecision will return the lowest precision encountered in a mathematical subexpression:

In[3]:=
e = Map[N[#, 5*#] &, Range[5]]
Out[3]=
In[4]:=
ResourceFunction["EffectivePrecision"][e]
Out[4]=

MachinePrecision is contagious insofar as it is considered to be lower than any software float precision:

In[5]:=
ResourceFunction["EffectivePrecision"][Append[e, N[Pi]]]
Out[5]=

Properties and Relations (2) 

EffectivePrecision is intended primarily for mathematical expressions rather than programming language constructs:

In[6]:=
ResourceFunction["EffectivePrecision"][If[x == 3, 1.0, 5]]
Out[6]=

To find the lowest precision in an arbitrary expression one can use Precision:

In[7]:=
Precision[If[x == 3, 1.0, 5]]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 21 February 2019

License Information