Re: Sin*Cos + Log

*To*: mathgroup at smc.vnet.net*Subject*: [mg113236] Re: Sin*Cos + Log*From*: Sam Takoy <sam.takoy at yahoo.com>*Date*: Wed, 20 Oct 2010 04:06:59 -0400 (EDT)

Thank you! Very educational. So to recap a small portion of it: as Times and Plus are defined now, f = Sin*Cos + Log is a largely useless expression that's you can't do much with. Thanks again, Sam ________________________________ From: Andrzej Kozlowski <akoz at mimuw.edu.pl> To: Sam Takoy <sam.takoy at yahoo.com> Cc: mathgroup at smc.vnet.net Sent: Tue, October 19, 2010 12:47:51 PM Subject: [mg113236] Re: [mg113215] Sin*Cos + Log Well, I can see three ways to go about this. One, which is convenient but perhaps carries some risks, is to redefine Plus and times so that they work as ring operations on functions. You can do it as follows: Unprotect[Plus, Times]; (f_ + g_)[x_] := f[x] + g[x] (c_?NumericQ f)[x_] := c f[x] (f_*g_)[x_] := f[x]*g[x] Protect[Plus, Times]; Then (Sin-2Cos*Log + Identity)[x] x + Sin[x] - 2*Log[x]*Cos[x] (You can add rules for powers too). Another possible approach is based on judicious use of Through. For example, in your example this works: (Through[#1, Times] & ) /@ Through[(Sin*Cos + Log)[x], Plus] Log[x] + Sin[x]*Cos[x] However, it's harder to make this work with expressions such as Sin*Cos - 2 Log. The third approach involves more typing. Simply, instead of f=Sin*Cos+Log, built a "pure function": f = (Sin[#]*Cos[#] - 2 Log[#]) &; then simply f[x] Sin[x]*Cos[x] - 2*Log[x] Andrzej Kozlowski On 19 Oct 2010, at 11:54, Sam Takoy wrote: > Hi, > > I'm working on a project that involves manipulating lots of functions. > It would be much easier if I could manipulate functions without > evaluating them and then evaluate them at the end. To this end, is there > a way to endow > > f = Sin*Cos + Log > > with meaning and then somehow evaluate > > f[x]? > > Many thanks in advance, > > Sam >