SYMPOL

# Elementary Symmetric Polynomials for the HP-41

Overview

1°)  Program#1
2°)  Program#2

-Given n real numbers  p1 , ............... , pn , these programs calculate the sums:

s1 = p1 + .............. + pn = SUM1<=i<=n pi
s2 = SUM1<=i1<i2 <=n pi1 pi2
s3 = SUM1<=i1<i2<i3 <=n pi1 pi2 pi3
.......................................................

sn = p1 .............. pn

1°)  Program#1

Data Registers:   R00 to R2n+8: temp
Flags: /
Subroutine:  "PRO"  product of 2 polynomials ( cf "Polynomials for the HP-41" ) & "LCO" ( cf "Short routines for the HP-41" )

-Line 13 is   append  ?

 01  LBL "SYMP"  02  8.008  03  STO 04          04  1  05  STO 05  06  STO 06  07  STO 08  08  LBL 01 09  " P"  10  FIX 0  11  CF 29  12  ARCL 05       13  "~?"  14  FIX 4  15  SF 29  16  PROMPT 17  FC?C 22  18  GTO 00  19  STO 07          20  6.007  21  RCL 04  22  RCL 04  23  FRC  24   E3 25  *  26  1  27  +  28  XEQ "PRO"  29  8  30  XEQ "LCO"  31  STO 04          32  ISG 05 33  CLX  34  GTO 01  35  LBL 00  36  RCL 04  37  1  38  +  39  STO 04          40  END

( 79 bytes / SIZE 2n+9 )

 STACK INPUT OUTPUT X / bbb.eee

where   bbb.eee  is the control number of the results  ( Rbb = s1 , .............. , Ree = sn )

Example:    We have 4 numbers pi      3   5   7   12

XEQ "SYMP"   >>>   " P1?"
3            R/S    " P2?"
5            R/S    " P3?"
7            R/S    " P4?"
12           R/S    " P5?"                           Press R/S without any digit entry when all the numbers are keyed in:
R/S     >>>>    9.012

-And we get:         R09 = s1 = 27  ;   R10= s2 = 251  ;   R11 = s3 = 957  ;  R12 = s4 = 1260

Notes:

-The delay between 2 successive PROMPTs increases with the number of data.
-If possible, replace  XEQ "LCO"  ( line 30 )  by the M-Code routine  LCO.

2°)  Program#2

-In this variant, you store n into R00 and p1 into R01 , ............... , pn into Rnn
-Moreover, the products of polynomials are performed directly,  without calling "PRO"
-Thus, the routine is both shorter and faster.

Data Registers:           •  R00 = n                 ( Registers R00 thru Rnn are to be initialized before executing "SYMP" )

•  R01 = p1     •  R02 = p2   .......................   •  Rnn = pn

>>>>  When the program stops,   Rn+2 = s1 ,  Rn+3 = s2 , ................... , R2n+1 = sn           ( and Rn+1 = 1 )

Flags: /
Subroutines: /

-Line 28 is a synthetic TEXT0
-It may be replaced by another NOP instruction like  STO X  ,   LBL 00  ...

 01  LBL "SYMP"  02  RCL 00          03  STO M  04  1  05  ST+ Y  06  STO IND Y  07  CLX  08  .1  09  % 10  +  11  LBL 01  12  ENTER^  13  ENTER^  14  SIGN  15  +  16  STO N          17  RCL IND M  18  SIGN 19  CLX  20  STO IND Y  21  LBL 02          22  CLX  23  RCL IND Z  24  LASTX  25  *  26  ST+ IND Y  27  DSE Z 28  ""  29  DSE Y  30  GTO 02  31  X<> N  32  DSE M  33  GTO 01          34  INT  35   E3  36  / 37  2  38  +  39  RCL 00          40  +  41  CLA  42  END

( 67 bytes / SIZE 2n+2 )

 STACK INPUT OUTPUT X / bbb.eee

where   bbb.eee  is the control number of the results  ( Rbb = s1 , .............. , Ree = sn )

Example:    With the same 4 numbers pi =  3   5   7   12

4  STO 00         3  STO 01   5  STO 02   7  STO 03   12  STO 04

XEQ "SYMP"   >>>   6.009                     ---Execution time = 5s---

-And we get:

R06 = s1 = 27  ,   R07 = s2 = 251  ,   R08 = s3 = 957  ,  R09 = s4 = 1260

Notes:

-With n = 10 ,  execution time =  21s
-With n = 50 ,  execution time = 7m41s