       Re: Factoring

• To: mathgroup at smc.vnet.net
• Subject: [mg65117] Re: [mg65069] Factoring
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Wed, 15 Mar 2006 06:28:33 -0500 (EST)
• References: <200603141059.FAA24051@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On 14 Mar 2006, at 11:59, Matt wrote:

> Hello Mathgroup,
>   I'm sure that I've overlooked something obvious, but for the past
> two
> and a half hours, I've been trying to figure out how to use built-in
> Mathematica functions to just factor the imaginary number 'I' out of
> this:
>
> 4*I*r^2*Sin[2*Î¸] + I*r^5*Sin[5*Î¸]
>
> using Factor[] gives me I*r^2*(4*Sin[2*Î¸] + r^3*Sin[5*Î¸])
>
> using FactorTerms[] gives me I*(4*r^2*Sin[2*Î¸] + r^5*Sin[5*Î¸]) which
> is what I want, but as soon as I add in a common numerical factor, it
> also factors that out as well,
>
> e.g. 4*I*r^2*Sin[2*Î¸] + 8*I*r^5*Sin[5*Î¸]
>
> I finally just decided to divide the whole thing by 'I', and do some
> reconstruction of my expression, but I have the distinct feeling I've
> totally missed something very simple.  As an additional example, what
> if I just wanted to extract 2*x*I out of the following:
>
> 4*x*I*Sin[t] + 28*x^3*I*Cos[t]
>
> how would I do that?  In general, I'm looking for a function that says
> "Given an expression 'expr' and another expression 'sub' that is
> common
> to all additive terms of 'expr', give a result that is the product of
> 'sub' and the result of factoring 'sub' out of 'expr'".
>
> Thanks,
>
> Matt
>

I think dividing out and then multiplying is the right thing to do,
although "algebraic division" will probably work better than
"arithmetical" one. Here is one way:

FactorOut[expr_, subexpr_] /;
PolynomialReduce[expr,
subexpr][] == 0 :=
PolynomialReduce[expr,
subexpr][[1,1]]*subexpr

Now, taking your example:

FactorOut[28*I*Cos[t]*x^3 +
4*I*Sin[t]*x, x*I*2]

2*I*x*(14*Cos[t]*x^2 +
2*Sin[t])

while

FactorOut[28*I*Cos[t]*x^3 +
4*I*Sin[t]*x, x^2]

FactorOut[28*I*Cos[t]*x^3 +
4*I*Sin[t]*x, x^2]

returns the original input. Of course one could change the latter
behaviour if a different one was desired.

Andrzej Kozlowski

```

• References:
• Factoring
• From: "Matt" <anonmous69@netscape.net>
• Prev by Date: Re: laplace transform
• Next by Date: Re: Factoring
• Previous by thread: Factoring
• Next by thread: Re: Factoring