[Maxima] Maxima 0 superscript
robert.dodier at gmail.com
Fri Apr 23 02:43:38 CDT 2010
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.)
(%i7) x`0 : a;
(%i8) x`1 : b;
(%i9) x`0 + x`1 + x`2;
(%o9) x + b + 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);
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:
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.
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.
: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)
:lisp (defun $\` (x y) (or (and (get x 'superscript-values) (gethash y
(get x 'superscript-values))) `(($\`) ,x ,y)))
More information about the Maxima