Re: How to use "Apply" to do differentiation ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg114456] Re: How to use "Apply" to do differentiation ?*From*: Achilleas Lazarides <achilleas.lazarides at gmx.com>*Date*: Sun, 5 Dec 2010 21:49:10 -0500 (EST)

Trace does show you what happened: Apply replaces the head of its second argument by the first. In this case, it replaces Power in Power[x,5] by D[#, x] & (the second step in the trace). So if instead of D[#,x]& you had eg Print[#1,#2]&, it would have printed x5 because that is what Print[x,5] does. The point is that it does not give you a message to the effect that your anonymous function has too many arguments in the second step in the trace; it just silently drops the second argument. This is what anonymous functions in Mathematica seem to do: silently drop extra arguments (I have no idea if this is good, bad, neutral, accidental etc). So basically you are evaluating (D[#1, x] & )[x, 5] which drops the second argument and differentiates x. On Dec4, 2010, at 1:16 PM, Mayasky wrote: > > Something simple yet unbelievable occurred when I use: > > Apply[D[#, x] &, x^5] > > The output is invariably 1 whether I use x^5 or x^100. > Also I suggest you to try "Trace" command to see > the weirdness -- the output is messy if pasted as > text here. > > Finally I have to take a detour and use: > Nest[D[#, x] &, x^5, 1] > > I have been using Mathematica for several years and > never found that. I myself is wordless, but can anyone > explain that?