\magnification = \magstep1
\centerline{SIMU 1999--Gr\"obner Bases Seminar}
\centerline{Week 1 Computer Laboratory Exercises}
\bigskip
\noindent
{\bf Background and Goals}
\bigskip
A large part of our work this summer will be carrying out calculations
of Gr\"obner bases and other computations within the computer algebra
system called {\it Maple\/}.  This week, we will want to get familiar
doing mathematics in this context.

\bigskip
\noindent
{\bf General Information about Maple}
\bigskip
\noindent
{\it Launching Maple}
\bigskip
\noindent
To get into Maple, you will need to:
\bigskip
\item{1)}  Turn the computer and monitor on. 
\item{2)}  Wait a few minutes while the computer ``boots up''
and launches Windows 95.
Eventually you will see a prompt to log onto the Novell campus
network.  It is possible to {\it bypass that\/}, by
pressing ENTER.  IMPORTANT NOTE:  To get paper printouts
of your work, though, you will need to log onto the network.
See printing directions at the end of this handout. 
\item{3)}  You should now see the Windows 95 desktop with ``icons''
(technically, ``shortcuts'' in Windows 95) for Maple, etc.   
You will double click on the Maple V Release 5 icon -- move the 
cursor arrow with the mouse until it is over the 
{\tt Maple V 5} icon and quickly click the left mouse 
button {\it twice\/} to launch Maple.
\item{4)}  After a few more seconds you should see a new 
Maple V Release 5 window, with a ``subwindow'' marked
Untitled (1) opened inside it.  The Untitled (1) window is a 
blank {\it Maple worksheet\/}.  
\bigskip
\noindent
{\it Maple Worksheets}
\bigskip
Worksheets are integrated text/graphics/mathematics
documents where any or all of the following can be done: 
\medskip
\itemitem{a)} you can type in commands from the keyboard  to ask Maple to 
perform many different kinds of calculations, read data
from external files, store work in files, etc.
\itemitem{b)}  output generated by Maple from your input
commands (numerical values,
symbolic formulas, and graphics) will be displayed, 
\itemitem{c)} you can modify commands, generating new output, store
your results for use later, etc.    
\itemitem{d)} you can enter text to annotate and explain the 
results of computations.
\medskip
\noindent
Much of your interactive ``management'' of a worksheet in progress
will take place through the File, Edit, View, Insert, etc. pull-down menus 
across the top, the ``tool bar'' below them with the icons for various 
operations (can you guess what each of them does?)
the ``scroll bar'' on the right that you can use to move around 
within the worksheet, to see previous input and output lines, etc. 
Most of the common operations appear both as items in one of the 
pull-down menus and as toolbar buttons.  The toolbar buttons are
faster to use, but somewhat limited in the options they offer, so 
you will want to have a general idea what is accessible from 
where in the pull-down menus.  

