Dividend, divisor, quotient, and remainder:
In[]:=
pA=8+8-20+40+0+30x-10;pD=2+3-4+6x-8;pQ=PolynomialQuotient[pA,pD,x];pR=PolynomialRemainder[pA,pD,x];
6
x
5
x
4
x
3
x
2
x
4
x
3
x
2
x
Degrees of the polynomials:
In[]:=
{degA,degD,degQ,degR}=Exponent[#,x]&/@{pA,pD,pQ,pR}
Out[]=
{6,4,2,0}
List of the monomials in polynomial p, highest degree first:
In[]:=
ml[p_,x_]:=Module{cl,l},cl:=Reverse[CoefficientList[p,x]];l=Length[cl];Tablecli*,{i,1,l}
l-i
x
mlA=ml[pA,x];mlD=ml[pD,x];mlQ=ml[pQ,x];mlR=ml[pR,x];
Unprotect[D];A=mlA;D=mlD;Q=mlQ;R=mlR;
The total number of rows and columns in the right-hand grid, remembering that the divisor is being placed in the first row:
In[]:=
nColsL=degD+1;nColsR=degA+1;nRows=2(degA-degD+1)+2;
In[]:=
{a,d,q,r}=Length/@{A,D,Q,R}
Out[]=
{7,5,3,4}
In[]:=
RowGrid{{},D}~Join~Table[{},{i,3,nCols}],DividersTablei,{i,1,d},2,3,Spacings{1,1},GridQ,A,plD,a,0,2,A-plD,a,0,2,plD,a,0,1,A-plD,a,0,2-plD,a,0,1,pl[Q〚3〛D,a,0],A-pl[Q〚1〛D,a,0,2]-pl[Q〚2〛D,a,0,1]-pl[Q〚3〛D,a,0],Dividers1,Tablei,{i,2,a},1,2,3,4,5,6,7,8,FrameTrue
A〚1〛
D〚1〛
A〚1〛
D〚1〛
A-plD,a,0,22
A〚1〛
D〚1〛
D〚1〛
A〚1〛
D〚1〛
A-plD,a,0,22
A〚1〛
D〚1〛
D〚1〛
Out[]=