MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: f + g

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7155] Re: [mg7120] f + g
  • From: jpk at max.mpae.gwdg.de
  • Date: Tue, 13 May 1997 01:57:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

it is not a good idea produce a general simplification like this.
I suggest that You produce two rule sets

opExpand={ (f_+g_)[x_] :> f[x]+g[x], (c_*f_)[x] /; FreeQ[c,x] :> c*f[x]}

opCollect={a_*f_[x_]:> (a*f)[x],f_[x_]+g_[x_] :> (f+g)[x]}

and two functions

OperatorExpand[any_]:=any //. opExpand
OperatorCollect[any_]:= any //. opCollect

That will do what You want with out touching the build in rules and
more over it will do it when You want.

Hope that helps
Jens

> In mathematics, we define the sum f + g of two arbitrary real-valued
> functions f and g (with the same domain) by the rule (f + g)(x) = f(x)
> + g(x), so that, for example, (cos + exp)(0) = 2.  Similarly, for a
> constant c and an arbitrary function f we define the product cf by the
> rule (cf)(x) = c (f(x)).  [Generalizations to other kinds of values
> and to other operations, such as the product of two functions, are
> possible but not of interest to me in this question.)
> 
> My question is:  is there some way directly to express this in
> Mathematica (3.0)?  That is, I would like to input
> 
>    (Cos + Exp)[0]
> 
> and get result 2 -- WITHOUT having to give first a specific rule for
> the sum of that particular pair of functions.  The sort of thing I
> have in mind is a general rule such as
> 
>     (f_ + g_)[x_] := f[x] + g[x]
> 
> but that certainly won't be acceptable to Mathematica (Tag Plus is
> Protected!)
> 
> The only thing I could come up with was:
> 
>    Unprotect[Plus]
>    (f_ + g_)[x_] := f[x] + g[x]
>    Protect[Plus]
> 
> But I find that most unsatisfactory: it seems to me that such a basic,
> common operation in mathematics ought to be directly accessible in "a
> software system for doing mathematics"!
> 
> Any other ways except the above, which I regard as something of a
> kludge?
> 
> --
>   Murray Eisenberg                       Internet:  murray at math.umass.edu
>   Mathematics & Statistics Dept.            Voice:  413-545-2859 (W)
>   University of Massachusetts                       413-549-1020 (H)
>   Amherst, MA 01003                           Fax:  413-545-1801
> 


  • Prev by Date: Re: Iterating NDSolve
  • Next by Date: Re: GUI for Mma
  • Previous by thread: Re: f + g
  • Next by thread: Re OPTICA