%%
%% This is file `polynom.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% polynom.dtx  (with options: `package')
%% 
%% The files  polynom.dtx  and  polynom.ins  and all files generated
%% from these two files are referred to as `this work'.
%% 
%% This work is copyright 2000-2017 Carsten Heinz, Hendri Adriaens.
%% 
%% This work may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3 of this
%% license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Hendri Adriaens.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{polynom}[2017/07/17 0.19 (CH,HA)]
\def\pld@AddTo#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\pld@Extend#1#2{%
    \expandafter\pld@AddTo\expandafter#1\expandafter{#2}}
\def\pld@ExpandTwo#1#2#3{%
    \expandafter\def\expandafter\pld@temp\expandafter{#2}%
    \pld@Extend\pld@temp{#3}%
    \expandafter#1\pld@temp}
\def\pld@true{\let\pld@if\iftrue}
\def\pld@false{\let\pld@if\iffalse}
\pld@false
\RequirePackage{keyval}[1997/11/10]
\def\polyset{\setkeys{pld}}
\def\pld@IfVar#1{%
    \def\pld@temp##1,#1,##2##3\relax{%
        \ifx\@empty##3\@empty \expandafter\@secondoftwo
                        \else \expandafter\@firstoftwo \fi}%
    \expandafter\pld@temp\pld@variables,#1,\@empty\relax}
\define@key{pld}{vars}{%
  \let\pld@variables\@empty
  \@tfor\pld@temp:=#1\do{%
    \pld@Extend\pld@variables{\expandafter,\pld@temp}%
    \edef\pld@temp{%
      \noexpand\define@key{pld}{\pld@temp}%
      {\noexpand\pld@GetValue{\pld@temp}{####1}}%
    }%
    \pld@temp
  }%
}
\def\pld@GetValue#1#2{%
  \pld@GetPoly{\pld@polya}{}{#2}%
  \ifx\pld@polya\@empty\def\pld@polya{\pld@R 01}\fi
  \expandafter\let\csname pld@value@#1\endcsname\pld@polya
}
\polyset{vars=Xx}
\define@key{pld}{style}
    {\@ifundefined{pld@style#1}%
         {\PackageError{polynom}{Unknown style `#1'}%
          {Arguments can be `A' or `B' or `C' or `D'.}}%
         {\let\pld@style=#1%
          \@nameuse{pld@style#1}}}
\def\pld@styleA{\let\pld@iftopresult\iftrue}
\def\pld@styleB{\let\pld@iftopresult\iffalse}
\let\pld@styleC\pld@styleB
\let\pld@styleD\pld@styleB
\polyset{style=A}
\define@key{pld}{delims}
    {\@ifnextchar[\pld@delims
                  {\pld@delims[{}{}]}#1{}{}}
\def\pld@delims[#1#2]#3#4{%
    \def\pld@leftxdelim{#1}\def\pld@rightxdelim{#2}%
    \def\pld@leftdelim{#3}\def\pld@rightdelim{#4}}
\polyset{delims=[{\left.}{\right.}]{\left(}{\right)}}
\define@key{pld}{div}{\def\pld@div{#1}}
\polyset{div=\div}
\define@key{pld}{stage}{%
    \@tempcnta#1\relax \ifnum\@tempcnta<\@ne \@tempcnta\@ne \fi
    \edef\pld@stage{\the\@tempcnta}}
\newcount\pld@currstage
\newcommand*\polymul[1]{%
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\pld@MultiplyPoly#1\pld@polya\pld@polyb
                 \ignorespaces}}
\newcommand*\polydiv[1]{%
    \begingroup
    \let\pld@stage\maxdimen
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\pld@DividePoly\pld@polya\pld@polyb
                 \let#1\pld@quotient
                 \let\polyremainder\pld@remainder
                 \pld@RestoreAftergroup#1\polyremainder\relax
    \endgroup\ignorespaces}}
\newif\ifpld@InsidePolylongdiv
\newcommand*\polylongdiv[1][]{%
    \begingroup\pld@InsidePolylongdivtrue
    \let\pld@stage\maxdimen \polyset{#1}%
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\pld@LongDividePoly\pld@polya\pld@polyb
                 \pld@PrintLongDiv
    \endgroup \ignorespaces}}
\newcommand*\polylonggcd[1][]{%
    \begingroup
    \let\pld@stage\maxdimen \polyset{#1}%
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\pld@LongEuclideanPoly\pld@polya\pld@polyb
                 \pld@PrintLongEuclidean
    \endgroup \ignorespaces}}
\newcommand*\polygcd[1]{%
    \begingroup
    \let\pld@stage\maxdimen
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\pld@LongEuclideanPoly\pld@polya\pld@polyb
                 \global\let\@gtempa\pld@vb
    \endgroup \let#1\@gtempa \ignorespaces}}
\newcommand*\polyfactorize{%
    \pld@GetPoly\pld@current
                {\pld@Factorize\pld@current \ensuremath{\pld@allines}}}
\newcommand*\polyprint{%
    \pld@GetPoly{\pld@polya}%
                {\ensuremath{\pld@PrintPoly\pld@polya}}}
\newcommand*\polyadd[1]{%
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\let#1\pld@polya \pld@ExtendPoly#1\pld@polyb
                 \pld@Simplify#1%
                 \ignorespaces}}
\newcommand*\polysub[1]{%
    \pld@GetPoly{\pld@polya\pld@polyb}%
                {\def\pld@tempoly{\pld@R{-1}1}%
                 \pld@MultiplyPoly\pld@polyb\pld@polyb\pld@tempoly
                 \let#1\pld@polya \pld@ExtendPoly#1\pld@polyb
                 \pld@Simplify#1%
                 \ignorespaces}}
\def\pld@RestoreAftergroup{%
    \global\let\@gtempa\@empty
    \pld@RestoreAfter@}
\def\pld@RestoreAfter@#1{%
    \ifx\relax#1%
        \aftergroup\@gtempa
    \else
        \global\pld@Extend\@gtempa{\expandafter\def\expandafter#1%
                                   \expandafter{#1}}%
        \expandafter\pld@RestoreAfter@
    \fi}
\def\pld@SplitMonom#1#2{%
    \pld@SplitMonom@#2\pld@V\relax {\pld@SplitMonom@V#1#2\relax}%
                                   {#1{#2}{}}}
\def\pld@SplitMonom@#1\pld@V#2\relax{%
    \ifx\@empty#2\@empty \expandafter\@secondoftwo
                   \else \expandafter\@firstoftwo \fi}
\def\pld@SplitMonom@V#1#2\pld@V#3\relax{#1{#2}{\pld@V#3}}
\def\pld@SplitMonomS#1#2{%
    \pld@SplitMonomS@#2\pld@S\relax {\pld@SplitMonomS@S#1#2\relax}%
                                   {#1{#2}{}}}
\def\pld@SplitMonomS@#1\pld@S#2\relax{%
    \ifx\@empty#2\@empty \expandafter\@secondoftwo
                   \else \expandafter\@firstoftwo \fi}
\def\pld@SplitMonomS@S#1#2\pld@S#3\relax{#1{#2}{\pld@S#3}}
\def\pld@IfSum#1{\pld@IfSum@#1+\@empty+\relax+}
\def\pld@IfSum@#1+#2+\relax+{%
    \ifx\@empty#2\@empty \expandafter\@secondoftwo
                   \else \expandafter\@firstoftwo \fi}
\def\pld@DefNegative#1#2{\pld@DefNegative@#1#2\@empty}
\def\pld@DefNegative@#1#2#3#4#5\@empty{%
    \ifx #2\pld@R\def#1{\pld@R{-#3}{#4}#5}%
           \else \def#1{\pld@R{-1}1#2{#3}{#4}#5}\fi}
\def\pld@DefInverse#1#2{%
    \let#1\@empty
    \pld@DefInverse@#1#2\relax\@empty\@empty}
\def\pld@DefInverse@#1#2#3#4{%
    \ifx\relax#2\relax \expandafter\@gobbletwo \else
        \ifx #2\pld@R \pld@AddTo#1{\pld@R{#4}{#3}}\else
        \ifx #2\pld@F \pld@AddTo#1{\pld@F{#4}{#3}}\else
        \ifx #2\pld@S \pld@AddTo#1{\pld@S{#3}{-#4}}\else
        \ifx #2\pld@V \pld@AddTo#1{\pld@V{#3}{-#4}}\else
            \pld@DIError
        \fi \fi \fi \fi
    \fi
    \pld@DefInverse@#1}
\def\pld@AddToPoly#1#2{%
    \ifx #1\@empty \def#1{#2}\else
                   \pld@AddTo#1{+#2}\fi}
\def\pld@ExtendPoly#1#2{%
    \ifx #1\@empty \pld@Extend#1{#2}\else
    \ifx #2\@empty
             \else \pld@Extend#1{\expandafter+#2}\fi \fi}
\def\pld@R{r}
\def\pld@F{f}
\def\pld@S{s}
\def\pld@V{v}
\def\pld@GetPoly#1#2{%
    \def\pld@pool{#1}\def\pld@aftermacro{#2}%
    \pld@GetPoly@}
\def\pld@GetPoly@{%
    \@ifnextchar\bgroup \pld@GetPolyArg\pld@GetPolyLet}
\def\pld@GetPolyArg#1{%
    \pld@Scan{#1}%
    \pld@GetPolyLet\pld@tempoly}
\def\pld@GetPolyLet{\expandafter\pld@GetPolyLet@\pld@pool\relax}
\def\pld@GetPolyLet@#1#2\relax#3{%
    \let#1#3\def\pld@pool{#2}%
    \pld@Simplify#1%
    \ifx\pld@pool\@empty \expandafter\pld@aftermacro
                   \else \expandafter\pld@GetPoly@ \fi}
\def\pld@ScanBegingroup{\begingroup \let\pld@tempoly\@empty}
\def\pld@ScanEndgroup{\pld@ScanSetA \endgroup}
\def\pld@ScanSetA{\global\let\@gtempa\pld@tempoly}
\def\pld@ScanSetB{\let\pld@tempoly\@gtempa}
\def\pld@Scan#1{%
    \let\pld@tempoly\@empty
      \pld@ScanOpen(#1\relax
    \pld@ScanEndgroup \pld@ScanEndgroup}
\def\pld@ScanIt#1{%
    \ifx \relax#1\let\pld@next\@gobble \else
    \ifx +#1\let\pld@next\pld@ScanAdd\else
    \ifx -#1\let\pld@next\pld@ScanSubtract\else
    \ifx *#1\let\pld@next\pld@ScanMultiply\else
    \ifx \cdot#1\let\pld@next\pld@ScanMultiply\else
    \ifx /#1\let\pld@next\pld@ScanDivide\else
    \ifx )#1\let\pld@next\pld@ScanClose\else
    \ifx ^#1\let\pld@next\pld@ScanPower\else
        \ifx \frac#1\let\pld@next\pld@ScanFrac\else
        \ifx (#1\let\pld@next\pld@ScanOpen\else
            \pld@IfNumber{#1}%
                {\let\pld@next\pld@ScanNumeric}%
                {\pld@IfVar{#1}{\let\pld@next\pld@ScanVar}%
                               {\let\pld@next\pld@ScanSymbol}}%
        \fi \fi
    \fi \fi \fi \fi \fi \fi \fi \fi
    \pld@next #1}
\def\pld@IfNumber#1{%
    \def\pld@temp##1#1##2##3\relax{%
        \ifx\@empty##2\@empty \expandafter\@secondoftwo
                        \else \expandafter\@firstoftwo \fi}%
    \pld@temp 0123456789#1\@empty\relax}
\def\pld@ScanOpen({%
    \ifx\@empty\pld@tempoly\else
        \pld@ScanMultiplyBase\pld@ScanBbyA
    \fi
    \pld@ScanBegingroup \aftergroup\pld@ScanSetB
    \pld@ScanBegingroup \aftergroup\pld@ScanSetB
    \pld@ScanIt}
\def\pld@ScanClose){%
    \pld@ScanEndgroup \pld@ScanEndgroup \pld@ScanSetA
    \pld@ScanIt}
\def\pld@ScanAdd+{\pld@ScanAddBase\pld@ScanAtoB}
\def\pld@ScanSubtract-{\pld@ScanAddBase\pld@ScanAfromB}
\def\pld@ScanAddBase#1{%
    \pld@ScanEndgroup \pld@ScanEndgroup
    \pld@ScanBegingroup \aftergroup#1%
    \pld@ScanBegingroup \aftergroup\pld@ScanSetB
    \pld@ScanIt}
\def\pld@ScanAtoB{\pld@ExtendPoly\pld@tempoly\@gtempa}
\def\pld@ScanAfromB{\pld@ExtendPoly\pld@tempoly{\@gtempa\pld@R{-1}1}}
\def\pld@ScanMultiply#1{\pld@ScanMultiplyBase\pld@ScanBbyA \pld@ScanIt}
\def\pld@ScanDivide/{\pld@ScanMultiplyBase\pld@ScanDivBbyA \pld@ScanIt}
\def\pld@ScanMultiplyBase{%
    \pld@ScanEndgroup \pld@ScanBegingroup \aftergroup}
\def\pld@ScanBbyA{\pld@MultiplyPoly\pld@tempoly\pld@tempoly\@gtempa}
\def\pld@ScanDivBbyA{%
    \def\pld@temp{\pld@F{}}%
    \pld@Extend\pld@temp{\expandafter{\@gtempa}}%
    \pld@Extend\pld@tempoly\pld@temp}
\def\pld@ScanPower^#1{%
    \let\pld@polya\pld@tempoly
    \@multicnt#1\relax
    \loop \ifnum\@multicnt>\@ne
        \advance\@multicnt\m@ne
        \pld@MultiplyPoly\pld@tempoly\pld@tempoly\pld@polya
    \repeat
    \pld@ScanIt}
\def\pld@ScanImplicitMultiply{%
    \expandafter\pld@IfSum\expandafter{\pld@tempoly}%
        {\pld@ScanMultiplyBase\pld@ScanBbyA}%
        {}}
\def\pld@ScanNumeric{%
    \pld@ScanImplicitMultiply
    \let\pld@temp\frac \let\frac\relax
    \afterassignment\pld@ScanNumeric@ \@tempcnta}
\def\pld@ScanNumeric@#1{%
    \let\frac\pld@temp
    \ifx #1.%
        \PackageError{polynom}{noninteger constants not supported}%
        {Constants must be integers in TeX's word range.\MessageBreak
         The fractional part will be lost.}%
        \def\pld@next##1{\afterassignment\pld@ScanIt\@tempcnta}%
    \else
        \let\pld@next\pld@ScanIt
    \fi
    \pld@Extend\pld@tempoly
        {\expandafter\pld@R\expandafter{\the\@tempcnta}1}%
    \pld@next #1}
\def\pld@ScanVar{\pld@ScanImplicitMultiply \pld@ScanVS\pld@V}
\def\pld@ScanSymbol{\pld@ScanImplicitMultiply \pld@ScanVS\pld@S}
\def\pld@ScanVS#1#2{%
    \@ifnextchar^{\pld@ScanVS@u#1{#2}}%
                 {\@ifnextchar_{\pld@ScanVar@l#1{#2}}%
                               {\pld@AddTo\pld@tempoly{#1{#2}1}%
                                \pld@ScanIt}}}
\def\pld@ScanVS@u#1#2^#3{%
    \@ifnextchar_{\pld@ScanVS@ul#1{#2}{#3}}%
                 {\pld@AddTo\pld@tempoly{#1{#2}{#3}}\pld@ScanIt}}
\def\pld@ScanVS@l#1#2_#3{%
    \@ifnextchar^{\pld@ScanVS@lu#1{#2}{#3}}%
                 {\pld@AddTo\pld@tempoly{#1{#2_{#3}}1}\pld@ScanIt}}
\def\pld@ScanVS@ul#1#2#3_#4{%
    \pld@AddTo\pld@tempoly{#1{#2_{#4}}{#3}}\pld@ScanIt}
\def\pld@ScanVS@lu#1#2#3^#4{%
    \pld@AddTo\pld@tempoly{#1{#2_{#3}}{#4}}\pld@ScanIt}
\def\pld@ScanFrac#1#2#3{%
    \pld@ScanImplicitMultiply
    \begingroup
      \pld@Scan{#2}\pld@AddTo\pld@tempoly\relax
      \global\let\@gtempa\pld@tempoly
    \endgroup
    \pld@Extend\pld@tempoly{\expandafter\pld@F\expandafter{\@gtempa}}%
    \begingroup
      \pld@Scan{#3}\pld@AddTo\pld@tempoly\relax
      \global\let\@gtempa\pld@tempoly
    \endgroup
    \pld@Extend\pld@tempoly{\expandafter{\@gtempa}}%
    \pld@ScanIt}
\def\pld@PrintPolyArg#1{%
    \def\pld@temp{#1}\pld@PrintPoly\pld@temp}
\def\pld@PrintPoly#1{%
    \ifx\@empty#1\@empty 0\else
        \pld@firsttrue \expandafter\pld@PrintMonoms#1+\relax+%
    \fi}
\def\pld@PrintPolyWithDelimsArg#1{%
    \def\pld@temp{#1}\pld@PrintPolyWithDelims\pld@temp}
\def\pld@PrintPolyWithDelims#1{%
    \ifx\@empty#1\@empty 0\else
        \pld@firsttrue
        \expandafter\pld@IfSum\expandafter{#1}\pld@true\pld@false
        \pld@if \pld@leftdelim
                \expandafter\pld@PrintMonoms#1+\relax+%
                \pld@rightdelim
          \else \expandafter\pld@PrintMonoms#1+\relax+\fi
    \fi}
\def\pld@PrintInit{%
    \let\pld@R\pld@PrintRational \strut
    \pld@AccuIfNegative
       {\pld@AccuNegate \pld@iffirst\pld@minustrue\else{}\fi -}%
                       {\pld@iffirst\pld@minusfalse\else{}+\fi}%
    \pld@firstfalse
    \pld@AccuIfAbsOne{}{\pld@AccuPrint \pld@true}%
    \let\pld@PrintInit\@empty}
\def\pld@minustrue{\global\let\pld@ifminus\iftrue}
\def\pld@minusfalse{\global\let\pld@ifminus\iffalse}
\def\pld@firsttrue{\global\let\pld@iffirst\iftrue}
\def\pld@firstfalse{\global\let\pld@iffirst\iffalse}
\pld@firstfalse
\def\pld@PrintMonoms#1+{%
    \ifx\relax#1\else
        \begingroup
          \pld@AccuSetX11%
          \let\pld@R\pld@AccuMul
          \let\pld@F\pld@PrintFrac
          \let\pld@S\pld@PrintSymbol
          \let\pld@V\pld@PrintSymbol
          \pld@false
          #1%
          \pld@PrintInit
          \pld@if\else \pld@AccuPrint \fi
        \endgroup
        \expandafter\pld@PrintMonoms
    \fi}
\def\pld@PrintRational#1#2{%
    \pld@true \pld@AccuSetX{#1}{#2}\pld@AccuPrint}
\def\pld@PrintSymbol#1#2{%
    \pld@PrintInit \pld@true #1\ifnum#2=\@ne\else^{#2}\fi}
\def\pld@PrintFrac#1#2{%
    \pld@PrintInit \pld@true
    \ifx\@empty#2\@empty
        \begingroup
          \pld@IfSum{#1}\pld@true\pld@false
          \pld@if\pld@leftdelim #1\pld@rightdelim\else #1\fi
        \endgroup
        \expandafter\@gobbletwo
    \else
        \expandafter\pld@PrintFrac@
    \fi
    {#1}{#2}}
\def\pld@PrintFrac@#1#2{%
    \ifx\@empty#1\@empty \frac1{#2}\else \frac{#1}{#2}\fi}
\def\pld@CondenseFactors#1{%
    \ifx\@empty#1\else
        \begingroup
          \let\pld@R\pld@AccuMul
          \let\pld@F\pld@CondenseFrac
          \let\pld@S\pld@CFSymbol
          \let\pld@V\pld@CFVar
          \let\pld@temp#1\let\pld@tempoly\@empty
          \expandafter\pld@CF@loop\pld@temp+\relax+%
          \global\let\@gtempa\pld@tempoly
        \endgroup
        \let#1\@gtempa
    \fi}
\def\pld@CF@loop#1+{%
    \ifx\relax#1\else
        \begingroup
          \pld@AccuSetX11%
          \def\pld@frac{{}{}}\let\pld@symbols\@empty\let\pld@vars\@empty
          \pld@false
          #1%
          \let\pld@temp\@empty
          \pld@AccuIfZero{}%
          {\pld@AccuIfOne{}{\pld@AccuGet\pld@temp
                            \edef\pld@temp{\noexpand\pld@R\pld@temp}}%
           \pld@if \pld@Extend\pld@temp{\expandafter\pld@F\pld@frac}\fi
           \expandafter\pld@CF@loop@\pld@symbols\relax\@empty
           \expandafter\pld@CF@loop@\pld@vars\relax\@empty
           \ifx\@empty\pld@temp
               \def\pld@temp{\pld@R11}%
           \fi}%
          \global\let\@gtempa\pld@temp
        \endgroup
        \ifx\@empty\@gtempa\else
            \pld@ExtendPoly\pld@tempoly\@gtempa
        \fi
        \expandafter\pld@CF@loop
    \fi}
\def\pld@CF@loop@#1#2{%
    \ifx\relax#1\else
        \xdef\@gtempa{\csname pld@@\string#2\endcsname}%
        \ifnum \@gtempa=\z@ \else
            \pld@AddTo\pld@temp{#1{#2}}%
            \pld@Extend\pld@temp{\expandafter{\@gtempa}}%
        \fi
        \expandafter\pld@CF@loop@
    \fi}
\def\pld@CFSymbol{\pld@CFSV\pld@symbols\pld@S}
\def\pld@CFVar{\pld@CFSV\pld@vars\pld@V}
\def\pld@CFSV#1#2#3#4{%
    \@ifundefined{pld@@\string#3}%
    {\@namedef{pld@@\string#3}{#4}%
     \pld@AddTo#1{#2{#3}}}%
    {\@tempcnta\csname pld@@\string#3\endcsname\relax
     \advance\@tempcnta#4\relax
     \expandafter\edef\csname pld@@\string#3\endcsname{\the\@tempcnta}}}
\def\pld@CondenseFrac#1#2{%
    \pld@IfSum{#1}{\pld@CFFracAdd{\pld@F{#1}{}}{}}%
                  {#1}%
    \pld@IfSum{#2}{\pld@CFFracAdd{}{\pld@F{}{#2}}}%
                  {\begingroup
                     \pld@DefInverse\pld@temp{#2}%
                     \global\let\@gtempa\pld@temp
                   \endgroup
                   \@gtempa}}
\def\pld@CFFracAdd{\pld@true \expandafter\pld@CFFracAdd@\pld@frac}
\def\pld@CFFracAdd@#1#2#3#4{\def\pld@frac{{#1#3}{#2#4}}}
\def\pld@CondenseMonomials#1#2{%
    \ifx\@empty#2\else
        \begingroup
          #1%
          \pld@if\else
              \let\pld@SortVars@V\pld@SortVars@S
              \let\pld@SplitMonom\pld@SplitMonomS
              \pld@SortMonomials#2%
          \fi
          \let\pld@R\pld@CMRational
          \let\pld@F\pld@CMFrac
          \let\pld@S\pld@CMSymbol
          \let\pld@V\pld@CMError
          \let\pld@temp#2\let\pld@tempoly\@empty
          \pld@AccuSetX01\let\pld@symbols\@empty \let\pld@monom\relax
          \expandafter\pld@CM@\pld@temp+\relax+%
          \global\let\@gtempa\pld@tempoly
        \endgroup
        \let#2\@gtempa
    \fi}
\def\pld@CM@#1+{%
    \ifx\relax#1\relax
        \pld@CMAddToTempoly
    \else
        \pld@SplitMonom\pld@CM@do{#1}%
        \expandafter\pld@CM@
    \fi}
\def\pld@CM@do#1#2{%
    \ifx\pld@monom\relax \else
        \def\pld@temp{#2}%
        \ifx\pld@temp\pld@monom \else
            \pld@CMAddToTempoly
            \pld@AccuSetX01\let\pld@symbols\@empty \let\pld@monom\relax
        \fi
    \fi
    \let\pld@op+%
    \ifx\@empty#1\@empty \pld@R11\relax \else #1\relax \fi
    \def\pld@monom{#2}}
\def\pld@CMAddToTempoly{%
    \pld@AccuIfZero{\let\pld@temp\@empty}%
                   {\pld@AccuGet\pld@temp
                    \edef\pld@temp{\noexpand\pld@R\pld@temp}}%
    \pld@CondenseMonomials\pld@false\pld@symbols
    \ifx\pld@symbols\@empty \else
        \pld@ExtendPoly\pld@temp\pld@symbols
    \fi
    \ifx\pld@temp\@empty \else
        \pld@if
            \expandafter\pld@IfSum\expandafter{\pld@temp}%
                {\expandafter\def\expandafter\pld@temp\expandafter
                    {\expandafter\pld@F\expandafter{\pld@temp}{}}}%
                {}%
        \fi
        \pld@ExtendPoly\pld@tempoly\pld@temp
        \pld@Extend\pld@tempoly{\pld@monom}%
    \fi}
\def\pld@CMFracAdd{%
    \ifx +\pld@op \let\pld@op\@empty
                  \expandafter\pld@AddToPoly
            \else \expandafter\pld@AddTo \fi
    \pld@symbols}
\def\pld@CMRational#1#2#3{%
    \ifx\relax#3%
        \pld@AccuAdd{#1}{#2}%
    \else
        \pld@CMFracAdd{\pld@R{#1}{#2}}%
        \expandafter#3%
    \fi}
\def\pld@CMSymbol#1#2{\pld@CMFracAdd{\pld@S{#1}{#2}}}%
\def\pld@CMFrac#1#2{%
    \ifx\@empty#2\@empty
        \pld@CMFrac@nom#1+\relax+%
    \else
        \pld@CMFrac@{#1}{#2}%
    \fi}
\def\pld@CMFrac@#1#2{%
    \pld@IfSum{#1}{\pld@CMFracAdd{\pld@F{#1}{}}}%
                  {#1}%
    \pld@IfSum{#2}{\pld@CMFracAdd{\pld@F{}{#2}}}%
                  {\begingroup
                     \pld@DefInverse\pld@temp{#2}%
                     \global\let\@gtempa\pld@temp
                   \endgroup
                   \@gtempa}}
\def\pld@CMFrac@nom#1+{%
    \ifx\relax#1\else
        #1\relax
        \expandafter\pld@CMFrac@nom
    \fi}
\def\pld@SortMonomials#1{%
    \ifx #1\@empty \else
        \begingroup
          \let\pld@temp#1\let\pld@tempoly\@empty
          \expandafter\pld@SortVars\pld@temp+\relax+%
          \let\pld@temp\pld@tempoly \let\pld@tempoly\@empty
          \expandafter\pld@SortSummands\pld@temp+\relax+%
          \global\let\@gtempa\pld@tempoly
        \endgroup
        \let#1\@gtempa
    \fi}
\def\pld@SortVars#1+{%
    \ifx\relax#1\relax\else
        \pld@SplitMonom\pld@SortVars@{#1}%
        \expandafter\pld@SortVars
    \fi}
\def\pld@SortVars@#1#2{%
    \begingroup
      \def\pld@monom{#2}%
      \ifx\@empty\pld@monom\else
          \let\pld@V\pld@SVVar
          \let\pld@S\pld@SVSymbol
          \pld@SortVars@V
      \fi
      \global\let\@gtempa\pld@monom
    \endgroup
    \def\pld@factor{#1}%
    \pld@Extend\pld@factor\@gtempa
    \pld@ExtendPoly\pld@tempoly\pld@factor}
\def\pld@SortVars@V{%
    \pld@false \let\pld@temp\pld@monom \let\pld@monom\@empty
    \pld@temp\pld@V\relax\relax
    \pld@if \expandafter\pld@SortVars@V \fi}
\def\pld@SVVar#1#2\pld@V#3#4{%
    \ifx\relax#3\relax
        \pld@AddTo\pld@monom{\pld@V{#1}{#2}}%
    \else
        \pld@IfVarL{#1}{#3}{\pld@AddTo\pld@monom{\pld@V{#1}{#2}}%
                            \def\pld@next{\pld@V{#3}{#4}}}%
                           {\pld@true
                            \pld@AddTo\pld@monom{\pld@V{#3}{#4}}%
                            \def\pld@next{\pld@V{#1}{#2}}}%
        \expandafter\pld@next
    \fi}
\def\pld@SortVars@S{%
    \pld@false \let\pld@temp\pld@monom \let\pld@monom\@empty
    \pld@temp\pld@S\relax\relax
    \pld@if \expandafter\pld@SortVars@S \fi}
\def\pld@SVSymbol#1#2\pld@S#3#4{%
    \ifx\relax#3\relax
        \pld@AddTo\pld@monom{\pld@S{#1}{#2}}%
    \else
        \pld@IfVarL{#1}{#3}{\pld@AddTo\pld@monom{\pld@S{#1}{#2}}%
                            \def\pld@next{\pld@S{#3}{#4}}}%
                           {\pld@true
                            \pld@AddTo\pld@monom{\pld@S{#3}{#4}}%
                            \def\pld@next{\pld@S{#1}{#2}}}%
        \expandafter\pld@next
    \fi}
\def\pld@SortSummands#1+{%
    \ifx\relax#1\relax\else
        \ifx\@empty\pld@tempoly
            \def\pld@tempoly{#1}%
        \else
            \def\pld@monom{#1}%
            \let\pld@temp\pld@tempoly \let\pld@tempoly\@empty
            \expandafter\pld@SortSummands@i\pld@temp+\relax+%
        \fi
        \expandafter\pld@SortSummands
    \fi}
\def\pld@SortSummands@i#1+{%
    \ifx\relax#1\relax
        \pld@ExtendPoly\pld@tempoly\pld@monom
        \expandafter\@gobble
    \else
        \expandafter\pld@SortSummands@j
    \fi
    {#1}}
\def\pld@SortSummands@j#1{%
    \expandafter\pld@IfMonomL\expandafter{\pld@monom}{#1}%
        {\pld@AddToPoly\pld@tempoly{#1}%
         \pld@SortSummands@i}%
        {\pld@SortSummands@k\pld@monom+#1+}}
\def\pld@SortSummands@k#1+\relax+{\pld@ExtendPoly\pld@tempoly{#1}}
\def\pld@IfVarL#1#2{%
    \begingroup
      \def\pld@va{#1}\def\pld@vb{#2}%
      \ifx\pld@va\pld@vb
          \aftergroup\@secondoftwo
      \else
          \edef\pld@next{\expandafter\strip@prefix\meaning\pld@va
                                           \relax\noexpand\@empty
                         \expandafter\strip@prefix\meaning\pld@vb
                                           \relax\noexpand\@empty}%
          \expandafter\pld@IfVarL@\pld@next
      \fi
    \endgroup}
\def\pld@IfVarL@#1#2\@empty#3#4\@empty{%
    \let\pld@next\@empty
          \ifx #3\relax \aftergroup\@secondoftwo
    \else \ifx #1\relax \aftergroup\@firstoftwo
    \else
        \ifx#1#3%
            \def\pld@next{\pld@IfVarL#2\@empty#4\@empty}%
        \else
            \ifnum`#1<`#3\relax \aftergroup\@firstoftwo
                          \else \aftergroup\@secondoftwo \fi
        \fi
    \fi \fi
    \pld@next}
