Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to typeset long division?

361 views
Skip to first unread message

Rodney B. Roeber

unread,
Oct 3, 1996, 3:00:00 AM10/3/96
to

Hi,

I need to include an example dividing polynomials using long division
in a document.
For example, I want to perform: x^9 + x^6 + x^5 + x / x^4 + x^3 + 1
I would like to use the "real" symbol (sort of looks like the square root
symbol) and have
the divisor on the left, the dividend under the division symbol and the
quotient above the symbol.
I need to show each step so the intermediate results must be lined up in
the proper
columns with the remainder on the lowest row.
I've looked through three TeX/LaTeX manuals without any success. I have
never attempted
to define a symbol before in LaTeX. If someone has already developed a
tool which will do this,
I would like to use it. Otherwise, I'll see if I can develop it. I would
appreciate
hints/suggestions/pointers. Thanks.

Rod
roe...@flinthills.com

Donald Arseneau

unread,
Oct 3, 1996, 3:00:00 AM10/3/96
to

In article <01bbb0d7$b960b2c0$e97ff0c7@roeberr>, "Rodney B. Roeber" <roe...@flinthills.com> writes...

> I need to include an example dividing polynomials using long division

I have long-division macros for integers, but they are not on CTAN according
to my notes.

The division is done in an alignment (\halign) and the first two
rows go like:

% longdiv.tex v.1 (1994) Donald Arseneau
%
% Work out and print integer long division problems. Use:
% \longdiv{numerator}{denominator}
% The numerator and denominator (divisor and dividend) must be integers, and
% the quotient is an integer too. \longdiv leaves a remainder.
% Use this in any type of TeX.

\newcount\gpten % (global) power-of-ten -- tells which digit we are doing
\countdef\rtot2 % running total -- remainder so far
\countdef\LDscratch4 % scratch

\vtop{\normalbaselines \offinterlineskip
\tabskip=0pt
\halign{\hfil##\cr % \halign for entire division problem
$\quotient$\strut\cr
#2$\,\overline{\vphantom{\big)}%
\hbox{\smash{\raise3.5\fontdimen8\textfont3\hbox{$\big)$}}}%
\mkern2mu \the\rtot}$\cr

(for \rtot / #2 = \quotient).

Donald Arseneau as...@reg.triumf.ca

Jean-Pierre Drucbert

unread,
Oct 4, 1996, 3:00:00 AM10/4/96
to

There is a little package for long divisions:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CUT HERE %%%%%%%%%%%%%%%%%%%%%%%%%

\newcount\gpten % (global) power-of-ten -- tells which digit we are doing
\newcount\rtot % running total -- remainder so far
\newcount\scratch

\def\longdiv#1#2{% long division: #1/#2; integers only, gives integer quotient and remainder
\vtop{\offinterlineskip
\setbox\strutbox\hbox{\vrule height 2.1ex depth .5ex width0ex}%
\def\showdig{$\underline{\the\scratch\strut}$\cr\the\rtot\strut\cr
\noalign{\kern-.2ex}}%
\global\rtot=#1\relax
\count0=\rtot\divide\count0by#2\edef\quotient{\the\count0}%\show\quotient
% make list macro out of digits in quotient:
\def\temp##1{\ifx##1\temp\else \noexpand\dodig ##1\expandafter\temp\fi}%
\edef\routine{\expandafter\temp\quotient\temp}%
% process list to give power-of-ten:
\def\dodig##1{\global\multiply\gpten by10\relax}\global\gpten=1\relax\routine
% to display effect of one digit in quotient (zero ignored):
\def\dodig##1{\global\divide\gpten by10\relax
\scratch =\gpten
\multiply\scratch by##1\relax
\multiply\scratch by#2\relax
\global\advance\rtot-\scratch \relax
\ifnum\scratch>0 \showdig \fi % must hide \cr in a macro to skip it
}%


\tabskip=0pt
\halign{\hfil##\cr % \halign for entire division problem
$\quotient$\strut\cr
#2$\,\overline{\vphantom{\big)}%

\smash{\raise3.5\fontdimen8\textfont3\hbox{$\big)$}}%

\mkern2mu \the\rtot}$\cr\noalign{\kern-.2ex}
\routine \cr % do each digit in quotient
}}}
\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CUT %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% EXAMPLES %%%%%%%%%%%%%%%%%%
\noindent Here are some long division problems

\indent
\longdiv{12345}{13} \quad
\longdiv{123}{1234} \quad
\longdiv{31415926}{2} \quad
\longdiv{81}{3} \quad
\longdiv{1132}{99} \quad
\longdiv{86491}{94}
%%%%%%%%%%%%%%%%%%%%%%%% CUT %%%%%%%%%%%%%%%%%%%%%%%%%%%%

This package was written by the prolific and irreplaceable
(is it the true englih word?) Donald Arseneau (as...@reg.triumf.ca).
Thanks to him.

--
Jean-Pierre Drucbert
CERT/ONERA GPI
Centre d'\'Etudes et de Recherches de Toulouse
de l'Office National d'\'Etudes et de Recherches A\'erospatiales
Groupe de Prestations Informatiques
Complexe Scientifique de Rangueil
2, Avenue \'Edouard Belin
BP 4025 F-31055 TOULOUSE CEDEX
FRANCE

Telephone +33-62-25-25-15

Email: druc...@onecert.fr

0 new messages