NHoldRest
Examples
open all close allBasic Examples (1)
Prevent N from affecting all but the first argument of a function:
SetAttributes[f, NHoldRest]N[f[Pi, 3]]N[f[E, Pi], 20]Scope (2)
System symbols with the NHoldRest attribute:
ssymb = Cases[Map[ToExpression, Names["System`*"]], _Symbol];
Select[ssymb, MemberQ[Attributes[#], NHoldRest]&]Use Part symbolically:
e = Quiet[x[[1]] + x[[-1]] - 1]Using N does not affect the specified parts:
ne = Quiet[N[e]]The expression works when x is substituted with a list:
ne /. x -> {2, 4, 8}Applications (1)
Define a function that represents the real-valued root
for positive
and positive integer
:
nthroot[x_ ? InexactNumberQ /; Positive[x], n_Integer /; Positive[n]] := FixedPoint[((n - 1) # ^ n + x) / (n # ^ (n - 1))&, N[1, Precision[x]]]Prevent its second argument from being converted to real using NHoldRest:
SetAttributes[nthroot, NHoldRest]An exact representation of the cube root of 2:
crt = nthroot[2, 3]N[crt]N[crt, 47]Properties & Relations (2)
Subscript by default has the NHoldRest attribute:
Attributes[Subscript]This means that subscripts generally do not change under N:
poly = Sum[(i + 1)Subscript[a, i] x ^ i, {i, 0, 5}]N[poly]HoldRest prevents evaluation while NHoldRest only prevents numerical evaluation:
SetAttributes[f1, HoldRest]f1[1, 2 + 3]N[%]SetAttributes[f2, NHoldRest]f2[1, 2 + 3]N[%]You can prevent both by setting both attributes:
SetAttributes[f, {HoldRest, NHoldRest}]f[1, 2 + 3]N[%]See Also
Tech Notes
Related Guides
History
Introduced in 1996 (3.0)
Text
Wolfram Research (1996), NHoldRest, Wolfram Language function, https://reference.wolfram.com/language/ref/NHoldRest.html.
CMS
Wolfram Language. 1996. "NHoldRest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NHoldRest.html.
APA
Wolfram Language. (1996). NHoldRest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NHoldRest.html
BibTeX
@misc{reference.wolfram_2026_nholdrest, author="Wolfram Research", title="{NHoldRest}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/NHoldRest.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_nholdrest, organization={Wolfram Research}, title={NHoldRest}, year={1996}, url={https://reference.wolfram.com/language/ref/NHoldRest.html}, note=[Accessed: 12-June-2026]}