\bigskip
\noindent
{\it Input and Text Regions in a Worksheet\/}
\bigskip
A new worksheet window will be labeled something
like Untitled (1) window.  On the first
line of the worksheet, there is a $[>$ in red.  This 
is the Maple {\it input prompt} -- the signal that Maple
is ready to accept a command from you and try to execute it.
A new input prompt will be generated automatically in a worksheet each time 
you enter a command and execute it {\it at the end of a worksheet in 
progress\/}. You can also go back and insert new commands and output 
at any point in a worksheet as follows.  You can {\it insert an input 
prompt\/} and an input region at any point in the worksheet by  
placing the cursor at the desired location and
pressing the toolbar button marked with $[>$.  (After executing
an inserted command like this, Maple will drop to the 
next input line, so to insert several input lines in the
middle of a worksheet, you will need repeat the above.) 
  
As we mentioned before, Maple worksheets can contain text
as well as commands and output.  To create a text region you can 
press the $[>$ button above, then the
button marked by a capital T (this changes the region into 
a text region).   Any text can now be entered, and this will
be treated as an ``inert'' comment.  That is, it will appear as
you enter it when you print out the worksheet, and it will
not be treated as Maple input.  After you create a text region,
if you press  the capital sigma ($\Sigma$) 
toolbar button with the cursor placed on that region, you 
can type in a Maple expression in input
format, and have it displayed (in ``inert'' form)
in usual mathematical notation (with 
raised exponents, no asterisks for multiplication, etc.  This is 
sometimes useful for creating ``pretty'' worksheets!

\bigskip
\noindent
{\it Saving and Reloading your Maple Worksheets}
\bigskip
When you begin working on a
worksheet, you will usually want to {\it save your work\/} every
once in a while in case
a computer problem develops, or in case
you need more than one lab session to complete the work you are
doing.  This can be done most directly by saving to your network
drive.  (You can also save to  a 3 1/2 inch
IBM format diskette.)
following these directions:
\medskip
\item{1)} If you are using a diskette, insert it in the diskette drive 
(it's usually called the a: drive).  Otherwise go directly to step 2.
\item{2)} In Maple, select the SAVE option from the FILE
pull-down menu.
\item{3)} If you are saving your work for the first time, 
you will see a SAVE AS dialog box.  In the Drives box, 
highlight the A: or network drive as appropriate, then go to the File 
Name box, and type in a name for the file where the worksheet will be 
stored (any string of letters and digits -- no spaces -- no 
more than 8 characters long is OK) type in a period after 
the file name you chose and then the ``extension'' {\it mws\/}
for {\it Maple Work Sheet\/}.  For instance, a good choice might 
be something like {\it lab1.mws\/}.  Then click the 
OK button to write the worksheet to the network drive or to your diskette.
(You will only need
to type the filename in once in a session.  Subsequent 
saves just update the file.)
\item{4)}  When you have the worksheet saved as you want it,
you can remove the diskette and exit Maple.  
\item{5)}  To update the worksheet further in a later session,
you can read the worksheet back into Maple using the OPEN
option from the FILE Menu, or the ``open'' toolbar button.  Get into Maple 
as above, (if the worksheet is stored on diskette, insert it in the a: drive), 
and select OPEN from the FILE Menu.  Maple will prompt you as above for the
name of the worksheet with a dialog box very like the SAVE AS
box described above.  Highlight the A: or network drive as appropriate, then 
the worksheet you want, and click OK.  IMPORTANT NOTE:  When
you read a previously created worksheet into a new Maple session, you 
{\it have not\/} actually executed any of the commands in it in the 
new session.  If you want to make use of any results in that
worksheet, you will need to execute the commands again.  In the 
EDIT pull-down menu, you will see an EXECUTE option that lets you 
recompute an entire worksheet or a section of one.
\bigskip
\noindent
\bigskip
\noindent
{\it Printing}
\bigskip
With the worksheet
you want to print open and highlighted, and press the toolbar icon 
that looks like a printer, and press OK on the PRINT dialog box 
(the settings should be set up correctly to print automatically).  
Your output should appear shortly on the printer. 
\bigskip
\noindent
{\it Getting Out}
\bigskip
When you leave, quit the Maple window (FILE/EXIT) or the X button on the top
right of the window.
\bigskip
\noindent
{\it Day 1:  A First Sample Maple Session}
\bigskip
Let's get right down to work and walk through a first sample
sample session!  First, you 
will need to get into Windows and Maple as described in the General 
Information section above.  
\bigskip
\noindent
{\it 2D Plotting}
\bigskip
The basic Maple command for 2D plotting, used for 
graphs of the form $y = f(x)$ and for parametric curves
$\alpha(t) = (x(t),y(t))$ is called {\tt plot}.  The basic format for graphs 
$y = f(x)$ is 
\medskip
\centerline{\tt plot(function,range,options);}
\medskip
\noindent
where 
\item{1)}  {\tt function} is the function to be plotted -- the
simplest way to specify one is via a formula for $f(x)$ (an 
{\it expression\/} in Maple)
\item{2)} {\tt range} is the range of $x$-values you want
to see plotted, entered in the form {\tt x = low..high}, and
\item{3)}  {\tt options} can be used to control the form
of the plot if desired.  No options need be specified however
if you don't want to. More on this later.
\bigskip
\noindent
{\it Example 1}
\bigskip
To plot 
$y = x^4 - 2x^3 + x - 5 \sin(x^2)$ 
for $-2\le x \le 1$,
you could use the Maple {\tt plot} command with no options:
\medskip
\centerline{\tt plot(x\^{}4-2*x\^{}3+x-5*sin(x\^{}2),x=-2..1);}
\medskip
\noindent
Try this now.
(Note: The close parenthesis comes directly after the range of 
$x$-values if there are no options.)
Type in this command line (exactly as here) and press ENTER.  
(Until you enter either a semicolon or
a colon and press ENTER, Maple will not
do anything with your command.
Also, if a command you want to enter
doesn't all fit on one line, just keep typing, 
but don't press ENTER until you are finished.  Maple automatically
wraps around to a new line if you need it.)
  
