hp41programs

Polynomials2

Polynomials(II) for the HP-41


Overview
 

 1°)  Square
 2°)  Square-Root
 3°)  Cube
 4°)  Cubic-Root
 5°)  Power of a Polynomial
 6°)  N-th Root of a Polynomial
 7°)  Derivative of a Polynomial
 8°)  Primitive of a Polynomial
 9°)  Primitive of Functions: p(x) Exp(A.x)
10°) Primitive of Functions: p(x) Sin(h) (A.x) + q(x) Cos(h) (A.x)
 
 

1°)  Square of a Polynomial
 

-Given a real polynomial   p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0 ,  "P^2"  calculates  [ p(x) ]2
 

Data Registers:             R00 = BBB.EEE              ( Registers Rbb thru Ree are to be initialized before executing "P^2" )

                                        R01 = bbb.eee
                                        R02-R03-R04-R05: temp              •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0
Flags: /
Subroutines: /
 
 

 01  LBL "P^2"
 02  STO 04
 03  X<>Y
 04  STO 01        
 05  STO 02 
 06  FRC
 07   E3
 08  *
 09  RCL 01
 10  INT
 11  -
 12  STO 05        
 13  ST+ X
 14  +
 15   E3
 16  /
 17  RCL 04
 18  +
 19  STO 00
 20  CLRGX
 21  LBL 01        
 22  RCL IND 01
 23  RCL IND 02
 24  *
 25  ST+ IND 04
 26  ISG 04
 27  CLX
 28  ISG 01
 29  GTO 01
 30  RCL 05        
 31  ST- 04
 32  1
 33  +
 34  ST- 01
 35  ISG 02
 36  GTO 01
 37  RCL 00        
 38  END

 
     ( 60 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y         bbb.eee             /
           X           BBB      BBB.EEE

   where     bbb.eee  =  control number of p(x)                       all  bbb > 005
     and      BBB.EEE = -----------------  [ p(x) ]2

Example:            p(x) = 2 x3 - 4 x2 + 3 x + 7

-If - for instance - you store p(x) in R11 thru R14  ( control number = 11.014 )

    2  STO 11      3  STO 13
   -4  STO 12      7  STO 14

 and if you choose  BBB = 15

    11.014   ENTER^
        15      XEQ "P^2"   >>>>  15.021                               ---Execution time = 8s---

-And you get  R15 = 4 ,  R16 = -16 ,  R17 = 28 ,  R18 = 4  ,  R19 = -47 ,  R20 = 42  , R21 = 49

 Whence,    [ p(x) ]2 = 4 x6 - 16 x5 + 28 x4 + 4 x3 - 47 x2 + 42 x + 49

Note:

-The blocks of registers cannot overlap
 

2°)  Square-Root of a Polynomial
 

-Given a polynomial  p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0     with n = deg p is even  and  an  non-negative,
 "SQRTP"  finds 2 polynomials  q(x)  &  r(x)  such that

     p = q2 + r   ,    deg q = n / 2   ,    deg r < deg q
 

Data Registers:             R00 = bbb.eee                    ( Registers Rbb thru Ree are to be initialized before executing "SQRTP" )

                                        R01 thru R04: temp                   •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0
Flag:  F10
Subroutines: /
 
 

  01  LBL "SQRTP"
  02  STO 00
  03  RCL IND X
  04  SQRT
  05  STO IND 00
  06  0
  07  RCL 00         
  08  ISG T
  09  X=0?
  10  RTN
  11  FRC
  12   E3
  13  *
  14  RCL 00 
  15  INT
  16  -
  17  2
  18  /
  19  FRC
  20  X#0?
  21  SF 41
  22  LASTX
  23  RCL 00
  24  INT
  25  STO Z
  26  +
  27  DSE X
  28   E3
  29  /
  30  +
  31  STO 01         
  32  SF 10
  33  LBL 01
  34  RCL 01
  35  INT
  36  STO 03
  37  RCL 00 
  38  INT
  39  1
  40  ST+ Z
  41  +
  42  RCL 03
  43   E3
  44  /
  45  +
  46  STO 02
  47  RCL IND Y
  48  FS?C 10
  49  GTO 00
  50  LBL 02
  51  RCL IND 02
  52  RCL IND 03
  53  *
  54  -
  55  DSE 03
  56  ISG 02
  57  GTO 02
  58  LBL 00 
  59  RCL IND 00
  60  ST+ X
  61  /
  62  STO IND 02
  63  ISG 01
  64  GTO 01
  65  RCL 00         
  66  FRC
  67  RCL 02
  68  INT
  69  STO 02
  70  +
  71  1
  72  +
  73  STO 01
  74  RCL 02
  75  RCL 03
  76  -
  77  STO 04
  78  RCL 00
  79  INT
  80  RCL 02         
  81   E3
  82  /
  83  +
  84  STO 03 
  85  ISG 03
  86  LBL 03
  87  RCL IND 01
  88  LBL 04
  89  RCL IND 02
  90  RCL IND 03
  91  *
  92  -
  93  DSE 02
  94  ISG 03
  95  GTO 04
  96  STO IND 01
  97  RCL 04
  98  ST+ 02
  99  DSE X
