Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
1 + f[1] // N 


 1. + f[1.]  

I don't want the argument of f evaluated by N; I want to get

1. + f[1]


In general, there is a large algebraic expression containing some subexpressions of type f[__]. N should not be applied inside f. N should be applied only outside.

Mapping N at a certain level only is not OK, since the tree structure of expression is not know in advance.

One possible trick is

1 + f[1] /. x_f :> 1. x + 0. 

It would be good to know other options.

share|improve this question
up vote 15 down vote accepted

The best option then is to bestow the attribute NHold on the head f.

In[2]:= SetAttributes[f, NHoldAll]

In[3]:= 2 + f[Sqrt[2] + 1] // N

Out[3]= 2. + f[1 + Sqrt[2]]
share|improve this answer
In fact there is an example given in the documentation of N which is similar to this one :) – Leo Fang Jul 30 '13 at 22:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.