({{, (RefLink[NumericFunction, paclet:ref/NumericFunction])
is an attribute that can be assigned to a symbol f to indicate that f[(Subscript[arg, 1]),(Subscript[arg, 2]),…] should be considered a numeric quantity whenever all the (Subscript[arg, i]) are numeric quantities. }})

OpenersNotesSection(Spacer1)Details

Most standard built-in mathematical functions have the attribute (RefLink[NumericFunction, paclet:ref/NumericFunction]).

(RefLink[NumericQ, paclet:ref/NumericQ]) checks the (RefLink[NumericFunction, paclet:ref/NumericFunction]) attribute of every function it encounters.

If you assign the attribute (RefLink[NumericFunction, paclet:ref/NumericFunction]) to a function that does not yield numerical values, then (RefLink[NumericQ, paclet:ref/NumericQ]) will give misleading results.

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

(RefLink[Log, paclet:ref/Log]) has the (RefLink[NumericFunction, paclet:ref/NumericFunction]) attribute:

Attributes[Log]

When (RefLink[Log, paclet:ref/Log]) has an argument that is a number, constant, or numeric, the result is numeric:

NumericQ[Log[2]]

In most cases when (RefLink[NumericQ, paclet:ref/NumericQ])[expr] gives (RefLink[True, paclet:ref/True]), then (RefLink[N, paclet:ref/N])[expr] yields an explicit number:

N[Log[2]]

OpenersExampleSection1(Spacer1)Scope  (2)

Define f to be a numeric function:

SetAttributes[f,NumericFunction]

If you have not assigned f to yield numerical values, then (RefLink[NumericQ, paclet:ref/NumericQ]) gives misleading results:

NumericQ[f[2]]

N[f[2]]

Assign f to evaluate for arguments that are approximate numbers:

f[x_?InexactNumberQ]:=Precision[x]-Accuracy[x]

N[f[2]]

The system symbols that are numeric functions:

Select[Names["System`*"], MemberQ[Attributes[#], NumericFunction]&]

OpenersExampleSection2(Spacer1)Applications  (1)

Define a function that can represent an exact value:

SetAttributes[f,NumericFunction];

Assign (RefLink[N, paclet:ref/N])[f[a]] to give the derivative with respect to a of the solution of an ODE at t=1:

N[f[a_],{prec_, acc_}]:=Block[{x,t,wp=If[prec==MachinePrecision,prec,2*prec]},First[xa[1]/.NDSolve[{x''[t]+Sin[a x[t]]==0,xa''[t]+x[t]Cos[a x[t]]==0,x[0]==1,x'[0]==xa[0]==xa'[0]==0},{x,xa},{t,0,1},WorkingPrecision->wp,Method->"Extrapolation"]]]

Assign f for approximate numbers:

f[a_?InexactNumberQ]:=Block[{x,t},First[xa[1]/.NDSolve[{x''[t]+Sin[a x[t]]==0,xa''[t]+x[t]Cos[a x[t]]==0,x[0]==1,x'[0]==xa[0]==xa'[0]==0},{x,xa},{t,0,1},WorkingPrecision->Precision[a],Method->"Extrapolation"]]]

f[1] does not evaluate but represents a number:

{f[1],NumericQ[f[1]]}

N[f[1]]

It will work with any precision (within reasonable limits!):

N[f[1],32]

A plot of the function:

Plot[f[a],{a,0,10}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NumericQ, paclet:ref/NumericQ])  ▪  (RefLink[NHoldAll, paclet:ref/NHoldAll])  ▪  (RefLink[N, paclet:ref/N])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Attributes, paclet:tutorial/Attributes])}, {▪(RefLinkPlain[Numeric Quantities, paclet:tutorial/NumericQuantities])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Attributes, paclet:guide/Attributes])}})}})