       Re: Interesting failure of Collect

• To: mathgroup at smc.vnet.net
• Subject: [mg61337] Re: Interesting failure of Collect
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sun, 16 Oct 2005 00:17:53 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <dipqve\$hdt\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Blimbaum, Jerry CIV NSWC PC wrote:
> Given the expr =  Sin[p]/(4 Pi a) + Sin[p]/(4 Pi b)
>
> and then applying the command
>
>
> Collect[expr, Sin[p]/(4 Pi)] works as it should, however,
>
> expr2 = Sin[p]/(4 Pi a) - Sin[p]/(4 Pi b)
>
> leaves the expression untouched.   (I realize I could use Simplify but
> this problem occurred on a much longer expression and this is intended
> just to convey the basic idea)....for longer expressions the Collect
> process works for all quantities with a + sign but the one with a minus
> sign will not be collected.....strikes me as a "bug".....
>
>
> thanks....jerry blimbaum
>
>
Hi Jerry,

I have got the same behavior with Mathematica 5.2 for Windows XP (see
below). One workaround is to add -- or more precisely to replace the
negative sign by -- an additional parameter, say c, as in the following
example, and to use a replacement rule to change the parameter c by -1.
*Collect* seems to work correctly in this case.

In:=
expr = Sin[p]/(4*Pi*a) + Sin[p]/(4*Pi*b)

Out=
Sin[p]/(4*a*Pi) + Sin[p]/(4*b*Pi)

In:=
Collect[expr, Sin[p]/(4*Pi)]

Out=
((1/a + 1/b)*Sin[p])/(4*Pi)

In:=
expr2 = Sin[p]/(4*Pi*a) - Sin[p]/(4*Pi*b)

Out=
Sin[p]/(4*a*Pi) - Sin[p]/(4*b*Pi)

In:=
Collect[expr2, Sin[p]/(4*Pi)]

Out=
Sin[p]/(4*a*Pi) - Sin[p]/(4*b*Pi)

In:=
expr3 = Sin[p]/(4*Pi*a) + c*(Sin[p]/(4*Pi*b))

Out=
Sin[p]/(4*a*Pi) + (c*Sin[p])/(4*b*Pi)

In:=
Collect[expr3, Sin[p]/(4*Pi)] /. c -> -1

Out=
((1/a - 1/b)*Sin[p])/(4*Pi)

In:=
\$Version

Out=
"5.2 for Microsoft Windows (June 20, 2005)"

Best regards,
/J.M.

```

• Prev by Date: Re: Re: Compile nested loops with depending index variables...
• Next by Date: Re: problem solving polynomial equations
• Previous by thread: Re: Interesting failure of Collect
• Next by thread: surface fitting question