[Maxima] rearranging and collecting terms
reyssat
eric.reyssat at math.unicaen.fr
Thu Aug 6 11:42:40 CDT 2009
Valery Pipin a écrit :
> Hi,
>
>
>>> 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 ?
>>>
>>> Factor or facsum work for the 2nd expression but lead to unwanted
>>> trigonometric expansion in the 1st expression.
>>>
>>>
> 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
>
Just two related remarks, no answer to the question :
1/ collecttermsl doesn't seem to be documented although collectterms is
(Maxima version: 5.17.1).
2/ sometimes radcan gives good results to "visually" simplify
expressions, but it may be very hard to predict (the documentation
doesn't say what it does, only gives some properties). For instance :
(%i44) radcan((3*a*b1-3*a*b2)*x);
(%o44) (3 a b1 - 3 a b2) x
(%i45) radcan((3*c*b1-3*c*b2)*x);
(%o45) (3 b1 - 3 b2) c x
This is an effect of the ordering of variables : b1 and b2 come after a
and after the constant 3 but before c, so c is factored out but neither
a nor 3.
I would be glad to know if radcan can be reliably used for anything else
than testing if an expression is 0 (even in this case which class of
expressions is safe ?).
Eric Reyssat
More information about the Maxima
mailing list