Polynomial Long Division over GF(p)
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.
Based on Leo's answer but I
- removed one column.
- replaced the
\big)
with a vertical rule. - made all rows have equal width.
\documentclass{article}
\usepackage{amssymb}
\usepackage{array}
\newcommand{\x}[1]{\multicolumn{1}{|r}{#1}}
\begin{document}
\[
x^3 - x + 1 = (x-1)(x^2+x) + 1 \in \mathbb{F}_3[x]
\]
\[
\renewcommand\arraystretch{1.2}% specify the vertical stretch
\begin{array}{*{6}{>{\hfill}m{7mm}}}%specify the column width
&
&
&
1&
1&
0\\\cline{3-6}
1&
-1&
\x{1}&
0&
-1&
1\\
&
&
1&
-1&
&
\\\cline{3-5}
&
&
&
1&
-1&
\\
&
&
&
1&
-1&
\\\cline{4-6}
&
&
&
&
&
1\\
\end{array}
\]
\end{document}