Re: Interesting failure of Collect
- To: mathgroup at smc.vnet.net
- Subject: [mg61340] Re: Interesting failure of Collect
- From: albert <awnl at arcor.de>
- Date: Sun, 16 Oct 2005 00:17:56 -0400 (EDT)
- References: <dipqve$hdt$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Jerry, > Given the expr = Sin[p]/(4 Pi a) + Sin[p]/(4 Pi b) > ... > 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"..... From the usage message of Collect: Collect[expr, x] collects together terms involving the same powers of objects matching x. I think this is the usual problem with pattern matching which does not know anything about mathematics but analyzes structure only. When you look at the expressions in FullForm you will see that there appear only Rational[1,4] in expr vs. additional Rational[-1,4] in expr2. These are not considered matching the same pattern x, in your case Sin[p]/(4 Pi), which is in FullForm: Times[Rational[1,4],Power[Pi,-1],Sin[p]] So I think it is not a bug, just the usual pattern matching oddity. A workaround would need to avoid the appearance of Rationals in the second arcument, e.g.: expr2 = Sin[p]/(4 Pi a) - Sin[p]/(4 Pi b) Collect[ expr2 /. {Pi -> piTimes4/4} , Sin[p]/piTimes4] /. piTimes4 -> 4Pi Usually transformations of symbolic expressions are easier and more efficient if you collect common prefactors as shown above. Other possibilities to avoid the Rational in the second argument in Collect might be better suited for your specific problem, though. hth albert