possible bug in monomial expressions



Not a bug, intentional behavior that Maxima goes out of its way to provide.

Maxima treats 2*x*y as "*"(2,x,y) and -2*x*y as "-"("*"(2,x,y)).

If you prefer, you can use the internal representation, in which the second
one is indeed "*"(-2,x,y):

    length(-2*x*y),inflag:true => 3

Maxima uses the external representation for all functions which examine the
form of an expression, including length, args, op, part, map, etc.  To use
the internal form, bind inflag to true.

To show the structure of expressions, try:
struct(ex):=
  if errcatch(op(ex))=[]
    then ex
  else funmake(concat("<",op(ex),">"),map(struct,args(ex)))$

Normal user-visible structure

map(struct,[1,-1,x,1/x,-1/x,2*x,-2*x,x-1]) =>
  [1, <->(1), x, <//>(1, x), <->(<//>(1, x)), <*>(2, x), <->(<*>(2, x)),
<+>(x, <->(1))]

Internal structure

map(struct,[1,-1,x,1/x,-1/x,2*x,-2*x,x-1]),inflag:true =>
  [1, - 1, x, <^>(x, - 1), <*>(- 1, <^>(x, - 1)), <*>(2, x), <*>(- 2, x),
<+>(- 1, x)]

Is that clearer?

           -s

On Dec 20, 2007 12:30 PM, S. Newhouse <sen1 at math.msu.edu> wrote:

> (%i103) p: 2*x*y;
> (%o103)                              2 x y
> (%i104) length(p);
> (%o104)                                3
> (%i105) q: -2*x*y;
> (%o105)                             - 2 x y
> (%i106) length(q);
> (%o106)                                1
>
> Is this a bug?  If so, what is the correct answer to length in these
> problems?
>