\def\pld@IfMonomL#1#2{%
    \begingroup
      \pld@IfMonomL@#1\pld@V\relax\relax\@empty
                    #2\pld@V\relax\relax\@empty
    \endgroup}
\def\pld@IfMonomL@#1\pld@V#2#3#4\@empty#5\pld@V#6#7#8\@empty{%
    \let\pld@next\@empty
          \ifx #6\relax \aftergroup\@secondoftwo
    \else \ifx #2\relax \aftergroup\@firstoftwo
    \else
        \def\pld@va{#2}\def\pld@vb{#6}%
        \ifx\pld@va\pld@vb
            \ifnum#3=#7\relax
                \def\pld@next{\pld@IfMonomL@#4\@empty#8\@empty}%
            \else
                \ifnum#3<#7\relax \aftergroup\@firstoftwo
                            \else \aftergroup\@secondoftwo \fi
            \fi
        \else
            \pld@IfVarL#2\relax\@empty#6\relax\@empty
                {\aftergroup\@firstoftwo}%
                {\aftergroup\@secondoftwo}%
        \fi
    \fi \fi
    \pld@next}
\def\pld@IfMonomE#1#2{\pld@IfMonomE@#1\pld@V\@empty#2\pld@V\@empty}
\def\pld@IfMonomE@#1\pld@V#2\@empty#3\pld@V#4\@empty{%
    \begingroup
      \def\pld@va{#2}\def\pld@vb{#4}%
      \ifx\pld@va\pld@vb \aftergroup\@firstoftwo
                   \else \aftergroup\@secondoftwo \fi
    \endgroup}
\def\pld@Simplify#1{%
    \pld@CondenseFactors#1%
    \pld@SortMonomials#1%
    \pld@CondenseMonomials\pld@true#1}
\def\pld@MultiplyPoly{\begingroup\pld@true \pld@MultiplyPoly@}
\def\pld@NMultiplyPoly{\begingroup\pld@false \pld@MultiplyPoly@}
\def\pld@MultiplyPoly@#1#2#3{%
      \let\pld@temp\@empty
      \ifx\@empty#2\@empty\else \ifx\@empty#3\@empty\else
          \expandafter\pld@MultiplyPoly@a\expandafter#2#3+\relax+%
      \fi \fi
      \global\let\@gtempa\pld@temp
    \endgroup
    \let#1\@gtempa \pld@CondenseFactors#1}
\def\pld@MultiplyPoly@a#1#2+{%
    \ifx\relax#2\else
        \pld@if \def\pld@va{#2}\else \def\pld@va{#2\pld@R{-1}1}\fi
        \expandafter\pld@MultiplyPoly@b#1+\relax+%
        \expandafter\pld@MultiplyPoly@a\expandafter#1%
    \fi}
\def\pld@MultiplyPoly@b#1+{%
    \ifx\relax#1\else
        \pld@ExtendPoly\pld@temp{\pld@va#1}%
        \expandafter\pld@MultiplyPoly@b
    \fi}
\def\pld@DividePoly{\pld@false \pld@DivPoly}
\def\pld@LongDividePoly#1#2{%
    \let\pld@pattern\@empty \let\pld@lastline\@empty
    \let\pld@subline\@empty \let\pld@currentline\@empty
    \let\pld@allines\@empty \let\pld@maxcol\z@
    \let\pld@maxcolplustwo\z@ \let\pld@linepos\z@
    \pld@true \pld@DivPoly#1#2%
    \pld@ArrangeResult#1}
\def\pld@DivPoly#1#2{%
    \pld@currstage\pld@stage\relax
    \let\pld@remainder#1\let\pld@divisor#2\let\pld@quotient\@empty
    \pld@DivPoly@l}