If you make a typing mistake, Maple will let
you know about it (!)  One frequent source of errors in Maple sessions 
is unmatched parentheses, (or square or curly brackets, etc.)  One 
``hacker's trick'' is to count the open parens, count the close parens 
and make sure you get the same number (of course, if you don't, you also
have to decide where to insert the missing one ...).

Fortunately, if this happens, the whole command does NOT need to 
be re-entered.  Just move the cursor arrow to the 
place on the input line you want to change, press the left
mouse button, and edit the input as needed.  Typing from the 
keyboard will {\it insert\/} new stuff at the cursor location; the 
DELETE and BACKSPACE keys will remove stuff (DELETE removes the 
character in front of the ``insert point''; BACKSPACE removes the
character in back).  You can also move around on the 
input line with the ARROW keys if more than one thing needs to 
be changed.  When you think it's OK, press ENTER again to 
have Maple execute the command again.  (Pressing ENTER with the 
cursor anywhere on an input line executes the whole input line.)

When all goes well you will see the graphics output displayed
under the input command in the worksheet.

From the formula $y = x^4 - 2x^3 + x - 5 \sin(x^2)$, you might 
guess that there is at least one other $x$-intercept for this graph 
for $x > 2$ (why?).  To see that part of the graph as well,
edit your previous command line to change the right hand
endpoint of the interval of $x$ values (do not retype the whole
command).  Press ENTER on that input line    
to have Maple execute the command again.  Experiment until you 
are sure that your plot shows all the $x$-intercepts of this graph.
(You can repeat this 
process of editing a command and re-running it as often 
as you want; the previous output is replaced by the new
output each time.)     

You can manipulate the graphics output {\it in place\/}
within the worksheet in several ways.  For instance:
\medskip
\item{1)}  If you click the left mouse button once over the 
graphics output, you will see a black box with eight ``tabs''
displayed at the corners and the midpoints of the edges of the 
box.  If you place the cursor on one of the tabs,
hold down the left mouse button, drag the cursor and 
release, you can {\it resize the graphics\/}.  Try it!
\item{2)} Maple 2D graphics output regions have another nice feature:
If you place the cursor arrow at a point in a 2D graphics region and 
click the LEFT mouse button once, {\it approximate coordinates\/} of 
the point at the head of the arrow are printed out in 
a box at the upper left
of the window. How good approximations can you get that way
to the $x$-intercepts of this graph?
\item{3)} Other features of the graph can be changed from the tool bar,
which will have a new selection of buttons displayed after the graphics
output is generated.  Experiment
and see if you can figure out what the different graphics tool bar icons do.
\medskip

When you get a graphics window with {\it all\/} the intercepts shown,
let's add one more thing. Sometimes, an informative title makes a graph 
much more understandable.  To add a text title to a plot, you can insert 
a comma after the range of $x$-values, and
include an option in the plot command  of the form
\medskip
\centerline{\tt title='whatever you want'}
\medskip
\noindent
Add an appropriate title to your plot. 
\bigskip
\noindent
{\it Example 2}
\bigskip
Next, let's move to another 2D plot, to see the parametric 
curve $\alpha(t) = (t^2 - 1, t^3 - t)$.  
The basic format for parametric curves $\alpha(t)=(x(t),y(t))$ is
\medskip
\centerline{\tt plot([x-comp,y-comp,t-range],options);}
\medskip
\noindent
where
\medskip
\item{1)}  {\tt x-comp} and {\tt y-comp} are the $x$- and $y$-component
functions of the curve to be plotted (each of these can be an 
{\it expression\/} involving the variable (parameter) $t$,
\item{2)} {\tt t-range} is the range of $t$-values you want
to see plotted, and
\item{3)}  {\tt options} can be used to control the form
of the plot if desired.  No options need be specified however
if you don't want to. 
\bigskip
\noindent
Note that the $x$- and $y$-components and the $t$-range all 
go inside a set of square brackets $[,]$, separated by commas.
This is also Maple's notation for a {\it vector, or ordered list\/}.

