Post Reply 
sum command...
10-11-2017, 05:01 AM
Post: #1
sum command...
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
Find all posts by this user
Quote this message in a reply
10-11-2017, 05:06 AM
Post: #2
RE: sum command...
If you want an approx value, enter one approx bound, for example
sum(1/x^2,x,1,5000.)
Same for integration.
Find all posts by this user
Quote this message in a reply
10-11-2017, 05:14 AM
Post: #3
RE: sum command...
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).
Find all posts by this user
Quote this message in a reply
10-11-2017, 09:07 AM
Post: #4
RE: sum command...
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...
Find all posts by this user
Quote this message in a reply
10-11-2017, 09:26 AM
Post: #5
RE: sum command...
sum is a CAS command. in Home try to use Σ instead (from the math template key). For ex: Σ(1/X^2,X,1,5000)
Find all posts by this user
Quote this message in a reply
10-11-2017, 10:19 AM
Post: #6
RE: sum command...
Wow.....sigma is really fast too...Thx!
Find all posts by this user
Quote this message in a reply
10-11-2017, 12:25 PM
Post: #7
RE: sum command...
(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?
Find all posts by this user
Quote this message in a reply
10-11-2017, 01:41 PM
Post: #8
RE: sum command...
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....
Find all posts by this user
Quote this message in a reply
10-11-2017, 11:11 PM (This post was last modified: 10-11-2017 11:42 PM by AlexFekken.)
Post: #9
RE: sum command...
(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:

[1] 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?

[2] 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).
Find all posts by this user
Quote this message in a reply
10-12-2017, 01:13 AM
Post: #10
RE: sum command...
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/
Find all posts by this user
Quote this message in a reply
10-12-2017, 05:04 AM (This post was last modified: 10-12-2017 05:11 AM by AlexFekken.)
Post: #11
RE: sum command...
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).
Find all posts by this user
Quote this message in a reply
10-12-2017, 06:23 AM
Post: #12
RE: sum command...
(10-12-2017 01:13 AM)webmasterpdx Wrote:  FYI, the XCas source code is here...
https://www-fourier.ujf-grenoble.fr/~parisse/giac/src/

I would instead recommend
giac in geogebra svn
Find all posts by this user
Quote this message in a reply
10-12-2017, 06:38 AM
Post: #13
RE: sum command...
(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/

I would instead recommend
giac in geogebra svn
Thanks.
Find all posts by this user
Quote this message in a reply
10-12-2017, 07:18 AM
Post: #14
RE: sum command...
Is this the official XCas source SVN database?
Find all posts by this user
Quote this message in a reply
10-12-2017, 09:29 AM
Post: #15
RE: sum command...
Keep in mind as you download and refer to various documents, the CAS changes. There have been a lot of, "fixed in source" notes on this forum, and perhaps many more changes behind the scenes. It may not be current code, to whatever conclusions that may take a reader.
Find all posts by this user
Quote this message in a reply
10-12-2017, 12:10 PM
Post: #16
RE: sum command...
(10-12-2017 07:18 AM)webmasterpdx Wrote:  Is this the official XCas source SVN database?
There is no official SVN source for Xcas, but a tarball on my webpage. The geogebra SVN contains the giac source code without the UI, and I maintain it up to date. Since the UI is not used on the Prime, I recommend it.
Find all posts by this user
Quote this message in a reply
10-12-2017, 01:02 PM
Post: #17
RE: sum command...
OK. Thats the one I've set the wiki to point to...
http://www.wiki4hp.com/doku.php?id=prime:start
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)