MathGroup Archive 2002

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

Search the Archive

Re: How to pick all terms which have are multiplied with a factor, e.g., 2


In a message dated 7/13/02 4:26:31 AM, mgi at vt.edu writes:

>I would like to simplify a large symbolic summation. I know that terms
>which 
>are multiplied with a common integer factor can ultimately be combined
>and 
>simplified.
>
>As an example: from the sum
>
>   2 a b^2 c^3 + 13 x y a b + 2 d^-1
>
>I would like to pick 2 a b^2 c^3 + 2 d^-1 to combine them; and similarly
>for 
>other common integer factors. I suspect that patterns would help, but I
>did 
>not manage to devise a correct one.

intFactor[expr_] := Module[{u},
 
      Fold[(Collect[#1 /. #2*se_ -> u*se, u] /. u->#2)&, expr,
        Union[Cases[expr, n_Integer*_ -> n]]]];

expr = 2 a b^2 c^3+13 x y a b+2 d^-1;

{intFactor[expr], Simplify[expr]}

{2*(a*b^2*c^3 + 1/d) + 13*a*b*x*y,
 
  2/d + a*b*(2*b*c^3 + 13*x*y)}

LeafCount /@ %

{21, 20}

expr = 2 a b^2 c^3+13 x y a b+2 d^-1+13z;

{intFactor[expr], Simplify[expr]}

{2*(a*b^2*c^3 + 1/d) + 13*(a*b*x*y + z),
 
  2/d + a*b*(2*b*c^3 + 13*x*y) + 13*z}

LeafCount /@ %

{24, 23}

As measured by LeafCount, Simplify works better.


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: How to pick all terms which have are multiplied with a factor, e.g., 2
  • Next by Date: Re: How to pick all terms which have are multiplied with a factor, e.g., 2
  • Previous by thread: Re: How to pick all terms which have are multiplied with a factor, e.g., 2
  • Next by thread: Re: How to pick all terms which have are multiplied with a factor, e.g., 2