Radical signs output for fractional degrees.



On 1/30/09, Andrew Yeltsin <gutierrez at nigma.ru> wrote:

> We're still working on a custom version of Maxima (step-by-step
> output for some problems)

I'd be interested to hear more about it.

> The question is - how to make fractional degrees to be output
> as radical signs (using \sqrt[root index]{expression})?

I've appended some code to clobber the built-in TeX function for
x^(1/y) expressions. (I didn't try to handle anything else such as x^(2/y).)

tex (x^(1/2));
 => $$\sqrt{x}$$

tex (x^(1/3));
 => $$\sqrt[3]{x}$$

tex (x^(2/3));
 => $$x^{{{2}\over{3}}}$$

tex (x^(1/n));
 => $$\sqrt[n]{x}$$

tex (x^(2/n));
 => $$x^{{{2}\over{n}}}$$

tex (x^(1/(n + m)));
 => $$\sqrt[n+m]{x}$$

tex (x^(2/(n + m)));
 => $$x^{{{2}\over{n+m}}}$$

> Even if it is not necessary for main Maxima version, we need it for
> our custom version. In this case we can pay for it.
> If you are interested in this job - write me. We'll discuss the requirements
> specification and payment details.

Well, in this case anyway, your appreciation is enough.
(Assuming this function does what you want!)
I might try to put this code somewhere in maxima/share/.

best

Robert Dodier

PS.
;; TeX output x^(1/n) as \sqrt[n]{x}
;; copyright 2009 by Robert Dodier
;; I release this work under terms of the GNU General Public License

(setf (symbol-function 'tex-mexpt-original) #'tex-mexpt)

(defun tex-mexpt (x l r)
  (let ((my-expt (third x)))
    (multiple-value-bind
      (hit my-root)
      (1-over-something-p my-expt)
      (if hit
        (let ((my-base (second x)))
          (tex-mexpt-root my-base my-root l r))
        (tex-mexpt-original x l r)))))

;; Try to detect: ((RAT) 1 FOO) ((MEXPT) FOO -1) ((MQUOTIENT) 1 FOO)
;; Dunno if there are other ways to represent 1/foo in Maxima.

(defun 1-over-something-p (x)
  (cond
    ((atom x)
     (values nil nil))
    ((and (eq (caar x) 'rat) (eq (second x) 1))
     (values t (third x)))
    ((and (eq (caar x) 'mexpt) (eq (third x) -1))
     (values t (second x)))
    ((and (eq (caar x) 'mquotient) (eq (second x) 1))
     (values t (third x)))
    (t (values nil nil))))

(defun tex-mexpt-root (my-base my-root l r)
  (append l
          (list "\\sqrt[")
          (tex my-root nil nil 'mparen 'mparen)
          (list "]{")
          (tex my-base nil nil 'mparen 'mparen)
          (list "}")
          r))