duplicating multiplication



On Wed, 23 Feb 2005 01:24:28 -0500, Allan Adler
 wrote:
> (1) take the existing multiplication infix operator * and replace it by
>     another symbol (say &) that does the same thing but
> (2) does the same thing by virtue of using lisp code which is a clone of
>     the lisp code underlying * by changing all the names of operators to
>     something else, e.g. prepending my_ to all of them.

This is neither straightforward nor useful.  The * simplification
routines know many specific things about *, for example that 2*2=4,
1*x=x*1 = x, x*x = x^2, x+y=y+x, x*(y*z)=(x*y)*z, a*(b+c)=a*b+a*c,
etc.  Conversely, there are many things about * that are known by
other routines like the + simplification routines, like 2*x+x = 3*x,
the ^ simplification routines, etc., so copying the * simplification
routines doesn't capture them.

> This exercise is preliminary to trying to implement in lisp the operation
> f # g that I asked about earlier. Once I know how to duplicate multiplication
> as described above, I can consider how to change the duplicate multiplication
> to do something else.

It is far simpler than that.  First you need to decide whether you
want your ## operator to be a programming function that takes a ## b
and gives some value (the way factor(x^2-1) => (x-1)*(x+1)), or
whether you want it to be a simplifying function which knows algebraic
identities (the way sin(x+%pi) => -sin(x) etc.).  (Note that the #
operator already exists and means not-equal.)

My impression was that you want ## to be the first of these, not the
second.  In which case things are very straightforward.  There are two
parts.  The trivial part is defining ## as an infix operator:
infix("##") (see documentation on 'infix').  Then you can define a
function at the Maxima level using "#"(a,b):=... or at the Lisp level
using (defun  |$##| (a b) ...).  As a model for this, you could look
at say $factcomb (combin.lisp).  I recommend that you *avoid* looking
at anything in the CRE package (ratXXX.lisp), because they have all
sorts of tricky conventions involving global variables etc.

If you want the second, things are a bit harder.  You might want to
look at simpabs (in simp.lisp) as a model.

         -s