(no subject)



On 11/06/2012 03:26 PM, Stavros Macrakis wrote:
> 'length' will count the number of terms.
>
> ...
>
> 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.
> ...
>
> On Tue, Nov 6, 2012 at 9:54 AM, Sean <seany at uni-bonn.de 
> <mailto:seany at uni-bonn.de>> wrote:
>
>     ...
>
>     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
>
Hi,
I think that Sean might find the following results unexpected:

(%i3) multiplicative_terms(a*b*c*d);
(%o3)                           4
(%i4) multiplicative_terms(-a*b*c*d);
(%o4)                           1

Perhaps the following function is what he is looking for?:

(%i5) nt([y]) := if length(y) < 1 then 0 else (if mapatom(first(y)) then 
1+apply(nt,rest(y)) else apply(nt,args(first(y))) + apply(nt,rest(y)))$

(%i6) nt(a*b*c*d);
(%o6)                           4

(%i7) nt(-a*b*c*d);
(%o7)                           4

(%i8) nt(-a*b*c*d + e/f +g);
(%o8)                           7

Regards,
Jaime