3

sqrtMaximaに関数の一般化があるかどうか疑問に思っていますか? 特に、 をまたはx^(a/b)として表示するかどうかを制御できるようにしたいと考えています。$x^{\frac{a}{b}}$$\sqrt[b]{x^{a}}$

ドキュメントのインデックスを検索しましたrootが、関連性があると特定できるものは何も見つかりませんでした。また、sqrtdispflagエントリからのリンクもありませんでした。

4

1 に答える 1

2

これは興味深い質問であり、Maxima がより柔軟な TeX 出力システムから利益を得ることができることをもう一度示していますが、私は脱線します。これが可能な解決策です。

これは、パターン マッチング ( defmatch) を使用して、さらに処理する商の式を識別し、一致が成功した場合は商の分子と分母を引き出します。パターン マッチャーは次のようなものを識別できませんb/c^2。これは、おそらくパターン マッチャーのバグと見なす必要があります。

デフォルトの TeX 出力関数は、TEX-MEXPT という名前の Lisp 関数です。私はそれを呼び出すためのLispコード(確かにあいまいです)の行を書きました。

/* tex_mexpt.mac -- look for quotient in exponent
 * copyright 2021 by Robert Dodier
 * I release this work under terms of the GNU General Public License
 */

matchdeclare (aa, all);
matchdeclare (bb, "#"(1));
defmatch (matches_quotient, aa/bb);
defmatch (matches_minus_quotient, -aa/bb);

:lisp (defun $tex_mexpt_default (e) (let (lop rop) (apply 'concatenate 'string (tex-mexpt e nil nil))))

my_tex_mexpt_quotient (base, expt_num, expt_denom) :=
  if expt_num = 1
    then printf(false, "\\sqrt[~a]{~a}", tex1 (expt_denom), tex1 (base))
    else printf(false, "\\sqrt[~a]{~a}", tex1 (expt_denom), tex_mexpt_default (base^expt_num));

my_tex_mexpt_minus_quotient (base, expt_num, expt_denom) :=
  if expt_num = 1
    then printf(false, "\\sqrt[~a]{{1}\\over{~a}}", tex1 (expt_denom), tex1 (base))
    else printf(false, "\\sqrt[~a]{~a}", tex1 (expt_denom), tex_mexpt_default (base^-expt_num));

my_tex_mexpt (e) :=
  if tex_mexpt_look_for_quotient
    then block ([base, expt],
                [base, expt]: args(e),
                if matches_quotient(expt) # false
                  then my_tex_mexpt_quotient (base, aa, bb)
                elseif matches_minus_quotient(expt) # false
                  then my_tex_mexpt_minus_quotient (base, aa, bb)
                  else tex_mexpt_default (e))
    else tex_mexpt_default (e);

/* examples */

stringdisp: true $

verbatim_and_equation (e) ::= printf (S, "\\begin{verbatim}~%~a~%\\end{verbatim}~%$$~a$$~%", string(e), tex1(e));

S: openw ("/tmp/foo.tex");
printf (S, "\\documentclass{article}~%\\begin{document}~%");

/* first without my_tex_mexpt at all */

verbatim_and_equation (a^(b/c));
verbatim_and_equation (a^-(b/c));
verbatim_and_equation (a^(-b/c));
verbatim_and_equation (a^(1/c));
verbatim_and_equation (a^-(1/c));
verbatim_and_equation (a^(-1/c));
verbatim_and_equation ((1 + (1 - x)^((y - z)/(y - w)))/((2*u - v)^(1/(n + 1))));

/* now enable my_tex_mexpt */

texput ("^", my_tex_mexpt);
tex_mexpt_look_for_quotient:true;

verbatim_and_equation (a^(b/c));
verbatim_and_equation (a^-(b/c));
verbatim_and_equation (a^(-b/c));
verbatim_and_equation (a^(1/c));
verbatim_and_equation (a^-(1/c));
verbatim_and_equation (a^(-1/c));
verbatim_and_equation ((1 + (1 - x)^((y - z)/(y - w)))/((2*u - v)^(1/(n + 1))));

/* verify disabled produces same output as originally */

tex_mexpt_look_for_quotient:false;