100  STO 04
101  ST- 03
102  ISG 01
103  GTO 03
104  RCL 03         
105  INT
106  RCL 00 
107  FRC
108  +
109  RCL 03
110  FRC
111  RCL 00
112  INT
113  +
114  END

 
        ( 162 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y             /      bbb.eee(r)
           X         bbb.eee      bbb.eee(q)

   where     bbb.eee  =  control number of p(x)                          bbb > 004

Example1:         p(x) =  4 x6 - 16 x5 + 28 x4 + 4 x3 - 47 x2 + 42 x + 49

-Store, for example, these 7 coefficients into  R05 thru R11

    5.011   XEQ "SQRTP"  >>>>   5.008                       ---Execution time = 9s---
                                         X<>Y   9.011

-You get in R05 thru R08   q(x) = 2 x3 - 4 x2 + 3 x + 7
     and    in R09 thru R11   r(x) = 0

Example2:         p(x) =  4 x6 - 16 x5 + 28 x4 + 4 x3 - 46 x2 + 44 x + 52

-Store, for example, these 7 coefficients into  R05 thru R11

    5.011   XEQ "SQRTP"  >>>>   5.008                       ---Execution time = 9s---
                                         X<>Y   9.011

-You get in R05 thru R08   q(x) = 2 x3 - 4 x2 + 3 x + 7
     and    in R09 thru R11   r(x) =   x2 + 2 x + 3
 

Notes:

-You could use "DEL" to delete the zero dominant elements in r(x)  ( cf "Polynomials for the HP-41" )
-The coefficients of q(x) and r(x) overwrite the coefficients of p(x)
-There is also another solution:  - q(x)

-Lines 01 to 64 calculate the square-root q(x). So, if you are sure that p(x) is the square of a real polynomial, the other lines are useless !
-If deg p is odd, you'll get  NONEXISTENT line 21
-If p(x) is a non-negative constant, Y-output = 0
 

3°)  Cube of a Polynomial
 

-Given a real polynomial   p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0 ,  "P^3"  calculates  [ p(x) ]3
 

Data Registers:             R00 = BBB.EEE              ( Registers Rbb thru Ree are to be initialized before executing "P^3" )

                                        R01 = bbb.eee
                                        R02-R03-R04-R05-R06: temp              •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0
Flags: /
Subroutines: /
 
 

 01  LBL "P^3"
 02  STO 05
 03  X<>Y
 04  STO 01
 05  STO 02        
 06  STO 03 
 07  FRC
 08   E3
 09  *
 10  RCL 01
 11  INT
 12  -
 13  STO 06        
 14  3
 15  *
 16  +
 17   E3
 18  /
 19  RCL 05
 20  +
 21  STO 00        
 22  CLRGX
 23  LBL 01
 24  RCL IND 01
 25  RCL IND 02
 26  RCL IND 03
 27  *
 28  *
 29  ST+ IND 05
 30  ISG 05
 31  CLX
 32  ISG 01
 33  GTO 01
 34  RCL 06        
 35  ENTER^
 36  ST- 05
 37  1
 38  +
 39  ST- 01
 40  ISG 02
 41  GTO 01
 42  ST- 02
 43  X<>Y
 44  ST- 05
 45  ISG 03
 46  GTO 01
 47  RCL 00        
 48  END

 
         ( 74 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y         bbb.eee             /
           X           BBB      BBB.EEE

   where     bbb.eee  =  control number of p(x)                       all  bbb > 006
     and      BBB.EEE = -----------------  [ p(x) ]3

Example:            p(x) = 2 x3 - 4 x2 + 3 x + 7

-If - for instance - you store p(x) in R11 thru R14  ( control number = 11.014 )

    2  STO 11      3  STO 13
   -4  STO 12      7  STO 14

 and if you choose  BBB = 15

    11.014   ENTER^
        15      XEQ "P^3"   >>>>  15.024                               ---Execution time = 35s---

-And you get in registers  R15 thru R24

     [ p(x) ]3 = 8 x9 - 48 x8 + 132 x7 - 124 x6 - 138 x5 + 480 x4 - 183 x3 - 399 x2 + 441 x + 343

Note:

-The blocks of registers cannot overlap
 

4°)  Cubic-Root of a Polynomial
 

