Post Reply 
(50g) Simple summation program that returns large integers
03-22-2017, 03:44 PM (This post was last modified: 03-22-2017 03:47 PM by pier4r.)
Post: #1
(50g) Simple summation program that returns large integers
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).

Code:

%%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.

@Remarks:
@ 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)

\<<
 0
 \->
 indexExpression
   @ contains alreay an expression between '' so can be stored without ''
 startIndex
 endIndex
 expression
 resultingSum
 \<<
   PUSH 
    @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
   startIndex
   endIndex
   FOR counter
     counter indexExpression STO
     expression EVAL
     'resultingSum' STO+
   NEXT
   resultingSum
   @POP
    @ 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.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
03-23-2017, 10:01 AM
Post: #2
RE: (50g) Simple summation program that returns large integers
Update. The built in summation function works fine with proper flags cleared (as they need to be cleared also in my program). See here.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 




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