# HP Forums

Full Version: sum command...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I try to evaluate sum(1/x^2,x,1,n), if n = infinity, it evaluates correctly to pi^2/6, but when i put n = 100, 1000, 2000, it calculates it as these giant fractions, which I have to run approx() on to get the decimal value. Then, when I try n = 5000, it runs out of space for the numerator and denominator, and gives me an answer of undef, instead of trying to calculate the decimal answer....
Wondering why it's trying to evaluate this as a huge fraction instead of decimally? and why it's coming up with an answer of undef instead of calculating the correct value?
Thx
-Donald
If you want an approx value, enter one approx bound, for example
sum(1/x^2,x,1,5000.)
Same for integration.
My guess would be that it is because you are using CAS and are exceeding its limits.

If you want numerical calculations you should use Home. And preferably sum back to front (if you can control that).
Of course I'm exceeding CAS limits, but why is it calculating it as a ratio? I would imagine or want the SUM function to work like this pseudocode:
sum = 0;
for x=1 to 5000
sum = sum + expression;
endfor

Clearly, that's not how it's being evaluated....which is kinda weird.
I tried running this in home:
sum(1/x^2, x, 1, 1000)

It gave be a bizarre ratio as an answer of 9.9999e499 as both numerator and denominator...
I was able to run approx(sum(1/x^2,x,1,1000)), and that worked....result was 1.6439..

....with 5000, I get undef in home mode too...
sum is a CAS command. in Home try to use Σ instead (from the math template key). For ex: Σ(1/X^2,X,1,5000)
Wow.....sigma is really fast too...Thx!
(10-11-2017 09:07 AM)webmasterpdx Wrote: [ -> ]Of course I'm exceeding CAS limits, but why is it calculating it as a ratio?

How else would it (try to) do an exact calculation? What would you expect it to do?

(10-11-2017 09:07 AM)webmasterpdx Wrote: [ -> ]I would imagine or want the SUM function to work like this pseudocode:

That's probably exactly what it does, or tries to do. Why would you assume that it doesn't?
It doesn't act like that pseudocode. It has to calculate it so it can handle an algebraic sum and get algebraic results....which is a lot more sophisticated. To do it like the pseudocode, you use the Σ function in Home as Didier suggests....
(10-11-2017 01:41 PM)webmasterpdx Wrote: [ -> ]It doesn't act like that pseudocode. It has to calculate it so it can handle an algebraic sum and get algebraic results....which is a lot more sophisticated.
I have no problem with "sophisticated", but I do have a problem with arguments based on what one of my professors used to call "proof by mathematical intimidation". :-) Can you pleae explain what you mean?

In the mean time:

 By providing an explicit upper bound (5000) you were asking for a rational number, not an algebraic expression. So regardless of the algortihm being used why would you complain about CAS trying to give you exactly what you asked for?

 If you are trying to suggest that there should be a magical short-cut to doing the calculation, similar to when you would be adding n^2 instead of n^(-2), then I doubt that one exists. But that's just based on my gut feeling, so feel free to correct me.

Of course that would not change the fact that in the end you are still asking for a rational number. The very worst thing CAS could do is to silently slip out of exact mode and give me an approximation when I clearly asked for an exact result (or I would be using Home mode).
I'm not a CAS expert, so you could look at the XCas source code if you really want to see how it does it, but I do know if you try the sum() function with arguments that are functions of different variables, it'll be a lot more complex than simply calling the same function over and over again. e.g. This SUM(1/y^2,y,x,1000x) results in Psi(x,1)-Psi(1000*x+1,1).

The sigma function is way way faster as it's just doing what that pseudocode does (calling the same function over and over again). e.g. Sum with an upper limit of 5000 takes about 20 seconds, but sigma returns an answer immediately.

FYI, the XCas source code is here...
https://www-fourier.ujf-grenoble.fr/~parisse/giac/src/
Ah, the plot thickens...

The "sophisticated" and "complex" work that you are referring to is simply a re-labelling of the partial sum. It does not do anything significant other than putting a name to the partial sums so that it looks "nicer" when you are using variable bounds.

But your original post isn't about that, it is about calculations with explicit bounds and the Psi function isn't going to help you one bit there, whereas actually doing the sum by going through the loop does (if it doesn't bump into its limitations first).
(10-12-2017 01:13 AM)webmasterpdx Wrote: [ -> ]FYI, the XCas source code is here...
https://www-fourier.ujf-grenoble.fr/~parisse/giac/src/

giac in geogebra svn
(10-12-2017 06:23 AM)parisse Wrote: [ -> ]
(10-12-2017 01:13 AM)webmasterpdx Wrote: [ -> ]FYI, the XCas source code is here...
https://www-fourier.ujf-grenoble.fr/~parisse/giac/src/