\def\pld@DivPoly@l{%
    \ifx\pld@remainder\@empty\else
        \pld@IfNeedsDivision\pld@remainder\pld@divisor
        {\pld@ExtendPoly\pld@quotient\pld@factor
         \pld@NMultiplyPoly\pld@sub\pld@divisor\pld@factor
         \pld@SubtractPoly\pld@remainder\pld@sub
         \expandafter\pld@DivPoly@l}%
        {\ifpld@InsidePolylongdiv\expandafter\pld@insert@remainder
         \pld@last@remainder+\relax\relax\fi}%
    \fi}
\def\pld@insert@remainder#1+#2\relax{%
    \ifx\relax#1\relax\else\pld@InsertItems\@empty\@empty{#1}\fi
    \ifx\relax#2\relax\else\pld@insert@remainder#2\relax\fi}
\def\pld@IfNeedsDivision#1#2{%
    \pld@ExpandTwo\pld@IfND{#1+\@empty}{#2+\@empty}}
\def\pld@IfND#1+#2\@empty#3+#4\@empty{%
    \pld@DefInverse\pld@factor{#3}%
    \pld@AddTo\pld@factor{#1}%
    \pld@CondenseFactors\pld@factor
    \begingroup
      \pld@true
      \expandafter\pld@IfND@\pld@factor\pld@V\relax\z@
      \pld@if \aftergroup\@firstoftwo
        \else \aftergroup\@secondoftwo \fi
    \endgroup}
\def\pld@IfND@#1\pld@V#2#3{%
    \ifx\relax#2\@empty \expandafter\@gobble
                  \else \ifnum#3<\z@ \pld@false \fi
    \fi \pld@IfND@}
\def\pld@SubtractPoly#1#2{%
    \ifx#2\@empty\else
        \pld@if
            \let\pld@firstcol\maxdimen \let\pld@lastcol\z@
        \fi
        \let\pld@tempoly\@empty
        \pld@ExpandTwo\pld@SubtractPoly@
                 {#1+\relax+\@empty}{#2+\relax+\@empty}%
        \let#1\pld@tempoly
        \pld@if
            \ifnum\pld@currstage>\z@
                \pld@Extend\pld@allines{\pld@lastline\cr}%
            \else
                \pld@InsertFake\pld@lastline
            \fi
            \advance\pld@currstage-\tw@
            \ifnum\pld@currstage>\z@
                \pld@Extend\pld@allines{\pld@subline\cr}%
                \edef\pld@subline{%
                    \noexpand\cline{\pld@firstcol-\pld@lastcol}
                    \noalign{\vskip\jot}}%
                \pld@Extend\pld@allines\pld@subline
            \else
                \pld@InsertFake\pld@subline
            \fi
            \advance\pld@currstage\m@ne
            \let\pld@lastline\pld@currentline
            \let\pld@subline\@empty
            \let\pld@currentline\@empty
        \fi
    \fi}
\def\pld@SubtractPoly@#1+#2\@empty#3+{%
    \pld@if
        \pld@DefNegative\pld@monom{#1}%
        \expandafter\pld@InsertItems\expandafter\@empty
            \expandafter{\pld@monom}{#1}%
    \fi
    \pld@SubtractPoly@l#2\@empty}
\def\pld@SubtractPoly@l#1+#2\@empty#3+#4\@empty{%
    \ifx\relax#1\relax
        \let\pld@last@remainder\@empty
        \ifx\relax#3\relax \let\pld@next\@empty \else
          \pld@AddToPoly\pld@tempoly{#3}%
          \pld@if \pld@InsertItems{#3}{#3}{}\fi
          \def\pld@next{\pld@SubtractPoly@l\relax+\@empty#4\@empty}%
        \fi
    \else
    \ifx\relax#3\relax
        \pld@SubtractPoly@r#1+#2\@empty
        \let\pld@next\@empty
    \else
        \pld@IfMonomE{#1}{#3}%
        {\def\pld@temp{#1+#3}%
         \pld@CondenseMonomials\pld@true\pld@temp
         \ifx\pld@temp\@empty\else
             \pld@ExtendPoly\pld@tempoly\pld@temp
         \fi
         \pld@if \expandafter\pld@InsertItems\expandafter
                 {\pld@temp}{#3}{#1}\fi
         \def\pld@next{\pld@SubtractPoly@l#2\@empty#4\@empty}}%
        {\pld@IfMonomL{#1}{#3}%
         {\pld@AddToPoly\pld@tempoly{#3}%
          \pld@if \pld@InsertItems{#3}{#3}{}\fi
          \def\pld@next{\pld@SubtractPoly@l#1+#2\@empty#4\@empty}}%
         {\pld@AddToPoly\pld@tempoly{#1}%
          \pld@if \pld@InsertItems{#1}{}{#1}\fi
          \def\pld@next{\pld@SubtractPoly@l#2\@empty#3+#4\@empty}}%
        }%
    \fi \fi
    \pld@next}
\def\pld@SubtractPoly@r#1+\relax+\@empty{%
    \pld@AddToPoly\pld@tempoly{#1}%
    \def\pld@last@remainder{#1}}
\def\pld@InsertFake#1{%
    \let\pld@temp\@empty
    \expandafter\pld@InsertFake@l#1&\relax&}
\def\pld@InsertFake@l#1&{%
    \ifx\relax#1\@empty
        \pld@Extend\pld@temp{\expandafter&\pld@fakeline}%
        \let\pld@fakeline\pld@temp
    \else
        \expandafter\pld@InsertFake@do\pld@fakeline\relax{#1}%
        \expandafter\pld@InsertFake@l
    \fi}
\def\pld@InsertFake@do#1&#2\relax#3{%
    \ifx\@empty#2\@empty \def\pld@fakeline{0pt&}%
                   \else \def\pld@fakeline{#2}\fi
    \@tempdima#1\relax
    \setbox\z@=\hbox{\ensuremath{#3}}%
    \ifdim\@tempdima<\wd\z@ \@tempdima=\wd\z@ \fi
    \ifx\pld@temp\@empty
        \edef\pld@temp{\the\@tempdima}%
    \else
        \pld@Extend\pld@temp{\expandafter&\the\@tempdima}%
    \fi}
\def\pld@fakeline{0pt&}% init
\def\pld@ConvertFake#1&{%
    \ifx\relax#1\@empty\else
        \ifx\@empty#1\@empty
            &%
        \else
            \noexpand\vrule\noexpand\@height\z@\noexpand\@depth\z@
                           \noexpand\@width#1\relax&%
        \fi
        \expandafter\pld@ConvertFake
    \fi}
\def\pld@SplitQuotient{%
    \let\pld@real\@empty \let\pld@shadow\empty
    \pld@currstage\pld@stage\relax
    \expandafter\pld@SplitQuotient@\pld@quotient+\relax+}
\def\pld@SplitQuotient@#1+{%
    \ifx\relax#1\@empty
            \advance\pld@currstage-\tw@
            \ifnum\pld@currstage<\z@
                \let\pld@PrintRemain\pld@XPLD
            \else
                \let\pld@PrintRemain\pld@PLD
            \fi
    \else
        \ifx\@empty#1\@empty\else
            \advance\pld@currstage-\tw@
            \ifnum\pld@currstage<\z@
                \pld@AddToPoly\pld@shadow{#1}%
            \else
                \pld@AddToPoly\pld@real{#1}%
            \fi
            \advance\pld@currstage\m@ne
        \fi
        \expandafter\pld@SplitQuotient@
    \fi}
\def\pld@PrintPolyShadow{%
    \pld@firsttrue
    \ifx\pld@real\@empty\else
        \expandafter\pld@PrintMonoms\pld@real+\relax+%
    \fi
    \ifx\pld@shadow\@empty\else
        \setbox\z@\hbox{$\expandafter\pld@PrintMonoms\pld@shadow
                                                     +\relax+$}%
        \phantom{\copy\z@}%
    \fi}
\def\pld@PrintLongDiv{%
    \ensuremath{\hbox{\vtop{\begingroup
          \offinterlineskip \tabskip=\z@
  \edef\pld@fakeline{\expandafter\pld@ConvertFake\pld@fakeline&\relax&}%
          \halign{\strut\pld@firsttrue\hfil$##$%
                       &\pld@firsttrue\hfil$##$%
                       &&\hfil$##$\cr
                  \pld@fakeline\cr \noalign{\vskip-\normalbaselineskip}%
                  \pld@allines}%
          \endgroup}}}}
\def\pld@InsertItems#1#2#3{%
    \ifx\@empty#1\@empty
    \ifx\@empty#2\@empty \def\pld@monom{#3}%
                   \else \def\pld@monom{#2}\fi
                   \else \def\pld@monom{#1}\fi
    \@tempcnta\@ne \let\pld@recentmonom\@empty
    \expandafter\pld@InsertItems@find\pld@pattern\relax&%
    \ifnum\pld@firstcol>\@tempcnta \edef\pld@firstcol{\the\@tempcnta}\fi
    \ifnum\pld@lastcol<\@tempcnta \edef\pld@lastcol{\the\@tempcnta}\fi
    \ifnum\pld@maxcol<\@tempcnta
      \edef\pld@maxcol{\the\@tempcnta}
      \@tempcntb\pld@maxcol\relax\advance\@tempcntb\tw@
      \edef\pld@maxcolplustwo{\the\@tempcntb}
    \fi
    \pld@InsertItems@do\pld@lastline{\pld@PLD{#3}}%
    \pld@InsertItems@do\pld@subline{\pld@PLD{#2}}%
    \pld@InsertItems@do\pld@currentline{\pld@PLD{#1}}}
\def\pld@InsertItems@do#1#2{%
    \let\pld@temp\@empty \@tempcntb\@tempcnta
    \expandafter\pld@InsertItems@do@a#1&&&&&\relax{#2}%
    \let#1\pld@temp}
\def\pld@InsertItems@do@a#1&#2&#3&#4&#5&#6\relax{%
    \ifcase\@tempcntb \or
    \or \pld@AddTo\pld@temp{#1&}%
    \or \pld@AddTo\pld@temp{#1&#2&}%
    \or \pld@AddTo\pld@temp{#1&#2&#3&}%
    \or \pld@AddTo\pld@temp{#1&#2&#3&#4&}%
    \else
        \pld@AddTo\pld@temp{#1&#2&#3&#4&#5&}%
        \advance\@tempcntb-5\relax
        \def\pld@next{\pld@InsertItems@do@a#6&&&&&\relax}%
        \expandafter\@firstoftwo\expandafter\pld@next
    \fi
    \pld@InsertItems@do@b}
\def\pld@InsertItems@do@b#1{\pld@AddTo\pld@temp{#1}}
\def\pld@InsertItems@find#1&{%
    \ifx\relax#1\relax
        \expandafter\pld@InsertItems@find@fill\pld@recentmonom\pld@V{}0\@empty
    \else
        \def\pld@recentmonom{#1}%
        \expandafter\pld@IfMonomE\expandafter{\pld@monom}{#1}%
            {\expandafter\pld@InsertItems@find@\expandafter&}%
            {\advance\@tempcnta\@ne \expandafter\pld@InsertItems@find}%
    \fi}
\def\pld@InsertItems@find@#1&\relax&{}
\def\pld@InsertItems@find@fill#1\pld@V#2#3#4\@empty{%
    \expandafter\pld@InsertItems@find@fill@\pld@monom\pld@V{}0\@empty{#3}}
\def\pld@InsertItems@find@fill@#1\pld@V#2#3#4\@empty#5{%
    \ifx\pld@pattern\@empty
        \def\pld@pattern{\pld@V&\pld@V{#2}{#3}&}%
        \@tempcnta\tw@
    \else
        \@tempcntb#5\relax
        \loop \ifnum #3<\@tempcntb
            \advance\@tempcnta\@ne
            \advance\@tempcntb\m@ne
            \ifnum\@tempcntb=\z@
                \def\pld@temp{#1}%
            \else
                \edef\pld@temp{\noexpand\pld@V{#2}{\the\@tempcntb}}%
            \fi
            \pld@Extend\pld@pattern{\pld@temp&}%
        \repeat
        \advance\@tempcnta\m@ne
    \fi}
\def\pld@ArrangeResult#1{%
    \ifx\pld@remainder\@empty
        \@tempcnta\pld@maxcol\relax
        \pld@InsertItems@do\pld@lastline
            {\pld@firsttrue\pld@PLD{\pld@R{0}{1}}}%
    \fi
    \ifnum\pld@currstage>\z@
        \pld@Extend\pld@allines{\pld@lastline\cr}%
    \else
        \pld@InsertFake\pld@lastline
    \fi
    \pld@iftopresult
        \def\pld@lastline{\pld@PrintPoly\pld@divisor\bigr)&}%
    \else
        \let\pld@lastline\@empty
        \ifx C\pld@style
          \def\pld@lastline{\pld@leftdelim\strut\pld@rightxdelim&}%
        \fi
    \fi
    \expandafter\pld@AR@col\expandafter\pld@PLD
                           \expandafter\pld@lastline#1+\relax+%
    \pld@SplitQuotient
    \pld@iftopresult
        \let\pld@currentline\@empty
        \expandafter\pld@AR@col\expandafter\pld@PLD
                               \expandafter\pld@currentline
                                           \pld@quotient+\relax+%
        \expandafter\pld@AR@col\expandafter\pld@XPLD
                               \expandafter\pld@currentline
                                           \pld@shadow+\relax+%
        \edef\pld@subline{%
            \noexpand\cline{\tw@-\pld@maxcol}%
            \noalign{\vskip\jot}}%
        \pld@Extend\pld@currentline{\expandafter\cr\pld@subline}%
    \else
        \@tempcnta-\@tempcnta
        \advance\@tempcnta\pld@maxcol\relax \advance\@tempcnta\@ne
        \edef\pld@span{\the\@tempcnta}%
        \@tempcntb\pld@maxcol\relax\advance\@tempcntb\pld@span%
        \advance\@tempcntb\@ne%
        \edef\pld@linepos{\the\@tempcntb}%
        \ifx B\pld@style
          \pld@AddTo\pld@lastline{%
            &\multispan\pld@span${}=%
            \pld@PrintPolyWithDelims\pld@divisor
            \expandafter\pld@IfSum\expandafter{\pld@divisor}{}{\cdot}%
            \expandafter\pld@IfSum\expandafter{\pld@quotient}\pld@true
                                                             \pld@false
            \pld@if \pld@leftdelim
                    \pld@PrintPolyShadow
                    \pld@rightdelim
              \else \pld@PrintPolyShadow \fi
            \pld@firstfalse
            \expandafter\pld@PrintRemain\expandafter{\pld@remainder}$}%
        \else
          \if C\pld@style
            \pld@AddTo\pld@lastline{%
              &\multispan\pld@span$\pld@leftxdelim\strut\pld@rightdelim
              \pld@div
              \pld@PrintPolyWithDelims\pld@divisor=
              \pld@PrintPolyShadow
              \ifx\pld@remainder\@empty\else
                  +{}%
                  \setbox\z@=\hbox{$\displaystyle
                    \frac{\let\strut\@empty\pld@firsttrue \expandafter
                          \pld@PrintRemain\expandafter{\pld@remainder}}%
                         {\let\strut\@empty\pld@PrintPoly\pld@divisor}$}%
                  \dp\z@=\z@\box\z@
              \fi
              $}%
          \else
            \pld@AddTo\pld@lastline{%
              \cr%
              \noalign{\vskip-\normalbaselineskip}%
              \multispan\pld@maxcol~&~&\multispan\pld@span${}\vrule~%
              \pld@PrintPoly\pld@divisor\hfil\hfil$\cr%
              \cline{\pld@maxcolplustwo-\pld@linepos}%
              \multispan\pld@maxcol~&~&\multispan\pld@span${}\vrule height
              2.25ex~\pld@PrintPolyShadow$\hfil\cr\noalign{\vskip-2\normalbaselineskip}}%
          \fi
        \fi
    \fi
    \expandafter\pld@AR@\pld@allines\relax}
\def\pld@AR@#1\cr#2\relax{%
    \pld@iftopresult
        \let\pld@allines\pld@currentline
        \pld@AddTo\pld@allines{\pld@lastline\cr #2}%
    \else
        \let\pld@allines\pld@lastline
        \pld@AddTo\pld@allines{\cr #2}%
    \fi}
\def\pld@AR@col#1#2#3+{%
    \ifx\relax#3\@empty\else
        \ifx\@empty#3\@empty\else
            \def\pld@monom{#3}\@tempcnta\@ne
            \expandafter\pld@InsertItems@find\pld@pattern\relax&%
            \pld@InsertItems@do#2{#1{#3}}%
        \fi
        \expandafter\pld@AR@col\expandafter#1\expandafter#2%
    \fi}
\def\pld@PLD#1{\ifx\@empty#1\@empty\else\pld@PrintMonoms#1+\relax+\fi}
\def\pld@XPLD#1{\phantom{\pld@PLD{#1}}}
\def\pld@LongEuclideanPoly#1#2{%
    \pld@false \let\pld@allines\@empty
    \pld@DivPoly#1#2%
    \ifx\pld@quotient\@empty
        \pld@DivPoly#2#1%
        \pld@InsertEuclidean#2#1%
        \let\pld@vb#1%
    \else
        \pld@InsertEuclidean#1#2%
        \let\pld@vb#2%
    \fi
    \pld@LongEuclideanPoly@l}
\def\pld@LongEuclideanPoly@l{%
    \ifx\pld@remainder\@empty \else
        \let\pld@va\pld@divisor
        \let\pld@vb\pld@remainder
        \pld@DivPoly\pld@va\pld@vb
        \pld@Simplify\pld@quotient \pld@Simplify\pld@remainder
        \pld@InsertEuclidean\pld@va\pld@vb
        \expandafter\pld@LongEuclideanPoly@l
    \fi}
\def\pld@InsertEuclidean#1#2{%
    \ifx \pld@allines\@empty \else
        \pld@AddTo\pld@allines{\noalign{\vskip\jot}}%
    \fi
    \pld@Extend\pld@allines{\expandafter\pld@PrintPolyArg
                            \expandafter{#1}&}%
    \pld@Extend\pld@allines{\expandafter\pld@PrintPolyWithDelimsArg
                            \expandafter{#2}\hfil\cdot\hfil}%
    \pld@Extend\pld@allines{\expandafter\pld@PrintPolyWithDelimsArg
                            \expandafter{\pld@quotient}&}%
    \pld@Extend\pld@allines{\expandafter\pld@PrintPolyWithDelimsArg
                            \expandafter{\pld@remainder}\cr}}
\def\pld@PrintLongEuclidean{
    \ensuremath{\hbox{\vtop{\begingroup
          \offinterlineskip \tabskip=\z@
          \halign{\strut\pld@firsttrue\hfil$##$%
                  &${}={}$\hfil$##$\hfil
                  &${}+##$\hfil\cr \pld@allines}%
          \endgroup}}}}
\def\pld@NextDivisorPair#1#2{%
    \pld@NextDivisor\@tempcnta{#1}%
    \pld@if\else
        \pld@NextDivisor\@tempcntb{#2}%
    \fi}
\def\pld@NextDivisor#1#2{%
    \advance#1\@ne
    \ifnum #1>#2\relax
        #1\@ne \pld@false
        \expandafter\@gobbletwo
    \else
        \@multicnt #2\relax
        \divide\@multicnt#1\multiply\@multicnt#1%
        \advance\@multicnt-#2\relax
        \ifnum \@multicnt=\z@
            \pld@true
            \expandafter\expandafter\expandafter\@gobbletwo
        \else
            \expandafter\expandafter\expandafter\pld@NextDivisor
        \fi
    \fi
    #1{#2}}
\def\pld@FindZeros#1#2{%
    \pld@NextDivisorPair{#1}{#2}%
    \pld@if
        \pld@CheckZeros
        \def\pld@next{\pld@FindZeros{#1}{#2}}%
        \expandafter\pld@next
    \fi}
\def\pld@CheckZeros{%
    \pld@true \@multicnt\z@
    \loop \pld@if
        \pld@CheckZero{\the\@tempcnta}{\the\@tempcntb}%
    \repeat
    \pld@AddRationalZero{\the\@tempcnta}{\the\@tempcntb}%
    \pld@true \@multicnt\z@
    \loop \pld@if
        \pld@CheckZero{-\the\@tempcnta}{\the\@tempcntb}%
    \repeat
    \pld@AddRationalZero{-\the\@tempcnta}{\the\@tempcntb}}
\def\pld@CheckZero#1#2{%
    \begingroup
      \edef\pld@temp{{-#2}{#1}}%
      \pld@Extend\pld@tempoly{\expandafter+\expandafter\pld@R\pld@temp}%
      \let\pld@stage\maxdimen \pld@DividePoly\pld@current\pld@tempoly
      \ifx\pld@remainder\@empty
          \global\let\@gtempa\pld@quotient
          \aftergroup\pld@true
      \else
          \aftergroup\pld@false
      \fi
    \endgroup
    \pld@if
        \advance\@multicnt\@ne
        \let\pld@current\@gtempa
    \fi}
\def\pld@AddRationalZero#1#2{%
    \ifnum\@multicnt=\z@\else
        \pld@AccuSetX{#2}{-#1}%
        \pld@AccuGet\pld@temp
        \edef\pld@temp{\noexpand\pld@R\pld@temp}%
        \expandafter\pld@AddZero\expandafter{\pld@temp}%
        \ifnum\@multicnt=\@ne\else
            \edef\pld@temp{^{\the\@multicnt}}%
            \pld@Extend\pld@allines\pld@temp
        \fi
    \fi}
\def\pld@AddZero#1{%
    \pld@Extend\pld@allines{\expandafter\pld@leftdelim
                            \expandafter\pld@firsttrue
                            \expandafter\pld@PLD
                            \expandafter{\pld@tempoly+#1}%
                            \pld@rightdelim}}
\def\pld@FactorizeInit#1{%
    \begingroup
      \pld@firsttrue \let\pld@sub\@empty
      \pld@AccuSetX11%
      \let\pld@R\pld@FRational
      \let\pld@F\@gobbletwo
      \let\pld@S\@gobbletwo
      \let\pld@V\pld@FVar
      \expandafter\pld@FactorizeInit@\pld@current+\relax+%
      \pld@if
          \pld@AccuGet\pld@temp
          \expandafter\pld@AccuMul\@gtempa
          \pld@AccuIfNegative{\pld@AccuNegate}{}%
          \pld@AccuGet\pld@va
          \expandafter\pld@AccuSetX\pld@temp
          \expandafter\pld@AccuMul\pld@lastline
          \pld@AccuIfNegative{\pld@AccuNegate}{}%
          \pld@AccuGet\pld@vb
      \else
          \let\pld@va\@gtempa
          \let\pld@vb\pld@lastline
      \fi
      \ifx\pld@sub\@empty \def\pld@sub{01}\fi
      \edef\pld@temp{\noexpand#1\pld@va\pld@vb{\the\@multicnt}\pld@sub}%
      \pld@Extend\pld@tempoly{\pld@temp}%
      \global\let\@gtempa\pld@tempoly
    \endgroup
    \@gtempa}
\def\pld@FactorizeInit@#1+{%
    \ifx\relax#1\else
        \def\pld@lastline{11}%
        #1%
        \expandafter\pld@FactorizeInit@
    \fi}
\def\pld@FRational#1#2{%
    \def\pld@lastline{{#1}{#2}}%
    \pld@iffirst
        \global\let\@gtempa\pld@lastline
        \def\pld@tempoly{\@multicnt\z@}%
    \fi
    \pld@LCM{#2}%
    \@multicnt\z@}
\def\pld@FVar#1#2{%
    \pld@iffirst
        \pld@firstfalse
        \global\let\@gtempa\pld@lastline
        \def\pld@tempoly{\def\pld@tempoly{\pld@V{#1}}%
                         \@multicnt#2\relax}%
    \fi
    \@multicnt#2\relax
    \ifnum\@multicnt=\@ne
        \let\pld@sub\pld@lastline
    \fi}
\def\pld@Factorize#1{%
    \ifx\@empty#1\@empty
        \def\pld@allines{\pld@PrintPolyWithDelims\@empty}%
    \else
        \let\pld@allines\@empty
        \let\pld@current#1%
        \pld@true \pld@FactorizeInit
        \pld@Factorize@
    \fi}
\def\pld@Factorize@#1#2#3#4#5#6#7{%
    \ifnum #5=\z@\else
        \pld@Extend\pld@allines{\expandafter\pld@firsttrue
                                \expandafter\pld@PLD
                                \expandafter{\pld@tempoly{#5}}}%
        \let\pld@va\pld@tempoly
        \pld@AddTo\pld@va{{-#5}}%
        \pld@MultiplyPoly\pld@current\pld@current\pld@va
    \fi
    \pld@AddTo\pld@tempoly{1}%
    \@tempcnta\z@ \@tempcntb\@ne
    \pld@FindZeros{#1}{#3}%
    \pld@false \pld@FactorizeInit
    \pld@FactorizeFinal}
\def\pld@FactorizeFinal#1#2#3#4#5#6#7{%
    \ifnum\@multicnt=\tw@
        \pld@AddTo\pld@tempoly{1}%
        \pld@AccuSetX{#6}{#7}%
        \pld@AccuIfZero{\let\pld@va\@empty}%
                       {\pld@AccuMul12%
                        \pld@AccuMul{#2}{#1}%
                        \pld@AccuGet\pld@sub
                        \edef\pld@va{\noexpand\pld@R\pld@sub+}%
                        \expandafter\pld@AccuMul\pld@sub}%
        \begingroup
          \pld@AccuSetX{#3}{#4}%
          \pld@AccuMul{-#2}{#1}%
          \pld@AccuGet\pld@temp
          \global\let\@gtempa\pld@temp
        \endgroup
        \expandafter\pld@AccuAdd\@gtempa
        \pld@AccuIfNegative
        {\@multicnt\tw@}%
        {\pld@AccuGet\pld@temp
         \expandafter\pld@FDefSqrt\pld@temp
         \let\pld@vb\pld@va
         \pld@AddTo\pld@vb{\pld@R{-1}1}%
         \pld@Extend\pld@va{\pld@temp}%
         \pld@Extend\pld@vb{\pld@temp}%
         \expandafter\pld@AddZero\expandafter{\pld@va}%
         \expandafter\pld@AddZero\expandafter{\pld@vb}%
         \@multicnt\z@
        }%
    \fi
    \ifnum\@multicnt=\z@
         \pld@AccuSetX{#1}{#2}%
         \pld@AccuIfOne{\let\pld@current\@empty}%
                       {\def\pld@current{\pld@R{#1}{#2}}}%
    \fi
    \ifx\pld@current\@empty\else
        \let\pld@temp\pld@allines
        \def\pld@allines{\pld@PrintPolyWithDelims\pld@current}%
        \pld@Extend\pld@allines{\pld@temp}%
    \fi}
\def\pld@FDefSqrt#1#2{%
    \pld@IfSquare{#1}%
    {\pld@FDefSqrt@{\pld@R{\pld@temp}1}%
                   {\sqrt{\noexpand\pld@R{#2}1}}}%
    {\pld@IfSquare{#2}%
     {\ifnum\pld@temp=\@ne
          \pld@FDefSqrt@{\sqrt{\noexpand\pld@R{#1}1}}{}%
      \else
          \pld@FDefSqrt@{\sqrt{\noexpand\pld@R{#1}1}}%
                        {\pld@R{\pld@temp}1}%
      \fi}%
     {\def\pld@temp{\pld@F{\sqrt{\pld@R{#1}{#2}}}{}}}%
    }}
\def\pld@FDefSqrt@#1#2{%
    \edef\pld@temp{\noexpand\pld@F
                   {\noexpand#1}%
                   {\ifx\@empty#2\@empty\else \noexpand#2\fi}}}
\def\pld@IfSquare#1{%
    \@tempcnta=#1\relax
    \@multicnt\@tempcnta \@tempcntb\@tempcnta
    \divide\@tempcntb\tw@ \advance\@tempcntb\@ne
    \loop \ifnum\@tempcntb<\@multicnt
        \@multicnt\@tempcntb
        \@tempcntb\@tempcnta
        \divide\@tempcntb\@multicnt
        \advance\@tempcntb\@multicnt
        \divide\@tempcntb\tw@
    \repeat
    \edef\pld@temp{\the\@multicnt}%
    \multiply\@multicnt\@multicnt
    \ifnum \@multicnt=\@tempcnta
        \expandafter\@firstoftwo
    \else
        \expandafter\@secondoftwo
    \fi}
\def\pld@XEuclidean#1#2#3{\pld@Euclidean#1{#2}{#3}%
                          \edef#1{#1{\the\@tempcntb}}}
\def\pld@Euclidean#1#2#3{%
   \@tempcnta#2\relax \divide\@tempcnta#3\relax
   \ifnum\@tempcnta=\z@ \@tempcnta#2\relax \@tempcntb#3\relax
                  \else \@tempcnta#3\relax \@tempcntb#2\relax \fi
   \ifnum\@tempcnta<\z@ \@tempcnta -\@tempcnta \fi
   \ifnum\@tempcntb<\z@ \@tempcntb -\@tempcntb \fi
   \pld@Euclidean@l
   \@tempcnta#3\relax \divide\@tempcnta\@tempcntb
   \edef#1{{\the\@tempcnta}}%
   \@tempcnta#2\relax \divide\@tempcnta\@tempcntb
   \edef#1{{\the\@tempcnta}#1}}
\def\pld@Euclidean@l{%
   \ifnum\@tempcnta=\z@\else
       \@multicnt\@tempcntb
       \divide\@tempcntb\@tempcnta
       \multiply\@tempcntb\@tempcnta
       \advance\@multicnt -\@tempcntb
       \@tempcntb\@tempcnta
       \@tempcnta\@multicnt
       \expandafter\pld@Euclidean@l
   \fi}
\def\pld@AccuGet{\expandafter\pld@AccuGet@\pld@accu}
\def\pld@AccuGet@#1#2#3{%
    \ifnum #2<\z@ \edef#3{{-#1}{-#2}}\else\edef#3{{#1}{#2}}\fi}
\def\pld@AccuSet#1#2{%
    \def\pld@accu{{#1}{#2}}%
    \expandafter\pld@Euclidean\expandafter\pld@accu\pld@accu
    \expandafter\pld@AccuGet@\pld@accu\pld@accu}
\def\pld@AccuSetX#1#2{\pld@AccuGet@{#1}{#2}\pld@accu}
\def\pld@AccuPrint{\expandafter\pld@AccuPrint@\pld@accu}
\def\pld@AccuPrint@#1#2{%
    \ifnum #2=\@ne \number#1\else \frac{\number#1}{\number#2}\fi}
\def\pld@AccuNegate{\expandafter\pld@AccuNegate@\pld@accu}
\def\pld@AccuNegate@#1#2{\def\pld@accu{{-#1}{#2}}}
\def\pld@AccuIfZero{\expandafter\pld@AccuIfZero@\pld@accu}
\def\pld@AccuIfZero@#1#2{%
    \ifnum #1=\z@ \expandafter\@firstoftwo
            \else \expandafter\@secondoftwo \fi}
\def\pld@AccuIfOne{\expandafter\pld@AccuIfOne@\pld@accu}
\def\pld@AccuIfOne@#1#2{%
    \ifnum #1=#2\relax \expandafter\@firstoftwo
                 \else \expandafter\@secondoftwo \fi}
\def\pld@AccuIfAbsOne{\expandafter\pld@AccuIfAbsOne@\pld@accu}
\def\pld@AccuIfAbsOne@#1#2{%
    \ifnum #1=#2\relax \expandafter\@firstoftwo \else
        \ifnum -#1=#2\relax
            \expandafter\expandafter\expandafter\@firstoftwo
        \else
            \expandafter\expandafter\expandafter\@secondoftwo
        \fi
    \fi}
\def\pld@AccuIfNegative{\expandafter\pld@AccuIfNegative@\pld@accu}
\def\pld@AccuIfNegative@#1#2{%
    \ifnum #1<\z@ \@tempcnta\m@ne \else \@tempcnta\@ne \fi
    \ifnum #2<\z@ \@tempcnta -\@tempcnta \fi
    \ifnum \@tempcnta<\z@ \expandafter\@firstoftwo
                    \else \expandafter\@secondoftwo \fi}
\def\pld@LCM{\expandafter\pld@LCM@\pld@accu}
\def\pld@LCM@#1#2#3{%
    \pld@Euclidean\pld@accu{#1}{#3}%
    \@tempcnta\expandafter\@firstoftwo\pld@accu\relax
    \multiply\@tempcnta#3\relax
    \edef\pld@accu{{\the\@tempcnta}1}}
\def\pld@AccuMul{\expandafter\pld@AccuMul@\pld@accu}
\def\pld@AccuMul@#1#2#3#4{%
    \begingroup
      \pld@Euclidean\pld@va{#1}{#4}%
      \pld@Euclidean\pld@vb{#3}{#2}%
      \pld@ExpandTwo\pld@AccuMul@m\pld@va\pld@vb
      \xdef\@gtempa{{\the\@tempcnta}{\the\@tempcntb}}%
    \endgroup
    \let\pld@accu\@gtempa}
\def\pld@AccuMul@m#1#2#3#4{%
    \@tempcnta#1\relax \multiply\@tempcnta#3\relax
    \@tempcntb#2\relax \multiply\@tempcntb#4\relax}
\def\pld@AccuAdd{\expandafter\pld@AccuAdd@a\pld@accu}
\def\pld@AccuAdd@a#1#2#3#4{%
    \ifnum#3=\z@\else
        \pld@AccuAdd@c{#1}{#2}{#3}{#4}%
    \fi}
\def\pld@AccuAdd@c#1#2#3#4{%
    \begingroup
      \pld@XEuclidean\pld@va{#1}{#3}%
      \pld@XEuclidean\pld@vb{#2}{#4}%
      \edef\pld@va{\pld@va\pld@vb}%
      \expandafter\pld@AccuAdd@b\pld@va{#2}{#4}}
\def\pld@AccuAdd@b#1#2#3#4#5#6#7#8{%
    \endgroup
    \@tempcnta#1\relax \multiply\@tempcnta#5\relax
    \@tempcntb#2\relax \multiply\@tempcntb#4\relax
    \advance\@tempcnta\@tempcntb
    \expandafter\pld@Euclidean\expandafter\pld@accu\expandafter
        {\the\@tempcnta}{#7}%
    \pld@AccuMul{#3}{#5}}
\def\pld@KVCases#1#2#3{%
    \@ifundefined{pld@#1@#2}%
    {\PackageError{Polynom}{Unknown value #2}{Try #3.}}%
    {\csname pld@#1@#2\endcsname}}
\def\pld@KVIf#1#2{%
    \@ifundefined{if#2}%
    {\PackageError{Polynom}{Unknown value #2}{Try `true' or `false'.}}%
    {\expandafter\let\expandafter#1\csname if#2\endcsname}}
\define@key{pld}{showbase}[middle]{\pld@KVCases{showbase}{#1}{`false', `top', `middle', or `bottom'}}%
\def\pld@showbase@false{\let\pld@basepos=f}
\def\pld@showbase@top{\let\pld@basepos=t}
\def\pld@showbase@middle{\let\pld@basepos=m}
\def\pld@showbase@bottom{\let\pld@basepos=b}
\define@key{pld}{showvar}[true]{\pld@KVIf\pld@ifshowvar{#1}}
\define@key{pld}{showbasesep}[true]{\pld@KVIf\pld@ifshowbasesep{#1}}
\define@key{pld}{showmiddlerow}[true]{\pld@KVIf\pld@ifshowmiddlerow{#1}}

\define@key{pld}{resultstyle}{\def\pld@resultstyle{#1}}
\define@key{pld}{resultleftrule}[true]{\pld@KVIf\pld@ifhornerresultleftrule{#1}}
\define@key{pld}{resultrightrule}[true]{\pld@KVIf\pld@ifhornerresultrightrule{#1}}
\define@key{pld}{resultbottomrule}[true]{\pld@KVIf\pld@ifhornerresultbottomrule{#1}}

\define@key{pld}{tutor}[true]{\pld@KVCases{tutor}{#1}{`true', or `false'}}%
\def\pld@tutor@true{\let\pld@iftutor\iftrue}
\def\pld@tutor@false{\let\pld@iftutor\iffalse}
\define@key{pld}{tutorstyle}{\def\pld@tutorstyle{#1}}
\define@key{pld}{tutorlimit}{\@tempcnta#1\relax \advance\@tempcnta\@ne
    \edef\pld@tutorlimit{\the\@tempcnta}}

\define@key{pld}{equalcolwidths}[true]{\pld@KVIf\pld@ifhornerequalcolwidths{#1}}
\define@key{pld}{arraycolsep}{\def\pld@hornerarraycolsep{#1\relax}}
\define@key{pld}{arrayrowsep}{\def\pld@hornerarrayrowsep{#1\relax}}

\polyset{showbase,
         showvar=false,
         showbasesep=true,
         showmiddlerow=true,
         tutor=false,
         tutorlimit=1,
         tutorstyle=\scriptscriptstyle,
         resultstyle=,
         resultleftrule=false,
         resultrightrule=false,
         resultbottomrule=false,
         equalcolwidths=true,
         arraycolsep=\arraycolsep,
         arrayrowsep=.5\arraycolsep}

\define@key{pld}{mul}{\def\pld@mul{#1}}%
\define@key{pld}{plusface}{\pld@KVCases{hornerplusface}{#1}{`left' or 'right'}}%
\define@key{pld}{plusyoffset}{\@tempdima#1\relax \edef\pld@hornerplusyoffset{\the\@tempdima}}
\define@key{pld}{downarrowxoffset}{\@tempdima#1\relax \edef\pld@hornerdownarrowxoffset{\the\@tempdima}}
\define@key{pld}{diagarrowxoffset}{\@tempdima#1\relax \edef\pld@hornerdiagarrowxoffset{\the\@tempdima}}
\define@key{pld}{downarrow}{\def\pld@hornerdownarrow{#1}}
\define@key{pld}{diagarrow}{\def\pld@hornerdiagarrow{#1}}
\def\pld@hornerplusface@left{\let\pld@hornerplusface\llap}
\def\pld@hornerplusface@right{\let\pld@hornerplusface\rlap}
\polyset{mul=\cdot,
         plusface=right,
         plusyoffset=\z@,
         downarrowxoffset=\z@,
         diagarrowxoffset=\z@,
         downarrow={\vector(0,-1){2.5}},
         diagarrow={\vector(2,1){1.6}}}
\newcommand*\polyhornerscheme[1][]{%
    \begingroup
    \let\pld@stage\maxdimen \polyset{#1}%
    \pld@GetPoly{\pld@polya}%
                {\expandafter\pld@Horner\expandafter{\pld@polya}%
    \endgroup \ignorespaces}}

\def\pld@Horner#1{%
    \pld@GetTotalDegree\pld@degree{#1}%
    \pld@Horner@#1++%
    \pld@ArrangeHorner}

\def\pld@Horner@#1+{%
    \pld@SplitMonom\pld@HornerInit{#1}%
    \pld@HornerIterate}

\def\pld@HornerIterate#1+{%
    \advance\@tempcnta\m@ne
    \ifx\@empty#1\@empty
        \ifnum \@tempcnta<\z@
            \let\pld@next\@empty
        \else
            \pld@HornerStep{\pld@R01}{}%
            \def\pld@next{\pld@HornerIterate+}%
        \fi
    \else
        \pld@GetTotalDegree\pld@degree{#1}%
        \ifnum \pld@degree=\@tempcnta
            \pld@SplitMonom\pld@HornerStep{#1}%
            \let\pld@next\pld@HornerIterate
        \else
            \pld@HornerStep{\pld@R01}{}%
            \def\pld@next{\pld@HornerIterate#1+}%
        \fi
    \fi
    \pld@next}

\def\pld@HornerStep#1#2{%
    \pld@AddTo\pld@lastline{&\pld@PrintPolyArg{#1}}%
    \pld@MultiplyPoly\pld@lastsum\pld@lastsum\pld@value
    \pld@Simplify\pld@lastsum
    \ifx\pld@lastsum\@empty \def\pld@lastsum{\pld@R 01}\fi
    \pld@AddTo\pld@subline{&}%
    \pld@HornerExtendLine\pld@subline
    \pld@AddTo\pld@lastsum{+#1}%
    \pld@Simplify\pld@lastsum
    \pld@AddTo\pld@currentline{&}%
    \pld@iftutor
        \pld@HornerExtendCurrentLine
        \advance\@multicnt\@ne
        \pld@HornerIfTutorStage{\pld@HornerExtendTutor\pld@HornerOtherDown}%
        \advance\@multicnt\m@ne
        \ifnum\@tempcnta>\z@
            \pld@HornerIfTutorStage{\pld@HornerExtendTutor\pld@HornerDiag}%
        \fi
    \else
        \pld@HornerExtendCurrentLine
    \fi}

\def\pld@HornerExtendTutor#1{%
    \ifnum\@tempcnta=\z@ \pld@AddTo\pld@hornerresult#1%
                   \else \pld@AddTo\pld@currentline#1\fi}
\def\pld@HornerExtendCurrentLine{%
    \ifnum\@tempcnta=\z@
        \let\pld@hornerresult\@empty
        \pld@Extend\pld@hornerresult{\expandafter{\expandafter\pld@resultstyle\expandafter{%
                                     \expandafter\pld@PrintPolyArg\expandafter{\pld@lastsum}}}}%
        \pld@HornerIfStage{}%
                          {\let\pld@lastsum\@empty
                           \pld@Extend\pld@lastsum{\expandafter\phantom\expandafter{\pld@hornerresult}}%
                           \let\pld@hornerresult\pld@lastsum}%
        \expandafter\@gobbletwo
    \fi
    \pld@HornerExtendLine\pld@currentline}
\def\pld@HornerExtendLine#1{%
    \pld@HornerIfStage{\pld@Extend#1{\expandafter\pld@PrintPolyArg\expandafter{\pld@lastsum}}}%
                      {\pld@Extend#1{\expandafter\phantom\expandafter{%
                                     \expandafter\pld@PrintPolyArg\expandafter{\pld@lastsum}}}}%
}

\def\pld@HornerFirstDown{%
    \rlap{\kern\pld@hornerdownarrowxoffset\relax
          \unitlength\ht\@arstrutbox
          \begin{picture}(0,0)%
          \setbox\z@\hbox{$\pld@tutorstyle{\pld@hornerdownarrow}$}%
          \put(0,.5){\raise\ht\z@\hbox{\raise\dp\z@\copy\z@}}%
          \end{picture}}}
\def\pld@HornerOtherDown{%
    \pld@HornerFirstDown
    \pld@hornerplusface{\kern\pld@hornerdownarrowxoffset\relax
                        \smash{\raise\pld@hornerplusyoffset
                               \hbox{\raise.5\ht\@arstrutbox
                                     \vbox to 2.5\ht\@arstrutbox
                                     {\vss$\pld@tutorstyle{+}$\vss}}}}}
\def\pld@HornerDiag{%
    \rlap{\kern\pld@hornerdiagarrowxoffset\relax
        \unitlength\ht\@arstrutbox
        \begin{picture}(0,0)%
        \setbox\z@\hbox{$\pld@tutorstyle{\pld@hornerdiagarrow}$}%
        \put(0,.5){\box\z@}%
        \put(0,.5){\kern.55\ht\@arstrutbox
                   $\pld@tutorstyle{\pld@mul \pld@hornerleftdelim
                                    \pld@PrintPolyWithDelims\pld@value
                                    \pld@hornerrightdelim}$}%
        \end{picture}}}

\def\pld@HornerIfStage{%
    \advance\@multicnt\m@ne
    \ifnum\@multicnt>\z@ \expandafter\@firstoftwo
                   \else \expandafter\@secondoftwo \fi}
\def\pld@HornerIfTutorStage{%
    \ifnum\@multicnt>\@ne
        \ifnum\@multicnt>\pld@tutorlimit
            \expandafter\expandafter\expandafter\@gobble
        \else
            \expandafter\expandafter\expandafter\@firstofone
        \fi
    \else
        \expandafter\@gobble
    \fi}

\def\pld@HornerInit#1#2{%
    \let\pld@V\@firstoftwo
    \ifx\@empty#2\@empty\else
        \edef\pld@var{#2}%
        \@ifundefined{pld@value@\pld@var}%
        {\PackageError{Polynom}{Missing value for variable \pld@var}{}%
         \@namedef{pld@value@\pld@var}{\pld@R01}}%
        {}%
        \expandafter\let\expandafter\pld@value\csname pld@value@\pld@var\endcsname
    \fi
    \setbox\@tempboxa\hbox{$\pld@PrintPoly\pld@value$}%
    \pld@ifminus
        \let\pld@hornerleftdelim(%
        \let\pld@hornerrightdelim)%
    \else
        \let\pld@hornerleftdelim\@empty
        \let\pld@hornerrightdelim\@empty
    \fi
    \@multicnt\pld@stage\relax
    \@tempcnta\pld@degree\relax
    \def\pld@lastline{\pld@PrintPolyArg{#1}}%
    \let\pld@subline\@empty
    \let\pld@currentline\@empty
    \def\pld@lastsum{#1}%
    \pld@iftutor
        \pld@HornerExtendCurrentLine
        \advance\@multicnt\@ne
        \pld@HornerIfTutorStage{\pld@AddTo\pld@currentline\pld@HornerFirstDown}%
        \advance\@multicnt\m@ne
        \ifnum\@tempcnta>\z@
            \pld@HornerIfTutorStage{\pld@AddTo\pld@currentline\pld@HornerDiag}%
        \fi
    \else
        \pld@HornerExtendCurrentLine
    \fi
    \def\pld@lastsum{#1}%
    \@tempcnta\pld@degree\relax % init moved up, delete this?
    \advance\@tempcnta\thr@@
    \edef\pld@hornermaxcol{\the\@tempcnta}%
    \@tempcnta\pld@degree\relax}
\def\pld@ArrangeHorner{%
    \begingroup
    \@tempdima\z@
    \pld@MeasureCells\pld@lastline
    \pld@MeasureCells\pld@subline
    \pld@MeasureCells\pld@currentline
    \pld@MeasureCells\pld@hornerresult
    \everycr{}\tabskip\z@skip
    \@tempdimb\ht\strutbox \advance\@tempdimb\pld@hornerarrayrowsep
    \@tempdimc\dp\strutbox \advance\@tempdimc\pld@hornerarrayrowsep
    \setbox\@arstrutbox\hbox{\vrule \@height\@tempdimb
                                    \@depth\@tempdimc
                                    \@width\z@}%
    \pld@ifhornerequalcolwidths\else
        \def\@startpbox##1{\hfil\vtop\bgroup \hbox\bgroup \@arrayparboxrestore}%
        \def\@endpbox{\@finalstrut\@arstrutbox \egroup\par\egroup}%
    \fi
    \def\pld@leftdelim{(}\def\pld@rightdelim{)}%
    \leavevmode
    \hbox{$\vcenter{\offinterlineskip \arraycolsep\pld@hornerarraycolsep
        \halign{\@arstrut
                \hskip\arraycolsep \hfill\ensuremath{##}\hskip\arraycolsep
              &##&&%
                \hskip\arraycolsep \@startpbox\@tempdima\hfill\ensuremath{##}\@endpbox \hskip\arraycolsep\cr
                \pld@ShowBase t&\pld@ifshowbasesep\vrule\fi&\pld@lastline\cr
                \pld@ifshowmiddlerow \pld@ShowBase m&\pld@ifshowbasesep\vrule\fi&\pld@subline\cr \fi \cline{2-\pld@hornermaxcol}%
                \pld@ShowBase b&&\pld@currentline\omit
                \pld@ifhornerresultleftrule \vrule \fi
                \hskip\arraycolsep \@startpbox\@tempdima\relax\hfill\ensuremath{\pld@hornerresult}\@endpbox \hskip\arraycolsep
                \pld@ifhornerresultrightrule \vrule \fi \cr
                \pld@ifhornerresultbottomrule \cline{\pld@hornermaxcol-\pld@hornermaxcol} \fi
               }%
    }$}%
    \endgroup}
\def\pld@ShowBase#1{%
    \ifx#1\pld@basepos
        \pld@ifshowvar x=\fi\pld@PrintPoly\pld@value
    \fi}
\def\pld@MeasureCells#1{\expandafter\pld@MeasureCells@#1&\@nil&}
\def\pld@MeasureCells@#1&{%
    \ifx\@nil#1\relax\else
        \setbox\@tempboxa\hbox{\ensuremath{#1}}%
        \ifdim\wd\@tempboxa>\@tempdima
            \@tempdima\wd\@tempboxa
        \fi
        \expandafter\pld@MeasureCells@
    \fi}
\def\pld@GetTotalDegree#1#2{%
    \begingroup
    \let\pld@R\@gobbletwo \let\pld@F\@gobbletwo \let\pld@S\@gobbletwo
    \def\pld@V##1##2{\advance\@tempcnta##2\relax}%
    \def#1##1+##2\@nil{##1}%
    \edef#1{\@tempcnta\z@#1#2+\@nil}%
    #1\xdef\@gtempa{\the\@tempcnta}%
    \endgroup
    \let#1\@gtempa}
%%
%%
\endinput
%%
%% End of file `polynom.sty'.