Using the {\tt plot}
command, as described above, display a plot of the curve 
$\alpha(t) = (t^2 - 1, t^3 - t)$ for $t \in [-3,3]$.
\bigskip
\noindent
{\it Example 3}
\bigskip
Frequently, it's the relationship between two or more different
graphs that you want to understand by looking at a plot.  You can also
use the {\tt plot} command to generate plots showing several graphs
with the same coordinate axes. 
You do this by plotting an {\it unordered list\/} or
set of functions.  You do this by putting the formulas for 
the functions you want, separated by {\it commas\/}, between 
{\it curly braces\/} -- $\{,\ \}$ -- where the single formula 
went before.  (In fact this is the way sets or unordered
lists are {\it always\/} entered in Maple.) For example, 
to plot $y = \sin(x)$ together with 
$y = \sin(x + 2)$ for $0 \le x \le 4\pi$, you could use:
\medskip
\centerline{\tt plot($\{$sin(x),sin(x+2)$\}$,x=0..4*Pi);}
\medskip
\noindent
Try it.  What is the general relationship between 
the graphs $y = f(x)$ and $y = f(x+k)$ for constant $k$?  Explain.
\bigskip
\noindent
{\it Assignment -- Due at end of Lab Period, Monday}
\bigskip
Add a text region describing each of your plots from Examples 1,2,3
above and answering the questions asked above, then save and print this 
worksheet.

\bigskip
\noindent
{\bf Days 2,3 -- More Detailed Information on Maple Commands and 
Expressions, More Plotting}
\bigskip
\noindent
{\it What is a Maple Command?}
\bigskip
It may help to 
think of a command as a {\it program} or {\it function of one or more variables} 
that Maple knows how to compute, given ``inputs'' from you, although
you must then keep straight the distinction between these functions
Maple knows how to execute, and the functions or formulas you 
enter for Maple to work with!

Now that we have seen some first examples of Maple commands,
here is some more information about the {\it syntax rules\/} that
Maple uses to decide if what you have typed in is a well-formed
command it can execute, and what the {\it semantics\/} or
meaning of the commands are.

Almost all of the built-in Maple commands have a syntax
like the {\tt plot} command discussed above.  The format is either
\medskip
\centerline{{\tt name(values);}\qquad or\qquad {\tt name(values):}}
\medskip
\noindent
In this general description, {\tt name} is the name of the command or function 
(like ``plot'' yesterday), there is a matching set of open and close 
parentheses following the name, and they surround the 
{\tt values} -- the input from you the command needs to do its job 
(like the formula of the function to be plotted and the range of $x$-values
you want).  The
values are listed separated by commas within the parentheses.  
The two forms of the command above tell Maple to execute the command
when you press ENTER on that input line.  In the first case -- ending 
the command with a semicolon (;) -- you are instructing Maple to 
display the output.  With colon (:), Maple will
execute the command but not display the output (this is useful sometimes for 
intermediate steps in a big computation where you don't want or don't need
to see the output).  
\bigskip
\noindent
{\it Getting Help On-Line}
\bigskip
The exact format Maple is expecting for each type of command is 
specified in the programming of the Maple system.  Usually, there
is {\it little or no freedom\/} in the ordering of what has to go where 
and in what format
in the list of values.  Much useful information on this for 
all the built-in commands, and LOTS of instructive examples are contained 
in the Maple on-line HELP facility.  For example try looking at the on-line help 
page for the {\tt plot command}.  (From the HELP pull-down menu, 
select Topic Search, type in the word ``plot,'' and press OK.)  Note
the example plot commands at the bottom and the links to related help pages.
\bigskip
\noindent
{\it Maple Expressions}
\bigskip
\noindent
Formulas or expressions are entered in something like usual 
mathematical notation: 
\medskip
\item{1)} The symbols for addition, subtraction, 
multiplication, and division are $+,-,*,/$ respectively.  
\item{2)} The caret (\^{}) is the Maple symbol for raising to 
a power.
\item{3)} The asterisk symbol
for multiplication MUST be included whenever you are 
performing a product in a formula. Moreover, everything must be 
entered in one linear string of characters, so you will need to use 
{\it parentheses\/} to group terms to get the expressions you want.  
The rule to keep in mind is: {\it Maple always evaluates expressions 
by doing powers first, then products and quotients, then sums and
differences, all left to right, unless parentheses are used to
override these built-in rules\/}.  For example, 
the Maple expression {\tt a + b*c\^{}2/d + e} is the same as the 
mathematical formula:
$$a + {b c^2 \over d} + e.$$
If you really want 
$${a + b c^2 \over d + e}$$
you will need to enter the expression
{\tt (a + b*c\^{}2)/(d + e)}.  What if you really wanted:
$${(a + bc)^2 \over d + e}?$$
\item{4)} Maple ``knows'' all the usual elementary functions
from calculus.  The names of the most common ones are
{\tt sin, cos, tan, exp, ln, sqrt}.  To use one of these functions in 
a Maple formula, you put the name, followed by the ``argument'' (that 
is, the constant or expression you are applying the function to) 
{\it in parentheses\/}.
\bigskip
\noindent
{\it Exercise 1 -- Exercises 1 - 7 should be done in a single 
Maple worksheet, due no later than the end of the day on Friday}
\bigskip
How would you enter each of the following formulas as Maple expressions?
Try typing each in as a Maple input line, and compare with the output they 
generate:
\medskip
\item{1)} 
$$ 4xy^2 - 2x^3 + 3y - 7$$
\item{2)}  
$$1 + {1\over x^2} - {x+2\over x^4}$$
\item{3)}  (Note: {\tt sqrt(x)} is the Maple syntax for $\sqrt{x}$.)
$${-b + \sqrt{b^2 - 4 a c} \over 2 a}$$
\bigskip
\noindent
{\it Implicit 2D Plotting}
\bigskip
The 2D plots we generated yesterday were all either graphs of functions 
$y = f(x)$,
or parametric curves.  In addition to these, we will also want to be able to 
plot the affine variety 
$${\bf V}(g(x,y)) = \{(x,y) \in {\bf R}^2 : g(x,y) = 0\}$$
for a general polynomial $g(x,y)$ in two variables.  The technical name for 
this in Maple is {\it implicit curve plotting}.  To plot 
these curves in Maple, we need a new command called {\tt implicitplot}.
This command is not part of the basic Maple system; instead it is a part of 
a separate {\it package\/} of commands for various plotting operations called
the {\tt plots} package.  Before you can use this command, you will need to 
``load'' the plots package with the command
\medskip
\centerline{\tt with(plots);}
\medskip
\noindent
(The output is the list of commands in the package; you should see {\tt implicitplot}
about halfway along the list.  If you don't want to see this each time, you 
can also put a colon after the {\tt with} command as described above.)