-Given a polynomial  p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0     with n = deg p is a multiple of 3 ,
 "CBRTP"  finds 2 polynomials  q(x)  &  r(x)  such that

     p = q3 + r   ,    deg q = n / 3   ,    deg r < 2 deg q
 

Data Registers:             R00 = bbb.eee                    ( Registers Rbb thru Ree are to be initialized before executing "CBRTP" )

                                        R01 thru R05: temp                   •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0
Flag:  F10
Subroutines: /
 

-Line 62 is a three-byte GTO
 
 

  01  LBL "CBRTP"
  02  STO 00
  03  RCL IND X
  04  3
  05  1/X
  06  Y^X
  07  STO IND 00
  08  0
  09  RCL 00          
  10  ISG T
  11  X=0?
  12  RTN
  13  FRC
  14   E3
  15  *
  16  STO 03
  17  RCL 00
  18  INT
  19  -
  20  3
  21  /
  22  STO 02
  23  STO 05
  24  FRC
  25  X#0?
  26  SF 41
  27  LASTX
  28  RCL 00          
  29  INT
  30  STO Z
  31  +
  32  DSE X
  33   E3
  34  /
  35  +
  36  1
  37  ST- 02
  38  +
  39  STO 01 
  40  RCL IND 01
  41  RCL IND 00
  42  X^2
  43  3
  44  *
  45  /
  46  STO IND 01
  47  RCL 02
  48  X#0?
  49  GTO 01
  50  CLX
  51  3
  52  Y^X
  53  ST- IND 03
  54  DSE 03
  55  RCL IND 01
  56  X^2
  57  RCL IND 00
  58  *
  59  3
  60  *
  61  ST- IND 03
  62  GTO 00
  63  LBL 01
  64  RCL 00          
  65  INT
  66  RCL 01
  67  INT
  68  STO 04
  69   E3
  70  /
  71  +
  72  STO 02
  73  STO 03
  74  CLST
  75  SF 10
  76  ISG 03
  77  LBL 02
  78  RCL IND 03
  79  RCL IND 04
  80  *
  81  +
  82  DSE 04
  83  ISG 03
  84  GTO 02
  85  RCL IND 02
  86  *
  87  -
  88  RCL 03          
  89  INT
  90  2
  91  FS?C 10
  92  SIGN
  93  -
  94  STO 04
  95   E3
  96  /
  97  RCL 00
  98  INT
  99  +
100  STO 03
101  CLX
102  ISG 02
103  GTO 02
104  CLX
105  RCL IND 02
106  +
107  RCL IND 00
108  X^2
109  3
110  *
111  /
112  STO IND 02
113  ISG 01
114  GTO 01
115  RCL 01          
116  INT
117   E3
118  /
119  RCL 00
120  INT
121  +
122  STO 01
123  STO 02
124  STO 03
125  LBL 03
126  RCL 05
127  RCL 01
128  RCL 02
129  RCL 03          
130  +
131  +
132  INT
133  RCL 00 
134  INT
135  ST+ Z
136  ST+ X
137  -
138  X<=Y?
139  GTO 04
140  RCL IND 01
141  RCL IND 02
142  RCL IND 03
143  *
144  *
145  ST- IND Y
146  LBL 04
147  ISG 01
148  GTO 03
149  RCL 05
150  1
151  +
152  ST- 01
153  ISG 02
154  GTO 03
155  ST- 02
156  ISG 03
157  GTO 03
158  LBL 00
159  RCL 00          
160  FRC
161  RCL 03
162  INT
163  ST+ Y
164  DSE X
165   E3
166  /
167  RCL 00
168  INT
169  +
170  END

 
        ( 238 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y             /      bbb.eee(r)
           X         bbb.eee      bbb.eee(q)

   where     bbb.eee  =  control number of p(x)                          bbb > 005

Example1:         p(x) =  8 x9 - 48 x8 + 132 x7 - 124 x6 - 138 x5 + 480 x4 - 183 x3 - 399 x2 + 441 x + 343

-Store, for example, these 10 coefficients into  R06 thru R15

    6.015   XEQ "CBRTP"  >>>>   6.009                       ---Execution time = 59s---
                                         X<>Y  10.015

-You get in R06 thru R09   q(x) = 2 x3 - 4 x2 + 3 x + 7
     and    in R10 thru R15   r(x) = 0

Example2:         p(x) =  8 x9 - 48 x8 + 132 x7 - 124 x6 - 136 x5 + 480 x4 - 183 x3 - 400 x2 + 440 x + 340

-Store, for example, these 10 coefficients into  R06 thru R15

    6.015   XEQ "CBRTP"  >>>>   6.009                       ---Execution time = 59s---
                                         X<>Y  10.015

-You get in R06 thru R09   q(x) = 2 x3 - 4 x2 + 3 x + 7
     and    in R10 thru R15   r(x) =  2 x5 - x2 - x - 3
 

Notes:

-You could use "DEL" to delete the zero dominant elements in r(x)  ( cf "Polynomials for the HP-41" )
-The coefficients of q(x) and r(x) overwrite the coefficients of p(x)

-If  an < 0 , you'll get a DATAERROR line 06, so lines 05-06 could be replaced by an M-code routine ( or a focal subroutine )  XROOT
  that works for negative arguments too...

-Lines 01 to 114 calculate the cubic-root q(x). So, if you are sure that p(x) is the cube of a real polynomial, the other lines are useless !
-If deg p is not a multiple of 3, you'll get  NONEXISTENT line 26
-If p(x) is a constant, Y-output = 0
 

5°)  Power of a Polynomial
 

