hp41programs

Lobb Numbers

Lobb Numbers for the HP-41


Overview
 

 1°)  Program#1
 2°)  Logarithm of Lobb Numbers
 3°)  Multiprecision
 
 

1°)  Program#1
 

-Lobb numbers are defined by   Lm,n = [(2m+1)/(m+n+1)] (2n) ! / [ (m+n) ! (n-m) ! ]
 

Data Registers: /
Flags: /
Subroutines: /
 
 
 

 01 LBL "LOB"
 02 STO Z
 03 ST+ Z
 04 X<>Y
 05 -
 06 X=0?
 07 GTO 00
 08 LASTX
 09 ST+ X
 10 ISG X
 11 LBL 01
 12 RCL Z
 13 *
 14 RCL Y
 15 /
 16 DSE Z
 17 DSE Y
 18 GTO 01
 19 R^
 20 /
 21 LBL 00
 22 X=0?
 23 SIGN
 24 END

 
( 42 bytes / SIZE 000 )
 
 

      STACK        INPUTS      OUTPUTS
           Y             m              /
           X             n         Lm,n

  Where  m , n  are non-negative & m <= n

Examples:

   7   ENTER^
  12  XEQ "LOB"  >>>>  L7,12 = 31878

  12  ENTER^
  41     R/S       >>>>  L12,41 ~  5.822503535 E21                    ---Execution time = 9s---
 

Notes:

-We have  L0,n = Cn = Catalan number, so we can use this routine to calculate  Cn
-Here are the first values:

  n \ m |   0   1   2   3   4   5
     0   |   1
     1   |   1   1
     2   |   2   3   1
     3   |   5   9   5   1
     4   |  14 28 20  7   1
     5   |  42 90 75 35  9   1
 

2°)  Logarithm of Lobb Numbers
 

-If  Lm,n >  9.999999999 E99 , the previous routine will produce an OUT OF RANGE
-Taking the decimal logarithms will return a good result - but less accurate.
 

Data Registers: /
Flags: /
Subroutines: /
 
 
 

 01 LBL "LOGLB"
 02 STO Z
 03 ST+ Z
 04 X<>Y
 05 -
 06 X=0?
 07 GTO 00
 08 LASTX
 09 ST+ X
 10 1
 11 +
 12 LOG
 13 LBL 01
 14 RCL Z
 15 LOG
 16 +
 17 RCL Y
 18 LOG
 19 -
 20 DSE Z
 21 DSE Y
 22 GTO 01
 23 R^
 24 LOG
 25 -
 26 LBL 00
 27 END

 
( 46 bytes / SIZE 000 )
 
 

      STACK        INPUTS      OUTPUTS
           Y             m              /
           X             n     Log ( Lm,n )

  Where  m , n  are non-negative & m <= n

Example:

    128  ENTER^
    357  XEQ "LOGLB"   >>>>    Log L128,357 ~ 192.7815403                            ---Execution time = 2m57s---

-Whence  L128,357 ~ 6.04700  10192
 

3°)  Multiprecision
 

-This program employs  Lm-1,n = [(2m-1).(n+m+1)] / [(2m+1).(n-m+1)]  Lm,n  recursively, starting with   Ln,n = 1
 
 

Data Registers:   R00 = n

                              R01...................Rkk = Lm,n  by groups of 6 digits
Flags: /
Subroutines: /
 
 
 

 01 LBL "LOBM"
 02 STO 00
 03 STO N
 04 X<>Y
 05 -
 06 STO M
 07 1
 08 STO 01
 09 STO O
 10 X<>Y
 11 X=0?
 12 GTO 09
 13 GTO 01
 14 LBL 11
 15 RCL O
 16 STO P
 17 CLX
 18 LBL 12
 19 RCL IND P
 20 RCL Z
 21 *
 22 +
 23 RCL X
 24 PI
 25 INT
 26 ST+ X
 27 10^X
 28 MOD
 29 STO IND P 
 30 ST- Y
 31 X<> L
 32 /
 33 DSE P
 34 GTO 12
 35 X=0?
 36 RTN
 37 RCL O
 38  E6
 39 /
 40 1.002
 41 +
 42 REGMOVE
 43 SIGN
 44 ST+ O
 45 X<>Y
 46 STO 01
 47 RTN
 48 LBL 13
 49 RCL O
 50  E3
 51 /
 52 ISG X
 53 STO P
 54 CLX
 55 LBL 14
 56 RCL IND P 
 57 +
 58 RCL X
 59 RCL Z
 60 MOD
 61 ST- Y
 62 X<> L
 63 ST/ Y
 64 RDN
 65 STO IND P 
 66 X<> L
 67 PI
 68 INT
 69 ST+ X
 70 10^X
 71 *
 72 ISG P
 73 GTO 14 
 74 RTN
 75 LBL 01
 76 RCL N
 77 ST+ X
 78 DSE X
 79 XEQ 11
 80 RCL 00
 81 RCL N
 82 +
 83 1
 84 +
 85 XEQ 11
 86 RCL N
 87 ST+ X
 88 1
 89 +
 90 XEQ 13
 91 RCL 00
 92 RCL N
 93 -
 94 1
 95 +
 96 XEQ 13
 97 DSE N
 98 CLX
 99 DSE M
100 GTO 01       
101 LBL 09
102 RCL O
103 .1
104 %
105 ISG X
106 CLA
107 END

 
     ( 176 bytes / SIZE var. )
 
 

      STACK        INPUTS      OUTPUTS
           Y           m < n             /
           X               n        1.kkk

  And  Lm,n  is stored in R01 ....... Rkk  by groups of 6 digits

Example1:    Calculate  L7,12

    7   ENTER^
   12  XEQ "LOBM"   >>>>   1.002                                            ---Execution time = 22s---

   R01 = 0
   R02 = 31878            whence   L7,12 = 31878

Example1:    Calculate  L12,41

  12   ENTER^
  41      R/S       >>>>    1.005                                            ---Execution time = 4m40s---

  R01 = 0
  R02 = 5822
  R03 = 503531
  R04 = 254673
  R05 =   98000       whence   L12,41 = 5822503531254673098000
 

Notes:

-Register R01 often contains 0
-Add 0's on the left if there are less than 6 digits in R02 .... Rkk

-Synthetic register P is used, so don't stop this program.

-There is a risk of roundoff errors if  n > 5000.
-So, only use this program with n < 5000 - except if  n-m  is very small...
 
 
 

References:

[1]  https://en.wikipedia.org/w/index.php?title=Lobb_number&oldid=880934174
[2]  On-line Encyclopedia of Integer Sequences - www.oeis.org/A039599