# Maple Basics

Maple was written for, and possibly by mathematicians. For that reason, its syntax is very like mathematics, for the most part, and is frequently unlike other programming languages. That said, it still has very much in common with other programming languages in terms of flow control, arrays, and other such standard features.

## Starting Maple

You can start the Maple program in its Java interface by typing`xmaple &`in a Linux command line. If you want to use the older, faster interface, you can get it using

`xmaple -cw &`. If you do not have X windows available, you can get a Maple command line by typing

`/usr/local/maple/bin/maple`.

You may want to change the Maple interface somewhat. Initially Maple forces you to use "2D Math Notation". Some people find this to be a bit painful - it is not an intuitive interface. If you want to use a more classical interface, you can go to Tools → Options, and click the "Display" tab. Change input display to "Maple Notation". Then click the "Interface" tab and change Default format for new worksheets to "Worksheet". Now when you open a new worksheet you will get the classic Maple input.

## Expressions

One difference between Maple and other languages is the syntax used for assignments. In particular, to assign a value to a variable, one uses the symbol ":=" instead of the simple equals sign. This is actually a common mathematical way of expressing "is defined to be", so it is more consistent mathematically than the equals sign by itself.

a := 3: b:= x^2;

A second thing to note is that *every Maple input line
must end in a semicolon or a colon.*
The semicolon tells where the end of the input is, the
colon tells Maple to suppress the output.
In the example above, Maple will echo the value of `b`,
but not `a`.
Note that in the "2D Math Notation" input format, you do not need
the semicolons - it is more line oriented.
Any time you press the <Enter>
key, Maple will process the line you typed in.
If you want to make a new line without having Maple
process the existing input (i.e. you want a command to go on several
lines), you can get a new line by holding the <Shift> key
and then hitting <Enter>.

Apart from those issues, entering expressions in Maple is very like typing them in any language. One major difference is that it is perfectly acceptable to enter expressions in terms of variables that have not been defined. Maple assumes that any variable that has not been defined is to be treated as a symbolic variable.

x:=2*a+5;
x:=11;
y:=cos(x/3);
y:=cos(11/3)
z:=exp(t^2);
z:=e^{(t2)}

## Floating point versus exact arithmetic

It is worth noting that Maple assumes that every calculation should take place in exact arithmetic, unless it is told otherwise. We could have received a decimal approximation to`y`from the previous example in either of two ways.

y:=evalf(cos(x/3)); y=-.8652868428 y:=cos(x/3.0); y=-.8652868433

In other words, if Maple sees one floating point number in an
expression, it performs all subsequent calculations using
floating point arithmetic. If you need to convert an exact
expression to floating point, you can use the `evalf`
function. Note that the results Maple gives in the above
examples differ. In the first case, Maple computed 11/3 in
exact arithmetic, and then only converted to floating point after
taking the cosine. In the second example, Maple computed 11/3 in
floating point arithmetic, and then took the cosine of that
approximation.

## Functions

Maple makes a strong distinction between expressions and functions. We can define functions in Maple using the -> notation.f:=t->t^2;
f:=t→t^{2}
f(x/3);
121/9

It is very important to note that the notation "f(t):=t^2;" does not define a function. It defines an expression that is put into a variable named "f(t)". If you want to be able to evaluate a function as e.g. f(2), then you must use the arrow notation.

Note that you can run Maple remotely
(without graphics) by using SSH to get to
your favorite Math machine, and then
typing
`/usr/local/maple16/bin/maple`.
This starts an old-fashioned command line
interface in which you can run .mc files
and such.