# [Tex/LaTex] Polynomial Long Division over GF(p)

math-mode

Is there a package like polynom for typesetting polynomial long division but over a finite field such as GF(2). If not, how to manually typeset long division in general?

Thanks.

I attempted the following solution! However, the vertical spacing between each line and exponents of the equation below it is quite small, how to increase it? I tried \vspace but received errors. Thanks.

$\begin{array}{m{3.5em}ccccccccc} & & & & &+x^4&+x^3& & &+1\\ \cline{2-10} \multicolumn{2}{l}{x^3+x+1\big)} &+x^7&+x^6&+x^5& & &+x^2&+x& \\ & &+x^7& &+x^5&+x^4& & & & \\ \cline{3-6} & & &+x^6& &+x^4& & & & \\ & & &+x^6& &+x^4&+x^3& & & \\ \cline{4-7} & & & & & &+x^3&+x^2&+x& \\ & & & & & &+x^3& &+x&+1\\ \cline{7-10} & & & & & & &+x^2& &+1\\ \end{array}$


I'm afraid there isn't such a package to do calculations over finite fields. Arithmetic over finite fields GF(p^n) may be too complex for TeX. GF(2) and GF(p) are much easier, but there seems no such a package either.

To typeset long division manually, you can simply use an array. For example:

\documentclass{article}
\usepackage{amssymb}

\begin{document}

$x^3 - x + 1 = (x-1)(x^2+x) + 1 \in \mathbb{F}_3[x]$

$\renewcommand\arraystretch{1.2} \begin{array}{*2r @{\hskip\arraycolsep}c@{\hskip\arraycolsep} *4r} & && & 1 & 1 & 0 \\ \cline{3-7} 1 & -1 &\big)& 1 & 0 & -1 & 1 \\ & && 1 & -1 \\ \cline{4-6} & && & 1 & -1 \\ & && & 1 & -1 \\ \cline{5-7} & && & & & 1 \\ \end{array}$

\end{document}


If you need a lot of these long divisions, it is worth to write a program (not necessarily in TeX) to generate the code. It's not very difficult for polynomials over GF(p).

For edited question:

To increase the vertical space between array lines, you can redefine the factor \arraystretch as showed above. Or you can use makecell package to add a gap.