Math 5-385
Info about using Maple for computing with polynomials
Last updated: November 3, 2008
General intro: At the beginning, we'll just use Maple to do compute GCD's of polynomials and maybe also to use the division algorithm a bit. But we could do a lot of this by hand. The real point is to get used to Maple so that we can use it later for Groebner basis calculations, where it really will be useful.
Contents
Starting Maple
Getting help in Maple
Type ?
at the maple prompt
>
to get a list of general
help topics. Typing ?topic
gives information about a particular command. For instance
?intro gives a general
introductory discussion about maple, while
?gcd gives information about how to use
the maple command gcd , which computes the GCD of two
polynomials.
Remote access for running maple
Entering commands in Maple
Storing answers for later use
Adding text to your worksheet.
Printing from Maple
Saving your work as a Maple
worksheet
Quitting Maple
Calculations with polynomials
in 1 variable
The Groebner package
Other useful commands
Comments and questions to: roberts@math.umn.edu
Back to
the help page index.
Back to the Math 5385 class homepage.
[hostname] 501 $ maple
|\^/|
Maple 10 (IBM INTEL LINUX)
._|\| |/|_. Copyright (c) 2005 by Waterloo Maple Inc.
\ MAPLE / All rights reserved. Maple is a registered trademark of
<____ ____> Waterloo Maple Inc.
| Type ? for help.
>
In the Xwindows version help commands pop up windows
which can be navigated by scrolling and mouse clicks.
If Maple isn't installed at your remote location, then you can
connect to a math department machine exactly as in the
remote access for the Matlab scripts.
If you're doing the command-line version (sufficient for most polynomial
computations), then a machine without Xwindows capability (i.e. only an
ssh client) is good enough!
If you want to see the output, then the command line must
end with a semicolon ; -- this is different
from Matlab!
For instance, to compute the GCD of
x6 - 1 and x4 - 1,
type:
gcd(x^4 - 1, x^6 - 1);
The help commands, however, don't end with a semicolon.
Of course, we must use the "hat symbol" ^ to have our exponents recognized correctly. Once this is
done, however,
it may appear that we're stuck in the exponent mode. To escape from use the right arrow key.
(The arrow keys usually
are at the bottom, just to the right of the main
part of the keyboard.) So, we really enter something more like this:
(Here the sequence -> is used
to indicate the rightarrow key.)
For instance:
g := gcd(x^4 - 1, x^6 - 1);
will print the value of g and also save it for use in
later calculations.
To add text to the end of any line (whether
or not anything else is already there), go to the upper left corner of the main
Maple window, and click "Text" instead of "Math". You also can start such
a line ahead of time, in order to have a header.
While your worksheet window is active, pull down the File
menu on the main Maple window, and select Print ...
If you're in Vincent 314, select
vinp314 from the list of printers.
(Or if a printer command is shown in a dialog box, make sure that the
command is lpr -Pvinp314
If working from a remote location, follow the instructions in the
remote printing instructions for
the Matlab scripts.
After selecting a worksheet document, click the Open button at the bottom
of the dialog box.
For instance:
> gcd(x^4 - 1, x^6 - 1);
2
x - 1
(This is what the output actually looks like in the command line version.)
For info about entering the exponents in the Xwindows version, please see
the important note above.
To save the answer for a future calculation:
> g = gcd(x^4 - 1, x^6 - 1);
2
g := x - 1
Now we'll use it in another calculation:
gcd(g,x^5 - 1);
x - 1
So, we have calculated the GCD of the 3 polynomials
x4 - 1, x6 - 1,
and x5 - 1.
For further information, type ?gcd
at the Maple prompt.
Combined example:
> f := x^10 - 1;
10
f := x - 1
> g := x^6 - 1;
6
g := x - 1
> q := quo(f,g);
Error, (in quo) wrong number (or type) of arguments
> q := quo(f,g,x);
4
q := x
> r := rem(f,g,x);
4
r := -1 + x
Now, let's try to check our work:
> q*g + r;
4 6 4
x (x - 1) - 1 + x
Well, that didn't quite do the trick.
But we can force Maple to simplify the answer:
> expand(q*g + r);
10
x - 1
Here's an example, involving the Reduce
command, which is discussed below:
> with(Groebner):
> Reduce(x^3*y^3*z^3, [x - y^2, x - z^2], grlex(x,y,z));
5
x y z
(The Maple help window calls this "total degree order", but if you
read the fine print, it actually explains reverse lex order correctly.)
For instance:
'matrix'([[1,1,1],[1,0,0],[0,1,0]],[x,y,z])
defines graded lex order with x > y > z. The quotes are
both single (forward) quotes. This may be needed in Math 5385
only if you're using an older version of Maple. {There are, however, other
applications of matrix-defined term orders.
Here's another version of the example given just above.
> with(Groebner):
> Reduce(x^3*y^3*z^3, [x - y^2, x - z^2], 'matrix'([[1,1,1],[1,0,0],[0,1,0]],[x,y,z]));
5
x y z
(The command was entered
as a single line in Maple, even if the line
appears to be broken in your browser window.)
Reduce(W,WL,T)
where W is a polynomial,
WL is a list or set of polynomials, and
T is a term order description.
For instance, let's check the result from
Example 4 on page 64 of the text, where we are to divide
f = x2y + xy2 + y2 by
f1 = y2 - 1 and
f2 = xy - 1:
> with(Groebner):
> Reduce(x^2*y + x*y^2 + y^2,[y^2 - 1, x*y - 1], plex(x,y));
2 x + 1
(Note the use of the square brackets [ ]
in forming the list.)
For an example using graded lex order see the discussion
of matrix defined term orders above.
For more information on the Reduce command,
type ?Groebner[Reduce]
at the Maple prompt.
Here are the calling sequences:
LeadingMonomial(W,T)
LeadingCoefficient(W,T)
LeadingTerm(W,T)
where W is a polynomial, and
T is a term order description.
For instance, let's check the example from the top of
page 57 of the text:
> with(Groebner):
> LeadingMonomial(4*x*y^2*z + 4*z^2 -5*x^3 + 7*x^2*z^2, plex(x,y,z));
3
-5, x
> LeadingMonomial(4*x*y^2*z + 4*z^2 -5*x^3 + 7*x^2*z^2, tdeg(x,y,z));
2
4, x y z
Basis(W,WL,T)
where W is a polynomial,
WL is a list or set of polynomials,
and T is a term order description.
For instance, Let's check Example 1 from pp. 86-87 of
the text, where we are to find a Groebner basis for the ideal in
k[x,y] generated by x3 - 2xy and
x2y - 2y2 + x:
> with(Groebner):
> Basis([x^3 - 2*x*y, x^2*y - 2*y^2 + x], tdeg(x,y));
2
2
[2 y - x, x y, x ]
This isn't the same as the answer obtained on page 87 of the text,
because the Groebner basis obtained there isn't minimal. If you
compare with the reduced Groebner basis for the same example,
obtained on page 89 of the text, the comparison should be pretty
clear.
Also note that the term order entered here --
tdeg(x,y) -- is actually graded reverse
lex order; this happens to coincide with graded lex order in the
case of 2 variables, and is easier to enter than the matrix description
for graded lex order.
Here's an example:
3
f := x - y z
> g:= x^2*y - z^2;
2 2
g := x y - z
> h := x*z - y^2;
2
h := x z - y
> s := SPolynomial(f,g,plex(x,y,z));
2 2
s := -y z + x z
Please note: We began our command with the string
s := in order to store the answer for possible further use;
the reasons will be explained shortly.
s := 0
A variant (needed with older versions of Maple)
There are two steps to the process:
The term order can be something like plex(x,y,z) ,
tdeg(x,y,z) , etc. The initial answer that we get
looks somewhat like "doubletalk", but the next stepwill take care of that.
Doing the above example by this method, we would enter:
> s := spoly(f,g,plex(x,y,z));
3 3 2 2 2
s := term_order[S-poly]([x - y z, 3, 1, x , 0], [x y - z ,
3, 1, x y, 0],
term_order)[1]
As expected, the answer looks as if Maple has just echoed the question.
But Maple's expand command will turn it into
something more useful:
> s:= expand(s);
2 2
s := -y z + x z
expand((x+1)^3 + (x-1)^3);
gives a polynomial answer with just two nonzero terms.
solve(x^2 + y^2 -4, x); expresses
x as a function of y subject to the equation
x2 + y2 - 4 = 0.
solve({x^2 - 1, x^3 -1},x);
finds the common roots of the polynomials
x² - 1 and x³ - 1,
while:
solve({2*x + y = 5, 3*x - y = 4}, [x,y]);
solves the system 2x + y = 5,
3x - y = 4.
G := [g1(y),
g2(x,y), g3(x,y)]
Then the solution set of our system of equations is the set of all pairs
(x,y) which satisfy all three equations
g1(y) = 0,
g2(x,y) = 0, and
g3(x,y) = 0. We first find
the y-values by using the command
solve(g1(y),y); or
solve(G[1],y); which gives us
finitely many y-values Y1, Y2,
... And then, for each of the
y-values, Yi both of
the equations
g2(x,Yi) = 0, and
g3(x,Yi) = 0 must be
satisfied. Therefore, for each of the y-values, we find the
corresponding x-values by doing the following
sequence of Maple commands:
p2:=eval(G[2],
y=Yi);
p3:=eval(G[3],
y=Yi);
solve({p2,p3},x);
fsolve(x^3 - 3*x + 1,x); finds all 3 real
roots of x³ - 3x + 1,
while:
fsolve(x^3 + 3*x + 1,x); finds the real
root of x³ + 3x + 1, but ignores
the other two complex roots, which happen to be non-real.
The fsolve command is useful
in situations where real solutions are the main -- or only -- objects of
interest. For instance, this would be the case in a Lagrange multiplier problem.
eval(x^2 + y^2 -4, y=-1); evaluates
x2 + y2 -4 when -1 is
substituted for y, and similarly:
eval(x^2 + y^2 -4, {x=1.5, y=-1.25});
evaluates
x2 + y2 -4 when
1.5 is substituted for x and -1.25 is substituted for y.
S:=solve(x^5 + x + 1);
then the command evalf(S); will produce floating point values
of all five solutions. On the other hand, if we happen to know that the
third solution is the only real one and we only want its decimal value, then we use the
command evalf(S[3]); or (for instance)
r:=evalf(S[3]); to store the value for use in later calculations.
(Please note the square brackets for picking a particular item
from a list.)
diff(y^2 - x^3 + 3*x - t,x); and
diff(y^2 - x^3 + 3*x - t,y);
calculate the partial derivatives of
y² - x³ + 3x - t
with respect to x and y respectively.
resultant(x*y - 1, x^2 + y^2 - 4, x);
calculates the x-resultant of xy - 1
and x² + y² - 4.
(The answer will be a polynomial in y.)
with(LinearAlgebra): or
with(LinearAlgebra);
The version with the semicolon will produce a lengthy list of commands included
in this package. The version that ends with a colon ¡suppresses!
all of that output.
Here's an example that combines these three commands:
with(LinearAlgebra):
S:=Matrix([[y,-1,0],[0,y,-1],[1,0,y^2-4]]);
S:=Transpose(S);
R:=Determinant(S);
The first command defines the 3 by 3 matrix S whose row vectors are
[y,-1,0], [0,y,-1], and [1,0,y² -4].
The second command replaces the matrix S with its transpose, and the third
command calculates the determinant of S storing the answer as
R, for use in possible later calculations. Note that we didn't
have to transpose S before calculating its determinant; we just did that
to exhibit it as the Sylvester matrix of the polynomials xy - 1
and x² + y² - 4, in the form that it
is defined in the text.