defining new types in maxima



On 4/26/08, S. Newhouse <sen1 at math.msu.edu> wrote:

>   Is there a standard way to define new types in maxima which could then
>  be assigned to variables, have operations done on them, etc?
>
>   One way to do this is to define certain named lists, operations on
>  those lists and their elements, checks to see if items belong to the
>  lists, etc.

Not sure what you want to accomplish, but if it is something like
a new mathematical object (e.g. base-60 notation, quantities with
physical units, infinite sets) then probably you can use the
simplification system for that. A simplification is conceptually
just an identity.

Maxima has tellsimp & friends to introduce new simplifications
which works OK (within limitations). I can try to explain more about
that if you say more about the problem you are working on.

>  I wondered if there is already an accepted way to do this, much like the
>  'typedef' or 'struct' of C.

Maxima has a defstruct system (undocumented, sorry) which creates
aggregates with named elements.

(%i1) defstruct (point (x, y));
(%o1)                     [point(x, y)]
(%i2) p : new (point);
(%o2)                      point(x, y)
(%i3) p at x : 1.75;
(%o3)                         1.75
(%i4) p;
(%o4)                  point(x = 1.75, y)
(%i5) defstruct (circle (center = point (0, 0), radius = 1));
(%o5)  [circle(center = point(x = 0, y = 0), radius = 1)]
(%i6) c : new (circle);
(%o6)   circle(center = point(x = 0, y = 0), radius = 1)
(%i7) c at center@y;
(%o7)                           0
(%i8) c at center@y : -3.25;
(%o8)                        - 3.25
(%i9) c;
(%o9) circle(center = point(x = 0, y = - 3.25), radius = 1)

Maxima defstruct is essentially a reimplementation of Lisp DEFSTRUCT.
It was originally written by RJF and I merged it into Maxima
a few years ago. It occurs to me now that maybe it would have
been easier to just expose Lisp DEFSTRUCT objects directly
(preserving the user-level operations more or less).

defstruct doesn't have any effect on the interactions between
objects -- use simplification for that.

Hope this helps,

Robert Dodier