Dividend, divisor, quotient, and remainder:
In[]:=
pA=8
6
x
+8
5
x
-20
4
x
+40
3
x
+0
2
x
+30x-10;​​pD=2
4
x
+3
3
x
-4
2
x
+6x-8;​​pQ=PolynomialQuotient[pA,pD,x];​​pR=PolynomialRemainder[pA,pD,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];​​Tablecli*
l-i
x
,{i,1,l}​​
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[]:=
Row​​Grid​​{{},D}~Join~Table[{},{i,3,nCols}],​​Dividers​​Tablei
,{i,1,d},​​2
,3
​​,​​Spacings{1,1}​​,​​Grid​​Q,​​​​A,​​pl
A〚1〛
D〚1〛
D,a,0,2,​​​​A-pl
A〚1〛
D〚1〛
D,a,0,2,​​pl
A-pl
A〚1〛
D〚1〛
D,a,0,22
D〚1〛
D,a,0,1,​​​​A-pl
A〚1〛
D〚1〛
D,a,0,2-pl
A-pl
A〚1〛
D〚1〛
D,a,0,22
D〚1〛
D,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]​​,​​Dividers​​1
,Tablei
,{i,2,a},​​1
,2
,3
,4
,5
,6
,7
,8
​​​​,​​FrameTrue
Out[]=
​
​
​
​
​
2
4
x
3
3
x
-4
2
x
6x
-8
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4
2
x
-2x
1
​
​
​
​
8
6
x
8
5
x
-20
4
x
40
3
x
0
30x
-10
8
6
x
12
5
x
-16
4
x
24
3
x
-32
2
x
0
0
0
-4
5
x
-4
4
x
16
3
x
32
2
x
30x
-10
0
-4
5
x
-6
4
x
8
3
x
-12
2
x
16x
0
0
0
2
4
x
8
3
x
44
2
x
14x
-10
0
0
2
4
x
3
3
x
-4
2
x
6x
-8
0
0
0
5
3
x
48
2
x
8x
-2