-Given a positive integer n and a real polynomial   p(x) = am.xm+am-1.xm-1+ ... + a1.x+a0 ,  "P^N"  calculates  [ p(x) ]n
 

Data Registers:             R00 = deg p              ( Registers Rbb thru Ree are to be initialized before executing "P^N" )

                                        R01 ...... Rnn: temp            •  Rbb = am  •  Rbb+1 = am-1  ................  •  Ree = a0
Flags: /
Subroutines: /
 
 

 01  LBL "P^N"
 02  STO O
 03  RDN
 04  STO N 
 05  X<>Y
 06  STO M        
 07  FRC
 08   E3
 09  *
 10  RCL M
 11  INT
 12  -
 13  STO 00
 14  RCL N 
 15  *
 16  RCL O        
 17  +
 18   E3
 19  /
 20  RCL O
 21  +
 22  STO P
 23  CLRGX
 24  RCL N
 25  RCL M 
 26  LBL 00
 27  STO IND Y
 28  DSE Y
 29  GTO 00
 30  LBL 01 
 31  RCL N        
 32  STO Q
 33  LBL 02
 34  RCL N 
 35  ENTER^
 36  SIGN
 37  LBL 03        
 38  RCL IND Y
 39  RDN
 40  RCL IND T
 41  *
 42  DSE Y
 43  GTO 03 
 44  ST+ IND O
 45  CLX
 46  SIGN
 47  ST+ O 
 48  ISG IND Q
 49  GTO 02
 50  LBL 04
 51  RCL 00        
 52  ST- O
 53  ENTER^
 54  SIGN
 55  +
 56  ST- IND Q
 57  DSE Q
 58  X=0?
 59  GTO 05
 60  ISG IND Q
 61  GTO 01
 62  GTO 04 
 63  LBL 05        
 64  RCL P 
 65  CLA
 66  END

 
           ( 109 bytes / SIZE nnn+1+??? )
 
 

      STACK        INPUTS      OUTPUTS
           Z         bbb.eee             /
           Y             n             /
           X           BBB      BBB.EEE

   where     bbb.eee  =  control number of p(x)                       all  bbb > nnn
     and      BBB.EEE = -----------------  [ p(x) ]n

Example:            p(x) = 2 x3 - 4 x2 + 3 x + 7   ,    n = 4

-If - for instance - you store p(x) in R11 thru R14  ( control number = 11.014 )

    2  STO 11      3  STO 13
   -4  STO 12      7  STO 14

 and if you choose  BBB = 15

    11.014   ENTER^
         4       ENTER^
        15      XEQ "P^N"   >>>>  15.027                               ---Execution time = 5m27s---

-And you get in registers  R15 thru R27

     [ p(x) ]4 = 16 x12 - 128 x11 + 480 x10 - 864 x9 + 280 x8 + 2064 x7 - 3568 x6 + 408 x5 + 5289 x4 - 3556 x3 - 2842 x2 + 4116 x + 2401

Notes:

-The blocks of registers cannot overlap
-This method is surely not the fastest way to compute the n-th power of a polynomial !
-On the other hand, it uses less data registers.
 

6°)  N-th Root of a Polynomial
 

-Given a positive integer n and a real polynomial   p(x) = am.xm+am-1.xm-1+ ... + a1.x+a0   where  m is a multiple of n

 "P^1/N"  calculates q(x) & r(x) such that

     deg q = m / n    deg r < (n-1) deg q     p = qn + r

-If  r = 0 ,  q(x) = [ p(x) ] 1/n
 

