The Museum of HP Calculators


Euler & Eulerian Numbers for the HP-41

This program is Copyright © 2004 by Jean-Marc Baillard and is used here by permission.

This program is supplied without representation or warranty of any kind. Jean-Marc Baillard and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Overview

-Three programs are listed below:

   1°) a) "EULN1" calculates the Euler numbers E(n) by a series expansion
        b)  "EULN2" uses a recurrence relation to produce E'(0) , E'(1) , ..... , E'(n)
   2°)     "EULN3" computes the Eulerian numbers A(n;k)
 

1°) The Euler Numbers

        a) A Series Expansion

-These integers  may be computed by the formula:

     E(n) = (-1)n/2 2n+2 n! pi -n-1 ( 1/1n+1 - 1/3n+1 + 1/5n+1 - ..... + (-1)k / (2k+1)n+1 + .....  )     if  n is even
     E(n) = 0  if  n is odd

-"EULN1" gives E(n) directly if n < 7 or n odd.
-The series expansion is used for n > 7 ; n even.
-The first values are:
 
       n        0        2        4        6        8       10
     E(n)        1       -1        5      -61     1385   -50521

Data Registers:   R00 = n ; R01 to R02: temp
Flag: /
Subroutine: /
 

01  LBL "EULN1"
02  STO 00
03  1
04  X>Y?
05  RTN
06  ST+ X
07  MOD
08  0
09  X#Y?
10  RTN
11  LASTX
12  RCL 00
13  X#Y?
14  GTO 00
15  1
16  CHS
17  RTN
18  LBL 00
19  5
20  X>Y?
21  RTN
22  CLX
23  6
24  X#Y?
25  GTO 00
26  61
27  CHS
28  RTN
29  LBL 00
30  SIGN
31  STO Z
32  STO 01
33  +
34  CHS
35  STO 02
36  LBL 01
37  CLX
38  2
39  RCL 01
40  +
41  STO 01
42  RCL 02
43  Y^X
44  X<>Y
45  CHS
46  ST+ Y
47  X#Y?
48  GTO 01
49  ABS
50  ST+ X
51  2
52  PI
53  /
54   E-10
55  +
56  RCL 02
57  CHS
58  STO 02
59  Y^X
60  *
61  2
62  RCL 02
63  4
64  MOD
65  -
66  *
67  DSE 02
68  LBL 02
69  RCL 02
70  *
71  DSE 02
72  GTO 02
73  END

( 97 bytes / SIZE 003 )
 
 
      STACK        INPUTS      OUTPUTS
           X             n           E(n)

Example:     -Find   E(78)

    78   XEQ "EULN1"  yields  E(78) =  -7.270601736 1099   ( in 15seconds )
 

        b) A Recurrence Relation

-Some authors define these numbers by the relations:

    E'(0) = 1  ;  E'(1) = -1  and   -E'(n) - 1 = C2n2 E'(n-1) + C2n4 E'(n-2) + ..... + C2n2n-2 E'(1)   if  n > 1      ( actually,  E'(n) = E(2n) )

  where   Cnk = n!/(k!(n-k)!)   are the binomial coefficients.

-"EULN2" uses this recurrence relation to calculate and store E'(0) ; E'(1) ; ..... ; E'(n)  in registers R00 ; R01 ; ..... ; Rnn
-The first values are:
 
 
        n         0         1         2         3         4         5          6           7
      E'(n)         1        -1         5       -61      1385    -50521   2702765  -199360981

 

Data Registers:   R00 = E'(0) ; R01 = E'(1) ; ....... ; Rnn = E'(n)
Flag: /
Subroutine: /

-Synthetic registers M , N , O may be replaced by any unused data registers.
 

01  LBL "EULN2"
02  STO O
03  SIGN
04  STO 00
05  STO N
06  CHS
07  STO 01
08  CHS
09  LBL 01
10  RCL 00
11  STO M
12  ST+ N
13  CHS
14  LBL 02
15  RCL Y
16  RCL 00
17  +
18  ST* M
19  ST+ X
20  LASTX
21  -
22  ST* M
23  CLX
24  RCL N
25  R^
26  -
27  ST/ M
28  ST+ X
29  RCL 01
30  +
31  ST/ M
32  CLX
33  RCL IND Z
34  RCL M
35  *
36  -
37  DSE Y
38  GTO 02
39  STO IND N
40  RCL O
41  RCL N
42  X<Y?
43  GTO 01
44  X<>Y
45  SIGN
46  RCL IND L
47  CLA
48  END

( 79 bytes / SIZE nnn+1 but at least 003 )
 
 
      STACK        INPUTS      OUTPUTS
           X             n           E(n)
           L             /             n

Example:     -Evaluate:   E'(10) = E(20)

     10  XEQ "EULN2"  >>>  3.703711883 1014   ( in 36 seconds )  and E'(0) , E'(1) , ..... E'(10)  in registers R00 , R01 , ...... , R10.
 

2°) The Eulerian Numbers  A(n;k)

-The integers  A(n;k) are computed by:   A(n;k) =  Cn+10  kn  -  Cn+11  (k-1)n  + Cn+12  (k-2)n - .......... + (-1)k  Cn+1k  (k-k)n    ( 0 < k < n+1 )
-The first values are:

        1
        1   1
        1   4     1
        1  11   11     1
        1  26   66    26    1
        1  57  302  302  57  1
        .....................................

-Note that some authors define these numbers differently ( with k+1 instead of k )

Data Registers: /
Flags: /
Subroutines: /
 

01  LBL "EULN3"
02  CLA
03  STO O
04  SIGN
05  STO M
06  CLX
07  ENTER^
08  LBL 01
09  X<> L
10  RCL N
11  -
12  R^
13  Y^X
14  RCL M
15  *
16  +
17  RCL N
18  R^
19  -
20  1
21  ST+ N
22  -
23  ST* M
24  CLX
25  RCL N
26  ST/ M
27  RCL O
28  -
29  X<= 0?
30  GTO 01
31  RDN
32  CLA
33  END

( 55 bytes / SIZE 000 )
 
 
      STACK        INPUTS      OUTPUTS
           Y             n            n
           X             k         A(n;k)
           L             /            k

Example:     -Calculate  A(16;7)

    16  ENTER^
     7   XEQ "EULN3"  >>>   A(16;7) = 3.207483180 1012   ( in 8 seconds )
 

Reference:     "The Book of Numbers"  by John H. Conway  & Richard K. Guy

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall