hp41programs

Cyclical Calendars

Cyclical Calendars for the HP-41


Overview
 

 1°)  Solar Calendars
 2°)  Luni-Solar Calendars

  a)  Program#1
  b)  2 M-Code Routines
  c)  Program#2  ( with M-Code Routines )
  d)  Program#3  ( without M-Code Routines )
 

-These programs use some of the formulae given in references [1] &[2] in the chapter "Generic Cyclical Calendars" with  dY = dM = 0
-Paragraph 1 deals with single cycle calendars whereas paragraph 2 deals with double cycle calendars
-All these calendars are arithmetic calendars.

-They are similar to the old Hindu calendars, but the formulas are simpler and there is no lost days:
-In the Solar calendar, months have 30 or 31 days
-In the Luni-Solar calendars, months have 29 or 30 days and years have 12 or 13 months.

-Moreover, we use the tropical year ( the Hindu calendars are based on the sidereal year )
 

1°)  Solar Calendars
 

-This routine employs a mean tropical year = 292559 / 801 days ~  365.2421973  days
 

 Formulae:     Given a date   YYYY.MNDD  in the Gregorian calendar, we first compute the number of days N since 2000/01/01:
 

  •  Let  s = N + 1863079  ,  the date  yyyy.mndd  in the Solar Calendar is obtained as follows:

     y  = FLOOR ( 801 s / 292559 )
     m = 1 + [ FLOOR ( 6912 s / 292559 ) ] MOD 12
     d  = 1 + FLOOR [ s mod ( 292559 / 6912 ) ]

  •  Given a date   yyyy.mmdd   in the Solar calendar,

     N = Number of days since 2000/01/01 = CEIL [ -1863080 + y 292559 / 801 + (m-1) 292559 / 6912 + d ]
 

Data Registers:  R00-R01-R02:  temp
Flags: /
Subroutines:   "J2" & "D2"  ( cf "Julian and Gregorian Calendars for the HP-41" )
 
 

 01  LBL "GR-SC"
 02  XEQ "J2"
 03  1863079
 04  +
 05  801
 06  *
 07  STO Y
 08  292559
 09  STO 00        
 10  MOD
 11  STO 01
 12  -
 13  RCL 00 
 14  /
 15  X<> 01
 16  12
 17  *
 18  STO Y
 19  RCL 00
 20  MOD
 21  STO 02
 22  -
 23  RCL 00        
 24  /
 25  X<> 02
 26  9612
 27  /
 28  INT
 29  1
 30  ST+ 02
 31  ST+ Y
 32  %
 33  RCL 02
 34  +
 35  1
 36  %
 37  RCL 01 
 38  +
 39  RTN
 40  LBL "SC-GR"
 41  INT
 42  STO 01        
 43  LASTX
 44  FRC
 45   E2
 46  STO 00
 47  *
 48  INT
 49  STO 02
 50  LASTX
 51  FRC
 52  ST* 00
 53  RCL 01        
 54  2328
 55  *
 56  RCL 02 
 57  292559
 58  ST* Y
 59  -
 60  +
 61  ENTER^
 62  CHS
 63  9612
 64  STO 02
 65  MOD
 66  +
 67  RCL 02        
 68  /
 69  RCL 01 
 70  365
 71  *
 72  +
 73  RCL 00 
 74  +
 75  1863080
 76  -
 77  XEQ "D2"
 78  END

 
     ( 147 bytes / SIZE 003 )
 
 

           STACK            INPUT1          OUTPUT1           INPUT2         OUTPUT2
               X     YYYY.MNDDGr         yyyy.mnddSC         yyyy.mnddSC    YYYY.MNDDGr

 
Examples:

  -3101.0123   XEQ "GR-SC"   >>>>      0.0101      XEQ "SC-GR"  ( or simply  R/S )  >>>> -3101.0123
   1979.0716   XEQ "GR-SC"   >>>>   5080.0623   XEQ "SC-GR"  ( or simply  R/S )  >>>>   1979.0716
   2013.0210   XEQ "GR-SC"   >>>>   5114.0120   XEQ "SC-GR"  ( or simply  R/S )  >>>>   2013.0210

