Polynomial Divisibility, Interpolation, and Algebraic Extensions
3-1. Commands for Handling Polynomial Expressions
This chapter is about working with polynomials and algebraic extensions. We will study the MATLAB commands that enable you to perform polynomial operations, working with roots, Galois extensions, Gröbner bases, polynomial interpolation, and operations modulo an integer. We will also present the commands that Maple implements to the same effect.
MATLAB enables agile work with polynomials, providing several commands for handling polynomial algebraic expressions. These expressions can also be treated as general algebraic expressions, but MATLAB offers particular tools for polynomial algebraic expressions, including case-specific commands. Let’s take a look at some of these commands:
Now let’s look at some examples of the above defined commands:
Let’s decompose the fraction (-x ^ 2 + 2 x + 1) /(x^2-1) into the sum of its simple fractions:
>> [r,p,k]=residue([-1,2,1],[1,0,-1])
r =
1.0000
1.0000
p =
-1.0000
1.0000
k =
-1
So the decomposition will be:
(-x ^ 2 + 2 x + 1) /(x^2-1) = 1 /(-1+x) + 1 / (x + 1) - 1
The same result can be obtained in the following way:
>> pretty(sym(maple('convert((-x^2+2*x+1)/(x^2-1),parfrac,x)')))
1 1
-1 + ----- + -----
x - 1 x + 1
Next we will evaluate the polynomial x ^ 4-6 * x ^ 3-x ^ 2 + 10 * x-11 at the point x = 5 and at the unit matrix of order 4.
>> polyval([1,-6,-1,10,-11],5)
ans =
-111
>> polyvalm([1,-6,-1,10,-11],ones(4))
ans =
-37 - 26 - 26 - 26
-26 - 37 - 26 - 26
-26 – 26 - 37 - 26
-26 - 26 – 26 - 37
Now let’s find the roots of the polynomial x ^ 3-x:
>> roots([1,0,-1,0])
ans =
0
-1.0000
1.0000
Now we solve the equation -x ^ 5 + 2 * x ^ 4 + x ^ 3 + x ^ 2 = 0:
>> roots([-1,2,1,1,0,0])
ans =
0
0
2.5468
-0.2734 + 0.5638i
-0.2734 - 0.5638i
EXERCISE 3-1
Consider the polynomials with coefficients a = [2 - 4, 5, 8, 0, 0, 1] and b = [- 7, 15, 0, 12, 0]. Calculate the coefficients of the product and the quotient of polynomials defined by a and b, and also calculate the coefficients of the derivatives of the product and quotient of the polynomials defined by a and b.
>> a=[2,-4,5,8,0,0,1]; b=[-7,15,0,12,0];
>> conv(a,b)
ans =
-14 58 -95 43 72 60 89 15 0 12 0
>> [q,r]=deconv(a,b)
q =
-0.2857 -0.0408 -0.8017
r =
0 0 0 23.4548 0.4898 9.6210 1.0000
>> polyder(a)
ans =
12 -20 20 24 0 0
>> polyder(a,b)
ans =
-140-522 - 760 301 432 300 356 45 0 12
>> [q, d] = polyder(a, b)
q =
-28 118 -120 251 -192 180 220 -45 0 -12
d =
49 -210 225 -168 360 0 144 0 0
In the previous calculations, we could instead have transformed the coefficient vectors into the equivalent polynomials with the command poly2sym, obtaining the results in polynomial form. The product polynomial is:
>> pretty(poly2sym(conv(a,b)))
10 9 8 7 6 5 4 3
-14 x + 58 x - 95 x + 43 x + 72 x + 60 x + 89 x + 15 x + 12 x
The quotient polynomial is:
>> pretty(poly2sym(q))
2 275
-2/7 x - 2/49 x - ---
343
The first derivative of the polynomial defined by a is:
>> pretty(poly2sym(polyder(a)))
5 4 3 2
12 x - 20 x + 20 x + 24 x
The first derivative of the product of polynomials defined by a and b is:
>> pretty(poly2sym(polyder(a,b)))
9 8 7 6 5 4 3 2
-140 x + 522 x - 760 x + 301 x + 432 x + 300 x + 356 x + 45 x + 12
The first derivative of the polynomial quotient a/b will be q/d where q and d are as follows:
>> [q,d]=polyder(a,b);
>> pretty(poly2sym(q))
9 8 7 6 5 4 3 2
-28 x + 118 x - 120 x + 251 x - 192 x + 180 x + 220 x - 45 x - 12
>> pretty(poly2sym(d))
8 7 6 5 4 2
49 x - 210 x + 225 x - 168 x + 360 x + 144 x
EXERCISE 3-2
Find the characteristic polynomial of the matrix whose rows are the vectors [2,-4,5,8], [0,0,0,1], [-7,15,0,12] and [0,-1,-1,0]. Also find the roots of this polynomial and verify that the matrix satisfies the characteristic polynomial equation.
>> A=[2,-4,5,8;0,0,0,1;-7,15,0,12;0,-1,-1,0]
A =
2 -4 5 8
0 0 0 1
-7 15 0 12
0 -1 -1 0
>> p=poly(A)
p =
1.0000 -2.0000 48.0000 -67.0000 33.0000
>> pretty(poly2sym(p))
4 3 2
x - 2 x + 48 x - 67 x + 33
To find the roots of the characteristic polynomial we do the following:
>> roots(p)
ans =
0.2836 + 6.8115i
0.2836 - 6.8115i
0.7164 + 0.4435i
0.7164 - 0.4435i
To verify that the matrix A satisfies the characteristic polynomial, we evaluate the characteristic polynomial at the matrix A and observe that it (almost) returns the null matrix.
>> polyvalm(p,A)
ans =
1.0E-012 *
0.4619 - 0.9663 0.0426 - 0.9095
0.0016 - 0.0071 0.0142 0.0142
0.1181 - 0.0568 0.6466 0.7390
-0.0995 0.2132 - 0.0140 0.1634
EXERCISE 3-3
Expand the following polynomial expressions:
>> syms x y z
>> pretty(expand(simple(5*x^3*y^2*z-4*x*y^2*z^3)^3))
9 6 3 7 6 5 5 6 7 3 6 9
125 x y z - 300 x y z + 240 x y z - 64 x y z
>> pretty(expand((x+y)*(x^4+x^2*y^2+y^4)*(x-y)))
6 6
x - y
Here we see that the first polynomial presents difficulties when we try to expand it using only the command expand; we need to use the simple command first.
EXERCISE 3-4
Factorize the following polynomial expressions as much as possible.
a) 4x2 + y2t2 + z4 − 4xyt + 4xz2 − 2ytz2
b) x4 − x2y2 + 2xy2 + x2 − 2x3 − y2
c) amx + amy − bmx − bmy + bnx − anx − any + bny
>> syms x y z t a b m n
>> pretty(factor(4*x^2+y^2*t^2+z^4-4*x*y*t+4*x*z^2-2*y*t*z^2))
2 2
(2 x - y t + z )
>> pretty(factor(x^4- x^2*y^2+2*x*y^2+x^2-2*x^3-y^2))
2
(x - 1) (x - y) (x + y)
>> pretty(factor(a*m*x+a*m*y-b*m*x-b*m*y+b*n*x-a*n*x-a*n*y+b*n*y))
- (x + y) (n - m) (- b + a)
In general, in polynomial expressions, the command expand performs operations and simplifies the result, and the command factor factorizes as much as possible.
3-2. Extracting Parts of a Polynomial
The following commands enable MATLAB to extract various parts of a polynomial (after prior use of the maple command):
Here are some examples:
>> pretty (sym (maple('p:= 2*x^2 + 3*y^3-5:'))))
>> pretty(sym(maple('coeff(p,x,2), coeff(p,x^2), coeff(p,x,0) ')))
3
2, 2, 3 y - 5
>> pretty (sym (maple ('q: = 3 * a * (x + 1) ^ 2 + sin (a) * x ^ 2 * y - y ^ 2 * x + x - a:')))
>> pretty(sym(maple('coeff(q,x)')))
2
6 a - y + 1
>> pretty(sym(maple('q := collect(q,x)')))
2 2
q: = (sin (a) y + 3a) x + (6 a - y + 1) x + 2a
>> pretty(sym(maple('coeff(q,x)')))
2
6 a - y + 1
>> pretty(sym(maple('s := 3*v^2*w^3*x^4+1')))
2 3 4
s: = 3 v w x + 1
>> pretty(sym(maple('lcoeff(s), tcoeff(s), lcoeff(s, [v,w], t), t')))
4 2 3
3, 1, 3 x, v w
>> maple('degree(2/x^2+5+7*x^3,x), ldegree(2/x^2+5+7*x^3,x),degree(x*sin(x),x)')
3, - 2, FAIL
>> maple('degree(x*sin(x),sin(x)), degree((x+1)/(x+2),x),degree(x*y^3+x^2,[x,y]) ')
1, FAIL, 2
>> pretty(sym(maple('degree(x*y^3+x^2,{x,y}), ldegree(x*y^3+x^2,[x,y]) ')))
4, 4
>> pretty(sym(maple('expr := 3*x^2*y^4 - 2*x*y^5 + x')))
>> pretty(sym(maple('indets(expr), sign(expr), sign(expr, [x,y]), sign(expr, [y,x]), sign(expr, [y,x], a), a')))
{x, y}, 1, 1, - 1, - 1, x * y ^ 5
3-3. Factorization of Polynomials
This section presents the commands that implement various polynomial factorizations (following prior use of the maple command).
Here are some examples:
>> pretty(sym(maple('factor(x^3+5)')))
3
x + 5
>> pretty(sym(maple('factor(x^3+5.0)')))
2
(x + 1.709975947). (x - 1.709975947 x + 2.924017740).
>> pretty(sym(maple('factor(a^3+a^2+a+1) ')))
2
(a + 1) (a + 1)
>> pretty(sym(maple('factor(a^3+a^2+a+1,complex) ')))
(a + 1.) (a + 1.) I) (a - 1. I)
>> pretty(sym(maple('readlib(factors):factors(a^10-2*a^5+1) ')))
3 4 2
[1, [[a - 1, 2], [a + a + a + a + 1, 2]]]
>> pretty(sym(maple('readlib(factors):factors(a^10-2*a^5+1,real) ')))
2
[1, [[a + 1.618033989 a + 1.000000000, 2], [a - 1., 2],]]
2
[[[a.6180339888 a + 1.000000000, 2]]]
>> pretty(sym(maple('Factors(a^10-2*a^5+1) mod 7')))
4 3 2
[1, [[a + 6, 2], [a + a + a + a + 1, 2]]]
>> pretty(sym(maple('Factor(a^10-2*a^5+1) mod 7')))
2 4 3 2 2
(a + 6) (a + a + a + a + 1)
>> pretty(sym(maple('Factor(a^10-2*a^5+1)')))
10 5
Factor(a - 2 a + 1)
>> pretty(sym(maple('evala(")')))
4 3 2 2 2
(a + a + a + a + 1) (a - 1)
>> pretty(sym(maple('readlib(split): split(x^2+x+1,x)')))
2 2
(x - RootOf(_Z + _Z + 1)) (x + 1 + RootOf(_Z + _Z + 1))
>> pretty(sym(maple('readlib(splits): splits(x^2+x+1,x)')))
2 2
[1,[[x - RootOf(_Z + _Z + 1), 1], [x + 1 + RootOf(_Z + _Z + 1), 1] ]]
>> pretty(sym(maple(' f := x^3*y-x^3-x^2*y^2+x^2*y')))
>> pretty(sym(maple('sqrfree(f,x) ')))
[y - 1, [[-y + x, 1], [x, 2]]]
>> pretty(sym(maple('sqrfree(f,y)')))
2 2
[-x , [[-x y + x + y - y, 1]]]
>> pretty(sym(maple('sqrfree(f,[x,y])')))
[1, [[y - 1, 1], [-y + x, 1], [x, 2]]]
>> pretty(sym(maple('Sqrfree(4*x^2+4*x+1) mod 7')))
[4, [[x + 4, 2]]]
>> pretty(sym(maple('irreduc( x^3+5 )')))
true
>> pretty(sym(maple('irreduc( x^3+5, 5^(1/3))')))
false
>> pretty(sym(maple('Irreduc(2*x^2+6*x+6) mod 7,Factor(2*x^2+6*x+6) mod 7')))
false, 2*(x+6)*(x+4)
>> pretty(sym(maple('Irreduc(x^4+x+1) mod 2, Factor(x^4+x+1) mod 2')))
true, x^4+x+1
As we have already seen many examples and exercises relating to factorization of univariate and multivariate polynomials, we shall present only a pair of exercises.
EXERCISE 3-5
Factorize the polynomial a4 - 9/4 in the following cases:
(a) over the field defined by its coefficients
(b) over the real field
(c) over the complex field
(d) over the algebraic extension Q(√2,√3)
(e) over the algebraic extension Q(√2,√3, i)
(f) over the algebraic extension Q(RootOf(Z^2+3/2)).
>> pretty(sym(maple('factor(a^4-9/4)')))
2 2
1/4 (2 a - 3) (2 a + 3)
>> pretty(sym(maple('factor(a^4-9/4,real)')))
2
(a + 1.224744871) (a - 1.224744871) (a + 1.499999999)
>> pretty(sym(maple('factor(a^4-9/4,complex)')))
(a + 1.224744871)(a + 1.224744871 I)(a-1.224744871 I)(a-1.224744871)
>> pretty(sym(maple('factor(a^4-9/4,{(3)^(1/2),2^(1/2)})')))
2 1/2 1/2 1/2 1/2
- 1/8 (2 a + 3) (2 a + 3 2 ) (-2 a + 3 2 )
>> pretty(sym(maple('factor(a^4-9/4,{(3)^(1/2),2^(1/2),I})')))
1/2 1/2 1/2 1/2 1/2 1/2
1/16 (-2 a + I 3 2 ) (2 a + I 3 2 ) (2 a + 3 2 )
1/2 1/2
(-2 a + 3 2 )
>> pretty(sym(maple('factor(a^4-9/4,RootOf(Z^2+3/2))')))
2 2 2
1/2 (2 a - 3) (a + RootOf(2 _Z + 3)) (a - RootOf(2 _Z + 3))
EXERCISE 3-6
Determine whether the polynomial x9 + 1 is irreducible in the following cases:
(a) over the field defined by its coefficients
(b) over the algebraic extension Q(√3 i).
Perform its factorization where possible.
>> pretty(sym(maple('irreduc(x^9+1)')))
false
>> pretty(sym(maple('factor(x^9+1)')))
2 6 3
(x + 1) (x - x + 1) (x - x + 1)
>> pretty(sym(maple('irreduc(x^9+1,(-3)^(1/2))')))
false
>> pretty(sym(maple('factor(x^9+1,(-3)^(1/2))')))
3 1/2 3 1/2 1/2
1/16 (-2 x + 1 + I 3 ) (2 x - 1 + I 3 ) (-2 x + 1 + I 3 )
1/2
(2 x - 1 + I 3 ) (x + 1)
3-4. Roots of Polynomials
The following group of MATLAB commands, all of which require the prior use of the maple command, may be used to work with roots of polynomials:
Here are some examples. First, we find the roots and their multiplicities over the field defined by the coefficients of the given polynomials:
>> pretty(sym(maple('roots(2*x^3+11*x^2+12*x-9)')))
[[-3, 2], [1/2, 1]]
>> pretty(sym(maple('roots(x^3+(-6-b-a)*x^2+(6*a+5+5*b+a*b)*x-5*a-5*a*b,x)')))
[[5, 1]]
Next, we find modular integer roots and their multiplicities.
>> pretty(sym(maple('Roots(x^3-x) mod 6')))
[[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]
>> pretty(sym(maple('Roots(x^3-1) mod 2')))
[[1, 1]]
>> pretty(sym(maple('alias(a=RootOf(x^2+x+1))'))) ;
>> pretty(sym(maple('Roots(x^3-1,a) mod 2')))
[[a + 1, 1], [1, 1], [a, 1]]
Next we solve a third-degree polynomial with integer coefficients that has 1.2324 as an approximate root:
>> pretty(sym(maple('readlib(lattice) : minpoly(1.234,3)')))
2 3
109. 61 _X + 5 _X - 22 _X
Next we generate a Sturm sequence for a given polynomial in order to find the number of roots of the polynomial in the specified ranges:
>> pretty(sym(maple('readlib(sturm): sturmseq(expand((x-1)*(x-2)*(x-3)),x)')))
3 2 2
[x - 6 x + 11 x - 6, x - 4 x + 11/3, x - 2, 1]
>> pretty(sym(maple('sturm(",x,3/2,4)')))
2
>> pretty(sym(maple('sturm("",x,1,2)')))
1
Next we calculate the square and cubic roots of the given polynomials:
>> pretty(sym(maple('readlib(psqrt): psqrt(x^2+2*x*y+y^2)')))
x + y
>> pretty(sym(maple('readlib(proot): proot(x^3+3*x^2+3*x+1,3)')))
x + 1
EXERCISE 3-7
Find the roots and their multiplicities of the polynomial x4 - 4 in the following cases:
(a) over the field defined by its coefficients
(b) over the algebraic extension Q(√2)
(c) over the algebraic extension Q(√2, i)
(d) over the algebraic extension Q(RootOf(x2- 2))
(e) over the algebraic extension Q(RootOf(x2- 2),RootOf(x2+ 2))
>> pretty(sym(maple('roots(x^4-4)')))
>> pretty(sym(maple('roots(x^4-4,x)')))
>> pretty(sym(maple('roots(x^4-4,sqrt(2))')))
1/2 1/2
[[2 , 1], [-2 , 1]]
>> pretty(sym(maple('roots(x^4-4, {sqrt(2),I})')))
1/2 1/2 1/2 1/2
[[I 2 , 1], [-I 2 , 1], [2 , 1], [-2 , 1]]
>> pretty(sym(maple('alias(a = RootOf(x^2-2))'))) ;
>> pretty(sym(maple('alias(b = RootOf(x^2+2))'))) ;
>> pretty(sym(maple('roots((x^4-4), x, a)')))
[[a, 1], [-a, 1]]
>> pretty(sym(maple('roots(x^4-4, {a, b})')))
[[b, 1], [-b, 1], [, 1], [-a, 1]]
EXERCISE 3-8
Find the intervals in which the real roots of the polynomial x8 + 5 x7 - 4 x6 - 20 x5 + 4 x4 + 20 x3 are located, with the following specifications:
(a) intervals with default width
(b) intervals with a width of one unit
(c) intervals with a half-unit width
(d) intervals with a width of one thousandth of a unit
>> pretty(sym(maple('readlib(realroot)')));
>> pretty(sym(maple('realroot(x^8+5*x^7-4*x^6-20*x^5+4*x^4+20*x^3)')))
[[0, 0], [0, 8], [- 4, 0], [- 8, - 4]]
We deduce that zero is a root.
>> pretty(sym(maple('realroot(x^8+5*x^7-4*x^6-20*x^5+4*x^4+20*x^3,1)')))
[[0, 0], [1, 2], [- 1, - 2] [- 5, - 5]]
We deduce that -5 is another root.
>> pretty(sym(maple('realroot(x^8+5*x^7-4*x^6-20*x^5+4*x^4+20*x^3,1/2)')))
[[0, 0], [1, 3/2], [-3/2, -1], [-5, -5]]
>> pretty(sym(maple('realroot(x^8+5*x^7-4*x^6-20*x^5+4*x^4+20*x^3,1/1000)')))
181 1449 -1449 -181
[[0, 0], [---, ----], [-----, ----], [-5, -5]]
128 1024 1024 128
3-5. Grouping and Ordering Terms
This section presents commands that allow you to group terms into univariate and multivariate polynomials, as well as to manage them according to certain criteria. The syntax of these commands is as follows (after using the maple command):
Here are some examples:
>> pretty(sym(maple('collect(x*y+a*x*y+y*x^2-a*y*x^2+x+a*x,[x,y],recursive)')))
2
(1 - a) y x + ((1 + a) y + 1 + a) x
>> pretty(sym(maple('collect(x*y+a*x*y+y*x^2-a*y*x^2+x+a*x,[y,x],recursive)')))
2
((1 - a) x + (1 + a) x) y + (1 + a) x
>> pretty(sym(maple('collect(x*y+a*x*y+y*x^2-a*y*x^2+x+a*x,[x,y], distributed)')))
2
(1 + a) x + (1 + a) x y + (1 - a) y x
>> pretty(sym(maple('collect(x^3*y+x^2*y^3+x+3,y)')))
3 2 3
x y + x y + x + 3
>> pretty(sym(maple('sort(",y)')))
2 3 3
x y + x y + x + 3
>> pretty(sym(maple('sort(y^3+y^2*x^2+x^3,[x,y])')))
2 2 3 3
x y + x + y
>> pretty(sym(maple('sort(y^3+y^2*x^2+x^3,[x,y],plex)')))
3 2 2 3
x + x y + y
>> pretty(sym(maple('sort(y^3+y^2*x^2+x^3,[x,y],tdeg)')))
2 2 3 3
x y + x + y
3-6. Handling of Polynomials
This section presents a group of commands that allow you to perform certain manipulations on univariate and multivariate polynomials, such as conversions, compositions, working with their operands, and so on. The syntax of these commands (following prior use of the maple command) is presented below:
Here are some examples:
>> pretty(sym(maple('compoly( x^2+2*x*y-7*x+y^2-7*y+16 )')))
2
16 - 7 y + y , y = y + x
>> pretty(sym(maple('compoly( x^4+4*x^3*y^3+6*x^2*y^6+4*x*y^9+y^12+x+y^3-1, {x,y})')))
2 3 4 3
-1 - 3 y + 6 y - 4 y + y , y = x + 1 + y
>> pretty(sym(maple('indets( x*y + z/x )')))
{z, y, x}
>> pretty(sym(maple('e:=x^(1/2)+exp(x^2)+ f(9): indets(e), indets(e,function)')))
2 1/2 2
{exp(x ), x , x}, {f(9), exp(x )}
>> pretty(sym(maple('convert(x^2+3*x+4,horner,x)')))
4 + (3 + x) x
>> pretty(sym(maple('poly := y^2*x^2 + 2*y^2*x + 2*y*x^2 + 4*y*x + x^2 + 2*x: ')))
>> pretty(sym(maple('convert(poly,horner,x)')))
2 2
(2 y + 4 y + 2 + (y + 2 y + 1) x) x
>> pretty(sym(maple('convert(poly,mathorner,x)')))
2 2
2 y + 4 y + 2 + (y + 2 y + 1) x &* x
>> pretty(sym(maple('convert(poly,horner,[x,y])')))
(2 + (4 + 2 y) y + (1 + (2 + y) y) x) x
>> pretty(sym(maple('convert(x^2+4*x+4,sqrfree,x)')))
2
(x + 2)
>> pretty(sym(maple('content(3*x*y+6*y^2,x ), content(3*x*y+6*y^2,[x,y])')))
3 y, 3
>> pretty(sym(maple('icontent(3*x*y+6*y^2)')))
3
>> pretty(sym(maple('op(y^2*x^2 + 2*y^2*x + 2*y*x^2 + 4*y*x + x^2 + 2*x)')))
2 2 2 2 2
y x , 2 y x, 2 y x , 4 y x, x , 2 x
EXERCISE 3-9
Transform into square-free form with respect to the variable x the polynomial y2x3+ 2y2x2+ y2x+2yx3+ 4yx2+ 2yx. Also transform the same polynomial into square-free form with respect to the variable y. Finally, find the greatest common divisor of the coefficients of the polynomial with respect to all variables, with respect to the variable x only, and with respect to the variable y only.
>> pretty (sym (maple('poly:= y^2*x^3+2*y^2*x^2+y^2*x+2*y*x^3+4*y*x^2+2*y*x:'))))
>> pretty(sym(maple('convert(poly,sqrfree,x) ')))
2 2
(y + 2 y) x (x + 1)
>> pretty(sym(maple('convert(poly,sqrfree,y)')))
3 2 2
(x + x + 2 x ) (y + 2 y)
>> pretty(sym(maple('content(poly)')))
1
>> pretty(sym(maple('content(poly,x)')))
2
2 y + y
>> pretty(sym(maple('content(poly,y)')))
3 2
x + 2 x + x
EXERCISE 3-10
Transform the second degree polynomial 9 x2 + 24 x + 16 into completed square form. Transform x2 - 2xa + a2 + y2 - 2yb + b2 = 23 into completed square form with respect to the variable x. Transform the same expression into completed square form simultaneously with respect to both variables x and y, and with respect to the variable a.
>> pretty(sym(maple('with(student):completesquare(9*x^2 + 24*x + 16)')))
2
9 (x + 4/3)
>> pretty(sym(maple('with(student):completesquare(x^2 - 2*x*a + a^2 +
y ^ 2-2 * y * b + b ^ 2 = 23, x)')))
2 2 2
(x - a) + y - 2 y b + b = 23
>> pretty(sym(maple('with(student):completesquare(x^2 - 2*x*a + a^2 +
y^2-2*y*b + b^2 = 23, [x,y])')))
2 2
(y - b) + (x - a) = 23
>> pretty(sym(maple('with(student):completesquare(x^2 - 2*x*a + a^2 +
y^2-2*y*b + b^2 = 23, a)')))
2 2 2
(a - x) + y - 2 y b + b = 23
EXERCISE 3-11
Find the 10th Fibonacci and Euler polynomials in the variable x. Also find the degree 5 Bernstein polynomial in the variable x that approximates the functional operator yÆsin(y) in the interval [0,1].
>> pretty(sym(maple('with(combinat):fibonacci(10,x)')))
9 7 5 3
x + 8 x + 21 x + 20 x + 5 x
>> pretty(sym(maple('with(combinat):euler(10,x)')))
10 9 7 5 3
x - 5 x + 30 x - 126 x + 255 x - 155 x
>> pretty(sym(maple('readlib(bernstein):bernstein(5,y->sin(y),x)')))
2 3 4 5
(5 x - 20 x + 30 x - 20 x + 5 x ) sin(1/5)
2 3 4 5
+ (10 x - 30 x + 30 x - 10 x ) sin(2/5)
3 4 5 4 5 5
+ (10 x - 20 x + 10 x ) sin(3/5) + (5 x - 5 x ) sin(4/5) +x sin(1)
EXERCISE 3-12
Given the following polynomial matrix:
Find its Hermite normal form in the variable x.
Find its Smith normal form in the variable x.
Find its Hermite normal form in the variable y.
Find its Smith normal form in the variable y.
>> maple('p:=x-1;q:=x+1;r:=x^2-1;s:=x^2+1'),
>> maple('M:=[[p,q],[r,s]]') ;
>> pretty(sym(maple('with(linalg):hermite(M,x)')))
[x - 1 1]
[ ]
[ 0 x]
>> pretty(sym(maple('with(linalg):smith(M,x)')))
[1 0 ]
[ ]
[ 2 ]
[0 x - x]
>> pretty(sym(maple('with(linalg):hermite(M,y),smith(M,y)')))
[1 0] [1 0]
[ ], [ ]
[0 1] [0 1]
3-7. Divisibility and Operations with Polynomials
MATLAB provides various tools for the analysis of divisibility. It can also perform a wide variety of operations on polynomials. We summarize below the commands it provides for these tasks (each of which requires the prior use of the maple command):
Here are some examples. First, we find the discriminant of the polynomial ax2+ bx:
>> pretty(sym(maple('p := a*x^2 + b*x + c: discrim(p,x)')))
2
-4 c + b
Now we calculate the resultant of several polynomials:
>> pretty(sym(maple('resultant(a*x+b,c*x+d,x), resultant((x+a)^5,(x+b)^5,x)')))
25
-c b + d a, (-a + b)
>> pretty(sym(maple('Resultant(2*x+1, 3*x+4, x) mod 7')))
5
>> pretty(sym(maple('r := x + RootOf(_Z^2-2): s := RootOf(_Z^2-2)*x + 1:
evala(Resultant(r,s,x))')))
-1
Next we check divisibility among polynomials, and in the positive case, find the ratios:
>> pretty(sym(maple('divide(x^3-y^3, x-y, q),q')))
2 2
true, x + x y + y
>> pretty(sym(maple('Divide(x^3+x^2+2*x+3,x+2,q) mod 5,q')))
2
true, x + 4 x + 4
Next we find quotients and remainders of division between polynomials:
>> pretty(sym(maple('rem(x^3+x+1, x^2+x+1, x, q), q')))
x + 2, x - 1
>> pretty(sym(maple('quo(x^3+x+1, x^2+x+1, x) ')))
x - 1
>> pretty(sym(maple('a := x^4+5*x^3+6: b := x^2+2*x+7: r := Rem(a,b,x,q) mod 13, q')))
>> maple r
ans =
5*x+6, x^2+3*x
EXERCISE 3-13
Find the greatest common divisor and least common multiple of the polynomials x2- y2 and x3- y3, and also the polynomials x+2 and x+3 modulo 7. Find the greatest common divisor for each of the sets of polynomials {x3- 1, x2 - 1} and {x2+ x + 1, x2- x + 1}, identifying the elements of Euclid’s algorithm. Also find the greatest common divisor modulo 11 of the polynomials x2 + 3 x + 2 and x2+ 4 x + 3, identifying the elements of Euclid’s algorithm.
>> pretty(sym(maple('gcd(x^2-y^2,x^3-y^3),lcm(x^2-y^2,x^3-y^3)')))
4 3 3 4
-y + x, x - x y + y x - y
>> pretty(sym(maple('gcd(x+2,x+3) mod 7, lcm(x+2,x+3) mod 7')))
2
1, x + 5 x + 6
>> pretty(sym(maple('gcdex(x^3-1,x^2-1,x,s,t),s,t')))
x - 1, 1, -x
>> pretty(sym(maple('gcdex(x^2+x+1,x^2-x+1,x,u,v),u,v')))
1, 1/2 - 1/2 x, 1/2 + 1/2 x
>> pretty(sym(maple('Gcd(x^2+3*x+2,x^2+4*x+3,f,g) mod 11, f, g')))
1 + x, x + 2, x + 3
EXERCISE 3-14
Find the 1, 2 and infinity norms of the polynomial x-3y. Also find the third and fourth powers of the polynomial x + 1 modulo 2.
>> pretty(sym(maple('norm(x-3*y,1),norm(x-3*y,2),norm(x-3*y,infinity)')))
1/2
4, 10 , 3
>> pretty(sym(maple('Power(x+1,3) mod 2, Power(x+1,4) mod 2')))
3 2 4
x + x + x + 1, x + 1
EXERCISE 3-15
Find the polynomials r, m and q in the variable x such that
m(x4+ 1) = q(cx4+1) + r.
There are two solutions to the problem; one via the pseudo-remainder between the polynomial x4+ 1 and cx2+ 1, and the other via the sparse pseudo-remainder between those polynomials.
>> pretty(sym(maple('a := x^4+1: b := c*x^2+1: r := prem(a,b,x,m,q)')))
>> pretty(sym(maple('r,m,q')))
2 3 2 2
c (c + 1), c , x c - c
>> maple('restart') ;
>> pretty(sym(maple('a := x^4+1: b := c*x^2+1: r := sprem(a,b,x,m,q)')))
>> pretty(sym(maple('r,m,q')))
2 2 2
c + 1, c , c x - 1
EXERCISE 3-16
Find the primitive part of the polynomial 4xy + 6y2 and x/a-1/2 in the variable x. Also find the primitive part of the polynomial x (y+4) + y2 + 4 in the variable x modulo 5.
>> maple ('restart')
>> pretty(sym(maple('primpart(-4*x*y + 6*y^2, x), primpart(x/a - 1/2,x)')))
3, - 2 x, 2 x - a
>> pretty(sym(maple('Primpart(x * (y+4) + y ^ 2 + 4 x) mod 5')))
x + y + 1
EXERCISE 3-17
Perform the following tasks concerning random polynomials:
Create a random polynomial in x of 6 terms.
Create a random 20 term polynomial in the variables x and y.
Create a random polynomial in x, cos(x) and sin(x).
Create a polynomial with random coefficients between 1 and 100.
Create a polynomial with random exponents between -5 and 5.
>> pretty(sym(maple('randpoly(x)')))
5 4 3 2
-85 x - 55 x - 37 x - 35 x + 97 x + 50
>> pretty(sym(maple('randpoly([x, y], terms = 20)')))
2 5 4 3 2
56 + 49 x + 63 y + 57 x y - 59 x y + 45 x - 8 x - 93 x + 92 x
3 2 3 2 2 3 4
+ 43 y - 62 x y + 77 x y + 66 x y + 54 x y - 5 x y
3 2 2 3 4 4 5
+ 99 x y - 61 x y - 50 x y - 12 y - 18 y
>> pretty(sym(maple('randpoly([x, sin(x), cos(x)])')))
2
-47 x - 61 x cos(x) + 41 x sin(x) cos(x) - 58 x cos(x)
3 3 2
- 90 sin(x) cos(x) + 53 sin(x) cos(x)
>> pretty(sym(maple('randpoly(x,coeffs=rand(1..100))')))
5 4 3 2
82 x + 71 x + 98 x + 64 x + 77 x + 39
>> pretty(sym(maple('randpoly(z,expons = rand(-5..5))')))
82 23 5
---- + ---- + 104 z + 88 z
5 z
Z
EXERCISE 3-18
Change the variable x of the polynomial x2 to the variable x + 1. Make the change of variable x = r1/3 in the expression 3xln(x3) and also the change of variable sin(x) = y in the expression sin(x) / (1-sin(x))1/2.
The first change of variable is a simple translation of a polynomial variable, so it will be done via the command translate, but the other two changes involve general algebraic expressions, so we will use the command subs as described in the previous chapter.
>> pretty(sym(maple('readlib(translate):translate(x^2,x,1)')))
2
1 + 2 x + x
>> pretty(sym(maple('subs(x=r^(1/3), 3*x*log(x^3))')))
1/3
3 r log(r)
>> pretty (sym (maple ('subs (y = sin (x),sin (x) / (1 - sin (x)) ^(1/2))')))
y
----------
1/2
(1 - y)
EXERCISE 3-19
Find the reciprocal polynomial of the polynomial x4 + x3 + x + 1. Also calculate the resultant of the polynomial and its reciprocal.
>> pretty(sym(maple('readlib(recipoly):recipoly(x^4+x^3+x+1,x,'p'),p')))
2
true, -2 + x + x
>> pretty(sym(maple('resultant(x^4+x^3+x+1,x^2+x-2,x)')))
28
3-8. Interpolation and Polynomial Fitting
MATLAB provides several commands for polynomial interpolation and fitting that we will study next:
EXERCISE 3-20
Calculate the interpolated degree 2 polynomial passing through the points (- 1,4), (0,2) and (1,6) which is the best fit in the least-squares sense.
>> x=[-1,0,1];y=[4,2,6];p=poly2sym(polyfit(x,y,2))
p =
3 * x ^ 2 + x + 2
EXERCISE 3-21
Represent 200 points of cubic interpolation between the points (x,y) given by the values that the exponential function e ^ x takes at 20 equally spaced x values between 0 and 2. Also represent the difference between the function e ^ x and its approximation by interpolation. Use cubic interpolation.
First, we define the 20 given points (x, y), for x values equally spaced between 0 and 2:
>> x = 0:0.1:2;
>> y = exp(x);
Now we find 200 points (xi, yi) using cubic interpolation, equally spaced between 0 and 2, and plot them on a graph, together with the 20 initial points (x, y) (indicated by asterisks). See Figure 3-1:
>> xi = 0:0.01:2;
>> yi = interp1(x,y,xi,'cubic'),
>> plot(x,y,'*',xi,yi)
We now graphically represent the difference between the exact function y = e ^ x and the function obtained by the above interpolation. In the case of zero error, the graph would be a horizontal line coinciding with the x axis. See Figure 3-2.
>> zi=(exp(xi));
>> di=yi-zi;
>> plot(xi,di)
EXERCISE 3-22
Find 25 interpolation points of the parametric function X = cos(t), Y = sin(t), Z = tan(t) for values of t between 0 and π/6, based on the set of points defined for values of t = iπ/6 with 0 ≤ i ≤ 6.
First, we define the 25 given points (x, y, z), equally spaced between 0 and π / 6.
>> t = 0: pi/150: pi/6;
>> x = cos (t); y = sin (t); z = tan (t);
Now we find the 25 points of interpolation (xi, yi, zi), for values of the parameter t equally spaced between 0 and π /6.
>> xi = cos (t); yi = sin (t);
>> zi = griddata(x,y,z,xi,yi);
>> points = [xi, yi, zi']
points =
1.0000 0 0.0000
0.9998 0.0209 0.0161
0.9991 0.0419 0.0367
0.9980 0.0628 0.0598
0.9965 0.0837 0.0836
0.9945 0.1045 0.1057
0.9921 0.1253 0.1269
0.9893 0.1461 0.1480
0.9860 0.1668 0.1692
0.9823 0.1874 0.1907
0.9781 0.2079 0.2124
0.9736 0.2284 0.2344
0.9686 0.2487 0.2567
0.9632 0.2689 0.2792
0.9573 0.2890 0.3019
0.9511 0.3090 0.3249
0.9444 0.3289 0.3483
0.9373 0.3486 0.3719
0.9298 0.3681 0.3959
0.9219 0.3875 0.4203
0.9135 0.4067 0.4452
0.9048 0.4258 0.4706
0.8957 0.4446 0.4969
0.8862 0.4633 0.5236
0.8763 0.4818 0.5505
0.8660 0.5000 0.5774
EXERCISE 3-23
Find 30 interpolation points (xi, yi) for the periodic function y = sin(x) for values of x that are equally spaced, interpolating them between values of (x, y) given by y = sin(x) for 20 x values evenly spaced in the interval (0,2π), and using the interpolation method based on the fast Fourier transform (FFT).
First, we define the 20 x values equally spaced between 0 and 2π:
>> x =(0:pi/10:2*pi);
Now we find the 30 interpolation points (x, y).
>> y = interpft(sin(x), 30);
>> points = [y', (asin(y))']
points =
0.0000 0.0000
0.1878 0.1890
0.4499 0.4667
0.6070 0.6522
0.7614 0.8654
0.9042 1.1295
0.9618 1.2935
0.9963 1.4848
0.9913 1.4388
0.9106 1.1448
0.8090 0.9425
0.6678 0.7312
0.4744 0.4943
0.2813 0.2852
0.0672 0.0673
-0.1640 - 0.1647
-0.3636 - 0.3722
-0.5597 - 0.5940
-0.7367 - 0.8282
-0.8538 - 1.0233
-0.9511 - 1.2566
-1.0035 - 1.5708 - 0. 0837i
-0.9818 - 1.3799
-0.9446 - 1.2365
-0.8526 - 1.0210
-0.6902 - 0.7617
-0.5484 - 0.5805
-0.3478 - 0.3553
-0.0807 - 0.0808
0.0086 0.0086
EXERCISE 3-24
Find the degree 3 polynomial that best fits the set of points (i, i2) for 1≤ i ≤ 7, in the least-squares sense. Find the value of the polynomial at x = 10 and graphically represent the fitted curve.
>> x=(1:7);y=[1,4,9,16,25,36,49];p=poly2sym(polyfit(x,y,2))
p =
4503599627370495/4503599627370496 * x ^ 2 +
310800181380337/79228162514264337593543950336 * x-3598276744230861/316912650057057350374175801344
Now we calculate the numerical value of the polynomial p at x = 10.
>> numeric(subs(p,10))
ans =
100
We can also approximate the coefficients of the polynomial p to 5 digits.
>> vpa(p,5)
ans =
1.00000 * x ^ 2 + 3 9228e-15 * x-1. 1354e-14
Figure 3-3 shows the graph of the fitted curve.
>> ezplot(p,[-5,5])
EXERCISE 3-25
Find the interpolated degree 2 polynomial passing through the points (-1,4), (0,2) and (1,6). Find the interpolated polynomial modulo 3 and, finally, perform Thiele interpolation for this case.
>> interp([-1,0,1],[4,2,6],x);
2
3 x + x + 2
>> Interp([-1,0,1],[4,2,6],x) mod 3;
x + 2
>> readlib(thiele):thiele([-1,0,1],[4,2,6],x);
x + 1
4 + -------------
- 1/2 + 3/2 x
3-9. Galois Extensions
The Maple program has commands which enable you to work with the Galois theory of finite fields and their extensions. The syntax of these commands is as follows:
EXERCISE 3-26
Find the Galois group for each of the univariate polynomials x4 + x + 1, t5 - 5t + 12, x5 + 2 and x7 + 4x5 - 3x2 + 5.
First, we check if the polynomials are irreducible; if so, we will calculate the Galois groups.
>> pretty(sym(maple('irreduc(x^4+x+1),irreduc(t^5-5*t+12),irreduc(x^5+2), irreduc(x^7+4*x^5- 3*x^2+5)')))
true, true, true, true
>> pretty(sym(maple('galois(x^4+x+1)')))
S4, 24, {(1 2 3 4), (1 2)}
>> pretty(sym(maple('galois(t^5-5*t+12)')))
+D5, 10, {(1 2 3 4 5), (2 5)(3 4)}
>> pretty(sym(maple('galois(x^5+2)')))
F20, 20, {(1 2 3 4 5), (2 3 5 4)}
>> pretty(sym(maple('galois(x^7+4*x^5-3*x^2+5)')))
S7, 5040, {(1 2 3 4 5 6 7), (1 2)}
EXERCISE 3-27
Consider the polynomial q = α4 + α + 1. Verify that it is irreducible over the integers and over the integers modulo 2. Consider the finite Galois field GF(24) and the Galois extension GF(2)[x]/(q). Perform the operations 3 + 4, 3 * 4 and 34 in this field. Convert the integer 12Œ[0,24- 1] to the corresponding element in the finite Galois field GF(24), and then do the reverse conversion. Convert the polynomial α to a Maple sum of products ‘a’ in the finite Galois field GF(24). Calculate α2 and α4 and check if a is a primitive element in GF(24). Find the corresponding value of x =a8 in the interval [0,24- 1] and its polynomial form in the Galois extension.
>> pretty(sym(maple('irreduc(alpha^4+alpha+1)')))
true
>> pretty(sym(maple('Irreduc(alpha^4+alpha+1) mod 2')))
true
>> pretty(sym(maple('readlib(GF):')))
>> pretty(sym(maple('G16 := GF(2,4,alpha^4+alpha+1):')))
>> pretty(sym(maple('G16[`+`](3,4), G16[`*`](3,4), G16[`^`](3,4)')))
5, 4, 3
>> pretty(sym(maple('G16[input](12)')))
1000100000000
>> pretty(sym(maple('G16[output](")')))
12
>> pretty(sym(maple('a := G16[ConvertIn](alpha)')))
>> pretty(sym(maple('a')))
10000
>> pretty(sym(maple('G16[`*`](a,a), G16[`^`](a,4)')))
100000000, 10001
>> pretty(sym(maple('G16[isPrimitiveElement](a)')))
true
>> pretty(sym(maple('x := G16[`^`](a,8)')))
>> pretty(sym(maple('x')))
100000001
>> pretty(sym(maple('G16[output](x)')))
5
>> pretty(sym(maple('G16[ConvertOut](x)')))
2
Alpha + 1
EXERCISE 3-28
Consider the polynomial q = b5 + 7b4 + b2 + b+1. Check that it is irreducible over the integers and over the integers modulo three. Consider the finite Galois field GF(35) and the Galois extension GF(3)[x]/(q). Calculate the product (b5+ 1)(b3+ b2+ 1) in the Galois extension and calculate its inverse.
First, we check that the polynomial is irreducible over the integers and over the integers modulo 3.
>> pretty(sym(maple('irreduc(b^5+7*b^4+b^2+b+1),irreduc(b^5+7*b^4+ b^2+b+1) mod 3')))
true, true
Then we transform the given polynomial to its corresponding value in the Galois field GF(35) and find the stated product in this field.
>> pretty(sym(maple('readlib(GF):')))
>> pretty(sym(maple('G243 := GF(3,5,b^5+7*b^4+b^2+b+1):')))
>> pretty(sym(maple('a1:=G243[ConvertIn](b^5+1)')))
>> pretty(sym(maple('a1')))
20000000200020000
>> pretty(sym(maple('a2:=G243[ConvertIn](b^3+b^2+1)')))
>> pretty(sym(maple('a2')))
1000100000001
>> pretty(sym(maple('prod1:=G243[`*`](a1,a2)')))
>> pretty(sym(maple('prod1')))
20000000100000001
Finally, we convert the value to its corresponding value in the extension GF(3)[x]/(q).
>> pretty(sym(maple('prod2:=G243[ConvertOut](prod1)')))
>> pretty(sym(maple('prod2')))
4 2
2 b + b + 1
To find the inverse of the product, we first convert it to the corresponding element in the Galois field GF(35). After finding the inverse we find the corresponding element in the extension GF(3)[x]/(q).
>> pretty(sym(maple('inv1:=G243[inverse](prod1)')))
>> pretty(sym(maple('inv1')))
20000000200010001
>> pretty(sym(maple('G243[`*`](prod1,inv1)')))
1
>> pretty(sym(maple('inv2:=G243[ConvertOut](inv1)')))
>> pretty(sym(maple('inv2')))
4 2
2 b + 2 b + b + 1
3-10. Gröbner Bases
Gröbner bases are used in the solution and analysis of solutions of systems of polynomial equations. The related MATLAB commands are as follows:
EXERCISE 3-29
Consider the following system of three polynomials: x2 - 2xz + 5, xy2 + yz3, 3y2 - 8z3. Test whether the system is solvable with respect to its three variables and has a finite number of solutions. Find a Gröbner basis for such a system and from that try to solve it. Also find a minimal reduced Gröbner basis in lexicographical order and total order.
First, we try to solve the system directly, but we find that this is not possible; only an approximate solution can be found.
>> pretty(sym(maple('solve({x^2-2*x*z+5=0,x*y^2+y*z^3=0,3*y^2-8*z^3=0})')))
2
{x = RootOf(_Z + 5), y = 0, z = 0}, {}
2 5 4
x = - 3/4 %1 - 9/20% 1 + 12/5% 1,
2 2 3
y = 2/5 %1 (- 16% 1 + 3% 1 + 5), z = 2 %1}
3 5 6
%1: = RootOf(30 _Z + 25-48 _Z + 9 _Z)
>> pretty(sym(maple('allvalues({x^22*x*z+5=0,x*y^2+y*z^3=0,3*y^28*z^3=0})')))
2 2 3 2 3
{ x – 2 z x + 5 = 0, x y + y z = 0, 3 y - 8 z = 0}
Now we confirm that the system is solvable with a finite number of solutions.
>> pretty(sym(maple('with(grobner):F:=[x^2-2*x*z+5,x*y^2+y*z^3,3*y^2-8*z^3]: ')))
>> pretty(sym(maple('solvable(F); finite(F)')))
true, true
Then we find a Gröbner basis for the system with the command gsolve, and subsequently try to solve it with the command solve.
>> pretty(sym(maple('gsolve(F)')))
2 5 4 2
[[y, z, x + 5], [80 y - 3 z + 32 z - 40 z ,
4 5 2 3 5 6
-96 z + 640 x + 9 z + 120 z , 240 z + 1600 - 96 z + 9 z ]]
A solution of the system could be obtained with solve in the following way:
>> pretty(sym(maple('solve({y=0, z=0, x^2 + 5=0})')))
2
{x = RootOf(_Z + 5), y = 0, z = 0}
>> pretty(sym(maple('allvalues(")')))
1/2 1/2
{y = 0, x = I 5 , z = 0}, {y = 0, x = -I 5 , z = 0}
The rest of the solutions can be found as follows:
>> pretty(sym(maple('solve({80*y-3*z^5+32*z^4-40*z^2=0, 96 * z ^ 4 + 640 * x + 9 * z ^ 5 +
120 * z ^ 2 = 0, 240 * z ^ 3 + 1600-96 * z ^ 5 + 9 * z ^ 6 = 0}) ')))
2 2 3
{y = 2/5 %1 (-16 %1 + 3 %1 + 5), z = 2 %1,
2 2 3
x = - 3/20 %1 (-16 %1 + 3 %1 + 5)}
3 5 6
%1 := RootOf(30 _Z + 25 - 48 _Z + 9 _Z )
>> pretty(sym(maple('allvalues(")')))
{x = -.9186354143 + 1.100517108 I, y = 2.449694438 - 2.934712287 I,
z = -1.576863306 - .7885511972 I},
{x = -.9186354143 - 1.100517108 I, y = 2.449694438 + 2.934712287 I,
z = -1.576863306 + .7885511972 I},
{x = .2580043290 + 1.169756595 I, y = -.6880115440 - 3.119350920 I,
z = .5785194088 - 1.453171854 I},
{x = .2580043290 - 1.169756595 I, y = -.6880115440 + 3.119350920 I,
z = .5785194088 + 1.453171854 I},
{x = 2.058161202, y = -5.488429872, z = 2.243757078},
{z = 10.41959738, x = 20.59643412, y = -54.92382432}
Then we find a minimal reduced Gröbner basis, first in lexicographical order and then in order of total degree.
>> pretty(sym(maple('gbasis(F,[y,x,z],plex)')))
2 3 3 8 7 5 2
[3 y - 8 z , 80 y z - 3 z + 32 z - 40 z , x - 2 x z + 5,
7 8 5 3
-96 z + 9 z + 120 z + 640 z x,
6 3 8 9
240 z + 1600 z - 96 z + 9 z ]
>> pretty(sym(maple('gbasis(F,[x,y,z],tdeg) ')))
2 2 3 2 3 4 3 2
[x - 2 x z + 5, -3 y + 8 z , 8 x y + 3 y , 9 y + 48 z y + 320 y ]
3-11. The mod Operator: Modular Operations with Polynomials
The operator mod evaluates an expression modulo m for a non-zero natural number m. MATLAB uses two representations for an integer modulo m. The positive mod m representation is an integer between 0 and m-1. The symmetric mod m representation is an integer between -floor((abs(m)-1)/2) and floor(abs(m)/2). The first operand of the mod operator generally tends to be an expression that will be evaluated by MATLAB over the ring of integers modulo n. For polynomials, MATLAB reduces the coefficients modulo m. When the first operand is a power, MATLAB uses the inert representation of the power, for example, i & ^ j mod m is calculated as ij mod m. Among the commands that use the mod operator with polynomials are, in addition to those we’ve already seen, the following (all require the prior use of the maple command):
Here are some examples:
>> pretty(sym(maple('p:= 11: a:= x^4-1')))
>> pretty(sym(maple('a := modp1(ConvertIn(a,x),p)')))
>> pretty(sym(maple('a')))
a := 1000000000000000000000000000000000010
>> pretty(sym(maple('modp1(ConvertOut(a,x),p),modp1(ConvertOut(a),p)')))
4
x + 10, [10, 0, 0, 0, 1]
>> pretty(sym(maple('b:=modp1(Randpoly(3),p):c:=modp1(Rem(a,b),p):
d:=modp1(Roots(a),p)')))
>> pretty(sym(maple('b,c,d')))
7000400010008, 400050001, [[1, 1], [10, 1]]
>> pretty(sym(maple('modp1(Factors(a),p)')))
[1, [[1000000001, 1], [1000000010, 1], [1000000000000000001, 1]]]
>> pretty(sym(maple('a:=x^4*y^2-1:b := modp2(ConvertIn(a,x,y),p)')))
>> pretty(sym(maple('b')))
[10 0 0 0 100000000]
EXERCISE 3-30
Consider the matrix M = [[a, b, c], [d, e, f], [g, h, k]] whose elements are, respectively, the following univariate modp1 modulo 5 polynomials: [[1, x + 1, x - 1], [2, x2 + 1, x2 - 1], [x, (x + 1)2,(x - 1)2]]. Find the following:
- The sum, product, and least common multiple of a and b modp1 modulo 5.
- The fourth power of the polynomial k modp1 modulo 5.
- M2, the determinant of M, the inverse of M and the Jordan diagonal form of M.
We begin by transforming the given format polynomials modp1 modulo 5.
>> maple('a:=modp1(ConvertIn(1,x),5):b:=modp1(ConvertIn(x+1,x),5):
c:=modp1(ConvertIn(x-1,x),5):d:=modp1(ConvertIn(2,x),5):
e:=modp1(ConvertIn(x^2+1,x),5):f:=modp1(ConvertIn(x^2-1,x),5):
g:=modp1(ConvertIn(x,x),5):h:=modp1(ConvertIn(x^2+2*x+1,x),5):
k:=modp1(ConvertIn(x^2-2*x+1,x),5):')
Then we perform the operations requested on the variables a and b.
>> pretty(sym(maple('modp1(Add(a,b),5)')))
10002
>> pretty(sym(maple('modp1(Multiply(a,b),5)')))
10001
>> pretty(sym(maple('modp1(Lcm(a,b),5)')))
10001
>> pretty(sym(maple('modp1(Power(k,4),5)')))
100020003000400000004000300020001
Now we define the matrix M and carry out the specified matrix operations.
>> maple('M: = matrix([[a,b,c],[d,e,f],[g,h,k]])')
M := matrix([[1, 10001, 10004], [2, 100000001, 100000004], [10000, 100020001, 100030001]])
>> pretty(sym(maple('multiply(M,M)')))
[ 100060003 2000700110006 2000800180012]
[ ]
[1000200040004 20002000700100007 20003001000140016]
[ ]
[1000500060002 20007001100080002 20008001700180005]
>> pretty(sym(maple('det(M)')))
-1999599949997
>> pretty(sym(maple('inverse(M)')))
[-999699949997 -200050003 299970000 ]
[------------- ------------- -------------]
[1999599949997 1999599949997 1999599949997]
[ ]
[-999799979998 9999 99979996 ]
[------------- ------------- -------------]
[1999599949997 1999599949997 1999599949997]
[ ]
[999799969998 10001 -99979999 ]
[------------- ------------- -------------]
[1999599949997 1999599949997 1999599949997]
>> pretty(sym((maple('evalf(jordan(M))'))))
[ 9 ]
[.20002500462526246741730553617573 10 , 0 , 0]
[ ]
[ -24 ]
[0 , 5000.3739380021880602966411765771 - .86603 10 i , 0]
[ ]
[ -24 ]
[0 , 0 , -1.9992004696053658328169045771 + .86603 10 i]