(no subject)



'length' will count the number of terms.

Some things to be aware of:

length(x) is an error, since x is atomic
length(x[a]) is 1 (considers it to be a function of one argument)
length(-x) is 1 (considers it to be a function of one argument -- "-"(x)
length of a matrix is the number of rows
length(x*y+1) is of course 2 -- "+"(x^2,1)
but so is length(x*y) -- "*"(x,y)


So if you mean number of *multiplicative* terms, you might want something
like:

multiplicative_terms(expr) := if mapatom(expr) or op(expr) # "*" then 1
else length(expr)$
*
Mutatis mutando *for additive terms.

*nterms* is documented:

     Returns the number of terms that <expr> would have if it were fully
     expanded out and no cancellations or combination of terms occurred.
     Note that expressions like `sin (<expr>)', `sqrt (<expr>)', `exp
     (<expr>)', etc. count as just one term regardless of how many
     terms <expr> has (if it is a sum).

So it counts the number of additive terms *after expansion* *and assuming
no cancellation*. (Not sure why that is useful...)

For example:

nterms((x-1)*(x+1)) => 4  (based on x^2 - x + x - 1, not x^2 - 1)


            -s


On Tue, Nov 6, 2012 at 9:54 AM, Sean <seany at uni-bonn.de> wrote:

> Hello everyone,
>
> i am a newcomer. i used maxima before to check my own solutions to
> differential equations or to check if my "organization" of equations e.g.
> substitution etc are okey or not.
>
> But now, i need some help.
>
> I need to know if there is a way to count the number of terms in an
> expression.
>
> EG: the expression a*b has two terms, namely a and b
>
> the function nterms() does not work. nterms(a*b) is one.
>
> thanks for your help and sorry for my bad english.
>
> I have maxima 5.28.0
>
> thanks,s
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>