34S SUM PROD change request ccccc >= fff



#8

Could you please change "ccccc > fff" to "ccccc >= fff" so that ccccc can count down to and include 0.

Thanks.


#9

This is somewhat limited by the definition of DSE unfortunately.

Here is the sum and product code as it currently exists in the firmware image. It is just a plain old keystroke program. Feel free to submit a patch :-)

The stack will always be four levels deep when this code is run and registers 0-4 and flags 0-14 are freely available.


Then again, I could look into adding DSL and ISE as instructions.


- Pauli


/**************************************************************************/
/* Sigma and products
* Register use:
* 0 I
* 1 product/sum
* 2 carry for sum
* 3 saved I
*/
LBL 99 /* Entry: SUMMATION */
XEQ entry
SPEC?
JMP sum_product_okay
STO 00
STO 03 /* Save for LastX*/
IP /* First function call is separate*/
FILL /* to avoid Kahan summing from zero*/
XEQUSR /* six extra instructions save nine*/
SPEC? /* from executing*/
JMP sum_product_nan
STO 01
iC 0
STO 02
JMP sum_entry

sum_loop:: RCL 00
IP
FILL
XEQUSR
SPEC?
JMP sum_product_nan
RCL- 02
ENTER[^]
RCL+ 01
ENTER[^]
RCL- 01
RCL- Z
x[<->]y
[cmplx]STO 01

sum_entry:: DSE 00
JMP sum_loop
JMP sum_product_okay


LBL 98 /* Entry: PRODUCT */
XEQ entry
SPEC?
JMP sum_product_okay
STO 00
STO 03
IP /* First function call is separate*/
FILL /* to avoid a multiply*/
XEQUSR
SPEC?
JMP sum_product_nan
STO 01
JMP product_entry

product_loop:: RCL 00
IP
FILL
XEQUSR
SPEC?
JMP sum_product_nan
STO[times] 01
product_entry:: DSE 00
JMP product_loop

sum_product_okay:: RCL 03
STO L
iC 0
FILL
RCL 01
JMP exit

sum_product_nan:: RCL 03

sum_product_error:: STO L
iC 0
FILL
# NaN
JMP exit


#10

DSL and ISE are now present :-)

- Pauli


#11

... and documented in the manual :-)

Walter

#12

Pauli, what is the reasoning behind the complicated summation. It must have to do with increasing accuracy but how does it work?

If you want to make the code shorter, the two loops may easily be merged and the operation selected by a flag inside the loop.


#13

The summation is indeed an attempt to improve precision. The algorithm used is known as the Kahan sum.

Essentially, it maintains the sum and some of the digits lost off the end in two registers. The lost digits act as a correction term as each new item is added in.


Yes, the two loops could be merged. I didn't investigate this option since neither is very large.


- Pauli


#14

We will certainly be fighting for a handful of bytes again...


Possibly Related Threads...
Thread Author Replies Views Last Post
  Prime feature request Stefan Dröge (Germany) 0 346 11-06-2013, 11:06 AM
Last Post: Stefan Dröge (Germany)
  request M.E. pac for HP-67/97 wallet cover scan Ignacio Sánchez 0 372 11-06-2013, 09:36 AM
Last Post: Ignacio Sánchez Reig
  Program to change entry mode on Prime Michael de Estrada 3 587 10-28-2013, 10:13 AM
Last Post: Han
  HP PRIME: How to change the column headers and reset data Joseph Ec 5 737 10-18-2013, 02:26 PM
Last Post: Joseph Ec
  Prime: sum-of Paul D. Fox 2 391 10-13-2013, 10:22 AM
Last Post: Tim Wessman
  Leading 0 change? Tim Wessman 12 1,114 10-07-2013, 12:11 PM
Last Post: Katie Wasserman
  HP-Prime Polynomials: User Guide and Request CompSystems 4 652 09-30-2013, 09:48 PM
Last Post: Han
  HP Prime "Notes" feature request Charles Bennett 0 291 09-27-2013, 12:14 PM
Last Post: Charles Bennett
  [REQUEST] Your "Prime" Conference Questions Tim Wessman 9 986 09-22-2013, 05:34 AM
Last Post: Giancarlo
  [HP-Prime xcas] operations with complex numbers + BUGs + Request CompSystems 9 1,168 09-08-2013, 10:40 PM
Last Post: CompSystems

Forum Jump: