custom plus-like operator



Hello,
on Sunday 23 November 2003 18:45 AZ wrote:
>Hello,
>Here's what I try to do. I want a "+"-like operator(s). I.e. they should
>be nary, infix and loaded with some algebraic properties, like term
>combining (a+0=a, a+a=2*a etc). My difficulties concern this algebraic
>loading. As far as I understand, mplus and mtimes are a kind of
>priviledged operators, since their processing is done inside of (is
>dispatched by ?) simplifya. In MMA parlance I'd express what I want as
>MyOp[x___, a_, a_, y___] :=MyOp[x,2 a, y] (MyOp should have ordered
>arguments then?). So, how can I do this in Maxima?
>  /* Here "aa"'s body should be changed to do simplus-like processing,
>buf alas! */
>(C1) "aa"([x]):=(print(x),'"aa"(x));
>
>(D1) 			 AA([x]) := (PRINT(x), 'AA(x))
>(C2) nary("aa");
>
>(D2) 				     "AA"
>(C3) infix("aa");
>
>(D3) 				     "AA"
>(C4) 1 aa 2 aa f aa 3;
>
>[1, 2]
>Wrong number of arguments to AA
>#0: AA(x=[1,2])
>#1: AA(x=1)
>#2: AA(x=23)
>  -- an error.  Quitting.  To debug this try DEBUGMODE(TRUE);)
On my system I have
(C1) infix("aa");
(D1)                                 "AA"
(C2) nary("aa");
(D2)                                 "AA"
(C3) "aa"([x]):=(print(x),'"aa"(x));
(D3)                    "AA"([x]) := (PRINT(x), 'AA(x))
(C4) 1 aa 2 aa f aa 3;
[1, 2, f, 3]
(D4)                           AA([1, 2, f, 3])

Is it what do you want to see?

take care,
V