Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Re: How can I force mathematica to collect a symbol from a
Replies: 0

 Alexei Boulbitch Posts: 483 Registered: 2/28/08
Re: How can I force mathematica to collect a symbol from a
Posted: Apr 11, 2013 4:10 AM

Let's say I have a polynomial:
a+b+c
Is there any way I can force mathematica to produce the following result:
a*(1+b/a+c/a)

I think such transformation of polynomials should be very common; however,
I have been trying all day and still can not get mathematica to do so automatically.

Hi,

It is my personal opinion, that one of few real drawbacks Mathematica has, is that the canonical Mathematica program has no function to make a factor of a customer's choice out of the parentheses. As well as few other functions of such a sort, to enable one to customize the forms of analytical expressions. I impatiently wait for such additional functions for already more than 10 years and strongly hope that the developers will one day take this opinion into account, soon, rather than late.

However, here is one way to do what you need:

expr1 = a + b + c;

Now let us substitute b -> x*a and c -> y*a and take a out of the parentheses:

expr2 = a + b + c /. {b -> x*a, c -> y*a} // Factor
a (1 + x + y)

Now let us substitute back. Here instead of the substitution x->b/a and y->c/a one should, however, put x -> HoldForm[b/a], y -> HoldForm[c/a] in order to prevent Mathematica simplifying the result on the spot:

expr3 = expr2 /. {x -> HoldForm[b/a], y -> HoldForm[c/a]}

a (1 + b/a + c/a)

If the expression in this form is your final aim, that's it. In this case you might also use Defer in the place of the HoldForm.

If, however, you are going to use this expression for further analytical operations, you might need the parts b/a and c/a not to be held further. This can be achieved by application of ReleaseHold to it:

expr4 = expr3 // ReleaseHold

a (1 + b/a + c/a)

Note that it may be done also on a later step of your calculations, if needed.
To check that ReleaseHold indeed makes its parts free from being held, let us apply Simplify to the result and see, what happens:

Simplify[expr4]

a + b + c

That's it, therefore.

There is, however, another, much better way for doing such things.

There is a package written by David Park entitled "Presentations" (you may have a look at it here: http://home.comcast.net/~djmpark/Mathematica.html). This package contains a part called Manipulations. The latter part contains a function FactorOut that in one line does the job you asked for. In addition Manipulations part has several other functions that enable one to transform analytical expressions and their parts very much the same way one is accustomed to do it on the paper.

I personally think that it is a must to have this package, I use it to reinforce Mathematica on the everyday basis and strongly recommend it to everyone interested.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu