How to avoid ^- in maxima output? (Leo Butler)



>   From: Martin Kraska <kraska at fh-brandenburg.de>
>   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}
>
>   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?

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 displayed. Here is what I mean:

(%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

smath.mac:
/* -*- Mode: maxima; Package: MAXIMA -*- */
/*
;; Copyright Leo Butler (leo.butler at member.fsf.org) 2013
;; Released under 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 */


smath.lisp:
;; -*- mode: lisp -*-
;; Copyright Leo Butler (leo.butler at member.fsf.org) 2013
;; Released under 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