The format for the {\tt implicitplot} command is 
\medskip
\centerline{\tt implicitplot(expression,x-range,y-range);}
\medskip
\noindent
The expression should be the equation $g(x,y)$ (Maple assumes
you mean to plot $g(x,y) = 0$.) This command generates
a plot of the part of the variety ${\bf V}(g(x,y))$ in the rectangular box 
in the plane defined by the $x$- and $y$-ranges.

\bigskip
\noindent
{\it Exercise 2}
\bigskip
\item{a)} For instance, try the following command:
\medskip
\centerline{\tt implicitplot(x\^{}3 - 3*x*y\^{}2 - 3,x=-3..3,y=-3..3);}
\medskip
\noindent
to plot the variety ${\bf V}(x^3 - 3xy^2 - 3)$
Add a text region answering the following questions:  
How many intersections of this variety are there with vertical lines
($x = a$) and horizontal lines ($y = b$) in ${\bf R}^2$?  Does the answer 
depend on the values of $a,b$?  Is it possible to ``see'' these numbers
from the form of the equation $g(x,y)$?  Explain.
\item{b)}  Same questions for ${\bf V}(x^3-3x + 2xy^2 - y^4 - 1)$

\bigskip
\noindent
{\it 3D Curve Plotting}
\bigskip
The {\tt spacecurve} command in the {\tt plots}
package can be used to draw  parametric curves in 3D. The format for 
the command is
\medskip
\centerline{\tt spacecurve([x(t),y(t),z(t),t=a..b]);}
\medskip
\noindent
where $x = x(t)$,$y = y(t)$,$z = z(t)$ are the parametric equations of 
the curve and the range of parameter values to be plotted is 
$a \le t \le b$.  (Note the placement of the square brackets which follows
the same pattern as the parametric version of {\tt plot}!) 
For instance, try entering
\medskip
\centerline{\tt spacecurve([t,t\^{}2,t\^{}3,t=-2..2]);}
\medskip
\noindent
to plot the {\it twisted cubic\/} curve from class.

