NHoldAll

NHoldAll

is an attribute which specifies that none of the arguments to a function should be affected by N.

Details

  • NHoldAll, NHoldFirst, and NHoldRest are useful in ensuring that arguments to functions are maintained as exact integers, rather than being converted by N to approximate numbers.

Examples

open allclose all

Basic Examples  (1)

Prevent N from affecting the arguments of a function:

Scope  (3)

System symbols with the NHoldAll attribute:

The arguments of Derivative remain unchanged with N:

N leaves the derivative order while changing the point of evaluation:

Define a pure function:

The function with coefficients converted to numerical values:

The positional parameters remain unchanged with N because Slot has the NHoldAll attribute:

Applications  (2)

Use an indexed variable:

With this attribute, the variables remain unchanged:

Define a data object that represents a polynomial in a sparse form {{c_(1),p_(1)},...}:

Make sure that N only affects the coefficients, not the powers:

Default N evaluation of the argument needs to be prevented for the rule above to work:

A representation of the polynomial :

Get the representation with approximate real coefficients:

Evaluate at :

Properties & Relations  (1)

HoldAll prevents evaluation while NHoldAll only prevents numerical evaluation:

You can prevent both by setting both attributes:

Introduced in 1996
 (3.0)