MathGroup Archive 1993

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

Search the Archive

Re: Distribute

  • To: mathgroup at
  • Subject: Re: Distribute
  • From: Frank Zizza <zizza at>
  • Date: Sat, 6 Mar 93 09:35:09 -0800

[I have combined all the responses to the original message into
one since most of the answers are similar. - steve c, moderator]

1) >I have a function that I want to be additively distributive.  The
>standard way for doing this
>But this is a problem when distributing over long sums, because it
>leads to Recursion errors.  Mathematica has a command Distribute, but
>if I just say
>I am immediately in a loop.  Thus, the simplest way I can see to use
>it in this situation is
>Is there way to do this without the introduction of a temporary
>variable?  Thanks in advance.
>                - Ian Robertson
>                  Oberlin College
>                 iroberts at

Add the rule
f[S_Plus] := f /@ S
to the end of the definitions you have made for f.
Here's an example:

Mathematica 2.1 for NeXT
Copyright 1988-92 Wolfram Research, Inc.
 -- NeXT graphics initialized --

In[1]:= f[S_Plus] := f /@ S

In[2]:= f[a+b+c]

Out[2]= f[a] + f[b] + f[c]

Frank Zizza
Willamette University
Salem, OR 97301
zizza at

2) From: tgayley at (Todd Gayley)

How about this:

f[x_Plus] := f /@ x

Todd Gayley

3) From: John Lee <lee at>

Here is a simple solution, which avoids recursion:

  In[1]:= f[x_Plus] := f /@ x;

  In[2]:= f[a + b + c + d + e]

  Out[2]= f[a] + f[b] + f[c] + f[d] + f[e]

Jack Lee
Dept. of Mathematics
University of Washington
Seattle, WA

4) From: reiszig at

sb. asked how to define a function to be additive (orig. mail see
The simplest way I know is:
f[x_Plus] := Map[f,x]
(use level specific. for special effects)
If needed, use in addition:
f[x_Plus y_] := f[ Expand[x y]]

G.Reiszig, Dresden, 8 Mar 93

5) From: wmm at (Martin McClain)

At the top of your script, write
        SetAttributes[Distribute, HoldAll]
Now Distribute will work the way you want.  Of course, this may introduce
undesirable behaviour in other aspects of your problem.  If it does, define
another  operator identical to Distribute and give it the HoldAll

  • Prev by Date: ContourSmoothing - changed in v2.1 ?
  • Next by Date: NonlinearFit
  • Previous by thread: Distribute
  • Next by thread: Integrate