The first plot you see here might be rather uninformative. Fortunately, Maple
also lets you add axes and look at a 3D plot from different viewpoints. 
Here's how:
\bigskip
\item{1)}  Press the left mouse button over the graph.  This 
should bring up a ``bounding box'' for the graph with corners you 
can {\it drag and drop\/} with the mouse to resize the graph. 
\item{2)}  If you place the mouse over the graph, depress the 
left button, and drag the cursor, you should see the graph rotating
following the cursor position.  Release the left mouse button 
when you get to the position you want.
\item{3)}  If you click  
the right mouse button, you will bring up a menu containing the options
{\tt Style, Axes, Color} and several others.  Select
{\tt Axes, Normal} with the left mouse button. 
\bigskip
\noindent
Practice a few times repositioning the viewpoint (rotating 
the viewing box) and redrawing the graph.  

To draw several parametric curves in the same graph, you can include
several curve specifications in the form {\tt [x(t),y(t),z(t),t=a..b]} 
between curly braces {\tt $\{$,$\}$}, separated by commas,
all inside the 
parentheses for the {\tt spacecurve\/} command.

\bigskip
\noindent
{\it Exercise 3}
\bigskip
The line segment from $(a,b,c)$ to $(d,e,f)$ can be parametrized as follows
$$\alpha(t) = (a + t(d-a), b + t(e-b), c + t(f - c))$$
for $0 \le t \le 1$.
The points $P = (0,0,0)$, $Q = (2,0,0)$, $R = (0,\sqrt{3},1)$, 
$S = (0,-1,\sqrt{3})$
are four corners of a cube in ${\bf R}^3$
with edges $PQ$, $PR$, and $PS$, because
the vectors $\vec{u} = Q-P, \vec{v} = R-P, \vec{w} = S-P$
all have magnitude 2, and
$\vec{u}\cdot\vec{v} = \vec{u}\cdot\vec{w} = \vec{v}\cdot\vec{w} = 0$.
Your assignment, should you decide to accept it (just kidding!), is to 
create a picture of this cube by drawing the 12 edges together on the 
same set of axes in ${\bf R}^3$ (begin by drawing the line segments
from $P$ to $Q$, $P$ to $R$, and $P$ to $S$).   Also explain how you found 
the other 4 corners of the cube.  This can be done in a text region.

\bigskip
\noindent
{\it Surface Plots}
\bigskip
\noindent
{\it a. Plotting a graph} $z = f(x,y)$.  
\bigskip
The  command for 
3D plotting is called {\tt plot3d} (naturally enough!)  Its format
is similar to, but not exactly the same as the format of {\tt plot}.
To draw a graph with {\tt plot3d\/}, you use a command of the format:  
\medskip
\centerline{\tt plot3d(function,xrange,yrange,options);}
\medskip\noindent
The {\tt function} is the function $f(x,y)$, entered
in the usual Maple syntax for expressions. The {\tt xrange}
and {\tt yrange} specify a rectangular box in the plane that the 
plot will be constructed over; the {\tt options} can be
used to specify how the plot is drawn.  Look at the online help
for {\tt plot3d[options]} if you want to see what things are 
possible.  Most of the options can also be invoked from the 
3D graphics output via the pop-up menu, or the 
toolbar buttons.  Using the PATCHCONTOUR
style is often a very effective way to visualize the shape of a surface.

For example, try
\medskip
\centerline{\tt plot3d(-x\^{}4+2*x\^{}2-x/2-y\^{}2-1,x=-2..2,y=-2..2);}
\medskip
\noindent
to plot the surface
$$z = -x^4 + 2x^2 - x/2 - y^2 - 1.$$

One very nice feature of Maple 3D graphics is that you can change viewpoint,
add axes, etc. using the mouse and the 
toolbar options in the 3D graphics window.  The method is the same as
that for the {\tt spacecurve} described above.