Data Registers:             R00 = deg p              ( Registers Rbb thru Ree are to be initialized before executing "P^1/N" )

                                        R01 ...... Rnn: temp            •  Rbb = am  •  Rbb+1 = am-1  ................  •  Ree = a0
Flag:  F10
Subroutines: /

-Lines 48 & 141 are three-byte  GTO's
 
 

  01  LBL "P^1/N"
  02  STO N
  03  X<>Y
  04  STO M 
  05  RCL IND X
  06  RCL Z
  07  1/X
  08  Y^X
  09  STO IND Y
  10  0
  11  RCL M 
  12  ISG T
  13  X=0?
  14  RTN
  15  FRC
  16   E3
  17  *
  18  RCL M          
  19  INT
  20  -
  21  RCL N
  22  /
  23  STO 00
  24  FRC
  25  X#0?
  26  SF 41
  27  RCL M
  28  ISG X
  29  RCL IND M
  30  RCL N
  31  1
  32  -
  33  Y^X
  34  RCL N 
  35  *
  36  ST/ IND Y
  37  X<>Y
  38  INT
  39   E3
  40  /
  41  RCL M 
  42  INT
  43  +
  44  STO O
  45  RCL 00
  46  1
  47  X=Y?
  48  GTO 08
  49  2
  50  LASTX
  51  RCL N          
  52  *
  53  ST+ Y
  54  RCL 00
  55  +
  56   E3
  57  /
  58  +
  59  STO P
  60  LBL 01
  61  RCL N
  62  RCL O
  63  LBL 02
  64  STO IND Y
  65  DSE Y
  66  GTO 02
  67  LBL 03
  68  RCL N 
  69  STO Q
  70  CLX
  71  SIGN
  72  SF 10
  73  LBL 04
  74  RCL N
  75  RCL P
  76  INT
  77  LBL 05
  78  RCL IND Y
  79  INT
  80  -
  81  DSE Y
  82  GTO 05
  83  X#0?
  84  GTO 00
  85  CF 10
  86  RCL N          
  87  R^
  88  LBL 06
  89  RCL IND Y
  90  RDN
  91  RCL IND T
  92  *
  93  DSE Y
  94  GTO 06
  95  RDN
  96  LBL 00
  97  R^
  98  ISG IND Q
  99  GTO 04
100  FS?C 10
101  GTO 07
102  RCL IND Q
103  X<>Y
104  ST- IND Y
105  LBL 07
106  RCL IND Q
107  FRC
108  RCL M 
109  INT
110  +
111  STO IND Q
112  DSE Q
113  X=0?
114  GTO 00
115  ISG IND Q
116  GTO 03
117  GTO 07
118  LBL 00
119  RCL O          
120  FRC
121  PI 
122  INT
123  10^X
124  *
125  ENTER^
126  SIGN
127  +
128  RCL IND M
129  RCL N
130  DSE X
131  Y^X
132  RCL N
133  *
134  ST/ IND Y
135  PI
136  INT
137  CHS
138  10^X
139  ST+ O
140  ISG P
141  GTO 01
142  LBL 08
143  RCL N 
144  RCL O 
145  LBL 09
146  STO IND Y
147  DSE Y
148  GTO 09
149  LBL 10
150  RCL N
151  STO P
152  LBL 11
153  RCL N          
154  RCL M
155  INT
156  RCL 00
157  ST+ Y
158  CLX
159  LBL 12
160  RCL IND Z
161  INT
162  +
163  DSE Z
164  GTO 12
165  RCL N
166  RCL M
167  INT
168  ST* Y
169  -
170  -
171  X<=Y?
172  GTO 00
173  RCL N          
174  ENTER^
175  SIGN
176  LBL 13
177  RCL IND Y
178  RDN
179  RCL IND T
180  *
181  DSE Y
182  GTO 13
183  ST- IND Z
184  LBL 00
185  ISG IND P
186  GTO 11
187  LBL 14
188  RCL IND P
189  FRC
190  RCL M
191  INT
192  +
193  STO IND P
194  DSE P
195  X=0?
196  GTO 00
197  ISG IND P
198  GTO 10
199  GTO 14
200  LBL 00
201  RCL O          
202  FRC
203   E3
204  *
205  1
206  +
207  RCL M
208  FRC
209  +
210  RCL O
211  CLA
212  END

 
        ( 329 bytes / SIZE nnn+1+??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y         bbb.eee      bbb.eee(r)
           X             n      bbb.eee(q)

   where     bbb.eee  =  control number of p(x)                          bbb > nnn

Example:         p(x) =  32 x10 - 320 x9 + 1520 x8 - 44792 x7 + 9040 x6 - 13024 x5 + 13560 x4 - 10080 x3 + 5130 x2 - 1620 x + 245  ,   n = 5

-Store, for example, these 11 coefficients into  R11 thru R21

    11.021   ENTER^
        5        XEQ "P^1/N"  >>>>   11.013                       ---Execution time = 11m55s---
                                         X<>Y   14.021

-You get in R11 thru R13   q(x) = 2 x2 - 4 x + 3
     and    in R14 thru R21   r(x) =     x7 + 2
 

Notes:

-You could use "DEL" to delete the zero dominant elements in r(x)  ( cf "Polynomials for the HP-41" )
-The coefficients of q(x) and r(x) overwrite the coefficients of p(x)

-If  am < 0 , you'll get a DATAERROR line 08, so lines 07-08 could be replaced by an M-code routine ( or a focal subroutine )  XROOT
  that works for negative arguments too ( if n is odd )...

-Or replace line 06 to 08 by

      CF 10           STO 00       CF 10            X<>Y          1/X
      X<0?            2                  X<> 00          ABS            Y^X
      SF 10           MOD           FC? 10          X<>Y          FS? 10
      RCL Z          X=0?           GTO 00         LBL 00         CHS

-Lines 01 to 142 calculate the n-th root q(x). So, if you are sure that p(x) is the n-th power of a polynomial, the other lines are useless !
-If deg p is not a multiple of n, you'll get  NONEXISTENT line 26
-If p(x) is a constant, Y-output = 0

-This method is surely not the fastest way to compute the n-th root of a polynomial, especially to find the remainder !
-On the other hand, it only uses the data registers employed by p(x) , plus R00 thru Rnn
 

7°)  Derivative of a Polynomial
 

 "DER" calculates the coefficients of a given polynomial p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0
 

