Meeting Maple

You can't break the program by experimenting!

Maple is a large computer program which can do many useful mathematical tasks. It has extensive numerical, graphical, and symbolic manipulation capabilities. It is installed on most Rutgers computer systems. There are several computer programs with similar capabilities. The most widely distributed programs are Mathematica and Maple. Maple is installed on almost every computer system at Rutgers, and I have a copy at home. So that's what I use and can comfortably discuss. 7/1/2002

Maple can be run in a command line interface or in its own window. From a Unix command line, just type maple which begins the program or in a window system (such as X) type xmaple &. 7/1/2002

A big calculator
All Maple commands should be ended with either : or ; and then followed by pressing the return or enter key. I admit with some embarrassment that I sometimes type a command and then forget either to type a semicolon or a colon, or I forget to press "Enter", and sit there wondering why the system is malfunctioning. 7/1/2002

You can type 3+2; at a command line. The prompt that Maple gives is usually >. See what the result is. Then try 17*3; and check the result. Then try %+4; to see what Maple thinks % means -- it should mean the previous result. Also try 3^2; to learn what ^ means. You might also try 5^2: to learn what ending a command with : rather than ; means. You can check your understanding by typing 2*%; afterwards and predicting the answer before it appears. Note that the command 67/8; returns the value 67/8. Maple won't "simplify" or approximate unless requested. If the command evalf(%); is then given, Maple immediately returns 8.375000000. The function evalf evaluates an expression as a floating-point number with the default number of digits (you can change the accuracy to 20 places with the command DIGITS:=20;. 7/1/2002

Maple uses := for assignment of values and uses = when testing for equality. I have made numerous mistakes with this notation. 7/8/2002

Symbolic capabilities
Maple can remember variable names. I tend to use longer variable names because I forget what the names mean. I make errors typing, though, and longer names increase the chance of mistakes. You could try a:=445; followed by a^2; and see what the result is. 7/1/2002

Lots of functions
Maple has many functions built into it: many, many, many functions. I'll concentrate here on just a few whose usefulness for our cryptographic studies will be apparent. 7/1/2002

Help
Surely the most important function is "help". If you want to learn about factoring, for example, you can type the command help(factor);. Most of the time you will get more information than you need, and some (much?) of the information is not relevant. Usually there are further references at the end (under See also) and this is very nice, because Maple has so many functions that finding the most appropriate and useful one can be difficult. For me, the examples are frequently the most helpful part of almost every help entry. 7/1/2002
Factoring integers
Maple can help you factor an integer with the command ifactor. The statement ifactor(3334); gets the response (2) (1667) almost immediately but ifactor(some long numeric string); may take a while. 7/1/2002
Modular arithmetic
The command 12+8 mod 11; returns the value 9 and that's how Maple does modular arithmetic. Maple can solve modular equations with the command msolve. Here are some examples. 7/1/2002
  • msolve(2*x+5=7,31); Maple response: {x = 1} One solution.
  • msolve(x^2=7,31); Maple response {x = 10}, {x = 21} Two solutions.
  • msolve(2*x=6,10); Maple response {x = 3}, {x = 8} Two solutions.
  • msolve(x^2=3,10); Maple response     Empty! No solutions.
  • msolve(2^x=1,31); Maple response {x = 5 _Z1~} Maple is trying to respond All integer multiples of 5 with this answer.
  • msolve(4^x=9,1231); Maple response {x = 424 + 615 _Z1~} meaning 424 plus all integer multiples of 615.
Note that equations involving larger integers may need more time and space for a response. 7/1/2002
Timing
It may sometimes be interesting for you to track the amount of time or other resources (storage) that Maple is using. The command time(); asks Maple to report how much CPU (computation time) it has used in seconds (to the nearest thousandth) so far. You can easily get elapsed time as in the following example. Note that when you try this, you will likely get different numbers.
The commands so_far:=time();ifactor(99933355199933355519993335551);time()-so_far; get the responses
so_far := 1.380
(3)  (7)  (13)  (19)  (31)  (37)  (211)  (241)  (525965029)  (2906161)   (2161)
.160
The first response indicates that during this session I have used about 1.380 seconds of CPU time (so far!). The second response is the factorization into primes of the l-o-n-g number entered into ifactor and the third response is the time needed for this computation: .03 seconds.
The first time you use a command in a session the CPU time may not correctly indicate the relevant computation, since the program must fetch the needed part of itself from slower memory.
You can also read about the command showtime if you want even more information. 7/1/2002
Modular exponentiation
Taking exponents easily and quickly modulo some integer is very important in the best known public key encryption ideas (RSA and Diffie-Hellman). Please consider the following two examples of sequences of commands.
  • A simple modular exponentiation.
    The command line is so_far:=time();1075^21339 mod 88897;time()-so_far; with Maple response
    so_far := 286.370
    80125
    .329
    The first response is the initial time (on my home computer). Then there's the actual answer, and last the elapsed time for the computation.
  • A slight variation: the only the change in the command line is from ^ to &^.
    so_far:=time();1075&^21339 mod 88897; time()-so_far; and now the Maple response
    so_far := 286.699
    80125
    0
    We get the same answer. Maple reports no elapsed time (or, better, the time elapsed was less than its threshold to notice).
The &^ part of the command notifies Maple to use smart exponentiation as discussed in section 5.7 of the lecture notes. This can represent a huge savings in time, etc. 7/1/2002
Polynomials
Maple knows about polynomials. For example, here are two commands and the Maple responses:
fox:=44*(x-5)*(x-99)^2;
fox := 44(x - 5) (x - 99)2
expand(fox);
44x3 - 8932 x2 + 474804 x - 2156220
The first command tells Maple that fox should be a certain polynomial. Notice that Maple "echoes" the value, but (lazily?) does not expand it until this is requested.

Maple can also substitute and evaluate the result.
subs(x=5,fox);

0
subs(x=7,fox);
744832
subs(x=7,fox) mod 17;
11
And for a last example, here is a computation you would definitely not want to do "by hand":
expand((fox^3)/9) mod 17;
8 x + 5 x3 + 9 x4 + 4 x2 + 10 x5 + 13 x6 + 11 x9 + 16 x8 + 3 x 7 + 13
Maple knows what to do with that division by 9 in modular arithmetic:
1/9 mod 17;
2
7/31/2002

You can't break the program by experimenting!

Almost surely you will have questions. Each paragraph has a date when it was written (here: 7/1/2002). When I receive questions of general interest, I will try to add text to this page. Have fun! You can send me mail.