\bigskip
\noindent
{\it Exercise 4}
\bigskip
We will build up a ``composite'' Maple graphics
display by combining a plot of a graph $z = f(x,y)$ produced
with {\tt plot3d} and a plot of a parametric curve produced
using {\tt spacecurve}.  This can be done via the {\tt display3d} command
in the {\tt plots} package.  First
we generate the plot of $z = x^2 - y^2$ for $(x,y) \in [-3,3]\times [-3,3]$,
and assign the output to the variable {\tt P1}.  
\medskip
\centerline{\tt P1:=plot3d(x\^{}2-y\^{}2,x=-3..3,y=-3..3):}
\medskip
\noindent
(The colon at the end of
the input line {\it suppresses the output\/}, which is Maple's 
internal form of the graph.  To see why I did that, try replacing 
the colon with a semicolon and pressing RETURN again on that line 
to reexecute!)
Then, we generate a plot of the parametric curve 
$\alpha(t) = (t,t^2,t^3)$ for $t \in [-2,2]$, drawn with a relatively 
thick line and in black for contrast, and put the 
results into the variable {\tt P2}:
\medskip
\centerline{\tt P2:=spacecurve([t,t\^{}2,t\^{}3,t=-2..2],color=black,thickness=2):}
\medskip
\noindent
Finally, we display both graphs together:
\medskip
\centerline{\tt display3d($\{$P1,P2$\}$);}
\medskip
\noindent
(Here of course, you {\it do\/} want to see the output, presumably.)  Maple
is smart enough about these plots to combine the scales correctly 
and show the curve and surface in their proper relative positions!  
Look at this one for a while until you see how the curve and the 
surface are intersecting.  How many intersection points are there?

Any number of different 3D plots can be displayed together in this 
way by assigning each to a variable, then putting the set or list
of plot variables names in the {\tt display3d} command.
\bigskip
\noindent
{\it b. Implicit Surface Plots}
\bigskip
To plot an surface defined as a variety ${\bf V}(g(x,y,z))$,
you can use the {\tt implicitplot3d} command.  Look up 
the on-line help listing for this command and use it in the following
exercise:
\bigskip
\noindent
{\it Exercise 5}
\bigskip
Generate a plot of the following variety in ${\bf R}^3$:
$$S = {\bf V}(z^2 - (16 - x^2 - y^2)((x+2)^2 + y^2 - 1)((x-2)^2 + y^2 - 1)/10)$$
and explain the shape you see.  You will want to ``walk around'' this one 
a lot by rotating and looking at it from different viewpoints (For example, which $(x,y)$ correspond
to points on $S$ and why?  You will also need to think about
how you choose the $x$-, $y$-, and $z$-ranges.  Be sure
you take the $x$- and $y$- ranges big enough to see all the points 
on the variety.)  Suggestion:
Use the options {\tt style=PATCHCONTOUR} and {\tt grid=[30,30,30]}
to see detail.  Be aware though that this larger than normal number
of grid points will mean the surface takes longer to compute and ``render''
or draw and your worksheet will require more space to store on disk if
you save the graphics.
\bigskip
\noindent
{\bf Day 4: Symbolic Computation in Maple}
\bigskip
Much of our work starting next week in Maple will consist of {\it symbolic}
computations in Maple -- mainly various manipulations of polynomials
in several variables.  Today, we will look at some first examples
of this sort of computation in Maple, with polynomials in one variable.
\bigskip
\noindent
{\it The assignment operator $:=$}
\bigskip
We have already run into this briefly when we combined two plots in the 
last lab.  In symbolic computation, we will use this idea all the time.
A Maple command of the form
\medskip
\centerline{\tt name := expression;}
\medskip
\noindent
assigns the right hand side to the name on the left.  Usually, the right
hand side will involve a known expression, or performing some operation on 
some information we already know.  We want to take the result of the operation 
and give it an abbreviated ``name'' for later use.  For instance,
\medskip
\centerline{\tt cube := (x\^{}2  - 16)\^{}3;}
\medskip
\noindent
Then later on, we could ``reuse'' the value of {\tt cube} in other 
expressions, just by putting in the name {\tt cube} at the appropriate 
place (e.g. {\tt plot(cube, x=5..10);}).  Note:  Maple also gives you 
a second way to refer back to results of previous computations.  At
any point in a session, if you enter $\%$, this stands for the result
of the previously executed command, $\%\%$ stands for the result of 
the command before that, and so on.  (Caution: The sequence is the 
sequence of the commands you have executed in the current session, {\it not\/}
the sequence of input lines in the worksheet.  This can be confusing
if you skip around, inserting new command lines between others.)
\bigskip
\noindent
{\it Some additional symbolic commands on polynomials}
\bigskip
\noindent
Maple has built-in commands:
\bigskip
\item{$\bullet$} {\tt expand} to multiply out (and also simplify) a factored 
polynomial.  Format:  {\tt expand(poly);}  This works on polynomials
in any number of variables.
\item{$\bullet$} {\tt factor} to factor a
polynomial.  This gives the factorization with {\it rational number coefficients}.
The factor command does not know about radicals, complex numbers, etc.
Format:  {\tt factor(poly);}  This works on polynomials
in any number of variables.
\item{$\bullet$} {\tt quo} to compute the quotient on division of one polynomial
$f(x)$ by another $g(x)$.  Format: {\tt quo(f,g,x);}  Note: the variable
must be included.  If $f$ or $g$  contain other variables besides $x$, 
they will be treated as constants in the coefficients.
\item{$\bullet$} {\tt rem} to compute the quotient on division of one polynomial
$f(x)$ by another $g(x)$.  Format: {\tt rem(f,g,x);}  Note: the variable
must be included again.
\item{$\bullet$} {\tt gcd} to compute the greatest common divisor of 
two polynomials
$f(x)$ and $g(x)$.  Format: {\tt gcd(f,g);}  Note: the variable
is {\it not} included in this one.  The greatest common divisor of a 
set of several polynomials can be computed by nested gcd's (see p. 43 of ``IVA'';
for example $gcd(f,g,h)$ can be computed by {\tt gcd(f,gcd(g,h))}.
\item{$\bullet$} {\tt diff} to compute derivative of a polynomial
(or any other function) with respect to 
a given variable.  Format {\tt diff(f,x);} 
\bigskip
\noindent
Here is a sample sequence of Maple input lines illustrating some of these 
commands. Try entering and executing them in sequence.  Look carefully
at the output and make sure you understand what happened in each case:
\medskip
\centerline{\tt cube := (x\^{}2 - 16)\^{}3;}
\centerline{\tt diff(cube,x);}
\centerline{\tt cubee:=expand(cube);}
\centerline{\tt factor(cubee);}
\centerline{\tt d:= x\^{}2-x+1;}
\centerline{\tt q:=quo(cubee,d,x);}
\centerline{\tt r:=rem(cubee,d,x);}
\centerline{\tt factor(expand(q*d+r));}
\medskip
\noindent
{\it Exercise 6}
\bigskip
Using Maple and the commands above, do problems 9,12,14,15 from Chapter 1,
\S 5 of ``IVA''.
\bigskip
\noindent
{\it A First Taste of Maple Programming}
\bigskip
In addition to a large collection of built-in commands for performing various
mathematical computations, Maple also contains a {\it programming language\/}
that you can use to code and implement your own new commands or procedures.  
Here is a first example of a Maple procedure which takes as input
two polynomials in one variable, $f(x)$ and $g(x)$, and computes their 
gcd $h(x)$, together with polynomials $A(x)$ and $B(x)$ satisfying 
$$h(x) = A(x) f(x) + B(x) g(x)$$
(recall this was question 10 from Chapter 1, \S 5 of ``IVA'').  Here
is Maple code for one way to do this:
\bigskip