Data Registers:             R00-R01: temp                   ( Registers Rbb thru Ree are to be initialized before executing "DER" )

                                    •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0
Flags:  /
Subroutines: /
 
 

 01  LBL "DER"
 02  ENTER^
 03  STO 00
 04  FRC
 05   E3
 06  *
 07  RCL 00
 08  INT
 09  -
 10  STO 01
 11  LBL 01
 12  RCL IND Y
 13  RCL Y
 14  *
 15  STO IND Z
 16  CLX
 17  SIGN
 18  -
 19  ISG Y
 20  GTO 01
 21  RCL 00
 22   E-3
 23  RCL 01
 24  X#0?
 25  SIGN
 26  *
 27  -
 28  END

 
( 44 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           X         bbb.eee      bbb'.eee

   where     bbb.eee  =  control number of p(x)   ,     bbb'.eee  =  control number of p'(x)      bbb > 001

Example:         p(x) =  4 x3 + 7 x2 - 3 x + 1

-Store these 4 coefficients in  R11-R12-R13-R14 ( for instance )

           11.014   XEQ "DER"  >>>>   12.014

  R11 = 12   R12 = 14  R13 = -3       so     p'(x) = 12 x2 + 14 x - 3
 

8°)  Primitive of a Polynomial
 

-Given a polynomial p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0   "PRIM"  calculates the coefficient of the primitive P(x) of p(x) that vanishes for x = 0
 

Data Registers:             R00: temp                   ( Registers Rbb thru Ree are to be initialized before executing "PRIM" )

                                    •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0            Ree+1 is used too
Flags:  /
Subroutines: /
 
 

 01  LBL "PRIM"
 02  ENTER^
 03  STO 00
 04  FRC
 05   E3
 06  *
 07  RCL 00
 08  INT
 09  -
 10  ISG X
 11  LBL 01
 12  RCL IND Y
 13  RCL Y
 14  /
 15  STO IND Z
 16  CLX
 17  SIGN
 18  -
 19  ISG Y
 20  GTO 01
 21  STO IND Y
 22  X<>Y
 23  INT
 24   E3
 25  /
 26  RCL 00
 27  INT
 28  +
 29  END

 
( 47 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           X         bbb.eee       bbb.eee'

   where     bbb.eee  =  control number of p(x)   ,     bbb.eee'  =  control number of P(x)      bbb > 000

Example:         p(x) =  8 x3 + 9 x2 - 4 x + 7

-Store these 4 coefficients in  R01-R02-R03-R04 ( for instance )

           1.004   XEQ "PRIM"  >>>>   1.005

  R01 = 2   R02 = 3  R03 = -2  R04 = 7  R05 = 0     so     P(x) = 2 x4 + 3 x3 - 2 x2 + 7 x
 

9°)  Primitive of Functions:   p(x) Exp(A.x)
 

-"PEX" returns a primitive F(x) of the form  P(x) Exp(A.x) where P(x) has the same degree as p(x)

   p(x) = an.xn+an-1.xn-1+ ... + a1.x+a0

