Tx · LaTeX & TikZ

How to Typeset Multivariate Polynomial Long Division in LaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose a monomial order

    State the order because it determines which terms are leading and can change the quotient and remainder.

  2. 2. Find the leading terms

    Divide the dividend's leading term by the divisor's leading term to get the next quotient term.

  3. 3. Subtract and repeat

    Multiply the divisor by that quotient term, subtract, and continue while a leading term is divisible.

  4. 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 x>yx>y: compare powers of xx first, then powers of yy if the xx 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 x+yx+y

Divide x2+xy+y2x^2+xy+y^2 by x+yx+y, using lexicographic order x>yx>y. The leading terms are x2x^2 and xx, so the first quotient term is x2/x=xx^2/x=x. Multiplying the divisor by xx gives x2+xyx^2+xy; subtracting leaves y2y^2.

The term y2y^2 is not divisible by the divisor’s leading monomial xx, so move it into the remainder. No terms remain to process. Thus

x2+xy+y2=(x+y)x+y2.x^2+xy+y^2=(x+y)x+y^2.

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 y>xy>x, the leading term of the dividend is y2y^2, and the leading term of the divisor is yy. The first quotient term is then yy. Subtracting y(x+y)=xy+y2y(x+y)=xy+y^2 leaves x2x^2, which is not divisible by the divisor’s leading monomial yy. The result is therefore quotient yy and remainder x2x^2 under this order:

x2+xy+y2=(x+y)y+x2.x^2+xy+y^2=(x+y)y+x^2.

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 array only 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: \phantom is useful for aligning one row, but long expressions can become fragile. For a less rigid display, write each algebraic step in an aligned environment and let the equations carry the explanation.

References

  1. The polynom package — CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.