Discussion:
How to avoid ^- in maxima output? (Leo Butler) [Martin Kraska]
Martin Kraska
2013-10-31 21:17:10 UTC
Permalink
Leo,

indeed the approach has solved the problem. It also inspired the solution of a similar problem with expressions of type a^b^c.

I suppose, we are not compatible to GPLv2, as we do not make any particular license statement and the base program SMath is closed source and we are bundling our stuff with SMath (plugin distribution is via the SMath extension manager).

Currently, we distribute the files smath.mac and smath.lisp together with the plugin and place them in the install dir of SMath (which is not really nice).

Having them in the Maxima installation would be fine for us. We would then load them from our init files. This, however would be problematic with existing Maxima installations, as there is no convenient Maxima update procedure (at least under windows).

Do you see any clean way to handle that?

Martin Kraska
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 31. Oktober 2013 14:55
An: Martin Kraska
Betreff: Re: AW: [Maxima] How to avoid ^- in maxima output? (Leo Butler)
Date: Thu, 24 Oct 2013 18:05:04 +0200
Leo,
thanks a lot for the great help.
I did not examine the code yet but I see that this might be the solution of
the given problem and I am glad to see that such problems can be handled
on
the Maxima side. We would like to avoid any modification of existing
Maxima
installations and rather load the scripts from our plugin directory. I guess
that the search path for maxima can be extended accordingly.
Best regards, Martin
Martin, sorry for the delay in replying, my outbound email server has been down
for a while.
I don't know if your project has found the code that I wrote useful. If so, and you
wish to use it to provide a plugin to Maxima, then there is the issue of
distribution. I do not know if your licensing is compatible with GPLv2. If it is,
then please distribute the code with your plugins. If it is not *or* you are
unsure (and I suspect this is the case), then the code can be added to Maxima
under the share/contrib directory where it will be distributed under GPLv2.
Regards,
Leo
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 24. Oktober 2013 16:48
An: Martin Kraska
Betreff: Re: [Maxima] How to avoid ^- in maxima output? (Leo Butler)
Date: Thu, 24 Oct 2013 01:09:02 +0200
Leo, thanks for the response ( and Robert, for your's as well).
Other examples are
"e^-cos(x)/b", misunderstood as e^{-cos(x)/b},
"e^-c/b" , misunderstood as e^{-c/b}
"e^(-cos(x))/b"
"e^(-c)/b"
Thus, how can Maxima be forced to bracket the unary minus operator in
1d
output?
Ok, I do see what you want. My suggestion is basically what RJF and
Robert
were hinting at. What you can do is use Maxima's ability to apply
transformation rules to expressions to re-write the expression before it
is
(%i10) (to_mx_display(), kill(all), load("smath.mac"))$
(%i1) [e^-4, %e^-t/d, %e^-cos(x)/y];
(%o1) [1/e^4,%e^-t/d,%e^-cos(x)/y]
(%i2) to_sm_display();
(%s2) %s <-- change outchar for different
display mode
(%i3) [e^-4, %e^-t/d, %e^-cos(x)/y];
(%s3) [e^{-4},%e^{-t}/d,%e^{-cos(x)}/y] <-- desired output
(%i4) to_mx_display();
(%o4) %o <-- revert to maxima's standard
1d display
(%i5) %s3;
(%o5) [1/e^4,%e^-t/d,%e^-cos(x)/y] <-- the expr in %s3 is valid
maxima
code
where
/* -*- Mode: maxima; Package: MAXIMA -*- */
/*
the
terms of GPLv2 */
matchdeclare([sm_x],true,sm_y,lambda([e],if is(numberp(e) and e<0 and
e#-1)
or is(not(atom(e)) and op(e)="-") then true else false));
defrule(sm_exp_to_power,sm_x^sm_y,sm_x^{sm_y});
sm_rules:['sm_exp_to_power];
load("smath.lisp")$
/* end of smath.mac */
;; -*- mode: lisp -*-
the
terms of GPLv2
(in-package :maxima)
(defvar *displa* (symbol-function 'displa)) (defvar *maxima-outchar*
$outchar)
(defvar *smath-outchar* '$%s) (defvar $sm_rules)
(defun $smath_displa (form &optional (sm-rules $sm_rules))
"Display FORM by APPLY1-ing the rules in SM-RULES to the EXPR in
FORM."
(declare (special $sm_rules *alt-display1d*))
(let ((rules (cdr sm-rules))
(*alt-display1d* nil)
(expr (third form)))
(funcall *displa*
(list (first form) (second form)
(dolist (rule rules expr)
(setf expr (mfuncall '$apply1 expr rule)))))))
(defun $to_sm_display ()
"Set-up Maxima to use SMATH_DISPLA to display output."
(declare (special *alt-display1d* $outchar *smath-outchar*))
(setf *alt-display1d* (symbol-function '$smath_displa))
(setf $outchar *smath-outchar*))
(defun $to_mx_display ()
"Return Maxima to use standard DISPLA for 1d output."
(declare (special *alt-display1d* $outchar *maxima-outchar*))
(setf *alt-display1d* nil)
(setf $outchar *maxima-outchar*))
; end of smath.lisp
Leo
Leo Butler
2013-11-01 01:21:08 UTC
Permalink
Date: Thu, 31 Oct 2013 22:17:10 +0100
Leo,
indeed the approach has solved the problem. It also inspired the solution of a similar problem with expressions of type a^b^c.
I suppose, we are not compatible to GPLv2, as we do not make any particular license statement and the base program SMath is closed source and we are bundling our stuff with SMath (plugin distribution is via the SMath extension manager).
Currently, we distribute the files smath.mac and smath.lisp together with the plugin and place them in the install dir of SMath (which is not really nice).
Having them in the Maxima installation would be fine for us. We would then load them from our init files. This, however would be problematic with existing Maxima installations, as there is no convenient Maxima update procedure (at least under windows).
Do you see any clean way to handle that?
Martin Kraska
Martin, I think the cleanest solution that respects all parties would
be to remove the GPL code from your distribution, put that code in the
Maxima code base, and distribute a plugin that offers to fetch the
code from Maxima's Sourceforge site (under its license). When the next
Maxima release comes, you could change that to offer to install the
latest version of Maxima which will come with enhancements for SMath.

Does that seem reasonable?

Regards,
Leo
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 31. Oktober 2013 14:55
An: Martin Kraska
Betreff: Re: AW: [Maxima] How to avoid ^- in maxima output? (Leo Butler)
Date: Thu, 24 Oct 2013 18:05:04 +0200
Leo,
thanks a lot for the great help.
I did not examine the code yet but I see that this might be the solution of
the given problem and I am glad to see that such problems can be handled
on
the Maxima side. We would like to avoid any modification of existing
Maxima
installations and rather load the scripts from our plugin directory. I guess
that the search path for maxima can be extended accordingly.
Best regards, Martin
Martin, sorry for the delay in replying, my outbound email server has been down
for a while.
I don't know if your project has found the code that I wrote useful. If so, and you
wish to use it to provide a plugin to Maxima, then there is the issue of
distribution. I do not know if your licensing is compatible with GPLv2. If it is,
then please distribute the code with your plugins. If it is not *or* you are
unsure (and I suspect this is the case), then the code can be added to Maxima
under the share/contrib directory where it will be distributed under GPLv2.
Regards,
Leo
Martin Kraska
2013-11-01 10:45:20 UTC
Permalink
Leo,

we think, that we can ask the user to install the latest maxima release, because this might be a plausible request for them. Insofar your proposal sounds reasonable

We perhaps won't ask the users to mess around in the maxima installation. In our understanding that would mean sacrificing user's convenience for the sake of our convenience. We also do not think that it is a good idea that we mess around in the maxima repository, things might go wrong there.

Thus we ask you to include the code in the next maxima release and accept a temporary perhaps non-GPL compliant state until the next windows release of maxima is available.

Martin.
-----Ursprüngliche Nachricht-----
Gesendet: Freitag, 1. November 2013 02:21
An: Martin Kraska
brandenburg.de
Betreff: Re: AW: AW: [Maxima] How to avoid ^- in maxima output? (Leo Butler)
[Martin Kraska]
brandenburg.de>
Date: Thu, 31 Oct 2013 22:17:10 +0100
Leo,
indeed the approach has solved the problem. It also inspired the solution of
a similar problem with expressions of type a^b^c.
I suppose, we are not compatible to GPLv2, as we do not make any particular
license statement and the base program SMath is closed source and we are
bundling our stuff with SMath (plugin distribution is via the SMath extension
manager).
Currently, we distribute the files smath.mac and smath.lisp together with the
plugin and place them in the install dir of SMath (which is not really nice).
Having them in the Maxima installation would be fine for us. We would then
load them from our init files. This, however would be problematic with existing
Maxima installations, as there is no convenient Maxima update procedure (at
least under windows).
Do you see any clean way to handle that?
Martin Kraska
Martin, I think the cleanest solution that respects all parties would be to
remove the GPL code from your distribution, put that code in the Maxima code
base, and distribute a plugin that offers to fetch the code from Maxima's
Sourceforge site (under its license). When the next Maxima release comes, you
could change that to offer to install the latest version of Maxima which will
come with enhancements for SMath.
Does that seem reasonable?
Regards,
Leo
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 31. Oktober 2013 14:55
An: Martin Kraska
Betreff: Re: AW: [Maxima] How to avoid ^- in maxima output? (Leo Butler)
Date: Thu, 24 Oct 2013 18:05:04 +0200
Leo,
thanks a lot for the great help.
I did not examine the code yet but I see that this might be the solution
of
the given problem and I am glad to see that such problems can be
handled
on
the Maxima side. We would like to avoid any modification of existing
Maxima
installations and rather load the scripts from our plugin directory. I
guess
that the search path for maxima can be extended accordingly.
Best regards, Martin
Martin, sorry for the delay in replying, my outbound email server has been
down
for a while.
I don't know if your project has found the code that I wrote useful. If so,
and you
wish to use it to provide a plugin to Maxima, then there is the issue of
distribution. I do not know if your licensing is compatible with GPLv2. If it
is,
then please distribute the code with your plugins. If it is not *or* you are
unsure (and I suspect this is the case), then the code can be added to
Maxima
under the share/contrib directory where it will be distributed under GPLv2.
Regards,
Leo
Leo Butler
2013-11-01 14:21:19 UTC
Permalink
Date: Fri, 1 Nov 2013 11:45:20 +0100
Leo,
we think, that we can ask the user to install the latest maxima release, because this might be a plausible request for them. Insofar your proposal sounds reasonable
We perhaps won't ask the users to mess around in the maxima installation. In our understanding that would mean sacrificing user's convenience for the sake of our convenience. We also do not think that it is a good idea that we mess around in the maxima repository, things might go wrong there.
Thus we ask you to include the code in the next maxima release and accept a temporary perhaps non-GPL compliant state until the next windows release of maxima is available.
Martin.
Martin, Ok.

You mentioned that you had patched the code to handle other
anomalies. Would you like me to include that?

Leo
Martin Kraska
2013-11-01 15:45:17 UTC
Permalink
Leo, thanks for the agreement. Yes, it is sensible to include the code
changes. For the future, I guess, just adding rules to sm_rules in our
session init would be sufficient, wouldn't it? Then we do not need to bother
with updates.

The only direct change was made to the match pattern in order to resolve
different interpretation of a^b^c in Maxima and SMath:

matchdeclare([sm_x],true,sm_y,lambda([e],if is(numberp(e) and e<0 and e#-1)
or is(not(atom(e)) and (op(e)="-" or op(e)="^")) then true else false));

Thanks again for your help.

Martin
-----Ursprüngliche Nachricht-----
Gesendet: Freitag, 1. November 2013 15:21
An: Martin Kraska
brandenburg.de
Betreff: Re: AW: AW: AW: [Maxima] How to avoid ^- in maxima output? (Leo
Butler) [Martin Kraska]
Date: Fri, 1 Nov 2013 11:45:20 +0100
Leo,
we think, that we can ask the user to install the latest maxima
release, because this might be a plausible request for them. Insofar
your proposal sounds reasonable
We perhaps won't ask the users to mess around in the maxima
installation.
In our understanding that would mean sacrificing user's convenience for
the
sake of our convenience. We also do not think that it is a good idea that
we
mess around in the maxima repository, things might go wrong there.
Thus we ask you to include the code in the next maxima release and
accept
a temporary perhaps non-GPL compliant state until the next windows release
of
maxima is available.
Martin.
Martin, Ok.
You mentioned that you had patched the code to handle other anomalies.
Would you like me to include that?
Leo
Leo Butler
2013-11-07 15:44:50 UTC
Permalink
Date: Fri, 1 Nov 2013 16:45:17 +0100
Leo, thanks for the agreement. Yes, it is sensible to include the code
changes. For the future, I guess, just adding rules to sm_rules in our
session init would be sufficient, wouldn't it? Then we do not need to bother
with updates.
The only direct change was made to the match pattern in order to resolve
matchdeclare([sm_x],true,sm_y,lambda([e],if is(numberp(e) and e<0 and e#-1)
or is(not(atom(e)) and (op(e)="-" or op(e)="^")) then true else false));
Thanks again for your help.
Martin
Martin, I pushed the patched plugin to the Maxima repository. Give it
a test run, please.

Note that I changed the rule slightly, to make it put braces around
almost all non-atomic exponents.

(%i1) load(smath);
(%o1) "/home/work/maxima/sandbox/git/maxima-sf/share/contrib/smath/smath.mac"

(%i2) to_sm_display();
(%s2) %s

(%i3) e^a^b^c^d;
(%s3) e^{a^{b^{c^d}}}

(%i4) e^(1+cos(e^a));
(%s4) e^{cos(e^a)+1}

(%i5) e^(1+cos(e^a^-w));
(%s5) e^{cos(e^{a^{-w}})+1}

Leo

Loading...