Next: Complex Numbers Up: Numbers Previous: Forcing Floating Point Evaluation

### Sums and Products

You can perform summations in Maxima in various ways. Function sum will return a numerical, although not necessarily a floating point, value if it can. This is how you would sum  :

Another variant of this function, called 'sum delays  the evaluation:

We can force the evaluation in two ways. The first one is to declare a variable simpsum to be true and then call 'sum again:

The other way is to invoke ev on 'sum with the simpsum flag raised:

The simpsum flag has no effect on sum, which always tries to evaluate the sum as far as it can.

We will see that delaying the evaluation is a technique frequently used in all three environments. The ability to control evaluation with flags is also very important.

In Maple the function sum is the same as sum in Maxima, and in place of Maxima's 'sum Maple has Sum:

You can force the evaluation of Sum by saying

As you must have already guessed, we switch from Maxima/Maple to Mathematica by replacing sum with Sum and replacing the range i=1..10 with {i,1,10}:

Delaying evaluation in Mathematica is done quite differently though. Observe the following:

Now we define yoursum, but this time we use := instead  of =:

When yoursum is requested in In[12] it is automatically evaluated, but it is stored as Sum[(1+i)/(1+i^4), {i,1,10}].

Working with infinite sums can be quite tricky. Consider the following sum: . The result is . Maxima can figure this out but you have to switch to the simpsum mode.

To check if this is correct, we can replace inf, which, by the way, Maxima, understands to be , with a very large integer and compare it to :
(C8) sum(1/k^2,k,1,1000),numer;
(D8)                          1.6439345666815615
(C9) %pi^2/6,numer;
(D9)                          1.6449340668482264
(C10)

This is close enough for government work. Observe that you can force floating point evaluation by appending ,numer to the command, and that is represented in Maxima by %pi.

Maple is just as clever when it comes to this sum:

> sum(1/k^2, k=1..infinity);
bytes used=1004340, alloc=786288, time=0.44
2
1/6 Pi

>


And Mathematica knows all that stuff too:

The way Maxima, Maple and Mathematica go about it is to recognise one thing. Namely that the series is an infinite one. There is a relatively small number of infinite series about which a great deal is known. So the first thing that all three have to do is to check if the series in question relates to any of the ones that they know about. If it does then by the means of some additional transformations an exact mapping and thus an exact result may be found.

You can work with products in a way that is very similar to  sums. In Maxima we again have two forms to deal, say, with :

However, the simpsum flag equivalent is not implemented, so you can't ev the 'product expression with that flag on and get a number.

In Maple we also have two forms: product and Product, where  Maxima's notation for range, i,0,10 is replaced with Maple's i=0..10:

In Mathematica products are produced with, yes you've guessed it, Product, which has its syntax similar to Maxima's and Maple's product:

Next: Complex Numbers Up: Numbers Previous: Forcing Floating Point Evaluation
Zdzislaw Meglicki
2001-02-26