Re: Failure to Evaluate?

*To*: mathgroup at smc.vnet.net*Subject*: [mg49843] Re: [mg49842] Failure to Evaluate?*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Wed, 4 Aug 2004 10:46:19 -0400 (EDT)*References*: <200408030511.BAA00239@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

On 3 Aug 2004, at 07:11, Scott Guthery wrote: > > f:=Function[#1^2/#1+1] > > g:=Function[#1^4+7] > > h:=D[f]/D[g] > > h[1] > > Gives > > ((#1^2/#1)+1 &)/(#1^4+7 &)[1] > > Why doesn't it evaluate by setting #1 to 1 to get 1/4? > > h/.#1->1//N sets #1 to 1 and gives > > (1 1 + 1 &)/(1 + 7 &) > > but still doesn't evaluate to 1/4. > > What gives? What's the Right Stuff? > > Thanks for any insight. > > Cheers, Scott > > Mathematica does not implement the algebra of functions so if f an g are a functions, f+g, f*g, and f/g are not. Also, your definition, f=Function[#1^2/#1+1] seems pointless, since this is just Function[#1+1]. Did you mean f=Function[#1^2/(#1+1)]? In addition, there is no point using delayed evaluation in the definitions of f, g and h; the only thing it does is make you code slightly slower. And another thing: what do you think D[f] and D[g] are? Well, whatever you intended they just return f and g. Presumably what you meant was f' and g' (Derivative[1][f],Derivative[1][g])? Anyway, there are two ways to deal with this. One is to unprotected Plus, Times, and Power and overload them to work with functions. I showed how to do this in this list several years ago but it is pretty obvious so I do not want to repeat it. Besides, I do not recommend this approach. A simpler way is simply this: f = #1 + 1 & ; g = #1^4 + 7 & ; h = Function[x, Derivative[1][f][x]/Derivative[1][g][x]]; h[1] 1/4 Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/

**References**:**Failure to Evaluate?***From:*"Scott Guthery" <sguthery@mobile-mind.com>