\leftline{\tt ExtEuc := proc(f,g,x)}
\item{} {\tt local A,B,C,Csave,D,Dsave,q,r,s,h;}
\item{} {\tt h := f; s:= g; A := 1; B := 0; C := 0; D := 1;}
\item{} {\tt while s <> 0 do}
\itemitem{}{\tt q := quo(h,s,x);}
\itemitem{}{\tt r := rem(h,s,x);}  
\itemitem{}{\tt h := s;}
\itemitem{}{\tt s := r;}
\itemitem{}{\tt Csave := C; Dsave := D;}
\itemitem{}{\tt C := expand(A - q*C); D := expand(B - q*D);}
\itemitem{}{\tt A := Csave; B:= Dsave;}
\item{}{\tt od;}
\item{}{\tt RETURN(h,A,B)}
\item{}{\tt end:}

\bigskip
\noindent
Note that the syntax here is very similar to our pseudocode for algorithms.
There is a file containing the above Maple code in our class directory.
You can read it into your Maple session using:
\medskip
\centerline{\tt read 'f:/users/simu/Little/ExtEuc.map';}
\medskip
\noindent
Then to use the procedure to compute the gcd and the polynomials $A,B$, you 
would enter a command like this:
\medskip
\centerline{\tt ExtEuc(fpoly,gpoly,var);}
\medskip
\noindent
where {\tt fpoly} and {\tt gpoly} are the two polynomials, and {\tt var} is 
the variable.  The output from the procedure consists of the last value of 
$h$ (the gcd, up to a constant multiple), then the polynomials
$A$ and $B$.  Use this to check your work from this morning.
\bye
