Subject: How to avoid ^- in maxima output? (Leo Butler)
From: Martin Kraska
Date: Thu, 24 Oct 2013 01:09:02 +0200
Leo, thanks for the response ( and Robert, for your's as well).
>
> There is a discussion of a related topic here:
>
> http://www.math.utexas.edu/pipermail/maxima/2013/033188.html
>
> My guess is that you could provide a slightly patched version of the
current 1d
> printer, and hook your custom printer in with the hook discussed in that
thread.
This indeed looks promising.
> Here is an alternative suggestion: define ^- as an infix operator in
Maxima with
> the same binding properties as in SMath.
>
> (%i1) :lisp (list (get '$- 'lbp) (get '$- 'rbp))
>
> (100 134)
> (%i1) :lisp (list (get '$^ 'lbp) (get '$^ 'rbp))
>
> (140 139)
>
> Define ^- to have the same lbp as ^ and a low rbp so it globs to the
right.
>
> (%i1) infix("^-",140,50);
>
> (%o1) "^-"
>
> Define the operator to do what it should:
>
> (%i2) "^-"(x,y) := x^ -y;
>
> (%o2) (x ^- y):=x^-y
>
> I think this is the behaviour you want:
>
> (%i3) e^-c/d;
>
> (%o3) 1/e^(c/d)
This is how SMath would interpret the input. What I want is to prevent SMath
from doing so by adding a bracket around the complete exponent, including
the unary minus.
The behavior as created in your example would make Maxima understand it's
own output in the same way as SMath would (both wrong in this case).
Perhaps I was not precise enough: There is no translation problem from SMath
to Maxima (yes, there are a lot of problems, including unicode characters
like russian or greek characters, but that is a different game). Maxima
understands the expressions from SMath as they are meant by SMath.
What does not work is the other way around.
>
> But you get the standard behaviour with a space:
>
> (%i4) e^ -c/d;
>
> (%o4) 1/(d*e^c)
>
>
> And the non-intuitive behaviour without explicit brackets:
>
> (%i6) e^-c/d + 1;
> (%o6) e^(-c/d-1)
Summands would not slip into the exponent in SMath interpretation. This just
happens with factors. But I gess this could be adjusted using the priority
levels.
>
> (%i7) (e^-c/d) + 1;
> (%o7) 1/e^(c/d)+1
>
> (%i8) e^(-c/d) + 1;
> (%o8) 1/e^(c/d)+1
>
>
> Leo
I tried the example and was able to reproduce it. However, I still get ^- in
the output:
(i) string((%e^(-(x*y)))/b);
(o) "%e^-(x*y)/b"
(copied from wxmaxima)
The native 1d version of this expression in SMath is {e^{-(x*y)}}/b (curly
braces are invisible ones). In the plugin, we just replace the curly braces
by ordinary ones and change e into %e. If I feed back the output (o) with
the % stripped to SMath, then b has slipped into the exponent. Again, the
serialized version in SMath is e^{-(x*y)/b}. This means that the translation
problem is not solved.
Other examples are
"e^-cos(x)/b", misunderstood as e^{-cos(x)/b},
"e^-c/b" , misunderstood as e^{-c/b}
1d versions which would be understood correctly, are:
"e^(-cos(x))/b"
"e^(-c)/b"
Thus, how can Maxima be forced to bracket the unary minus operator in 1d
output?
Best regards,
Martin Kraska