[Date Index]
[Thread Index]
[Author Index]
Re: How to pick all terms which have are multiplied with a factor, e.g., 2
*To*: mathgroup at smc.vnet.net
*Subject*: [mg35476] Re: [mg35463] How to pick all terms which have are multiplied with a factor, e.g., 2
*From*: BobHanlon at aol.com
*Date*: Sun, 14 Jul 2002 06:19:53 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
My initial response did not handle negative terms and pure numerical
constants. This should be better:
intFactor[expr_] :=
Module[{u},
Fold[(Collect[#1 /.
{#2*se_. -> u*se, -#2*se_. -> -u*se},
u] /.
u -> #2)&, expr,
Union[Cases[expr, n_Integer*_ -> n]]]];
intFactor[2 a b^2 c^3+13 x y a b+2 d^-1+2-13z]
2*(1 + a*b^2*c^3 + 1/d) + 13*(a*b*x*y - z)
Bob Hanlon
In a message dated 7/13/02 7:02:01 AM, writes:
>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.
>
Prev by Date:
**Re: How to pick all terms which have are multiplied with a factor, e.g., 2**
Next by Date:
**Re: Re: Factoring question**
Previous by thread:
**Re: How to pick all terms which have are multiplied with a factor, e.g., 2**
Next by thread:
**Changing delayed formula**
| |