-The coefficients of P(x) overwrite the coefficients of p(x)
 

Data Registers:             R00-R01-R02:   temp                   ( Registers Rbb thru Ree are to be initialized before executing "PEX" )

                                    •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0
Flags:  /
Subroutines: /
 

-Line 23 is a synthetic TEXT0  ( NOP instruction )
-It may be replaced by LBL 01
 
 

 01  LBL "PEX"
 02  X<>Y
 03  STO 01
 04  STO 02
 05  INT
 06  LASTX
 07  FRC
 08   E3
 09  *
 10  -
 11  STO 00
 12  CLX
 13  DSE 00
 14  LBL 01
 15  RCL 00
 16  *
 17  RCL IND 02
 18  +
 19  X<>Y
 20  /
 21  STO IND 02
 22  ISG 00
 23  ""
 24  ISG 02
 25  GTO 01
 26  RCL 01
 27  END

 
( 42 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y        bbb.eee            /
           X             A        bbb.eee

   where     bbb.eee  =  control number of p(x)  =  control number of P(x)      bbb > 002

Example:         f(x) = ( 7 x6 - 3 x5 + 4 x4 + 2 x3 + 8 x2 + 5 x + 1 ) exp ( -x/2 )

-Store - for instance - these 7 coefficients into R11 to R17

     7  STO 11     2  STO 14      1  STO 17
    -3 STO 12     8  STO 15
     4  STO 13     5  STO 16

-Here,     A = -1/2   so,

     11.017  ENTER^
       -0.5     XEQ "PEX"   >>>>    11.017                              ---Execution time = 4s---

-And we find in R11 thru R17:    -14   -162   -1628   -13028   -78184   -312746   -625494

-Thus,   F(x) = ( -14 x6 - 162 x5 - 1628 x4 - 13028 x3 - 78184 x2 - 312746 x - 625494 ) exp ( -x/2 )

Notes:

-As usual, add an arbitrary constant to get all the primitives
-The costant A is saved in L-register
 

10°) Primitive of Functions: p(x) Sin(h) (A.x) + q(x) Cos(h) (A.x)
 

-If flag F01 is clear, "PS+QC"  gives a primitive F(x) = P(x) Sin (A.x) + Q(x) Cos (A.x) of the function f(x) = p(x) Sin (A.x) + q(x) Cos (A.x)

-If flag F01 is set,    "PS+QC"  gives a primitive F(x) = P(x) Sinh (A.x) + Q(x) Cosh (A.x) of the function f(x) = p(x) Sinh (A.x) + q(x) Cosh (A.x)

    where  p , q  , P , Q  are polynomials

-We assume that p & q  have the same degree.
-However, it's easy to use this program even if  deg p # deg q  ( cf example 2 )
 

Data Registers:             R00-R01-R02:   temp                   ( Registers Rbb thru Ree are to be initialized before executing "PS+QC" )

                                    •  Rbb = an  •  Rbb+1 = an-1  ................  •  Ree = a0    coefficients of p(x)
                                    •  Rbb' = a'n •  Rbb'+1 = a'n-1  ..............  •  Ree' = a'0   coefficients of q(x)

Flags:  F01                     CF 01 = Sin & Cos
                                        SF 01 = Sinh & Cosh
Subroutines: /
 

