使用多項式時如何對齊商

使用多項式時如何對齊商

我正在使用該polynom包來說明多項式的長除法。通常,當我手動解決這些問題時,我會將商數中的第一項與紅利中的第一項對齊。然而,正如下面的程式碼所示,對齊本質上就是我所需要的。

在此輸入影像描述

\documentclass{article}
\usepackage{polynom}

\begin{document}
\polylongdiv{2x^4+7x^3+8x^2+5x+4}{x^3+x^2+x+1}
\end{document}

有沒有辦法將商數的 2 與被除數的 2 對齊?

答案1

簡答

\documentclass{article}
    \usepackage{polynom}
\begin{document}
    \makeatletter
    \let\oldpld@SplitQuotient\pld@SplitQuotient
    \def\pld@SplitQuotient{\oldpld@SplitQuotient\def\pld@pattern{}}
    \polylongdiv{X^9-X^8-X^5+X^4+X+1}{X-1}
\end{document}

長答案

經過一些實驗後,人們可能會注意到polynom在列印非連續單項式時會留下一些漏洞。

該機制是polynom用作\pld@pattern佔位符。因為紅利的次數是 9,\pld@pattern所以是X^9+X^8+...+1(有點)。

然後它開始匹配\pld@quotient\pld@pattern。在本例中,請X^8轉到X^8-X^4轉到X^4。當polynom嘗試列印股息時也會發生同樣的情況。這就是商與紅利X^8一致的原因。-X^8

為了解決這個問題,我們需要用更短的佔位符來取代佔位符。

但那樣的話就會是不太聰明如果我們必須手動指派佔位符。好消息是,用任何東西替換佔位符都不會強制polynom(重新)產生更短的佔位符。現在它應該就是你想要的了。

剩下的問題是去哪裡更換呢?這裡我在\def\pld@pattern{}後面添加一個\pld@SplitQuotient只是因為polynom要打印商。

\documentclass{article}
    \usepackage{polynom}
    \usepackage[active,floats,tightpage]{preview}
\begin{document}
    \makeatletter
    \let\oldpld@SplitQuotient\pld@SplitQuotient
    \begin{figure}
        \polylongdiv{X^9-X^8-X^5+X^4+X+1}{X-1}
    \end{figure}
    \begin{figure}
        \def\pld@SplitQuotient{\oldpld@SplitQuotient\def\pld@pattern{}}
        \polylongdiv{X^9-X^8-X^5+X^4+X+1}{X-1}
    \end{figure}
    \begin{figure}
        \def\pld@SplitQuotient{\oldpld@SplitQuotient
            \def\pld@quotient{\pld@V{X}{9}+\pld@V{X}{8}+\pld@V{X}{7}+\pld@V{X}{6}+\pld@V{X}{5}+\pld@V{X}{4}+\pld@V{X}{3}+\pld@V{X}{2}+\pld@V{X}{1}+\pld@R 11}}
        \polylongdiv{X^9-X^8-X^5+X^4+X+1}{X-1}
    \end{figure}
    \begin{figure}
        \def\pld@SplitQuotient{\oldpld@SplitQuotient\def\pld@pattern{}
            \def\pld@quotient{\pld@V{X}{8}+\pld@V{X}{7}+\pld@V{X}{6}+\pld@V{X}{5}+\pld@V{X}{4}+\pld@V{X}{3}+\pld@V{X}{2}+\pld@V{X}{1}+\pld@R 11}}
        \polylongdiv{X^9-X^8-X^5+X^4+X+1}{X-1}
    \end{figure}
\end{document}

相關內容