Fwd: Question about op, args.



On 2012-07-10, SoC Stevenson <steve at cs.clemson.edu> wrote:

> First surprise was that op(teste) is not a symbol but
> nounify(op(teste)) is. That's fine.

All operators which are handled specially by the parser are returned as
strings by op. That makes the results readable (i.e. the parser can read
the operator without its arguments).

> (%i5) buildq( [mop : lop, margs : largs], mop ( splice(margs)));
> (%o5)                             mplus(b, a)

apply("+", [a, b]) constructs b + a -- no need to nounify the operator
(in fact, you won't get a "+" expression if you do).

Here is a macro to take an expression apart and put it back together:

(%i1) display2d : false $
(%i2) foo (e) ::= buildq ([o : op (e), a : args (e)], apply (o, a)) $
(%i3) macroexpand (foo (a + b));
(%o3) apply("+",[b,a])
(%i4) foo (a + b);
(%o4) b+a

> My question is: Am I guaranteed that reverse(args( ... )) is the correct order?

The arguments of all commutative operators and functions are put in a
canonical ordering by Maxima's expression simplifier. 

For most commutative operators, the arguments are displayed in their
canonical ordering. For "+", the display order is controlled by the
global flag powerdisp. When powerdisp = true, the arguments of "+" are
displayed in their canonical ordering. When false (default), they are
displayed in the reverse order.

powerdisp only controls display; the internal order of the arguments is
always the same.

best

Robert Dodier