custom plus-like operator



1. Tellsimp, and tellsimpafter can be used with mplus, mtimes, etc.
The dispatch from simplifya to these programs checks for "tellsimp"
properties.  Since you want many of the same features as +, I think
you should use +, if possible. That way you will get x+y+x --> y+2*x,
and x-x --> 0.

2. If you write it yourself, you can collect the arguments to "aa" as
shown, call sort() and play around with it yourself. make sure you can
handle x-x -->0, if that is one of the possibilities.

You may need to have some way of tagging your operands, e.g.  f(a) + 
f(a) -->
f(2*a)  etc. Maybe your additional algebraic properties can be put together
with f.  Note that the mathematica way of doing things may take exponential
time, if the system must search for all possible matches in a list of n 
items.
Macsyma does not try all permutations,  and also,  

aa(b,b)  is not a sub-part of aa(b,a,b) or aa(b,b), so it will not match.
The macsyma matching program does not have a facility for matching 
aa(....,b,b,.....).
I suppose it could be added.  In fact, the whole mathematica 3.0 pattern
matcher written in lisp, could be added, since it is in mockmma.  The
internal representation is slightly different, e.g.  (Plus a b) instead of
((mplus) $a $b).



Good luck.

RJF

Andrei Zorine 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);)
> (C5)
> Tellsimp'ing doesn't help:
> (C1) (nary("aa"),infix("aa"))$
>
> (C2) (matchdeclare(a,true),tellsimp(a aa a, 2*a))$
>
> (C3) b aa a aa b;
>
> (D3)                   b AA a AA b
> (C4) a aa a aa b;
>
> (D4)                   (2 a) AA b
> (C5) declare("aa",commutative);
>
> (D5)                      DONE
> (C6) ''c3;
>
> (D6)                   b AA a AA b
> (C7)
>
> -- 
> Andrei Zorine
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima