tex - (wx)Maxima : general roots of numbers, 超出 sqrt?

标签 tex maxima wxmaxima

我想知道 Maxima 中是否有 sqrt 函数的泛化?特别是,我希望能够控制 x^(a/b) 是否显示为 $x^{\frac{a}{b}}$$\sqrt[b]{x^{a}}$

我搜索了 root 的文档索引,但没有找到任何我可以识别为相关的内容,并且 sqrtdispflag 条目中没有任何链接.

最佳答案

这是一个有趣的问题,再次表明 Maxima 可以从更灵活的 TeX 输出系统中受益,但我离题了。这是一个可能的解决方案。

这使用模式匹配(在 defmatch 中)来识别 something-to-a-quotient 表达式以供进一步处理,如果匹配成功则提取商的分子和分母。模式匹配器无法识别像 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}

关于tex - (wx)Maxima : general roots of numbers, 超出 sqrt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65689845/

相关文章:

function - Maxima:强制函数仅使用局部变量运行?/如何避免局部操作影响全局变量?

pdf - 保持尺寸的 JPEG 到 EPS 转换

javascript - MathJax 将宏定义为最终或最后一个

lisp - 用 maxima 语言编码 vs lisp

maxima - wxMaxima:如何使用texput告诉tex1如何处理字符串?

list - (wx)最大: does `makelist` work in parallel or serially?

latex - TeX:在每个内容页后添加空白页

java - Java 中的完整 LaTeX 解析器

plot - 在 Maxima 中显示 3D 函数的有组织的自上而下 View

symbolic-math - 最大值:将矩阵转换为列表