How to Typeset Multivariate Polynomial Long Division in LaTeX
At a glance
- 1. Choose a monomial order
State the order because it determines which terms are leading and can change the quotient and remainder.
- 2. Find the leading terms
Divide the dividend's leading term by the divisor's leading term to get the next quotient term.
- 3. Subtract and repeat
Multiply the divisor by that quotient term, subtract, and continue while a leading term is divisible.
- 4. Format the work
Use an array for the visual layout, or aligned equations for a compact, readable derivation.
LaTeX can display multivariate polynomial long division, but the usual approach is to build the layout yourself. The array environment gives you control over columns and rules; it does not perform the algebra. You must also specify a monomial order, since that order determines which term to divide at each step.
Choose a monomial order first
In one variable, the leading term is simply the term with the highest power. In several variables, you need a rule for comparing monomials. A common choice is lexicographic order with : compare powers of first, then powers of if the powers tie.
For division by a single polynomial over a field, consider the current leading term at each step. If it is divisible by the divisor’s leading monomial, divide the leading terms, multiply the divisor by the result, and subtract. If it is not divisible, move that term into the remainder and continue with the remaining terms. Stop when no terms remain to process; the remainder then has no term divisible by the divisor’s leading monomial. With several divisors, the order in which you use them can also affect the quotient and remainder.
Worked example: divide by
Divide by , using lexicographic order . The leading terms are and , so the first quotient term is . Multiplying the divisor by gives ; subtracting leaves .
The term is not divisible by the divisor’s leading monomial , so move it into the remainder. No terms remain to process. Thus
Here is one way to display the steps in LaTeX:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{r|l}
& x \\
\cline{2-2}
x+y & x^2+xy+y^2 \\
& -(x^2+xy) \\
\cline{2-2}
& \phantom{x^2+xy+}y^2
\end{array}
\]
\end{document}
The two columns hold the divisor and the work; the vertical rule separates them. The quotient is placed above the dividend. \cline{2-2} draws a horizontal rule across only the second column, and \phantom{...} reserves invisible space so the remainder sits approximately under its position in the dividend. This is a typesetting choice, not a requirement of the division algorithm. Adjust the spacing or alignment if your own expressions need it.
Why the order matters
With lexicographic order , the leading term of the dividend is , and the leading term of the divisor is . The first quotient term is then . Subtracting leaves , which is not divisible by the divisor’s leading monomial . The result is therefore quotient and remainder under this order:
Both decompositions are valid. This is why a multivariate long-division display should name its monomial order rather than imply that there is one universal answer.
When to use polynom
The polynom package provides tools for polynomial typesetting and operations, including long-division notation for ordinary univariate polynomials. It is not a substitute for specifying a multivariate monomial order or carrying out a general multivariate division algorithm. For a multivariate worked calculation, a hand-built array or a sequence of aligned equations is often the clearest option.
Common mistakes
- Leaving out the monomial order: Without it, “leading term” may be ambiguous, and the division result may not be reproducible.
- Expecting LaTeX to calculate the division: An
arrayonly lays out material you provide. Check each multiplication and subtraction yourself. - Stopping at the first nondivisible leading term: Move that term into the remainder and continue processing the remaining terms. The algorithm ends when no terms remain to process; the remainder has no term divisible by the divisor’s leading monomial.
- Overusing spacing commands:
\phantomis useful for aligning one row, but long expressions can become fragile. For a less rigid display, write each algebraic step in analignedenvironment and let the equations carry the explanation.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.