# Why N is not affecting the rest of Power, but not NHoldRest is set?

Posted 1 year ago
2227 Views
|
2 Replies
|
6 Total Likes
|
 Dear all,I'm surprised why "N" is not affecting all parameters of "Power", even "Power" has not the attribute "NHoldRest"? Is this feature documented somewhere, or is it a bug?Input: Attributes[Power] SetAttributes[myPower, Attributes[Power]] Power[x, 2] //N //FullForm Power[2, y] //N //FullForm myPower[x, 2] //N //FullForm myPower[2, y] //N //FullForm Result: {Listable, NumericFunction, OneIdentity, Protected} Power[x, 2] Power[2., y] myPower[x, 2.] myPower[2., y] Mathematica 10.0.2 (x64), Windows 7
2 Replies
Sort By:
Posted 1 year ago
 I don't see why this should be called a bug. The behaviour is exactly as it should be, although it is not achieved through NHoldRest, but through other means.Why is it not achieved through NHoldRest? I don't know, but the most reasonable guess is that there are cases where a naïve use of NHoldRest would cause behaviour that seems unreasonable from a mathematical perspective. Let us try to find such a case.It seems to me that the following would be such a case: In[]:= N@Power[x, Power[2, y]] Out[]= x^2.^y More generally, Power[x, f[someExplicitNumber]] would be such a case, e.g. Power[x, Sin[2]].Why treat Sin[2] differently from 2? Well, x^2 is x*x. The same is not valid for x^2.0. Thus there is value in retaining the exact 2 in x^2. More importantly, retaining integer powers in polynomial expression would seem essential.What about rational powers? One would expect N@Sqrt[x] to stay Sqrt[x] and not turn into x^0.5.The same does not apply to something like x^Sin[2].
 I'm not sure if this is documented, But I guess you have to interpet x^2 as x*x indeed. If you want to force it you could do: x^(5/2) MapAt[N, %, -1] giving: x^2.5 `Also: I think that N tries to evaluate the entire expression to an approximate number, not necessarily all the subexpressions.