-Lines 35-37 are synthetic TEXT0  ( NOP instruction )
-They may be replaced by LBL 01
 
 

 01  LBL "PS+QC"
 02  STO 00
 03  RDN
 04  STO 01          
 05  STO 02
 06  X<>Y
 07  STO 03
 08  STO 04          
 09  INT
 10  LASTX
 11  FRC
 12   E3
 13  *
 14  -
 15  STO 05
 16  CLST
 17  DSE 05
 18  LBL 01
 19  RCL 05          
 20  ST* Z
 21  *
 22  RCL IND 02
 23  +
 24  RCL 00          
 25  /
 26  STO Z
 27  X<> IND 04
 28  +
 29  RCL 00          
 30  /
 31  FC? 01
 32  CHS
 33  STO IND 02
 34  ISG 05
 35  ""
 36  ISG 02
 37  ""
 38  ISG 04
 39  GTO 01
 40  RCL 01          
 41  RCL 03
 42  END

 
     ( 64 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Z     bbb.eee(p)             /
           Y     bbb.eee(q)      bbb.eee(Q)
           X             A      bbb.eee(P)

   where      bbb > 005

Example1a:   Calculate the indefinite integral    I = §  [ ( 2 x4 + 5 x3 + 3 x2 - 4 x + 7 ) Sin ( x/2 ) + ( 3 x4 - 2 x2 - 4 x - 1 ) Cos ( x/2 )  ] dx

-Store, for example, the coefficients of p(x) into R11 thru R15 and the coeficients of q(x) into R21 thru R25

   2   STO 11                 3   STO 21
   5   STO 12                 0   STO 22
   3   STO 13                -2   STO 23
  -4  STO 14                -4   STO 24
   7   STO 15                -1  STO 25

-Here,     A = 1/2   so,

     CF  01                     ( Sin & Cos )

     11.015  ENTER^
     21.025  ENTER^
        0.5     XEQ "PS+QC"  >>>>  11.015                                     ---Execution time = 4s---
                                           X<>Y  21.025

  R11-R12-R13-R14-R15 =  [ 6  32  -232  -752  1838 ]
  R21-R22-R23-R24-R25 =  [ -4  38  186  -920  -1518 ]

-Thus,  I = ( 6 x4 + 32 x3 - 232 x2 - 752 x + 1838 ) Sin ( x/2 ) + ( -4 x4 + 38 x3 + 186 x2 - 920 x - 1518 ) Cos ( x/2 ) + Cste

Example1b:   Calculate the indefinite integral    I = §  [ ( 2 x4 + 5 x3 + 3 x2 - 4 x + 7 ) Sinh ( x/2 ) + ( 3 x4 - 2 x2 - 4 x - 1 ) Cosh ( x/2 )  ] dx

-Store, for example, the coefficients of p(x) into R11 thru R15 and the coeficients of q(x) into R21 thru R25

   2   STO 11                 3   STO 21
   5   STO 12                 0   STO 22
   3   STO 13                -2   STO 23
  -4  STO 14                -4   STO 24
  7   STO 15                 -1  STO 25

-Here,     A = 1/2   so,

     SF  01                     ( Sinh & Cosh )

     11.015  ENTER^
     21.025  ENTER^
        0.5     XEQ "PS+QC"  >>>>  11.015                                     ---Execution time = 4s---
                                           X<>Y  21.025

  R11-R12-R13-R14-R15 =  [ 6  -32  224  -800  1806 ]
  R21-R22-R23-R24-R25 =  [ 4  -38  198  -904  1614 ]

-Thus,  I = ( 6 x4 - 32 x3 + 224 x2 - 800 x + 1806 ) Sinh ( x/2 ) + ( 4 x4 - 38 x3 + 198 x2 - 904 x + 1614 ) Cosh ( x/2 ) + Cste
 

Example2:

-If  deg p # deg q , "PS+QC" will return wrong results.
-But simply add zeros on the left and use control numbers as if the degrees were the same:

-Calculate    I = §  [ ( 2 x4 + 5 x3 + 3 x2 - 4 x + 7 ) Sin ( x/2 ) + ( - 2 x2 - 4 x - 1 ) Cos ( x/2 )  ] dx

-Store, for example, the coefficients of p(x) into R11 thru R15 and the coeficients of q(x) into R21 thru R25 as if deg q = 4

   2   STO 11                 0   STO 21
   5   STO 12                 0   STO 22
   3   STO 13                -2   STO 23
  -4  STO 14                -4   STO 24
   7   STO 15                -1  STO 25

-Here,     A = 1/2   so,

     CF  01                     ( Sin & Cos )

     11.015  ENTER^
     21.025  ENTER^
        0.5     XEQ "PS+QC"  >>>>  11.015                                     ---Execution time = 4s---
                                           X<>Y  21.025

  R11-R12-R13-R14-R15 =  [ 0  32  56  -752  -466 ]
  R21-R22-R23-R24-R25 =  [ -4  -10  186  232  -1518 ]

-Thus,  I = ( 32 x3 + 56 x2 - 752 x - 466 ) Sin ( x/2 ) + ( -4 x4 - 10 x3 + 186 x2 + 232 x - 1518 ) Cos ( x/2 ) + Cste

-Likewise, you will find ( with SF 01 ):

 I = §  [ ( 2 x4 + 5 x3 + 3 x2 - 4 x + 7 ) Sinh ( x/2 ) + ( - 2 x2 - 4 x - 1 ) Cosh ( x/2 )  ] dx

   =  ( -32 x3 - 64 x2 - 800 x - 498 ) Sinh ( x/2 ) + ( 4 x4 + 10 x3 + 198 x2 + 248 x + 1614 ) Cosh ( x/2 ) + Cste

Note:

-It could be useful to add the following instructions after line 15

     RCL 01       FRC        -
     INT              E3         X#Y?
     LAST           *           SF 99

  to produce an error message ( NONEXISTENT ) if deg p # deg q