verbatim_and_equation (a^(b/c));
verbatim_and_equation (a^-(b/c));
verbatim_and_equation (a^(-b/c));
verbatim_and_equation (a^(1/c));
verbatim_and_equation (a^-(1/c));
verbatim_and_equation (a^(-1/c));
verbatim_and_equation ((1 + (1 - x)^((y - z)/(y - w)))/((2*u - v)^(1/(n + 1))));

printf (S, "\\end{document}~%");
close(S);

ご覧のとおり、出力を少し確認するために、いくつかの例をそこに入れました。maxima --batch=foo.macまたは保存されたファイルの名前が何であれ、それを実行できます。で出力を生成します/tmp/foo.tex。で処理してlatexから で表示しましたxdvi

記録のために、これがfoo.tex私が得た出力です。

\documentclass{article}
\begin{document}
\begin{verbatim}
a^(b/c)
\end{verbatim}
$$a^{{{b}\over{c}}}$$
\begin{verbatim}
a^-(b/c)
\end{verbatim}
$${{1}\over{a^{{{b}\over{c}}}}}$$
\begin{verbatim}
a^((-b)/c)
\end{verbatim}
$${{1}\over{a^{{{b}\over{c}}}}}$$
\begin{verbatim}
a^(1/c)
\end{verbatim}
$$a^{{{1}\over{c}}}$$
\begin{verbatim}
a^-(1/c)
\end{verbatim}
$${{1}\over{a^{{{1}\over{c}}}}}$$
\begin{verbatim}
a^((-1)/c)
\end{verbatim}
$${{1}\over{a^{{{1}\over{c}}}}}$$
\begin{verbatim}
(1+(1-x)^((y-z)/(y-w)))/(2*u-v)^(1/(n+1))
\end{verbatim}
$${{\left(1-x\right)^{{{y-z}\over{y-w}}}+1}\over{\left(2\,u-v\right)^{{{1}\over{n+1}}}}}$$
\begin{verbatim}
a^(b/c)
\end{verbatim}
$$\sqrt[c]{a^{b}}$$
\begin{verbatim}
a^-(b/c)
\end{verbatim}
$${{1}\over{\sqrt[c]{a^{b}}}}$$
\begin{verbatim}
a^((-b)/c)
\end{verbatim}
$${{1}\over{\sqrt[c]{a^{b}}}}$$
\begin{verbatim}
a^(1/c)
\end{verbatim}
$$\sqrt[c]{a}$$
\begin{verbatim}
a^-(1/c)
\end{verbatim}
$${{1}\over{\sqrt[c]{a}}}$$
\begin{verbatim}
a^((-1)/c)
\end{verbatim}
$${{1}\over{\sqrt[c]{a}}}$$
\begin{verbatim}
(1+(1-x)^((y-z)/(y-w)))/(2*u-v)^(1/(n+1))
\end{verbatim}
$${{\sqrt[y-w]{\left(1-x\right)^{y-z}}+1}\over{\sqrt[n+1]{2\,u-v}}}$$
\begin{verbatim}
a^(b/c)
\end{verbatim}
$$a^{{{b}\over{c}}}$$
\begin{verbatim}
a^-(b/c)
\end{verbatim}
$${{1}\over{a^{{{b}\over{c}}}}}$$
\begin{verbatim}
a^((-b)/c)
\end{verbatim}
$${{1}\over{a^{{{b}\over{c}}}}}$$
\begin{verbatim}
a^(1/c)
\end{verbatim}
$$a^{{{1}\over{c}}}$$
\begin{verbatim}
a^-(1/c)
\end{verbatim}
$${{1}\over{a^{{{1}\over{c}}}}}$$
\begin{verbatim}
a^((-1)/c)
\end{verbatim}
$${{1}\over{a^{{{1}\over{c}}}}}$$
\begin{verbatim}
(1+(1-x)^((y-z)/(y-w)))/(2*u-v)^(1/(n+1))
\end{verbatim}
$${{\left(1-x\right)^{{{y-z}\over{y-w}}}+1}\over{\left(2\,u-v\right)^{{{1}\over{n+1}}}}}$$
\end{document}
于 2021-01-14T03:29:27.010 に答える