This chapter explains what symbolic computing and computer algebra systems (CAS) are. It’s easier to understand these terms in context. If we consider a basic calculator, typically numbers are put in and you get numbers out. The numbers are what are called floating point numbers, but they look like decimals. For example if you enter 2, then the square root button, you will see
1.414213562
Alternatively, in a CAS, if you enter the square root of two, you will get
$$ \sqrt{2} $$
The difference is that the decimal number above truncates to 10 or 12 decimal places, whereas the output of the CAS is exactly the square root of two. You can see that if you square each of these. Using the calculator by starting with 2, then taking the square root, then squaring, you might get
1.9999999989
which is close to 2, but not exactly, whereas in the CAS, the answer will be 2.
Additionally, a CAS allows one to enter in mathematical expressions and manipulate them. For example if you enter
$$(x+2)^{2}$$
and then have the CAS expand it (skipping exactly how to do this until later), the CAS will return:
$$x^{2}+4x+4$$
which is how to expand it via the distributive law (or doing FOIL). Standard calculators can’t handle such an operation.
Another classic example of a CAS is that of precision of numbers. Later in the course, we will discuss the number of digits in an approximation, say in finding $\sqrt{2}$ , but recall that the factorial of a positive integer is the product of the number and all subsequence smaller integers until reaching one. For example 5!=5·4·3·2·1=120. Maple will compute factorials easily, note that
$$10! = 3628800$$
$$20! = 2432902008176640000$$
and so on. Most calculators cannot display more that 12-15 digits, so 20! may not be represented accuracy. Maple however can display as many digits as there are. Note that
$$50! = 30414093201713378043612608166064768844377641568960512000000000000$$
$$100!=93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000$$
Again, this is a big difference between a calculator and a CAS. If you try these on a calculator, you will probably get an error (typically an overflow error).
Before we venture too much into the realm of CAS, we need to discuss some specifics of software. There are a lot of programs that fall into Computer Algebra Systems, and if you are interested in seeing the breadth of such software, visit the Wikipedia site that lists CAS’s. The major commercial ones are Mathematica and Maple and a nice open source one is Sage.
All of the examples here will be in Maple, however the other software is similar with different syntax.
As we saw above with the $\sqrt{2}$ example, a CAS is more complicated than a calculator and a firm understanding of the basics of a CAS is needed. Before we dive into things, let’s look at some basic objects in a CAS.
Expressions are created using a combination of the keyboard and the palettes (listed on the left side of the Maple window).
To enter the expression: $(x + 2)(x + 5)$, you should type (x+2)·(x+5)
. The ·
(multiply) symbol is entered by typing Shift then 8 or the star key. This is very important for multiplying most function expressions. Try typing out the expression without the ·. What happens?
The easiest way to enter the expression: $\displaystyle \frac{x+5}{2-x} + 3$
is to type
(x+5)/(2-x)+3
Note: you must use parentheses in the numerator. When you hit the / key, everything in the parentheses is automatically put into the numerator of the expression. Then 1 enter 2-x
. In order to add the +3, you must press the right arrow key in order to get out of the denominator of the expression.
The transcendental functions must be written with parentheses around the argument. In other words, $\sin x$ must be typed sin(x)
in Maple. Many of these functions also appear in the Expression Palette or other palettes.
The exponential function is a bit tricky. If we type e^x
it looks right, but Maple won’t take the right value for $e$. Instead, type e
, then hit ESC on the keyboard and select Exponential 'e'
. Then type ^x
.
The function $\sin^{2}(2x)$ can either be entered as (sin(2x))ˆ2
(The symbol ˆ
is Shift-6), or sinˆ2(2x)
. Try both ways and see that the results are the same.
The absolute value of x is entered |x|
, using the | (vertical line key), which is on the key above the Enter key on the keyboard, or use the Expression Palette.
A very handy way of getting expressions (like the constants $\pi$ and e) in Maple without using the palette is to type the first few characters of the name of the expression then click on the ESC button (upper left corner of the keyboard). For example, try typing pi
, then hitting ESC. You will see all Maple expressions that start with those two letters. The constant π is the first one. Click ENTER to paste it into the document. Alternatively, you can click on the e or $\pi$ under Common Symbols palette on the left side of the screen.
The square root function can be put in by typing sqrt
hitting ESC and then selecting the square root symbol. Then type x
.
Put the following into Maple:
$(x-3)^{3}$
$\displaystyle \frac{7+3x}{11+x}$
$\tan 3x$
$\cos^{2}(\frac{1}{x})$
$\sqrt{3-\frac{4}{x^{2}+1}}$
${\rm e} ^{\sqrt{x}}$
Generally to get Maple to do something, we will use a command. All commands in Maple have the form name(param1,param2,...)
where name
is the name of the command and there are some number of parameters separated by commas.
There are thousands of commands in Maple and obviously, we won’t be going over all of them. It is good to be able to understand in general about a Maple command and the many options available as well as where to get extended help. We will cover more of this later in the course.
Generally Maple does something to a parameter (or argument) and returns an object of a certain type.
expand((x+1)·(x+2))
which will be $x^{2}+3x+2$. The return type is also an expression.
simplify(1/2 + x/(x+1) + 3/(x+1))
which results in $\dfrac{2x+4}{x+1}$. And again, the return type is also an expression.
When you create a new document in Maple there are a couple of different possibilities: a Maple Worksheet and Maple Document. A worksheet is an old style of storing Maple commands and if you’d like to read more about it, type worksheet in the help search. Everything in this class will be in Maple Document format.
A Maple Document allows its author to mix mathematics and text. To create a new Maple Document, type CTRL(CMD)-N or do File->New->Document Mode. Don’t forget, keyboard shortcuts are more efficient. When you do this, you will get a blank document.
There are two standard modes to input in a Maple Document: math mode and text mode. You can tell the mode you are in by the highlighted mode at the top of the document
As you can see, Math and Text are two of the options and the other three will be explained later, but they are not input types.
It’s fairly obvious that in Math mode, you can type out mathematics and also evaluate Maple commands. In Text mode, you have many of the features of a text editor/word processor including section headers, bold and italics and spell checking. Often in this class you will be asked to explain results and when you do this, you should be using text mode.
You can toggle between the two modes by clicking on the mode in the toolbar, but it is much easier to use the F5 key to do this. Try it!
You may notice that nearly everytime that you enter an expression in Maple, the result is centered in blue font and that there is a number on the right side of the screen. This is called the line number, and it can be very helpful. For example, if you have the expression
$$ x \cdot (7x-4)$$
and let’s say it is line 8. If we want to use this expression and say expand
it, we can type
expand((8))
where the (8)
above needs to be entered as Insert->Label… and then type in 8. (If you expression is on a different line number, type that one.) You should get in the habit of using a keyboard shortcut and type CTRL-L (or CMD-L on the Mac) to get the dialog instead. Keyboard shortcuts are always faster. The result above should be
$$7x^{2}-4x$$
and if you get the number 8 as an answer then you just typed 8 and not the insert label.
Maple has a good set of help pages built-in. It is highly recommended that you use it often. There are two standard ways to ask for help.
?expand
will open the Help Browser and open the `expand` command.