> On Aug. 6, 2009, Mario Maio wrote:
> ---------------------------
> I hope this is not too much a trivial question, I'm a newbie to Maxima.
> I'd
> like to rearrange expressions like this
>
> (3*cos(d1)^3-3*cos(d2)^3)*x
>
> or this
>
> (3*a*b1-3*a*b2)*x
>
> into a simpler form with collected terms;
>
> 3*(cos(d1)^3-cos(d2)^3)*x
>
> 3*a*(b1-b2)*x
>
>
> Is there a solution that works in BOTH cases ?
--------------------------------------------------------------------------------------
> use fac * ev( expr/fac, ratsimp )
>
> (%i1) display2d:false$
>
> (%i2) e1 : x*(A*cos(d1)^3 - A*cos(d2)^3);
> (%o2) x*(cos(d1)^3*A-cos(d2)^3*A)
> (%i3) A*ev (e1/A,ratsimp);
> (%o3) (cos(d1)^3-cos(d2)^3)*x*A
>
> (%i4) e2 : x*(A*a*b1 - A*a*b2);
> (%o4) x*(a*b1*A-a*b2*A)
> (%i5) A*a*ev(e2/(A*a),ratsimp );
> (%o5) a*(b1-b2)*x*A
>
>
> -----------
> or maybe simpler:
>
> (%i6) A*ratsimp(e1/A);
> (%o6) (cos(d1)^3-cos(d2)^3)*x*A
> (%i7) A*a*ratsimp(e2/(A*a));
> (%o7) a*(b1-b2)*x*A
>
> Ted
>
----------------------------------------------------------------------------------
The following answers the particular question
(%i1) display2d:false;
(%o1) false
(%i2) (3*cos(d1)^3-3*cos(d2)^3)*x;
(%o2) (3*cos(d1)^3-3*cos(d2)^3)*x
(%i3) facsum(subst([cos(d1)^3=b1,cos(d2)^3=b2],%));
(%o3) -3*(b2-b1)*x
(%i4) subst([b1=cos(d1)^3,b2=cos(d2)^3],%);
(%o4) -3*(cos(d2)^3-cos(d1)^3)*x
If you have a more general case say then I would do as follows
(%i5) (A*cos(d1)^3-A*cos(d2)^3)*x;
(%o5) x*(cos(d1)^3*A-cos(d2)^3*A)
(%i6) facsum(%);
(%o6) -(cos(d2)-cos(d1))*(cos(d2)^2+cos(d1)*cos(d2)+cos(d1)^2)*x*A
(%i7) collecttermsl(expand(%),[A,x]);
(%o7) (cos(d1)^3-cos(d2)^3)*x*A
all rhe best!
V
---------------------------------------------------------------------------------
Thank you so much Ted and Valery for the solutions found. Unfortunately
they presuppose that I know in advance the exact form of the expressions
resulting from the computation, which is not my case (sorry if I was not
clear enough). The solution I look for should work for any kind of
expression, trigonometric (cos 2x, cos^2, sin^4, tan^3, and so on) or not.
Basically I need to pull out a number or variable factor from an expression
without incurring in trigonometric or other kind of expansion; a very simple
operation to do by hand (in these cases), but difficult for Maxima, it seems
(I'd like Maxima to do it in order to avoid manual steps that could lead to
errors).
I guess a general solution could have something to do with ratvars and
ratweight, or maybe it's just impossible and a brand new switch should be
implemented such as a 'notrigexpand' that prevented trigonometric expansion
at any level.
Best wishes.
Mario