Maxima:数字一般根的求解,超出sqrt?

3
我想知道Maxima是否有sqrt函数的概括?特别是,我想控制x^(a/b)的显示方式,使其显示为$x^{\frac{a}{b}}$$\sqrt[b]{x^{a}}$
我在文档的索引中搜索了root但没有找到任何相关的内容,并且sqrtdispflag条目中也没有任何链接。

1
我猜你只想在TeX中获得那种输出,而不是在Maxima或wxMaxima中显示;对吗? - Robert Dodier
@RobertDodier 是的 - Maxima 中的显示对我的目的并不重要。谢谢! - Rax Adaam
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}

1
我完全被震撼了,罗伯特:我无言以对。你的支持和帮助是难以置信的:我们整个团队都非常感激。谢谢! - Rax Adaam
1
嘿,没问题,我很高兴能帮忙。Maxima包含一些有趣的想法,这使得解决问题变得更加有趣。谢谢你的赞美之词,继续保持好工作。 - Robert Dodier

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接