Maxima 0 superscript



On 4/20/10, Oliverks <oliverks1 at yahoo.com> wrote:

> This would be a nice feature.  Being able to add super or sub scripts to
> function or variable names which are purely symbolic (i.e. not array, or
> power designators) would be handy.  That way I could import the latex
> output directly into an openoffice document without having to rework it to
> fit conventions in the area a document is being written about.

This is really an interesting idea. As it stands, Maxima doesn't have any
idea that a variable could be anything other than a symbol or a subscripted
symbol, but we can make some progress towards allowing arbitrary
expressions to be variables without too much trouble.

With the simple-minded hackery shown in the PS, I get the following.
I've used the backtick to indicate the superscript; Maxima has too
many ideas how the caret acts. (The following output is all messed
up unless displayed by a fixed-width font, sorry about that.)

(%i4) x`0;
                                0
(%o4)                          x
(%i5) y`1;
                                1
(%o5)                          y
(%i6) x`1;
                                1
(%o6)                          x
(%i7) x`0 : a;
(%o7)                           a
(%i8) x`1 : b;
(%o8)                           b
(%i9) x`0 + x`1 + x`2;
                            2
(%o9)                      x  + b + a
(%i10) y`k;
                                k
(%o10)                         y
(%i11) y`k:x`0;
(%o11)                          a
(%i12) y`k;
(%o12)                          a
(%i13) :lisp (get '$x 'superscript-values)
#S(HASH-TABLE TEST FASTHASH-EQL (1 . $B) (0 . $A))
(%i13) tex (z`0 + z`1 + z`2 + z`i);
$$z^i+z^2+z^1+z^0$$
(%o13)                        false

So far, so good. However note that trying to use a superscript in a
function name causes Maxima to get all bent out of shape:

(%i16) (f`k)(x);
              k
apply: found f  where a function was expected.
 -- an error.

This is one of those days when I wish Maxima applied its
laissez faire attitude a little more extensively ....

What are some superscripted expressions you would like to
work with? I'll give them a try.

FWIW

Robert Dodier

PS. here's the code, such as it is.
It makes use of the mset_extension_operator, the undocumented
feature by which multiple assignment was implemented, thanks to RJF.

/* make x`y act like a superscripted variable
 * copyright 2010 by Robert Dodier
 * I release this work under terms of the GNU General Public License.
 */

infix ("`");
:lisp (setf (get '$\` 'dimension) (get 'mexpt 'dimension))
texput ("`", "^", 'infix);
:lisp (setf (get '$\` 'mset_extension_operator) 'superscript-assign)
:lisp (defun superscript-assign (expr value) (let* ((x (second expr))
(y (third expr)) (z (or (get x 'superscript-values) (setf (get x
'superscript-values) (make-hash-table))))) (setf (gethash y z)
value)))
:lisp (defun $\` (x y) (or (and (get x 'superscript-values) (gethash y
(get x 'superscript-values))) `(($\`) ,x ,y)))