Discussion:
Collecting Terms
Mike Higgins
2007-07-16 21:00:14 UTC
Permalink
I'm a total neophyte so forgive some beginner questions and
frustrations. I'm using wxMaxima as a front end to Maxsima and I want to
collect terms, at least that's what I call what I want to do. When I
look collectterms up in the wxMaxima help index it tells me that this is
a function for re-arranging forms (whatever they are) that are messed up
by the facexp package (which does something I cannot decipher). That
documentation says the arguments are:
collectterms(arg_1,...,arg_n)
but I was looking for a function with args like:
collectterms(expr,var_1,...,var_n)
To my surprise, if I assume that collectterms does what I want, it
sometimes does! By dumb luck I found that if I expand the expression
first, then collectterms always works! (Well, it has in two cases where
I needed it). I'm happy now but how come the documentation was no help
whatsoever and where do I go the next time I want to do something
different? Here's an example of collecting terms working for me:

((p4-3*p3+3*p2-p1)*T^3+(-p4+4*p3-5*p2+2*p1)*T^2+(p3-p1)*T+2*p2)/2
expand(%)
collectterms(%,p1,p2,p3,p4)
final output:
p2*((3*T^3)/2-(5*T^2)/2+1)+p4*(T^3/2-T^2/2)+p1*(-T^3/2+T^2-T/2)+p3*(-(3*T^3)/2+2*T^2+T/2)

------------------------------------
Code in haste, debug at leisure
Harald Geyer
2007-07-16 23:53:41 UTC
Permalink
Post by Mike Higgins
When I
look collectterms up in the wxMaxima help index it tells me that this is
a function for re-arranging forms (whatever they are) that are messed up
by the facexp package (which does something I cannot decipher).
"re-arranging forms" means that it takes an expression and returns an
other but mathematically equivalent expression.

I think facexp basically does what you want. collectterms() is just a
special (speed optimized) case of that.
Post by Mike Higgins
That
collectterms(arg_1,...,arg_n)
collectterms(expr,var_1,...,var_n)
This is a bug in the documentation. Your description seems appropriate.
Post by Mike Higgins
To my surprise, if I assume that collectterms does what I want, it
sometimes does! By dumb luck I found that if I expand the expression
first, then collectterms always works! (Well, it has in two cases where
I needed it).
I try to rephrase the documentation a bit to explain what's going on:
Consider you have two expressions with collected terms with respect
to the same variables. Now if you just add this two expressions, the
result usually won't have collected terms, but it's quite easy to do
the transformation in this case. That's the job of collectterms().

I think now it is easy to understand, why expand() helps: Each term
in a full expansion is a trivial case of a term collected expression
and thus a full expansion is a valid input for collectterms().

But I assume using other functions from facexp is generally much
faster than collectterms(expand(expr), var_1, ..., var_n);
Post by Mike Higgins
I'm happy now but how come the documentation was no help
whatsoever
There are not enough people like you giving feedback on it.
Post by Mike Higgins
and where do I go the next time I want to do something different?
You are new to maxima, I think you did quite well. If you get to
a weak point of the documentation it will be unavoidable to ask
some questions on this list or get any other peer support.

HTH,
Harald
Richard Fateman
2007-07-17 03:01:43 UTC
Permalink
See if rat(expr, var1,var2,...)
Does what you want.
Or if ratexpand does what you need from expand. If so, ratexpand is much
much faster.
RJF
-----Original Message-----
Sent: Monday, July 16, 2007 4:54 PM
To: Mike Higgins
Subject: Re: [Maxima] Collecting Terms
Post by Mike Higgins
When I
look collectterms up in the wxMaxima help index it tells me
that this is
Post by Mike Higgins
a function for re-arranging forms (whatever they are) that
are messed up
Post by Mike Higgins
by the facexp package (which does something I cannot decipher).
"re-arranging forms" means that it takes an expression and returns an
other but mathematically equivalent expression.
I think facexp basically does what you want. collectterms() is just a
special (speed optimized) case of that.
Post by Mike Higgins
That
collectterms(arg_1,...,arg_n)
collectterms(expr,var_1,...,var_n)
This is a bug in the documentation. Your description seems
appropriate.
Post by Mike Higgins
To my surprise, if I assume that collectterms does what
I want, it
Post by Mike Higgins
sometimes does! By dumb luck I found that if I expand the
expression
Post by Mike Higgins
first, then collectterms always works! (Well, it has in two
cases where
Post by Mike Higgins
I needed it).
Consider you have two expressions with collected terms with respect
to the same variables. Now if you just add this two expressions, the
result usually won't have collected terms, but it's quite easy to do
the transformation in this case. That's the job of collectterms().
I think now it is easy to understand, why expand() helps: Each term
in a full expansion is a trivial case of a term collected expression
and thus a full expansion is a valid input for collectterms().
But I assume using other functions from facexp is generally much
faster than collectterms(expand(expr), var_1, ..., var_n);
Post by Mike Higgins
I'm happy now but how come the documentation was no help
whatsoever
There are not enough people like you giving feedback on it.
Post by Mike Higgins
and where do I go the next time I want to do something different?
You are new to maxima, I think you did quite well. If you get to
a weak point of the documentation it will be unavoidable to ask
some questions on this list or get any other peer support.
HTH,
Harald
_______________________________________________
Maxima mailing list
http://www.math.utexas.edu/mailman/listinfo/maxima
Mike Higgins
2007-07-18 19:29:45 UTC
Permalink
Harald Geyer said:
[about the facexp package documentation and collectterms()]
Post by Harald Geyer
"re-arranging forms" means that it takes an expression and returns
an other but mathematically equivalent expression.
I think facexp basically does what you want. collectterms()
is just a special (speed optimized) case of that.
But don't half of the functions in Maxima "take an expression and
return an other but mathematically equivalent expression"? simplify (all
the variations), factor, expand, reduce, and many others. Most of which
I don't know the name of so I cannot guess what might be available.
Richard Fateman suggested rat and ratexpand and sure enough they are
close to what I needed. How does a beginner find the functions that one
needs? The Maxima manual in the Windows version of wxMaxima does not
find any functions when you search on "collect", the index finds only
collectterms (and at first I could not get that to work). Who would have
guessed that typing "rat" to the index would have helped me collect terms?

The manual has a chapter on simplification, I thought this might help.
But this seems to dive down to specifics immediately. As a beginner I
don’t know yet why a function that determines if an expression is an
integer is useful for simplification.

I’ve looked at several tutorials on the WEB and the ones I have seen so
far only give very specific examples. Is there a tutorial or a book
about Maxima that gives a bigger picture? How you can approach problems,
how you find your way through the sea of functions?
--
------------------------------------
Code in haste, debug at leisure
Continue reading on narkive:
Loading...