HP Forums
(50g) Simple summation program that returns large integers - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50g) Simple summation program that returns large integers (/thread-7997.html)

(50g) Simple summation program that returns large integers - pier4r - 03-22-2017 03:44 PM

So, In my little explorations reusing the hp 50g after years, I found out that the \GS built in function (sigma) of the 50g works on real or complex numbers, returning those two types of numbers.

After the suggestion of John Keit, I decided to create a program that simulate the summation function to return all the digits if the computation involves only integers and produces an integer. So I wrote the following complement of the built in summation function (more here on assembla.com git repo).


%%HP: T(0)A(D)F(.);
@ You may edit the T(0)A(D)F(.) parts.
@ The earlier parts of the line are used by Debug4x.

@ FLAG 3 and 105 will be cleared and not restored, since so far if they were set 
@ and they are restored 
@ the result is transformed in a real number hiding digits.

@Arguments on the stack
@ 4: index expression
@ 3: starting index
@ 2: ending index
@ 1: expression to evaluate

@ Example
@ sum from n=1 to n=2014 of n^3
@ 4: 'n'
@ 3: 1
@ 2: 2014
@ 1: 'n^3' (or equation writer object)

   @ contains alreay an expression between '' so can be stored without ''
    @let's store system flag
   -3 CF
     @no numeric mode when symbols are used (so also better integer precision)
   -105 CF
     @ exact mode, no approximations
   FOR counter
     counter indexExpression STO
     expression EVAL
     'resultingSum' STO+
    @ restore system flags

I suppose that such a complement can be expanded in a proper function, like handling errors, better flag handling, handling rational numbers that are still composed by integers, double summations, multiple index, index that can step more than +1 and so on. As it is, the program is pretty rough but may help (it helped me), if someone wants to expand the idea, feel free to do it. Shared knowledge is the best.

I'm also pretty sure that someone worked on programs like this already, because the amount of amazing math libraries existing for saturn compatible calculators is incredible, just I did not find anything about this topic with the search string "site:http://www.hpmuseum.org/forum summation OR sum 50g". So if someone knows already existing programs that are better than the one I made, please share them with a reply to this thread!

Side note on this section: would be nice to organize a naming convention for the titles, since I was not sure about it. I just followed the most common pattern.

RE: (50g) Simple summation program that returns large integers - pier4r - 03-23-2017 10:01 AM

Update. The built in summation function works fine with proper flags cleared (as they need to be cleared also in my program). See here.