Notes:

-The years yyyy must be non-negative.
-If you want to use another origin, change lines 03 and 75.
 

2°)  Luni-Solar Calendars
 

     a)  Program#1
 

-This first program employs the same value for the mean tropical year:  292559 / 801 days ~  365.2421973  days
-And for the mean Lunar month:   23654 / 801 days ~  29.53058677  days

-A Full Moon occurs - theoretically - on the last day of each month.
-Of course, this is just an approximation since the duration of the lunations is not constant.
 

 Formulae:     Given a date   YYYY.MNDD  in the Gregorian calendar, we calculate the number of days N since 2000/01/01:
 

  •  Let  s = N + 1863079  ,  the date  yyyy.mndd  in the Luni-Solar Calendar is obtained as follows:

     With  m' = FLOOR ( 801 s / 23654 ) + 1

     y  = CEIL ( 23654 m' / 292559 ) - 1
     m = m' - [ FLOOR ( 292559 y / 23654 ) ]
     d  = s - CEIL [ ( m' - 1 ) ( 23654 / 801 ) ] + 1

  •  Given a date   yyyy.mmdd   in the Luni-Solar calendar,

      N = Number of days since 2000/01/01 = CEIL [ -1863080 + { FLOOR ( y 292559 / 23654 + (m-1) } 23654 / 801 + d ]
 

Data Registers:  R00 to R03:  temp
Flags: /
Subroutines:   "J2" & "D2"  ( cf "Julian and Gregorian Calendars for the HP-41" )
 
 

 01  LBL "GR-LS"
 02  XEQ "J2"
 03  1863079
 04  +
 05  STO Y
 06  801
 07  STO 01        
 08  *
 09  RCL X
 10  23654
 11  STO 02
 12  STO 03 
 13  MOD
 14  -
 15  ST+ 03
 16  ENTER^
 17  CHS
 18  RCL 01
 19  MOD
 20  +
 21  RCL 01 
 22  /
 23  -
 24  1
 25  ST+ Y
 26  %
 27  RCL 03
 28  ENTER^
 29  CHS
 30  292559
 31  STO 01        
 32  MOD
 33  +
 34  RCL 01
 35  -
 36  ENTER^
 37  STO 00
 38  RCL 02
 39  MOD 
 40  -
 41  RCL 03 
 42  -
 43  RCL 02
 44  /
 45  -
 46  1
 47  %
 48  RCL 00        
 49  RCL 01 
 50  /
 51  STO Z
 52  SIGN
 53  *
 54  +
 55  RTN
 56  LBL "LS-GR"
 57  STO 00
 58  INT
 59  292559
 60  *
 61  STO Y
 62  23654
 63  STO 01 
 64  MOD
 65  -
 66  RCL 00        
 67  ABS
 68  FRC
 69   E2
 70  *
 71  STO 00 
 72  INT
 73  RCL 01
 74  ST* Y
 75  -
 76  +
 77  ENTER^
 78  CHS
 79  801
 80  STO 01 
 81  MOD
 82  +
 83  RCL 01        
 84  /
 85  RCL 00 
 86  FRC
 87   E2
 88  *
 89  +
 90  1863080
 91  -
 92  XEQ "D2"
 93  END

 
   ( 160 bytes / SIZE 004 )
 
 

           STACK            INPUT1          OUTPUT1           INPUT2         OUTPUT2
               X     YYYY.MNDDGr         yyyy.mnddLS         yyyy.mnddLS    YYYY.MNDDGr

 
Examples:

  -3101.0123   XEQ "GR-LS"   >>>>      0.0101      XEQ "LS-GR"  ( or simply  R/S )  >>>> -3101.0123
   1979.0716   XEQ "GR-LS"   >>>>   5080.0722   XEQ "LS-GR"  ( or simply  R/S )  >>>>   1979.0716
   2012.1221   XEQ "GR-LS"   >>>>   5113.1308   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2012.1221
   2013.0210   XEQ "GR-LS"   >>>>   5114.0129   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2013.0210

Notes:

-Here, the years yyyy may be negative.
-If you want to use another origin, change lines 03 and 90.
 

Interesting Formulae
 

-The following formulae are useful ( they are also given in "Hindu Calendars for the HP-41" ):

    (x.y)  mod  b   =  [ x ( y mod b ) ] mod b       ( usefull when  x.y > 10^10 , provided  x.b < 10^10 )
    (x/y) mod (a/b) = [ (bx) mod (ay) ] / (by)

    floor (x/y) = ( x - x mod y ) / y
    ceil   (x/y) = [ x + (-x) mod y ] / y

    [ floor ( 12 x/y ) ] mod 12 = [ 12 r - ( 12 r ) mod y ] / y      with  r = x mod y
 

     b)  2 M-Code-Routines
 

-In calendrical calculations, we often have to compute  floor(y.z/x) or ceil(y.z/x)  where  x , y , z  are integers
-We can take advantage of the 13-digit routines to use these formulas even if  y.z > E10  provided  y.z/x  remains < E10
-FMD & CMD compute these functions.

-There is no check for alpha data, overflow and underflow.
 

084   "D"
00D  "M"
003   "C"     Ceil (y.z/x)
108   SETF 8
02B   JNC+05
084   "D"
00D  "M"
006   "F"     Floor (y.z/x)
104   CLRF 8
2A0  SETDEC
078   C=Z
10E   A=C ALL
0B8  C=Y
135   C=
060   A*C
0F8   C=X
128   L=C
10C  ?FSET 8
013   JNC+02
2BE  C=-C
000   NOP
269   C=
060   AB/C
2EE  ?C#0 ALL
10B   JNC+ 33d
130   LDI S&X
200   200h
306   ?A<C S&X
02F   JC+05
01A  A=0 M
006  A=0 S&X
02E  B=0 ALL
073  JNC+14d
130  LDI S&X
010  010h
306  ?A<C S&X
06B  JNC+13d
0A6  A<>C S&X
106   A=C S&X
35C  PT=12
3D4  PT=PT-1
266  C=C-1 S&X
3F3  JNC-02
2CA  ?B#0 PT <-
02B  JNC+05
02A  B=0 PT <-
35E  ?A#0 MS
009   C=
061   AB-1  if carry
04E  C= 0 ALL
025  C=
060  AB+C
2EE  ?C#0 ALL
023  JNC+04
10C  ?FSET 8
013  JNC+02
2BE  C=-C
0E8  X=C
046  C
270  =
038  T
068  Z=C
0A8  Y=C
3E0   RTN

( 64 words )
 
 

      STACK        INPUTS      OUTPUTS
           T             T             T
           Z             z             T
           Y             y             T
           X             x        F(x,y,z)
           L             L            x

   where  F(x,y,z) = Floor (y.z/x)   with  FMD
    and     F(x,y,z) =  Ceil  (y.z/x)   with  CMD

Examples:

  •  123456789  ENTER^
        12345        ENTER^
       654321       XEQ "FMD"  >>>>  FLOOR ( 123456789*12345 / 654321) = 2329245

  •  123456789  ENTER^
        12345        ENTER^
       654321       XEQ "CMD"  >>>>  CEIL ( 123456789*12345 / 654321) = 2329246

Notes:

-These routines also work with negative arguments
-We have used  ceil(x) = - floor(-x)
-The results may be wrong if  y.z  has more than 13 digits and / or if x is too large.
 

     c)  Program#2  ( With M-Code Routines )
 

-Focal programs are limited by 10-digit arithmetic, but with the 2 M-Code routines above FMD & CMD,
 we can use better approximations to the mean lunar month and the mean tropical year
-In the following routine:

         1 Lunar month = 334995 / 11344 days ~ 29.53058886  days
 and   1 tropical year / 1 lunar month = 774439 / 62615 ~ 12.36826639
which leads to  1 tropical year ~ 365.2421896 days
 

Data Registers:  R00 to R03:  temp
Flags: /
Subroutines:   "J2" & "D2"  ( cf "Julian and Gregorian Calendars for the HP-41" )
 
 

 01  LBL "GR-LS"
 02  XEQ "J2"
 03  1863079
 04  +
 05  STO Y
 06  11344
 07  STO 01 
 08  334995
 09  STO 02
 10  FMD
 11  STO 00        
 12  RCL 02      
 13  RCL 01
 14  CMD
 15  -
 16  1
 17  ST+ 00
 18  ST+ Y
 19  %
 20  RCL 00
 21  62615
 22  STO 01 
 23  774439
 24  STO 02        
 25  CMD
 26  1
 27  -
 28  STO 03
 29  RCL 02
 30  RCL 01
 31  FMD
 32  RCL 00
 33  X<>Y
 34  -
 35  +
 36  1
 37  %
 38  RCL 03        
 39  SIGN
 40  *
 41  RCL 03
 42  +
 43  RTN
 44  LBL "LS-GR"
 45  INT
 46  STO 01
 47  LASTX
 48  ABS
 49  FRC
 50   E2
 51  STO 00        
 52  *
 53  INT
 54  STO 02 
 55  LASTX
 56  FRC
 57  ST* 00
 58  RCL 01
 59  774439
 60  62615
 61  FMD
 62  RCL 02 
 63  +
 64  1
 65  -
 66  334995
 67  11344
 68  CMD
 69  RCL 00        
 70  +
 71  1863080
 72  -
 73  XEQ "D2"
 74  END

 
   ( 159 bytes / SIZE 004 )
 
 

           STACK            INPUT1          OUTPUT1           INPUT2         OUTPUT2
               X     YYYY.MNDDGr         yyyy.mnddLS         yyyy.mnddLS    YYYY.MNDDGr

 
Examples:

  -3101.0123   XEQ "GR-LS"   >>>>      0.0101      XEQ "LS-GR"  ( or simply  R/S )  >>>> -3101.0123
   1979.0716   XEQ "GR-LS"   >>>>   5080.0721   XEQ "LS-GR"  ( or simply  R/S )  >>>>   1979.0716
   2012.1221   XEQ "GR-LS"   >>>>   5113.1308   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2012.1221
   2013.0210   XEQ "GR-LS"   >>>>   5114.0129   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2013.0210

Notes:

-Here, the years yyyy may also be negative ( otherwise, delete lines 48-40-39-38 ).

-All these programs take the onset of the Kali-Yuga as origin i-e  -3101.0123 ( Gregorian Calendar )  -3101 = 3102 B.C.
-If you want to use another origin, change lines 03 and 71.
-For example, assuming Lord Jesus was born near the New Moon on  -1.1225 (???)  ( Gregorian ),
 replace 1863079 ( line 03 ) by  730492  and replace line 71 by 730493

-With these modifications, you will have a Christian Luni-Solar Calendar and, for instance:

    -1.1224     XEQ "GR-LS"   >>>>    -1.1329      XEQ "LS-GR"  ( or simply  R/S )  >>>>     -1.1224
    -1.1225     XEQ "GR-LS"   >>>>      0.0101      XEQ "LS-GR"  ( or simply  R/S )  >>>>     -1.1225
  2013.0210   XEQ "GR-LS"   >>>>   2013.0229   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2013.0210
 

     d)  Program#3  ( Without M-Code Routines )
 

-In fact, we can use the same approximations for the mean lunar months and solar years without using M-Code routines.
-We simply have to re-write some formulas and employ the RND function in FIX 0 mode.
-The "interesting formulae" given in paragraph 2°) a) are also very useful.
 

 Formula:     Given a date   YYYY.MNDD  in the Gregorian calendar, we calculate the number of days N since 2000/01/01:
 

  •  Let  s = N + 1863079  ,  the date  yyyy.mndd  in the Luni-Solar Calendar is obtained as follows:

     With  m' = FLOOR ( 11344 s / 334995 ) + 1

     d  = FLOOR [ s mod ( 334995 / 11344 ) ] + 1
     m = CEIL [ m' amod ( 774439 / 62615 ) ]                         where   y amod x = y mod x  if  y mod x # 0
     y  = CEIL ( 62615 m' / 774439 ) - 1                                    and    y amod x = x             if  y mod x = 0
 

Data Registers:  R00 to R03:  temp
Flags: /
Subroutines:   "J2" & "D2"  ( cf "Julian and Gregorian Calendars for the HP-41" )
 
 

  01  LBL "GR-LS"
  02  XEQ "J2"
  03  1863079
  04  +
  05  11344
  06  STO 01 
  07  *
  08  STO 00        
  09  334995
  10  STO 02 
  11  MOD
  12  ENTER^
  13  ST- 00
  14  RCL 01
  15  MOD
  16  -
  17  RCL 01
  18  /
  19  FIX 0
  20  RND
  21  1
  22  ST+ Y
  23  %
  24  RCL 00
  25  RCL 02 
  26  /
  27  RND
  28  1
  29  +
  30  62615
  31  STO 01        
  32  *
  33  STO 00
  34  774439
  35  STO 02
  36  MOD
  37  X=0?
  38  X<> L
  39  ENTER^
  40  CHS
  41  RCL 01 
  42  MOD
  43  +
  44  RCL 01
  45  /
  46  RND
  47  +
  48  1
  49  %
  50  RCL 00 
  51  ENTER^
  52  CHS
  53  RCL 02        
  54  MOD
  55  + 
  56  RCL 02
  57  / 
  58  RND
  59  1
  60  -
  61  STO Z
  62  SIGN
  63  *
  64  +
  65  FIX 4
  66  RTN
  67  LBL "LS-GR"
  68  INT
  69  STO 01
  70  LASTX
  71  ABS
  72  FRC
  73   E2
  74  STO 00 
  75  *
  76  INT
  77  STO 02        
  78  LASTX
  79  FRC
  80  ST* 00
  81  RCL 01
  82  774439
  83  * 
  84  STO Y
  85  62615
  86  STO 03
  87  MOD
  88  -
  89  RCL 03
  90  /
  91  FIX 0
  92  RND
  93  RCL 02 
  94  + 
  95  1
  96  -
  97  334995 
  98  *
  99  ENTER^
100  CHS
101  11344
102  STO 03        
103  MOD
104  +
105  RCL 03
106  /
107  RND
108  RCL 00
109 +
110  1863080
111  -
112  XEQ "D2"
113  FIX 4
114  END

 
    ( 197 bytes / SIZE 004 )
 
 

           STACK            INPUT1          OUTPUT1           INPUT2         OUTPUT2
               X     YYYY.MNDDGr         yyyy.mnddLS         yyyy.mnddLS    YYYY.MNDDGr

 
Examples:

  -5724.1214   XEQ "GR-LS"   >>>>  -2623.1201   XEQ "LS-GR"  ( or simply  R/S )  >>>> -5724.1214
  -3101.0123   XEQ "GR-LS"   >>>>      0.0101      XEQ "LS-GR"  ( or simply  R/S )  >>>> -3101.0123
   1979.0716   XEQ "GR-LS"   >>>>   5080.0721   XEQ "LS-GR"  ( or simply  R/S )  >>>>   1979.0716
   2012.1221   XEQ "GR-LS"   >>>>   5113.1308   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2012.1221
   2013.0210   XEQ "GR-LS"   >>>>   5114.0129   XEQ "LS-GR"  ( or simply  R/S )  >>>>   2013.0210

Notes:

-The results are of course identical to those of the previous version.
-In fact, several RND are superfluous in most cases.
 

References:

[1]  Nachum Dershowitz & Edward M. Reingold - "Calendrical Calculations" - Cambridge University Press - ISBN 978-0-521-70238-6
[2]  Nachum Dershowitz & Edward M. Reingold - "Indian Calendrical Calculations"