Calendrical calculations [3rd ed] 9780521885409, 9780521702386, 052188540X, 0521702380

A valuable resource for working programmers, as well as a fount of useful algorithmic tools for computer scientists, thi

438 111 18MB

English Pages XXIX-479 p.: ill.; 25 cm [515] Year 2007;2008

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Calendrical calculations [3rd ed]
 9780521885409, 9780521702386, 052188540X, 0521702380

Table of contents :
Cover......Page 1
Half-title......Page 3
Title......Page 7
Copyright......Page 8
Contents......Page 11
List of Frontispieces......Page 16
List of Figures......Page 17
List of Tables......Page 18
Abbreviations......Page 19
Mathematical Notations......Page 20
Preface......Page 23
Credits......Page 31
License and Limited Warranty and Remedy......Page 32
1 Calendar Basics......Page 37
1.1 Calendar Units and Taxonomy......Page 40
1.2 Fixed Day Numbers......Page 45
1.3 Negative Years......Page 48
1.4 Epochs......Page 50
1.5 Julian Day Numbers......Page 52
1.6 Mathematical Notation......Page 53
1.7 Search......Page 56
1.8 Dates and Lists......Page 58
1.9 A Simple Calendar......Page 60
1.10 Cycles of Days......Page 63
1.11 Simultaneous Cycles......Page 66
1.12 Cycles of Years......Page 68
1.13 Warnings about the Calculations......Page 75
References......Page 77
I ARITHMETICAL CALENDARS......Page 79
2.1 Structure......Page 81
2.2 Implementation......Page 84
2.3 Alternative Formulas......Page 88
2.4 The Zeller Congruence......Page 92
2.5 Holidays......Page 93
References......Page 96
3.1 Structure and Implementation......Page 99
3.2 Roman Nomenclature......Page 101
3.3 Roman Years......Page 105
3.4 Holidays......Page 106
References......Page 107
4.1 The Coptic Calendar......Page 109
4.2 The Ethiopic Calendar......Page 111
4.3 Holidays......Page 112
References......Page 113
5 The ISO Calendar......Page 115
Reference......Page 117
6.1 Structure and Implementation......Page 119
6.2 Holidays......Page 122
References......Page 123
7 The Hebrew Calendar......Page 125
7.1 Structure and History......Page 126
7.2 Implementation......Page 131
7.3 Holidays and Fast Days......Page 137
7.4 Personal Days......Page 141
7.5 Possible Days of Week......Page 144
References......Page 146
8 The Ecclesiastical Calendars......Page 149
8.1 Orthodox Easter......Page 150
8.2 Gregorian Easter......Page 152
8.4 Movable Christian Holidays......Page 155
References......Page 157
9.1 Structure and History......Page 159
9.2 The Solar Calendar......Page 162
9.3 The Lunisolar Calendar......Page 164
References......Page 170
10 The Mayan Calendars......Page 173
10.1 The Long Count......Page 174
10.2 The Haab and Tzolkin Calendars......Page 175
10.3 The Aztec Calendars......Page 181
References......Page 186
11.1 Structure and Implementation......Page 189
11.2 Conjunction Days......Page 195
References......Page 197
12.1 Single Cycle Calendars......Page 199
12.2 Double Cycle Calendars......Page 202
12.3 Summary......Page 204
II ASTRONOMICAL CALENDARS......Page 205
13 Time and Astronomy......Page 207
13.1 Position......Page 208
13.2 Time......Page 210
13.3 The Day......Page 215
13.4 The Year......Page 221
13.5 Astronomical Solar Calendars......Page 228
13.6 The Month......Page 229
13.7 Times of Day......Page 243
References......Page 250
14.1 Structure......Page 253
14.2 The Astronomical Calendar......Page 255
14.3 The Arithmetic Calendar......Page 257
14.4 Holidays......Page 262
References......Page 263
15.1 Structure......Page 265
15.2 Western Version......Page 267
15.3 The Future Bahá’í Calendar......Page 269
15.4 Holidays......Page 272
References......Page 273
16 The French Revolutionary Calendar......Page 275
16.1 The Original Form......Page 277
16.2 The Modified Arithmetical Form......Page 278
References......Page 280
17 The Chinese Calendar......Page 283
17.1 Solar Terms......Page 284
17.2 Months......Page 287
17.3 Conversions to and from Fixed Dates......Page 294
17.4 The Sexagesimal Cycle of Names......Page 296
17.5 Common Misconceptions......Page 299
17.6 Holidays......Page 300
17.7 Chinese Age......Page 302
17.8 Chinese Marriage Auguries......Page 303
17.9 The Japanese Calendar......Page 304
17.10 The Korean Calendar......Page 305
17.11 The Vietnamese Calendar......Page 307
References......Page 308
18 The Modern Hindu Calendars......Page 311
18.1 Hindu Astronomy......Page 317
18.2 Calendars......Page 323
18.3 Sunrise......Page 328
18.4 Alternatives......Page 331
18.5 Astronomical Versions......Page 335
18.6 Holidays......Page 339
References......Page 348
19.1 Calendar......Page 351
19.2 Holidays......Page 355
References......Page 358
20.1 Astronomical Easter......Page 361
20.2 Lunar Crescent Visibility......Page 362
20.3 The Observational Islamic Calendar......Page 364
20.4 The Classical Hebrew Calendar......Page 365
References......Page 367
Coda......Page 369
III APPENDICES......Page 371
A.1 Types......Page 373
A.2 Function Types......Page 378
A.3 Constant Types and Values......Page 392
B.1 Lisp Preliminaries......Page 397
B.2 Basic Code......Page 400
B.3 The Egyptian/Armenian Calendars......Page 402
B.5 The Gregorian Calendar......Page 403
B.6 The Julian Calendar......Page 408
B.7 The Coptic and Ethiopic Calendars......Page 411
B.8 The ISO Calendar......Page 412
B.9 The Islamic Calendar......Page 413
B.10 The Hebrew Calendar......Page 414
B.11 The Ecclesiastical Calendars......Page 421
B.12 The Old Hindu Calendars......Page 422
B.13 The Mayan Calendars......Page 424
B.14 The Balinese Pawukon Calendar......Page 428
B.15 Time and Astronomy......Page 431
B.16 The Persian Calendar......Page 447
B.17 The Bahá’í Calendar......Page 449
B.18 The French Revolutionary Calendar......Page 452
B.19 The Chinese Calendar......Page 453
B.20 The Modern Hindu Calendars......Page 460
B.21 The Tibetan Calendar......Page 471
B.22 Astronomical Lunar Calendars......Page 473
Reference......Page 475
C Sample Data......Page 477
References......Page 483
Index......Page 485
Envoi......Page 513
About the Cover......Page 515

Citation preview

ii

ii

CALENDRICAL CALCULATIONS, Third Edition This new edition of the popular calendar book expands the treatment of the previous edition to new calendar variants: generic cyclical calendars and astronomical lunar calendars, as well as the Korean, Vietnamese, Aztec, and Tibetan calendars. As interest grows in the impact of seemingly arbitrary calendrical systems upon our daily lives, this book frames the calendars of the world in a completely algorithmic form. Easy conversion among these calendars is a byproduct of the approach, as is the determination of secular and religious holidays. Calendrical Calculations makes accurate calendrical algorithms readily available. This book is a valuable resource for working programmers, as well as a fount of useful algorithmic tools for computer scientists. In addition, the lay reader will find the historical setting and general calendar descriptions of great interest. Beyond his expertise in calendars, Nachum Dershowitz is a leading figure in software verification in general and termination of programs in particular; he is an international authority on equational inference and term rewriting. Other areas in which he has made major contributions include program semantics and combinatorial enumeration. Dershowitz has authored or coauthored more than 100 research papers and several books and has held visiting positions at prominent institutions around the globe. He has won numerous awards for his research and teaching. He was born in 1951, and his graduate degrees in applied mathematics are from the Weizmann Institute in Israel. He is currently a professor of computer science at Tel Aviv University. Edward M. Reingold was born in Chicago, Illinois, in 1945. He has an undergraduate degree in mathematics from the Illinois Institute of Technology and a doctorate in computer science from Cornell University. Reingold was a faculty member in the Department of Computer Science at the University of Illinois at Urbana-Champaign from 1970–2000; he retired as a Professor Emeritus of Computer Science in December 2000 and moved to the Department of Computer Science at the Illinois Institute of Technology as professor and chair, an administrative post he held until 2006. His research interests are in theoretical computer science—especially the design and analysis of algorithms and data structures. A Fellow of the Association for Computing Machinery since 1995, Reingold has authored or coauthored more than 70 research papers and 10 books; his papers on backtrack search, generation of combinations, weight-balanced binary trees, and drawing of trees and graphs are considered classics. He has won awards for his undergraduate and graduate teaching. Reingold is intensely interested in calendars and their computer implementation; in addition to Calendrical Calculations and Calendrical Tabulations, he is the author and former maintainer of the calendar/diary part of GNU Emacs.

i

ii

Calendrical Calculations THIRD EDITION NACHUM DERSHOWITZ Tev Aviv University

EDWARD M. REINGOLD Illinois Institute of Technology

iii

CAMBRIDGE UNIVERSITY PRESS

Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paolo, Delhi Cambridge University Press 32 Avenue of the Americas, New York, NY 10013-2473, USA www.cambridge.org Information on this title: www.cambridge.org/9780521885409 © Cambridge University Press 2008 This publication is in copyright. Subject to statutory exception and to the provisions of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published 2008 Printed in the United States of America A catalog record for this publication is available from the British Library. Library of Congress Cataloging in Publication Data Dershowitz, Nachum. Calendrical calculations / Nachum Dershowitz, Edward M. Reingold. – 3rd ed. p. cm. Rev. ed. of: Calendrical calculations / Edward M. Reingold, Nachum Dershowitz. Millennium ed. Includes bibliographical references and index. ISBN 978-0-521-88540-9 (hardback) – ISBN 978-0-521-70238-6 (pbk.) 1. Calendar – Mathematics. I. Reingold, Edward M., 1945– II. Reingold, Edward M., 1945– Calendrical calculations. III. Title. CE12.D473 2007 529’.3–dc22 2007024347 ISBN ISBN

978-0-521-88540-9 hardback 978-0-521-70238-6 paperback

Cambridge University Press has no responsibility for the persistence or accuracy of URLs for external or third-party Internet Web sites referred to in this publication and does not guarantee that any content on such Web sites is, or will remain, accurate or appropriate.

iv

˙ ˙    ˙ ˙           ˙ 

v

vi

Contents

List of Frontispieces

page xii

List of Figures

xiii

List of Tables

xiv

Abbreviations

xv

Mathematical Notations

xvi

Preface

xix

Credits

xxvii

License and Limited Warranty and Remedy

xxviii

1 Calendar Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Calendar Units and Taxonomy 1.2 Fixed Day Numbers 1.3 Negative Years 1.4 Epochs 1.5 Julian Day Numbers 1.6 Mathematical Notation 1.7 Search 1.8 Dates and Lists 1.9 A Simple Calendar 1.10 Cycles of Days 1.11 Simultaneous Cycles 1.12 Cycles of Years 1.13 Warnings about the Calculations References I

4 9 12 14 16 17 20 22 24 27 30 32 39 41

ARITHMETICAL CALENDARS

2 The Gregorian Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.1 2.2

Structure Implementation

45 48 vii

viii

Contents

2.3 Alternative Formulas 2.4 The Zeller Congruence 2.5 Holidays References

52 56 57 60

3 The Julian Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.1 Structure and Implementation 3.2 Roman Nomenclature 3.3 Roman Years 3.4 Holidays References

63 65 69 70 71

4 The Coptic and Ethiopic Calendars . . . . . . . . . . . . . . . . . . . . 73 4.1 The Coptic Calendar 4.2 The Ethiopic Calendar 4.3 Holidays References

73 75 76 77

5 The ISO Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Reference

81

6 The Islamic Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 6.1 Structure and Implementation 6.2 Holidays References

83 86 87

7 The Hebrew Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 7.1 Structure and History 7.2 Implementation 7.3 Holidays and Fast Days 7.4 Personal Days 7.5 Possible Days of Week References

90 95 101 105 108 110

8 The Ecclesiastical Calendars . . . . . . . . . . . . . . . . . . . . . . . 113 8.1 Orthodox Easter 8.2 Gregorian Easter 8.3 Astronomical Easter 8.4 Movable Christian Holidays References

114 116 119 119 121

9 The Old Hindu Calendars . . . . . . . . . . . . . . . . . . . . . . . . 123 9.1 Structure and History 9.2 The Solar Calendar 9.3 The Lunisolar Calendar References

123 126 128 134

Contents

ix

10 The Mayan Calendars . . . . . . . . . . . . . . . . . . . . . . . . . . 137 10.1 The Long Count 10.2 The Haab and Tzolkin Calendars 10.3 The Aztec Calendars References

138 139 145 150

11 The Balinese Pawukon Calendar . . . . . . . . . . . . . . . . . . . . 153 11.1 Structure and Implementation 11.2 Conjunction Days References

153 159 161

12 Generic Cyclical Calendars . . . . . . . . . . . . . . . . . . . . . . . 163 12.1 Single Cycle Calendars 12.2 Double Cycle Calendars 12.3 Summary

163 166 168

II ASTRONOMICAL CALENDARS

13 Time and Astronomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 13.1 Position 13.2 Time 13.3 The Day 13.4 The Year 13.5 Astronomical Solar Calendars 13.6 The Month 13.7 Times of Day References

172 174 179 185 192 193 207 214

14 The Persian Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 14.1 Structure 14.2 The Astronomical Calendar 14.3 The Arithmetic Calendar 14.4 Holidays References

217 219 221 226 227

15 The Bah´a’´ı Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 15.1 Structure 15.2 Western Version 15.3 The Future Bah´a’´ı Calendar 15.4 Holidays References

229 231 233 236 237

16 The French Revolutionary Calendar . . . . . . . . . . . . . . . . . . 239 16.1 The Original Form 16.2 The Modified Arithmetical Form References

241 242 244

x

Contents

17 The Chinese Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . 247 17.1 Solar Terms 17.2 Months 17.3 Conversions to and from Fixed Dates 17.4 The Sexagesimal Cycle of Names 17.5 Common Misconceptions 17.6 Holidays 17.7 Chinese Age 17.8 Chinese Marriage Auguries 17.9 The Japanese Calendar 17.10 The Korean Calendar 17.11 The Vietnamese Calendar References

248 251 258 260 263 264 266 267 268 269 271 272

18 The Modern Hindu Calendars . . . . . . . . . . . . . . . . . . . . . . 275 18.1 Hindu Astronomy 18.2 Calendars 18.3 Sunrise 18.4 Alternatives 18.5 Astronomical Versions 18.6 Holidays References

281 287 292 295 299 303 312

19 The Tibetan Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . 315 19.1 Calendar 19.2 Holidays References

315 319 322

20 Astronomical Lunar Calendars . . . . . . . . . . . . . . . . . . . . . 325 20.1 Astronomical Easter 20.2 Lunar Crescent Visibility 20.3 The Observational Islamic Calendar 20.4 The Classical Hebrew Calendar References

325 326 328 329 331

Coda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 III APPENDICES

A Function, Parameter, and Constant Types . . . . . . . . . . . . . . . 337 A.1 A.2 A.3

Types Function Types Constant Types and Values

337 342 356

B Lisp Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 B.1

Lisp Preliminaries

361

Contents

B.2 Basic Code B.3 The Egyptian/Armenian Calendars B.4 Cycles of Days B.5 The Gregorian Calendar B.6 The Julian Calendar B.7 The Coptic and Ethiopic Calendars B.8 The ISO Calendar B.9 The Islamic Calendar B.10 The Hebrew Calendar B.11 The Ecclesiastical Calendars B.12 The Old Hindu Calendars B.13 The Mayan Calendars B.14 The Balinese Pawukon Calendar B.15 Time and Astronomy B.16 The Persian Calendar B.17 The Bah´a’´ı Calendar B.18 The French Revolutionary Calendar B.19 The Chinese Calendar B.20 The Modern Hindu Calendars B.21 The Tibetan Calendar B.22 Astronomical Lunar Calendars Reference

xi

364 366 367 367 372 375 376 377 378 385 386 388 392 395 411 413 416 417 424 435 437 439

C Sample Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 References

447

Index

449

Envoi

477

About the Cover

479

List of Frontispieces

Page from a 1998 Iranian synagogue calendar Two pages of Scaliger’s De Emendatione Temporum Swedish almanac for February, 1712 Profile of Julius Cæsar Calendar monument at Medinet Habu, Thebes Banker’s calendar from 1881 Illustration of Mohammed instituting the lunar calendar Sixteenth-century Hebrew astrolabe Finger calculation for the date of Easter Stone astrolabe from India Mayan New Year ceremonies Balinese plintangen Painting of Joseph Scaliger Kepler’s mystical harmony of the spheres Arabian lunar stations Shrine of the B¯ab on Mount Carmel Vend´emiaire by Laurent Guyot The 12 traditional Chinese calendrical animals Stone slab from Andhra Pradesh with signs of the zodiac Tibetan calendar carving Equation of time wrapped onto a cylinder Blue and white glazed jar from the reign of K¯ang X¯ı Page from a 1911 Turkish calendar Astronomical clock Japanese calendar chart dials First page of the index to Scaliger’s De Emendatione Temporum

xii

page xviii 0 44 62 72 78 82 88 112 122 136 152 162 170 216 228 238 246 274 314 324 332 336 360 440 448

List of Figures

1.1 2.1 7.1 8.1 9.1 10.1 10.2 13.1 13.2 13.3 13.4 13.5 13.6 17.1 17.2 17.3 18.1 18.2

Meaning of “day” in various calendars A corrective term in the Gregorian calendar calculation Molad of Nisan versus the actual moment of the new moon Distribution of Gregorian Easter dates Old Hindu lunisolar calendar Haab month signs Tzolkin name signs Standard time zones of the world as of 2006 DT − UT for −500–1600 DT − UT for 1600–2012 Equation of time Length of year Length of synodic month Possible numberings of the months on the Chinese calendar Hypothetical Chinese year Distribution of Chinese New Year dates Modern Hindu lunisolar calendar Hindu calculation of longitude

xiii

page 13 54 96 118 130 141 143 176 180 181 183 188 194 254 256 265 280 283

List of Tables

Abbreviations Mathematical notations 1.1 Mean year and month lengths on various calendars 1.2 Epochs for various calendars 1.3 Functions δ(d) for use in formula (1.62) 1.4 Constants describing the leap-year structure of various calendars 3.1 Roman nomenclature 8.1 Comparative dates of Passover and Easter, 9–40 C.E 9.1 Samvatsaras 9.2 Hindu solar (saura) months 11.1 Pawukon day names 11.2 The 210-day Balinese Pawukon calendar 12.1 Constants for generic arithmetic calendars 13.1 Arguments for solar-longitude 13.2 Solar longitudes and dates of equinoxes and solstices 13.3 Arguments for nth-new-moon 13.4 Arguments for nth-new-moon 13.5 Arguments for lunar-longitude 13.6 Arguments for lunar-latitude 13.7 Arguments for lunar-distance 13.8 Significance of various solar depression angles 14.1 Astronomical versus arithmetic Persian calendars, 1000–1800 A.P. 17.1 Solar terms of the Chinese year 18.1 Suggested correspondence of lunar stations and asterisms 18.2 Hindu sine table 18.3 The cycle of karan.as Sample data

xiv

page xv xvi 10 15 30 33 67 120 125 127 154 157 167 190 191 197 198 200 204 206 212 225 249 279 284 310 441

Abbreviations

Abbreviation

Meaning

Explanation

a.d. A.D. A.H.

Ante Diem Anno Domini (= C.E.) Anno Hegiræ

a.m. A.M.

JD

Ante meridiem Anno Mundi Anno Martyrum Anno Persico Anno Persarum Ab Urbe Condita Before Christ (= B.C.E.) Before the Common Era (= B.C.) Bahá’í Era Common Era (= A.D.) Ethiopic Era Julian Day number

K.Y.

Kali Yuga

m

R.D.

Meters Modified Julian Day number ´ Saka Era Post meridiem Rata Die

U.T.

Universal Time

V.E.

Vikrama Era

A.P. A.U.C. B.C. B.C.E. B.E. C.E. E.E.

MJD S.E.

p.m.

Prior day In the year of the Lord In the year of Mohammed’s emigration to Medina Before noon In the year of the world since creation Era of the Martyrs Persian year From the founding of the city of Rome

Elapsed days since noon on Monday, January 1, 4713 B.C.E. (Julian); sometimes J.A.D., Julian Astronomical Day “Iron Age” epoch of the traditional Hindu calendar Julian day number minus 2400000.5 Epoch of the modern Hindu calendar After noon Fixed date—elapsed days since the onset of Monday, January 1, 1 (Gregorian) Mean solar time at Greenwich, England (0◦ meridian), reckoned from midnight; sometimes G.M.T., Greenwich Mean Time Alternative epoch of the modern Hindu calendar

xv

Mathematical Notations

Notation

Name

x x round(x) x mod y x amod y gcd(x, y) lcm(x, y) |x| signum(x)

Floor Ceiling Round Remainder Adjusted mod Greatest common divisor Least common multiple Absolute value Sign

i ◦ j  k 

Angle

π

Pi

sin x cos x tan x arcsin x arccos x arctan x [l, u] (l, u) [l, u) ¬p p(i)  f (i)

Sine Cosine Tangent Arc sine Arc cosine Arc tangent Closed interval Open interval Half-open interval Logical negation

Meaning Largest integer not larger than x Smallest integer not smaller than x Nearest integer to x, that is, x + 0.5 x − yx/y y if x mod y = 0, x mod y otherwise x if y = 0, gcd(y, x mod y) otherwise x y/ gcd(x, y) Unsigned value of x −1 when x is negative, +1 when x is positive, 0 when x is 0 i degrees, j arc minutes, and k arc seconds Ratio of circumference of circle to diameter Sine of x, given in degrees Cosine of x, given in degrees Tangent of x, given in degrees Inverse sine of x, in degrees Inverse cosine of x, in degrees Inverse tangent of x, in degrees All real numbers x, l ≤ x ≤ u All real numbers x, l < x < u All real numbers x, l ≤ x < u True when p is false and vice versa The sum of f (i) for all integers i = k, k + 1, . . . , continuing only as long as the condition p(i) holds The largest integer ξ = µ, µ + 1, . . . such that ψ(µ), ψ(µ + 1), . . . , ψ(ξ ) are true The smallest integer ξ = µ, µ + 1, . . . such that ψ(ξ ) is true

Summation

i≥k

MAX {ψ(ξ )} ξ ≥µ

Maximum integer value

MIN {ψ(ξ )} ξ ≥µ

Minimum integer value

xvi

Mathematical Notations

Notation

Name

xvii

Meaning

p(µ,ν)

MIN {ψ(ξ )} ξ ∈[µ,ν]

Minimum value

f −1 (y, [a, b])

Function inverse

f1 f2 f3

···

Record formation

Rf

x0 , x1 , x2 , . . .

L [i] L [i...]

Field selection List formation Empty list List element Sublist

A||B x˜ {x0 , x1 , x2 , . . .} x∈S x ∈Z A∩B A∪B h:m:s i d j h k ml s bogus

Concatenation Vector Set formation Set membership Integer Set intersection Set union Time of day Duration of time Error

The value ξ such that ψ is false in [µ, ξ ) and is true in [ξ, ν]; see equation (1.30) on page 21 for details Approximate x in [a, b] such that f (x) = y The record containing fields f1 , f2 , f3 , . . . Contents of field f of record R The list containing x0 , x1 , x2 , . . . A list with no elements The ith element of list L; 0-based A list of the ith, (i + 1)st, and so on elements of list L The concatenation of lists A and B Indexed list of elements x0 , x1 , . . . The set containing x0 , x1 , x2 , . . . The element x is a member of set S The number x is an integer The intersection of sets A and B The union of sets A and B h hours, m minutes, and s seconds i days, j hours, k minutes, and l seconds Invalid calendar date

Page from an Iranian synagogue calendar for mid-March 1998 showing the Gregorian, Hebrew, Persian, and Islamic calendars.

xviii

Preface

No one has the right to speak in public before he has rehearsed what he wants to say two, three, and four times, and learned it; then he may speak. . . . But if a man . . . puts it down in writing, he should revise it a thousand times, if possible. —Moses Maimonides: The Epistle on Martyrdom (circa 1165)

This book has developed over a 20-year period during which the calendrical algorithms and our presentation of them have continually evolved. Our initial motivation was an effort by one of us (E.M.R.) to create Emacs-Lisp code that would provide calendar and diary features for GNU Emacs [8]; this version of the code included the Gregorian, Islamic, and Hebrew calendars (the Hebrew implemented by N.D.). A deluge of inquiries from around the globe soon made it clear to us that there was keen interest in an explanation that would go beyond the code itself, leading to our article [2] and encouraging us to rewrite the code completely, this time in Common Lisp [9]. The subsequent addition—by popular demand—of the Mayan and French Revolutionary calendars to GNU Emacs prompted a second article [6]. We received many hundreds of reprint requests for these articles. This response far exceeded our expectations and provided the impetus to write a book in which we could more fully address the multifaceted subject of calendars and their implementation. The subject of calendars has always fascinated us with its cultural, historical, and mathematical wealth, and we have occasionally employed calendars as accessible examples in introductory programming courses. Once the book’s plan took shape, our curiosity turned into obsession. We began by extending our programs to include other calendars such as the Chinese, Coptic, modern Hindu, and arithmetic Persian. Then, of course, the code for these newly added calendars needed to be rewritten, in some cases several times, to bring it up to the standards of the earlier material. We have long lost track of the number of revisions, and, needless to say, we could undoubtedly devote another decade to polishing what we have, tracking down minutiæ, and implementing and refining additional interesting calendars. As much as we might be tempted to, circumstances do not allow us to follow Maimonides’ dictum quoted above. In this book we give a unified algorithmic presentation for more than 30 calendars of current and historical interest: the Gregorian (current civil), ISO (International Organization for Standardization), Egyptian (and nearly identical Armenian), xix

xx

Preface

Julian (old civil), Coptic, Ethiopic, Islamic (Moslem) arithmetic and observational, modern Persian (both astronomical and arithmetic forms), Bahá’í (both present and future forms), Hebrew (Jewish) standard and observational, Mayan (long count, haab, and tzolkin) and two almost identical Aztec, Balinese Pawukon, French Revolutionary (both astronomical and arithmetic forms), Chinese (and nearly identical Japanese, Korean, and Vietnamese), old Hindu (solar and lunisolar), Hindu (solar and lunisolar), Hindu astronomical, and Tibetan. Easy conversion among these calendars is a natural outcome of the approach, as is the determination of secular and religious holidays. Our goal in this book is twofold: to give precise descriptions of each calendar and to make accurate calendrical algorithms readily available for computer use. The complete workings of each calendar are described in prose and in mathematical/ algorithmic form. Working computer programs are included in an appendix and are available on the World Wide Web (see following). Calendrical problems are notorious for plaguing software, as shown by the following examples: 1. Since the early days of computers, when storage was at a premium, programmers—especially COBOL programmers—usually allocated only two decimal digits for internal storage of years [4], thus billions of dollars were spent fixing untold numbers of programs to prevent their going awry on New Year’s Day of 2000 by interpreting “00” as 1900 instead of 2000. This became known as the “Y2K problem.” 2. In a Reuters story dated Monday, November 6, 2006, Irene Klotz writes, A computer problem could force NASA to postpone next month’s launch of shuttle Discovery until 2007 to avoid having the spaceship in orbit when the clock strikes midnight on New Year’s Eve. The shuttle is due to take off from the Kennedy Space Center in central Florida on December 7 on a 12day mission to continue construction of the half-built International Space Station. But if the launch is delayed for any reason beyond December 17 or 18, the flight likely would be postponed until next year, officials at the U.S. space agency said on Monday. To build in added cushion, NASA may move up the take off to December 6. “The shuttle computers were never envisioned to fly through a year-end changeover,” space shuttle program manager Wayne Hale told a briefing. After the 2003 accident involving space shuttle Columbia, NASA started developing procedures to work around the computer glitch. But NASA managers still do not want to launch Discovery knowing it would be in space when the calendar rolls over to January 1, 2007. The problem, according to Hale, is that the shuttle’s computers do not reset to day one, as ground-based systems that support shuttle navigation do. Instead, after December 31, the 365th day of the year, shuttle computers figure January 1 is just day 366. 3. Many programs err in, or simply ignore, the century rule for leap years on the Gregorian calendar (every 4th year is a leap year, except every 100th year, which is not, except every 400th year, which is):

Preface

xxi

(a) According to the New York Times of March 1, 1997, the New York City Taxi and Limousine Commission chose March 1, 1996, as the start date for a new, higher fare structure for cabs. Meters programmed by one company in Queens ignored the leap day and charged customers the higher rate on February 29. (b) According to the New Zealand Herald of January 8, 1997, a computer software error at the Tiwai Point aluminum smelter at midnight on New Year’s Eve caused more than A$ 1 million of damage. The software error was the failure to consider 1996 a leap year; the same problem occurred 2 hours later at Comalco’s Bell Bay smelter in Tasmania (which was 2 hours behind New Zealand). The general manager of operations for New Zealand Aluminum Smelters, David Brewer, said, “It was a complicated problem and it took quite some time to find the cause.” (c) Early releases of the popular spreadsheet program Lotus R 1-2-3 R treated 2000 as a nonleap year—a problem eventually fixed. However, all releases of Lotus R 1-2-3 R take 1900 as a leap year, which is a serious problem with historical data; by the time this error was recognized, the company deemed it too late to correct: “The decision was made at some point that a change now would disrupt formulas which were written to accommodate this anomaly” [10]. Excel R , part of Microsoft Office R , suffers from the same flaw; Microsoft acknowledges this error on its “Help and Support” web site, claiming that “the disadvantages of [correcting the problem] outweigh the advantages.” (d) According to Reuters (March 22, 2004), the computer display in the 2004 Pontiac Grand Prix shows the wrong day of the week because engineers overlooked the fact that 2004 is a leap year. 4. The calculation of holidays and special dates is a source of confusion: (a) According to the New York Times of January 12, 1999, for example, Microsoft Windows R 95, 98, and NT get the start of daylight saving time wrong for years, like 2001, in which April 1 is a Sunday; in such cases Windows has daylight saving time starting on April 8. An estimated 40 million to 50 million computers are affected, including some in hotels that are used for wake-up calls. (b) Microsoft Outlook R 98 has the wrong date for U. S. Memorial Day in 1999, giving it as May 24, 1999, instead of May 31, 1999. It gives wrong dates for U. S. Thanksgiving Day for 1997–2000. Outlook R 2000 corrected the Memorial Day error, but compounded the Thanksgiving Day error by giving two dates for Thanksgiving for 1998–2000. (c) Various programs calculate the Hebrew calendar by first determining the date of Passover using Gauss’s method [3] (see [7]); this method is correct only when sufficient precision is used, and thus such an approach often leads to errors. (d) Delrina Technology’s 1994 Daily Planner has 3 days for Rosh ha-Shanah. 5. At least one modern, standard source for calendrical matters, Parise [5], has many errors, some of which are presumably not due to sloppy editing, but to the algorithms used to produce the tables. For example, the Mayan date 8.1.19.0.0 is given

xxii

Preface

incorrectly as February 14, 80 (Gregorian) on page 290; the dates given on pages 325–327 for Easter for the years 1116, 1152, and 1582 are not Sundays; the epact for 1986 on page 354 is wrongly given as 20; Chinese New Year is wrong for many years; the epoch is wrong for the Ethiopic calendar, and hence that entire table is flawed. 6. Even the Astronomical Applications Department of the U. S. Naval Observatory is not immune to calendrical errors! They gave Sunday, April 9, 2028 and Thursday, March 29, 2029 for Passover on their web site http://aa.usno. navy.mil/faq/docs/passover.html, instead of the correct dates Tuesday, April 11, 2028 and Saturday, March 31, 2029, respectively. The site was corrected on March 10, 2004. Finally, the computer world is plagued with unintelligible code that seems to work by magic. Consider the following Unix script for calculating the date of Easter: 1 2 3 4 5

echo $* ’[ddsf[lfp[too early ]Pq]s@1583>@ ddd19%1+sg100/1+d3*4/12-sx8*5+25/5-sz5*4/lx-10-sdlg11*20+lz+lx-30% d[30+]s@0>@d[[1+]s@lg11@dld+7%-7+ [March ]smd[31-[April ]sm]s@31p]splpx’ | dc

We want to provide transparent algorithms to replace the gobbledegook that is so common. The algorithms presented also serve to illustrate all the basic features of nonstandard calendars: The Mayan calendar requires dealing with multiple, independent cycles and exemplifies the kind of reasoning often needed for calendrical-historical research. The French and Chinese calendars are examples in which accurate astronomical calculations are paramount. The Hindu calendar is an example of one in which the cycles (days of the month, months of the year) are irregular. We hope that in the process of reworking classical calendrical calculations and rephrasing them in the algorithmic language of the computer age we have also succeeded in affording the reader a glimpse of the beauty and individuality of diverse cultures past and present. The Third Edition Obiter dicimus priorem illam editionem huius ævi ingeniorum examen fuisse, ex qua non minus quid non possent, quam quid nollent scire, perspici potuit. [We say in passing that the first edition was a test for the minds of this age, from which both what they could not, and what they did not want to know could be seen.] —Joseph Justus Scaliger: De Emendatione Temporum, dedication to the second edition (1598)

After the first edition of the book was published in 1997 we continued to gather material, polish the algorithms, and keep track of errors. Because the second edition was to be published in the year 2000, some wag at Cambridge University Press dubbed it “The Millennium Edition,” and that title got used in prepublication catalogs, creating a fait accompli. The millennium edition was a comprehensive revision

Preface

xxiii

of the first edition. Since its publication, we have continued to gather new material and polish existing material; this third edition is, once again, a comprehensive revision. In preparing this third edition we have corrected all known errors (though, fortunately, no serious errors were ever reported in the Millennium Edition), added much new material, reworked and rearranged some of the material from the Millennium Edition to accommodate the new material, improved the robustness of the functions, added many new references, and made an enormous number of small improvements. Among the new material the reader will find a new section on Zeller’s congruence, a new chapter on generic cyclical calendars, a new section on which weekdays are possible for Hebrew calendar dates, and a greatly enlarged section on the determination of holidays on the modern Hindu calendars; implementations of the Aztec, Korean, Vietnamese, variants of the Hindu calendars, and Tibetan calendars have also been added. We made a major effort to improve the automatic typesetting of our functions and make the cross references more accurate. Calendrical Tabulations A man who possessed a calendar and could read it was an important member of the village community, certain to be widely consulted and suitably awarded. —K. Tseng: “Balinese Calendar,” Myths & Symbols in Indonesian Art (1991)

A companion volume by the authors, Calendrical Tabulations, is also available. It contains tables for easy conversion of dates and some holidays on the world’s major calendars (Gregorian, Hebrew, Islamic, Hindu, Chinese, Coptic/Ethiopic, and Persian) for the years 1900–2200. These tables were computed using the Lisp functions from Appendix B of the Millennium Edition and typeset directly from LATEX output produced by driver code. To insure that our calendar functions were not corrupted in making the changes necessary for the third edition of Calendrical Calculations, we recomputed the tables in Calendrical Tabulations with the functions from this third edition. Only the following immaterial discrepancies were found: • The depression angle used for astronomical sunrise for the Hindu calendar was changed slightly between editions (see page 298), causing an occasional one-day shift in leap days and expunged days. • Some constants in the astronomical code were updated, causing occasional oneminute differences in the rounded times of lunar phases.1 1

The following minor errors regarding lunar phases in Calendrical Tabulations should be noted: First, the dust jacket uses a negative image of the calendar pages; this has the effect of interchanging the full/new moon symbols and the first quarter/last quarter symbols visible in the Gregorian calendar at the middle bottom. Second, our rounding of times was incompatible with our method of determining a date, so that when a lunar phase (or equinox or solstice) occurs seconds before midnight, the date is correctly indicated, but the time is rounded up to midnight and shown as 0:00 instead of 24:00. Finally, when two lunar phases occur during the same week, the times given at the right are in reverse order.

xxiv

Preface

• The functions for computing Hindu holidays were improved, compared to those used in Calendrical Tabulations (these functions, given in Section 18.6, were not given in previous editions of Calendrical Calculations), so that now only nonleap days are indicated. I determined, therefore, to attempt the reformation; I consulted the best lawyers and the most skilled astronomers, and we cooked up a bill for that purpose. But then my difficulty began: I was to bring in this bill, which was necessarily composed of law jargon and astronomical calculations, to both of which I am an utter stranger. However, it was absolutely necessary to make the House of Lords think that I knew something of the matter; and also to make them believe that they knew something themselves, which they do not. For my own part, I could just as soon have talked Celtic or Sclavonian to them, as astronomy, and could have understood me full as well; so I resolved . . . to please instead of informing them. I gave them, therefore, only an historical account of calendars, from the Egyptian down to the Gregorian, amusing them now and then with little episodes. . . . They thought I was informed, because I pleased them; and many of them said, that I had made the whole story very clear to them; when, God knows, I had not even attempted it. —Letter from Philip Dormer Stanhope (Fourth Earl of Chesterfield, the man who in 1751 introduced the bill in Parliament for reforming the calendar in England) to his son, March 18, 1751 C.E. (Julian), the day of the Second Reading debate

The Cambridge University Press Web Site Unlike the Millennium Edition, this edition of Calendrical Calculations does not include a compact disc. Rather, it was decided to make the code available through a Cambridge University Press web site, http://www.cambridge.org/us/9780521702386

That web site contains links to files related to this book, including the Lisp code from Appendix C. The Authors’ Web Page The author has tried to indicate every known blemish in [2]; and he hopes that nobody will ever scrutinize any of his own writings as meticulously as he and others have examined the ALGOL report. —Donald E. Knuth: “The Remaining Trouble Spots in ALGOL 60,” Communications of the ACM (1967)

To facilitate electronic communication with our readers, we have established a home page for this book on the World Wide Web: http://www.calendarists.com

An errata document for the book is available via that home page. Try as we have, at least one error remains in this book.

Preface

xxv

Acknowledgments It is traditional for the author to magnanimously accept the blame for whatever deficiencies remain. I don’t. Any errors, deficiencies, or problems in this book are somebody else’s fault, but I would appreciate knowing about them so as to determine who is to blame. —Steven Skiena: The Algorithm Design Manual (1997)

Stewart M. Clamen wrote an early version of the Mayan calendar code. Parts of Section 2.3 are based on suggestions by Michael H. Deckers. Chapter 19 is based in part on the work of Svante Janson. Our preparation of the third edition was aided considerably by the help of Helmer Aslaksen, Rodolphe Audette, Armond Avanes, Haim Avron, Kfir Bar, Olivier Beltrami, Irvin Bromberg, Ananda Shankar Chakrabarty, Anoop Chaturvedi, Franz Corr, Nicholas J. Cox, John Cross, Ehssan Dabal, Michael H. Deckers, Idan Dershowitz, Robert H. Douglass, Donald W. Fausett, Winfried G¨orke, Edward Henning, Nicolas Herran, Burghart Hoffrichter, Peter Zilahy Ingerman, Svante Janson, Daher Kaiss, Richard P. Kelly, Richard M. Koolish, Jonathan Leffler, Alon Lerner, Yaaqov Loewinger, Andrew Main, Zhuo Meng, Ofer Pasternak, Andy Pepperdine, Tom Peters, Pal Singh Purewal, K. Ramasubramanian, Akshay Regulagedda, Nigel Richards, Denis B. Roegel, Theodore M. Rolle, Arthur J. Roth, Jeff Sagarin, Robert A. Saunders, Shriramana Sharma, S. Khalid Shaukat, G. Sivakumar, Michael R. Stein, Otto Stolz, Claus Tondering, Robert H. van Gent, Oscar van Vlijmen, Eiiti Wada, Helmut Wildmann, and Fariba Zarineba, who pointed out errors, suggested improvements, and helped gather materials. We also thank all those acknowledged in the prior editions for their help. The late Gerald M. Browne, Sharat Chandran, Shigang Chen, Jeffrey L. Copeland, Nazli Goharian, Mayer Goldberg, Shiho Inui, Yoshiyasu Ishigami, Howard Jacobson, Subhash Kak, Claude Kirchner, Sakai K¯o, Jungmin Lee, Nabeel Naser El-deen, the late Gerhard A. Nothmann, Trần Đức Ngọc, Roman Waupotitsch, Daniel Yaqob, and Afra Zomorodian helped us with various translations and foreign language fonts. Charles Hoot labored hard on the program for automatically transforming Lisp code into arithmetic expressions and provided general expertise in Lisp. Mitchell A. Harris helped with fonts, star names, and the automatic translation; Benita Ulisano was our tireless system support person; Marla Brownfield helped with various tables. Erga Dershowitz, Idan Dershowitz, Molly Flesner, Schulamith Halevy, Christine Mumm, Deborah Reingold, Eve Reingold, Rachel Reingold, Ruth Reingold, and Joyce Woodworth were invaluable in proofreading tens of thousands of dates, comparing our results with published tables. We are grateful to all of them. Portions of this book appeared, in a considerably less polished state, in our papers [2] and [6]. We thank John Wiley & Sons for allowing us to use that material here. THE END. This work was completed on the 17th or 27th day of May, 1618; but Book v was reread (while the type was being set) on the 9th or 19th of February, 1619. At Linz, the capital of Austria—above the Enns. —Johannes Kepler: Harmonies of the World

xxvi

Preface I have not always executed my own scheme, or satisfied my own expectations. . . . [But] I look with pleasure on my book however defective and deliver it to the world with the spirit of a man that has endeavored well. . . . When it shall be found that much is omitted, let it not be forgotten that much likewise has been performed. —Samuel Johnson: preface to his Dictionary

R.D.

732716 Tel Aviv, Israel Chicago, Illinois

N.D. E.M.R. References

[1] A. Birashk, A Comparative Calendar of the Iranian, Muslim Lunar, and Christian Eras for Three Thousand Years, Mazda Publishers (in association with Bibliotheca Persica), Costa Mesa, CA, 1993. [2] N. Dershowitz and E. M. Reingold, “Calendrical Calculations,” Software—Practice and Experience, vol. 20, no. 9, pp. 899–928, September 1990. [3] C. F. Gauss, “Berechnung des j¨udischen Osterfestes,” Monatliche Correspondenz zur Bef¨orderung der Erd- und Himmelskunde, vol. 5 (1802), pp. 435–437. Reprinted in Gauss’s Werke, Herausgegeben von der K¨oniglichen Gesellschaft der Wissenschaften, G¨ottingen, vol. VI, pp. 80–81, 1874; republished, Georg Olms Verlag, Hildesheim, 1981. [4] P. G. Neumann, “Inside Risks: The Clock Grows at Midnight,” Communications of the ACM, vol. 34, no. 1, p. 170, January 1991. [5] F. Parise, ed., The Book of Calendars, Facts on File, New York, 1982. [6] E. M. Reingold, N. Dershowitz, and S. M. Clamen, “Calendrical Calculations, Part II: Three Historical Calendars,” Software—Practice and Experience, vol. 23, no. 4, pp. 383– 404, April 1993. [7] I. Rhodes, “Computation of the Dates of the Hebrew New Year and Passover,” Computers & Mathematics with Applications, vol. 3, pp. 183–190, 1977. [8] R. M. Stallman, GNU Emacs Manual, 13th ed., Free Software Foundation, Cambridge, MA, 1997. [9] G. L. Steele, Jr., Common Lisp: The Language, 2nd ed., Digital Press, Bedford, MA, 1990. [10] Letter to Nachum Dershowitz from Kay Wilkins, Customer Relations Representative, Lotus Development Corporation, Cambridge, MA, April 21, 1992. La dernière chose qu’on trouve en faisant un ouvrage, est de savoir celle qu’il faut mettre la première. [The last thing one settles in writing a book is what one should put in first.] —Blaise Pascal: Pensées sur l’esprit et le style (1660)

Credits

Whoever relates something in the name of its author brings redemption to the world. —Midrash Tanh.uma (Numbers, 27)

Quote on page xix from Epistles of Maimonides: Crisis and Leadership, A. Halkin, trans., Jewish Publication Society, 1993; used with permission. Translation of Scaliger’s comment on the Roman calendar on page 63 is from A. T. Grafton, Joseph Scaliger: A Study in the History of Classical Scholarship, vol. II, Historical Chronography, Oxford University Press, Oxford, 1993; used with permission. Translation of Ptolemy III’s Canopus Decree on page 76 is from page 90 of R. Hannah, Greek & Roman Calendars, Gerald Duckworth & Co., Ltd., London, 2005; used with permission. Translation on page 90 of Scaliger’s comment on the Hebrew calendar (found on page 294 of Book 7 in the 1593 Frankfort edition of De Emendatione Temporum) is by H. Jacobson; used with permission. Translation of “The Synodal Letter” on page 113 (found in Gelasius, Historia Concilii Nicæni, book II, chapter xxxiii) from J. K. Fotheringham, “The Calendar,” The Nautical Almanac and Astronomical Ephemeris, His Majesty’s Stationery Office, London, 1931–1934; revised 1935–1938; abridged 1939–1941. Translation of the extract from Canon 6 of Gregorian reform on page 114 is by M. H. Deckers; used with permission. Translation of Quintus Curtius Rufus quotation on page 217 is from J. C. Rolfe, History of Alexander, Harvard University Press, Cambridge, MA, 1946. Letter on page 233 reprinted with permission.

xxvii

License and Limited Warranty and Remedy

The Functions (code, formulas, and calendar data) contained in this book were written by Nachum Dershowitz and Edward M. Reingold (the “Authors”), who retain all rights to them except as granted in the License and subject to the warranty and liability limitations below. These Functions are subject to this book’s copyright. In case there is cause for doubt about whether a use you contemplate is authorized, please contact the Authors. 1.

LICENSE.

The Authors grant you a license for personal use. This means that for strictly personal use you may copy and use the code and keep a backup or archival copy also. The Authors grant you a license for re-use within non-commercial, non-profit software provided prominent credit is given and the Authors’ rights are preserved. Any other uses, including, without limitation, allowing the code or its output to be accessed, used, or available to others, are not permitted. 2. WARRANTY. (a) The Authors and Publisher provide no warranties of any kind, either express or implied, including, without limiting the generality of the foregoing, any implied warranty of merchantability or fitness for a particular purpose. (b) Neither the Authors nor Publisher shall be liable to you or any third parties for damages of any kind, including without limitation, any lost profits, lost savings, or other incidental or consequential damages arising out of, or related to, the use, inability to use, or accuracy of calculations of the code and functions contained herein, or the breach of any express or implied warranty, even if the Authors or Publisher have been advised of the possibility of those damages. (c) The foregoing warranty may give you specific legal rights which may vary from state to state in the U.S.A. 3. LIMITATION OF LICENSEE REMEDIES. You acknowledge and agree that your exclusive remedy (in law or in equity), and Authors’ and Publisher’s entire liability with respect to the material herein, for any breach of representation or for any inaccuracy shall be a refund of the price of this book. Some States in the U.S.A. do not allow the exclusion or limitation of liability for incidental or consequential damages, and thus the preceding exclusions or limitation may not apply to you. xxviii

License and Limited Warranty and Remedy

4.

DISCLAIMER.

xxix

Except as expressly set forth above, Authors and Publisher: (a) make no other warranties with respect to the material and expressly disclaim any others; (b) do not warrant that the functions contained in the code will meet your requirements or that their operation shall be uninterrupted or error free; (c) license this material on an “as is” basis, and the entire risk as to the quality, accuracy, and performance herein is yours should the code or functions prove defective (except as expressly warranted herein). You alone assume the entire cost of all necessary corrections.

xxx

CALENDRICAL CALCULATIONS, Third Edition

xxxi

0

Two pages of Joseph Scaliger’s, De Emendatione Temporum (Frankfort edition, 1593), giving month names on many calendars. (Courtesy of the University of Illinois, Urbana, IL.)

1

Calendar Basics

A learned man once asked me regarding the eras used by different nations, and regarding the difference of their roots, that is, the epochs where they begin, and of their branches, that is, the months and years, on which they are based; further regarding the causes which led to such difference, and the famous festivals and commemoration-days for certain times and events, and regarding whatever else one nation practices differently from another. He urged me to give an explanation, the clearest possible, of all this, so as to be easily intelligible to the mind of the reader, and to free him from the necessity of wading through widely scattered books, and of consulting their authors. Now I was quite aware that this was a task difficult to handle, an object not easily to be attained or managed by anyone, who wants to treat it as a matter of logical sequence, regarding which the mind of the student is not agitated by doubt. —Ab¯u-Raih.a¯ n Muh.ammad ibn ’Ah.mad al-B¯ır¯un¯ı: ¯ ar al-B¯aqiyah ‘an al-Qur¯un al-Kh¯aliyah (1000) Al-Ath¯

Calendrical calculations are ubiquitous. Banks need to calculate interest on a daily basis. Corporations issue paychecks on weekly, biweekly, or monthly schedules. Bills and statements must be generated periodically. Computer operating systems need to switch to and from daylight saving time. Dates of secular and religious holidays must be computed for consideration in planning events. Most of these calculations are not difficult because the rules of our civil calendar (the Gregorian calendar) are straightforward. Complications begin when we need to know the day of the week on which a given date falls or when various religious holidays based on other calendars occur. These complications lead to difficult programming tasks—not often difficult in an algorithmic sense but difficult because it can be extremely tedious to delve, for example, into the complexities of the Hebrew calendar and its relation to the civil calendar. The purpose of this book is to present, in a unified, completely algorithmic form, a description of thirty calendars and how they relate to one another: the present civil calendar (Gregorian); the recent ISO commercial calendar; the old civil calendar (Julian); the ancient Egyptian calendar (and its Armenian equivalent); the Coptic and the (virtually identical) Ethiopic calendars; the Islamic (Moslem) calendar (both the arithmetical version and one based on calculated observability); 1

2

1 Calendar Basics

the (modern) Persian calendar (both astronomical and arithmetic forms); the Bahá’í calendar (both present Western and future forms); the Hebrew (Jewish) calendar, both its present arithmetical form and a speculative observational form; the three Mayan calendars and two (virtually identical) Aztec calendars; the Pawukon calendar from Bali; the French Revolutionary calendar (both astronomical and arithmetic forms); the Chinese calendar and (virtually identical) Japanese, Korean, and Vietnamese calendars; both the old (mean) and new (true) Hindu (Indian) solar and lunisolar calendars; and the Tibetan calendar. Information that is sufficiently detailed to allow computer implementation is difficult to find for most of these calendars because the published material is often inaccessible, ecclesiastically oriented, incomplete, inaccurate, based on extensive tables, overburdened with extraneous material, focused on shortcuts for hand calculation to avoid complicated arithmetic or to check results, or difficult to find in English. Most existing computer programs are proprietary, incomplete, or inaccurate. The need for such a secular, widely available presentation was made clear to us when we (primarily E.M.R., with contributions by N.D.), in implementing a calendar/diary feature for GNU Emacs [29], found difficulty in gathering and interpreting appropriate source materials that describe the interrelationships among the various calendars and the determination of the dates of holidays. Some of the calendars (Chinese, Japanese, Korean, Vietnamese, Hindu, and Tibetan) never had full algorithmic descriptions published in English. The calendar algorithms in this book are presented as mathematical function definitions in standard mathematical format; Appendix A gives the types (ranges and domains) of all functions and constants we use. To ensure correctness, all calendar functions were automatically typeset1 directly from the working Common Lisp [31] functions listed in Appendix B.2 In Appendix C we tabulate results of the calendar calculations for 33 sample dates; this will aid those who develop their own implemenations of our calendar functions. We chose mathematical notation as the vehicle for presentation because of its universality and easy convertibility to any programming language. We have endeavored to simplify the calculations as much as possible without obscuring the intuition. Many of the algorithms we provide are considerably more concise than previously published ones; this is particularly true of the arithmetic Persian, Hebrew, and old Hindu calendars. We chose Lisp as the vehicle for implementation because it encourages functional programming and has a trivial syntax, nearly self-evident semantics, historical durability, and wide distribution; moreover, Lisp was amenable to translation into ordinary mathematical notation. Except for a few short macros, the code uses 1

2

This has meant some sacrifice in the typography of the book; we hope readers sympathize with our decision. We provide these Lisp functions through a Cambridge University Press web site http://www.cambridge.org/us/9780521702386 under the terms of the License Agreements and Limited Warranty on page xxviii. Any errata are available over the World Wide Web at http://www.calendarists.com

1 Calendar Basics

3

only a very simple, side-effect-free subset of Lisp. We emphasize that our choice of Lisp should be considered irrelevant to readers, whom we expect to follow the mathematical notation used in the text, not to delve into Appendix B. It is not the purpose of this book to give a detailed historical treatment of the material, nor, for that matter, a mathematical one; our goal is to give a logical, thorough computational treatment. Thus, although we give much historical, religious, mathematical, and astronomical data to leaven the discussion, the focus of the presentation is algorithmic. Full historical/religious details and mathematical/astronomical underpinnings of the calendars can be pursued in the references. In the remainder of this chapter, we describe the underlying unifying theme of all the calculations along with some useful mathematical facts. The details of specific calendars are presented in subsequent chapters. Historically, the oldest of the calendars that we consider is the Egyptian (more than 3000 years old). The Chinese and Mayan calendars also derive from millennia-old calendars. Next are the classical (observation-based) Hebrew, the Julian (the roots of which date back to the ancient Roman empire), the Coptic and Ethiopic (third century), the current Hebrew (fourth century) and the old Hindu (fifth century), followed by the Islamic calendar (seventh century), the newer Hindu calendars (tenth century), the Persian and Tibetan calendars (eleventh century), the Gregorian modification to the Julian calendar (sixteenth century), the French Revolutionary calendar (eighteenth century), and the Bahá’í calendar (nineteenth century). Finally, the International Organization for Standardization’s ISO calendar and the arithmetic Persian calendar are of twentieth-century origin. For expository purposes, however, we present the Gregorian calendar first, in Part I, because it is the most popular calendar currently in use. Because the Julian calendar is so close in substance to the Gregorian, we present it next, followed by the very similar Coptic and Ethiopic calendars. Then we give the ISO calendar, which is trivial to implement and depends wholly on the Gregorian. The arithmetic Islamic calendar, which because of its simplicity is easy to implement, follows. Next, we present the Hebrew calendar, one of the more complicated and difficult calendars to implement, followed by a chapter on the computation of Easter, which is lunisolar like the Hebrew calendar. The ancient Hindu solar and lunisolar calendars are described next; these are simple versions of the modern Hindu solar and lunisolar calendars described in Part II. Next, the Mayan (and similar Aztec) calendars of historical interest, have several unique computational aspects, followed by the Balinese Pawukon calendar. All of the calendars described in Part I are “arithmetical” in that they operate by straightforward integer-based rules. We conclude Part I with a chapter describing generic arithmetic calendar schemata that apply to many of the calendars in this part. In Part II we present calendars that are controlled by irregular astronomical events (or close approximations to them), although these calendars may have an arithmetical component as well. Because the calendars in Part II require some understanding of astronomical events such as solstices and new moons, we begin Part II with a chapter introducing the needed topics and algorithms. We then give the modern Persian calendar in its astronomical and arithmetic forms followed by the Bahá’í

4

1 Calendar Basics

calendar, also in two versions: the Western, which depends wholly on the Gregorian, and the future version, which is astronomical. Next we describe the original (astronomical) and modified (arithmetic) forms of the French Revolutionary calendar. All of these calendars are computationally simple, provided certain astronomical values are available. Next is the Chinese lunisolar calendar and its Japanese, Korean, and Vietnamese versions. Then we describe the modern Hindu calendars, which are by far the most complicated of the calendars in this book. The Tibetan calendars are presented next. We conclude with some astronomical calendars based on the moon: the observational Islamic calendar, the classical Hebrew calendar, and the proposed astronomical calculation of Easter. As each calendar is discussed, we also provide algorithms for computing holidays based on it. In this regard we take the ethnocentric view that our task is to compute the dates of holidays in a given Gregorian year; there is clearly little difficulty in finding the dates of, say, Islamic New Year in a given Islamic year! In general we have tried to mention significant holidays on the calendars we cover, but have not attempted to be exhaustive and include all variations. The interested reader can find extensive holiday definitions in [12], [13], and [14]. The selection of calendars we present was chosen with two purposes: to include all common modern calendars and to cover all calendrical techniques. We do not give all variants of the calendars we discuss, but we have given enough details to make any calendar easy to implement.

1.1 Calendar Units and Taxonomy Teach us to number our days, that we may attain a wise heart. —Psalms 90:12

The sun moves from east to west, and night follows day with predictable regularity. This apparent motion of the sun as viewed by an earthbound observer provided the earliest time-keeping standard for humankind. The day is, accordingly, the basic unit of time underlying all calendars, but various calendars use different conventions to structure days into larger units: weeks, months, years, and cycles of years. Different calendars also begin their day at different times: the French Revolutionary day, for example, begins at true (apparent) midnight; the Islamic, Bahá’í, and Hebrew days begin at sunset; the Hindu day begins at sunrise. The various definitions of day are surveyed in Section 13.3. The purpose of a calendar is to give a name to each day. The mathematically simplest naming convention would be to assign an integer to each day; fixing day 1 would determine the whole calendar. The Babylonians had such a day count (in base 60). Such diurnal calendars are used by astronomers (see Section 13.3) and by calendarists (see, for example, Section 9.1); we use a day numbering in this book as an intermediate device for converting from one calendar to another (see the following section). Day-numbering schemes can be complicated by using a mixed-radix system in which the day number is given as a

1.1 Calendar Units and Taxonomy

5

sequence of numbers or names. The Mayans, for example, utilized such a method (see Section 10.1).3 Calendar day names are generally distinct, but this is not always the case. For example, the day of the week is a calendar, in a trivial sense, with infinitely many days having the same day name (see Section 1.10). A 7-day week is almost universal today. In many cultures, the days of the week were named after the 7 “wandering stars” (or after the gods associated with those heavenly bodies), namely, the Sun, the Moon, and the five planets visible to the naked eye—Mercury, Venus, Mars, Jupiter, and Saturn. In some languages—Arabic, Lithuanian, Portuguese, and Hebrew are examples—some or all of the days of the week are numbered, not named. In the Armenian calendar, for example, the days of the week are named as follows [12, vol. 3, p. 70]: Sunday Monday Tuesday Wednesday Thursday Friday Saturday

Kiraki (or Miashabathi) Erkoushabathi Erekhshabathi Chorekhshabathi Hingshabathi Urbath (or Vetsshabathi) Shabath

“Shabath” means “day of rest” (from the Hebrew), “Miashabathi” means the first day following the day of rest, “Erkoushabathi” is the second day following the day of rest, and so on. The Armenian Christian church later renamed “Vetsshabathi” as “Urbath,” meaning “to get ready for the day of rest.” Subsequently, they declared the first day of the week as “Kiraki” or “the Lord’s day.” Other cycles of days have also been used, including 4-day weeks (in the Congo), 5-day weeks (in Africa, in Bali, and in Russia in 1929), 6-day weeks (Japan), 8-day weeks (in Africa and in the Roman Republic), and 10-day weeks (in ancient Egypt and in France at the end of the eighteenth century; see page 240). The mathematics of cycles of days are described in Section 1.10. Many calendars repeat after one or more years. In one of the Mayan calendars (see Section 10.2), and in many preliterate societies, day names are recycled every year. The Chinese calendar uses a repeating 60-name scheme for days and years, and at one time used it to name months. An interesting variation in some calendars is the use of two or more cycles running simultaneously. For example, the Mayan tzolkin calendar (Section 10.2) combines a cycle of 13 names with a cycle of 20 numbers. The Chinese cycle of 60 names for years is actually composed of cycles of length 10 and 12 (see Section 17.4). The Balinese calendar takes this idea to an extreme; see Chapter 11. The mathematics of simultaneous cycles are described in Section 1.11. 3

It has been claimed that in equatorial regions, where the tropical year is not of paramount agricultural importance, arbitrary year lengths are more prevalent, such as the 210-day Balinese Pawukon calandar (Chapter 11) and the 260-day Mayan divine year (Section 10.2).

6

1 Calendar Basics

The notions of “month” and “year,” like the day, were originally based on observations of heavenly phenomena, namely the waxing and waning of the moon, and the cycle of seasons, respectively.4 Some calendars begin each month with the new moon, when the crescent moon first becomes visible (as in the Hebrew calendar of classical times and in the religious calendar of the Moslems today—see Sections 20.2 and 20.4); others begin the month at full moon (in northern India, for example)—see page 128. For calendars in which the month begins with the observed new moon, beginning the day at sunset is natural. Over the course of history, many different schemes have been devised for determining the start of the year. Some are astronomical, beginning at the autumnal or spring equinox, or at the winter or summer solstice. Solstices are more readily observable, either by observing when the midday shadow of a gnomon is longest (winter solstice in the northern hemisphere) or shortest (summer), or by noting the point in time when the sun rises or sets as far south at it does during the course of the year (which is winter in the northern hemisphere) or maximally north (summer). The ancient Egyptians began their year with the heliacal rising of Sirius—that is, on the day that the Dog Star Sirius (the brightest fixed star in the sky) can first be seen in the morning after a period during which the sun’s proximity to Sirius makes the latter invisible to the naked eye. The Pleiades (“Seven Sisters”) were used by the Maoris and other peoples for the same purpose. Various other natural phenomena have been used among North American tribes [3] to establish the onset of a new year such as harvests or the rutting seasons of certain animals. Calendars have an integral number of days in a month and an integral number of months in a year. However, these astronomical periods—day, month, and year— are incommensurate: their periods do not form integral multiples of one another. The lunar month is about 29 12 days long, and the solar year is about 365 14 days long. (Chapter 13 has precise definitions and values.) How exactly one coordinates these time periods and the accuracy with which they approximate their astronomical values are what differentiate one calendar from another. Broadly speaking, solar calendars—including the Egyptian, Armenian, Persian, Gregorian, Julian, Coptic, Ethiopic, ISO, French Revolutionary, and Bahá’í—are based on the yearly solar cycle, whereas lunar and lunisolar calendars—such as the Islamic, Hebrew, Hindu, Tibetan, and Chinese—take the monthly lunar cycle as their basic building block. Most solar calendars are divided into months, but these months are divorced from the lunar events; they are sometimes related to the movement of the sun through the 12 signs of the zodiac, notably in the Hindu solar calendars (see Chapter 18). Because observational methods suffer from vagaries of weather and chance, they have for the most part been supplanted by calculations. The simplest option is to approximate the length of the year, of the month, or of both. Originally, the Babylonian solar calendar was based on 12 months of 30 days each, overestimating the length of the month and underestimating the year. Such a calendar is easy to calculate, but each month begins at a slightly later lunar phase than the previous, and the 4

The lunar cycle formed the basis for palaeolithic marking of time; see [18] and [5].

1.1 Calendar Units and Taxonomy

7

seasons move forward slowly through the year. The ancient Egyptian calendar achieved greater accuracy by having 12 months of 30 days plus 5 extra days. Conversions for this calendar are illustrated in Section 1.9. To achieve better correlation with the motion of the moon, one can instead alternate months of 29 and 30 days. Twelve such months, however, amount to 354 days—more than 11 days short of the solar year. Almost every calendar in this book, and virtually all other calendars, incorporate a notion of “leap” year to deal with the cumulative error caused by approximating a year by an integral number of days and months.5 Solar calendars add a day every few years to keep up with the astronomical year. The calculations are simplest when the leap years are evenly distributed and the numbers involved are small; for instance, the Julian, Coptic, and Ethiopic calendars add 1 day every 4 years. Formulas for the evenly distributed case, such as when one has a leap year every fourth or fifth year, are derived in Section 1.12. The old Hindu solar calendar (Chapter 9) follows such a pattern; the arithmetical Persian calendar almost does (see Chapter 14). The Gregorian calendar, however, uses an uneven distribution of leap years but a relatively easy-to-remember rule (see Chapter 2). The modified French Revolutionary calendar (Chapter 16) included an even more accurate but uneven rule. Most lunar calendars incorporate the notion of a year. Purely lunar calendars may approximate the solar year with 12 lunar months (as does the Islamic), though this is about 11 days short of the astronomical year. Lunisolar calendars invariably alternate 12- and 13-month years, according either to some fixed rule (as in the Hebrew calendar) or to an astronomically determined pattern (Chinese and modern Hindu). The so-called Metonic cycle is based on the observation that 19 solar years contain almost exactly 235 lunar months. This correspondence, named after the Athenian astronomer Meton (who published it in 432 B.C.E.) and known much earlier to ancient Babylonian and Chinese astronomers, makes a relatively simple and accurate fixed solar/lunar calendar feasible. The 235 = 12 × 12 + 7 × 13 months in the cycle are divided into 12 years of 12 months and 7 leap years of 13 months. The Metonic cycle is used in the Hebrew calendar (Chapter 7) and for the ecclesiastical calculation of Easter (Chapter 8). The more precise the mean year, the larger the underlying constants must be. For example the Metonic cycle is currently accurate to within 6.5 minutes a year, but other lunisolar cycles are conceivable: 3 solar years are approximately 37 lunar months with an error of 1 day per year; 8 years are approximately 99 months with an error of 5 hours per year; 11 years are approximately 136 months with an error of 3 hours per year; and 334 years are 4131 months with an error of 7.27 seconds per year. The old Hindu calendar is even more accurate, comprising 2,226,389 months in a cycle of 180,000 years (see Chapter 9) to which the leap-year formulas of Section 1.12 apply, and errs by fewer than 8 seconds per year. The placement of leap years must make a trade-off between two conflicting requirements: Small constants defining a simple leap year rule of limited accuracy or greater accuracy at the expense of larger constants, as the examples in the last 5

See [2, pp. 677–678] for a discussion of the etymology of the term “leap.”

8

1 Calendar Basics

paragraph suggest. The choice of the constants is aided by taking the continued fraction (see [16]) of the desired ratio and choosing among the convergents (where to stop in evaluating the fraction). In the case of lunisolar calendars, the solar year is about 365.24244 days, while the lunar month is about 29.53059 days, so we write 365.24244 = 12 + 29.53059

1

.

1

2+

1

1+

1

2+

1

1+

1

1+ 18 +

1 3 + ···

By choosing further and further stopping points, we get better and better approximations to the true ratio. For example, 12 +

1 2+

1

=

37 , 3

1

while 1

12 + 2+

=

1 1+

99 , 8

1 2

1

12 +

=

1

2+

136 , 11

1

1+

2+

1 1

and 1

12 +

=

1

2+

235 ; 19

1

1+ 2+

1 1+

1 1

these are the ratios of the previous paragraph. Not all approximations must come from continued fractions, however: 84 years are approximately 1039 lunar months with an error of 33 minutes per year, but this is not one of the convergents.

1.2 Fixed Day Numbers

9

Continued fractions can be used to get approximations to solar calendars too. The number of days per solar year is about 365.242177 which we can write as 1

365.242177 = 365 +

.

1

4+

1

7+

1

1+

1

2+ 1+

1 5 + ···

The convergents are 1/4 (the basis of the Julian, Coptic, and Ethiopic calendars), 7/29, 8/33 (possibly used for an ancient Persian calendar), 23/95, and 31/128 (used in our implementation of the arithmetical Persian calendar—see Chapter 14). Table 1.1 compares the values for the mean length of the year and month as implemented by the various solar, lunar, and lunisolar calendars in this book. The true values change over time, as explained in Chapter 13. 1.2 Fixed Day Numbers May those who calculate a fixed date. . . perish.6 —Morris Braude: Conscience on Trial: Three Public Religious Disputations between Christians and Jews in the Thirteenth and Fifteenth Centuries (1952)

Over the centuries, human beings have devised an enormous variety of methods for specifying dates.7 None are ideal computationally, however, because all have idiosyncrasies resulting from attempts to coordinate a convenient human labeling with lunar and solar phenomena. For a computer implementation, the easiest way to reckon time is simply to count days: Fix an arbitrary starting point as day 1 and specify a date by giving a day number relative to that starting point; a single 32-bit integer allows the representation of more than 11.7 million years. Such a reckoning of time is, evidently, extremely awkward for human beings and is not in common use, except among astronomers, who use julian day numbers to specify dates (see Section 1.5), and calendarists, who use them to facilitate conversion among calendars—see equation (9.2) for the ancient Indian method; for a more modern example, see [27]. The day-count can 6

7

This is a loose translation of a famous dictum from the Babylonian Talmud Sanhedrin 97b. The omitted words from Braude’s translation (page 112 of his book) are “for the coming of the Messiah.” The exact Talmudic wording is “Blasted be the bones of those who calculate the end.” The best reference is still Ginzel’s monumental three-volume work [7], in German. An exceptional survey can be found in the Encyclopædia of Religion and Ethics [12, vol. III, pp. 61–141 and vol. V, pp. 835–894]. Useful, modern summaries are [2], [4], [26], and [30]; [2] and [26] have an extensive bibliographies. The incomparable tables of Schram [27] are the best available for converting dates by hand, whereas those of Parise [21] are best avoided because of an embarrassingly large numbers of errors.

10

1 Calendar Basics Table 1.1: Length in days of mean year on solar and lunisolar calendars and length in days of mean lunar month on lunar and lunisolar calendars. Year length is given in italics when the sidereal, rather than tropical, value is intended. These may be compared with the astronomical values given for various millennial points—in solar days current at the indicated time. No values are given here for the Chinese, astronomical Persian, observational Islamic, future Bahá’í, and (original) French Revolutionary calendars because they are selfadjusting.

Astronomical

Calendrical

Calendar (or year) Egyptian Mayan (haab) Julian/Coptic/Ethiopic Hebrew Easter (Orthodox) Islamic (Arithmetic) Hindu (Arya) Hindu (S¯urya) Tibetan (Phugpa) Gregorian Easter (Gregorian) French (Arithmetic) Persian (Arithmetic) Year −1000 Year 0 Year 1000 Year 2000 Year 3000

Mean Year (days) 365 365 365.25 365.24682 365.25 365.25868 365.25876 365.27065 365.2425 365.2425 365.24225 365.24220 365.24257 365.24244 365.24231 365.24218 365.24204

Mean Month (days)

29.530594 29.530851 29.530556 29.530582 29.530588 29.530587 29.530587

29.530598 29.530595 29.530591 29.530588 29.530584

be augmented by a fractional part to give a specific moment during the day; for example, noon on a day i, an integer, would be specified by i + 0.5. We have chosen midnight at the onset of Monday, January 1, 1 (Gregorian) as our fixed date 1, which we abbreviate as R.D.8 1, and count forward day-by-day from there. Of course, this is anachronistic because there was no year 1 on the Gregorian calendar—the Gregorian calendar was devised only in the sixteenth century—thus by January 1, 1 (Gregorian) we mean the day we get if we extrapolate backwards from the present; this day turns out to be Monday, January 3, 1 C.E.9 (Julian); this too is anachronistic. We call an R.D. that has a fractional part giving the time of day a “moment.” The date Monday, January 1, 1 (Gregorian), though arbitrarily chosen as our starting point, has a desirable characteristic: It is early enough that almost all dates of interest are represented by positive integers of moderate size. We have been careful to write our functions in such a way that all dependencies on this choice of 8 9

Rata Die, or fixed date. We are indebted to Howard Jacobson for this coinage. Common Era, or A.D.

1.2 Fixed Day Numbers

11

starting point are explicit. To change the origin of the calculations we have provided a function rd (t)

def

=

t − epoch

(1.1)

where epoch

=

0

that defines the origin, epoch. Changing this definition to epoch = 710347, for example, would make Monday, November 12, 1945 (Gregorian) the starting point. We should thus think of the passage of time as a sequence of days numbered . . . , −2, −1, 0, 1, 2, 3, . . . , which the various human-oriented calendars label differently. For example, R.D. 710,347 is called • Monday, November 12, 1945, on the Gregorian calendar. • October 30, 1945 C.E., on the Julian calendar, which would be called ante diem III Kalendas Novembris in the Roman nomenclature. • Julian day number 2,431,772 (at noon). • Modified julian day number 31,771. • Month 7, day 10, 2694, on the ancient Egyptian calendar. • Tr¯e 5, 1395, on the Armenian calendar. • Day 1 of week 46 of year 1945, on the ISO calendar. • Ath¯or 3, 1662, Era of the Martyrs, on the Coptic calendar (until sunset). • H – ed¯ar 3, 1938, on the Ethiopic calendar (until sunset). • Dhu al-H.ijja 6, 1364, on the arithmetic and observational Islamic calendars (until sunset). • Kislev 7, 5706, on the Hebrew calendar (until sunset). • Kislev 6, 5706, on the observational Hebrew calendar (until sunset). • 12.16.11.16.9 in the Mayan long count. • 7 Zac on the Mayan haab calendar. • 11 Muluc on the Mayan tzolkin calendar. • Atlcahualo 11 on the Aztec xihuitl calendar. • 9 Ozomatli on the Aztec tonalpohualli calendar. • Lunag, Pepet, Pasah, Sri, Pon, Tungleh, Coma of Gumbreg, Ludra, Urungan, Pati on the Balinese Pawukon calendar. • Tul¯a 29, 5046, Kali Yuga Era (elapsed) on the old Hindu solar calendar (after sunrise). • Day 8 in the bright half of K¯artika, 5046, Kali Yuga Era (elapsed) on the old Hindu lunisolar calendar (after sunrise). • Ab¯an 21, 1324, on the modern Persian arithmetic and astronomical calendars. • The day of Asm¯a’, of the month of Qudrat, of the year Abad, of the sixth Vahid, of the first Kull-i-Shay on the Bahá’í calendar (until sunset). • Décade III, Primidi de Brumaire de l’Année 154 de la République on the arithmetical and astronomical French Revolutionary calendars. • Day 8 of the tenth month in the year Yˇıyˇou on the Chinese calendar.

12

1 Calendar Basics

´ • K¯artika 27, 1867, Saka Era (elapsed) on the modern and astronomical Hindu solar calendars (after sunrise). • Day 7 in the bright half of K¯artika, 2002, Vikrama Era (elapsed) on the modern and astronomical Hindu lunisolar calendars (after sunrise). • Day 7 of the tenth month, 2072 on the Tibetan calendar. All that is required for calendrical conversion is to be able to convert each calendar to and from this fixed calendar. Because some calendars begin their day at midnight and others at sunrise or sunset, We fix the time of day at which conversions are performed to be noon. Figure 1.1 shows the relationships of various calendar’s times for the beginning and ending of days. We give, in subsequent chapters, functions to do the conversions for the thirty calendars. For each calendar x, we write a function fixed-from-x(x-date) to convert a given date x-date on that calendar to the corresponding R.D. date, and a function x-from-fixed(date) to do the inverse operation, taking the R.D. date and computing its representation in calendar x. One direction is often much simpler to calculate than the other, and occasionally we resort to considering a range of possible dates on calendar x, searching for the one that converts to the given R.D. date (see Section 1.7). To convert from calendar x to calendar y, one need only compose the two functions: y-from-x(x-date)

def

=

y-from-fixed(fixed-from-x(x-date)) Each calendar has an epoch, the first day of the first year of that calendar (see Section 1.4). We assign an integer R.D. date to an epoch, even if the calendar in question begins its days at a time other than midnight. Such assignment is done as per Figure 1.1. All of the algorithms given in this book give mathematically sensible results for dates prior to the calendar’s epoch. 1.3 Negative Years Quis enim potest intelligere dies et tempora et annos, nisi per numerum? [Who can understand days and seasons and years, save by number?] —attributed to the Venerable Bede: De Computo Dialogus

We cannot avoid dealing with dates before the common era. For example, the Hebrew calendar begins at sunset on Sunday, September 6, −3760 (Gregorian); scholarly literature is replete with such statements. Thus, to aid the reader, we now explain how years before the common era are conventionally handled. This convention is often a source of confusion, even among professional historians. It is computationally convenient, and mathematically sensible, to label years with the sequence of integers . . . , −3, −2, −1, 0, 1, 2, 3, . . . so that year 0 precedes year 1; we do this when extrapolating backward on the Gregorian calendar so that the same leap-year rule will apply based on divisibility by 4, 100, and 400 (see

13 Midnight R.D. i

Noon R.D. i + 0.5

Fixed date i

Gregorian/Julian/Persian/Chinese day

Midnight i+ 1 R.D.

Noon i + 1.5 R.D.

Figure 1.1: Meaning of “day” in various calendars. Conversion from a date on a calendar to an R.D. date is done as of noon; the rectangles indicate the day of a calendar that gets converted to R.D. i. For example, the Hebrew date corresponding to fixed date i is the Hebrew day that begins at sunset of the evening of fixed date i − 1 and ends at sunset of the evening of fixed date i. Similarly, the Hindu date corresponding to fixed date i is the Hindu day that begins at sunrise in the morning of fixed i and ends at sunrise of the morning of fixed date i + 1. The JD corresponding to fixed date i begins at noon of fixed date i and ends at noon of fixed date i + 1.

Noon i − 0.5

R.D.

JD (J.A.D.)

Hindu/Ancient Egyptian day

Hebrew/Islamic/Coptic/Ethiopic Bahá’í/Ecclesiastical day

Nautical day

14

1 Calendar Basics

Chapter 2). However, on the Julian calendar it is customary to refer to the year preceding 1 C.E. as 1 B.C.E.,10 counting it as a leap year in accordance with the every-fourth-year leap-year rule of the Julian calendar. Thus, the beginning of the Hebrew calendar can alternatively be referred to as sunset October 6, 3761 B.C.E. (Julian). To highlight this asymmetry, in the prose of this book we append “B.C.E.” only to Julian calendar years, reserving the minus sign for Gregorian calendar years. Care must therefore be taken when doing arithmetic with year numbers. For n ≥ 0, the rough present-day alignment of the Julian and Gregorian calendars gives year −n (Gregorian) ≈ year (n + 1) B.C.E. (Julian), and, for n ≥ 1, year n (Gregorian) ≈ year n C.E. (Julian). However, as an internal computer representation of B.C.E. Julian years in the Lisp functions in Appendix B and sample data in Appendix C, we also use negative numbers with the convention that year n B.C.E. (Julian) is represented as −n. 1.4 Epochs Epochæ celebriores, astronomis, historicis, chronologis, Chataiorvm, Syro-Græcorvm Arabvm, Persarvm, Chorasmiorvm, usitatæ [Famous epochs customarily in use by astronomers, historians, chronologists, Hittites, Syrian-Greeks, Arabs, Persians, and Chorasmians] —Title of John Greaves’ Latin/Persian edition (1650) of a work by the fourteenth-century Persian astronomer Ulugh Beg, grandson of Tamerlane

Every calendar has an epoch or starting date. This date is virtually never the date the calendar was adopted but rather a hypothetical starting point for the first day. For example, the Gregorian calendar was devised and adopted in the sixteenth century, but its epoch is January 1, 1. Because days begin at different hours on different calendars, we follow the convention that a calendar’s epoch is the onset of the (civil) day containing the first noon (see Figure 1.1). For example, we take midnight at the onset of September 7, −3760 (Gregorian) as the epoch of the Hebrew calendar, which was codified in the fourth century, though the first Hebrew day began at sunset the preceding evening. For calendars like the Chinese or Balinese Pawukon, in which cycles are unnumbered, the choice of epoch is arbitrary; the first day of any cycle can be used. Table 1.2 gives the epochs of the calendars discussed in this book. With the exception of Julian day number, we express the epochs of all the calendars as integer R.D. dates, that is, the integer R.D. day number at noon of the first day of the calendar (again, see Figure 1.1). Thus, the epoch for the Gregorian calendar is R.D. 1, and that for the Hebrew calendar is R.D. −1, 373, 427. Using this form of calendar epochs is convenient because R.D. 10

d = (d − calendar epoch) days since the start of that calendar.

Before the Common Era, or B.C.

1.4 Epochs Table 1.2: Epochs for various calendars Calendar

Epoch (R.D.)

Julian day number

−1,721,424.5

Hebrew

−1,373,427

Mayan

−1,137,142

Hindu (Kali Yuga)

−1,132,959

Chinese

−963,099

Egyptian

−272,787

Tibetan

−46,410 −1

Julian Gregorian

1

ISO

1

Ethiopic

2796

Coptic

103,605

Armenian

201,443

Persian

226,896

Islamic

227,015

Zoroastrian

230,638

French Revolutionary

654,415

Bahá’í

673,222

Modified julian day number

678,576

Equivalents Noon, November 24, −4713 (Gregorian) Noon, January 1, 4713 B.C.E. (Julian) September 7, −3760 (Gregorian) October 7, 3761 B.C.E. (Julian) August 11, −3113 (Gregorian) September 6, 3114 B.C.E. (Julian) January 23, −3101 (Gregorian) February 18, 3102 B.C.E. (Julian) February 15, −2636 (Gregorian) March 8, 2637 B.C.E. (Julian) February 18, −746 (Gregorian) February 26, 747 B.C.E. (Julian) December 7, −127 (Gregorian) December 10, 127 B.C.E. (Julian) December 30, 0 (Gregorian) January 1, 1 C.E. (Julian) January 1, 1 (Gregorian) January 3, 1 C.E. (Julian) January 1, 1 (Gregorian) January 3, 1 C.E. (Julian) August 27, 8 (Gregorian) August 29, 8 C.E. (Julian) August 29, 284 (Gregorian) August 29, 284 C.E. (Julian) July 13, 552 (Gregorian) July 11, 552 C.E. (Julian) March 22, 622 (Gregorian) March 19, 622 C.E. (Julian) July 19, 622 (Gregorian) July 16, 622 C.E. (Julian) June 19, 632 (Gregorian) June 16, 632 C.E. (Julian) September 22, 1792 (Gregorian) September 11, 1792 C.E. (Julian) March 21, 1844 (Gregorian) March 9, 1844 C.E. (Julian) November 17, 1858 (Gregorian) November 5, 1858 C.E. (Julian)

For example, 710,347 − (Hebrew calendar epoch)

=

710,347 − (−1,373,427)

=

2,083,774,

and hence R.D.

710,347 = 2,083,774 days since the start of the Hebrew calendar.

15

16

1 Calendar Basics

Because, for the most part, our formulas depend on the number of days elapsed on some calendar, we often use the expression (d − calendar epoch) in our calendar formulas. For many calendars, including the Gregorian, the same calendar rules were used with different eras and different month names at different times and in different places. In Taiwan, for instance, the Gregorian calendar is used with an era beginning with the founding of the republic in 1911. An often-encountered era from the second century B.C.E. until recent times—used with many calendars—was the Era of Alexander, or the Seleucid Era, in which year 1 corresponds to 312 B.C.E. In general, we avoid describing the details of such trivial variants of calendars. 1.5 Julian Day Numbers Iulianam vocauimus: quia ad annum Iulianum dumtaxat accommodata est. [I have called this the Julian period because it is fitted to the Julian year.] —Joseph Justus Scaliger: De Emendatione Temporum, end of introduction to Book V (1583)

Astronomers in recent centuries have avoided the confusing situation of date references on different calendars, each with its idiosyncrasies, by specifying moments in time by giving them in “julian days” or JD (sometimes “julian astronomical days” or J.A.D.). The “Julian period,” published in 1583 by Joseph Justus Scaliger, was originally a counting of years in a repeating pattern 7980 years long, starting from 4713 B.C.E. (Julian). It is often claimed ([1, page 431], for example) that Scaliger named the period after his father, the Renaissance physician Julius Cæsar Scaliger, but this claim is not borne out by examination of Scaliger’s great work, De Emendatione Temporum, from which the section quote above is taken. Grafton [8] gives a full history of De Emendatione Temporum. The details of the derivation for the value 7980 are given in [24]; the roots of the 7980-year cycle are much earlier than Scaliger, however, dating back to the twelfth century [23]. In the mid-nineteenth century, Herschel [15, page 532] adapted the system into a strict counting of days backward and forward from JD

0

=

Noon on Monday, January 1, 4713 B.C.E. (Julian)

=

Noon on Monday, November 24, −4713 (Gregorian).

A fractional part of a julian11 date gives the fraction of a day beyond noon; switching dates at noon makes sense for astronomers who work through the night. In this system, for example, sunset on the first day of the Hebrew calendar occurred at about JD 347,997.25 (local time), which is 1/4 of a day after noon. The literature on the Mayan calendar commonly specifies the beginning of the calendar in julian days. Because noon of R.D. 0 is JD 1,721,425, it follows that JD 11

n = Noon on R.D. (n − 1,721,425).

We use lowercase here to avoid any confusion between a julian day number and a date on the Julian calendar.

1.6 Mathematical Notation

17

In other words, Midnight at the onset of R.D. d = JD (d + 1,721,424.5).

(1.2)

We do not use julian days directly, as suggested in [11], because we want our days to begin at civil midnight. We also use fractional days when we need to calculate with time but begin each day at midnight. To distinguish clearly between the Julian calendar and julian days in our functions, we use the abbreviation “jd” instead of “julian.” We have jd-epoch

def

=

R.D.

−1721424.5 def

=

moment-from-jd (jd)

def

=

jd-from-moment (t)

(1.3)

jd + jd-epoch t − jd-epoch

(1.4) (1.5)

where jd can be a fraction representing time as well as date. As used by historians, julian day numbers are defined as jd + 0.5 (see [19, vol. 3, p. 1064], for example). Thus our function fixed-from-jd gives the R.D. date intended by historians when they refer to julian dates. For dates near the present, the julian day number is inconvenient because at least 7-digit accuracy is needed. Astronomers occasionally use modified julian day numbers, or MJD defined as Modified julian day number = julian day number − 2400000.5, which counts days from midnight, Wednesday, November 17, 1858 (Gregorian). This is equivalent to defining mjd-epoch

def

=

R.D.

fixed-from-mjd (mjd) mjd-from-fixed (date)

678576

(1.6)

def

=

mjd + mjd-epoch

(1.7)

def

date − mjd-epoch

(1.8)

=

We do not use modified julian days directly because we want positive numbers for dates within recent history. 1.6 Mathematical Notation The best notation is no notation. —Paul Halmos: How to Write Mathematics (1970)

We use the following mathematical notation (see [9]) when describing the calendar calculations: The floor function, x, gives the largest integer less than or equal to x. For example, π  = 3. In general, x = −−x, so for example −π  = −4. The similar ceiling function, x, gives the smallest integer greater than or equal to

18

1 Calendar Basics

x. For example, π  = 4 and −π  = −3. For integers n, n = n = n. Using the floor function, we can convert a moment into an R.D. date by fixed-from-moment (t)

def

=

t

(1.9)

Similarly, we can convert a moment given in julian days to an R.D. date, with no fractional part by fixed-from-jd (jd)

def

=

moment-from-jd (jd)

(1.10)

The inverse is simply the same as jd-from-moment: jd-from-fixed (date)

def

=

jd-from-moment (date)

(1.11)

Occasionally we need to round values to the nearest integer. We can express this using the floor function as def

round(x) = x + 0.5,

(1.12)

which is either x or x. We use the single large left bracket to indicate a conditional expression, one whose value depends on two or more conditions. For example, in   value1 condition1 , def (1.13) x = value2 condition2 ,  value3 otherwise, the conditions are examined in order, from top down. Thus the value of x is value1 if condition1 is true, value2 if condition1 is false but condition2 is true, and value3 if both conditions are false. Note that if both conditions are true, the sequential evaluation of them means that the value of the expression is value1 . As a simple example of such a conditional expression we define the sign function   −1 if y < 0, def signum(y) = (1.14) 0 if y = 0,  1 if y > 0. The remainder, or modulus, function, x mod y, is defined for y = 0 as x mod y

def

=

x − yx/y,

(1.15)

which is the remainder when x is divided by y (x and y need not be integers). For example, 9 mod 5 = 4, −9 mod 5 = 1, 9 mod −5 = −1, and −9 mod −5 = −4. Definition (1.15) makes sense for any nonzero value of y; for example, 5/3 mod 3/4 = 1/6. In particular, when y = 1, x mod 1 is the fractional part of x, allowing us to obtain the time of day as a fraction from a moment by time-from-moment (t)

def

=

t mod 1

(1.16)

In programming languages (including C, C++, and Pascal) without a built-in remainder function that works for nonintegers, the definition given in (1.15) must be used instead.

1.6 Mathematical Notation

19

There are five important consequences of definition (1.15). First, if y > 0, then x mod y ≥ 0, for all x, even for negative values of x; we use this property throughout our calculations. Care must thus be exercised in implementing our algorithms in computer languages like C and C++ in which the mod operator % may have (x % y) < 0 for x < 0, y > 0. It follows from (1.15) that (−x) mod y = y − (x mod y) for y > 0 and x ≡ 0 (mod y). The third consequence is that the definition of the mod function implies that for y = 0 and z = 0, a = (x mod y) if and only if az = (x z mod yz).

(1.17)

Fourth, x − (x mod y) is always an integer multiple of y.

(1.18)

Finally, the fifth consequence is a generalization of the first consequence: for y = 0, 0 ≤ signum(y) × (x mod y) < |y|.

(1.19)

The mod function allows us to define two other important functions, the greatest common divisor and the least common multiple. The greatest common divisor of two positive integers, x and y is defined as  x if y = 0, def (1.20) gcd(x, y) = gcd(y, x mod y) otherwise, and their least common multiple as def

lcm(x, y) =

xy . gcd(x, y)

(1.21)

We also find it convenient to use an adjusted remainder function, x amod y, defined for y = 0 as  y if x mod y = 0, def (1.22) x amod y = x mod y otherwise. The amod function can also be described as x amod y = y + x mod (−y).

(1.23)

It satisfies x amod y = x − y(x/y − 1)

(1.24)

for all y = 0. On a few occasions (especially in Chapter 18) we will want to recenter the remainder; this is easy with the mod function. For example, to convert an angle α to the range [−180◦ , 180◦ ), we write (α + 180◦ ) mod 360 − 180◦ .

(1.25)

20

1 Calendar Basics

Lastly, we use a special summation operator, p(i) 

f (i) = f (k) + f (k + 1) + · · ·

(1.26)

i≥k

whose value is that obtained when f (i) is summed for all i = k, k + 1, . . . , continuing only as long as the condition p(i) holds. This operator can be defined as follows:   p(i) p(i)  f (k) + i≥k+1 f (i) if p(k) (1.27) f (i) = 0 otherwise i≥k

Thus, the whole sum is 0 when p(k) is false. 1.7 Search . . . as two grains of wheat hid in two bushels of chaff: you shall seek all day ere you find them, and when you have them, they are not worth the search. —William Shakespeare: Merchant of Venice, Act I, scene i (1600)

In many calendar computations, it is easy to compute an approximate date, and easy to check whether a date in question is correct, but difficult to compute the correct date directly. In such cases, we compute a lower bound d0 on the possible date and then perform a linear search, day by day, until the correct date d is reached. For that purpose we use the operator

MIN {ψ(d)} ,

(1.28)

d≥d0

which searches for the smallest d in the sequence d0 , d0 + 1, d0 + 2, . . . such that the condition ψ holds true for d. In other words, using the symbol “¬” for logical negation, we have ¬ψ(d0 ), ¬ψ(d0 + 1), ¬ψ(d0 + 2), . . . , ¬ψ(d − 1), but ψ(d). MIN is undefined and does not terminate if the predicate ψ(d) does not become true eventually. Occasionally, we search the sequence for the day prior to the first d  such that ¬ψ(d  ) and use instead

MAX {ψ(d)} .

(1.29)

d≥d0

With this operator, we have ψ(d0 ), ψ(d0 + 1), ψ(d0 + 2), . . . , ψ(d), but ¬ψ(d + 1). MAX is undefined and does not terminate if the predicate ψ(d) does not become false eventually. These two operators may be defined formally as follows:  k if ψ(k) MIN {ψ(d)} = MIN {ψ(d)} otherwise d≥k 

MAX {ψ(d)} = d≥k

d≥k+1

k−1

if ¬ψ(k)

MAX {ψ(d)} otherwise d≥k+1

Thus, MAX {ψ(d)} = d0 − 1 when ψ(d0 ) is already false. d≥d0

1.7 Search

21

To determine the time of astronomical events, such as equinox or solstice, we need to invert astronomical functions, such as the celestial longitude of the sun in Section 13.4. In the absence of explicit methods for calculating the inverse of a function f , that is, for calculating a value x such that f (x) = y, given the value of y, we need to search an interval of time [a, b] for the moment a ≤ x ≤ b when f (x) = y. To express such a calculation, we write f −1 (y, [a, b]). In other words, f −1 (y, [a, b]) returns a value x0 such that there is some x ∈ [a, b] for which f (x) = y, precisely, and |x −x0 | < ε, where ε > 0 is some small tolerance within which the result is acceptable. When the function in question f is increasing, bisection search [28, section 3.2] can be an effective means of inverting f . We define φ(l,u)

y ≈ MIN {ψ(ξ )} ξ ∈[µ,ν]

means that

µ ≤ l < y < u ≤ ν, φ(l, u), ¬ψ(l), and ψ(u)

(1.30)

That is, we search for a y satisfying the definiens under the assumption that the region [µ, ν] can be split into two intervals [µ, x), up to but not including x, and [x, ν], such that ψ is false throughout the former and true in the latter. Then y must be close enough to x so that it lies in an interval [l, u], sandwiching x, small enough to satisfy the test φ(l, u). We implement the definition using a straightforward bisection search of the interval [µ, ν]:

MIN (µ, ν, φ, ψ) def =     x   

(1.31) if φ (µ, ν)

MIN (µ, x, φ, ψ) if ψ (x) MIN (x, ν, φ, ψ) otherwise

where x

=

ν+µ 2

If ψ is true of the midpoint x, then we “go left” and let the new upper bound ν be x. On the other hand, if ψ is false, we “go right” and let the new lower bound µ be x. This process continues until the interval [µ, ν] is small enough that φ is true, at which point the midpoint is returned. At each stage of the search, ψ(µ) is false and ψ(ν) is true. For the most part, we use bisection search to invert astronomical functions f that take moments and return values in the range [0◦ , 360◦ ). That is, given a desired value y, in degrees, we search for a moment x, within some given range, such that f (x) = y. Since the search interval will always be relatively small, we sidestep the

22

1 Calendar Basics

discontinuity at 360◦ = 0◦ by searching for the first moment at which f (x) − y modulo 360 becomes tiny. Using bisection, this is achieved as follows: def

f −1 (y, [a, b]) =

u−l - ?@:  utt - ?@:  A

*+ A

  a>! B" C > > - a)D utt - a)D a  я r( ! C  ) > - 0 utt - 0  

α Arietis (Hamal) 35 Arietis η Tauri (Alcyone) α Tauri (Aldebaran) λ Orionis (Meissa) α Orionis (Betelgeuse) β Geminorum (Pollux) δ Cancri (Asellus Australis) α Cancri (Acubens) α Leonis (Regulus) δ Leonis (Zosma) β Leonis (Denebola) γ Corvi (Gienah) α Virginis (Spica) α Bootis (Arcturus) α Libræ (Zubenelgenubi) δ Scorpii (Dschubba) α Scorpii (Antares) γ Scorpii δ Sagittarii (Kaus Media) σ Sagittarii (Nunki) α Lyræ (Vega) α Aquilæ (Altair) α Delphini (Sualocin) λ Aquarii α Pegasi (Markab) α Andromedæ (Alpheratz) ζ Piscium

Associated deity A´svinau Yama Agni Praj¯apati Soma Rudra Aditi Br.haspati Sarp¯ah. Pitarah. Aryaman Bhaga Savitr. Indra V¯ayu Indr¯agni Mitra Indra Pitarah. ¯ . Apah Vi´sve dev¯ah. Brahm¯a Vis.n.u Vasavah. Indra Aja Ekap¯ad Ahirbudhnya

5. Compare the current month name with that of the next new moon. If they are the same, then it is a leap month (and “adhika” is appended to the month’s name). Consider the unusual lunar year that began on March 26, 1982 C.E. The sequence of solar entries into zodiacal signs (bold) and new moons (italics) events in that year was: March 14, 1982 March 25, 1982 April 14, 1982

17:39:48 15:21:52 2:08:34

330◦ month 1 0◦

280

Capricorn 270˚

10 10

Aquarius 300˚

11 leap 12

Pisces 330˚

12 12 Lunar New Year

Aries 0˚

Solar New Year

1

1

Taurus 30˚

2

2

Gemini 60˚

3

3

solar months lunar months

Figure 18.1: The modern Hindu lunisolar calendar. Solar events (entry in zodiac constellations) are shown above the time line; lunar events (lunar conjunctions) are shown below; longitudes are sidereal. The solar months are shown in boldface numbers; the lunar months, in italic numbers. Note the expunged eleventh lunar month.

Lunar events

New moons

Zodiac: Solar longitude:

Solar events

18.1 Hindu Astronomy

April 24, 1982 May 15, 1982 May 23, 1982 June 15, 1982 June 21, 1982 July 17, 1982 July 21, 1982 August 17, 1982 August 19, 1982 September 17, 1982 September 17, 1982 October 17, 1982 October 18, 1982 November 15, 1982 November 16, 1982 December 15, 1982 December 16, 1982 January 14, 1983 January 14, 1983 February 13, 1983 February 13, 1983 March 14, 1983 March 14, 1983 April 13, 1983

1:55:58 0:33:27 10:18:42 10:38:20 17:20:29 2:06:17 0:01:51 13:30:07 7:31:17 13:58:01 16:46:25 4:35:29 0:34:25 19:28:07 22:01:12 13:18:01 9:48:12 9:03:50 17:26:14 4:10:17 4:45:34 22:26:19 23:52:24 13:06:31

281

month 2 30◦ month 3 60◦ month 4 90◦ month 5 120◦ month 6 150◦ leap month 7 month 7 180◦ month 8 210◦ month 9 240◦ month 10 270◦ 300◦ leap month 12 month 12 330◦ month 1

There were two new moons between the sun’s reaching 150◦ and 180◦ , and between 300 and 330◦ , so both the seventh and twelfth months are leap. Because there was no new moon between 270 and 300◦ , month 11 is expunged. In contrast, the calculations of the old (mean) Hindu lunisolar calendar can result in added months and lost days but not lost months nor added days. Because the mean lunar month is shorter than the mean solar month, there is never a situation on the mean calendar in which an expunged lunar month is called for. Similarly, because a civil day is longer than a thirtieth of a mean synodic month, leap days were never needed.

18.1 Hindu Astronomy I dare not hope that I have made myself quite clear, simply because [my explanation] involves too many fractions and details. To tell the truth it took me several days to get familiar with the [calendar] system. . . . Several of my Brahmin friends themselves were unable to explain the intricacies of the Hindu calendar. . . . But let me not leave the impression that these attempts on the part of the Brahmins of old to reconcile the seemingly irreconcilable have been futile. . . There can be no doubt that, from the point of view of correctness and exactitude, the Hindu calendars are by far the nearest approaches to the actual machinery

282

18 The Modern Hindu Calendars of astronomical phenomena governing life on our planet. The only fault of the Hindu calendars is that they are unintelligible to the common man. —Hashim Amir Ali: Facts and Fancies (1946)

From the time of Ptolemy’s Almagest in the second century until the Keplerian Revolution of the seventeenth century, it was well known that the motions of the seven heavenly bodies visible to the naked eye (the sun, the moon, Mercury, Venus, Mars, Jupiter, and Saturn) can best be described by combinations of circular motions, that is, cycles and epicycles.5 The Hindu calendar approximations are based on such epicycles. To find the true positions of the sun and moon we need to adjust their mean (sidereal) longitudes by the contribution of the epicycle. The heavenly body is assumed to remain on the deferent (the main circle) but to be “pulled” in one direction or the other by “winds” and “cords of air” originating on the epicycle. If we assume the center of the epicycle is at longitude β and the anomaly (angle of the heavenly body around the epicycle, measured from the farthest point from Earth along the epicycle) is α, the angular position is approximately β − arcsin(r sin α), where r is the ratio of radii of epicycle and deferent. Figure 18.2 illustrates this arrangement. The S¯urya-Siddh¯anta and earlier Hindu astronomical tracts give a table of sines for angles of 0◦ to 90◦ , in increments of 225 minutes of arc, and interpolation is used for intermediate values. The sines, shown in Table 18.2, are given as integers in the range 0. . . 3438 (that is, in terms of a radius of 3438 units) and serve as close approximations to the true sine.6 We implement the table by means of the following ad hoc function, which returns an amplitude in the range [0 : 1] for angles given in units of 225 : 1 def × round (exact + error) (18.4) hindu-sine-table (entry) = 3438 where   exact = 3438 × sin entry × 225 error 5

6

=

0.215 × signum (exact) × signum (|exact| − 1716)

Elliptical motion is indeed exactly characterized by one retrograde epicycle, on which motion is in the opposite direction of that along the deferent and the period is double (see Figure 18.2); the distinction between elliptical motion and epicyclical motion is conceptual. Kepler’s second law of 1609 explains that the motion is not uniform. Ptolemaic astronomy also included eccentric orbits to account for the off-center position of Earth and equants to model the uneven speeds. A radius of 3438 and a quadrant comprising 5400 minutes imply a value of 5400×4 ≈ 3.141361 for π . 3438×2 A recurrence is given in the S¯urya-Siddh¯anta for producing this table of sines, namely 1  sin(nα) = nα − (n − i) sin(iα), 225 i 57    (n − 1) amod 7 otherwise

310 36

43

42

50

49

48

47

46

45

44

44–50

57

56

55

54

53

52

51

51–60

59

29

35

41

40

39

38

37

37–43

60

22

28

34

33

32

31

30

30–36

:

Catus.pada N¯aga

9 10

8

15

21

27

26

25

24

23

23–29

* ;

8

 F

Vis.t.i ´ Sakuni

7

14

20

19

18

17

16

16-22

58

7

 (я

Van.ija

6

13

12

11

10

9

9–15

Sequence

 

6

5

:

Taitila Gara

Kaulava

3 4

5

3



4

V¯alava

2

2



 6 

Bava

1

1

3A n

1–8

'

Kim . stughna

Name

0

Number

Karan.a

Table 18.3: The cycle of 60 karan.as (lunar half-days). The number and name for each half-day are given to the left of each row. Four special names apply at the beginning and end of a month; the other seven names repeat regularly during mid-month. The function karana returns the number in the leftmost column.

18.6 Holidays

311

A yoga (meaning “addition”) is the varying period of time during which the solar and lunar longitudes increase a total of 800 arc minutes (13◦ 20 ). A full circle contains 27 segments of 800 , corresponding to the 27 yogas: (1) Vis.kambha (2) Pr¯ıti (3) Ayus.m¯an (4) Saubh¯agya ´ (5) Sobhana (6) Atigan.d.a (7) Sukarman (8) Dhr.ti ´ ula (9) S¯ (10) Gan.d.a (11) Vr.ddhi (12) Dhruva (13) Vy¯agh¯ata (14) Hars.an.a

0# pr( a0 4 6   a78 # $4  : 78 d  3

if α ∈ Z 60 60 60 [α]  (α mod 1) × tibetan-sun-equation (α)       + (( − α) mod 1) × tibetan-sun-equation (α)     otherwise def

tibetan-moon-equation (α) =   if α > 14   − tibetan-moon-equation (α − 14)    tibetan-moon-equation (14 − α) if α > 7      0, 5 , 10 , 15 , 19 , 22 , 24 , 25

if α ∈ Z 60 60 60 60 60 60 60 [α]  (α mod 1) × tibetan-moon-equation (α)       + (( − α) mod 1) × tibetan-moon-equation (α)     otherwise

(19.3)

For the solar equation, explicit values are given for 12 points in the full circle; for the lunar equation, for 28 points. To convert from an Tibetan date to an R.D. date, we first use our cycle formulas (1.72) to determine how many (ordinary and leap) months have elapsed, then use that to calculate how many mean lunar days and mean civil days have elapsed, and, lastly, make the solar and lunar adjustments:2 fixed-from-tibetan  year

month

 leap-month

day

leap-day

(19.4) def

=

tibetan-epoch + mean + sun + moon 2

It is traditional to perform these astronomical calculations for the end of the lunar day, unlike our algorithm, which is based on the beginning of the given day.

318

19 The Tibetan Calendar

where  months

=

days

=

30 × months + day

=

11135 − 30 + days × 11312

mean

× (year − 1) + 67 × month 65  *  −1 if leap-month 64 + + 65 0 otherwise 804 65



0

if leap-day

−1

otherwise

* +

1071 1616



 13 2117 days × + mod 1 4824 4824   3781 2837 mod 1 days × + 105840 15120

solar-anomaly

=

lunar-anomaly

=

sun

=

− tibetan-sun-equation (12 × solar-anomaly)

moon

=

tibetan-moon-equation (28 × lunar-anomaly)

For the other direction, we simply estimate when the year begins, then search for the year, month, and day, in turn, perhaps adjusting them in the case of a leap-month: tibetan-from-fixed (date) year

month

def

=

leap-month

(19.5) day

leap-day

where Y

=

years

=

year0

=

365 

4975 18382

date − tibetan-epoch



Y

MAX y≥years

    date ≥ fixed-from-tibetan     y 1 false 1

    false

   

19.2 Holidays

month0

=

MAX

   

m ≥1

   date ≥ fixed-from-tibetan     year m false

1

0

est

=

   

false

date − fixed-from-tibetan  year0

day0

=

month0

 false

1

false

MAX

   

d≥ est−2

   date ≥ fixed-from-tibetan     year month0 0

false

d

false

leap-month

=

day0 > 30

day

=

month

=

day0 amod 30     month − 1 if day > day   0 0   amod 12 month0 + 1 if leap-month      month  otherwise 0

year

=

    year0 − 1 year0 + 1    year

=

   

if day > day0 and month0 = 1 if leap-month and month0 = 12 otherwise

0

leap-day

319

date = fixed-from-tibetan  year

month

 leap-month

day

true

This algorithm relies on the fact that fixed-from-tibetan gives the fixed date of the following day when a day is expunged. The efficiency of the search for the month could be improved by starting from an under-estimate.

19.2 Holidays Yogas (combined motions of sun and moon), naks.atras (lunar stations), and karan.as (lunar half-days) follow the same patterns as on the Hindu calendar. One version of the 27 yoga names is as follows:

320

19 The Tibetan Calendar

(1) sel ba (2) mdza’ ba (3) tshe dang ldan pa (4) skal bzang (5) bzang po (6) shin tu skrang (7) las bzang (8) ’dzin pa (9) zug rngu (10) skrang (11) ’phel ba (12) nges pa (13) kun ’joms (14) dga’ ba

(15) rdo rje (16) grub pa (17) shin tu lhung (18) mchog can (19) yongs ’joms (20) zhi ba (21) grub pa (22) bsgrub bya (23) dge ba (24) dkar po (25) tshangs pa (26) dbang po (27) khon ’dzin

The 28 naks.atras are: (1) tha skar (2) bra nye (3) smin drug (4) snar ma (5) mgo (6) lag (7) nabs so (8) rgyal (9) skag (10) mchu (11) gre (12) dbo (13) me bzhi (14) nag pa

(15) sa ri (16) sa ga (17) lha mtshams (18) snron (19) snrubs (20) chu stod (21) chu smad (22) gro bzhin (23) byi bzhin (24) mon gre (25) mon gru (26) khrums stod (27) khrums smad (28) nam gru

The karan.a names follow the same pattern as those of the Hindu calendar (Table 18.3): (0) mi sdug pa (1) gdab pa (2) byis pa (3) rigs can (4) til rdung (5) khyim skyes

(6) tshong ba (7) vishti (8) bkra shis (9) rkang bzhi (10) klu

The rules for holidays are similar to those of the Hindu calendar. The new year is called Losar; it is the first day of the year, even when the first month of the year is a leap month—other holidays are celebrated only in non-leap months. The leap day is preferred for day-specific Buddhist religious practices; in the event of an expunged day, the practice is performed on the prior day. Various days of the month

19.2 Holidays

321

may be auspicious or inauspicious for specific activities: especially inauspicious is the period from noon on the sixth of the eleventh month until noon on the seventh; the immediately following twenty-four hour period is particularly auspicious. To determine if a month is leap, we can check that inverting a leap-month date gives the same month: tibetan-leap-month? (t-month, t-year)

def

=

(19.6)

t-month  = tibetan-from-fixed  fixed-from-tibetan  t-year

t-month

 true

2

false

month

Then we can determine the fixed date of Losar, as follows: losar (t-year)

def

=





fixed-from-tibetan

t-year

1

t-leap

1

(19.7)

false

where t-leap

=

tibetan-leap-month? (1, t-year)

Celebration of the new year lasts three days. Since in the distant past and future there are Gregorian years with zero occurrences of Losar (last in 719 C.E., long before this calendar was instituted, and next in 12698 C.E.), or with 2 occurrences (as in 718 C.E. and 12699 C.E.), we need to check for the onset of two Tibetan years in each Gregorian year: tibetan-new-year (g-year)

def

=

(19.8)

{losar (t-year − 1) , losar (t-year)} ∩ gregorian-year-range (g-year) where dec31

=

gregorian-year-end (g-year)

t-year

=

(tibetan-from-fixed (dec31 )) year

For example, according to this function, Losar was on March 3, 2003 (Gregorian). In the Tsurphu version, on the other hand, it was on February 2. Vesak or Vaisakha, Gautama Buddha’s Birthday, is celebrated on different dates on different calendars, including: the seventh, eighth, or fifteenth day of the fourth month on the Tibetan calendar, the fifteenth of Vai´sa¯ kha on the Hindu calendar, the eighth day of the fourth month on the Chinese calendar, April 8 on the Gregorian calendar, or on the full moon day of May. The whole first half of the first month of the year is significant, commemorating miracles performed by the Buddha. Buddha’s Enlightenment (nirv¯an.a) is celebrated

322

19 The Tibetan Calendar

on the fifteenth day of the fourth lunar month. The Turning of the Wheel of Dharma is celebrated on the fourth day of the sixth month; Buddha’s Descent is celebrated on the twenty-second day of the ninth month. References

[1] E. Henning, Kalacakra and the Tibetan Calendar, American Institute of Buddhist Studies, 2007. [2] S. Janson, “Tibetan Calendar Mathematics,” manuscript, 2007. [3] D. Schuh, Untersuchungen zur Geschichte der Tibetischen Kalenderrechnung, Franz Steiner Verlag, Wiesbaden, 1973.

323

The equation of time wrapped onto a cylinder. The rotational range is 1 year; the axial range is Gregorian years 1500–12500. This rendering was converted into a three-dimensional cam by Stewart P. Dickson to be used as a mechanical cam in the “Clock of the Long Now” by W. Daniel Hillis and the Long Now Foundation. The clock is designed to keep local, absolute, and astronomical time over a span of 10,000 years. The cam resynchronizes the clock at local solar noon via a thermal trigger. See The Clock of the Long Now: Time and Responsibility by Stewart Brand, Basic Books, New York, 1999 for more information. (Reproduced by permission.)

324

20

Astronomical Lunar Calendars

He spent his days and half his nights writing a book on the history of calendars. —Isaac Bashevis Singer: The Family Moskat (1950)

In this chapter, we apply the methods of Chapter 13 to compute the proposed uniform date of Easter, the observational Islamic lunar calendar, and the classical Hebrew lunisolar calendar. 20.1 Astronomical Easter Snout: Doth the moon shine that night we play our play? Bottom: A calendar, a calendar! look in the almanac; find out moonshine, find out moonshine. Quince: Yes, it doth shine that night. —William Shakespeare: A Midsummer Night’s Dream, Act III, scene i (1600)

In 1997, the World Council of Churches [4] proposed a uniform date for Easter for both Eastern and Western churches (see Chapter 8). With the algorithms of Chapter 13, the proposed astronomical determination of Easter is straightforward. We need to find the first Sunday in Jerusalem1 after the first true full moon after the true vernal equinox: astronomical-easter (g-year)

def

=

(20.1)

kday-after (sunday, paschal-moon) where

1

jan1

=

equinox

=

gregorian-new-year (g-year)   solar-longitude-after spring, jan1

“Astronomical observations, of course, depend upon the position on earth which is taken as the point of reference. This consultation believes that it is appropriate to employ the meridian of Jerusalem. . . ” [4].

325

326

20 Astronomical Lunar Calendars

paschal-moon

=



apparent-from-local  local-from-universal  lunar-phase-at-or-after (full, equinox) ,  jerusalem ,  jerusalem

Table 8.1 in Chapter 8 (page 119) compares the traditional dates of Passover and Easter with those obtained by the preceding astronomical calculations.

20.2 Lunar Crescent Visibility So patent are the evils of a purely lunar year whose length varies, owing to primitive methods of observation and determination of the new moon, that efforts to correct them have never ceased from the beginning to the present day. —K. Vollers: Encyclopædia of Religion and Ethics, vol. III, p. 127 (1911)2

Astronomical methods, as well as rules of thumb, for predicting the time of first visibility of the crescent moon (the phasis) have been developed over the millennia by the ancient Babylonians, medieval Moslem and Hindu scientists, and by modern astronomers. One simple, recent criterion for likely visibility of the crescent moon, proposed by S. K. Shaukat [1], requires a minimum difference in altitudes between the setting sun and moon (ignoring parallax and refraction, for simplicity), and a minimumsize crescent, which depends on the elongation (angular separation), arc-of-light, between the two bodies: visible-crescent (date, locale)

def

=

(20.2)

new < phase < first-quarter and 10.6◦ ≤ arc-of-light ≤ 90◦ and altitude > 4.1◦ where t

=

universal-from-standard (dusk (date − 1, locale, 4.5◦ ) , locale)

phase

=

lunar-phase (t)

altitude

=

lunar-altitude (t, locale)

arc-of-light

=

arccos (cos (lunar-latitude (t)) × cos phase)

 @ > % &X / #01 $     % Y 81! 341 $  1 &X @ 2



. !  -

20.2 Lunar Crescent Visibility

327

This boolean function checks whether the moon was visible on the eve of date at location locale. With it, we can calculate the day the new moon is first observable before or after any give date by approximating the date and checking for visibility: phasis-on-or-before (date, locale) 

MIN

def

=

(20.3) *

visible-crescent (d, locale)

d≥τ

where mean

τ

=

=

date  lunar-phase (date + 1) − 360◦  ×mean-synodic-month   mean − 30         

if date − mean ≤ 3 and not visible-crescent (date, locale)

mean − 2

otherwise

phasis-on-or-after (date, locale) 

MIN

def

=

(20.4) *

visible-crescent (d, locale)

d≥τ

where mean

τ

=

=

date  lunar-phase (date + 1) − 360◦  ×mean-synodic-month   date         

mean + 29

if date − mean ≤ 3 and not visible-crescent (date − 1, locale) otherwise

Shaukat and numerous others have continued working on improved criteria for predicting visibility based on topocentric altitude (page 207), rather than geocentric (page 203). One might also want to take lunar diameter into account for determining

328

20 Astronomical Lunar Calendars

lunar visibility. One could also use the following approximation for the geocentric apparent lunar diameter (in degrees): lunar-diameter (t)

1792367000◦

def

=

9 × lunar-distance (t)

(20.5)

Finally, once could compute the times of the moon’s rising and setting by performing a bisection search search (page 21) using topocentric-lunar-altitude (page 207). For a synthesis of modern methods, see [2]. 20.3 The Observational Islamic Calendar It is He who gave the sun its radiance, the moon its luster, and appointed its stations so that you may compute years and numbers. God did not create them but with deliberation. He distinctly explains His signs for those can understand. —Koran (X, 5)

Moslems in India, Pakistan, and Bangladesh base their calendar on reported moon sightings. In Egypt, they require moonset to be at least 5 minutes after sunset on the first day of the month. In the United States, according to S. K. Shaukat (national coordinator and consultant for the Islamic Shura Council of North America): “A confirmed crescent sighting report in North America will be accepted as long as such a report does not contradict indisputable astronomical information.” In Saudi Arabia and most of the Gulf countries, the moon must set after the sun on the last day of the month, as seen from Mecca. With the functions of the previous section, we can approximate the observationbased Islamic calendars that are used in practice. Suppose we take Cairo, site of AlAzhar University, a major Islamic religious center, as the location of observation:3 islamic-locale 30.1◦

31.3◦

def

=

(20.6) 200m

2h

Then we calculate the calendar as follows: fixed-from-observational-islamic   year 3

month

day

(20.7) def

=

In our Calendrical Tabulations, we made the less-than-obvious choice of Los Angeles as the location for the Islamic calendar based on the following advice of S. K. Shaukat [personal communication]: The reason I pick Los Angeles is that according to the known practices these dates would be closest to Middle Eastern countries’ practices although the visibility would not be in the Middle East. Moreover, in many cases, if the visibility is not in Los Angeles then most of the world would see it the next day and that would be reflected in the calculated dates for Los Angeles. The dates for Los Angeles would also be good for the rest of North America if an aided eye is used, which will also be in line with actual practice and I think these dates would be the closest to practices all around the world. In other words, actual observance of Ramad.a¯ n, and other Islamic events frequently precedes dates as calculated astronomically, for various non-scientific reasons. Thus, choosing Los Angeles gave dates that are both scientifically and religiously reasonable for the United States and in good agreement with actual observance in the Mideast.

20.4 The Classical Hebrew Calendar

329

phasis-on-or-before (midmonth, islamic-locale) + day − 1 where midmonth

=

islamic-epoch   + (year − 1) × 12 + month − 12  ×mean-synodic-month

observational-islamic-from-fixed (date) year

month

def

=

(20.8)

day

where crescent

=

phasis-on-or-before (date, islamic-locale)

elapsed-months

=

round

year

=

month

=

crescent − islamic-epoch mean-synodic-month   1 × elapsed-months + 1 12 (elapsed-months mod 12) + 1

day

=

date − crescent + 1





These functions for the Islamic calendar are approximate at best for many reasons: The phenomenon of visibility is still an area of astronomical research and is not yet fully understood; this criterion is just one of many suggestions. It ignores the distance to the moon and also clarity of the atmosphere, which depends on location and season as well as on unpredictable factors. Moslem countries base the calendar on reported observations, not calculated observability. The best location for seeing the new moon varies from month to month (western locations are always better), and different religious authorities accept testimony from within different regions. 20.4 The Classical Hebrew Calendar O, swear not by the moon, th’ inconstant moon, That monthly changes in her circle orb. . . —William Shakespeare: Romeo and Juliet, Act II, scene ii (1591)

In classical times, the Hebrew month began with the reported observation of the crescent new moon just like the Islamic religious calendar of the previous section.4 Unlike the Islamic calendar, leap months were intercalated so that the spring equinox always fell before the onset of Nisan 16 [3, 4:2]. The exact method of determining 4

Karaite Jews still use this form of the Hebrew calendar.

330

20 Astronomical Lunar Calendars

the day of the equinox and the exact cutoff date are uncertain; also, the courts had leeway to declare a leap year when spring came late. We take Jaffa, an old city at the western edge of Israel, as the location from which observations are made (being west makes visibility more likely): jaffa

def

=

(20.9)

32◦ 1 60

34◦ 45

0m

2h

With the methods of this chapter, it is straightforward to convert dates for this classical Hebrew observational calendar. The first of Nisan is determined, based on the vernal equinox: observational-hebrew-new-year (g-year) phasis-on-or-after  14 equinox − 13

def

=

if equinox < set

(20.10)

*

 ,jaffa

otherwise

where jan1

=

equinox

=

set

=

gregorian-new-year (g-year)   solar-longitude-after spring, jan1 universal-from-standard (sunset (equinox , jaffa) , jaffa)

The start of each month is determined by the observability of the new moon: observational-hebrew-from-fixed (date) year

month

def

=

day

where crescent

=

phasis-on-or-before (date, jaffa)

g-year

=

gregorian-year-from-fixed (date)

ny

=

new-year

=

observational-hebrew-new-year (g-year)   observational-hebrew-new-year     (g-year − 1)

month

=

    

if date < ny ny

otherwise 

round

 1 × (crescent − new-year) + 1 29.5

(20.11)

References

year

=

(hebrew-from-fixed (new-year)) year  * 1 if month ≥ tishri + 0 otherwise

day

=

date − crescent + 1

331

The inverse computation is fixed-from-observational-hebrew   year

month

day

(20.12) def

=

phasis-on-or-before (midmonth, jaffa) + day − 1 where



year − 1

if month ≥ tishri

year1

=

start

=

fixed-from-hebrew

g-year

=

gregorian-year-from-fixed (start + 60)

new-year

=

observational-hebrew-new-year (g-year)

midmonth

=

new-year + round (29.5 × (month − 1)) + 15

year

otherwise  year1

 nisan

1

Using the above functions, we can approximate the classical date of Passover Eve (Nisan 14) in any given Gregorian year: classical-passover-eve (g-year)

def

=

(20.13)

observational-hebrew-new-year (g-year) + 13

References

[1] K. Abdali, O. Afzal, I. A. Ahmad, M. Durrani, A. Salama, and S. K. Shaukat, “Crescent Moon Visibility: Consensus on Moon-Sighting and Determination of an Islamic Calendar,” manuscript, 1996. [2] R. E. Hoffman, “Rational Design of Lunar-Visibility Criteria,” The Observatory, vol. 125, no. 1186, pp. 156–168, 2005. [3] Maimonides (= Moshe ben Maimon), Mishneh Torah: Sefer Zemanim—Hilh.ot Kiddush HaH . odesh, 1178. Translated by S. Gandz (with commentary by J. Obermann and O. Neugebauer), as Code of Maimonides, Book Three, Treatise Eight, Sanctification of the New Moon, Yale Judaica Series, vol. XI, Yale University Press, New Haven, CT, 1956. Addenda and corrigenda by E. J. Wiesenberg appear at the end of Code of Maimonides, Book Three, The Book of Seasons, translated by S. Gandz and H. Klein, Yale Judaica Series, vol. XIV, Yale University Press, New Haven, CT, 1961. [4] World Council of Churches, “The Date of Easter: Science Offers Solution to Ancient Religious Problem,” Press release, March 24, 1997.

Blue and white glazed jar from the reign of K¯ang X¯ı (1662–1722), showing plum blossoms against a background of melting ice and used to hold a gift of fragrant tea for New Year’s Day. (Courtesy of the Victoria & Albert Museum, London.)

332

Coda

I hate quotations. Tell me what you know. —Ralph Waldo Emerson: Journal (May, 1849)

The following description of the presentation of the annual calendar in China is taken from Peter (Pierre) Hoang (A Notice of the Chinese Calendar and a Concordance with the European Calendar, 2nd ed., Catholic Mission Press, Shanghai, 1904): Every year, on the 1st of the 2nd month, the Board of Mathematics presents to the Emperor three copies of the Annual Calendar for the following year, namely in Chinese, in Manchou and in Mongolian. Approbation being given, it is engraved and printed. Then on the 1st of the 4th month, two printed copies in Chinese are sent to the Fan-t‘ai (Treasurer) of each province, that of Chih li excepted; one of which, stamped with the seal of the Board of Mathematics, is to be preserved in the archives of the Treasury, while the other is used for engraving and printing for public use in the province. On the 1st day of the 10th month, early in the morning, the Board of Mathematics goes to offer Calendars to the Imperial court. The copies destined to the Emperor and Empresses are borne upon a sedan-like stand painted with figures of dragons (Lung t‘ing), those for the Princes, the Ministers and officers of the court being carried on eight similar stands decorated with silk ornaments (Ts‘ai-t‘ing). They are accompanied by the officers of the Board with numerous attendants and the Imperial band of music. On arriving at the first entrance of the palace, the Calendars for the Emperor are placed upon an ornamented stand, those for other persons being put upon two other stands on each side. The copies for the Emperor and his family are not stamped with the seal of the Board of Mathematics, while the others are. The middle stand is taken into the palace, where the officers of the Board make three genuflections, each followed by three prostrations, after which the Calendars are handed to the eunuchs who present them to the Emperor, the Empress-mother, the Empress and other persons of the seraglio, two copies being given to each, 333

334

Coda

viz. one in Chinese and one in Manchou. The master of ceremonies then proceeds to the entrance of the palace where the two other stands were left, and where the Princes, the Ministers with the civil and military mandarins, both Manchous and Mongols all in robes of state are in attendance. The master of ceremonies reads the Imperial decree of publication of the Calendars, namely: “The Emperor presents you all with the Annual Calendar of the year, and promulgates it throughout the Empire,” which proclamation is heard kneeling. Then follow three genuflections and nine prostrations, after which all receive the Calendar on their knees, the Princes two copies, one in Chinese and one in Manchou, the ministers and other officers only one, each in his own language. Lastly the Corean envoy, who must attend every year on that day, is presented kneeling with one hundred Chinese copies, to take home with him. In the provinces, the Fan-t‘ai (Treasurer), after getting some printed copies of the Calendar stamped with a special seal, also on the 1st of the 10th month, sends them on a sedan-like stand to the Viceroy or Governor, accompanied by the mandarin called Li-wen-t‘ing, who is instructed with the printing of the Calendar. The Viceroy or Governor receives them to the sound of music and of three cannon shots. The Calendars being set upon a stand between two tapers in the tribunal, the Viceroy or Governor, in robes of state, approaches the stand, and turning towards that quarter where Peking is situated, makes three genuflections and nine prostrations, after which ceremony he reverently receives the Calendars. The Treasurer sends the Calendar to all the civil and military Mandarins, all of whom, except those of inferior degree, receive it with the same forms. Any copies left are sold to the people. The reprinting of the Calendar is forbidden under a penalty (except in Fu-chien and Kuang-tong where it is tolerated). If therefore any copy is found without seal or with a false one, its author is sought after and punished. Falsification of the Calendar is punished with death; whoever reprints the Annual Calendar is liable to 100 blows and two months cangue. Now that’s a society that takes calendars (and copyrights) seriously!

Part III

Appendices

335

Page from a 1911 Turkish calendar. The uppermost portion gives the Islamic date, followed by dates in Arabic and Turkish; below that is the Gregorian date in Russian; below that on the left is the Julian date in Greek and the Gregorian date in French—the time of midday in Turkey is given at the left and right edges and the date of the full moon is given at the middle edges; below that are entries giving the time of sunset in Armenian on the left and French on the right; below that is the Hebrew date, with the day of the week given in Ladino. (Courtesy of Nicholas Stavroulakis and the Etz Hayyim Synagogue, Hania, Crete, Greece.)

336

Appendix A

Function, Parameter, and Constant Types

You must never forget that programs will be read by people as well as machines. Write them carefully. —George E. Forsythe: Remark to Alan George (1967)

In this appendix we list all of the types of objects used in our calendar functions. After giving a list of the types themselves, we list, for each function, the types of its parameters and of its result. Then, we give a similar list for all constants. A.1 Types Name amplitude angle armenian-date

armenian-day armenian-month armenian-year aztec-tonalpohualli-date aztec-tonalpohualliname aztec-tonalpohuallinumber aztec-xihuitl-date aztec-xihuitl-day aztec-xihuitl-month aztec-xiuhmolpillidesignation

Type or Range

Supertype

[−1 : 1] [0 : 360) [−180 : 180)

armenian-year, armenian-month, armenian-day 1 . . . 31 1 . . . 13 integer

aztec-tonalpohualli-number, aztec-tonalpohualli-name 1 . . . 20

real real real standard-date

1 . . . 13

nonnegative-integer

aztec-xihuitl-month, aztec-xihuitl-day 1 . . . 20 1 . . . 19

aztec-tonalpohualli-number, aztec-tonalpohualli-name

list-of-nonnegative-integers

positive-integer positive-integer list-of-nonnegative-integers nonnegative-integer

nonnegative-integer positive-integer list-of-nonnegative-integers

(continued)

337

338

Appendix A. Function, Parameter, and Constant Types

(continued) Name aztec-xiuhmolpilli-name aztec-xiuhmolpillinumber bahai-cycle bahai-date

bahai-day bahai-major bahai-month bahai-year boolean chinese-branch chinese-cycle chinese-date

chinese-day chinese-leap chinese-month chinese-name chinese-stem chinese-year clock-time coptic-date coptic-day coptic-month coptic-year day-of-week distance duration egyptian-date

egyptian-day egyptian-month egyptian-year ethiopic-date ethiopic-day ethiopic-month ethiopic-year fixed-date fraction-of-day

Type or Range

Supertype

1, 8, 13, 18 1 . . . 13

positive-integer positive-integer

1 . . . 19

bahai-major, bahai-cycle, bahai-year, bahai-month, bahai-day 1 . . . 19 integer 0 . . . 19 1 . . . 19 true, false 1 . . . 12 integer

chinese-cycle, chinese-year, chinese-month, chinese-leap-month, chinese-day 1 . . . 31 boolean 1 . . . 12

chinese-stem, chinese-branch 1 . . . 10 1 . . . 60

positive-integer list-of-integers

coptic-year, coptic-month, coptic-day 1 . . . 31 1 . . . 13 integer 0...6

egyptian-year, egyptian-month, egyptian-day 1 . . . 30 1 . . . 13 integer

ethiopic-year, ethiopic-month, ethiopic-day 1 . . . 31 1 . . . 13 integer integer [−0.5,0.5]

positive-integer nonnegative-integer positive-integer positive-integer list

positive-integer positive-integer list-of-nonnegative-integers positive-integer positive-integer list-of-reals standard-date positive-integer positive-integer nonnegative-integer real real standard-date

positive-integer positive-integer standard-date positive-integer positive-integer

real

Appendix A. Function, Parameter, and Constant Types

Name french-date french-day french-month french-year gregorian-date

gregorian-day gregorian-month gregorian-year hebrew-date hebrew-day hebrew-month hebrew-year hindu-lunar-date

hindu-lunar-day hindu-lunar-leap-day hindu-lunar-leap-month hindu-lunar-month hindu-lunar-year hindu-solar-date

hindu-solar-day hindu-solar-month hindu-solar-year hindu-year hour ides integer islamic-date islamic-day islamic-month islamic-year iso-date iso-day iso-week

Type or Range

french-year, french-month, french-day 1 . . . 30 1 . . . 13 integer

gregorian-year, gregorian-month, gregorian-day 1 . . . 31 1 . . . 12 integer

hebrew-year, hebrew-month, hebrew-day 1 . . . 30 1 . . . 13 integer

hindu-lunar-year, hindu-lunar-month, hindu-lunar-leap-month, hindu-lunar-day, hindu-lunar-leap-day 1 . . . 30 boolean boolean 1 . . . 12 integer

hindu-solar-year, hindu-solar-month, hindu-solar-day 1 . . . 32 1 . . . 12 integer integer 0 . . . 23 13,15

islamic-year, islamic-month, islamic-day 1 . . . 30 1 . . . 12 integer

iso-year, iso-week, iso-day 1...7 1 . . . 53

339

Supertype standard-date positive-integer positive-integer standard-date

positive-integer positive-integer standard-date positive-integer positive-integer list

positive-integer

positive-integer standard-date

positive-integer positive-integer

nonnegative-integer roman-count rational standard-date positive-integer positive-integer list-of-integers positive-integer positive-integer (continued)

340

Appendix A. Function, Parameter, and Constant Types

(continued) Name iso-year julian-date julian-day julian-day-number julian-month julian-year list list-of-angles list-of-fixed-dates list-of-integers list-of-nonnegativeintegers list-of-pairs list-of-reals list-of-weekdays location mayan-baktun mayan-haab-date mayan-haab-day mayan-haab-month mayan-katun mayan-kin mayan-long-count-date

mayan-tun mayan-tzolkin-date mayan-tzolkin-name mayan-tzolkin-number mayan-uinal minute moment nakshatra nones nonnegative-integer nonzero-integer nonzero-real old-hindu-lunar-date

old-hindu-lunar-day old-hindu-lunar-leap

Type or Range integer

julian-year, julian-month, julian-day 1 . . . 31 real 1 . . . 12 nonzero-integer

Supertype

standard-date positive-integer positive-integer

list-of-reals list-of-integers list list-of-integers

angle, angle, distance, real integer

mayan-haab-month, mayan-haab-day 0 . . . 19 1 . . . 19 0 . . . 19 0 . . . 19

mayan-baktun, mayan-katun, mayan-tun, mayan-uinal, mayan-kin 0 . . . 17

mayan-tzolkin-number, mayan-tzolkin-name 1 . . . 20 1 . . . 13 0 . . . 19 0 . . . 59 real 1 . . . 27 5, 7 0, 1, . . . . . . , −2, −1, 1, 2, . . . (−∞ : 0) ∪ (0 : ∞)

old-hindu-lunar-year, old-hindu-lunar-month, old-hindu-lunar-leap, old-hindu-lunar-day 1 . . . 30 boolean

list list list-of-nonnegative-integers list list-of-nonnegative-integers nonnegative-integer positive-integer nonnegative-integer nonnegative-integer list-of-integers

nonnegative-integer list-of-nonnegative-integers nonnegative-integer nonnegative-integer nonnegative-integer nonnegative-integer positive-integer roman-count integer integer real list

positive-integer

Appendix A. Function, Parameter, and Constant Types

Name old-hindu-lunar-month old-hindu-lunar-year old-hindu-month old-hindu-year omer-count persian-date persian-day persian-month persian-year phase positive-integer radian range rational rational-amplitude rational-angle rational-moment real roman-count roman-date

roman-event roman-leap roman-month roman-year season second standard-date

standard-day standard-month standard-year string tibetan-date

tibetan-day tibetan-leap-day tibetan-leap-month tibetan-month tibetan-year time

Type or Range 1 . . . 12 integer 1 . . . 12 integer

0 . . . 7, 0 . . . 6

persian-year, persian-month, persian-day 1 . . . 31 1 . . . 12 nonzero-integer [0 : 360) 1, 2, . . . [0 : 2π)

moment, moment [−1 : 1] [0 : 360) rational (−∞ : ∞) 1 . . . 19

roman-year, roman-month, roman-event, roman-count, roman-leap 1...3 boolean 1 . . . 12 nonzero-integer [0 : 360) [0 : 60)

standard-year, standard-month, standard-day 1 . . . 31 1 . . . 13 integer

tibetan-year, tibetan-month, tibetan-leap-month, tibetan-day, tibetan-leap-day 1 . . . 30 boolean boolean 1 . . . 12 integer

hour, minute, second

341

Supertype positive-integer positive-integer list-of-nonnegative-integers standard-date positive-integer positive-integer angle integer real list-of-reals real rational rational moment positive-integer list

positive-integer positive-integer angle duration list-of-integers

positive-integer positive-integer

list

positive-integer

positive-integer list-of-reals

342

Appendix A. Function, Parameter, and Constant Types

A.2 Function Types

Function

Parameter Type(s)

Result Type

aberration advent alt-fixed-fromgregorian alt-gregorian-fromfixed alt-gregorian-yearfrom-fixed alt-hindu-sunrise alt-orthodox-easter amod angle

moment gregorian-year gregorian-date

±angle fixed-date fixed-date

fixed-date

gregorian-date

fixed-date

gregorian-year

fixed-date gregorian-year

real, nonzero-real

nonnegative-integer, nonnegative-integer, real angle

moment, location

moment, location, ±angle, boolean amplitude amplitude

real, real fixed-date

rational-moment fixed-date real angle

angle angle angle french-date

french-year

boolean

fixed-date

persian-date

persian-year

boolean

fixed-date

persian-year

armenian-year, armenian-month, armenian-day fixed-date

fixed-date, location moment

armenian-date

armenian-date moment hindu-solar-year

fixed-date

hindu-lunar-date

fixed-date

hindu-solar-date

fixed-date moment

moment hindu-lunar-day

gregorian-year

fixed-date

angle-from-degrees apparent-from-local approx-moment-ofdepression arccos-degrees arcsin-degrees arctan-degrees arithmetic-frenchfrom-fixed arithmetic-french-leapyear? arithmetic-persianfrom-fixed arithmetic-persianleap-year? arithmetic-persianyear-from-fixed armenian-date

armenian-from-fixed asr astro-hindu-calendaryear astro-hindu-lunarfrom-fixed astro-hindu-solar-fromfixed astro-hindu-sunset astro-lunar-day-frommoment astronomical-easter

list-of-reals moment moment (or bogus)

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

auc-year-from-julianyear ayanamsha aztec-tonalpohuallidate aztec-tonalpohuallifrom-fixed aztec-tonalpohualliname aztec-tonalpohuallinumber aztec-tonalpohualli-onor-before aztec-tonalpohualliordinal aztec-xihuitl-date

julian-year

nonzero-integer

moment

aztec-tonalpohualli-number, aztec-tonalpohualli-name fixed-date

angle aztec-tonalpohualli-date

aztec-tonalpohualli-date

aztec-tonalpohualli-name

aztec-tonalpohualli-date

aztec-tonalpohuallinumber fixed-date

aztec-xihuitl-day aztec-xihuitl-from-fixed aztec-xihuitl-month aztec-xihuitl-on-orbefore aztec-xihuitl-ordinal aztec-xihuitltonalpohualli-on-orbefore aztec-xiuhmolpillidesignation

aztec-tonalpohualli-date, fixed-date aztec-tonalpohualli-date

aztec-tonalpohualli-date

nonnegative-integer

aztec-xihuitl-month, aztec-xihuitl-day aztec-xihuitl-date fixed-date aztec-xihuitl-date

aztec-xihuitl-date, fixed-date

aztec-xihuitl-date

aztec-xihuitl-date

aztec-xihuitl-date, aztec-tonalpohualli-date, fixed-date

aztec-tonalpohualli-number, aztec-tonalpohualli-name

nonnegative-integer fixed-date (or bogus)

aztec-xihuitl-day aztec-xihuitl-date aztec-xihuitl-month fixed-date

aztec-xiuhmolpillifrom-fixed

fixed-date

aztec-xiuhmolpilliname aztec-xiuhmolpillinumber bahai-cycle bahai-date

aztec-xiuhmolpilli-designation

aztec-xiuhmolpillidesignation (or bogus) aztec-xiuhmolpillidesignation (or bogus) aztec-xiuhmolpilli-name

aztec-xiuhmolpilli-designation

aztec-xiuhmolpilli-number

bahai-date

bahai-major, bahai-cycle, bahai-year, bahai-month, bahai-day bahai-date fixed-date bahai-date bahai-date gregorian-year

bahai-cycle bahai-date

bahai-day bahai-from-fixed bahai-major bahai-month bahai-new-year

343

bahai-day bahai-date bahai-major bahai-month fixed-date (continued)

344

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

bahai-year bali-asatawara bali-asatawara-fromfixed bali-caturwara bali-caturwara-fromfixed bali-dasawara bali-dasawara-fromfixed bali-day-from-fixed bali-dwiwara bali-dwiwara-fromfixed bali-luang bali-luang-from-fixed balinese-date

bahai-date balinese-date fixed-date

bahai-year 1. . . 8 1. . . 8

balinese-date fixed-date

1. . . 4 1. . . 4

balinese-date fixed-date

0. . . 9 0. . . 9

fixed-date balinese-date fixed-date

0. . . 209 1. . . 2 1. . . 2

balinese-date fixed-date

boolean,1. . . 2, 1. . . 3, 1. . . 4, 1. . . 5, 1. . . 6, 1. . . 7, 1. . . 8, 1. . . 9, 0. . . 9

balinese-date, fixed-date balinese-date fixed-date

boolean boolean balinese-date

fixed-date

balinese-date

balinese-date fixed-date

1. . . 6 1. . . 6

balinese-date fixed-date

1. . . 9 1. . . 9

balinese-date fixed-date

1. . . 7 1. . . 7 1. . . 3 1. . . 3 1. . . 30 julian-year real

birkath-ha-hama ce chinese-age

balinese-date fixed-date fixed-date standard-year

—, real, —, real, —, real→boolean, real, real →boolean gregorian-year standard-year

chinese-date, fixed-date

chinese-branch

chinese-name

bali-on-or-before bali-pancawara bali-pancawara-fromfixed bali-pawukon-fromfixed bali-sadwara bali-sadwara-fromfixed bali-sangawara bali-sangawara-fromfixed bali-saptawara bali-saptawara-fromfixed bali-triwara bali-triwara-from-fixed bali-week-from-fixed bce binary-search

fixed-date 1. . . 5 1. . . 5

list-of-fixed-dates julian-year nonnegative-integer (or bogus) chinese-branch

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

chinese-cycle chinese-date

chinese-date

chinese-cycle, chinese-year, chinese-month, chinese-leap, chinese-day chinese-date

chinese-name, fixed-date

chinese-cycle chinese-date

fixed-date chinese-date moment chinese-date

chinese-stem, chinese-branch

chinese-name, chinese-name

chinese-date chinese-leap location chinese-month chinese-name (or bogus) nonnegative-integer

fixed-date

chinese-month, chinese-year chinese-year fixed-date

chinese-name chinese-name chinese-name fixed-date

fixed-date

fixed-date

gregorian-year fixed-date fixed-date

fixed-date fixed-date fixed-date

fixed-date

boolean

fixed-date, fixed-date

boolean

integer

chinese-name

season, fixed-date

moment

chinese-name fixed-date

chinese-stem fixed-date

chinese-date

chinese-cycle, chinese-year

chinese-year 0. . . 3

gregorian-year gregorian-year moment gregorian-year

coptic-year, coptic-month, coptic-day

fixed-date fixed-date clock-time list-of-fixed-dates coptic-date

chinese-day chinese-day-name-onor-before chinese-from-fixed chinese-leap chinese-location chinese-month chinese-name chinese-namedifference chinese-name-of-day chinese-name-of-month chinese-name-of-year chinese-new-moonbefore chinese-new-moon-onor-after chinese-new-year chinese-new-year-in-sui chinese-new-year-onor-before chinese-no-major-solarterm? chinese-prior-leapmonth? chinese-sexagesimalname chinese-solar-longitudeon-or-after chinese-stem chinese-winter-solsticeon-or-before chinese-year chinese-year-marriageaugury christmas classical-passover-eve clock-from-moment coptic-christmas coptic-date

345

chinese-day fixed-date

(continued)

346

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

coptic-from-fixed coptic-in-gregorian

fixed-date

coptic-month, coptic-day, gregorian-year coptic-year angle fixed-date

coptic-date list-of-fixed-dates boolean amplitude integer

fixed-date

integer

fixed-date, location, angle gregorian-date fixed-date gregorian-year gregorian-year hebrew-year gregorian-date

fixed-date, location

moment, angle, angle real list-of-reals real radian

degree, minute, real

moment (or bogus) positive-integer day-of-week fixed-date fixed-date 353,354,355,383,384,385 nonnegative-integer real (or bogus) angle angle list-of-angles angle angle angle

location, location gregorian-year gregorian-year

fixed-date, location, angle moment

angle list-of-fixed-dates fixed-date moment (or bogus) moment

gregorian-year gregorian-year

fixed-date list-of-fixed-dates

egyptian-year, egyptian-month, egyptian-day fixed-date gregorian-year location range moment gregorian-year moment

season, moment

egyptian-date

coptic-leap-year? cosine-degrees current-major-solarterm current-minor-solarterm dawn day-number day-of-week-from-fixed daylight-saving-end daylight-saving-start days-in-hebrew-year days-remaining daytime-temporal-hour declination deg degrees degrees-from-radians degrees-minutesseconds direction diwali dragon-festival dusk dynamical-fromuniversal easter eastern-orthodoxchristmas egyptian-date

egyptian-from-fixed election-day elevation end ephemeris-correction epiphany equation-of-time estimate-prior-solarlongitude

egyptian-date fixed-date distance moment fraction-of-day fixed-date fraction-of-day moment

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

ethiopic-date

ethiopic-year, ethiopic-month, ethiopic-day fixed-date gregorian-year

—, integer, integer→boolean

day-of-week, gregorian-date french-date

ethiopic-date ethiopic-date fixed-date integer fixed-date fixed-date

persian-date

fixed-date

armenian-date hindu-lunar-date

fixed-date fixed-date

hindu-solar-date

fixed-date

bahai-date chinese-date coptic-date egyptian-date ethiopic-date french-date bahai-date

fixed-date fixed-date fixed-date fixed-date fixed-date fixed-date fixed-date

gregorian-date hebrew-date hindu-lunar-date

fixed-date fixed-date fixed-date

hindu-lunar-date hindu-solar-date islamic-date iso-date julian-day-number julian-date julian-day-number mayan-long-count-date

fixed-date fixed-date fixed-date fixed-date fixed-date fixed-date fixed-date fixed-date

moment hebrew-date

fixed-date fixed-date

islamic-date

fixed-date

ethiopic-from-fixed feast-of-ridvan final first-kday fixed-from-arithmeticfrench fixed-from-arithmeticpersian fixed-from-armenian fixed-from-astro-hindulunar fixed-from-astro-hindusolar fixed-from-bahai fixed-from-chinese fixed-from-coptic fixed-from-egyptian fixed-from-ethiopic fixed-from-french fixed-from-futurebahai fixed-from-gregorian fixed-from-hebrew fixed-from-hindufullmoon fixed-from-hindu-lunar fixed-from-hindu-solar fixed-from-islamic fixed-from-iso fixed-from-jd fixed-from-julian fixed-from-mjd fixed-from-mayan-longcount fixed-from-moment fixed-fromobservationalhebrew fixed-fromobservational-islamic

347

(continued)

348

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

fixed-from-old-hindulunar fixed-from-old-hindusolar fixed-from-persian fixed-from-roman fixed-from-tibetan french-date

old-hindu-lunar-date

fixed-date

hindu-solar-date

fixed-date

persian-date roman-date tibetan-date

french-year, french-month, french-day fixed-date fixed-date

fixed-date fixed-date fixed-date french-date

fixed-date

bahai-date

fixed-date

fixed-date

gregorian-year, gregorian-month, gregorian-day

gregorian-date, gregorian-date fixed-date gregorian-year gregorian-year gregorian-year fixed-date

gregorian-date

gregorian-date boolean fixed-date fixed-date gregorian-year

gregorian-year

hebrew-date, hebrew-year

hebrew-date, gregorian-year

range fixed-date list-of-fixed-dates

hebrew-year

integer

hebrew-year, hebrew-month, hebrew-day fixed-date hebrew-year hebrew-year hebrew-year

hebrew-date hebrew-date boolean fixed-date boolean

hebrew-year

0. . . 2

rational-amplitude

fixed-date, location

rational-angle rational-angle

french-from-fixed french-new-year-on-orbefore future-bahai-fromfixed future-bahai-new-yearon-or-before gregorian-date

gregorian-datedifference gregorian-from-fixed gregorian-leap-year? gregorian-new-year gregorian-year-end gregorian-year-fromfixed gregorian-year-range hebrew-birthday hebrew-birthday-ingregorian hebrew-calendarelapsed-days hebrew-date hebrew-from-fixed hebrew-leap-year? hebrew-new-year hebrew-sabbaticalyear? hebrew-year-lengthcorrection hindu-arcsin hindu-ascensionaldifference

french-date fixed-date

integer

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

hindu-calendar-year hindu-daily-motion hindu-date-occur

rational-moment fixed-date

hindu-lunar-month, hindu-lunar-day, hindu-lunar-year fixed-date fixed-date

hindu-lunar-month, hindu-lunar-year fixed-date

hindu-solar-year rational-angle fixed-date

hindu-day-count hindu-equation-of-time hindu-expunged? hindu-fullmoon-fromfixed hindu-lunar-date

hindu-lunar-day hindu-lunar-day-at-orafter hindu-lunar-day-frommoment hindu-lunar-event hindu-lunar-from-fixed hindu-lunar-holiday

hindu-lunar-leap-day hindu-lunar-leapmonth hindu-lunar-longitude hindu-lunar-month hindu-lunar-new-year hindu-lunar-on-orbefore? hindu-lunar-phase hindu-lunar-station hindu-lunar-year hindu-mean-position hindu-new-moonbefore hindu-rising-sign hindu-sine

349

integer rational-moment boolean hindu-lunar-date

hindu-lunar-year, hindu-lunar-month, hindu-lunar-leap-month, hindu-lunar-day, hindu-lunar-leap-day hindu-lunar-date

rational, rational-moment

hindu-lunar-day rational-moment

rational-moment

hindu-lunar-day

hindu-lunar-month, rational, rational, gregorian-year fixed-date

hindu-lunar-month, hindu-lunar-day, gregorian-year hindu-lunar-date hindu-lunar-date

list-of-fixed-dates

rational-moment hindu-lunar-date gregorian-year

hindu-lunar-date, hindu-lunar-date rational-moment fixed-date hindu-lunar-date

rational-moment, rational rational-moment

rational-angle hindu-lunar-month fixed-date boolean rational-angle nakshatra hindu-lunar-year rational-angle rational-moment

fixed-date angle

rational rational-amplitude

hindu-lunar-date

hindu-lunar-date list-of-fixed-dates

hindu-lunar-leap-day hindu-lunar-leap-month

(continued)

350

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

hindu-sine-table hindu-solar-date

integer

hindu-solar-year, hindu-solar-month, hindu-solar-day fixed-date rational-moment

season, moment

rational-amplitude hindu-solar-date

fixed-date

rational-angle

rational-moment, location fixed-date fixed-date

hindu-lunar-month, rational, rational, hindu-lunar-year fixed-date

rational-moment rational-moment rational-moment fixed-date

rational-moment, rational, rational, rational, rational rational-moment clock-time real roman-month

moment, range gregorian-year

moment, moment

real→angle, real, real, real

islamic-year, islamic-month, islamic-day fixed-date

islamic-month, islamic-day, gregorian-year islamic-year

iso-year, iso-week, iso-day iso-date fixed-date iso-year iso-date iso-date moment fixed-date moment

fixed-date, location

fixed-date, location

rational-angle

hindu-solar-from-fixed hindu-solar-longitude hindu-solar-longitudeat-or-after hindu-solar-siderealdifference hindu-sundial-time hindu-sunrise hindu-sunset hindu-tithi-occur hindu-tropicallongitude hindu-true-position hindu-zodiac hour hr ides-of-month in-range? independence-day interval invert-angular islamic-date islamic-from-fixed islamic-in-gregorian islamic-leap-year? iso-date iso-day iso-from-fixed iso-long-year? iso-week iso-year japanese-location jd-from-fixed jd-from-moment jewish-dusk jewish-morning-end

hindu-solar-date rational-angle moment

rational-angle

hindu-solar-month hour duration ides boolean fixed-date range real islamic-date islamic-date list-of-fixed-dates boolean iso-date day-of-week iso-date boolean iso-week iso-year location julian-day-number julian-day-number moment moment

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

jewish-sabbath-ends jovian-year julian-centuries julian-date

fixed-date, location fixed-date moment

julian-year, julian-month, julian-day fixed-date

julian-month, julian-day, gregorian-year julian-year nonzero-integer

moment 1 . . . 60 real julian-date

julian-from-fixed julian-in-gregorian julian-leap-year? julian-year-from-aucyear kajeng-keliwon karana kday-after kday-before kday-nearest kday-on-or-after kday-on-or-before korean-location korean-year labor-day last-day-of-hebrewmonth last-kday last-month-of-hebrewyear latitude list-range local-from-apparent local-from-standard local-from-universal location long-marheshvan? longitude losar lunar-altitude lunar-anomaly lunar-diameter lunar-distance lunar-elongation lunar-latitude

351

julian-date list-of-fixed-dates boolean julian-year

gregorian-year 1 . . . 60

day-of-week, fixed-date

day-of-week, fixed-date

day-of-week, fixed-date

day-of-week, fixed-date

day-of-week, fixed-date moment

chinese-cycle, chinese-year gregorian-year

hebrew-month, hebrew-year

list-of-fixed-dates 0 . . . 10 fixed-date fixed-date fixed-date fixed-date fixed-date location integer fixed-date hebrew-day

day-of-week, gregorian-date hebrew-year

fixed-date hebrew-month

location

list-of-moments, range

moment, location

moment, location

moment, location

±angle, ±angle, distance, fraction-of-day hebrew-year location tibetan-year

moment, location real moment moment real moment

±angle range moment moment moment location boolean ±angle fixed-date ±angle angle angle distance angle angle (continued)

352

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

lunar-longitude lunar-parallax lunar-phase lunar-phase-at-or-after lunar-phase-at-orbefore major-solar-term-onor-after mawlid-an-nabi mayan-baktun mayan-calendar-roundon-or-before

moment

moment, location moment

phase, moment

phase, moment

angle angle phase moment moment

fixed-date

moment

gregorian-year mayan-long-count-date

mayan-haab-date, mayan-tzolkin-date, fixed-date

mayan-haab-month, mayan-haab-day mayan-haab-date fixed-date mayan-haab-date

mayan-haab-date, fixed-date

list-of-fixed-dates mayan-baktun fixed-date (or bogus)

mayan-haab-date mayan-long-count-date mayan-long-count-date

mayan-baktun, mayan-katun, mayan-tun, mayan-uinal, mayan-kin fixed-date

nonnegative-integer mayan-katun mayan-kin mayan-long-count-date

mayan-long-count-date

mayan-tzolkin-number, mayan-tzolkin-name fixed-date

mayan-tun mayan-tzolkin-date

mayan-tzolkin-date mayan-tzolkin-date

mayan-tzolkin-date, fixed-date mayan-tzolkin-date mayan-long-count-date fixed-date

mayan-tzolkin-name mayan-tzolkin-number fixed-date

mayan-haab-date mayan-haab-day mayan-haab-from-fixed mayan-haab-month mayan-haab-on-orbefore mayan-haab-ordinal mayan-katun mayan-kin mayan-long-count-date

mayan-long-countfrom-fixed mayan-tun mayan-tzolkin-date mayan-tzolkin-fromfixed mayan-tzolkin-name mayan-tzolkin-number mayan-tzolkin-on-orbefore mayan-tzolkin-ordinal mayan-uinal mayan-year-bearerfrom-fixed mean-lunar-longitude memorial-day mesha-samkranti midday midday-in-tehran

real gregorian-year gregorian-year

fixed-date, location fixed-date

mayan-haab-date mayan-haab-day mayan-haab-date mayan-haab-month fixed-date

mayan-long-count-date

mayan-tzolkin-date

nonnegative-integer mayan-uinal mayan-tzolkin-name (or bogus) angle fixed-date rational-moment moment moment

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

midnight midnight-in-china midnight-in-paris minor-solar-term-onor-after minute mjd-from-fixed molad moment-from-jd moment-of-depression

fixed-date, location fixed-date fixed-date fixed-date

moment moment moment moment

clock-time fixed-date

hebrew-month, hebrew-year julian-day-number

moment, location, ±angle, boolean real real gregorian-year moment moment

—, integer, integer→boolean

fixed-date, location

minute julian-day-number moment moment moment (or bogus)

roman-month

integer, day-of-week, gregorian-date integer moment moment fixed-date

nones fixed-date moment angle angle hebrew-date

gregorian-year

fixed-date

fixed-date

islamic-date

old-hindu-lunar-year, old-hindu-lunar-month, old-hindu-lunar-leap, old-hindu-lunar-day old-hindu-lunar-date fixed-date

old-hindu-lunar-date

old-hindu-lunar-date old-hindu-lunar-year

old-hindu-lunar-leap boolean

old-hindu-lunar-date old-hindu-lunar-date fixed-date

old-hindu-lunar-month old-hindu-lunar-year hindu-solar-date

moon-node mt naw-ruz new-moon-at-or-after new-moon-before next nighttime-temporalhour nones-of-month nth-kday nth-new-moon nutation obliquity observational-hebrewfrom-fixed observational-hebrewnew-year observational-islamicfrom-fixed old-hindu-lunar-date

old-hindu-lunar-day old-hindu-lunar-fromfixed old-hindu-lunar-leap old-hindu-lunar-leapyear? old-hindu-lunar-month old-hindu-lunar-year old-hindu-solar-fromfixed

353

angle distance fixed-date moment moment integer real (or bogus)

old-hindu-lunar-day old-hindu-lunar-date

(continued)

354

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

omer orthodox-easter passover pentecost persian-date

fixed-date gregorian-year gregorian-year gregorian-year

persian-year, persian-month, persian-day fixed-date fixed-date

omer-count (or bogus) fixed-date fixed-date fixed-date persian-date

persian-from-fixed persian-new-year-onor-before phasis-on-or-after phasis-on-or-before poly positions-in-range

possible-hebrew-days precession purim qing-ming quotient radians-from-degrees rama rd right-ascension roman-count roman-date

roman-event roman-from-fixed roman-leap roman-month roman-year sacred-wednesdays sacred-wednesdays-inrange sec seconds secs sh-ela shift-days shiva short-kislev? sidereal-from-moment sidereal-solar-longitude

persian-date fixed-date

fixed-date, location

fixed-date, location

real, list-of-reals

positive-integer, positive-integer, nonnegative-integer, range

hebrew-month, hebrew-day moment gregorian-year gregorian-year

real, nonzero-real real gregorian-year moment

moment, angle, angle roman-date

roman-year, roman-month, roman-event, roman-count, roman-leap roman-date fixed-date roman-date roman-date roman-date gregorian-year range

roman-event roman-date roman-leap roman-month roman-year list-of-fixed-dates list-of-fixed-dates

real clock-time real gregorian-year

list-of-weekdays, integer gregorian-year hebrew-year moment moment

duration second angle list-of-fixed-dates list-of-weekdays list-of-fixed-dates boolean angle season

fixed-date fixed-date real list-of-fixed-dates

list-of-weekdays angle fixed-date fixed-date integer radian list-of-fixed-dates moment angle roman-count roman-date

Appendix A. Function, Parameter, and Constant Types

Function

Parameter Type(s)

Result Type

sidereal-zodiac sigma

moment

list-of-pairs, list-of-reals→real angle

moment, location, ±angle real moment

season, moment standard-date

moment, location

moment, location

moment, location

hindu-solar-month real

sin-degrees sine-offset solar-anomaly solar-longitude solar-longitude-after standard-day standard-from-local standard-from-sundial standard-fromuniversal standard-month standard-year start sum sunrise sunset sunset-in-haifa ta-anit-esther tangent-degrees tibetan-date

tibetan-day tibetan-from-fixed tibetan-leap-day tibetan-leap-month tibetan-leap-month? tibetan-month tibetan-moon-equation tibetan-new-year tibetan-sun-equation tibetan-year time-from-clock time-from-moment time-of-day tishah-be-av topocentric-lunaraltitude tumpek

355

amplitude real angle season moment standard-day moment moment (or bogus) moment

standard-date standard-date range

integer→real, —, integer, integer→boolean

fixed-date, location

fixed-date, location fixed-date gregorian-year angle

tibetan-year, tibetan-month, tibetan-leap-month, tibetan-day, tibetan-leap-day tibetan-date fixed-date tibetan-date tibetan-date

tibetan-month, tibetan-year tibetan-date rational-angle gregorian-year rational-angle tibetan-date clock-time moment

hour, minute, second gregorian-year

moment, location

standard-month standard-year moment real

tibetan-day tibetan-date tibetan-leap-day tibetan-leap-month boolean tibetan-month rational list-of-fixed-dates rational tibetan-year time time clock-time fixed-date ±angle

gregorian-year

list-of-fixed-dates

moment moment moment fixed-date real tibetan-date

(continued)

356

Appendix A. Function, Parameter, and Constant Types

(continued) Function

Parameter Type(s)

Result Type

universal-fromdynamical universal-from-local universal-fromstandard unlucky-fridays-inrange vietnamese-location visible-crescent yahrzeit yahrzeit-in-gregorian yoga yom-ha-zikkaron yom-kippur zone zone-from-longitude

moment

moment

moment, location

moment, location

moment moment

range

list-of-fixed-dates

moment

fixed-date, location

hebrew-date, hebrew-year

hebrew-date, gregorian-year fixed-date gregorian-year gregorian-year location angle

location boolean fixed-date list-of-fixed-dates 1 . . . 27 fixed-date fixed-date real duration

A.3 Constant Types and Values

Constant

Type

Value

adar adarii april av armenian-epoch arya-jovian-period arya-lunar-day arya-lunar-month arya-solar-month arya-solar-year ayyam-i-ha august autumn aztec-correlation aztec-tonalpohuallicorrelation aztec-xihuitlcorrelation bahai-epoch bali-epoch

hebrew-month hebrew-month standard-month hebrew-month fixed-date rational rational rational rational rational bahai-month standard-month season fixed-date fixed-date

12 13 4 5 201443 131493125/30352 26298625/26716668 131493125/4452778 210389/6912 210389/576 0 8 180 555403 555299

fixed-date

555202

fixed-date fixed-date

673222 −1721279

Appendix A. Function, Parameter, and Constant Types

357

Constant

Type

Value

bogus chinese-day-nameepoch chinese-epoch chinese-month-nameepoch coptic-epoch december egyptian-epoch elul ethiopic-epoch evening false february first-quarter french-epoch friday full gregorian-epoch haifa hebrew-epoch hindu-anomalisticmonth hindu-anomalistic-year hindu-creation hindu-epoch hindu-locale

string integer

“bogus” 45

fixed-date integer

−963099 57

fixed-date standard-month fixed-date hebrew-month fixed-date boolean boolean standard-month phase fixed-date day-of-week phase fixed-date location fixed-date rational

103605 12 −272787 6 2430 false false 2 90 654415 5 180 1

32.82, 35, 0, 1/12 −1373427 1577917828/57265137

rational fixed-date fixed-date location

1577917828000/4319999613 −714403429586 −1132959

463/20, 2273/30, 0, 383/75 3044 394479457/14438334 394479457/1080000 3179 394479457/13358334 3 227015

30.1, 31.3, 200, 1/12 2 730120.5

961/30, 139/4, 0, 1/12 1 −1721424.5

31.8, 35.2, 800, 1/12

hindu-lunar-era hindu-sidereal-month hindu-sidereal-year hindu-solar-era hindu-synodic-month ides islamic-epoch islamic-locale iyyar j2000 jaffa january jd-epoch jerusalem

standard-year rational rational standard-year rational integer fixed-date location hebrew-month moment location standard-month moment location

(continued)

358

Appendix A. Function, Parameter, and Constant Types

(continued) Constant

Type

Value

julian-epoch july june kalends kislev last-quarter march marheshvan may mayan-epoch mayan-haab-epoch mayan-tzolkin-epoch mean-sidereal-year mean-synodic-month mean-tropical-year mecca

fixed-date standard-month standard-month integer hebrew-month phase standard-month hebrew-month standard-month fixed-date fixed-date fixed-date real real real location

mjd-epoch monday morning new nisan nones november october paris

fixed-date day-of-week boolean phase hebrew-month integer standard-month standard-month location

persian-epoch pi saturday september shevat sidereal-start sivan spring summer sunday tammuz tehran tevet thursday tibetan-epoch tishri

fixed-date real day-of-week standard-month hebrew-month angle hebrew-month season season day-of-week hebrew-month location hebrew-month day-of-week fixed-date hebrew-month

−1 7 6 1 9 270 3 8 5 −1137142 −1137490 −1137302 365.25636 29.530588853 365.242189

6427/300, 11947/300, 298, 1/8 678576 1 true 0 1 2 11 10

175811/3600, 187/80, 27, 1/24 226896 3.141592653589793 6 9 11 156.13605090692624 3 0 90 0 4

35.68, 51.42, 1100, 7/48 10 4 294075 7

Appendix A. Function, Parameter, and Constant Types

Constant

Type

Value

true tuesday ujjain

boolean day-of-week location

wednesday winter year-rome-founded

day-of-week season julian-year

true 2

463/20 45461/600 0 45461/216000 3 270 −753

359

Astronomical clock designed and made in Norway by Rasmus Sornes between 1958 and 1964. It computes sidereal time, apparent solar time, mean solar time, Gregorian date (taking the leap rule fully into account), solar and lunar eclipses, precession, and the positions of all planets. (Courtesy of The Time Museum, Rockford, IL.)

360

361

Please bear in mind the limits of the License and that the copyright on this book includes the code. Also please keep in mind that if the result of any calculation is critical, it should be verified by independent means. For licensing information about nonpersonal and other uses, contact the authors. The code is distributed in the hope that it may be useful but without any warranty as to the accuracy of its output and with liability limited to return of the price of this book, which restrictions are set forth on page xxviii.

http://www.cambridge.org/us/9780521702386

This appendix contains the complete Common Lisp implementation of the calendar functions described in the text. The functions in the text were automatically typeset from the definitions in this appendix. These functions are available over the World Wide Web at

—Donald E. Knuth: “Computer Science and its Relation to Mathematics,” American Mathematical Monthly (1974)

It has been often said that a person does not really understand something until he teaches it to someone else. Actually a person does not really understand something until he can teach it to a computer, i.e., express it as an algorithm.

Lisp Implementation

Appendix B

4

3

2

1

4

3

2

1

;; TYPE day-of-week ;; Residue class for Monday. (+ sunday 1))

(defconstant monday

0)

(defconstant sunday ;; TYPE day-of-week ;; Residue class for Sunday.

For example,

(defconstant constant-name expression)

is used. The function nth, used as (nth i l), extracts the ith element of the list l, indexing from 0; the predicate member, used as (member x l), tests if x is an element of l. To get the first (indexed 0), second, and so on, through tenth elements of a list, we use the functions first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, and tenth. All but the first element of a list is obtained using rest. The empty list is represented by nil. Constants are defined with the defconstant command, which has the syntax

(list e0 e1 e2 ... en)

evaluates to t. The Lisp functions =, /= (not equal), , and >= (greater than or equal) are similar. The predicate evenp tests whether an integer is even. Lists are Lisp’s main data structure. To construct a list (e0 e1 e2 ... en) the expression

( moment

Common Lisp uses L0 after a number to specify unscaled maximum-precision (at least 50-bit) constants. We use the identity function

4

3

2

1

and we implement julian day calculations by writing

4

3

2

1

For example, we compute the day of the week of an R.D. date (page 27) with

(defun function-name (param1 ... paramn) expression)

The function equal can be used to check lists and strings for equality. Functions are defined using the defun command, which has the following syntax:

4

3

2

1

We also use a string constant to signify an error value:

4

3

2

1

362 Appendix B. Lisp Implementation

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

(- date mjd-epoch))

(defun mjd-from-fixed (date) ;; TYPE fixed-date -> julian-day-number ;; Modified julian day number of fixed date.

;; Fixed date of modified julian day number mjd. (+ mjd mjd-epoch))

(defun fixed-from-mjd (mjd) ;; TYPE julian-day-number -> fixed-date

;; Fixed time of start of the modified julian day number. (rd 678576))

(defconstant mjd-epoch ;; TYPE fixed-date

;; TYPE fixed-date -> julian-day-number ;; Julian day number of fixed date. (jd-from-moment date))

(defun jd-from-fixed (date)

;; TYPE julian-day-number -> fixed-date ;; Fixed date of julian day number jd. (floor (moment-from-jd jd)))

(defun fixed-from-jd (jd)

;; TYPE moment -> julian-day-number ;; Julian day number of moment tee. (- tee jd-epoch))

(defun jd-from-moment (tee)

(+ jd jd-epoch))

(defun moment-from-jd (jd) ;; TYPE julian-day-number -> moment ;; Moment of julian day number jd.

to make it easy to adapt the code to an alternate fixed-date enumeration—all that is needed is to change the value of epoch in line 6 of rd. The Common Lisp construct let* defines a sequence of constants (possibly in terms of previously defined constants) and ends with an expression whose value is returned by the construct. ;; Whole part of m/n. (floor m n))

(defun quotient (m n) ;; TYPE (real nonzero-real) -> integer

;; The value of (x mod y) with y instead of 0. (+ y (mod x (- y))))

(defun amod (x y) ;; TYPE (real real) -> real

 k≤ireal) * integer (integer->boolean)) ;; TYPE -> real ;; Sum expression for index = initial and successive

that is, the expression f (i) is summed for all i = k, k + 1, . . . , continuing only as long as the condition p(i) holds. The sum is 0 if p(k) is false. The (mysterious-looking) Common Lisp definition of sum is as follows:

computes

(sum f i k p)

For convenience in expressing our calendar functions in Lisp, we introduce a macro to compute sums (the few instances in which we use macros and not functions avoid the issue of passing functions to functions). The expression

4

3

2

1

is x, the greatest integer less than or equal to x. As a final example of a function definition, note that the Common Lisp function mod always returns a nonnegative value for a positive divisor; we use this property occasionally, but we also need a function like mod with its values adjusted so that the modulus of a multiple of the divisor is the divisor itself rather than 0. To define this function, denoted “amod” also in the text, we write

(floor x)

The floor function can also be called with one argument:

4

3

2

1

As another example of a function definition, we can define a function (inconveniently named floor in Common Lisp) to return the (truncated) integer quotient of two integers, m/n:

Appendix B. Lisp Implementation 363

(,index ,initial (1+ ,index))) ((not ,condition) ,temp))))

(let* ((temp (gensym))) ‘(do ((,temp 0 (+ ,temp ,expression))

;; list is of the form ((i1 l1)..(in ln)). ;; Sum of body for indices i1..in ;; running simultaneously thru lists l1..ln.

‘(apply ’+ (mapcar (function (lambda ,(mapcar ’car list) ,body))

4

7

(+ (first a) (* x (poly x (rest a))))))

;; in list a. (if (equal a nil) 0

(defun poly (x a) ;; TYPE (real list-of-reals) -> real ;; Sum powers of x with coefficients (from order 0 up)

6

5

4

3

2

1

(,condition ,index)))

;; First integer greater or equal to initial such that ;; condition holds. ‘(do ((,index ,initial (1+ ,index)))

(defmacro next (index initial condition) ;; TYPE (* integer (integer->boolean)) -> integer

The function if has three arguments: a boolean condition, a then-expression, and an else-expression. The cond statement lists a sequence of tests and values such as a generalized case statement. Two additional sum-like macros are used for searching; the first implements the MIN function, equation (1.28), and the second implements MAX, equation (1.29):

7

6

5

4

3

2

1

10

9

8

6

5

3

,@(mapcar ’cadr list))))

(defmacro sigma (list body) ;; TYPE (list-of-pairs (list-of-reals->real)) ;; TYPE -> real

2

1

A summation macro sigma and a summation function poly for polynomials are used in the astronomical code:

9

8

7

6

(,end (/ (+ ,h ,l) 2)))))

B.2 Basic Code

(< (mod (- (,f x) ,y) 360) (deg 180)) (< (- u l) ,varepsilon))))

;; f at y within interval [a,b]. (let* ((varepsilon 1/100000)); Desired accuracy ‘(binary-search l ,a u ,b x

(defmacro invert-angular (f y a b) ;; TYPE (real->angle real real real) -> real ;; Use bisection to find inverse of angular function

Binary search is used mainly for function inversion:

2

1

;; TYPE standard-date -> standard-month

(defun standard-month (date)

To extract a particular component from a date, we use, when necessary, the functions standard-month, standard-day, and standard-year. For example:

8

7

6

5

4

3

2

1

11

10

9

8

7

6

(,left false ,test) (,l ,lo (if ,left ,l ,x)) (,h ,hi (if ,left ,x ,h)))

;; end holds. test determines when to go left. (let* ((left (gensym))) ‘(do* ((,x false (/ (+ ,h ,l) 2))

5

4

3

;; TYPE (* real * real * (real->boolean) ;; TYPE ((real real)->boolean)) -> real ;; Bisection search for x in [lo,hi] such that

(defmacro binary-search (l lo h hi x test end)

We also use binary search—see equation (1.30)—expressed as the macro binary-search:

((not ,condition) (1- ,index))))

;; Last integer greater or equal to initial such that ;; condition holds. ‘(do ((,index ,initial (1+ ,index)))

(defmacro final (index initial condition) ;; TYPE (* integer (integer->boolean)) -> integer

2

1

6

5

4

3

2

1

364 Appendix B. Lisp Implementation

(first date))

(defun standard-year (date) ;; TYPE standard-date -> standard-year ;; Year field of date = (year month day).

(third date))

(defun standard-day (date) ;; TYPE standard-date -> standard-day ;; Day field of date = (year month day).

;; Month field of date = (year month day). (second date))

4

3

2

(floor tee))

(defun fixed-from-moment (tee) ;; TYPE moment -> fixed-date ;; Fixed-date from moment tee.

1

3

2

(defun time-of-day (hour minute second) ;; TYPE (hour minute second) -> clock-time (list hour minute second))

(third clock))

(defun seconds (clock) ;; TYPE clock-time -> second

(second clock))

(defun minute (clock) ;; TYPE clock-time -> minute

(first clock))

(defun hour (clock) ;; TYPE clock-time -> hour

1

3

2

1

3

2

1

3

2

1

Such constructors and selectors could be defined as macros. In languages like C or C++, these would be more naturally be field selection in fixed-size records rather than lists. We also have

4

3

2

1

4

3

2

1

4

3

;; Time from moment tee. (mod tee 1))

3

3

2

1

9

8

7

6

5

4

3

2

1

4

3

2

1

4

3

;; Time of day from hms = (hour minute second).

(defun time-from-clock (hms) ;; TYPE clock-time -> time

r))))

(let* ((r (list-range (rest ell) range))) (if (in-range? (first ell) range) (append (list (first ell)) r)

;; Those moments in list ell that occur in range. (if (equal ell nil) nil

(defun list-range (ell range) ;; TYPE (list-of-moments range) -> range

( boolean ;; True if tee is in range.

;; TYPE range -> moment ;; End t1 of range=[t0,t1]. (second range))

(defun end (range)

1 2

(first range))

(defun start (range) ;; TYPE range -> moment ;; Start t0 of range=[t0,t1].

;; TYPE (moment moment) -> range ;; Closed interval [t0,t1]. (list t0 t1))

4

3

2

1

4

3

2

1

4

(defun interval (t0 t1)

(defun time-from-moment (tee) ;; TYPE moment -> time

2

1

Appendix B. Lisp Implementation 365

(fixed-from-jd 1448638))

TYPE fixed-date Fixed date of start of the Egyptian (Nabonasser) calendar. JD 1448638 = February 26, 747 BCE (Julian).

6

5

4

3

;; ;; ;; ;;

(defconstant egyptian-epoch

;; TYPE (egyptian-year egyptian-month egyptian-day) ;; TYPE -> egyptian-date (list year month day))

(defun egyptian-date (year month day)

B.3 The Egyptian/Armenian Calendars

(m (floor (* 60 (mod alpha 1)))) (s (mod (* alpha 60 60) 60))) (degrees-minutes-seconds d m s)))

;; List of degrees-arcminutes-arcseconds from angle ;; alpha in degrees. (let* ((d (floor alpha))

(defun angle-from-degrees (alpha) ;; TYPE angle -> list-of-reals

2

1

4

3

2

1

8

7

6

5

4

3

2

1

8

7

6

5

(second (mod (* time 24 60 60) 60))) (time-of-day hour minute second)))

(let* ((time (time-from-moment tee)) (hour (floor (* time 24))) (minute (floor (mod (* time 24 60) 60)))

4

3

2

(defun clock-from-moment (tee) ;; TYPE moment -> clock-time ;; Clock time hour:minute:second from moment tee.

(s (seconds hms))) (* 1/24 (+ h (/ (+ m (/ s 60)) 60)))))

(let* ((h (hour hms)) (m (minute hms))

1

7

6

5

4

(month; Calculate the month by division. (1+ (quotient (mod days 365) 30))) (day ; Calculate the day by subtraction. (- days (* 365 (1- year))

8

11

5

4

3

2

1

4

3

2

1

16

15

14

13

12

10

9

7

6

;; Fixed date of start of the Armenian calendar. ;; = July 11, 552 CE (Julian). (rd 201443))

(defconstant armenian-epoch ;; TYPE fixed-date

(list year month day))

(defun armenian-date (year month day) ;; TYPE (armenian-year armenian-month armenian-day) ;; TYPE -> armenian-date

(* 30 (1- month)) -1))) (egyptian-date year month day)))

(- date egyptian-epoch)) (year ; Year since epoch. (1+ (quotient days 365)))

5

4

3

;; TYPE fixed-date -> egyptian-date ;; Egyptian equivalent of fixed date. (let* ((days ; Elapsed days since epoch.

(defun egyptian-from-fixed (date)

(* 30 (1- month)); Days in prior months this year day -1))) ; Days so far this month

(year (standard-year e-date))) (+ egyptian-epoch ; Days before start of calendar (* 365 (1- year)); Days in prior years

;; Fixed date of Egyptian date e-date. (let* ((month (standard-month e-date)) (day (standard-day e-date))

(defun fixed-from-egyptian (e-date) ;; TYPE egyptian-date -> fixed-date

2

1

10

9

8

7

6

5

4

3

2

1

366 Appendix B. Lisp Implementation

5

4

3

2

1

5

date) fixed-date) -> fixed-date k-day nearest fixed date. k=1 means Monday, and so on.

(kday-on-or-before k (+ date 3)))

(defun kday-nearest (k ;; TYPE (day-of-week ;; Fixed date of the ;; k=0 means Sunday,

;; k=0 means Sunday, k=1 means Monday, and so on. (kday-on-or-before k (+ date 6)))

4

3

2

(defun kday-on-or-after (k date) ;; TYPE (day-of-week fixed-date) -> fixed-date ;; Fixed date of the k-day on or after fixed date.

;; Fixed date of the k-day on or before fixed date. ;; k=0 means Sunday, k=1 means Monday, and so on. (- date (day-of-week-from-fixed (- date k))))

(defun kday-on-or-before (k date) ;; TYPE (day-of-week fixed-date) -> fixed-date

B.4 Cycles of Days

(+ date (- egyptian-epoch armenian-epoch))))

;; TYPE fixed-date -> armenian-date ;; Armenian equivalent of fixed date. (egyptian-from-fixed

(defun armenian-from-fixed (date)

1

5

4

3

2

1

5

4

3

2

1

10

9

8

7

(egyptian-date year month day)) egyptian-epoch))))

(year (standard-year a-date))) (+ armenian-epoch (- (fixed-from-egyptian

6

5

4

;; Fixed date of Armenian date a-date. (let* ((month (standard-month a-date)) (day (standard-day a-date))

(defun fixed-from-armenian (a-date) ;; TYPE armenian-date -> fixed-date

3

2

1

4

3

2

1

4

3

2

1

5

4

3

2

1

4

3

2

1

5

4

3

2

1

5

4

3

2

1

2)

(defconstant february ;; TYPE standard-month ;; February on Julian/Gregorian calendar.

;; TYPE standard-month ;; January on Julian/Gregorian calendar. 1)

(defconstant january

;; calendar. (rd 1))

(defconstant gregorian-epoch ;; TYPE fixed-date ;; Fixed date of start of the (proleptic) Gregorian

(list year month day))

(defun gregorian-date (year month day) ;; TYPE (gregorian-year gregorian-month gregorian-day) ;; TYPE -> gregorian-date

B.5 The Gregorian Calendar

;; k=0 means Sunday, k=1 means Monday, and so on. (kday-on-or-before k (- date 1)))

(defun kday-before (k date) ;; TYPE (day-of-week fixed-date) -> fixed-date ;; Fixed date of the k-day before fixed date.

;; Fixed date of the k-day after fixed date. ;; k=0 means Sunday, k=1 means Monday, and so on. (kday-on-or-before k (+ date 7)))

(defun kday-after (k date) ;; TYPE (day-of-week fixed-date) -> fixed-date

Appendix B. Lisp Implementation 367

4

3

2

1

4

3

2

10)

(defconstant october ;; TYPE standard-month ;; October on Julian/Gregorian calendar.

9)

(defconstant september ;; TYPE standard-month ;; September on Julian/Gregorian calendar.

1

4

3

;; TYPE standard-month ;; August on Julian/Gregorian calendar. 8)

(defconstant august

;; July on Julian/Gregorian calendar. 7)

(defconstant july ;; TYPE standard-month

2

1

4

3

2

1

4

3

2

6)

(defconstant june ;; TYPE standard-month ;; June on Julian/Gregorian calendar.

1

4

3

;; TYPE standard-month ;; May on Julian/Gregorian calendar. 5)

(defconstant may

;; TYPE standard-month ;; April on Julian/Gregorian calendar. 4)

(defconstant april

;; March on Julian/Gregorian calendar. 3)

(defconstant march ;; TYPE standard-month

2

1

4

3

2

1

4

3

2

1

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

7

6

5

4

3

2

1

4

3

2

1

4

3

2

1

0

(quotient ; Days in prior months this year... (- (* 367 month) 362); ...assuming 30-day Feb 12) (if ( fixed-date

(list 100 200 300)))))

;; calendar. (and (= (mod g-year 4) 0) (not (member (mod g-year 400)

(defun gregorian-leap-year? (g-year) ;; TYPE gregorian-year -> boolean ;; True if g-year is a leap year on the Gregorian

;; TYPE standard-month ;; December on Julian/Gregorian calendar. 12)

(defconstant december

;; November on Julian/Gregorian calendar. 11)

(defconstant november ;; TYPE standard-month

368 Appendix B. Lisp Implementation

; Days so far this month.

21

(defun gregorian-year-end (g-year) ;; TYPE gregorian-year -> fixed-date

1

20

19

18

17

16

15

14

13

12

11

9

(year (+ (* 400 n400)

(d3 ; Prior days not in n400, n100, or n4. (mod d2 1461)) (n1 ; Years not in n400, n100, or n4. (quotient d3 365))

(mod d1 36524)) (n4 ; 4-year cycles not in n400 or n100. (quotient d2 1461))

(n100 ; 100-year cycles not in n400. (quotient d1 36524)) (d2 ; Prior days not in n400 or n100.

10

8

(quotient d0 146097)) (d1 ; Prior days not in n400. (mod d0 146097))

(let* ((d0 ; Prior days. (- date gregorian-epoch)) (n400 ; Completed 400-year cycles.

(defun gregorian-year-from-fixed (date) ;; TYPE fixed-date -> gregorian-year ;; Gregorian year corresponding to the fixed date.

7

6

5

4

3

2

1

5

4

3

2

;; Fixed date of December 31 in g-year. (fixed-from-gregorian (gregorian-date g-year december 31)))

2

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

5

4

3

1

(gregorian-date g-year january 1)))

5

4

3

27

26

25

24

23

22

;; TYPE gregorian-year -> fixed-date ;; Fixed date of January 1 in g-year. (fixed-from-gregorian

(defun gregorian-new-year (g-year)

-2)) day)))

(if (gregorian-leap-year? year) -1

2

1

23

22

21

20

(gregorian-date year month day)))

(1+ (- date (fixed-from-gregorian (gregorian-date year month 1))))))

(+ (* 12 (+ prior-days correction)) 373) 367)) (day ; Calculate the day by subtraction.

2))) (month ; Assuming a 30-day Feb (quotient

0 (if (gregorian-leap-year? year) 1

(correction; To simulate a 30-day Feb (if (< date (fixed-from-gregorian (gregorian-date year march 1)))

(let* ((year (gregorian-year-from-fixed date)) (prior-days; This year (- date (gregorian-new-year year)))

(defun gregorian-from-fixed (date) ;; TYPE fixed-date -> gregorian-date ;; Gregorian (year month day) corresponding to fixed date.

(interval (gregorian-new-year g-year) (gregorian-year-end g-year)))

(defun gregorian-year-range (g-year) ;; TYPE gregorian-year -> range ;; The range of moments in Gregorian year g-year.

(1+ year)))); Date is ordinal day (1+ (mod d3 365)) ; in (1+ year).

n1))) (if (or (= n100 4) (= n1 4)) year ; Date is day 366 in a leap year.

(* 100 n100) (* 4 n4)

Appendix B. Lisp Implementation 369

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

6

5

4

3

2

1

6

5

4

3

2

1

6

5

4

3

2

1

(quotient (1- y) 100))

(* 365 (1- y)); Ordinary days since epoch. (quotient (1- y) 4); Julian leap days since epoch... (; ...minus century years since epoch...

(y (+ year (quotient (+ month 9) 12)))) (+ (1- gregorian-epoch) -306 ; Days in March...December.

(day (standard-day g-date)) (year (standard-year g-date)) (m (amod (- month 2) 12))

;; Alternative calculation of fixed date equivalent to the ;; Gregorian date g-date. (let* ((month (standard-month g-date))

(defun alt-fixed-from-gregorian (g-date) ;; TYPE gregorian-date -> fixed-date

(gregorian-year-end (standard-year g-date))))

;; Days remaining in year after Gregorian date g-date. (gregorian-date-difference g-date

(defun days-remaining (g-date) ;; TYPE gregorian-date -> nonnegative-integer

g-date))

;; Day number in year of Gregorian date g-date. (gregorian-date-difference (gregorian-year-end (1- (standard-year g-date)))

(defun day-number (g-date) ;; TYPE gregorian-date -> positive-integer

(fixed-from-gregorian g-date1)))

;; Number of days from Gregorian date g-date1 until ;; g-date2. (- (fixed-from-gregorian g-date2)

(defun gregorian-date-difference (g-date1 g-date2) ;; TYPE (gregorian-date gregorian-date) -> integer 17

5

4

3

2

1

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

23

22

21

20

19

18

(quotient (- date gregorian-epoch -2)

(defun alt-gregorian-year-from-fixed (date) ;; TYPE fixed-date -> gregorian-year ;; Gregorian year corresponding to the fixed date. (let* ((approx ; approximate year

(gregorian-date year month 1)))))) (gregorian-date year month day)))

(day (1+ (- date (fixed-from-gregorian

3) 12)) (year (- y (quotient (+ month 9) 12)))

(amod (+ (quotient (+ (* 5 prior-days) 2) 153)

(- date (fixed-from-gregorian (gregorian-date (1- y) march 1)))) (month

date 306))) (prior-days

;; corresponding to fixed date. (let* ((y (gregorian-year-from-fixed (+ (1- gregorian-epoch)

(defun alt-gregorian-from-fixed (date) ;; TYPE fixed-date -> gregorian-date ;; Alternative calculation of Gregorian (year month day)

(* 30 (1- m)) day))) ; Days so far this month.

(quotient ; Days in prior months this year. (1- (* 3 m)) 5)

(quotient ; ...plus years since epoch divisible... (1- y) 400); ...by 400.

370 Appendix B. Lisp Implementation

;; and so on. (nth-kday 1 k g-date))

5

6

4

3

;; TYPE (day-of-week gregorian-date) -> fixed-date ;; Fixed date of first k-day on or after Gregorian date ;; g-date. A k-day of 0 means Sunday, 1 means Monday,

(defun first-kday (k g-date)

(kday-after k (fixed-from-gregorian g-date)))))

2

1

12

11

10

9

8

7

(+ (* 7 n) (kday-before k (fixed-from-gregorian g-date))) (+ (* 7 n)

;; or before g-date. A k-day of 0 means Sunday, 1 ;; means Monday, and so on. (if (> n 0)

6

5

4

;; Fixed date of n-th k-day after Gregorian date ;; g-date. If n>0, return the n-th k-day on or ;; after g-date. If n fixed-date

;; Gregorian year g-yaer. (fixed-from-gregorian (gregorian-date g-year july 4)))

(defun independence-day (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of United States Independence Day in

3

2

1

5

4

3

2

1

15

14

13

12

approx (1+ approx))))

(- (quotient approx 100)) (quotient approx 400)))) (if (< date start)

10

9

11

146097/400)) ; start of next year

(+ gregorian-epoch (* 365 approx) (quotient approx 4)

(start

8

7

6

6

5

4

3

2

1

6

5

;; November). (first-kday sunday (gregorian-date g-year november 1)))

;; TYPE gregorian-year -> fixed-date ;; Fixed date of the end of United States daylight saving ;; time in Gregorian year g-year (the first Sunday in

(defun daylight-saving-end (g-year)

;; saving time in Gregorian year g-year (the second ;; Sunday in March). (nth-kday 2 sunday (gregorian-date g-year march 1))) 4

3

2

(defun daylight-saving-start (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of the start of United States daylight

(first-kday tuesday (gregorian-date g-year november 2)))

;; Fixed date of United States Election Day in Gregorian ;; year g-year (the Tuesday after the first Monday in ;; November).

(defun election-day (g-year) ;; TYPE gregorian-year -> fixed-date

;; year g-year (the last Monday in May). (last-kday monday (gregorian-date g-year may 31)))

(defun memorial-day (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of United States Memorial Day in Gregorian

;; year g-year (the first Monday in September). (first-kday monday (gregorian-date g-year september 1)))

(defun labor-day (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of United States Labor Day in Gregorian

(nth-kday -1 k g-date))

;; Fixed date of last k-day on or before Gregorian date ;; g-date. A k-day of 0 means Sunday, 1 means Monday, ;; and so on.

(defun last-kday (k g-date) ;; TYPE (day-of-week gregorian-date) -> fixed-date

1

6

5

4

3

2

1

5

4

3

2

1

5

4

3

2

1

6

5

4

3

2

1

Appendix B. Lisp Implementation 371

16

15

14

13

12

11

10

9

8

7

6

(unlucky-fridays-in-range (interval (1+ fri) b))) nil)))

(if (= (standard-day date) 13) (list fri) nil)

(date (gregorian-from-fixed fri))) (if (in-range? fri range) (append

(let* ((a (start range)) (b (end range)) (fri (kday-on-or-after friday a))

5

4

3

;; TYPE range -> list-of-fixed-dates ;; List of Fridays within range of dates ;; that are day 13 of Gregorian months.

(defun unlucky-fridays-in-range (range)

;; Fixed date of Epiphany in U.S. in Gregorian year ;; g-year (the first Sunday after January 1). (first-kday sunday (gregorian-date g-year january 2)))

2

1

5

4

3

2

1

7

6

(defun epiphany (g-year) ;; TYPE gregorian-year -> fixed-date

(kday-nearest sunday (fixed-from-gregorian (gregorian-date g-year november 30))))

5

4

3

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Advent in Gregorian year g-year ;; (the Sunday closest to November 30).

(defun advent (g-year)

;; Fixed date of Christmas in Gregorian year g-year. (fixed-from-gregorian (gregorian-date g-year december 25)))

(defun christmas (g-year) ;; TYPE gregorian-year -> fixed-date

2

1

5

4

3

2

1

;; TYPE standard-year -> julian-year ;; Negative value to indicate a BCE Julian year. (- n))

(defun bce (n)

9

8

7

6

5

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

year)))

(day (standard-day j-date)) (year (standard-year j-date)) (y (if (< year 0) (1+ year) ; No year zero

;; TYPE julian-date -> fixed-date ;; Fixed date equivalent to the Julian date j-date. (let* ((month (standard-month j-date))

(defun fixed-from-julian (j-date)

;; TYPE fixed-date ;; Fixed date of start of the Julian calendar. (fixed-from-gregorian (gregorian-date 0 december 30)))

(defconstant julian-epoch

;; TYPE julian-year -> boolean ;; True if j-year is a leap year on the Julian calendar. (= (mod j-year 4) (if (> j-year 0) 0 3)))

(defun julian-leap-year? (j-year)

;; TYPE (julian-year julian-month julian-day) ;; TYPE -> julian-date (list year month day))

(defun julian-date (year month day)

n)

(defun ce (n) ;; TYPE standard-year -> julian-year ;; Positive value to indicate a CE Julian year.

and positive numbers for C.E. (Julian) years:

4

3

2

1

In the Lisp code we use −n for year n B.C.E. (Julian):

B.6 The Julian Calendar

372 Appendix B. Lisp Implementation

; Days before start of calendar ; Ordinary days since epoch.

; Correct for 28- or 29-day Feb

; Days so far this month.

(- date (fixed-from-julian (julian-date year january 1)))) (correction; To simulate a 30-day Feb

11

14 15

; Calculate the day by subtraction.

(day

13

12

24

23

22

21

11

10

9

8

7

(month ; Assuming a 30-day Feb (quotient (+ (* 12 (+ prior-days correction)) 373) 367))

(if (julian-leap-year? year) 1 2)))

6

5

4

3

2

1

6

5

4

3

2

1

6

5

4

(julian-date y-prime j-month j-day))))

;; The possible occurrences in one year are (date1 (fixed-from-julian (julian-date y j-month j-day))) (date2 (fixed-from-julian

(y-prime (if (= y -1) 1 (1+ y)))

;; j-day that occur in Gregorian year g-year. (let* ((jan1 (gregorian-new-year g-year)) (y (standard-year (julian-from-fixed jan1)))

;; TYPE (julian-month julian-day gregorian-year) ;; TYPE -> list-of-fixed-dates ;; List of the fixed dates of Julian month j-month, day

(defun julian-in-gregorian (j-month j-day g-year)

(if ( nonzero-integer ;; Year AUC equivalent to Julian year

(+ year year-rome-founded)))

;; Julian year equivalent to AUC year (if ( julian-year

;; Year on the Julian calendar of the founding of Rome. (bce 753))

(defconstant year-rome-founded ;; TYPE julian-year

(julian-date year month 1)))))) (julian-date year month day)))

(1+ (- date (fixed-from-julian

1

4

3

2

1

28

27

26

25

20

19

18

17

16

15

14

13

12

10

9

(if (< date (fixed-from-julian (julian-date year march 1))) 0

(1- approx) ; No year 0. approx)) (prior-days; This year

8

7

6

(quotient (+ (* 4 (- date julian-epoch)) 1464) 1461)) (year (if ( julian-date ;; Julian (year month day) corresponding to fixed date. (let* ((approx ; Nominal year.

(defun julian-from-fixed (date)

day)))

(if (julian-leap-year? year) -1 -2))

12) (if ( roman-event

1

3

;; TYPE roman-date -> roman-month (second date))

(defun roman-month (date)

;; TYPE roman-date -> roman-year (first date))

(defun roman-year (date)

;; TYPE (roman-year roman-month roman-event roman-count ;; TYPE roman-leap) -> roman-date (list year month event count leap))

2

1

3

2

1

4

3

2

1

4

2

4

(defun roman-date (year month event count leap)

;; Class of Nones. 2)

3

2

(defconstant nones ;; TYPE roman-event

1)

(defconstant kalends ;; TYPE roman-event ;; Class of Kalends.

1

4

3

2

1

In languages like Lisp that allow functions as parameters, one could write a generic version of this function to collect holidays of any given calendar and pass fixed-from-julian to it as an additional parameter. We have deliberately avoided this and similar advanced language features in the interests of portability.

17

16

18

17

16

15

14

13

12

11

10

9

((= day 1) (roman-date year month kalends 1 false))

(kalends1 (fixed-from-roman (roman-date year-prime month-prime kalends 1 false)))) (cond

(if (/= year -1) (1+ year) 1)))

(month-prime (amod (1+ month) 12)) (year-prime (if (/= month-prime 1) year

8

7

6

(month (standard-month j-date)) (day (standard-day j-date)) (year (standard-year j-date))

;; TYPE fixed-date -> roman-date ;; Roman name for fixed date. (let* ((j-date (julian-from-fixed date))

(defun roman-from-fixed (date)

;; Date of Nones in Roman month. (- (ides-of-month month) 8))

(defun nones-of-month (month) ;; TYPE roman-month -> nones

13))

;; Date of Ides in Roman month. (if (member month (list march may july october)) 15

(defun ides-of-month (month) ;; TYPE roman-month -> ides

(fifth date))

(defun roman-leap (date) ;; TYPE roman-date -> roman-leap

(fourth date))

(defun roman-count (date) ;; TYPE roman-date -> roman-count

5

4

3

2

1

4

3

2

1

6

5

4

3

2

1

3

2

1

3

2

1

374 Appendix B. Lisp Implementation

19

(month (roman-month r-date)) (year (roman-year r-date))) (+ (cond

7

17

16

15

14

13

12

11

10

9

8

6

5

18

8 9

(julian-date year month (ides-of-month month)))))

7

6

5

4

3

2

1

4

3

2

1

4

3

2

1

3

2

1

27

26

25

24

23

22

21

20

19

(fixed-from-julian (julian-date year month (nones-of-month month)))) ((= event ides) (fixed-from-julian

((= event kalends) (fixed-from-julian (julian-date year month 1))) ((= event nones)

(let* ((leap (roman-leap r-date)) (count (roman-count r-date)) (event (roman-event r-date))

4

3

2

(defun fixed-from-roman (r-date) ;; TYPE roman-date -> fixed-date ;; Fixed date for Roman name r-date.

(roman-date year march kalends (- 31 day) (= day 25))))))

(roman-date year march kalends (- 30 day) false)) (true ; February of a leap year, on or after leap day

1

37

36

35

34

33

32

31

30

29

28

(1+ (- kalends1 date)) false)) ((< day 25) ; February of a leap year, before leap day

; After the Ides, in a month that is not February of a ; leap year (roman-date year-prime month-prime kalends

27

26

25

(1+ (- (ides-of-month month) day)) false)) ((or (/= month february) (not (julian-leap-year? year)))

(1+ (- (nones-of-month month) day)) false)) (( boolean ;; True if c-year is a leap year on the Coptic calendar.

;; TYPE fixed-date ;; Fixed date of start of the Coptic calendar. (fixed-from-julian (julian-date (ce 284) august 29)))

(defconstant coptic-epoch

(list year month day))

(defun coptic-date (year month day) ;; TYPE (coptic-year coptic-month coptic-day) -> coptic-date

B.7 The Coptic and Ethiopic Calendars

1 ; Leap day 0)))) ; Non-leap day

0 ; After Ides until leap day 1) ; Otherwise (if leap

(= month march) (= event kalends) (>= 16 count 6))

(- count) (if (and (julian-leap-year? year)

Appendix B. Lisp Implementation 375

7

6

5

4

3

2

1

4

3

(+ ethiopic-epoch

;; Fixed date of Ethiopic date e-date. (let* ((month (standard-month e-date)) (day (standard-day e-date)) (year (standard-year e-date)))

(defun fixed-from-ethiopic (e-date) ;; TYPE ethiopic-date -> fixed-date

;; TYPE fixed-date ;; Fixed date of start of the Ethiopic calendar. (fixed-from-julian (julian-date (ce 8) august 29)))

(defconstant ethiopic-epoch

1

2

(list year month day))

(defun ethiopic-date (year month day) ;; TYPE (ethiopic-year ethiopic-month ethiopic-day) ;; TYPE -> ethiopic-date

(coptic-date year month 1))))) (coptic-date year month day)))

(day ; Calculate the day by subtraction. (- date -1 (fixed-from-coptic

(- date (fixed-from-coptic (coptic-date year 1 1))) 30)))

1461)) (month; Calculate the month by division. (1+ (quotient

;; Coptic equivalent of fixed date. (let* ((year ; Calculate the year by cycle-of-years formula (quotient (+ (* 4 (- date coptic-epoch)) 1463)

(defun coptic-from-fixed (date) ;; TYPE fixed-date -> coptic-date

(* 30 (1- month)); Days in prior months this year day))) ; Days so far this month

4

3

2

1

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

11

10

3

2

1

5

4

3

2

1

14

13

12

11

10

9

8

7

6

5

4

3

2

1

5

4

3

2

1

10

9

8

;; TYPE (iso-year iso-week iso-day) -> iso-date (list year week day))

(defun iso-date (year week day)

B.8 The ISO Calendar

;; in Gregorian year g-year. (coptic-in-gregorian 4 29 g-year))

(defun coptic-christmas (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates ;; List of zero or one fixed dates of Coptic Christmas

(gregorian-year-range g-year))))

(date2 (fixed-from-coptic (coptic-date (1+ y) c-month c-day)))) (list-range (list date1 date2)

;; The possible occurrences in one year are (date1 (fixed-from-coptic (coptic-date y c-month c-day)))

;; c-day that occur in Gregorian year g-year. (let* ((jan1 (gregorian-new-year g-year)) (y (standard-year (coptic-from-fixed jan1)))

;; TYPE (coptic-month coptic-day gregorian-year) ;; TYPE -> list-of-fixed-dates ;; List of the fixed dates of Coptic month c-month, day

(defun coptic-in-gregorian (c-month c-day g-year)

(coptic-from-fixed (+ date (- coptic-epoch ethiopic-epoch))))

(defun ethiopic-from-fixed (date) ;; TYPE fixed-date -> ethiopic-date ;; Ethiopic equivalent of fixed date.

coptic-epoch))))

(- (fixed-from-coptic (coptic-date year month day))

376 Appendix B. Lisp Implementation

11

13

12

(fixed-from-iso (iso-date year 1 1)))

(1+ approx) approx)) (week (1+ (quotient (- date

9

10

8

7

(year (if (>= date (fixed-from-iso (iso-date (1+ approx) 1 1)))

;; ISO (year week day) corresponding to the fixed date. (let* ((approx ; Year may be one too small. (gregorian-year-from-fixed (- date 3)))

6

5

4

3

2

1

11

10

(defun iso-from-fixed (date) ;; TYPE fixed-date -> iso-date

(+ (nth-kday week sunday (gregorian-date (1- year) december 28)) day)))

9

8

7

(year (iso-year i-date))) ;; Add fixed date of Sunday preceding date plus day ;; in week.

6

5

4

3

2

;; Fixed date equivalent to ISO i-date. (let* ((week (iso-week i-date)) (day (iso-day i-date))

(defun fixed-from-iso (i-date) ;; TYPE iso-date -> fixed-date

1

3

2

(defun iso-year (date) ;; TYPE iso-date -> iso-year (first date))

;; TYPE iso-date -> day-of-week (third date))

(defun iso-day (date)

(second date))

(defun iso-week (date) ;; TYPE iso-date -> iso-week

1

3

2

1

3

2

1

14

5

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

9

8

7

6

5

4

3

(day (standard-day i-date))

(defun fixed-from-islamic (i-date) ;; TYPE islamic-date -> fixed-date ;; Fixed date equivalent to Islamic date i-date. (let* ((month (standard-month i-date))

(< (mod (+ 14 (* 11 i-year)) 30) 11))

(defun islamic-leap-year? (i-year) ;; TYPE islamic-year -> boolean ;; True if i-year is an Islamic leap year.

(fixed-from-julian (julian-date (ce 622) july 16)))

(defconstant islamic-epoch ;; TYPE fixed-date ;; Fixed date of start of the Islamic calendar.

(list year month day))

(defun islamic-date (year month day) ;; TYPE (islamic-year islamic-month islamic-day) ;; TYPE -> islamic-date

B.9 The Islamic Calendar

(or (= jan1 thursday) (= dec31 thursday))))

(gregorian-new-year i-year))) (dec31 (day-of-week-from-fixed (gregorian-year-end i-year))))

;; TYPE iso-year -> boolean ;; True if i-year is a long (53-week) year. (let* ((jan1 (day-of-week-from-fixed

(defun iso-long-year? (i-year)

1 2

(iso-date year week day)))

7))) (day (amod (- date (rd 0)) 7)))

16

15

Appendix B. Lisp Implementation 377

(* (1- year) 354) ; Ordinary days since epoch. (quotient ; Leap days since epoch. (+ 3 (* 11 year)) 30)

(* 29 (1- month)) (quotient month 2) day)))

8

11

;; The possible occurrences in one year are

8

7

6

5

;; List of the fixed dates of Islamic month i-month, day ;; i-day that occur in Gregorian year g-year. (let* ((jan1 (gregorian-new-year g-year)) (y (standard-year (islamic-from-fixed jan1)))

(defun islamic-in-gregorian (i-month i-day g-year) ;; TYPE (islamic-month islamic-day gregorian-year) ;; TYPE -> list-of-fixed-dates

(islamic-date year month 1)))))) (islamic-date year month day)))

325)) (day (1+ (- date (fixed-from-islamic

(month (quotient (+ (* 11 prior-days) 330)

4

3

2

1

19

18

17

16

15

14

13

12

11

10

9

8

7

(prior-days (- date (fixed-from-islamic (islamic-date year 1 1))))

(quotient (+ (* 30 (- date islamic-epoch)) 10646) 10631))

6

5

4

;; Islamic date (year month day) corresponding to fixed ;; date. (let* ((year

(defun islamic-from-fixed (date) ;; TYPE fixed-date -> islamic-date

; Days so far this month.

3

2

1

13

12

10

9

; Days in prior months this year

(year (standard-year i-date))) (+ (1- islamic-epoch) ; Days before start of calendar

7

6

9

4

3

2

1

4

3

2

1

4

3

2

1

3

2

1

5

4

3

2

1

;; Sivan is month number 3. 3)

(defconstant sivan ;; TYPE hebrew-month

2)

(defconstant iyyar ;; TYPE hebrew-month ;; Iyyar is month number 2.

1)

(defconstant nisan ;; TYPE hebrew-month ;; Nisan is month number 1.

(list year month day))

(defun hebrew-date (year month day) ;; TYPE (hebrew-year hebrew-month hebrew-day) -> hebrew-date

B.10 The Hebrew Calendar

;; Gregorian year g-year. (islamic-in-gregorian 3 12 g-year))

(defun mawlid-an-nabi (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates ;; List of fixed dates of Mawlid-an-Nabi occurring in

(gregorian-year-range g-year))))

17

16

15

(islamic-date (+ y 2) i-month i-day)))) ;; Combine in one list those that occur in current year (list-range (list date1 date2 date3)

(date2 (fixed-from-islamic (islamic-date (1+ y) i-month i-day))) (date3 (fixed-from-islamic

(date1 (fixed-from-islamic (islamic-date y i-month i-day)))

14

13

12

11

10

378 Appendix B. Lisp Implementation

4

3

2

1

4

3

2

11)

(defconstant shevat ;; TYPE hebrew-month ;; Shevat is month number 11.

10)

(defconstant tevet ;; TYPE hebrew-month ;; Tevet is month number 10.

1

4

3

;; TYPE hebrew-month ;; Kislev is month number 9. 9)

(defconstant kislev

;; Marheshvan is month number 8. 8)

(defconstant marheshvan ;; TYPE hebrew-month

2

1

4

3

2

1

4

3

2

7)

(defconstant tishri ;; TYPE hebrew-month ;; Tishri is month number 7.

1

4

3

;; TYPE hebrew-month ;; Elul is month number 6. 6)

(defconstant elul

;; TYPE hebrew-month ;; Av is month number 5. 5)

(defconstant av

;; Tammuz is month number 4. 4)

(defconstant tammuz ;; TYPE hebrew-month

2

1

4

3

2

1

4

3

2

1

5

4

3

2

1

5

4

3

2

1

6

5

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

(fixed-from-julian (julian-date (bce 3761) october 7)))

;; TYPE fixed-date ;; Fixed date of start of the Hebrew calendar, that is, ;; Tishri 1, 1 AM.

(defconstant hebrew-epoch

;; calendar. (= (mod h-year 7) 0))

(defun hebrew-sabbatical-year? (h-year) ;; TYPE hebrew-year -> boolean ;; True if h-year is a sabbatical year on the Hebrew

adarii adar))

;; TYPE hebrew-year -> hebrew-month ;; Last month of Hebrew year. (if (hebrew-leap-year? h-year)

(defun last-month-of-hebrew-year (h-year)

;; True if h-year is a leap year on Hebrew calendar. (< (mod (1+ (* 7 h-year)) 19) 7))

(defun hebrew-leap-year? (h-year) ;; TYPE hebrew-year -> boolean

;; TYPE hebrew-month ;; Adar II is month number 13. 13)

(defconstant adarii

;; Adar is month number 12. 12)

(defconstant adar ;; TYPE hebrew-month

Appendix B. Lisp Implementation 379

21

1 2

;;

20

19

18

(* 793 (quotient months-elapsed 1080))

;; (parts-elapsed ;; (+ 204 (* 793 (mod months-elapsed 1080)))) ;; (hours-elapsed ;; (+ 11 (* 12 months-elapsed)

17

4

3

2

1

16

15

14

(quotient parts-elapsed 25920))) ;; If (* 13753 months-elapsed) causes integers that ;; are too large, use instead:

13

12

11

10

9

8

7

6

5

4

3

2

1

6

5

4

3

2

1

28

27

26

25

24

23

22

13

12

11

10

9

8

(+ 12084 (* 13753 months-elapsed))) (days ; Whole days since prior noon. (+ (* 29 months-elapsed)

(let* ((months-elapsed ; Since start of Hebrew calendar. (quotient (- (* 235 h-year) 234) 19)) (parts-elapsed; Fractions of days since prior noon.

7

6

5

;; to the epoch of the Hebrew calendar to the mean ;; conjunction (molad) of Tishri of Hebrew year h-year, ;; or one day later.

(defun hebrew-calendar-elapsed-days (h-year) ;; TYPE hebrew-year -> integer ;; Number of days elapsed from the (Sunday) noon prior

-876/25920 (* months-elapsed (+ 29 (hr 12) 793/25920)))))

(- (* 235 y) 234) 19)))) (+ hebrew-epoch

(months-elapsed (+ (- h-month tishri) ;; Months this year. (quotient ;; Months until New Year.

(if (< h-month tishri) (1+ h-year) h-year))

;; Moment of mean conjunction of h-month in Hebrew ;; h-year. (let* ((y ;; Treat Nisan as start of year.

(defun molad (h-month h-year) ;; TYPE (hebrew-month hebrew-year) -> moment

4

3

2

1

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

)

(+ (* 29 months-elapsed) (quotient hours-elapsed 24)))

;; TYPE hebrew-year -> boolean

(defun short-kislev? (h-year)

(member (days-in-hebrew-year h-year) (list 355 385)))

(defun long-marheshvan? (h-year) ;; TYPE hebrew-year -> boolean ;; True if Marheshvan is long in Hebrew year h-year.

((= (- ny1 ny0) 382) ; Previous year too short. 1) (t 0))))

(cond ((= (- ny2 ny1) 356) ; Next year would be too long. 2)

(let* ((ny0 (hebrew-calendar-elapsed-days (1- h-year))) (ny1 (hebrew-calendar-elapsed-days h-year)) (ny2 (hebrew-calendar-elapsed-days (1+ h-year))))

;; TYPE hebrew-year -> {0,1,2} ;; Delays to start of Hebrew year h-year to keep ordinary ;; year in range 353-356 and leap year in range 383-386.

(defun hebrew-year-length-correction (h-year)

(hebrew-year-length-correction h-year)))

;; Fixed date of Hebrew new year h-year. (+ hebrew-epoch (hebrew-calendar-elapsed-days h-year)

(defun hebrew-new-year (h-year) ;; TYPE hebrew-year -> fixed-date

(if (< (mod (* 3 (1+ days)) 7) 3); Sun, Wed, or Fri (+ days 1) ; Delay one day. days)))

;; ;;

;; (quotient parts-elapsed 1080))) ;; (days

380 Appendix B. Lisp Implementation

(not (hebrew-leap-year? h-year))) (and (= h-month marheshvan) (not (long-marheshvan? h-year)))

(and (= h-month kislev) (short-kislev? h-year)))

7

10

14

13

12

11

10

9

8

7

6

5

4

3

2

1

5

4

3

(< ;; ;; (+ m tishri

month tishri) Then add days in prior months this year before and after Nisan. (sum (last-day-of-hebrew-month m year)

(+ (hebrew-new-year year) day -1 ; Days so far this month. (if ;; before Tishri

(let* ((month (standard-month h-date)) (day (standard-day h-date)) (year (standard-year h-date)))

(defun fixed-from-hebrew (h-date) ;; TYPE hebrew-date -> fixed-date ;; Fixed date of Hebrew date h-date.

;; Number of days in Hebrew year h-year. (- (hebrew-new-year (1+ h-year)) (hebrew-new-year h-year)))

29

28

27

26

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

(hebrew-date year month day)))

(last-day-of-hebrew-month m year)))))) (day ; Calculate the day by subtraction. (1+ (- date (fixed-from-hebrew (hebrew-date year month 1))))))

(hebrew-date year m

(next m start ( hebrew-date ;; Hebrew (year month day) corresponding to fixed date.

m tishri (< m month))))))

m nisan (< m month))) ;; Else add days in prior months this year (sum (last-day-of-hebrew-month m year)

( hebrew-day ;; Last day of monthh-month in Hebrew year h-year.

;; True if Kislev is short in Hebrew year h-year. (member (days-in-hebrew-year h-year) (list 353 383)))

4

3

2

1

4

3

Appendix B. Lisp Implementation 381

2

1

11

10

9

8

7

6

5

;; TYPE gregorian-year -> fixed-date

(defun purim (g-year)

(list (quotient c 7) (mod c 7)) bogus)))

(passover (gregorian-year-from-fixed date))))) (if ( omer-count ;; Number of elapsed weeks and days in the omer at date.

(gregorian-year-from-fixed hebrew-epoch)))) (fixed-from-hebrew (hebrew-date hebrew-year nisan 15))))

;; g-year. (let* ((hebrew-year (- g-year

(defun passover (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Passover occurring in Gregorian year

1

8

7

6

5

4

3

2

1

9

8

7

6

hebrew-epoch))))) (fixed-from-hebrew (hebrew-date hebrew-year tishri 10))))

(let* ((hebrew-year (1+ (- g-year (gregorian-year-from-fixed

5

4

3

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Yom Kippur occurring in Gregorian year ;; g-year.

(defun yom-kippur (g-year)

2

1

We are using Common Lisp exact arithmetic for rationals here (and elsewhere). Without that facility, one must rephrase all quotient operations to work with integers only. The function hebrew-calendar-elapsed-days is called repeatedly during the calculations, often several times for the same year. A more efficient algorithm could avoid such repetition.

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

11

10

9

8

7

6

5

4

3

2

1

10

9

8

7

6

5

4

3

(1+ av9) av9)))

(if ; Ninth of Av is Saturday (= (day-of-week-from-fixed av9) saturday) ;; Then the next day

(av9 (fixed-from-hebrew (hebrew-date hebrew-year av 9))))

(let* ((hebrew-year (- g-year (gregorian-year-from-fixed hebrew-epoch)))

(defun tishah-be-av (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Tishah be-Av occurring in ;; Gregorian year g-year.

;; Else previous day (1- purim-date))))

(= (day-of-week-from-fixed purim-date) sunday) ;; Then prior Thursday (- purim-date 3)

;; Gregorian year g-year. (let* ((purim-date (purim g-year))) (if ; Purim is on Sunday

(defun ta-anit-esther (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Ta’anit Esther occurring in

(last-month-of-hebrew-year hebrew-year))) (fixed-from-hebrew (hebrew-date hebrew-year last-month 14))))

(- g-year (gregorian-year-from-fixed hebrew-epoch))) (last-month ; Adar or Adar II

;; Fixed date of Purim occurring in Gregorian year g-year. (let* ((hebrew-year

382 Appendix B. Lisp Implementation

dates

(iyyar4; Ordinarily Iyyar 4 (fixed-from-hebrew (hebrew-date hebrew-year iyyar 4))))

8

5

4

3

2

1

18

(coptic-in-gregorian 3 26 g-year))

(defun sh-ela (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates ;; List of fixed dates of Sh’ela occurring in ;; Gregorian year g-year.

(1+ iyyar4)) (t iyyar4))))

17

16

15

(kday-before wednesday iyyar4)) ;; If it’s on Sunday, then Monday ((= sunday (day-of-week-from-fixed iyyar4))

14

13

12

11

10

9

7

6

(cond ((member (day-of-week-from-fixed iyyar4) (list thursday friday)) ;; If Iyyar 4 is Friday or Saturday, then Wednesday

(let* ((hebrew-year (- g-year (gregorian-year-from-fixed hebrew-epoch)))

5

4

3

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Yom ha-Zikkaron occurring in Gregorian ;; year g-year.

(defun yom-ha-zikkaron (g-year)

nil)))

17))

28)

(if (and (not (equal dates nil)) (= (mod (standard-year (coptic-from-fixed (first dates)))

;; List of fixed date of Birkath ha-Hama occurring in ;; Gregorian year g-year, if it occurs. (let* ((dates (coptic-in-gregorian 7 30 g-year)))

(defun birkath-ha-hama (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates

2

1

12

11

10

9

8

7

6

5

4

3

2

1

3

2

1

13

12

11

10

9

8

7

6

5

4

3

2

1

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

;; Fixed date of the anniversary of Hebrew death-date

(defun yahrzeit (death-date h-year) ;; TYPE (hebrew-date hebrew-year) -> fixed-date

(date2 (hebrew-birthday birthdate (1+ y)))) ;; Combine in one list those that occur in current year. (list-range (list date1 date2) (gregorian-year-range g-year))))

(y (standard-year (hebrew-from-fixed jan1))) ;; The possible occurrences in one year are (date1 (hebrew-birthday birthdate y))

;; List of the fixed dates of Hebrew birthday ;; that occur in Gregorian g-year. (let* ((jan1 (gregorian-new-year g-year))

(defun hebrew-birthday-in-gregorian (birthdate g-year) ;; TYPE (hebrew-date gregorian-year) ;; TYPE -> list-of-fixed-dates

(hebrew-date h-year birth-month 1)) birth-day -1))))

;; Else use the normal anniversary of the birth date, ;; or the corresponding day in years without that date (+ (fixed-from-hebrew

(fixed-from-hebrew (hebrew-date h-year (last-month-of-hebrew-year h-year) birth-day))

; in a Hebrew leap year, (= birth-month (last-month-of-hebrew-year birth-year)) ;; Then use the same day in last month of Hebrew year.

(birth-month (standard-month birthdate)) (birth-year (standard-year birthdate))) (if ; It’s Adar in a normal Hebrew year or Adar II

;; Fixed date of the anniversary of Hebrew birthdate ;; occurring in Hebrew h-year. (let* ((birth-day (standard-day birthdate))

(defun hebrew-birthday (birthdate h-year) ;; TYPE (hebrew-date hebrew-year) -> fixed-date

Appendix B. Lisp Implementation 383

(not (hebrew-leap-year? h-year))) (fixed-from-hebrew (hebrew-date h-year shevat 30))) ;; In all other cases, use the normal anniversary of

37

39

38

36

35

;; last day in Shevat. ((and (= death-day 30) (= death-month adar)

34

33

32

31

30

29

28

h-year (last-month-of-hebrew-year h-year) death-day))) ;; If it’s the 30th in Adar I and Hebrew year is not a ;; Hebrew leap year (so Adar has only 29 days), use the

((= death-month adarii) (fixed-from-hebrew (hebrew-date

27

26

25

(hebrew-date h-year tevet 1)))) ;; If it’s Adar II, use the same day in last ;; month of Hebrew year (Adar or Adar II).

(= death-day 30) (short-kislev? (1+ death-year))) (1- (fixed-from-hebrew

;; anniversary; if that was not Kislev 30, use ;; the day before Tevet 1. ((and (= death-month kislev)

(1- (fixed-from-hebrew (hebrew-date h-year kislev 1)))) ;; If it’s Kislev 30 it depends on the first

((and (= death-month marheshvan) (= death-day 30) (not (long-marheshvan? (1+ death-year))))

;; If it’s Marheshvan 30 it depends on the first ;; anniversary; if that was not Marheshvan 30, use ;; the day before Kislev 1.

(death-month (standard-month death-date)) (death-year (standard-year death-date))) (cond

;; occurring in Hebrew h-year. (let* ((death-day (standard-day death-date))

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

(y (standard-year (hebrew-from-fixed jan1))) ;; The possible occurrences in one year are (date1 (yahrzeit death-date y)) (date2 (yahrzeit death-date (1+ y)))) ;; Combine in one list those that occur in current year (list-range (list date1 date2) (gregorian-year-range g-year))))

7

10 11

13

;; TYPE (hebrew-month hebrew-day) -> list-of-weekdays ;; Possible days of week (let* ((h-date0 (hebrew-date 5 nisan 1))

2

;; leap year with full pattern (h-year (if (> h-month elul) 6 5)) (h-date (hebrew-date h-year h-month h-day)) (n (- (fixed-from-hebrew h-date) (fixed-from-hebrew h-date0))) (tue-thu-sat (list tuesday thursday saturday)) (sun-wed-fri (cond ((and (= h-day 30)

8

11

(t (list sunday))))

17 18

16

15

14

(member h-month (list marheshvan kislev))) nil) ((= h-month kislev) (list sunday wednesday friday))

13

12

10

9

7

6

5

4

3

(defun possible-hebrew-days (h-month h-day)

1

12

9

8

6

5

;; List of the fixed dates of death-date (yahrzeit) ;; that occur in Gregorian year g-year. (let* ((jan1 (gregorian-new-year g-year))

(defun yahrzeit-in-gregorian (death-date g-year) ;; TYPE (hebrew-date gregorian-year) ;; TYPE -> list-of-fixed-dates

(hebrew-date h-year death-month 1)) death-day -1)))))

;; the date of death. (t (+ (fixed-from-hebrew

4

3

2

1

43

42

41

40

384 Appendix B. Lisp Implementation

19

(1- g-year))) (paschal-moon ; Day after full moon on ; or after March 21. (- (fixed-from-julian (julian-date j-year april 19))

9

13

12

11

10

8

7

shifted-epact)))

30)) (j-year (if (> g-year 0); Julian year number. g-year

6

5

4

;; Fixed date of Orthodox Easter in Gregorian year g-year. (let* ((shifted-epact ; Age of moon for April 5. (mod (+ 14 (* 11 (mod g-year 19)))

3

2

1

(defun orthodox-easter (g-year) ;; TYPE gregorian-year -> fixed-date

(julian-in-gregorian december 25 g-year))

5

4

3

;; TYPE gregorian-year -> list-of-fixed-dates ;; List of zero or one fixed dates of Eastern Orthodox ;; Christmas in Gregorian year g-year.

(defun eastern-orthodox-christmas (g-year)

B.11 The Ecclesiastical Calendars

(shift-days (rest l) cap-Delta))))

nil (append (list (day-of-week-from-fixed (+ (first l) cap-Delta)))

;; TYPE (list-of-weekdays integer) -> list-of-weekdays ;; Shift each weekday on list l by cap-Delta days (if (equal l nil)

(defun shift-days (l cap-Delta)

(list monday) nil))) (shift-days (append tue-thu-sat sun-wed-fri mon) n)))

(mon (if (member h-month (list kislev tevet shevat adar))

2

1

8

7

6

5

4

3

2

1

23

22

21

20

14

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

13

12

11

10

9

8

7

6

5

4

3

2

1

15

(paschal-moon; Day after full moon on

(and (= shifted-epact 1) (< 10 (mod g-year 19)))) (1+ shifted-epact) shifted-epact))

30)) (adjusted-epact ; Adjust for 29.5 day month. (if (or (= shifted-epact 0)

(quotient; ...corrected for Metonic ; cycle inaccuracy. (+ 5 (* 8 century)) 25))

(+ 14 (* 11 (mod g-year 19)); ...by Nicaean rule (- ;...corrected for the Gregorian century rule (quotient (* 3 century) 4))

(let* ((century (1+ (quotient g-year 100))) (shifted-epact ; Age of moon for April 5... (mod

(defun easter (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Easter in Gregorian year g-year.

;; Return the Sunday following the Paschal moon. (kday-after sunday paschal-moon)))

(quotient g-year 4) (- (quotient g-year 19)) -272)))

; or after March 21. (+ (* 354 g-year) (* 30 (quotient (+ (* 7 g-year) 8) 19))

;; Alternative calculation of fixed date of Orthodox Easter ;; in Gregorian year g-year. (let* ((paschal-moon ; Day after full moon on

(defun alt-orthodox-easter (g-year) ;; TYPE gregorian-year -> fixed-date

;; Return the Sunday following the Paschal moon. (kday-after sunday paschal-moon)))

Appendix B. Lisp Implementation 385

21

6

5

4

3

2

1

5

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

60))

;; TYPE fixed-date -> {1-60} ;; Year of Jupiter cycle at fixed date. (amod (+ 27 (quotient (hindu-day-count date) (/ arya-jovian-period 12)))

(defun jovian-year (date)

;; Number of days in one revolution of Jupiter around the ;; Sun. 1577917500/364224)

(defconstant arya-jovian-period ;; TYPE rational

;; Elapsed days (Ahargana) to date since Hindu epoch (KY). (- date hindu-epoch))

(defun hindu-day-count (date) ;; TYPE fixed-date -> integer

;; Fixed date of start of the Hindu calendar (Kali Yuga). (fixed-from-julian (julian-date (bce 3102) february 18)))

(defconstant hindu-epoch ;; TYPE fixed-date

B.12 The Old Hindu Calendars

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Pentecost in Gregorian year g-year. (+ (easter g-year) 49))

(defun pentecost (g-year)

(kday-after sunday paschal-moon)))

26

25

24

(gregorian-date g-year april 19)) adjusted-epact))) ;; Return the Sunday following the Paschal moon.

; or after March 21. (- (fixed-from-gregorian

23

22

5

4

3

2

1

11

10

9

8

7

6

5

4

3

2

1

11

10

9

8

7

6

5

4

3

2

1

4

3

2

1

4

3

2

1

(list year month leap day))

(defun old-hindu-lunar-date (year month leap day) ;; TYPE (old-hindu-lunar-year old-hindu-lunar-month ;; TYPE old-hindu-lunar-leap old-hindu-lunar-day) ;; TYPE -> old-hindu-lunar-date

day (hr -30))))) ; Midnight of day.

(+ hindu-epoch ; Since start of era. (* year arya-solar-year) ; Days in elapsed years (* (1- month) arya-solar-month) ; ...in months.

(day (standard-day s-date)) (year (standard-year s-date))) (ceiling

;; TYPE hindu-solar-date -> fixed-date ;; Fixed date corresponding to Old Hindu solar date s-date. (let* ((month (standard-month s-date))

(defun fixed-from-old-hindu-solar (s-date)

12))) (day (1+ (floor (mod sun arya-solar-month))))) (hindu-solar-date year month day)))

(year ; Elapsed years. (quotient sun arya-solar-year)) (month (1+ (mod (quotient sun arya-solar-month)

;; Old Hindu solar date equivalent to fixed date. (let* ((sun ; Sunrise on Hindu date. (+ (hindu-day-count date) (hr 6)))

(defun old-hindu-solar-from-fixed (date) ;; TYPE fixed-date -> hindu-solar-date

;; Length of Old Hindu solar month. (/ arya-solar-year 12))

(defconstant arya-solar-month ;; TYPE rational

;; Length of Old Hindu solar year. 1577917500/4320000)

(defconstant arya-solar-year ;; TYPE rational

386 Appendix B. Lisp Implementation

(defun old-hindu-lunar-year (date)

1

3

2

1

8

7

6

5

;; Old Hindu lunar date equivalent to fixed date.

(defun old-hindu-lunar-from-fixed (date) ;; TYPE fixed-date -> old-hindu-lunar-date

arya-lunar-month) 23902504679/1282400064))

;; old Hindu calendar. (>= (mod (- (* l-year arya-solar-year) arya-solar-month)

4

3

2

(defun old-hindu-lunar-leap-year? (l-year) ;; TYPE old-hindu-lunar-year -> boolean ;; True if l-year is a leap year on the

;; TYPE rational ;; Length of Old Hindu lunar day. (/ arya-lunar-month 30))

(defconstant arya-lunar-day

;; TYPE rational ;; Length of Old Hindu lunar month. 1577917500/53433336)

(defconstant arya-lunar-month

1

4

3

2

1

4

3

2

1

3

2

3

2

;; TYPE old-hindu-lunar-date -> old-hindu-lunar-year (first date))

(defun old-hindu-lunar-day (date) ;; TYPE old-hindu-lunar-date -> old-hindu-lunar-day (fourth date))

1

3

2

(defun old-hindu-lunar-leap (date) ;; TYPE old-hindu-lunar-date -> old-hindu-lunar-leap (third date))

(second date))

(defun old-hindu-lunar-month (date) ;; TYPE old-hindu-lunar-date -> old-hindu-lunar-month

1

3

2

1

(let* ((year (old-hindu-lunar-year l-date)) (month (old-hindu-lunar-month l-date)) (leap (old-hindu-lunar-leap l-date))

5

(lunar-new-year ; New moon after mina. (* arya-lunar-month (1+ (quotient mina arya-lunar-month))))) 11

18

17

16

15

14

13

12

10

(if ; If there was a leap month this year.

(ceiling (+ hindu-epoch lunar-new-year (* arya-lunar-month

(day (old-hindu-lunar-day l-date)) (mina ; One solar month before solar new year. (* (1- (* 12 year)) arya-solar-month)) 9

8

7

6

4

3

;; TYPE old-hindu-lunar-date -> fixed-date ;; Fixed date corresponding to Old Hindu lunar date ;; l-date.

(defun fixed-from-old-hindu-lunar (l-date)

(old-hindu-lunar-date year month leap day)))

(year ; Solar year at end of lunar month(s). (1- (ceiling (/ (+ new-moon arya-solar-month) arya-solar-year)))))

12))) (day ; Lunar days since beginning of lunar month. (1+ (mod (quotient sun arya-lunar-day) 30)))

(month ; Next solar month’s name. (1+ (mod (ceiling (/ new-moon arya-solar-month))

(and (>= (- arya-solar-month arya-lunar-month) (mod new-moon arya-solar-month)) (> (mod new-moon arya-solar-month) 0)))

(new-moon ; Beginning of lunar month. (- sun (mod sun arya-lunar-month))) (leap ; If lunar contained in solar.

(let* ((sun ; Sunrise on Hindu date. (+ (hindu-day-count date) (hr 6)))

2

1

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

Appendix B. Lisp Implementation 387

19

;; TYPE (mayan-baktun mayan-katun mayan-tun mayan-uinal ;; TYPE mayan-kin) -> mayan-long-count-date (list baktun katun tun uinal kin))

2

(defun mayan-katun (date)

1

3

2

1

3

2

1

3

2

1

3

2

3

(fifth date))

(defun mayan-kin (date) ;; TYPE mayan-long-count-date -> mayan-kin

;; TYPE mayan-long-count-date -> mayan-uinal (fourth date))

(defun mayan-uinal (date)

;; TYPE mayan-long-count-date -> mayan-tun (third date))

(defun mayan-tun (date)

;; TYPE mayan-long-count-date -> mayan-katun (second date))

(defun mayan-baktun (date) ;; TYPE mayan-long-count-date -> mayan-baktun (first date))

2

1

4

3

(defun mayan-long-count-date (baktun katun tun uinal kin)

1

28

B.13 The Mayan Calendars

(hr -6))))) ; Subtract 1 if phase begins before ; sunrise.

26

25

27

month))

month (1- month))) (* (1- day) arya-lunar-day) ; Lunar days.

(- arya-solar-month arya-lunar-month)))

(and (not leap) ( mayan-long-count-date ;; Mayan long count date of fixed date.

(* uinal 20) kin)))

(* baktun 144000); Baktun. (* katun 7200) ; Katun. (* tun 360) ; Tun.

4

3

2

1

15

14

13

12

11

10

9

8

7

6

(uinal (mayan-uinal count)) (kin (mayan-kin count))) (+ mayan-epoch ; Fixed date at Mayan 0.0.0.0.0

(let* ((baktun (mayan-baktun count)) (katun (mayan-katun count)) (tun (mayan-tun count))

5

4

3

;; TYPE mayan-long-count-date -> fixed-date ;; Fixed date corresponding to the Mayan long count, ;; which is a list (baktun katun tun uinal kin).

(defun fixed-from-mayan-long-count (count)

(fixed-from-jd 584283))

;; Fixed date of start of the Mayan calendar, according ;; to the Goodman-Martinez-Thompson correlation. ;; That is, August 11, -3113.

(defconstant mayan-epoch ;; TYPE fixed-date

2

1

6

5

4

3

2

1

388 Appendix B. Lisp Implementation

4

3

2

1

8

7

6

5

4

3

2

1

5

4

3

2

1

6

5

4

3

2

1

3

2

1

3

2

1

3

2

1

;; that is Mayan haab date haab.

(defun mayan-haab-on-or-before (haab date) ;; TYPE (mayan-haab-date fixed-date) -> fixed-date ;; Fixed date of latest date on or before fixed date

(day (mod count 20)) (month (1+ (quotient count 20)))) (mayan-haab-date month day)))

;; Mayan haab date of fixed date. (let* ((count (mod (- date mayan-haab-epoch) 365))

(defun mayan-haab-from-fixed (date) ;; TYPE fixed-date -> mayan-haab-date

(mayan-haab-ordinal (mayan-haab-date 18 8))))

;; TYPE fixed-date ;; Fixed date of start of haab cycle. (- mayan-epoch

(defconstant mayan-haab-epoch

(month (mayan-haab-month h-date))) (+ (* (1- month) 20) day)))

;; TYPE mayan-haab-date -> nonnegative-integer ;; Number of days into cycle of Mayan haab date h-date. (let* ((day (mayan-haab-day h-date))

(defun mayan-haab-ordinal (h-date)

(first date))

(defun mayan-haab-month (date) ;; TYPE mayan-haab-date -> mayan-haab-month

(second date))

(defun mayan-haab-day (date) ;; TYPE mayan-haab-date -> mayan-haab-day

(list month day))

(defun mayan-haab-date (month day) ;; TYPE (mayan-haab-month mayan-haab-day) -> mayan-haab-date

7

6

5

4

3

2

1

5

4

3

2

1

8

7

6

5

4

3

2

1

3

2

1

3

2

1

4

3

2

1

8

7

6

5

(mayan-tzolkin-date number name)))

;; Mayan tzolkin date of fixed date. (let* ((count (- date mayan-tzolkin-epoch -1)) (number (amod count 13)) (name (amod count 20)))

(defun mayan-tzolkin-from-fixed (date) ;; TYPE fixed-date -> mayan-tzolkin-date

(mayan-tzolkin-ordinal (mayan-tzolkin-date 4 20))))

;; TYPE fixed-date ;; Start of tzolkin date cycle. (- mayan-epoch

(defconstant mayan-tzolkin-epoch

(* 39 (- number name))) 260)))

(let* ((number (mayan-tzolkin-number t-date)) (name (mayan-tzolkin-name t-date))) (mod (+ number -1

(defun mayan-tzolkin-ordinal (t-date) ;; TYPE mayan-tzolkin-date -> nonnegative-integer ;; Number of days into Mayan tzolkin cycle of t-date.

(defun mayan-tzolkin-name (date) ;; TYPE mayan-tzolkin-date -> mayan-tzolkin-name (second date))

(defun mayan-tzolkin-number (date) ;; TYPE mayan-tzolkin-date -> mayan-tzolkin-number (first date))

;; TYPE (mayan-tzolkin-number mayan-tzolkin-name) ;; TYPE -> mayan-tzolkin-date (list number name))

(defun mayan-tzolkin-date (number name)

(mayan-haab-ordinal haab)) 365)))

(- date (mod (- date mayan-haab-epoch

Appendix B. Lisp Implementation 389

;; Fixed date of latest date on or before fixed date ;; that is Mayan tzolkin date tzolkin. (- date

3

(let* ((x (mayan-haab-on-or-before (mayan-haab-date 1 0) (+ date 364))))

5

(mayan-tzolkin-name (mayan-tzolkin-from-fixed x)))))

11

;; Mayan haab date haab and tzolkin date tzolkin. ;; Returns bogus for impossible combinations. (let* ((haab-count

5

15

14

13

12

11

10

9

8

7

6

4

(mod (- date haab-count (* 365 diff))

mayan-tzolkin-epoch)) (diff (- tzolkin-count haab-count))) (if (= (mod diff 5) 0) (- date

(+ (mayan-haab-ordinal haab) mayan-haab-epoch)) (tzolkin-count (+ (mayan-tzolkin-ordinal tzolkin)

;; TYPE (mayan-haab-date mayan-tzolkin-date fixed-date) ;; TYPE -> fixed-date ;; Fixed date of latest date on or before date, that is

2

3

(defun mayan-calendar-round-on-or-before (haab tzolkin date)

1

10

9

(if (= (mayan-haab-month (mayan-haab-from-fixed date)) 19) bogus

8

7

6

4

3

;; TYPE fixed-date -> mayan-tzolkin-name ;; Year bearer of year containing fixed date. ;; Returns bogus for uayeb.

(defun mayan-year-bearer-from-fixed (date)

260)))

2

1

9

8

7

6

5

4

(mod (- date mayan-tzolkin-epoch (mayan-tzolkin-ordinal tzolkin))

(defun mayan-tzolkin-on-or-before (tzolkin date) ;; TYPE (mayan-tzolkin-date fixed-date) -> fixed-date

2

1

3

2

1

5

4

3

2

1

7

6

5

4

3

2

1

3

2

1

3

2

1

4

3

2

1

4

3

2

1

17

16

18980)) haab-tzolkin combination is impossible.

;; Aztec xihuitl date of fixed date.

(defun aztec-xihuitl-from-fixed (date) ;; TYPE fixed-date -> aztec-xihuitl-date

(- aztec-correlation (aztec-xihuitl-ordinal (aztec-xihuitl-date 11 2))))

(defconstant aztec-xihuitl-correlation ;; TYPE fixed-date ;; Start of a xihuitl cycle.

(let* ((day (aztec-xihuitl-day x-date)) (month (aztec-xihuitl-month x-date))) (+ (* (1- month) 20) (1- day))))

;; TYPE aztec-xihuitl-date -> nonnegative-integer ;; Number of elapsed days into cycle of Aztec xihuitl ;; x-date.

(defun aztec-xihuitl-ordinal (x-date)

(defun aztec-xihuitl-day (date) ;; TYPE aztec-xihuitl-date -> aztec-xihuitl-day (second date))

(defun aztec-xihuitl-month (date) ;; TYPE aztec-xihuitl-date -> aztec-xihuitl-month (first date))

(list month day))

(defun aztec-xihuitl-date (month day) ;; TYPE (aztec-xihuitl-month aztec-xihuitl-day) -> ;; TYPE aztec-xihuitl-date

;; TYPE fixed-date ;; Known date of Aztec cycles (Caso’s correlation) (fixed-from-julian (julian-date 1521 August 13)))

(defconstant aztec-correlation

bogus)));

390 Appendix B. Lisp Implementation

8

7

6

5

4

3

2

1

3

2

1

4

3

2

1

4

3

2

1

8

7

6

5

4

(mod (+ number -1 (* 39 (- number name))) 260)))

;; Number of days into Aztec tonalpohualli cycle of t-date. (let* ((number (aztec-tonalpohualli-number t-date)) (name (aztec-tonalpohualli-name t-date)))

(defun aztec-tonalpohualli-ordinal (t-date) ;; TYPE aztec-tonalpohualli-date -> nonnegative-integer

(second date))

(defun aztec-tonalpohualli-name (date) ;; TYPE aztec-tonalpohualli-date -> aztec-tonalpohualli-name

;; aztec-tonalpohualli-number (first date))

(defun aztec-tonalpohualli-number (date) ;; TYPE aztec-tonalpohualli-date ->

(list number name))

(defun aztec-tonalpohualli-date (number name) ;; TYPE (aztec-tonalpohualli-number aztec-tonalpohualli-name) ;; TYPE -> aztec-tonalpohualli-date

(mod (- date aztec-xihuitl-correlation (aztec-xihuitl-ordinal xihuitl)) 365)))

;; Fixed date of latest date on or before fixed date ;; that is Aztec xihuitl date xihuitl. (- date

3

2

(defun aztec-xihuitl-on-or-before (xihuitl date) ;; TYPE (aztec-xihuitl-date fixed-date) -> fixed-date

(month (1+ (quotient count 20)))) (aztec-xihuitl-date month day)))

(let* ((count (mod (- date aztec-xihuitl-correlation) 365)) (day (1+ (mod count 20)))

1

7

6

5

4

4

3

2

1

4

;; TYPE -> aztec-xiuhmolpilli-name (second date))

(defun aztec-xiuhmolpilli-name (date) ;; TYPE aztec-xiuhmolpilli-designation

;; TYPE -> aztec-xiuhmolpilli-number (first date)) 3

2

(defun aztec-xiuhmolpilli-number (date) ;; TYPE aztec-xiuhmolpilli-designation

;; TYPE -> aztec-xiuhmolpilli-designation (list number name))

(defun aztec-xiuhmolpilli-designation (number name) ;; TYPE (aztec-xiuhmolpilli-number aztec-xiuhmolpilli-name)

1

4

3

2

1

9

8

7

6

(aztec-tonalpohualli-ordinal tonalpohualli)) 260)))

(- date (mod (- date aztec-tonalpohualli-correlation

5

4

3

;; TYPE (aztec-tonalpohualli-date fixed-date) -> fixed-date ;; Fixed date of latest date on or before fixed date ;; that is Aztec tonalpohualli date tonalpohualli.

(defun aztec-tonalpohualli-on-or-before (tonalpohualli date)

(aztec-tonalpohualli-date number name)))

(let* ((count (- date aztec-tonalpohualli-correlation -1)) (number (amod count 13)) (name (amod count 20)))

(defun aztec-tonalpohualli-from-fixed (date) ;; TYPE fixed-date -> aztec-tonalpohualli-date ;; Aztec tonalpohualli date of fixed date.

(aztec-tonalpohualli-date 1 5))))

;; Start of a tonalpohualli date cycle. (- aztec-correlation (aztec-tonalpohualli-ordinal

(defconstant aztec-tonalpohualli-correlation ;; TYPE fixed-date

2

1

7

6

5

4

3

2

1

6

5

4

3

2

1

Appendix B. Lisp Implementation 391

(let* ((xihuitl-count (+ (aztec-xihuitl-ordinal xihuitl) aztec-xihuitl-correlation))

10

22

21

20

19

18

17

16

15

14

13

12

11

9

8

18980)) bogus))); xihuitl-tonalpohualli combination is ; impossible.

(if (= (mod diff 5) 0) (- date (mod (- date xihuitl-count (* 365 diff))

(tonalpohualli-count (+ (aztec-tonalpohualli-ordinal tonalpohualli) aztec-tonalpohualli-correlation)) (diff (- tonalpohualli-count xihuitl-count)))

;; date that is Aztec xihuitl date xihuitl and ;; tonalpohualli date tonalpohualli. ;; Returns bogus for impossible combinations.

7

6

5

;; TYPE fixed-date) -> fixed-date ;; Fixed date of latest xihuitl-tonalpohualli combination ;; on or before date. That is the date on or before

(defun aztec-xihuitl-tonalpohualli-on-or-before (xihuitl tonalpohualli date) ;; TYPE (aztec-xihuitl-date aztec-tonalpohualli-date

(aztec-tonalpohualli-from-fixed x))))

4

3

2

1

12

11

10

9

8

7

(aztec-xihuitl-from-fixed date)))) (if (= month 19) bogus

(aztec-xihuitl-date 18 20) (+ date 364))) (month (aztec-xihuitl-month

6

5

4

;; Designation of year containing fixed date. ;; Returns bogus for nemontemi. (let* ((x (aztec-xihuitl-on-or-before

(defun aztec-xiuhmolpilli-from-fixed (date) ;; TYPE fixed-date -> aztec-xiuhmolpilli-designation

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

4

3

2

1

;; TYPE balinese-date -> 1-8 (eighth b-date))

(defun bali-asatawara (b-date)

(seventh b-date))

(defun bali-saptawara (b-date) ;; TYPE balinese-date -> 1-7

;; TYPE balinese-date -> 1-6 (sixth b-date))

(defun bali-sadwara (b-date)

(fifth b-date))

(defun bali-pancawara (b-date) ;; TYPE balinese-date -> 1-5

;; TYPE balinese-date -> 1-4 (fourth b-date))

(defun bali-caturwara (b-date)

(third b-date))

(defun bali-triwara (b-date) ;; TYPE balinese-date -> 1-3

;; TYPE balinese-date -> 1-2 (second b-date))

(defun bali-dwiwara (b-date)

(first b-date))

(defun bali-luang (b-date) ;; TYPE balinese-date -> boolean

;; TYPE -> balinese-date (list b1 b2 b3 b4 b5 b6 b7 b8 b9 b0))

(defun balinese-date (b1 b2 b3 b4 b5 b6 b7 b8 b9 b0) ;; TYPE (boolean 1-2 1-3 1-4 1-5 1-6 1-7 1-8 1-9 0-9)

B.14 The Balinese Pawukon Calendar

392 Appendix B. Lisp Implementation

(amod (bali-asatawara-from-fixed date) 4))

4

3

2

(defun bali-caturwara-from-fixed (date) ;; TYPE fixed-date -> 1-4 ;; Position of date in 4-day Balinese cycle.

1

4

3

2

(1+ (mod (bali-day-from-fixed date) 3)))

(defun bali-triwara-from-fixed (date) ;; TYPE fixed-date -> 1-3 ;; Position of date in 3-day Balinese cycle.

1

4

3

;; TYPE fixed-date -> 1-2 ;; Position of date in 2-day Balinese cycle. (amod (bali-dasawara-from-fixed date) 2))

(defun bali-dwiwara-from-fixed (date)

;; Membership of date in "1-day" Balinese cycle. (evenp (bali-dasawara-from-fixed date)))

(defun bali-luang-from-fixed (date) ;; TYPE fixed-date -> boolean

;; Position of date in 210-day Pawukon cycle. (mod (- date bali-epoch) 210))

(defun bali-day-from-fixed (date) ;; TYPE fixed-date -> 0-209

2

1

4

3

2

1

4

3

2

1

4

3

2

(fixed-from-jd 146))

(defconstant bali-epoch ;; TYPE fixed-date ;; Fixed date of start of a Balinese Pawukon cycle.

1

3

2

(defun bali-dasawara (b-date) ;; TYPE balinese-date -> 0-9 (tenth b-date))

(ninth b-date))

(defun bali-sangawara (b-date) ;; TYPE balinese-date -> 1-9

1

3

2

1

5

4

3

2

1

6

5

4

3

2

1

9

8

7

6

5

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

210)))

(- (bali-day-from-fixed date) 3))

(1- (bali-pancawara-from-fixed date)))

(defun bali-dasawara-from-fixed (date) ;; TYPE fixed-date -> 0-9 ;; Position of date in 10-day Balinese cycle. (let* ((i ; Position in 5-day cycle.

9)))

;; TYPE fixed-date -> 1-9 ;; Position of date in 9-day Balinese cycle. (1+ (mod (max 0

(defun bali-sangawara-from-fixed (date)

8))))

(1+ (mod (max 6 (+ 4 (mod (- day 70)

;; TYPE fixed-date -> 1-8 ;; Position of date in 8-day Balinese cycle. (let* ((day (bali-day-from-fixed date)))

(defun bali-asatawara-from-fixed (date)

(1+ (mod (bali-day-from-fixed date) 7)))

(defun bali-saptawara-from-fixed (date) ;; TYPE fixed-date -> 1-7 ;; Position of date in Balinese week.

;; TYPE fixed-date -> 1-6 ;; Position of date in 6-day Balinese cycle. (1+ (mod (bali-day-from-fixed date) 6)))

(defun bali-sadwara-from-fixed (date)

;; Position of date in 5-day Balinese cycle. (amod (+ (bali-day-from-fixed date) 2) 5))

(defun bali-pancawara-from-fixed (date) ;; TYPE fixed-date -> 1-5

Appendix B. Lisp Implementation 393

11

11

10

9

8

7

6

5

4

3

2

1

4

3

2

1

14

13

12

(mod (+ a5 14 (* 15 (- b7 a5))) 35))

(1- (bali-sadwara b-date))) (b7 ; Position in 7-day subcycle. (1- (bali-saptawara b-date))) (b35 ; Position in 35-day subcycle.

(let* ((a5 ; Position in 5-day subcycle. (1- (bali-pancawara b-date))) (a6 ; Position in 6-day subcycle.

(defun bali-on-or-before (b-date date) ;; TYPE (balinese-date fixed-date) -> fixed-date ;; Last fixed date on or before date with Pawukon b-date.

;; TYPE fixed-date -> 1-30 ;; Week number of date in Balinese cycle. (1+ (quotient (bali-day-from-fixed date) 7)))

(defun bali-week-from-fixed (date)

(bali-sangawara-from-fixed date) (bali-dasawara-from-fixed date)))

(bali-sadwara-from-fixed date) (bali-saptawara-from-fixed date) (bali-asatawara-from-fixed date)

10

9

8

(bali-triwara-from-fixed date) (bali-caturwara-from-fixed date) (bali-pancawara-from-fixed date)

;; calendar. (balinese-date (bali-luang-from-fixed date) (bali-dwiwara-from-fixed date)

(defun bali-pawukon-from-fixed (date) ;; TYPE fixed-date -> balinese-date ;; Positions of date in ten cycles of Balinese Pawukon

(mod (+ 1 (nth i (list 5 9 7 4 8)) (nth j (list 5 4 3 7 8 6 9))) 10)))

(j ; Weekday. (1- (bali-saptawara-from-fixed date))))

7

6

5

4

3

2

1

10

9

8

7

6

7

6

5

4

3

2

1

7

6

(cap-Delta (bali-day-from-fixed 0))) (positions-in-range 14 35 cap-Delta year)))

;; Occurrences of Tumpek (14th day of Pawukon and every ;; 35th subsequent day) within Gregorian year g-year. (let* ((year (gregorian-year-range g-year))

(defun tumpek (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates

(let* ((year (gregorian-year-range g-year)) (cap-Delta (bali-day-from-fixed 0))) (positions-in-range 9 15 cap-Delta year)))

5

4

3

;; TYPE gregorian-year -> list-of-fixed-dates ;; Occurrences of Kajeng Keliwon (9th day of each ;; 15-day subcycle of Pawukon) in Gregorian year g-year.

(defun kajeng-keliwon (g-year)

(append (list pos) (positions-in-range n c cap-Delta (interval (1+ pos) b))))))

(pos (+ a (mod (- n a cap-Delta 1) c)))) (if (> pos b) nil

;; cap-Delta is position in cycle of RD 0. (let* ((a (start range)) (b (end range))

;; TYPE -> list-of-fixed-dates ;; List of occurrences of n-th day of c-day cycle ;; in range.

(defun positions-in-range (n c cap-Delta range) ;; TYPE (positive-integer positive-integer ;; TYPE nonnegative-integer range)

(cap-Delta (bali-day-from-fixed 0))) (- date (mod (- (+ date cap-Delta) days) 210))))

(days ; Position in full cycle. (+ a6 (* 36 (- b35 a6))))

2

1

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

15

14

13

12

394 Appendix B. Lisp Implementation

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

;; Arctangent of y/x in degrees.

(defun arctan-degrees (y x) ;; TYPE (real real) -> angle

;; Tangent of theta (given in degrees). (tan (radians-from-degrees theta)))

(defun tangent-degrees (theta) ;; TYPE angle -> real

;; Cosine of theta (given in degrees). (cos (radians-from-degrees theta)))

(defun cosine-degrees (theta) ;; TYPE angle -> amplitude

;; Sine of theta (given in degrees). (sin (radians-from-degrees theta)))

(defun sin-degrees (theta) ;; TYPE angle -> amplitude

;; Convert angle theta from radians to degrees. (degrees (/ theta pi 1/180)))

(defun degrees-from-radians (theta) ;; TYPE radian -> angle

(* (degrees theta) pi 1/180))

(defun radians-from-degrees (theta) ;; TYPE real -> radian ;; Convert angle theta from degrees to radians.

(mod theta 360))

(defun degrees (theta) ;; TYPE real -> angle ;; Normalize angle theta to range [0,360) degrees.

Common Lisp’s built-in trigonometric functions work with radians, whereas we have used degrees. The following functions do the necessary normalization and conversions:

B.15 Time and Astronomy

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

12

11

10

9

8

7

6

5

4

;; x meters. x)

(defun mt (x) ;; TYPE real -> distance

;; TYPE real -> duration ;; x seconds. (/ x 24 60 60))

(defun sec (x)

(/ x 24))

(defun hr (x) ;; TYPE real -> duration ;; x hours.

We also use the following functions to indicate units:

(degrees-from-radians (acos x)))

(defun arccos-degrees (x) ;; TYPE amplitude -> angle ;; Arccosine of x in degrees.

;; TYPE amplitude -> angle ;; Arcsine of x in degrees. (degrees-from-radians (asin x)))

(defun arcsin-degrees (x)

360))

(if (>= x 0) alpha (+ alpha (deg 180L0)))))

(* (signum y) (deg 90L0)) (let* ((alpha (degrees-from-radians (atan (/ y x)))))

(mod (if (and (= x 0) (/= y 0))

Appendix B. Lisp Implementation 395

(defun angle (d m s)

1

(+ d (/ (+ m (/ s 60)) 60)))

5

3

2

1

3

2

(third locale))

(defun elevation (locale) ;; TYPE location -> distance

(second locale))

(defun longitude (locale) ;; TYPE location -> angle

1

3

;; TYPE location -> angle (first locale))

2

1

(defun latitude (locale)

;; TYPE (angle angle distance real) -> location (list latitude longitude elevation zone))

2

3

(defun location (latitude longitude elevation zone)

The following allow us to specify locations:

(list d m s))

1

3

2

1

4

(defun degrees-minutes-seconds (d m s) ;; TYPE (degree minute real) -> angle

;; TYPE (nonnegative-integer ;; TYPE nonnegative-integer real) -> angle ;; d degrees, m arcminutes, s arcseconds.

3

2

3

2

(defun secs (x) ;; TYPE real -> angle (/ x 3600))

;; TYPE list-of-reals -> list-of-angles ;; x degrees. x)

(defun deg (x) ;; TYPE real -> angle

1

5

4

3

2

1

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

4

3

2

1

5

4

3

2

1

3

2

1

The following functions compute times:

((= phi-prime (deg -90)) (deg 180)) (t (arctan-degrees y x)))))

(- psi psi-prime)))))) (cond ((or (= x y 0) (= phi-prime (deg 90))) (deg 0))

(tangent-degrees phi-prime)) (* (sin-degrees phi) (cosine-degrees

(y (sin-degrees (- psi-prime psi))) (x (- (* (cosine-degrees phi)

(phi-prime (latitude focus)) (psi (longitude locale)) (psi-prime (longitude focus))

;; standing in locale. Subject to errors near focus and ;; its antipode. (let* ((phi (latitude locale))

(defun direction (locale focus) ;; TYPE (location location) -> angle ;; Angle (clockwise from North) to face focus when

;; Location of Jerusalem. (location (deg 31.8L0) (deg 35.2L0) (mt 800) (hr 2)))

(defconstant jerusalem ;; TYPE location

(mt 298) (hr 3)))

;; TYPE location ;; Location of Mecca. (location (angle 21 25 24) (angle 39 49 24)

(defconstant mecca

(fourth locale))

(defun zone (locale) ;; TYPE location -> real

396 Appendix B. Lisp Implementation

(lambda (poly c (deg (list 280.46645L0 36000.76983L0

7

(deg (list 357.52910L0 35999.05030L0 -0.0001559L0 -0.00000048L0)))) (eccentricity

13

6 7

(cosine-degrees (* 2 lambda)))

5

4

26

25

24

23

3

2

1

7

6

5

4

3

2

1

6

5

4

3

2

1

4

3

2

1

4

3

2

1

30

29

(* (/ 1 2 pi) (+ (* y (sin-degrees (* 2 lambda))) (* -2 eccentricity (sin-degrees anomaly)) (* 4 eccentricity y (sin-degrees anomaly)

(varepsilon (obliquity tee)) (y (expt (tangent-degrees (/ varepsilon 2)) 2)) (equation

27 28

22

21

20

19

18

17

16

15

14

(poly c (list 0.016708617L0 -0.000042037L0 -0.0000001236L0)))

(anomaly (poly c

12

11

10

9

8

6

5

0.0003032L0))))

;; Adapted from "Astronomical Algorithms" by Jean Meeus, ;; Willmann-Bell, Inc., 1991. (let* ((c (julian-centuries tee))

4

3

2

(defun equation-of-time (tee) ;; TYPE moment -> fraction-of-day ;; Equation of time (as fraction of day) for moment tee.

;; Noon at start of Gregorian year 2000. (+ (hr 12L0) (gregorian-new-year 2000)))

(defconstant j2000 ;; TYPE moment

;; Julian centuries since 2000 at moment tee. (/ (- (dynamical-from-universal tee) j2000) 36525L0))

(defun julian-centuries (tee) ;; TYPE moment -> real

1

4

3

2

1

5

4

3

2

1

(mod (poly c

;; Mean sidereal time of day from moment tee expressed ;; as hour angle. Adapted from "Astronomical Algorithms" ;; by Jean Meeus, Willmann-Bell, Inc., 1991. (let* ((c (/ (- tee j2000) 36525L0)))

(defun sidereal-from-moment (tee) ;; TYPE moment -> angle

(standard-from-local (local-from-apparent date locale) locale))

;; TYPE (fixed-date location) -> moment ;; Standard time on fixed date of true (apparent) ;; midnight at locale.

(defun midnight (date locale)

(local-from-apparent (+ date (hr 12L0)) locale) locale))

;; TYPE (fixed-date location) -> moment ;; Standard time on fixed date of midday at locale. (standard-from-local

(defun midday (date locale)

(- tee (equation-of-time (universal-from-local tee locale))))

(defun local-from-apparent (tee locale) ;; TYPE (moment location) -> moment ;; Local time from sundial time tee at locale.

;; TYPE (moment location) -> moment ;; Sundial time at local time tee at locale. (+ tee (equation-of-time (universal-from-local tee locale))))

(defun apparent-from-local (tee locale)

(sin-degrees (* 2 anomaly))))))) (* (signum equation) (min (abs equation) (hr 12L0)))))

(* -0.5 y y (sin-degrees (* 4 lambda))) (* -1.25 eccentricity eccentricity

Appendix B. Lisp Implementation 397

0.000387933L0 -1/38710000)))

(* (deg -0.0003667L0) (sin-degrees cap-B)))))

11

5

4

3

2

1

5

4

3

2

1

4

3

2

1

4

3

2

1

10

9

(- tee_rom-s (zone locale)))

(defun universal-from-standard (tee_rom-s locale) ;; TYPE (moment location) -> moment ;; Universal time from tee_rom-s in standard time at ;; locale.

;; locale. (+ tee_rom-u (zone locale)))

(defun standard-from-universal (tee_rom-u locale) ;; TYPE (moment location) -> moment ;; Standard time from tee_rom-u in universal time at

;; TYPE (moment location) -> moment ;; Local time from universal tee_rom-u at locale. (+ tee_rom-u (zone-from-longitude (longitude locale))))

(defun local-from-universal (tee_rom-u locale)

;; Universal time from local tee_ell at locale. (- tee_ell (zone-from-longitude (longitude locale))))

(defun universal-from-local (tee_ell locale) ;; TYPE (moment location) -> moment

(cap-B (poly c (deg (list 201.11L0 72001.5377L0 0.00057L0))))) (+ (* (deg -0.004778L0) (sin-degrees cap-A))

8

7

6

(julian-centuries tee)) (cap-A (poly c (deg (list 124.90L0 -1934.134L0 0.002063L0))))

;; TYPE moment -> angle ;; Longitudinal nutation at moment tee. (let* ((c ; moment in Julian centuries

(defun nutation (tee)

360)))

(deg (list 280.46061837L0 (* 36525L0 360.98564736629L0)

5

4

3

2

1

11

10

9

8

18

17

16

15

14

13

12

11

10

9

8

7

6

(( moment ;; Local time from standard tee_rom-s at locale.

locale))

;; Standard time from local tee_ell at locale. (standard-from-universal (universal-from-local tee_ell locale)

(defun standard-from-local (tee_ell locale) ;; TYPE (moment location) -> moment

2

1

5

4

3

2

1

6

5

4

3

2

1

6

5

4

3

2

1

398 Appendix B. Lisp Implementation

19

3

2

1

3

2

1

4

3

2

365.25636L0)

(defconstant mean-sidereal-year ;; TYPE real

365.242189L0)

(defconstant mean-tropical-year ;; TYPE real

The remaining solar and lunar astronomical functions are:

(- tee (ephemeris-correction tee)))

(defun universal-from-dynamical (tee) ;; TYPE moment -> moment ;; Universal moment from Dynamical time tee.

1

4

3

;; TYPE moment -> moment ;; Dynamical time at Universal moment tee. (+ tee (ephemeris-correction tee)))

(defun dynamical-from-universal (tee)

(gregorian-date year january 1))))) (* 1/86400 (- (/ (* x x) 41048480L0) 15)))))))

(t (let* ((x (+ (hr 12L0) (gregorian-date-difference (gregorian-date 1810 january 1)

2

1

37

36

35

34

33

32

31

30

29

28

(* 1/86400 (poly (- year 1600) (list 196.58333L0 -4.0675L0 0.0219167L0))))

(list 8.118780842L0 -0.005092142L0 0.003336121L0 -0.0000266484L0)))) (( angle ;; Declination at moment UT tee of object at ;; longitude lambda and latitude beta. (let* ((varepsilon (obliquity tee)))

(defun declination (tee beta lambda)

(angle 0 0 -46.8150L0) (angle 0 0 -0.00059L0) (angle 0 0 0.001813L0))))))

(let* ((c (julian-centuries tee))) (+ (angle 23 26 21.448L0) (poly c (list 0L0

(defun obliquity (tee) ;; TYPE moment -> angle ;; Obliquity of ecliptic at moment tee.

The Lisp construct 1L-5 represents the long-precision value 10−5 .

13

12

11

10

9

8

7

6

(+ tee (* rate (mod (- lambda (solar-longitude tee)) 360))))

(let* ((rate ; Mean days for 1 degree change. (/ mean-tropical-year (deg 360))) (tau ; Estimate (within 5 days).

5

4

3

;; TYPE (season moment) -> moment ;; Moment UT of the first time at or after tee ;; when the solar longitude will be lambda degrees.

(defun solar-longitude-after (lambda tee)

;; TYPE season ;; Longitude of sun at winter solstice. (deg 270))

(defconstant winter

;; Longitude of sun at autumnal equinox. (deg 180))

2

1

4

3

2

1

4

3

1

4

3

2

1

4

3

2

1

9

8

7

6

5

4

3

;; Aberration at moment tee. (let* ((c ; moment in Julian centuries (julian-centuries tee)))

(defun aberration (tee) ;; TYPE moment -> angle

1

2

360)))

(z multipliers)) (* x (sin-degrees (+ y (* z c))))))))) (mod (+ lambda (aberration tee) (nutation tee))

(* (deg 0.000005729577951308232L0) (sigma ((x coefficients) (y addends)

51

50

49

48

47

46

45

44

43

42

41

40

(lambda (+ (deg 282.7771834L0) (* (deg 36000.76953744L0) c)

8.0L0 197.1L0 250.4L0 65.3L0 162.7L0 341.5L0 291.6L0 98.5L0 146.7L0 110.0L0 5.2L0 342.6L0

37

38

400 Appendix B. Lisp Implementation

(sin-degrees varepsilon) (sin-degrees lambda))))))

9

(- (* (sin-degrees lambda) (cosine-degrees varepsilon)) (* (tangent-degrees beta)

(sin-degrees varepsilon))) (cosine-degrees lambda))))

7

10

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4 5

3

2

1

3

2

1

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

7

6

5

4

3

2

1

23

(cap-A (* (cosine-degrees eta) (sin-degrees cap-P)))

360))

21 22

(p (mod (poly c (list 0 (secs 5029.0966L0) (secs 1.11113L0) (secs 0.000006L0))) 360))

(secs -869.8089L0) (secs 0.03536L0)))

360)) (cap-P (mod (poly c (list (deg 174.876384L0)

(secs 0.000060L0)))

(eta (mod (poly c (list 0 (secs 47.0029L0) (secs -0.03302L0)

;; Adapted from "Astronomical Algorithms" by Jean Meeus, ;; Willmann-Bell, Inc., 1991. (let* ((c (julian-centuries tee))

4

3

2

(defun precession (tee) ;; TYPE moment -> angle ;; Precession at moment tee using 0,0 as J2000 coordinates.

1

11

9

8

6

5

;; latitude lambda and longitude beta (let* ((varepsilon (obliquity tee))) (arctan-degrees

4

3

2

1

10

(defun right-ascension (tee beta lambda) ;; TYPE (moment angle angle) -> angle ;; Right ascension at moment UT tee of object at

(cosine-degrees varepsilon)) (* (cosine-degrees beta)

8

7

;; by Jean Meeus, Willmann-Bell, Inc., 2nd ed., 1998.

(defun nth-new-moon (n) ;; TYPE integer -> moment ;; Moment of n-th new moon after (or before) the new moon ;; of January 11, 1. Adapted from "Astronomical Algorithms"

29.530588853L0)

(defconstant mean-synodic-month ;; TYPE real

(deg 180)))) (min tee (- tau (* rate cap-Delta)))))

(- (mod (- (solar-longitude tau) lambda (- (deg 180))) 360)

lambda) 360)))) (cap-Delta ; Difference in longitude.

(tau ; First approximation. (- tee (* rate (mod (- (solar-longitude tee)

;; when solar longitude just exceeded lambda degrees. (let* ((rate ; Mean change of one degree. (/ mean-tropical-year (deg 360)))

(defun estimate-prior-solar-longitude (lambda tee) ;; TYPE (season moment) -> moment ;; Approximate moment at or before tee

360))

(mod (+ (solar-longitude tee) (- (precession tee)) sidereal-start)

(defun sidereal-solar-longitude (tee) ;; TYPE moment -> season ;; Sidereal solar longitude at moment tee

(mod (- (+ p cap-P) arg) 360)))

(cap-B (cosine-degrees cap-P)) (arg (arctan-degrees cap-A cap-B)))

Appendix B. Lisp Implementation 401

-0.0016341L0 -0.00000227L0 0.000000011L0)))) (cap-omega ; Longitude of ascending node.

29

41

40

39

38

37

0 1 2 1 1 1 3 4)) (moon-coeff (list 0 0 0 2 0 0 0 -2 2 0 0 2 -2 0 0 -2 0 -2 2 2 2 -2 0 0))

(solar-coeff (list 0 1 0 0 -1 1 2 0 0 1 0 1 1 -1 2 0 3 1 0 1 -1 -1 1 0)) (lunar-coeff (list 1 0 2 0 1 1 0 1 1 2 3 0 0 2 1 2

36

35

34

33

(poly c (list 124.7746L0 (* -1.56375580L0 1236.85L0) 0.0020691L0 0.00000215L0))) (E-factor (list 0 1 0 0 1 1 2 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0))

32

31

30

28

27

(moon-argument ; Moon’s argument of latitude. (poly c (deg (list 160.7108L0 (* 390.67050274L0 1236.85L0)

1236.85L0) 0.0107438L0 0.00001239L0 -0.000000058L0))))

(lunar-anomaly (poly c (deg (list 201.5643L0 (* 385.81693528L0

26

25

24

23

22

21

20

19

18

-0.0000218L0 -0.00000011L0))))

(solar-anomaly (poly c (deg (list 2.5534L0 (* 1236.85L0 29.10535669L0)

17

16

15

-0.000000150L0 0.00000000073L0)))) (cap-E (poly c (list 1 -0.002516L0 -0.0000074L0)))

(* mean-synodic-month 1236.85L0) 0.0001337L0

(c (/ k 1236.85L0)) ; Julian centuries. (approx (+ j2000 (poly c (list 5.09765L0

(let* ((n0 24724) ; Months from RD 0 until j2000. (k (- n n0)) ; Months since j2000.

14

13

12

11

10

9

8

7

6

77

76

75

74

73

72

71

70

69

68

67

66

65

64

63

62

61

60

59

58

57

56

55

54

53

52

51

50

49

48

47

46

45

44

43

42

0.000110L0 0.000062L0 0.000060L0 0.000056L0 0.000047L0 0.000042L0 0.000040L0 0.000037L0 0.000035L0 0.000023L0))

3.592518L0)) (add-factor (list 0.000165L0 0.000164L0 0.000126L0

(list 0.016321L0 26.641886L0 36.412478L0 18.206239L0 53.303771L0 2.453732L0 7.306860L0 27.261239L0 0.121824L0 1.844379L0 24.198154L0 25.513099L0

141.74L0 207.14L0 154.84L0 34.52L0 207.19L0 291.34L0 161.72L0 239.56L0 331.55L0)) (add-coeff

(* z moon-argument))))))) (add-const (list 251.88L0 251.83L0 349.42L0 84.66L0

(sin-degrees (+ (* x solar-anomaly) (* y lunar-anomaly)

(y lunar-coeff) (z moon-coeff)) (* v (expt cap-E w)

(sigma ((v sine-coeff) (w E-factor) (x solar-coeff)

-0.00002L0 0.00002L0)) (correction (+ (* (deg -0.00017L0) (sin-degrees cap-omega))

-0.00024L0 -0.00007L0 0.00004L0 0.00004L0 0.00003L0 0.00003L0 -0.00003L0 0.00003L0 -0.00002L0

0.00739L0 -0.00514L0 0.00208L0 -0.00111L0 -0.00057L0 0.00056L0 -0.00042L0 0.00042L0 0.00038L0

(sine-coeff (list -0.40720L0 0.17241L0 0.01608L0 0.01039L0

402 Appendix B. Lisp Implementation

78

5

4

3

2

1

8

7

6

5

4

3

2

1

8

7

6

5

4

3

2

1

90

89

88

87

86

85

84

83

82

81

80

79

;; Adapted from "Astronomical Algorithms" by Jean Meeus,

(defun mean-lunar-longitude (c) ;; TYPE real -> angle ;; Mean longitude of moon (in degrees) at moment ;; given in Julian centuries c.

(n (round (- (/ (- tee t0) mean-synodic-month) (/ phi (deg 360)))))) (nth-new-moon (next k n (>= (nth-new-moon k) tee)))))

;; Moment UT of first new moon at or after tee. (let* ((t0 (nth-new-moon 0)) (phi (lunar-phase tee))

(defun new-moon-at-or-after (tee) ;; TYPE moment -> moment

(nth-new-moon (final k (1- n) (< (nth-new-moon k) tee)))))

(phi (lunar-phase tee)) (n (round (- (/ (- tee t0) mean-synodic-month) (/ phi (deg 360))))))

;; TYPE moment -> moment ;; Moment UT of last new moon before tee. (let* ((t0 (nth-new-moon 0))

(defun new-moon-before (tee)

(universal-from-dynamical (+ approx correction extra additional))))

(j add-coeff) (l add-factor)) (* l (sin-degrees (+ i (* j k)))))))

(additional (sigma ((i add-const)

-0.009173L0))))))

(sin-degrees (poly c (deg (list 299.77L0 132.8475848L0

(extra (* (deg 0.000325L0)

10

9

8

7

6

(poly c (deg (list 134.9633964L0 477198.8675055L0 0.0087414L0 1/69699 -1/14712000)))))

;; Adapted from "Astronomical Algorithms" by Jean Meeus, ;; Willmann-Bell, Inc., 2nd ed., 1998. (degrees 5

4

3

;; TYPE real -> angle ;; Mean anomaly of moon (in degrees) at moment ;; given in Julian centuries c.

(defun lunar-anomaly (c)

(deg (list 357.5291092L0 35999.0502909L0 -0.0001536L0 1/24490000)))))

;; Willmann-Bell, Inc., 2nd ed., 1998. (degrees (poly c

;; Mean anomaly of sun (in degrees) at moment ;; given in Julian centuries c. ;; Adapted from "Astronomical Algorithms" by Jean Meeus,

(defun solar-anomaly (c) ;; TYPE real -> angle

2

1

10

9

8

7

6

5

4

3

2

1

10

9

8

-0.0018819L0 1/545868 -1/113065000)))))

(degrees (poly c (deg (list 297.8501921L0 445267.1114034L0

7

6

5

;; given in Julian centuries c. ;; Adapted from "Astronomical Algorithms" by Jean Meeus, ;; Willmann-Bell, Inc., 2nd ed., 1998.

(defun lunar-elongation (c) ;; TYPE real -> angle ;; Elongation of moon (in degrees) at moment

(poly c (deg (list 218.3164477L0 481267.88123421L0 -0.0015786L0 1/538841 -1/65194000)))))

;; Willmann-Bell, Inc., 2nd ed., 1998. (degrees

4

3

2

1

10

9

8

7

6

Appendix B. Lisp Implementation 403

(cap-M-prime (lunar-anomaly c)) (cap-F (moon-node c)) (cap-E (poly c (list 1 -0.002516L0 -0.0000074L0)))

10

2 2 4 0 4 1 2 0 1 3 4 2 0 1 2)) (args-solar-anomaly (list 0 0 0 0 1 0 0 -1 0 -1 1 0 1 0 0 0 0 0 0 1 1

16

26

25

24

23

(args-moon-node

(list 1 -1 0 2 0 0 -2 -1 1 0 -1 0 1 0 1 1 -1 3 -2 -1 0 -1 0 1 2 0 -3 -2 -1 -2 1 0 2 0 -1 1 0 -1 2 -1 1 -2 -1 -1 -2 0 1 4 0 -2 0 2 1 -2 -3 2 1 -1 3))

22

21

20

0 1 -1 0 0 0 1 0 -1 0 -2 1 2 -2 0 0 -1 0 0 1 -1 2 2 1 -1 0 0 -1 0 1 0 1 0 0 -1 2 1 0)) (args-lunar-anomaly

19

18

17

15

14

(args-lunar-elongation (list 0 2 2 0 0 0 2 2 2 2 0 1 0 2 0 0 4 0 4 2 2 1 1 2 2 4 2 0 2 2 1 2 0 0 2 2 2 4 0 3 2 4 0 2

13

12

11

9

8

(cap-L-prime (mean-lunar-longitude c)) (cap-D (lunar-elongation c)) (cap-M (solar-anomaly c))

;; Adapted from "Astronomical Algorithms" by Jean Meeus, ;; Willmann-Bell, Inc., 2nd ed., 1998. (let* ((c (julian-centuries tee))

(defun lunar-longitude (tee) ;; TYPE moment -> angle ;; Longitude of moon (in degrees) at moment tee.

7

6

5

4

3

2

1

10

9

8

7

(deg (list 93.2720950L0 483202.0175233L0 -0.0036539L0 -1/3526000 1/863310000)))))

;; Willmann-Bell, Inc., 2nd ed., 1998. (degrees (poly c

6

5

4

;; Moon’s argument of latitude (in degrees) at moment ;; given in Julian centuries c. ;; Adapted from "Astronomical Algorithms" by Jean Meeus,

(defun moon-node (c) ;; TYPE real -> angle

3

2

1

27

62

61

60

59

58

57

56

55

54

53

52

51

50

49

48

47

46

45

44

43

42

41

40

39

38

37

36

35

34

33

32

31

30

29

28

(* (deg 1962/1000000) (sin-degrees (- cap-L-prime cap-F))))) (mod (+ cap-L-prime correction venus jupiter flat-earth

(flat-earth

(+ (deg 53.09L0) (* c (deg 479264.29L0))))))

(sin-degrees (+ (deg 119.75L0) (* c (deg 131.849L0)))))) (jupiter (* (deg 318/1000000) (sin-degrees

(* y cap-M-prime) (* z cap-F))))))) (venus (* (deg 3958/1000000)

(sin-degrees (+ (* w cap-D) (* x cap-M)

(y args-lunar-anomaly) (z args-moon-node)) (* v (expt cap-E (abs x))

(sigma ((v sine-coefficients) (w args-lunar-elongation) (x args-solar-anomaly)

327 -323 299 294)) (correction (* (deg 1/1000000)

-2602 2390 -2348 2236 -2120 -2069 2048 -1773 -1595 1215 -1110 -892 -810 759 -713 -700 691 596 549 537 520 -487 -399 -381 351 -340 330

58793 57066 53322 45758 -40923 -34720 -30383 15327 -12528 10980 10675 10034 8548 -7888 -6766 -5163 4987 4036 3994 3861 3665 -2689

0 0 -2 0 0 0 0 -2 -2 0 0 0 0 0 0 0)) (sine-coefficients (list 6288774 1274027 658314 213618 -185116 -114332

(list 0 0 0 0 0 2 0 0 0 0 0 0 0 -2 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 -2 2 0 2 0 0 0 0

404 Appendix B. Lisp Implementation

63

3

2

1

11

10

9

8

7

6

5

4

3

2

1

18

17

16

15

14

13

12

11

10

9

8

;; Moment UT of the next time at or after tee

(defun lunar-phase-at-or-after (phi tee) ;; TYPE (phase moment) -> moment

(b (min tee (+ tau 2)))) ; At or before tee. (invert-angular lunar-phase phi a b)))

(* mean-synodic-month (/ 1 (deg 360)) (mod (- (lunar-phase tee) phi) 360)))) (a (- tau 2))

;; when the lunar-phase was phi degrees. (let* ((tau ; Estimate. (- tee

(defun lunar-phase-at-or-before (phi tee) ;; TYPE (phase moment) -> moment ;; Moment UT of the last time at or before tee

(if (> (abs (- phi phi-prime)) (deg 180)) ; close call phi-prime phi)))

(mod (/ (- tee (nth-new-moon n)) mean-synodic-month) 1))))

(t0 (nth-new-moon 0)) (n (round (/ (- tee t0) mean-synodic-month))) (phi-prime (* (deg 360)

(let* ((phi (mod (- (lunar-longitude tee) (solar-longitude tee)) 360))

7

6

5

;; An angle of 0 means a new moon, 90 degrees means the ;; first quarter, 180 means a full moon, and 270 degrees ;; means the last quarter.

(defun lunar-phase (tee) ;; TYPE moment -> phase ;; Lunar phase, as an angle in degrees, at moment tee.

(nutation tee)) 360)))

4

3

2

1

64

4

3

2

1

5

4

3

2

1

5

4

3

2

1

;; Adapted from "Astronomical Algorithms" by Jean Meeus,

(defun lunar-latitude (tee) ;; TYPE moment -> angle ;; Latitude of moon (in degrees) at moment tee.

;; Excess of lunar longitude over solar longitude at last ;; quarter moon. (deg 270))

(defconstant last-quarter ;; TYPE phase

(deg 90))

;; TYPE phase ;; Excess of lunar longitude over solar longitude at first ;; quarter moon.

(defconstant first-quarter

(deg 180))

5

4

3

;; TYPE phase ;; Excess of lunar longitude over solar longitude at full ;; moon.

(defconstant full

;; moon. (deg 0))

(defconstant new ;; TYPE phase ;; Excess of lunar longitude over solar longitude at new

(a (max tee (- tau 2))) ; At or after tee. (b (+ tau 2))) (invert-angular lunar-phase phi a b)))

(+ tee (* mean-synodic-month (/ 1 (deg 360)) (mod (- phi (lunar-phase tee)) 360))))

;; when the lunar-phase is phi degrees. (let* ((tau ; Estimate.

2

1

5

4

3

2

1

11

10

9

8

7

6

5

4

Appendix B. Lisp Implementation 405

(cap-M-prime (lunar-anomaly c)) (cap-F (moon-node c)) (cap-E (poly c (list 1 -0.002516L0 -0.0000074L0)))

10

0 2 1 1 0 2 1 2 0 4 4 1 4 1 4 2)) (args-solar-anomaly (list 0 0 0 0 0 0 0 0 0 0 -1 0 0 1 -1 -1 -1 1 0 1

16

0 0)) (args-moon-node (list 1 1 -1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1

25

40

39

(beta (* (deg 1/1000000)

-177 176 166 -164 132 -119 115 107))

38

36

35

37

(sine-coefficients (list 5128122 280602 277693 173237 55413 46271 32573 17198 9266 8822 8216 4324 4200 -3359 2463 2211 2065 -1870 1828 -1794 -1749 -1565 -1491 -1475 -1410 -1344 -1335 1107 1021 833 777 671 607 596 491 -451 439 422 421 -366 -351 331 315 302 -283 -229 223 223 -220 -220 -185 181

34

33

32

31

30

29

28

27

26

24

23

21

-1 1 3 1 1 1 -1 -1 -1 1 -1 1 -3 1 -3 -1 -1 1 -1 1 -1 1 1 1 1 -1 3 -1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 -1 1))

(list 0 1 1 0 -1 -1 0 2 1 2 0 -2 1 0 -1 0 -1 -1 -1 0 0 -1 0 1 1 0 0 3 0 -1 1 -2 0 2 1 -2 3 2 -3 -1 0 0 1 0 1 1 0 0 -2 -1 1 -2 2 -2 -1 1 1 -2

22

20

0 1 0 1 1 1 0 0 0 0 0 0 0 0 -1 0 0 0 0 1 1 0 -1 -2 0 1 1 1 1 1 0 -1 1 0 -1 0 0 0 -1 -2)) (args-lunar-anomaly

19

18

17

15

14

(args-lunar-elongation (list 0 0 0 2 2 2 2 0 2 0 2 2 2 2 2 2 2 0 4 0 0 0 1 0 0 0 1 0 4 4 0 4 2 2 2 2 0 2 2 2 2 4 2 2

13

12

11

9

8

(cap-L-prime (mean-lunar-longitude c)) (cap-D (lunar-elongation c)) (cap-M (solar-anomaly c))

;; Willmann-Bell, Inc., 1998. (let* ((c (julian-centuries tee))

7

6

5

41

;; Algorithms" by Jean Meeus, Willmann-Bell, Inc., 1998.

TYPE (moment location) -> angle Geocentric altitude of moon at tee at locale, as a small positive/negative angle in degrees, ignoring parallax and refraction. Adapted from "Astronomical 6

5

4

3

;; ;; ;; ;;

(defun lunar-altitude (tee locale)

(sin-degrees (+ (deg 313.45L0) (* c (deg 481266.484L0))))))) (+ beta venus flat-earth extra)))

(* (deg -115/1000000) (sin-degrees (+ cap-L-prime cap-M-prime))))) (extra (* (deg 382/1000000)

(sin-degrees cap-L-prime)) (* (deg 127/1000000) (sin-degrees (- cap-L-prime cap-M-prime)))

(- cap-F)))))) (flat-earth (+ (* (deg -2235/1000000)

cap-F)) (sin-degrees (+ (deg 119.75L0) (* c (deg 131.849L0))

(venus (* (deg 175/1000000) (+ (sin-degrees (+ (deg 119.75L0) (* c (deg 131.849L0))

(* x cap-M) (* y cap-M-prime) (* z cap-F)))))))

(* v (expt cap-E (abs x)) (sin-degrees (+ (* w cap-D)

(x args-solar-anomaly) (y args-lunar-anomaly) (z args-moon-node))

(sigma ((v sine-coefficients) (w args-lunar-elongation)

2

1

70

69

68

67

66

65

64

63

62

61

60

59

58

57

56

55

54

53

52

51

50

49

48

47

46

45

44

43

42

406 Appendix B. Lisp Implementation

(cap-H ; Local hour angle. (mod (- theta0 (- psi) alpha) 360)) (altitude

21

13

12

11

10

9

8

7

(list 0 2 2 0 0 0 2 2 2 2 0 1 0 2 0 0 4 0 4 2 2 1

(cap-M-prime (lunar-anomaly c)) (cap-F (moon-node c)) (cap-E (poly c (list 1 -0.002516L0 -0.0000074L0))) (args-lunar-elongation

(let* ((c (julian-centuries tee)) (cap-D (lunar-elongation c)) (cap-M (solar-anomaly c))

6

5

4

;; Distance to moon (in meters) at moment tee. ;; Adapted from "Astronomical Algorithms" by Jean Meeus, ;; Willmann-Bell, Inc., 2nd ed.

3

2

1

29

28

(defun lunar-distance (tee) ;; TYPE moment -> distance

(cosine-degrees delta) (cosine-degrees cap-H)))))) (- (mod (+ altitude (deg 180)) 360) (deg 180))))

27

26

25

(arcsin-degrees (+ (* (sin-degrees phi) (sin-degrees delta)) (* (cosine-degrees phi)

24

23

22

20

19

(declination tee beta lambda)) (theta0 ; Sidereal time. (sidereal-from-moment tee))

(alpha ; Lunar right ascension. (right-ascension tee beta lambda)) (delta ; Lunar declination.

(lunar-longitude tee)) (beta ; Lunar latitude. (lunar-latitude tee))

(psi ; Local longitude. (longitude locale)) (lambda ; Lunar longitude.

(let* ((phi ; Local latitude. (latitude locale))

18

17

16

15

14

13

12

11

10

9

8

7

14

48

47

46

45

44

43

42

41

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

20

19

18

17

16

15

args-lunar-elongation) args-solar-anomaly) args-lunar-anomaly) args-moon-node))

(* x cap-M) (* y cap-M-prime)

(* v (expt cap-E (abs x)) (cosine-degrees (+ (* w cap-D)

(w (x (y (z

8752)) (correction (sigma ((v cosine-coefficients)

-7003 0 10056 6322 -9884 5751 0 -4950 4130 0 -3958 0 3258 2616 -1897 -2117 2354 0 0 -1423 -1117 -1571 -1739 0 -4421 0 0 0 0 1165 0 0

246158 -152138 -170733 -204586 -129620 108743 104755 10321 0 79661 -34782 -23210 -21636 24208 30824 -8379 -16675 -12831 -10445 -11650 14403

0 0 -2 0 0 0 0 -2 -2 0 0 0 0 0 0 0 -2)) (cosine-coefficients (list -20905355 -3699111 -2955968 -569925 48888 -3149

(args-moon-node (list 0 0 0 0 0 2 0 0 0 0 0 0 0 -2 2 -2 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 -2 2 0 2 0 0 0 0

-1 0 -1 0 1 2 0 -3 -2 -1 -2 1 0 2 0 -1 1 0 -1 2 -1 1 -2 -1 -1 -2 0 1 4 0 -2 0 2 1 -2 -3 2 1 -1 3 -1))

-1 2 2 1 -1 0 0 -1 0 1 0 1 0 0 -1 2 1 0 0)) (args-lunar-anomaly (list 1 -1 0 2 0 0 -2 -1 1 0 -1 0 1 0 1 1 -1 3 -2

(args-solar-anomaly (list 0 0 0 0 1 0 0 -1 0 -1 1 0 1 0 0 0 0 0 0 1 1 0 1 -1 0 0 0 1 0 -1 0 -2 1 2 -2 0 0 -1 0 0 1

1 2 2 4 2 0 2 2 1 2 0 0 2 2 2 4 0 3 2 4 0 2 2 2 4 0 4 1 2 0 1 3 4 2 0 1 2 2))

Appendix B. Lisp Implementation 407

(let* ((phi (latitude locale)) (tee-prime (universal-from-local tee locale)) (delta ; Declination of sun.

(declination tee-prime (deg 0L0) (solar-longitude tee-prime)))) (+ (* (tangent-degrees phi) (tangent-degrees delta))

7

10

14

13

12

11

9

8

6

5

(/ (sin-degrees alpha)

;; local time tee and ;; when its depression is alpha at locale. ;; Out of range when it does not occur.

4

3

2

(defun sine-offset (tee locale alpha) ;; TYPE (moment location angle) -> real ;; Sine of angle between position of sun at

1

7

Times of day are computed by the following functions:

(- (lunar-altitude tee locale) (lunar-parallax tee locale)))

6

5

4

;; Topocentric altitude of moon at tee at locale, ;; as a small positive/negative angle in degrees, ;; ignoring refraction.

(defun topocentric-lunar-altitude (tee locale) ;; TYPE (moment location) -> angle

(arcsin-degrees arg)))

(Delta (lunar-distance tee)) (alt (/ (mt 6378140) Delta)) (arg (* alt (cosine-degrees geo))))

;; Adapted from "Astronomical ;; Algorithms" by Jean Meeus, Willmann-Bell, Inc., 1998. (let* ((geo (lunar-altitude tee locale))

(defun lunar-parallax (tee locale) ;; TYPE (moment location) -> angle ;; Parallax of moon at tee at locale.

(* z cap-F))))))) (+ (mt 385000560) correction)))

3

2

1

10

9

8

7

6

5

4

3

2

1

50

49

7

6

5

4

3

2

1

26

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

Moment in local time near approx when depression angle of sun is alpha (negative if above horizon) at locale; early? is true when morning event is sought, and false for evening. ;; Returns bogus if depression angle is not reached.

;; ;; ;; ;;

(defun moment-of-depression (approx locale alpha early?) ;; TYPE (moment location angle boolean) -> moment

locale) bogus)))

1) (hr 6))))

(/ (arcsin-degrees value) (deg 360)))

(+ date (hr 12) (* (if early? -1 1) (- (mod (+ (hr 12)

try))) (if ( (abs try) 1) (sine-offset alt locale alpha)

(date (fixed-from-moment tee)) (alt (if (>= alpha 0) (if early? date (1+ date))

;; and false for evening. Returns bogus if depression ;; angle is not reached. (let* ((try (sine-offset tee locale alpha))

6

5

4

;; Moment in local time near tee when depression angle ;; of sun is alpha (negative if above horizon) at ;; locale; early? is true when morning event is sought

(defun approx-moment-of-depression (tee locale alpha early?) ;; TYPE (moment location angle boolean) -> moment

(* (cosine-degrees delta) (cosine-degrees phi))))))

3

2

1

16

15

408 Appendix B. Lisp Implementation

;; Returns bogus if there is no dawn on date. (let* ((result (moment-of-depression (+ date (hr 6)) locale alpha morning)))

5

7

6

5

4

3

2

(+ date (hr 18)) locale alpha evening)))

;; Standard time in evening on fixed date at ;; locale when depression angle of sun is alpha. ;; Returns bogus if there is no dusk on date. (let* ((result (moment-of-depression

(defun dusk (date locale alpha) ;; TYPE (fixed-date location angle) -> moment

1

10

9

(if (equal result bogus) bogus (standard-from-local result locale))))

8

7

6

4

3

;; TYPE (fixed-date location angle) -> moment ;; Standard time in morning on fixed date at ;; locale when depression angle of sun is alpha.

(defun dawn (date locale alpha)

2

1

4

3

2

false)

(defconstant evening ;; TYPE boolean ;; Signifies evening.

1

4

;; Signifies morning. true)

(defconstant morning ;; TYPE boolean

tee (moment-of-depression tee locale alpha early?)))))

(sec 30))

(if (equal tee bogus) bogus (if (< (abs (- approx tee))

(let* ((tee (approx-moment-of-depression approx locale alpha early?)))

3

2

1

15

14

13

12

11

10

9

8

3

2

1

5

4

3

2

1

11

10

9

8

7

6

5

4

3

2

1

11

10

9

8

7

6

;; Standard time of end of Jewish sabbath on fixed date

(defun jewish-sabbath-ends (date locale) ;; TYPE (fixed-date location) -> moment

;; TYPE (fixed-date location) -> moment ;; Standard time of Jewish dusk on fixed date ;; at locale (as per Vilna Gaon). (dusk date locale (angle 4 40 0)))

(defun jewish-dusk (date locale)

(dusk date locale alpha)))

(arccos-degrees (/ cap-R (+ cap-R h)))) (alpha (+ (angle 0 50 0) dip (* (secs 19) (sqrt h)))))

(let* ((h (max (mt 0) (elevation locale))) (cap-R (mt 6.372d6)) ; Radius of Earth. (dip ; Depression of visible horizon.

;; TYPE (fixed-date location) -> moment ;; Standard time of sunset on fixed date at ;; locale.

(defun sunset (date locale)

(dawn date locale alpha)))

(arccos-degrees (/ cap-R (+ cap-R h)))) (alpha (+ (angle 0 50 0) dip (* (secs 19) (sqrt h)))))

(let* ((h (max (mt 0) (elevation locale))) (cap-R (mt 6.372d6)) ; Radius of Earth. (dip ; Depression of visible horizon.

5

4

3

;; TYPE (fixed-date location) -> moment ;; Standard time of sunrise on fixed date at ;; locale.

(defun sunrise (date locale)

(standard-from-local result locale))))

(if (equal result bogus) bogus

2

1

10

9

8

Appendix B. Lisp Implementation 409

(let* ((date (fixed-from-moment tee)) (hour (* 24 (mod tee 1))) (h (cond (( moment ;; Standard time of asr on fixed date at locale. (let* ((noon; Time when sun nearest zenith.

(defun asr (date locale)

(standard-from-sundial (+ date (hr 10)) locale))

;; TYPE (fixed-date location) -> moment ;; Standard time on fixed date at locale of end of ;; morning according to Jewish ritual.

(defun jewish-morning-end (date locale)

(t ; this evening (+ (sunset date locale) (* (- hour 18) h))))))

(+ (sunrise date locale) (* (- hour 6) h))) ((< hour 6) ; early this morning (+ (sunset (1- date) locale) (* (+ hour 6) h)))

(cond ((equal h bogus) bogus) (( moment ;; Standard time of temporal moment tee at locale. ;; Returns bogus if temporal hour is undefined that day.

(defun standard-from-sundial (tee locale)

(sunset date locale)) 12)))

(equal (sunset date locale) bogus)) bogus (/ (- (sunrise (1+ date) locale)

;; Length of nighttime temporal hour on fixed date at locale. ;; Returns bogus if there no sunrise or sunset on date. (if (or (equal (sunrise (1+ date) locale) bogus)

(defun nighttime-temporal-hour (date locale) ;; TYPE (fixed-date location) -> real

12)))

bogus (/ (- (sunset date locale) (sunrise date locale))

;; Returns bogus if there no sunrise or sunset on date. (if (or (equal (sunrise date locale) bogus) (equal (sunset date locale) bogus))

(defun daytime-temporal-hour (date locale) ;; TYPE (fixed-date location) -> real ;; Length of daytime temporal hour on fixed date at locale.

;; at locale (as per Berthold Cohn). (dusk date locale (angle 7 5 0)))

2

1

10

9

8

7

6

5

4

3

2

1

10

9

8

7

6

5

4

3

2

1

5

4

410 Appendix B. Lisp Implementation

2

1

10

9

8

7

6

5

4

3

2

1

6

5

4

3

2

1

5

4

3

2

1

4

3

2

;; TYPE persian-date -> fixed-date

(defun fixed-from-persian (p-date)

(+ spring (deg 2))))))

spring (midday-in-tehran date)))) (next day (- (floor approx) 1) ( fixed-date ;; Fixed date of Astronomical Persian New Year on or

tehran))

;; Universal time of midday on fixed date in Tehran. (universal-from-standard (midday date tehran)

(defun midday-in-tehran (date) ;; TYPE fixed-date -> moment

;; Location of Tehran, Iran. (location (deg 35.68L0) (deg 51.42L0) (mt 1100) (hr (+ 3 1/2))))

(defconstant tehran ;; TYPE location

;; Fixed date of start of the Persian calendar. (fixed-from-julian (julian-date (ce 622) march 19)))

(defconstant persian-epoch ;; TYPE fixed-date

1

4

;; TYPE -> persian-date (list year month day))

(defun persian-date (year month day) ;; TYPE (persian-year persian-month persian-day)

3

2

1

B.16 The Persian Calendar

11

19

18

17

16

15

14

13

12

(- date (1- (fixed-from-persian

(month (if ( persian-date

(* 31 (1- month)) (+ (* 30 (1- month)) 6)) day))) ; Days so far this month.

year))))))); No year zero. (+ (1- new-year) ; Days in prior years. (if ( fixed-date ;; Fixed date equivalent to Persian date p-date.

31)))

128)

(+ (mod y 2820) 474))) (< (mod (* (+ year 38) 31)

(- p-year 474) (- p-year 473))); No year zero (year ; Equivalent year in the range 474...3263

;; True if p-year is a leap year on the Persian calendar. (let* ((y ; Years since start of 2820-year cycles (if (< 0 p-year)

(defun arithmetic-persian-leap-year? (p-year) ;; TYPE persian-year -> boolean

(persian-date year month 1)))))) (persian-date year month day)))

7

6

5

4

3

2

1

13

12

11

10

9

8

7

6

5

4

3

2

1

21

20

;; Persian date corresponding to fixed date.

(defun arithmetic-persian-from-fixed (date) ;; TYPE fixed-date -> persian-date

; cycle (if (< 0 year) year (1- year)))); No year zero

(+ 474 ; Years before start of 2820-year cycles (* 2820 n2820) ; Years in prior 2820-year cycles y2820))); Years since start of last 2820-year

(quotient (+ (* 128 d1) 46878) 46751))) (year ; Years since Persian epoch

;; Last day of 2820-year cycle 2820 ;; Otherwise use cycle of years formula

(mod d0 1029983)) (y2820 ; Years since start of last 2820-year cycle (if (= d1 1029982)

(quotient d0 1029983)) (d1 ; Prior days not in n2820--that is, days ; since start of last 2820-year cycle

(- date (fixed-from-arithmetic-persian (persian-date 475 1 1)))) (n2820 ; Completed prior 2820-year cycles

;; Persian year corresponding to the fixed date. (let* ((d0 ; Prior days since start of 2820-year cycle ; beginning in Persian year 474

(defun arithmetic-persian-year-from-fixed (date) ;; TYPE fixed-date -> persian-year

(* 31 (1- month)) (+ (* 30 (1- month)) 6)) day))) ; Days so far this month

(- (* 31 year) 5) 128) (if ( bahai-date (list major cycle year month day))

(defun bahai-date (major cycle year month day) ;; TYPE (bahai-major bahai-cycle bahai-year

B.17 The Bahá’í Calendar

(1- persian-year) persian-year))) (fixed-from-persian (persian-date y 1 1))))

(let* ((persian-year (1+ (- g-year (gregorian-year-from-fixed

5

4

3

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Persian New Year (Naw-Ruz) in Gregorian ;; year g-year.

(defun naw-ruz (g-year)

(- date (1- (fixed-from-arithmetic-persian (persian-date year month 1)))))) (persian-date year month day)))

(day

(ceiling (/ day-of-year 31)) (ceiling (/ (- day-of-year 6) 30)))) ; Calculate the day by subtraction

(fixed-from-arithmetic-persian (persian-date year 1 1))))) (month (if ( fixed-date ;; Fixed date equivalent to the Bahai date b-date. (let* ((major (bahai-major b-date))

(defun fixed-from-bahai (b-date)

(fixed-from-gregorian (gregorian-date 1844 march 21)))

(defconstant bahai-epoch ;; TYPE fixed-date ;; Fixed date of start of Bahai calendar.

;; TYPE bahai-month ;; Signifies intercalary period of 4 or 5 days. 0)

(defconstant ayyam-i-ha

;; TYPE bahai-date -> bahai-day (fifth date))

(defun bahai-day (date)

(fourth date))

(defun bahai-month (date) ;; TYPE bahai-date -> bahai-month

(third date))

(defun bahai-year (date) ;; TYPE bahai-date -> bahai-year

(second date))

(defun bahai-cycle (date) ;; TYPE bahai-date -> bahai-cycle

5

4

3

2

1

4

3

2

1

4

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

Appendix B. Lisp Implementation 413

26

25

24

23

22

21

20

19

18

17

(fixed-from-bahai

(fixed-from-bahai (bahai-date major cycle year 19 1))) 19) ; Last month of year. ((>= date ; Intercalary days.

(month (cond ((>= date

(bahai-date major cycle year 1 1))))

(year (1+ (mod years 19))) (days; Since start of year (- date (fixed-from-bahai

16

15

14

1 0))) (major (1+ (quotient years 361))) (cycle (1+ (quotient (mod years 361) 19)))

13

12

11

10

9

8

(if ( bahai-date ;; Bahai (major cycle year month day) corresponding to fixed

(t (* 19 (1- month)))); Elapsed months. day))) ; Days of current month.

21

20

19

(if (gregorian-leap-year? (1+ g-year)) 347 ; Long ayyam-i-ha. 346)); Ordinary ayyam-i-ha.

(cond ((= month ayyam-i-ha) ; Intercalary period. 342) ; 18 months have elapsed. ((= month 19); Last month of year.

(+ (fixed-from-gregorian ; Prior years. (gregorian-date g-year march 20))

18

17

16

15

14

13

27

28

27

26

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

34

33

32

31

30

29

28

(floor (* mean-tropical-year

(- years 1/2))))) 341 day)) (t (+ (future-bahai-new-year-on-or-before (+ bahai-epoch

(+ (future-bahai-new-year-on-or-before (+ bahai-epoch (floor (* mean-tropical-year

-20 day)) ((= month ayyam-i-ha) ; intercalary month, between 18th & 19th

(+ bahai-epoch (floor (* mean-tropical-year (+ years 1/2)))))

year))) (cond ((= month 19); last month of year (+ (future-bahai-new-year-on-or-before

(years; Years from epoch (+ (* 361 (1- major)) (* 19 (1- cycle))

(year (bahai-year b-date)) (month (bahai-month b-date)) (day (bahai-day b-date))

;; Fixed date of Bahai date b-date. (let* ((major (bahai-major b-date)) (cycle (bahai-cycle b-date))

(defun fixed-from-future-bahai (b-date) ;; TYPE bahai-date -> fixed-date

(fixed-from-bahai (bahai-date major cycle year month 1))))) (bahai-date major cycle year month day)))

ayyam-i-ha) ; Intercalary period. (t (1+ (quotient days 19))))) (day (- date -1

(bahai-date major cycle year ayyam-i-ha 1)))

414 Appendix B. Lisp Implementation

(cycle (1+ (quotient (mod years 361) 19))) (year (1+ (mod years 19))) (days; Since start of year

(- date new-year)) (month (cond

8

11

19) ((>= date (fixed-from-future-bahai

17

5

4

3

2

(gregorian-date g-year march 21)))

(defun bahai-new-year (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Bahai New Year in Gregorian year g-year. (fixed-from-gregorian

1

27

(bahai-date major cycle year month 1))))) (bahai-date major cycle year month day)))

(t (1+ (quotient days 19))))) (day (- date -1 (fixed-from-future-bahai

26

25

24

23

22

21

20

19

18

16

(bahai-date major cycle year ayyam-i-ha 1))) ; intercalary month ayyam-i-ha)

((>= date (fixed-from-future-bahai (bahai-date major cycle year 19 1))) ; last month of year

15

14

13

12

10

9

7

6

(years (round (/ (- new-year bahai-epoch) mean-tropical-year))) (major (1+ (quotient years 361)))

;; TYPE fixed-date -> bahai-date ;; Future Bahai date corresponding to fixed date. (let* ((new-year (future-bahai-new-year-on-or-before date))

5

4

3

2

1

(defun future-bahai-from-fixed (date)

3

day -1)))))

31

11

10

9

8

7

6

5

4

3

2

1

10

9

8

7

6

(fixed-from-future-bahai (bahai-date major cycle year 2 13))))

(major (1+ (quotient years 361))) (cycle (1+ (quotient (mod years 361) 19))) (year (1+ (mod years 19))))

(let* ((years (- g-year (gregorian-year-from-fixed bahai-epoch)))

(defun feast-of-ridvan (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Feast of Ridvan in Gregorian year g-year.

(next day (1- (floor approx)) ( fixed-date ;; Fixed date of Future Bahai New Year on or before fixed ;; date.

(defun future-bahai-new-year-on-or-before (date)

haifa))

;; in Haifa. (universal-from-standard (sunset date haifa)

(defun sunset-in-haifa (date) ;; TYPE fixed-date -> moment ;; Universal time of sunset of evening before fixed date

;; Location of Haifa, Israel. (location (deg 32.82L0) (deg 35) (mt 0) (hr 2)))

(defconstant haifa ;; TYPE location

2

1

7

6

5

4

3

2

1

4

2

1

(- years 1/2))))) (* (1- month) 19)

30

29

Appendix B. Lisp Implementation 415

(location (angle 48 50 11) (angle 2 20 15) (mt 27) (hr 1)))

6

10

9

8

7

6

(next day (- (floor approx) 1) ( fixed-date ;; Fixed date of French Revolutionary New Year on or ;; before fixed date.

(defun french-new-year-on-or-before (date)

(midnight (+ date 1) paris) paris))

;; Universal time of true midnight at end of fixed date ;; in Paris. (universal-from-standard

2

1

7

6

5

4

3

2

1

5

(defun midnight-in-paris (date) ;; TYPE fixed-date -> moment

;; Location of Paris Observatory. Longitude corresponds ;; to difference of 9m 21s between Paris time zone and ;; Universal Time.

4

3

2

1

(defconstant paris ;; TYPE location

(fixed-from-gregorian (gregorian-date 1792 september 22)))

5

4

3

;; TYPE fixed-date ;; Fixed date of start of the French Revolutionary ;; calendar.

(defconstant french-epoch

1

2

(list year month day))

(defun french-date (year month day) ;; TYPE (french-year french-month french-day) -> french-date

3

2

1

B.18 The French Revolutionary Calendar

3

2

1

7

6

5

4

3

2

1

10

9

8

7

6

5

4

3

2

1

14

13

12

11

10

9

8

7

Days in prior years Days in prior months Days this month

;; Fixed date of French Revolutionary date f-date.

(defun fixed-from-arithmetic-french (f-date) ;; TYPE french-date -> fixed-date

(not (member (mod f-year 400) (list 100 200 300))) (not (= (mod f-year 4000) 0))))

;; True if f-year is a leap year on the French ;; Revolutionary calendar. (and (= (mod f-year 4) 0)

(defun arithmetic-french-leap-year? (f-year) ;; TYPE french-year -> boolean

(french-date year month day)))

mean-tropical-year)))) (month (1+ (quotient (- date new-year) 30))) (day (1+ (mod (- date new-year) 30))))

(let* ((new-year (french-new-year-on-or-before date)) (year (1+ (round (/ (- new-year french-epoch)

(defun french-from-fixed (date) ;; TYPE fixed-date -> french-date ;; French Revolutionary date of fixed date.

(+ new-year -1 ; (* 30 (1- month)); day))) ;

(floor (+ french-epoch 180; Spring after epoch. (* mean-tropical-year (1- year)))))))

(year (standard-year f-date)) (new-year (french-new-year-on-or-before

6

5

4

;; Fixed date of French Revolutionary date. (let* ((month (standard-month f-date)) (day (standard-day f-date))

(defun fixed-from-french (f-date) ;; TYPE french-date -> fixed-date

3

2

1

416 Appendix B. Lisp Implementation

day))); Days this month.

15

;; date. (let* ((approx ; Approximate year (may be off by 1). (1+ (quotient (- date french-epoch -2)

4

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

3

(fixed-from-arithmetic-french (french-date year month 1)))))) (french-date year month day)))

30))) (day ; Calculate the day by subtraction. (1+ (- date

(month ; Calculate the month by division. (1+ (quotient (- date (fixed-from-arithmetic-french (french-date year 1 1)))

(french-date approx 1 1))) (1- approx) approx))

1460969/4000))) (year (if (< date (fixed-from-arithmetic-french

(defun arithmetic-french-from-fixed (date) ;; TYPE fixed-date -> french-date ;; French Revolutionary date (year month day) of fixed

2

1

13

12

14

; Leap days in prior years. (quotient (1- year) 4) (- (quotient (1- year) 100))

(year (standard-year f-date))) (+ french-epoch -1; Days before start of calendar. (* 365 (1- year)); Ordinary days in prior years.

(let* ((month (standard-month f-date)) (day (standard-day f-date))

(quotient (1- year) 400) (- (quotient (1- year) 4000)) (* 30 (1- month)); Days in prior months this year.

11

10

9

8

7

6

5

4

9

8

7

6

5

4

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

4

3

2

1

(amod (+ 2 (quotient s (deg 30))) 12)))

(universal-from-standard date (chinese-location date)))))

;; Last Chinese major solar term (zhongqi) before fixed ;; date. (let* ((s (solar-longitude

(defun current-major-solar-term (date) ;; TYPE fixed-date -> integer

(defun chinese-day (date) ;; TYPE chinese-date -> chinese-day (fifth date))

(fourth date))

(defun chinese-leap (date) ;; TYPE chinese-date -> chinese-leap

(defun chinese-month (date) ;; TYPE chinese-date -> chinese-month (third date))

;; TYPE chinese-date -> chinese-year (second date))

(defun chinese-year (date)

(first date))

(defun chinese-cycle (date) ;; TYPE chinese-date -> chinese-cycle

;; TYPE chinese-leap chinese-day) -> chinese-date (list cycle year month leap day))

(defun chinese-date (cycle year month leap day) ;; TYPE (chinese-cycle chinese-year chinese-month

B.19 The Chinese Calendar

Appendix B. Lisp Implementation 417

(let* ((tee (solar-longitude-after lambda (universal-from-standard

6

3

2

1

9

8

7

6

;; Last Chinese minor solar term (jieqi) before date.

(defun current-minor-solar-term (date) ;; TYPE fixed-date -> integer

(l (mod (* 30 (ceiling (/ s 30))) 360))) (chinese-solar-longitude-on-or-after l date)))

;; major terms begin when the sun’s longitude is a ;; multiple of 30 degrees. (let* ((s (solar-longitude (midnight-in-china date)))

5

4

3

;; TYPE fixed-date -> moment ;; Moment (in Beijing) of the first Chinese major ;; solar term (zhongqi) on or after fixed date. The

(defun major-solar-term-on-or-after (date)

tee (chinese-location tee))))

2

1

13

12

11

10

9

8

7

5

4

date (chinese-location date))))) (standard-from-universal

;; Moment (Beijing time) of the first date on or after ;; fixed date (Beijing time) when the solar longitude ;; will be lambda degrees.

3

2

(defun chinese-solar-longitude-on-or-after (lambda date) ;; TYPE (season moment) -> moment

(mt 43.5) (hr 8)))))

(location (angle 39 55 0) (angle 116 25 0) (mt 43.5) (hr 1397/180)) (location (angle 39 55 0) (angle 116 25 0)

;; Location of Beijing; time zone varies with tee. (let* ((year (gregorian-year-from-fixed (floor tee)))) (if (< year 1929)

(defun chinese-location (tee) ;; TYPE moment -> location

1

9

8

7

6

5

4

3

2

1

4

3

2

1

10

9

8

7

6

5

4

3

2

1

14

13

12

11

10

9

8

7

6

5

4

3

2

1

9

8

7

6

5

4

;; fixed date.

(defun chinese-new-moon-on-or-after (date) ;; TYPE fixed-date -> fixed-date ;; Fixed date (Beijing) of first new moon on or after

(chinese-location tee)))))

(floor (standard-from-universal tee

;; date. (let* ((tee (new-moon-before (midnight-in-china date))))

(defun chinese-new-moon-before (date) ;; TYPE fixed-date -> fixed-date ;; Fixed date (Beijing) of first new moon before fixed

(deg 15)) 360))) (chinese-solar-longitude-on-or-after l date)))

(+ (* 30 (ceiling (/ (- s (deg 15)) 30)))

;; degrees. (let* ((s (solar-longitude (midnight-in-china date))) (l (mod

;; Moment (in Beijing) of the first Chinese minor solar ;; term (jieqi) on or after fixed date. The minor terms ;; begin when the sun’s longitude is an odd multiple of 15

(defun minor-solar-term-on-or-after (date) ;; TYPE fixed-date -> moment

12)))

date (chinese-location date))))) (amod (+ 3 (quotient (- s (deg 15)) (deg 30)))

(let* ((s (solar-longitude (universal-from-standard

418 Appendix B. Lisp Implementation

;; date in China. (universal-from-standard date (chinese-location date)))

4

10

9

8

7

6

5

4

3

2

1

5

3

(< winter (solar-longitude (midnight-in-china (1+ day)))))))

(estimate-prior-solar-longitude winter (midnight-in-china (+ date 1))))) (next day (1- (floor approx))

;; Fixed date, in the Chinese zone, of winter solstice ;; on or before fixed date. (let* ((approx ; Approximate time of solstice.

(defun chinese-winter-solstice-on-or-before (date) ;; TYPE fixed-date -> fixed-date

(defun midnight-in-china (date) ;; TYPE fixed-date -> moment ;; Universal time of (clock) midnight at start of fixed

1

2

(chinese-new-moon-on-or-after (+ date 1)))))

;; has no major solar term. (= (current-major-solar-term date) (current-major-solar-term

(defun chinese-no-major-solar-term? (date) ;; TYPE fixed-date -> boolean ;; True if Chinese lunar month starting on date

(fixed-from-gregorian (gregorian-date -2636 february 15)))

(defconstant chinese-epoch ;; TYPE fixed-date ;; Fixed date of start of the Chinese calendar.

(chinese-location tee)))))

(floor (standard-from-universal tee

(let* ((tee (new-moon-at-or-after (midnight-in-china date))))

7

6

5

4

3

2

1

4

3

2

1

10

9

8

7

6

5

11

(chinese-new-year-in-sui (- date 180))))) 10

9

8

; Got the New Year after--this happens if date is ; after the solstice but before the new year. ; So, go back half a year.

(let* ((new-year (chinese-new-year-in-sui date))) (if (>= date new-year) new-year

(defun chinese-new-year-on-or-before (date) ;; TYPE fixed-date -> fixed-date ;; Fixed date of Chinese New Year on or before fixed date.

(chinese-new-moon-on-or-after (1+ m13)) m13)))

12) (or (chinese-no-major-solar-term? m12) (chinese-no-major-solar-term? m13)))

; either m12 or m13 has no major solar term (and (= (round (/ (- next-m11 m12) mean-synodic-month))

(chinese-new-moon-before (1+ s2)))) (if ; Either m12 or m13 is a leap month if there are ; 13 new moons (12 full lunar months) and

7

6

5

4

3

2

1

25

24

23

22

21

20

19

18

17

16

15

14

13

12

(m13 ; month after m12--either 12 (or leap 12) or 1 (chinese-new-moon-on-or-after (1+ m12))) (next-m11 ; next 11th month

(+ s1 370))) (m12 ; month after 11th month--either 12 or leap 11 (chinese-new-moon-on-or-after (1+ s1)))

9 10

8

7

(chinese-winter-solstice-on-or-before date)) (s2; following solstice (chinese-winter-solstice-on-or-before

;; Fixed date of Chinese New Year in sui (period from ;; solstice to solstice) containing date. (let* ((s1; prior solstice

(defun chinese-new-year-in-sui (date) ;; TYPE fixed-date -> fixed-date

6

5

4

3

2

1

Appendix B. Lisp Implementation 419

(m12 ; month after last 11th month (chinese-new-moon-on-or-after (1+ s1))) (next-m11; next 11th month

(chinese-new-moon-before (1+ s2))) (m ; start of month containing date (chinese-new-moon-before (1+ date)))

(leap-year; if there are 13 new moons (12 full ; lunar months) (= (round (/ (- next-m11 m12)

8

11

14

20

; it’s a leap month if...

(leap-month

30

18 19

29

27

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

46

45

44

43

42

41

40

39

38

37

36

35

34

33

28

(chinese-prior-leap-month? m12 m))

(round (/ (- m m12) mean-synodic-month)) ;; minus 1 during or after a leap month (if (and leap-year

(amod (;; ordinal position of month in year

12)) (month ; month number

31 32

1 0)) 12))

26

25

24

23

22

21

20

19

18

17

16

15

13

12

10

9

7

6

mean-synodic-month))

(chinese-winter-solstice-on-or-before date)) (s2; Following solstice (chinese-winter-solstice-on-or-before (+ s1 370)))

5

4

3

;; TYPE fixed-date -> chinese-date ;; Chinese date (cycle year month leap day) of fixed date. (let* ((s1; Prior solstice

(defun chinese-from-fixed (date)

(gregorian-date g-year july 1))))

;; Fixed date of Chinese New Year in Gregorian year g-year. (chinese-new-year-on-or-before (fixed-from-gregorian

(defun chinese-new-year (g-year) ;; TYPE gregorian-year -> fixed-date

2

1

6

5

4

3

2

1

(+ new-year (* (1- month) 29))))

(new-year (chinese-new-year-on-or-before mid-year)) (p; new moon before date--a month too early if ; there was prior leap month that year (chinese-new-moon-on-or-after

(1- year) ; prior years this cycle 1/2) ; half a year mean-tropical-year))))

(floor (+ chinese-epoch (* (+ (* (1- cycle) 60); years in prior cycles

(leap (chinese-leap c-date)) (day (chinese-day c-date)) (mid-year ; Middle of the Chinese year

(let* ((cycle (chinese-cycle c-date)) (year (chinese-year c-date)) (month (chinese-month c-date))

(defun fixed-from-chinese (c-date) ;; TYPE chinese-date -> fixed-date ;; Fixed date of Chinese date c-date.

(day (1+ (- date m)))) (chinese-date cycle year month leap-month day)))

mean-tropical-year)))) (cycle (1+ (quotient (1- elapsed-years) 60))) (year (amod elapsed-years 60))

(floor (+ 1.5L0 ; 18 months (because of truncation) (- (/ month 12)); after at start of year (/ (- date chinese-epoch)

; month m12 (chinese-new-moon-before m))))) (elapsed-years ; Approximate since the epoch

(chinese-no-major-solar-term? m) ; no major solar term (not (chinese-prior-leap-month? ; and no prior leap

(and leap-year; ...there are 13 months

420 Appendix B. Lisp Implementation

21

; If the months match... (and (= month (chinese-month d)) (equal leap (chinese-leap d)))

m-prime (chinese-new-moon-before m)))))

9

;; TYPE (chinese-stem chinese-branch) -> chinese-name ;; Returns bogus if stem/branch combination is ;; impossible.

(if (= (mod stem 2) (mod branch 2)) (list stem branch) bogus))

(defun chinese-stem (name) ;; TYPE chinese-name -> chinese-stem (first name))

(defun chinese-branch (name) ;; TYPE chinese-name -> chinese-branch (second name))

5

1

1

3

2

3

2

7

6

4

3

2

1

10

8

7

(defun chinese-name (stem branch)

(and (>= m m-prime) (or (chinese-no-major-solar-term? m) (chinese-prior-leap-month?

6

5

4

;; True if there is a Chinese leap month on or after lunar ;; month starting on fixed day m-prime and at or before ;; lunar month starting at fixed date m.

(defun chinese-prior-leap-month? (m-prime m) ;; TYPE (fixed-date fixed-date) -> boolean

(chinese-new-moon-on-or-after (1+ p))))) (+ prior-new-moon day -1)))

p; ...that’s the right month ;; otherwise, there was a prior leap month that ;; year, so we want the next month

(if

(d (chinese-from-fixed p)) (prior-new-moon

3

2

1

30

29

28

27

26

25

24

23

22

5

4

3

2

1

5

4

3

2

1

4

3

2

1

14

13

12

11

10

9

8

7

6

5

4

3

2

1

5

4

3

2

1

(let* ((elapsed-months (+ (* 12 (1- year))

(defun chinese-name-of-month (month year) ;; TYPE (chinese-month chinese-year) -> chinese-name ;; Sexagesimal name for month month of Chinese year ;; year.

;; cycle. 57)

(defconstant chinese-month-name-epoch ;; TYPE integer ;; Elapsed months at start of Chinese sexagesimal month

;; Sexagesimal name for Chinese year of any cycle. (chinese-sexagesimal-name year))

(defun chinese-name-of-year (year) ;; TYPE chinese-year -> chinese-name

(* 25 (- branch-difference stem-difference))) 60))))

(stem-difference (- stem2 stem1)) (branch-difference (- branch2 branch1))) (1+ (mod (+ (1- stem-difference)

(stem2 (chinese-stem c-name2)) (branch1 (chinese-branch c-name1)) (branch2 (chinese-branch c-name2))

;; Number of names from Chinese name c-name1 to the ;; next occurrence of Chinese name c-name2. (let* ((stem1 (chinese-stem c-name1))

(defun chinese-name-difference (c-name1 c-name2) ;; TYPE (chinese-name chinese-name) -> nonnegative-integer

;; The n-th name of the Chinese sexagesimal cycle. (chinese-name (amod n 10) (amod n 12)))

(defun chinese-sexagesimal-name (n) ;; TYPE integer -> chinese-name

Appendix B. Lisp Implementation 421

11

10

9

8

7

6

5

4

3

2

1

11

10

9

8

7

6

5

4

3

2

1

5

4

3

2

1

4

3

2

1

8

7

6

(fixed-from-chinese (chinese-date cycle year 5 false 5))))

(gregorian-year-from-fixed chinese-epoch)))) (cycle (1+ (quotient (1- elapsed-years) 60))) (year (amod elapsed-years 60)))

;; Gregorian year g-year. (let* ((elapsed-years (1+ (- g-year

(defun dragon-festival (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of the Dragon Festival occurring in

(chinese-sexagesimal-name chinese-day-name-epoch))) 60)))

(mod (+ date (chinese-name-difference name

;; Fixed date of latest date on or before fixed date ;; that has Chinese name. (- date

(defun chinese-day-name-on-or-before (name date) ;; TYPE (chinese-name fixed-date) -> fixed-date

(- date chinese-day-name-epoch)))

;; TYPE fixed-date -> chinese-name ;; Chinese sexagesimal name for date. (chinese-sexagesimal-name

(defun chinese-name-of-day (date)

;; RD date of a start of Chinese sexagesimal day cycle. (rd 45))

(defconstant chinese-day-name-epoch ;; TYPE integer

(- elapsed-months chinese-month-name-epoch))))

(1- month)))) (chinese-sexagesimal-name

(let* ((today (chinese-from-fixed date))) (if (>= date (fixed-from-chinese birthdate)) (+ (* 60 (- (chinese-cycle today)

6

14

13

12

11

10

9

8

7

6

5

4

3

2

1

13

12

11

10

9

8

7

5

4

1

(c (if (= year 60); next year’s cycle (1+ cycle) cycle)) (y (if (= year 60); next year’s number

;; it occurs twice (double-bright or double-happiness). (let* ((new-year (fixed-from-chinese (chinese-date cycle year 1 false 1)))

;; 0 means lichun does not occur (widow or double-blind ;; years), 1 means it occurs once at the end (blind), 2 ;; means it occurs once at the start (bright), and 3 means

(defun chinese-year-marriage-augury (cycle year) ;; TYPE (chinese-cycle chinese-year) -> {0,1,2,3} ;; The marriage augury type of Chinese year in cycle.

1) bogus)))

(chinese-cycle birthdate))) (- (chinese-year today) (chinese-year birthdate))

;; Age at fixed date, given Chinese birthdate, ;; according to the Chinese custom. Returns bogus if ;; date is before birthdate.

3

2

(defun chinese-age (birthdate date) ;; TYPE (chinese-date fixed-date) -> nonnegative-integer

(minor-solar-term-on-or-after (fixed-from-gregorian (gregorian-date g-year march 30)))))

;; Fixed date of Qingming occurring in Gregorian year ;; g-year. (floor

(defun qing-ming (g-year) ;; TYPE gregorian-year -> fixed-date

1

8

7

6

5

4

3

2

1

422 Appendix B. Lisp Implementation

(/= next-first-minor-term 12)); ...only at end 1) ; blind ((and

29

4

3

2

1

10

9

8

7

6

5

4

3

2

1

35

34

33

32

31

30

28

27

lichun at start and end

;; Seoul city hall at a varying time zone.

(defun korean-location (tee) ;; TYPE moment -> location ;; Location for Korean calendar; varies with tee.

(mt 24) (hr (+ 9 143/450))) ; Longitude 135 time zone (location (deg 35) (deg 135) (mt 0) (hr 9)))))

(if (< year 1888) ; Tokyo (139 deg 46 min east) local time (location (deg 35.7L0) (angle 139 46 0)

;; TYPE moment -> location ;; Location for Japanese calendar; varies with tee. (let* ((year (gregorian-year-from-fixed (floor tee))))

(defun japanese-location (tee)

(t 3)))); double-bright

(/= first-minor-term 1) ; lichun at start... (= next-first-minor-term 12)) ; ... not at end 2) ; bright

; no lichun at start...

0) ; double blind ((and (= first-minor-term 1)

26

25

24

((and (= first-minor-term 1) ; no lichun at start... (= next-first-minor-term 12)) ; ...or at end

(next-first-minor-term (current-minor-solar-term next-new-year))) (cond

(chinese-date c y 1 false 1))) (first-minor-term (current-minor-solar-term new-year))

(1+ year))) (next-new-year (fixed-from-chinese

23

22

21

20

19

18

17

16

15

9)

7))) (location (angle 21 2 0) (angle 105 51 0) (mt 12) (hr z)))) 8

10

9

7

6

(let* ((z (if (< tee (gregorian-new-year 1968)) 8

;; TYPE moment -> location ;; Location for Vietnamese calendar is Hanoi; varies with ;; tee. Time zone has changed over the years.

(defun vietnamese-location (tee)

;; Equivalent Korean year to Chinese cycle and year (+ (* 60 cycle) year -364))

(defun korean-year (cycle year) ;; TYPE (chinese-cycle chinese-year) -> integer

(mt 0) (hr z))))

8.5) (t 9)))) (location (angle 37 34 0) (angle 126 58 0)

((< tee (fixed-from-gregorian (gregorian-date 1961 august 10)))

(fixed-from-gregorian (gregorian-date 1954 march 21)))

(gregorian-date 1912 january 1))) 8.5) ((< tee

3809/450) ((< tee (fixed-from-gregorian

(fixed-from-gregorian (gregorian-date 1908 april 1))) ;; local mean time for longitude 126 deg 58 min

(let* ((z (cond ((< tee

5

4

3

2

1

4

3

2

1

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

Appendix B. Lisp Implementation 423

11

10

9

8

7

6

5

4

3

2

(- (hindu-sine-table pos) below)))))))

(hindu-sine-table (1- pos)))) (* (angle 0 225 0) (+ pos -1 ; Interpolate. (/ (- amp below)

(if (< amp 0) (- (hindu-arcsin (- amp))) (let* ((pos (next k 0 ( rational-angle ;; Inverse of Hindu sine function of amp.

1

10

9

(hindu-sine-table (ceiling entry))) (* (- 1 fraction) (hindu-sine-table (floor entry))))))

(/ theta (angle 0 225 0))); Interpolate in table. (fraction (mod entry 1))) (+ (* fraction

;; TYPE angle -> rational-amplitude ;; Linear interpolation for theta in Hindu table. (let* ((entry

8

7

6

5

4

3

2

1

9

8

(defun hindu-sine (theta)

(error (* 0.215 (signum exact) (signum (- (abs exact) 1716))))) (/ (round (+ exact error)) 3438)))

7

6

5

;; entry is an angle given as a multiplier of 225’. (let* ((exact (* 3438 (sin-degrees (* entry (angle 0 225 0)))))

(defun hindu-sine-table (entry) ;; TYPE integer -> rational-amplitude ;; This simulates the Hindu sine table.

4

3

2

1

Common Lisp supplies arithmetic with arbitrary rational numbers, and we take advantage of it for implementing the Hindu calendars. With other languages, 64-bit arithmetic is required for many of the calculations.

B.20 The Modern Hindu Calendars

;; radii of epicycle and deferent. anomalistic is the ;; period of retrograde revolution about epicycle. ;; change is maximum decrease in epicycle size. (let* ((lambda ; Position of epicycle center (hindu-mean-position tee period)) (offset ; Sine of anomaly

6

9

4

3

2

1

16

15

14

13

12

11

10

8

7

5

;; TYPE rational ;; Mean length of Hindu sidereal month. (+ 27 4644439/14438334))

(defconstant hindu-sidereal-month

(hindu-arcsin (* offset (- size contraction))))) (mod (- lambda equation) 360)))

(hindu-sine (hindu-mean-position tee anomalistic))) (contraction (* (abs offset) change size)) (equation ; Equation of center

;; TYPE rational) -> rational-angle ;; Longitudinal position at moment tee. period is ;; period of mean motion in days. size is ratio of

4

3

2

1

(defun hindu-true-position (tee period size anomalistic change) ;; TYPE (rational-moment rational rational rational

(* (deg 360) (mod (/ (- tee hindu-creation) period) 1)))

5

4

3

;; TYPE (rational-moment rational) -> rational-angle ;; Position in degrees at moment tee in uniform circular ;; orbit of period days.

(defun hindu-mean-position (tee period)

;; TYPE fixed-date ;; Fixed date of Hindu creation. (- hindu-epoch (* 1955880000 hindu-sidereal-year)))

(defconstant hindu-creation

;; Mean length of Hindu sidereal year. (+ 365 279457/1080000))

(defconstant hindu-sidereal-year ;; TYPE rational

2

1

4

3

2

1

4

3

2

1

424 Appendix B. Lisp Implementation

5

4

3

2

1

5

4

3

2

1

5

4

3

2

1

5

4

3

2

1

4

3

2

1

4

3

2

1

4

3

2

1

(mod (- (hindu-lunar-longitude tee)

(defun hindu-lunar-phase (tee) ;; TYPE rational-moment -> rational-angle ;; Longitudinal distance between the sun and moon ;; at moment tee.

(hindu-true-position tee hindu-sidereal-month 32/360 hindu-anomalistic-month 1/96))

(defun hindu-lunar-longitude (tee) ;; TYPE rational-moment -> rational-angle ;; Lunar longitude at moment tee.

;; Zodiacal sign of the sun, as integer in range 1..12, ;; at moment tee. (1+ (quotient (hindu-solar-longitude tee) (deg 30))))

(defun hindu-zodiac (tee) ;; TYPE rational-moment -> hindu-solar-month

14/360 hindu-anomalistic-year 1/42))

;; TYPE rational-moment -> rational-angle ;; Solar longitude at moment tee. (hindu-true-position tee hindu-sidereal-year

(defun hindu-solar-longitude (tee)

(/ 1577917828 (- 57753336 488199)))

(defconstant hindu-anomalistic-month ;; TYPE rational ;; Time from apogee to apogee, with bija correction.

;; TYPE rational ;; Time from aphelion to aphelion. (/ 1577917828000 (- 4320000000 387)))

(defconstant hindu-anomalistic-year

;; Mean time from new moon to new moon. (+ 29 7087771/13358334))

(defconstant hindu-synodic-month ;; TYPE rational

5

4

3

2

1

4

3

2

1

4

3

2

1

14

13

12

11

10

9

8

7

6

(hindu-sunrise (1+ date)))

(defun hindu-solar-from-fixed (date) ;; TYPE fixed-date -> hindu-solar-date ;; Hindu (Orissa) solar date equivalent to fixed date. (let* ((critical ; Sunrise on Hindu date.

;; TYPE standard-year ;; Years from Kali Yuga until Saka era. 3179)

(defconstant hindu-solar-era

;; TYPE -> hindu-solar-date (list year month day))

(defun hindu-solar-date (year month day) ;; TYPE (hindu-solar-year hindu-solar-month hindu-solar-day)

(< (- u l) varepsilon)))))

u (min tee (1+ tau)) x (< (hindu-lunar-phase x) (deg 180)) (or (= (hindu-zodiac l) (hindu-zodiac u))

hindu-synodic-month)))) (binary-search ; Search for phase start. l (1- tau)

(let* ((varepsilon (expt 2 -1000)) ; Safety margin. (tau ; Can be off by almost a day. (- tee (* (/ 1 (deg 360)) (hindu-lunar-phase tee)

5

4

3

;; TYPE rational-moment -> rational-moment ;; Approximate moment of last new moon preceding moment ;; tee, close enough to determine zodiacal sign.

(defun hindu-new-moon-before (tee)

;; the range 1..30. (1+ (quotient (hindu-lunar-phase tee) (deg 12))))

(defun hindu-lunar-day-from-moment (tee) ;; TYPE rational-moment -> hindu-lunar-day ;; Phase of moon (tithi) at moment tee, as an integer in

(hindu-solar-longitude tee)) 360))

2

1

5

4

3

2

1

7

6

Appendix B. Lisp Implementation 425

hindu-solar-era)) (approx ; 3 days before start of mean month. (- date 3

(mod (floor (hindu-solar-longitude critical)) (deg 30)))) (begin ; Search forward for beginning...

(next i approx ; ... of month. (= (hindu-zodiac (hindu-sunrise (1+ i))) month)))

8

11

14

(let* ((month (standard-month s-date)) (day (standard-day s-date)) (year (standard-year s-date))

5

(list year month leap-month day leap-day))

4 5

(+ day -1

3

2

15

14

13

12

(/ (1- month) 12)) ; in months... hindu-sidereal-year)) ; ... and years hindu-epoch))) ; and days before RD 0. ;; Search forward to correct month

1

4

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

(let* ((critical (hindu-sunrise date)) ; Sunrise that day.

(defun hindu-lunar-from-fixed (date) ;; TYPE fixed-date -> hindu-lunar-date ;; Hindu lunar date, new-moon scheme, ;; equivalent to fixed date.

;; Years from Kali Yuga until Vikrama era. 3044)

(defconstant hindu-lunar-era ;; TYPE standard-year

(defun hindu-lunar-year (date) ;; TYPE hindu-lunar-date -> hindu-lunar-year (first date))

;; TYPE hindu-lunar-date -> hindu-lunar-leap-day (fifth date))

(defun hindu-lunar-leap-day (date)

(fourth date))

(defun hindu-lunar-day (date) ;; TYPE hindu-lunar-date -> hindu-lunar-day

(defun hindu-lunar-leap-month (date) ;; TYPE hindu-lunar-date -> hindu-lunar-leap-month (third date))

;; TYPE hindu-lunar-date -> hindu-lunar-month (second date))

(defun hindu-lunar-month (date)

5

4

3

;; TYPE (hindu-lunar-year hindu-lunar-month ;; TYPE hindu-lunar-leap-month hindu-lunar-day ;; TYPE hindu-lunar-leap-day) -> hindu-lunar-date

(defun hindu-lunar-date (year month leap-month day leap-day)

month)))))

(next d (- begin 3) (= (hindu-zodiac (hindu-sunrise (1+ d)))

2

1

18

17

16

11

10

9

8

7

6

4

(begin ; Approximate start of month ; by adding days... (+ (floor (* (+ year hindu-solar-era

;; TYPE hindu-solar-date -> fixed-date ;; Fixed date corresponding to Hindu solar date s-date ;; (Saka era; Orissa rule.)

3

2

1

(defun fixed-from-hindu-solar (s-date)

(deg 360)))))

7

6

5

(round (- (/ (- tee hindu-epoch) hindu-sidereal-year) (/ (hindu-solar-longitude tee)

(defun hindu-calendar-year (tee) ;; TYPE rational-moment -> hindu-solar-year ;; Determine solar year at given moment tee.

4

3

2

1

18

17

16

15

13

12

10

9

(day (- date begin -1))) (hindu-solar-date year month day)))

(month (hindu-zodiac critical)) (year (- (hindu-calendar-year critical)

7

6

426 Appendix B. Lisp Implementation

(leap-day ; If previous day the same. (= day (hindu-lunar-day-from-moment (hindu-sunrise (- date 1)))))

(last-new-moon (hindu-new-moon-before critical)) (next-new-moon

(hindu-new-moon-before (+ (floor last-new-moon) 35))) (solar-month ; Solar month name.

(hindu-zodiac last-new-moon)) (leap-month ; If begins and ends in same sign. (= solar-month (hindu-zodiac next-new-moon)))

(month ; Month of lunar year. (amod (1+ solar-month) 12)) (year ; Solar year at end of month.

(- (hindu-calendar-year (if ( fixed-date ;; Fixed date corresponding to Hindu lunar date l-date. (let* ((year (hindu-lunar-year l-date))

(defun fixed-from-hindu-lunar (l-date)

(hindu-lunar-date year month leap-month day leap-day)))

5

4

3

2

1

29

28

27

26

25

24

22

21

19

18

16

15

13

12

10

9

(+ date 180) date)) hindu-lunar-era)))

(day (hindu-lunar-day-from-moment critical)); Day of month.

7

6

48

47

46

45

44

43

42

41

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

20

19

18

17

16

15

14

13

(/ (1- month) 12)))))

(hindu-sunrise d)) (list day (amod (1+ day) 30)))))) (if leap-day (1+ date) date)))

-15)) (date (next d (1- tau) (member (hindu-lunar-day-from-moment

(- est (mod (- (hindu-lunar-day-from-moment (+ est (hr 6))) day -15) 30)

(t ; In preceding month. (+ (mod (- k 15) 30) 15))))) (tau ; Refined estimate.

(and (hindu-lunar-leap-month mid) (not leap-month)))) (- (mod (+ k 15) 30) 15))

(- s 15)))) (or ; In month starting near s. (/= (hindu-lunar-month mid) month)

k) ((let* ((mid ; Middle of preceding solar month. (hindu-lunar-from-fixed

(- s (- day) (cond ((< 3 k 27) ; Not borderline case.

(deg 180)))))) (k (hindu-lunar-day-from-moment (+ s (hr 6)))) (est

(* (1- month) (deg 30)) (- (deg 180))) 360)

(- approx (* (/ 1 (deg 360)) hindu-sidereal-year (- (mod (- (hindu-solar-longitude approx)

(s (floor

Appendix B. Lisp Implementation 427

16

15

14

13

12

11

10

9

8

7

360)))

(mod (+ (deg 27) (* (deg 108) 600/1577917828 days)) 108)))))) (mod (- (hindu-solar-longitude date) precession)

(- (deg 27) (abs (- (deg 54)

;; (= 1577917828/600 days). (let* ((days (floor (- date hindu-epoch))) ; Whole days. (precession

6

5

4

;; Hindu tropical longitude on fixed date. ;; Assumes precession with maximum of 27 degrees ;; and period of 7200 sidereal years

(defun hindu-tropical-longitude (date) ;; TYPE fixed-date -> rational-angle

;; TYPE fixed-date -> rational-angle ;; Difference between solar and sidereal day on date. (* (hindu-daily-motion date) (hindu-rising-sign date)))

(defun hindu-solar-sidereal-difference (date)

(hindu-arcsin (- (/ earth-sine diurnal-radius)))))

3

2

1

4

3

2

1

15

14

13

12

11

10

(/ (hindu-sine phi) (hindu-sine (+ (deg 90) phi)))) (earth-sine (* sin_delta tan_phi)))

(diurnal-radius (hindu-sine (+ (deg 90) (hindu-arcsin sin_delta)))) (tan_phi ; Tangent of latitude as rational number.

9

8

7

(* 1397/3438 ; Sine of inclination. (hindu-sine (hindu-tropical-longitude date)))) (phi (latitude locale))

;; Difference between right and oblique ascension ;; of sun on date at locale. (let* ((sin_delta

(defun hindu-ascensional-difference (date locale) ;; TYPE (fixed-date location) -> rational-angle

6

5

4

3

2

1

9

8

7

6

5

4

3

2

1

16

15

14

13

12

11

9

(equation-sun ; Sun’s equation of center

(let* ((offset (hindu-sine (hindu-mean-position date hindu-anomalistic-year)))

;; TYPE fixed-date -> rational-moment ;; Time from true to mean midnight of date. ;; (This is a gross approximation to the correct value.)

(defun hindu-equation-of-time (date)

(* mean-motion (1+ factor))))

(hindu-sine-table entry))) (factor (* -3438/225 sine-table-step epicycle)))

(entry (quotient anomaly (angle 0 225 0))) (sine-table-step ; Marginal change in anomaly (- (hindu-sine-table (1+ entry))

10

8

(hindu-mean-position date hindu-anomalistic-year)) (epicycle ; Current size of epicycle. (- 14/360 (/ (abs (hindu-sine anomaly)) 1080)))

(let* ((mean-motion ; Mean daily motion in degrees. (/ (deg 360) hindu-sidereal-year)) (anomaly

(defun hindu-daily-motion (date) ;; TYPE fixed-date -> rational-angle ;; Sidereal daily motion of sun on date.

(list 1670/1800 1795/1800 1935/1800 1935/1800 1795/1800 1670/1800))))

(quotient (hindu-tropical-longitude date) (deg 30)))) (nth (mod i 6)

;; Tabulated speed of rising of current zodiacal sign on ;; date. (let* ((i ; Index.

(defun hindu-rising-sign (date) ;; TYPE fixed-date -> rational-amplitude

7

6

5

4

3

2

1

10

9

8

7

6

5

4

3

2

1

428 Appendix B. Lisp Implementation

7

6

5

4

3

2

1

11

(month (hindu-lunar-month l-date))

;; Hindu lunar date, full-moon scheme, ;; equivalent to fixed date. (let* ((l-date (hindu-lunar-from-fixed date)) (year (hindu-lunar-year l-date))

(defun hindu-fullmoon-from-fixed (date) ;; TYPE fixed-date -> hindu-lunar-date

(/ 1577917828/1582237828 (deg 360)) (+ (hindu-ascensional-difference date hindu-locale) (* 1/4 (hindu-solar-sidereal-difference date))))))

9

10

8

7

(deg 360)) ; Difference from longitude. (- (hindu-equation-of-time date)) ; Apparent midnight. (* ; Convert sidereal angle to fraction of civil day.

;; Sunrise at hindu-locale on date. (+ date (hr 6) ; Mean sunrise. (/ (- (longitude ujjain) (longitude hindu-locale))

(defun hindu-sunrise (date) ;; TYPE fixed-date -> rational-moment

;; TYPE location ;; Location (Ujjain) for determining Hindu calendar. ujjain)

(defconstant hindu-locale

(mt 0) (hr (+ 5 461/9000))))

;; TYPE location ;; Location of Ujjain. (location (angle 23 9 0) (angle 75 46 6)

(defconstant ujjain

hindu-sidereal-year)))

(- 14/360 (/ (abs offset) 1080))))) (* (/ (hindu-daily-motion date) (deg 360)) (/ equation-sun (deg 360))

; Arcsin is not needed since small (* offset (angle 57 18 0)

6

5

4

3

2

1

4

3

2

1

5

4

3

2

1

15

14

13

12

11

10

11

10

9

8

7

6

5

(list l-year l-month false 15 false))))))

(hindu-lunar-month (hindu-lunar-from-fixed (fixed-from-hindu-lunar

;; True of Hindu lunar month l-month in l-year ;; is expunged. (/= l-month 4

3

2

(defun hindu-expunged? (l-month l-year) ;; TYPE (hindu-lunar-month hindu-lunar-year) -> ;; TYPE boolean

(fixed-from-hindu-lunar (hindu-lunar-date year m leap-month day leap-day))))

1

16

15

14

13

12

((hindu-expunged? (amod (1- month) 12) year) (amod (- month 2) 12)) (t (amod (1- month) 12)))))

(leap-day (hindu-lunar-leap-day l-date)) (m (cond ((or leap-month ( fixed-date

(hindu-lunar-from-fixed (+ date 20))) month))) (hindu-lunar-date year m leap-month day leap-day)))

(leap-day (hindu-lunar-leap-day l-date)) (m (if (>= day 16) (hindu-lunar-month

(leap-month (hindu-lunar-leap-month l-date)) (day (hindu-lunar-day l-date))

6

5

4

3

2

1

15

14

13

12

11

10

9

8

Appendix B. Lisp Implementation 429

17

16

15

14

13

12

11

9

(cond ((= q 3) (hr 18))

(b (cond ((= q 0) (hindu-sunrise date)) ((= q 3) (hindu-sunrise (1+ date))) (t (hindu-sunset date))))) (+ a (* 2 (- b a) (- time

(hindu-sunset date)) (t ; daytime today (hindu-sunrise date))))

10

8

(a (cond ((= q 0) ; early this morning (hindu-sunset (1- date))) ((= q 3) ; this evening

(let* ((date (fixed-from-moment tee)) (time (mod tee 1)) (q (floor (* 4 time))) ; quarter of day

(defun hindu-sundial-time (tee) ;; TYPE rational-moment -> rational-moment ;; Hindu local time of temporal moment tee.

(+ (- (hindu-ascensional-difference date hindu-locale)) (* 3/4 (hindu-solar-sidereal-difference date))))))

(- (hindu-equation-of-time date)) ; Apparent midnight. (* ; Convert sidereal angle to fraction of civil day. (/ 1577917828/1582237828 (deg 360))

(+ date (hr 18) ; Mean sunset. (/ (- (longitude ujjain) (longitude hindu-locale)) (deg 360)) ; Difference from longitude.

7

6

5

4

3

2

1

11

10

9

8

7

6

5

4

3

2

1

7

(defun hindu-sunset (date) ;; TYPE fixed-date -> rational-moment ;; Sunset at hindu-locale on date.

(let* ((rise (dawn date hindu-locale (angle 0 47 0)))) (* 1/24 1/60 (round (* rise 24 60)))))

6

5

4

;; Astronomical sunrise at Hindu locale on date, ;; per Lahiri, ;; rounded to nearest minute, as a rational number.

(defun alt-hindu-sunrise (date) ;; TYPE fixed-date -> rational-moment

3

2

1

18

6

5

4

3

2

1

7

6

5

4

3

2

1

5

4

3

2

1

5

4

3

2

1

4

3

2

1

5

4

3

2

1

19

(astro-hindu-sunset date))

;; TYPE fixed-date -> hindu-solar-date ;; Astronomical Hindu (Tamil) solar date equivalent to ;; fixed date. (let* ((critical ; Sunrise on Hindu date.

(defun astro-hindu-solar-from-fixed (date)

(/ (sidereal-solar-longitude tee) (deg 360)))))

;; Astronomical Hindu solar year KY at given moment tee. (round (- (/ (- tee hindu-epoch) mean-sidereal-year)

(defun astro-hindu-calendar-year (tee) ;; TYPE moment -> hindu-solar-year

(1+ (quotient (sidereal-solar-longitude tee) (deg 30))))

;; TYPE moment -> solar-month ;; Sidereal zodiacal sign of the sun, as integer in range ;; 1..12, at moment tee.

(defun sidereal-zodiac (tee)

(- (solar-longitude tee) (sidereal-solar-longitude tee)))

(defun ayanamsha (tee) ;; TYPE moment -> angle ;; Difference between tropical and sidereal solar longitude.

;; TYPE fixed-date -> moment ;; Geometrical sunset at Hindu locale on date. (dusk date hindu-locale (deg 0)))

(defun astro-hindu-sunset (date)

(mesha-samkranti (ce 285)) hindu-locale)))

(defconstant sidereal-start ;; TYPE angle (precession (universal-from-local

((= q 0) (hr -6)) (t (hr 6))))))))

430 Appendix B. Lisp Implementation

hindu-solar-era)) (approx ; 3 days before start of mean month. (- date 3

9

5

4

3

2

1

17

16

15

14

13

12

11

10

9

8

7

6

5

(1+ (quotient (lunar-phase tee) (deg 12))))

(defun astro-lunar-day-from-moment (tee) ;; TYPE moment -> hindu-lunar-day ;; Phase of moon (tithi) at moment tee, as an integer in ;; the range 1..30.

month)))) (+ begin day -1)))

(begin ; Search forward for beginning... (next i approx ; ... of month. (= (sidereal-zodiac (astro-hindu-sunset i))

(floor (* (+ (+ year hindu-solar-era) (/ (1- month) 12)) mean-sidereal-year))))

(year (standard-year s-date)) (approx ; 3 days before start of mean month. (+ hindu-epoch -3

;; Hindu solar date (Tamil rule; Saka era). (let* ((month (standard-month s-date)) (day (standard-day s-date))

4

3

2

(defun fixed-from-astro-hindu-solar (s-date) ;; TYPE hindu-solar-date -> fixed-date ;; Fixed date corresponding to Astronomical

(day (- date begin -1))) (hindu-solar-date year month day)))

(next i approx ; ... of month. (= (sidereal-zodiac (astro-hindu-sunset i)) month)))

1

19

18

17

16

15

14

13

12

11

10

(mod (floor (sidereal-solar-longitude critical)) (deg 30)))) (begin ; Search forward for beginning...

(month (sidereal-zodiac critical)) (year (- (astro-hindu-calendar-year critical)

8

7

8

7

6

5

4

3

2

1

28

27

26

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

; new year.

(leap-day (hindu-lunar-leap-day l-date))

(let* ((year (hindu-lunar-year l-date)) (month (hindu-lunar-month l-date)) (leap-month (hindu-lunar-leap-month l-date)) (day (hindu-lunar-day l-date))

(defun fixed-from-astro-hindu-lunar (l-date) ;; TYPE hindu-lunar-date -> fixed-date ;; Fixed date corresponding to Hindu lunar date l-date.

hindu-lunar-era))) (hindu-lunar-date year month leap-month day leap-day)))

(+ date 180) date))

(year ; Solar year at end of month. (- (astro-hindu-calendar-year (if ( hindu-lunar-date

Appendix B. Lisp Implementation 431

9

44

43

42

41

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

-15)) (date (next d (1- tau)

30)

(- est (mod (- (astro-lunar-day-from-moment (+ est (hr 6))) day -15)

(- (mod (+ k 15) 30) 15)) (t ; In preceding month. (+ (mod (- k 15) 30) 15))))) (tau ; Refined estimate.

(/= (hindu-lunar-month mid) month) (and (hindu-lunar-leap-month mid) (not leap-month))))

(astro-hindu-lunar-from-fixed (- s 15)))) (or ; In month starting near s.

((< 3 k 27) ; Not borderline case. k) ((let* ((mid ; Middle of preceding solar month.

(est (- s (- day) (cond

23

22

21

360) (deg 180)))))) (k (astro-lunar-day-from-moment (+ s (hr 6))))

(- (mod (- (sidereal-solar-longitude approx) (* (1- month) (deg 30)) (- (deg 180)))

(s (floor (- approx (* (/ 1 (deg 360)) mean-sidereal-year

(* mean-sidereal-year (+ year hindu-lunar-era (/ (1- month) 12)))))

(approx (+ hindu-epoch

20

19

18

17

16

15

14

13

12

11

10

10

9

8

7

6

5

4

3

2

1

6

5

4

3

2

1

14

13

12

11

10

9

8

7

6

(a (max tee (- tau 5))) ; At or after tee.

(+ tee (* hindu-sidereal-year (/ 1 (deg 360)) (mod (- lambda (hindu-solar-longitude tee)) 360))))

;; Moment of the first time at or after tee ;; when Hindu solar longitude will be lambda degrees. (let* ((tau ; Estimate (within 5 days).

(defun hindu-solar-longitude-at-or-after (lambda tee) ;; TYPE (season moment) -> moment

(angle 0 800 0)))))

;; Hindu lunar station (nakshatra) at sunrise on date. (let* ((critical (hindu-sunrise date))) (1+ (quotient (hindu-lunar-longitude critical)

(defun hindu-lunar-station (date) ;; TYPE fixed-date -> nakshatra

(invert-angular hindu-lunar-phase phase a b)))

hindu-synodic-month))) (a (max tee (- tau 2))) (b (+ tau 2)))

(+ tee (* (/ 1 (deg 360)) (mod (- phase (hindu-lunar-phase tee)) 360)

(let* ((phase ; Degrees corresponding to k. (* (1- k) (deg 12))) (tau ; Mean occurrence of lunar-day.

5

4

3

;; TYPE (rational rational-moment) -> rational-moment ;; Time lunar-day (tithi) number k begins at or after ;; moment tee. k can be fractional (for karanas).

(defun hindu-lunar-day-at-or-after (k tee)

(list day (amod (1+ day) 30)))))) (if leap-day (1+ date) date)))

(member (astro-lunar-day-from-moment (alt-hindu-sunrise d))

2

1

48

47

46

45

432 Appendix B. Lisp Implementation

11

(defun hindu-lunar-new-year (g-year) ;; TYPE gregorian-year -> fixed-date ;; Fixed date of Hindu lunisolar new year in Gregorian

;; g-year. (let* ((jan1 (gregorian-new-year g-year)) (mina ; Fixed moment of solar longitude 330.

1

4

(h-day (floor new-moon)) (critical ; Sunrise that day. (hindu-sunrise h-day)))

10

7

6

5

4

(leap1 (hindu-lunar-leap-month l-date1))

;; True if Hindu lunar date l-date1 is on or before ;; Hindu lunar date l-date2. (let* ((month1 (hindu-lunar-month l-date1)) (month2 (hindu-lunar-month l-date2))

3

2

(defun hindu-lunar-on-or-before? (l-date1 l-date2) ;; TYPE (hindu-lunar-date hindu-lunar-date) -> boolean

0 1))))

(if (or (< new-moon critical) (= (hindu-lunar-day-from-moment (hindu-sunrise (1+ h-day))) 2))

1

19

18

17

16

15

14

13

12

11

9

(+ h-day ;; Next day if new moon after sunrise, ;; unless lunar day ends before next sunrise.

(hindu-solar-longitude-at-or-after (deg 330) jan1)) (new-moon ; Next new moon. (hindu-lunar-day-at-or-after 1 mina))

8

7

6

5

3

2

6

5

;; in Gregorian g-year. (let* ((jan1 (gregorian-new-year g-year))) (hindu-solar-longitude-at-or-after (deg 0) jan1)))

(defun mesha-samkranti (g-year) ;; TYPE gregorian-year -> rational-moment ;; Fixed moment of Mesha samkranti (Vernal equinox)

(b (+ tau 5))) (invert-angular hindu-solar-longitude lambda a b)))

4

3

2

1

12

(day2 (hindu-lunar-day l-date2)) (leap-day1 (hindu-lunar-leap-day l-date1)) (leap-day2 (hindu-lunar-leap-day l-date2))

10

(let* ((lunar (hindu-lunar-date l-year l-month false l-day false)) (try (fixed-from-hindu-lunar lunar)) 8

18

17

16

15

14

13

12

11

10

9

7

6

l-day false)))

(l-date ; day in next month (hindu-lunar-date (hindu-lunar-year mid) (hindu-lunar-month mid) (hindu-lunar-leap-month mid)

(mid (hindu-lunar-from-fixed (if (> l-day 15) (- try 5) try))) (expunged? (/= l-month (hindu-lunar-month mid)))

;; l-day in Hindu lunar year l-year, taking leap and ;; expunged days into account. When the month is ;; expunged, then the following month is used.

5

4

3

;; TYPE (hindu-lunar-month hindu-lunar-day ;; TYPE hindu-lunar-year) -> fixed-date ;; Fixed date of occurrence of Hindu lunar l-month,

(defun hindu-date-occur (l-month l-day l-year)

))))))

(and (= day1 day2) (or (not leap-day1) leap-day2)))))

(or (and leap1 (not leap2)) (and (equal leap1 leap2) (or (< day1 day2)

(and (= year1 year2) (or (< month1 month2) (and (= month1 month2)

2

1

25

24

23

22

21

20

19

18

17

16

15

14

13

12

11

(year1 (hindu-lunar-year l-date1)) (year2 (hindu-lunar-year l-date2))) (or (< year1 year2)

(leap2 (hindu-lunar-leap-month l-date2)) (day1 (hindu-lunar-day l-date1))

9

8

Appendix B. Lisp Implementation 433

19

9

17

8

7

6

5

4

3

2

1

5

4

3

2

1

12

11

10

9

8

7

(hindu-date-occur l-month (floor tithi) l-year))

;; Fixed date of occurrence of Hindu lunar tithi prior ;; to sundial time tee, in Hindu lunar l-month, ;; l-year. (let* ((approx

(defun hindu-tithi-occur (l-month tithi tee l-year) ;; TYPE (hindu-lunar-month rational rational ;; TYPE hindu-lunar-year) -> fixed-date

;; List of fixed date(s) of Diwali in Gregorian year ;; g-year. (hindu-lunar-holiday 8 1 g-year))

(defun diwali (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates

(gregorian-year-range g-year))))

(date1 (hindu-date-occur l-month l-day l-year)) (date2 (hindu-date-occur l-month l-day (1+ l-year)))) (list-range (list date1 date2)

(let* ((l-year (hindu-lunar-year (hindu-lunar-from-fixed (gregorian-new-year g-year))))

6

5

4

;; TYPE gregorian-year) -> list-of-fixed-dates ;; List of fixed dates of occurrences of Hindu lunar ;; month, day in Gregorian year g-year.

3

2

1

(defun hindu-lunar-holiday (l-month l-day g-year) ;; TYPE (hindu-lunar-month hindu-lunar-day

16

(t try))))

5

4

3

2

1

;; year g-year. (hindu-lunar-event 1 9 (hr 12) g-year))

(defun rama (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates ;; List of fixed date(s) of Rama’s Birthday in Gregorian

(hindu-lunar-event 11 29 (hr 24) g-year)) 5

4

3

;; TYPE gregorian-year -> list-of-fixed-dates ;; List of fixed date(s) of Night of Shiva in Gregorian ;; year g-year.

(defun shiva (g-year)

l-month tithi tee (1+ l-year)))) (list-range (list date1 date2) (gregorian-year-range g-year))))

2

1

14

13

12

11

10

9

8

7

(gregorian-new-year g-year)))) (date1 (hindu-tithi-occur l-month tithi tee l-year)) (date2 (hindu-tithi-occur

;; in Gregorian year g-year. (let* ((l-year (hindu-lunar-year (hindu-lunar-from-fixed

6

5

4

;; TYPE gregorian-year) -> list-of-fixed-dates ;; List of fixed dates of occurrences of Hindu lunar tithi ;; prior to sundial time tee, in Hindu lunar l-month,

(defun hindu-lunar-event (l-month tithi tee g-year) ;; TYPE (hindu-lunar-month rational rational

try (1+ try))))

(> (hindu-lunar-phase (standard-from-sundial (+ try 1 tee) ujjain)) (* 12 tithi)))

(try (fixed-from-moment lunar)) (tee_h (standard-from-sundial (+ try tee) ujjain))) (if (or ( list-of-fixed-dates ;; List of Wednesdays within range of dates

;; that are day 8 of Hindu lunar months. (let* ((a (start range)) (b (end range))

1

4

(append (if (= (hindu-lunar-day h-date) 8) (list wed) nil)

10

14

13

12

11

9

(sacred-wednesdays-in-range

(wed (kday-on-or-after wednesday a)) (h-date (hindu-lunar-from-fixed wed))) (if (in-range? wed range)

8

7

6

5

3

2

6

5

;; that are day 8 of Hindu lunar months. (sacred-wednesdays-in-range (gregorian-year-range g-year)))

(defun sacred-wednesdays (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates ;; List of Wednesdays in Gregorian year g-year

(hindu-lunar-longitude date)) (angle 0 800 0)) 27))))

;; TYPE fixed-date -> {1-27} ;; Hindu yoga on date. (1+ (floor (mod (/ (+ (hindu-solar-longitude date)

(defun yoga (date)

((> n 57) (- n 50)) (t (amod (1- n) 7))))

;; Number (0-10) of the name of the n-th (1-60) Hindu ;; karana. (cond ((= n 1) 0)

(defun karana (n) ;; TYPE {1-60} -> {0-10}

4

3

2

1

7

6

5

4

3

2

1

7

6

5

4

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

3

2

1

5

4

3

2

1

16

15

(defconstant tibetan-epoch ;; TYPE fixed-date (fixed-from-gregorian (gregorian-date -127 december 7)))

;; TYPE tibetan-date -> tibetan-leap-day (fifth date))

(defun tibetan-leap-day (date)

(defun tibetan-day (date) ;; TYPE tibetan-date -> tibetan-day (fourth date))

(third date))

(defun tibetan-leap-month (date) ;; TYPE tibetan-date -> tibetan-leap-month

;; TYPE tibetan-date -> tibetan-month (second date))

(defun tibetan-month (date)

(defun tibetan-year (date) ;; TYPE tibetan-date -> tibetan-year (first date))

;; TYPE tibetan-leap-day) -> tibetan-date (list year month leap-month day leap-day))

(defun tibetan-date (year month leap-month day leap-day) ;; TYPE (tibetan-year tibetan-month ;; TYPE tibetan-leap-month tibetan-day

B.21 The Tibetan Calendar

(interval (1+ wed) b))) nil)))

Appendix B. Lisp Implementation 435

25/60))) (t (+ (* (mod alpha 1) (tibetan-moon-equation (ceiling alpha)))

9

11

10

9

8

7

6

5

4

3

2

1

13

12

11

10

8

7

(if leap-month -1 0) 64/65)))

(day (tibetan-day t-date)) (leap-day (tibetan-leap-day t-date)) (months ; Lunar month count. (floor (+ (* 804/65 (1- year)) (* 67/65 month)

(let* ((year (tibetan-year t-date)) (month (tibetan-month t-date)) (leap-month (tibetan-leap-month t-date))

(defun fixed-from-tibetan (t-date) ;; TYPE tibetan-date -> fixed-date ;; Fixed date corresponding to Tibetan lunar date t-date.

(* (mod (- alpha) 1) (tibetan-moon-equation (floor alpha)))))))

((integerp alpha) (nth alpha (list 0 5/60 10/60 15/60 19/60 22/60 24/60

6

5

4

;; Interpolated tabular sine of lunar anomaly alpha. (cond ((> alpha 14) (- (tibetan-moon-equation (- alpha 14)))) ((> alpha 7) (tibetan-moon-equation (- 14 alpha)))

(defun tibetan-moon-equation (alpha) ;; TYPE rational-angle -> rational

(tibetan-sun-equation (ceiling alpha))) (* (mod (- alpha) 1) (tibetan-sun-equation (floor alpha)))))))

((integerp alpha) (nth alpha (list 0 6/60 10/60 11/60))) (t (+ (* (mod alpha 1)

;; Interpolated tabular sine of solar anomaly alpha. (cond ((> alpha 6) (- (tibetan-sun-equation (- alpha 6)))) ((> alpha 3) (tibetan-sun-equation (- 6 alpha)))

(defun tibetan-sun-equation (alpha) ;; TYPE rational-angle -> rational

3

2

1

11

10

9

8

7

6

5

4

3

2

1

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

23

22

21

20

19

18

17

16

15

14

13

12

(tibetan-date year0 month0 false d false)))))

(final d (- est 2) (>= date (fixed-from-tibetan

(- date (fixed-from-tibetan (tibetan-date year0 month0 false 1 false)))) (day0 ; Search for day.

(fixed-from-tibetan (tibetan-date year0 m false 1 false))))) (est ; Estimated day.

(month0 ; Search for month. (final m 1 (>= date

(>= date (fixed-from-tibetan (tibetan-date y 1 false 1 false)))))

(years (ceiling (/ (- date tibetan-epoch) cap-Y))) (year0 ; Search for year. (final y years

;; TYPE fixed-date -> tibetan-date ;; Tibetan lunar date corresponding to fixed date. (let* ((cap-Y (+ 365 4975/18382)) ; Average Tibetan year.

(defun tibetan-from-fixed (date)

(floor (+ tibetan-epoch mean sun moon))))

(mod (+ (* days 3781/105840) 2837/15120) 1)) (sun (- (tibetan-sun-equation (* 12 solar-anomaly)))) (moon (tibetan-moon-equation (* 28 lunar-anomaly))))

(solar-anomaly (mod (+ (* days 13/4824) 2117/4824) 1)) (lunar-anomaly

(mean ; Mean civil days since epoch. (+ (* days 11135/11312) -30 (if leap-day 0 -1) 1071/1616))

(days ; Lunar day count. (+ (* 30 months) day))

436 Appendix B. Lisp Implementation

(fixed-from-tibetan (tibetan-date t-year 1 t-leap 1 false))))

6

9 10

;; List of fixed dates of Tibetan New Year in

8

3

2

(defun tibetan-new-year (g-year) ;; TYPE gregorian-year -> list-of-fixed-dates

7

6

5

4

3

2

1

14

13

12

11

10

9

8

7

6

5

4

3

2

1

10

9

8

7

6

5

4

1

7

5

4

;; Fixed date of Tibetan New Year (Losar) ;; in Tibetan year t-year. (let* ((t-leap (tibetan-leap-month? 1 t-year)))

(defun losar (t-year) ;; TYPE tibetan-year -> fixed-date

(tibetan-date t-year t-month true 2 false))))))

(tibetan-month (tibetan-from-fixed (fixed-from-tibetan

;; TYPE (tibetan-month tibetan-year) -> boolean ;; True if t-month is leap in Tibetan year t-year. (= t-month

(defun tibetan-leap-month? (t-month t-year)

(tibetan-date year month leap-month day true))))) (tibetan-date year month leap-month day leap-day)))

(leap-day (= date (fixed-from-tibetan

((and leap-month (= month0 12)) (1+ year0)) (t year0)))

12)) (year (cond ((and (> day day0) (= month0 1)) (1- year0))

(month (amod (cond ((> day day0) (1- month0)) (leap-month (1+ month0)) (t month0))

(leap-month (> day0 30)) (day (amod day0 30))

3

2

1

8

7

6

5

4

3

2

1

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

(if (and ( fixed-date

(- mean 30) ; Must go back a month. (- mean 2)))) (next d tau (visible-crescent d locale))))

(tau ; Check if not visible yet on date. (if (and ( fixed-date

B.22 Astronomical Lunar Calendars

(losar t-year)) (gregorian-year-range g-year))))

(t-year (tibetan-year (tibetan-from-fixed dec31)))) (list-range (list (losar (1- t-year))

;; Gregorian year g-year. (let* ((dec31 (gregorian-year-end g-year))

Appendix B. Lisp Implementation 437

11

(not (visible-crescent (1- date) locale)))

(let* ((tee ; Best viewing time prior evening. (universal-from-standard (dusk (1- date) locale (deg 4.5L0))

5

(/ (deg 1792367000/9) (lunar-distance tee)))

6

2

1

5

;; TYPE islamic-date -> fixed-date

(defun fixed-from-observational-islamic (i-date)

;; (Cairo, Egypt). (location (deg 30.1L0) (deg 31.3L0) (mt 200) (hr 2)))

4

3

2

(defconstant islamic-locale ;; TYPE location ;; Sample location for Observational Islamic calendar

1

5

4

;; Geocentric apparent lunar diameter of the moon (in ;; degrees) at moment tee. Adapted from "Astronomical ;; Algorithms" by Jean Meeus, Willmann-Bell, Inc., 2nd ed.

(defun lunar-diameter (tee) ;; TYPE moment -> angle

(> altitude (deg 4.1L0)))))

3

2

1

17

16

15

14

13

12

(cosine-degrees phase))))) (and (< new phase first-quarter) ( boolean ;; S. K. Shaukat’s criterion for likely ;; visibility of crescent moon on eve of date at locale.

(defun visible-crescent (date locale)

(+ mean 29)))) ; next new moon (next d tau (visible-crescent d locale))))

date

2

1

14

13

12

9

8

7

6

(paschal-moon ; Date of next full moon.

(let* ((jan1 ; Beginning of year. (gregorian-new-year g-year)) (equinox ; Spring equinox. (solar-longitude-after spring jan1)) 5

4

3

;; TYPE gregorian-year -> fixed-date ;; Date of (proposed) astronomical Easter in Gregorian ;; year g-year.

(defun astronomical-easter (g-year)

2

1

13

12

11

9

(islamic-date year month day)))

(year (1+ (quotient elapsed-months 12))) (month (1+ (mod elapsed-months 12))) (day (1+ (- date crescent))))

10

8

(elapsed-months (round (/ (- crescent islamic-epoch) mean-synodic-month)))

;; corresponding to fixed date. (let* ((crescent ; Most recent new moon. (phasis-on-or-before date islamic-locale))

(defun observational-islamic-from-fixed (date) ;; TYPE fixed-date -> islamic-date ;; Observational Islamic date (year month day)

midmonth islamic-locale) day -1)))

month -1/2) mean-synodic-month))))) (+ (phasis-on-or-before ; First day of month.

(midmonth ; Middle of given month. (+ islamic-epoch (floor (* (+ (* (1- year) 12)

(let* ((month (standard-month i-date)) (day (standard-day i-date)) (year (standard-year i-date))

;; Fixed date equivalent to Observational Islamic date ;; i-date.

7

6

5

4

3

2

1

15

14

13

12

11

10

9

8

7

6

5

4

3

438 Appendix B. Lisp Implementation

8

7

6

5

4

3

2

(ny (observational-hebrew-new-year g-year))

;; corresponding to fixed date. (let* ((crescent ; Most recent new moon. (phasis-on-or-before date jaffa)) (g-year (gregorian-year-from-fixed date))

(defun observational-hebrew-from-fixed (date) ;; TYPE fixed-date -> hebrew-date ;; Observational Hebrew date (year month day)

1

16

15

(if ; Spring starts before sunset. (< equinox set) 14 13)) jaffa)))

jaffa))) (phasis-on-or-after (- (floor equinox) ; Day of equinox

14

13

12

11

10

9

8

7

6

(set ; Moment (UT) of sunset on day of equinox. (universal-from-standard (sunset (floor equinox) jaffa)

(let* ((jan1 (gregorian-new-year g-year)) (equinox ; Moment (UT) of spring of g-year. (solar-longitude-after spring jan1))

5

4

3

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Observational (classical) ;; Nisan 1 occurring in Gregorian year g-year.

(defun observational-hebrew-new-year (g-year)

;; Location of Jaffa, Israel. (location (angle 32 1 60) (angle 34 45 0) (mt 0) (hr 2)))

(defconstant jaffa ;; TYPE location

;; Return the Sunday following the Paschal moon. (kday-after sunday paschal-moon)))

(lunar-phase-at-or-after full equinox) jerusalem) jerusalem))))

(floor (apparent-from-local (local-from-universal

2

1

4

3

2

1

16

15

14

13

12

11

10

9

[1]

5

4

3

2

1

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

17

16

15

14

13

12

11

10

G. L. Steele, Jr., Common LISP: The Language, 2nd ed. Digital Press, Bedford, MA, 1990.

Reference

(+ (observational-hebrew-new-year g-year) 13))

;; TYPE gregorian-year -> fixed-date ;; Fixed date of Classical (observational) Passover Eve ;; (Nisan 14) occurring in Gregorian year g-year.

(defun classical-passover-eve (g-year)

day -1)))

(+ new-year (round (* 29.5 (1- month))) 15))) (+ (phasis-on-or-before ; First day of month. midmonth jaffa)

(+ start 60))) (new-year (observational-hebrew-new-year g-year)) (midmonth ; Middle of given month.

(start (fixed-from-hebrew (hebrew-date year1 nisan 1))) (g-year (gregorian-year-from-fixed

(day (standard-day h-date)) (year (standard-year h-date)) (year1 (if (>= month tishri) (1- year) year))

;; TYPE hebrew-date -> fixed-date ;; Fixed date equivalent to Observational Hebrew date. (let* ((month (standard-month h-date))

(defun fixed-from-observational-hebrew (h-date)

(hebrew-date year month day)))

(year (+ (standard-year (hebrew-from-fixed new-year)) (if (>= month tishri) 1 0))) (day (- date crescent -1)))

(1- g-year)) ny)) (month (1+ (round (/ (- crescent new-year) 29.5))))

(new-year (if (< date ny) (observational-hebrew-new-year

Appendix B. Lisp Implementation 439

440

Hand-printed chart dials for the Japanese calendar by Hikotaro Kaneko, Ise, Japan, 1886. The wheels on the left calculate one’s age; those on the right show lunar and solar months, tides, and so on.

Appendix C

Sample Data

 

—Abraham ben David of Posquieres: Strictures to Maimonides’ Mishneh Torah, Gifts to the Poor 5:11

To aid the reader interested in translating our functions into other programming languages, we give a table of 33 dates from years −1000 to 2100 with their equivalents on all the calendars discussed in the book. For each date we also give the dates of Easter that same year (Orthodox, Gregorian, and astronomical), the solar longitude at 12:00:00 U.T., the moment of the next summer solstice (U.T.), the lunar longitude at 00:00:00 U.T., the moment of the next new moon (U.T.), the standard time of astronomical dawn in Paris, and the standard time of sunset for Jerusalem. All dates and values given are as computed by our functions and hence may not represent historical reality; furthermore, some of these dates are not meaningful for all calendars. The bottom of each column in the tables gives the equation number and corresponding page of the function used to compute that column. But go thou thy way till the end be; and thou shalt rest, and shalt stand up to thy lot, at the end of the days. —Daniel 12:13

441

442 (1.51), 27

−214193 −61387 25469 49217 171307 210155 253427 369740 400085 434355 452605 470160 473837 507850 524156 544676 567118 569477 601716 613424 626596 645554 664224 671401 694799 704424 708842 709409 709580 727274 728714 744313 764652 (eqn), pg:

(1.5), 17

(1.8), 17

Modified Julian Day Julian Day 1507231.5 −892769 1660037.5 −739963 1746893.5 −653107 1770641.5 −629359 1892731.5 −507269 1931579.5 −468421 1974851.5 −425149 2091164.5 −308836 2121509.5 −278491 2155779.5 −244221 2174029.5 −225971 2191584.5 −208416 2195261.5 −204739 2229274.5 −170726 2245580.5 −154420 2266100.5 −133900 2288542.5 −111458 2290901.5 −109099 2323140.5 −76860 2334848.5 −65152 2348020.5 −51980 2366978.5 −33022 2385648.5 −14352 2392825.5 −7175 2416223.5 16223 2425848.5 25848 2430266.5 30266 2430833.5 30833 2431004.5 31004 2448698.5 48698 2450138.5 50138 2465737.5 65737 2486076.5 86076 (2.23), 51

(5.2), 80

(3.4), 64

(3.11), 68

(1.40), 25

(1.43), 26

(4.4), 74

Julian1 Gregorian ISO Date Roman Name Egyptian Armenian Coptic −586 7 24 −586 29 7 −587 7 30 −587 8 1 3 f 161 7 15 −1138 4 10 −870 12 6 −168 12 5 −168 49 3 −169 12 8 −169 12 3 6 f 580 3 6 −720 12 6 −451 4 12 70 9 24 70 39 3 70 9 26 70 10 1 6 f 818 2 22 −482 11 22 −213 1 29 135 10 2 135 39 7 135 10 3 135 10 2 5 f 883 3 15 −417 12 15 −148 2 5 470 1 8 470 2 3 470 1 7 470 1 3 7 f 1217 9 15 −82 6 10 186 5 12 576 5 20 576 21 1 576 5 18 576 6 1 15 f 1324 2 18 24 11 18 292 9 23 694 11 10 694 45 6 694 11 7 694 11 3 7 f 1442 9 10 143 6 5 411 3 11 1013 4 25 1013 16 7 1013 4 19 1013 5 1 13 f 1761 5 8 462 2 3 729 8 24 1096 5 24 1096 21 7 1096 5 18 1096 6 1 15 f 1844 6 28 545 3 23 812 9 23 1190 3 23 1190 12 5 1190 3 16 1190 4 1 17 f 1938 5 18 639 2 13 906 7 20 1240 3 10 1240 10 6 1240 3 3 1240 3 2 5 f 1988 5 18 689 2 13 956 7 7 1288 4 2 1288 14 5 1288 3 26 1288 4 1 7 f 2036 6 23 737 3 18 1004 7 30 1298 4 27 1298 17 7 1298 4 20 1298 5 1 12 f 2046 7 20 747 4 15 1014 8 25 1391 6 12 1391 23 7 1391 6 4 1391 6 2 2 f 2139 9 28 840 6 23 1107 10 10 1436 2 3 1436 5 3 1436 1 25 1436 2 1 8 f 2184 5 29 885 2 24 1152 5 29 1492 4 9 1492 14 6 1492 3 31 1492 4 1 2 f 2240 8 19 941 5 14 1208 8 5 1553 9 19 1553 38 6 1553 9 9 1553 9 3 5 f 2302 2 11 1002 11 11 1270 1 12 1560 3 5 1560 9 6 1560 2 24 1560 3 1 6 f 2308 7 30 1009 4 25 1276 6 29 1648 6 10 1648 24 3 1648 5 31 1648 6 1 2 f 2396 11 29 1097 8 24 1364 10 6 1680 6 30 1680 26 7 1680 6 20 1680 7 1 12 f 2428 12 27 1129 9 22 1396 10 26 1716 7 24 1716 30 5 1716 7 13 1716 7 3 3 f 2465 1 24 1165 10 24 1432 11 19 1768 6 19 1768 24 7 1768 6 8 1768 6 3 6 f 2517 1 2 1217 10 2 1484 10 14 1819 8 2 1819 31 1 1819 7 21 1819 8 1 12 f 2568 2 27 1268 11 27 1535 11 27 1839 3 27 1839 13 3 1839 3 15 1839 3 3 1 f 2587 10 29 1288 7 24 1555 7 19 1903 4 19 1903 16 7 1903 4 6 1903 4 3 8 f 2651 12 7 1352 9 2 1619 8 11 1929 8 25 1929 34 7 1929 8 12 1929 8 3 2 f 2678 4 17 1379 1 12 1645 12 19 1941 9 29 1941 40 1 1941 9 16 1941 10 1 16 f 2690 5 25 1391 2 20 1658 1 19 1943 4 19 1943 16 1 1943 4 6 1943 4 3 8 f 2691 12 17 1392 9 12 1659 8 11 1943 10 7 1943 40 4 1943 9 24 1943 10 1 8 f 2692 6 3 1393 2 28 1660 1 26 1992 3 17 1992 12 2 1992 3 4 1992 3 2 4 f 2740 11 27 1441 8 22 1708 7 8 1996 2 25 1996 8 7 1996 2 12 1996 2 3 2 f 2744 11 7 1445 8 2 1712 6 17 2038 11 10 2038 45 3 2038 10 28 2038 11 1 5 f 2787 8 1 1488 4 26 1755 3 1 2094 7 18 2094 28 7 2094 7 5 2094 7 2 3 f 2843 4 20 1544 1 15 1810 11 11

mentioned in Section 1.3, the negative years in the first two lines of the columns for Julian date and the Roman name are B.C.E. years: 587 B.C.E. and 169 B.C.E., respectively. They appear as negative numbers because the table consists of raw output from the functions.

1 As

Weekday Sunday Wednesday Wednesday Sunday Wednesday Monday Saturday Sunday Sunday Friday Saturday Friday Sunday Sunday Wednesday Saturday Saturday Saturday Wednesday Sunday Friday Sunday Monday Wednesday Sunday Sunday Monday Monday Thursday Tuesday Sunday Wednesday Sunday

R. D .

443 (eqn), pg:

−214193 −61387 25469 49217 171307 210155 253427 369740 400085 434355 452605 470160 473837 507850 524156 544676 567118 569477 601716 613424 626596 645554 664224 671401 694799 704424 708842 709409 709580 727274 728714 744313 764652

R. D .

(4.7), 76

(6.4), 85

(20.8), 329

Islamic Ethiopic Arithmetic Observational −594 12 6 −1245 12 9 −1245 12 11 −175 4 12 −813 2 23 −813 2 25 63 1 29 −568 4 1 −568 4 2 128 2 5 −501 4 6 −501 4 7 462 5 12 −157 10 17 −157 10 18 568 9 23 −47 6 3 −47 6 3 687 3 11 75 7 13 75 7 13 1005 8 24 403 10 5 403 10 5 1088 9 23 489 5 22 489 5 22 1182 7 20 586 2 7 586 2 7 1232 7 7 637 8 7 637 8 7 1280 7 30 687 2 20 687 2 21 1290 8 25 697 7 7 697 7 7 1383 10 10 793 7 1 793 6 30 1428 5 29 839 7 6 839 7 6 1484 8 5 897 6 1 897 6 2 1546 1 12 960 9 30 960 9 30 1552 6 29 967 5 27 967 5 27 1640 10 6 1058 5 18 1058 5 18 1672 10 26 1091 6 2 1091 6 3 1708 11 19 1128 8 4 1128 8 4 1760 10 14 1182 2 3 1182 2 4 1811 11 27 1234 10 10 1234 10 10 1831 7 19 1255 1 11 1255 1 11 1895 8 11 1321 1 21 1321 1 20 1921 12 19 1348 3 19 1348 3 19 1934 1 19 1360 9 8 1360 9 7 1935 8 11 1362 4 13 1362 4 14 1936 1 26 1362 10 7 1362 10 7 1984 7 8 1412 9 13 1412 9 12 1988 6 17 1416 10 5 1416 10 5 2031 3 1 1460 10 12 1460 10 12 2086 11 11 1518 3 5 1518 3 5 −6 −5 −4 −4 −3 −3 −3 −2 −2 −1 −1 −1 −1 −1 −1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 (15.4), 232

Western 6 3 7 9 3 14 2 13 10 6 2 11 4 13 16 10 6 4 16 10 13 14 6 2 18 13 4 4 12 1 7 4 19 9 15 1 10 6 2 15 4 5 17 10 17 1 10 2 4 14 10 5 1 19 9 14 5 11 8 6 13 6 7 16 1 5 18 14 8 19 15 1 4 3 2 5 10 9 6 3 11 6 5 2 6 5 11 8 15 19 8 19 18 11 5 13 14 4 7 12 13 17 6 9 4 7 17 8 3 9 13 19 8 16 1 12 4 6 7 12 15 2 7 11 6 3 11 11 16 19 7 6

−6 −5 −4 −4 −3 −3 −3 −2 −2 −1 −1 −1 −1 −1 −1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1

Bahá’í

(15.9), 235

Future 6 3 7 9 3 14 2 13 10 6 2 11 4 13 16 10 6 4 16 10 13 14 6 2 18 13 4 4 12 1 7 4 19 9 15 1 10 6 3 15 4 5 17 10 17 1 10 2 4 14 10 5 1 19 9 14 5 11 8 6 13 6 7 16 1 5 18 14 8 19 15 1 4 3 2 5 10 9 6 3 11 6 5 2 6 5 11 8 15 19 8 19 18 11 5 13 14 4 7 11 13 18 6 10 5 7 17 9 3 10 14 1 8 16 2 12 4 7 8 13 16 2 7 10 6 3 11 11 17 19 8 7

6 7 8 8 9 9 9 10 10 10 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 (10.3), 139

Long Count 8 3 13 9 8 3 1 9 8 4 15 7 1 14 10 7 2 8 13 2 12 9 5 14 13 10 1 18 5 4 0 15 17 3 4 13 3 14 16 8 9 7 10 14 12 13 11 12 16 14 1 17 0 10 1 10 2 3 2 12 4 19 4 7 11 16 10 3 14 11 3 13 14 8 13 15 15 8 16 7 13 16 9 5 16 9 14 18 18 16 19 2 16 1 6 4 4 2 13

Tzolkin 5 9 9 15 12 11 9 19 3 9 7 17 2 9 4 2 7 7 9 17 7 7 12 2 10 19 2 12 6 18 12 18 3 20 9 19 8 18 3 6 6 18 10 16 12 6 13 3 11 1 3 6 1 4 9 11 11 2 12 16 9 16 8 15 2 14

Aztec Xihuitl Tonalp. 2 6 5 9 14 2 9 15 13 8 12 11 14 11 9 19 5 6 3 9 13 4 7 17 5 1 2 9 17 4 4 2 1 9 7 7 17 14 9 17 17 14 7 7 1 4 12 2 2 11 10 19 5 19 2 12 18 5 6 18 3 20 12 18 12 17 3 20 3 1 9 19 8 20 8 18 10 8 3 6 11 20 6 18 10 18 10 16 13 13 12 6 7 10 13 3 9 8 11 1 16 3 3 6 18 1 1 4 9 18 9 11 18 9 11 2 8 18 12 16 7 18 9 16 3 2 8 15 16 6 2 14 (10.6), 140 (10.9), 142 (10.17), 147 (10.21), 148

Mayan Haab 9 11 12 15 5 3 11 4 9 19 5 12 9 14 12 17 4 5 9 14 7 2 8 5 7 10 15 17 8 15 7 8 15 2 10 10 19 11 17 12 15 5 18 9 6 18 13 6 0 3 18 19 12 7 18 18 6 6 1 9 18 3 1 16 1 19 6 4 14 3 16 16 1 18 14 6 7 4 4 9 2 11 19 4 2 9 10 16 18 4 16 17 4 15 12 8 14 7 7

444 (eqn), pg:

−214193 −61387 25469 49217 171307 210155 253427 369740 400085 434355 452605 470160 473837 507850 524156 544676 567118 569477 601716 613424 626596 645554 664224 671401 694799 704424 708842 709409 709580 727274 728714 744313 764652

R. D .

(7.28), 99

(20.11), 330

Hebrew Standard Observational 3174 5 10 3174 5 11 3593 9 25 3593 9 24 3831 7 3 3831 7 2 3896 7 9 3896 7 7 4230 10 18 4230 10 18 4336 3 4 4336 3 3 4455 8 13 4455 9 13 4773 2 6 4773 2 5 4856 2 23 4856 2 22 4950 1 7 4950 1 7 5000 13 8 5000 13 7 5048 1 21 5048 1 21 5058 2 7 5058 2 7 5151 4 1 5151 3 30 5196 11 7 5196 12 6 5252 1 3 5252 2 2 5314 7 1 5313 6 30 5320 12 27 5320 12 27 5408 3 20 5408 3 18 5440 4 3 5440 4 3 5476 5 5 5476 5 4 5528 4 4 5528 4 4 5579 5 11 5579 5 10 5599 1 12 5599 1 11 5663 1 22 5663 1 20 5689 5 19 5689 6 19 5702 7 8 5702 7 7 5703 1 14 5703 2 14 5704 7 8 5704 8 7 5752 13 12 5752 1 12 5756 12 5 5756 12 5 5799 8 12 5799 9 12 5854 5 5 5854 5 5 (8.1), 115

(8.3), 117

(20.1), 325

Easter (same year) Julian Gregorian Astronomical −586 4 3 −586 4 3 −586 4 3 −168 4 1 −168 4 8 −168 4 8 70 4 13 70 4 13 70 4 13 135 4 17 135 4 17 135 4 17 470 4 6 470 4 6 470 4 6 576 4 7 576 4 7 576 4 7 694 4 22 694 4 22 694 4 22 1013 4 11 1013 4 11 1013 4 11 1096 4 19 1096 4 19 1096 4 19 1190 4 1 1190 4 1 1190 4 1 1240 4 22 1240 4 22 1240 4 22 1288 4 4 1288 3 28 1288 3 28 1298 4 13 1298 4 6 1298 4 6 1391 4 3 1391 4 3 1391 4 3 1436 4 17 1436 4 17 1436 4 17 1492 5 1 1492 3 27 1492 3 27 1553 4 12 1553 4 12 1553 4 12 1560 4 24 1560 3 27 1560 3 27 1648 4 12 1648 4 12 1648 4 12 1680 4 21 1680 4 21 1680 4 21 1716 4 12 1716 4 12 1716 4 12 1768 4 10 1768 4 3 1768 4 3 1819 4 18 1819 4 11 1819 4 11 1839 4 7 1839 3 31 1839 3 31 1903 4 19 1903 4 12 1903 4 19 1929 5 5 1929 3 31 1929 3 31 1941 4 20 1941 4 13 1941 4 13 1943 4 25 1943 4 25 1943 3 28 1943 4 25 1943 4 25 1943 3 28 1992 4 26 1992 4 19 1992 4 19 1996 4 14 1996 4 7 1996 4 7 2038 4 25 2038 4 25 2038 3 28 2094 4 11 2094 4 4 2094 4 4 (11.1), 155

Balinese Pawukon f 111311573 t 221454552 t 221554156 f 123351353 f 113314315 t 221152180 f 123357327 f 122121221 f 121151181 t 231136132 f 111117515 t 234166862 f 123351353 f 114141471 f 122224257 f 124227889 t 214447474 f 123357327 f 134264837 t 224521454 t 212246216 t 224521454 f 134562833 f 111214547 t 221551584 t 232561234 t 222322212 f 123552323 t 224125484 t 222523282 t 224521454 t 213414712 f 134361863 (14.6), 220

(14.10), 224

Persian Astronomical Arithmetic −1208 5 1 −1208 5 1 −790 9 14 −790 9 14 −552 7 2 −552 7 2 −487 7 9 −487 7 9 −153 10 19 −153 10 18 −46 2 31 −46 2 30 73 8 19 73 8 19 392 2 5 392 2 5 475 3 4 475 3 3 569 1 3 569 1 3 618 12 20 618 12 20 667 1 14 667 1 14 677 2 8 677 2 8 770 3 22 770 3 22 814 11 13 814 11 13 871 1 21 871 1 21 932 6 28 932 6 28 938 12 14 938 12 14 1027 3 21 1027 3 21 1059 4 10 1059 4 10 1095 5 2 1095 5 2 1147 3 30 1147 3 30 1198 5 10 1198 5 10 1218 1 7 1218 1 7 1282 1 29 1282 1 29 1308 6 3 1308 6 3 1320 7 7 1320 7 7 1322 1 29 1322 1 29 1322 7 14 1322 7 14 1370 12 27 1370 12 27 1374 12 6 1374 12 6 1417 8 19 1417 8 19 1473 4 28 1473 4 28 (16.6), 242

(16.9), 243

French Revolutionary Original Modified −2378 11 5 −2378 11 4 −1959 3 14 −1959 3 13 −1721 1 2 −1721 1 2 −1656 1 10 −1656 1 10 −1322 4 19 −1322 4 18 −1216 9 1 −1216 9 1 −1097 2 19 −1097 2 19 −779 8 5 −779 8 4 −696 9 5 −696 9 5 −602 7 2 −602 7 1 −552 6 20 −552 6 20 −504 7 13 −504 7 13 −494 8 8 −494 8 8 −401 9 23 −401 9 23 −356 5 14 −356 5 13 −300 7 20 −300 7 19 −239 13 2 −239 13 1 −232 6 15 −232 6 14 −144 9 22 −144 9 22 −112 10 12 −112 10 12 −76 11 6 −76 11 6 −24 10 1 −24 10 1 27 11 14 27 11 14 47 7 6 47 7 6 111 7 28 111 7 29 137 12 7 137 12 7 150 1 7 150 1 7 151 7 29 151 7 29 152 1 15 152 1 15 200 6 27 200 6 27 204 6 6 204 6 7 247 2 20 247 2 20 302 10 30 302 11 1

445 (eqn), pg:

−214193 −61387 25469 49217 171307 210155 253427 369740 400085 434355 452605 470160 473837 507850 524156 544676 567118 569477 601716 613424 626596 645554 664224 671401 694799 704424 708842 709409 709580 727274 728714 744313 764652

R. D .

35 42 46 47 52 54 56 61 63 64 65 66 66 68 68 69 70 70 72 72 73 74 75 75 76 77 77 77 77 78 78 78 79 (17.16), 259

Date 11 6 f 9 10 f 7 8 f 12 8 f 46 11 f 33 4 f 31 10 f 50 3 f 13 4 f 47 2 f 37 2 f 25 2 f 35 3 f 8 5 f 53 1 f 49 3 f 50 8 f 57 1 f 25 4 t 57 6 f 33 6 f 25 5 f 16 6 f 36 2 f 40 3 f 6 7 f 18 8 f 20 3 f 20 9 f 9 2 f 13 1 f 55 10 f 51 6 f 12 27 4 9 20 5 15 7 24 9 9 23 9 2 8 4 2 29 20 5 6 5 12 13 22 21 9 15 9 14 7 14 7 (17.24), 262

(17.4), 250

Chinese Name Next Zhongqi 2 10 −214191.634729 8 8 −61370.733038 4 8 25498.215830 2 8 49239.006687 2 10 171318.590237 10 2 210156.746118 2 2 253439.316510 5 11 369767.417293 10 8 400113.935688 10 6 434384.030321 10 4 452615.453447 5 3 470177.755730 2 8 473861.320341 5 1 507860.232802 1 11 524172.834565 1 11 544687.133715 3 1 567122.834963 2 8 569492.996118 1 3 601727.342116 9 11 613446.520888 1 7 626626.467423 9 5 645556.325334 9 3 664246.376294 6 4 671426.124336 4 2 694801.614263 9 3 704453.869488 7 5 708867.143728 4 8 709411.313395 5 11 709597.630491 9 5 727277.699907 9 5 728738.668667 8 4 744325.562389 7 3 764656.564424 19 26 11 17 19 28 17 26 24 20 7 30 24 7 28 3 12 27 1 21 13 8 20 13 4 11 15 4 23 2 11 26 2

(9.8), 127

Old 2515 5 2933 9 3171 7 3236 7 3570 10 3677 2 3795 8 4114 1 4197 2 4290 12 4340 12 4388 12 4399 1 4492 3 4536 10 4593 1 4654 6 4660 11 4749 3 4781 3 4817 4 4869 3 4920 4 4939 12 5004 1 5030 5 5042 6 5044 1 5044 6 5092 12 5096 11 5139 7 5195 4 (18.20), 288

(18.45), 300

Hindu Solar Modern Astronomical −664 5 19 −664 5 13 −246 9 26 −246 9 21 −8 7 9 −8 7 5 57 7 16 57 7 11 391 10 21 391 10 17 498 2 31 498 2 27 616 8 16 616 8 13 935 1 28 935 1 26 1018 2 26 1018 2 24 1111 12 23 1111 12 21 1161 12 10 1161 12 8 1210 1 2 1209 12 31 1220 1 27 1220 1 25 1313 3 8 1313 3 7 1357 10 30 1357 10 28 1414 1 5 1414 1 4 1475 6 10 1475 6 9 1481 11 29 1481 11 28 1570 3 3 1570 3 2 1602 3 22 1602 3 22 1638 4 13 1638 4 13 1690 3 10 1690 3 9 1741 4 20 1741 4 20 1760 12 16 1760 12 15 1825 1 7 1825 1 7 1851 5 10 1851 5 10 1863 6 14 1863 6 14 1865 1 7 1865 1 6 1865 6 21 1865 6 21 1913 12 4 1913 12 4 1917 11 13 1917 11 13 1960 7 24 1960 7 25 2016 4 2 2016 4 2 (9.13), 133

Old 2515 6 f 2933 9 f 3171 8 f 3236 8 f 3570 11 t 3677 3 f 3795 9 f 4114 2 f 4197 2 f 4291 1 f 4340 12 f 4389 1 f 4399 2 f 4492 4 f 4536 11 f 4593 1 f 4654 7 f 4660 11 f 4749 3 f 4781 4 f 4817 5 f 4869 4 f 4920 5 f 4940 1 t 5004 1 f 5030 5 f 5042 7 f 5044 1 f 5044 7 f 5092 12 f 5096 12 f 5139 8 f 5195 4 f 11 26 3 9 19 5 15 7 24 9 9 23 8 2 7 3 2 29 20 4 6 5 12 13 23 21 9 15 9 14 7 14 6 (18.23), 289

(18.48), 301

Hindu Lunisolar Modern Astronomical −529 6 f 11 f −529 6 t 11 f −111 9 f 27 f −111 9 f 27 f 127 8 f 3 f 127 8 f 3 t 192 8 f 9 f 192 8 f 9 f 526 11 f 19 f 526 10 f 20 f 633 3 f 5 f 633 3 f 5 f 751 9 f 15 f 751 8 f 15 f 1070 2 f 6 f 1070 2 f 6 f 1153 3 t 23 f 1153 2 f 23 f 1247 1 f 8 f 1247 1 f 8 f 1297 1 f 8 f 1296 12 f 8 f 1345 1 f 22 f 1345 1 f 23 f 1355 2 f 8 f 1355 2 f 8 f 1448 4 f 1 f 1448 4 f 1 f 1492 11 f 7 f 1492 11 f 7 f 1549 2 t 3 f 1549 2 t 4 f 1610 7 f 2 f 1610 7 f 2 f 1616 11 f 28 t 1616 11 f 29 f 1705 3 f 20 f 1705 3 f 20 f 1737 4 f 4 f 1737 4 f 5 f 1773 5 f 6 f 1773 5 f 6 f 1825 4 f 5 f 1825 4 f 5 f 1876 5 f 11 f 1876 5 f 11 f 1896 1 f 13 f 1896 1 f 13 f 1960 1 f 22 f 1960 1 f 22 f 1986 5 f 20 f 1986 5 f 20 f 1998 7 f 9 f 1998 7 f 9 f 2000 1 f 14 f 2000 1 f 14 f 2000 7 f 8 f 2000 7 f 8 f 2048 12 f 14 f 2048 12 f 14 f 2052 12 f 7 f 2052 12 f 7 f 2095 8 f 14 f 2095 8 f 14 f 2151 4 f 6 f 2151 4 f 6 f (19.5), 318

Tibetan −459 8 f 11 −41 12 f 27 197 10 f 3 262 10 f 9 596 12 f 19 703 5 f 4 821 10 f 15 1140 4 f 6 1223 4 f 23 1317 3 f 8 1367 2 f 8 1415 2 f 22 1425 4 f 8 1518 5 f 1 1563 1 f 7 1619 3 f 3 1680 8 f 2 1687 1 f 29 1775 4 f 20 1807 6 t 4 1843 6 f 6 1895 5 f 5 1946 6 f 11 1966 2 f 13 2030 2 f 22 2056 7 f 20 2068 8 f 9 2070 3 t 14 2070 8 f 8 2119 1 f 14 2123 1 f 7 2165 9 f 14 2221 6 f 6 f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f

446

Solar Longitude at 12:00:00 U.T. (Degrees) 119.474975 254.252390 181.435260 188.662093 289.089403 59.119357 228.316498 34.466872 63.193926 2.462920 350.480679 13.502229 37.407733 81.030567 313.862451 19.955639 176.060000 344.923458 79.964907 99.302275 121.535304 88.567429 129.289884 6.146911 28.251993 151.780633 185.945867 28.555608 193.347892 357.151263 336.170709 228.185702 116.439301 (13.30), 189

R. D . −214193 −61387 25469 49217 171307 210155 253427 369740 400085 434355 452605 470160 473837 507850 524156 544676 567118 569477 601716 613424 626596 645554 664224 671401 694799 704424 708842 709409 709580 727274 728714 744313 764652

(eqn), pg:

(13.33), 190

Next Solstice/Equinox (R.D.) −214131.148928 −61371.056417 25556.789828 49297.586395 171378.541421 210187.908538 253468.411088 369798.552809 400113.612313 434446.323153 452615.130066 470240.013295 473892.428626 507859.909423 524202.620476 544749.317503 567122.511586 569492.672741 601727.018740 613508.259114 626656.970915 645556.001954 664276.907719 671488.166886 694863.628311 704453.536160 708926.239053 709473.300040 709656.728163 727277.366570 728738.335335 744354.791992 764718.468889 (13.47), 199

Lunar Longitude at 00:00:00 U.T. (Degrees) 244.874423 208.899019 213.737971 292.023244 156.788280 108.049774 39.379279 98.640750 333.042222 92.324006 78.197657 275.005178 128.410088 89.554059 24.630218 53.502041 187.906162 320.178528 314.042381 145.473477 185.030508 142.189133 253.743375 151.648685 287.987744 25.626707 290.288301 189.913142 284.931730 152.339160 51.662468 26.691791 175.500184 (13.46), 198

Next New Moon (R.D.) −214174.621008 −61383.008248 25495.802668 49238.497566 171318.433031 210180.687915 253442.854298 369763.737893 400091.570277 434376.571202 452627.186209 470167.573455 473858.848230 507878.663442 524179.244329 544702.752301 567146.512283 569479.202529 601727.033423 613449.761986 626620.369647 645579.076668 664242.886600 671418.970437 694807.563367 704433.491161 708863.596972 709424.404926 709602.082675 727291.209381 728737.447666 744329.573169 764676.191300 (13.69), 209

Dawn in Paris 48.84◦ N, 2.34◦ E, 27m (Standard Time) 0.095289 = 02:17:13 0.277374 = 06:39:25 0.203568 = 04:53:08 0.212229 = 05:05:37 0.286371 = 06:52:22 0.096281 = 02:18:39 0.253733 = 06:05:23 0.149460 = 03:35:13 0.088473 = 02:07:24 0.209209 = 05:01:16 0.228545 = 05:29:06 0.189853 = 04:33:23 0.143913 = 03:27:14 bogus 0.272360 = 06:32:12 0.178066 = 04:16:25 0.196840 = 04:43:27 0.236578 = 05:40:40 0.045748 = 01:05:53 bogus 0.105595 = 02:32:03 bogus 0.122463 = 02:56:21 0.202857 = 04:52:07 0.162579 = 03:54:07 0.163289 = 03:55:08 0.208698 = 05:00:32 0.162020 = 03:53:19 0.216912 = 05:12:21 0.217688 = 05:13:28 0.247981 = 05:57:06 0.251891 = 06:02:43 0.094955 = 02:16:44 (13.73), 210

Sunset in Jerusalem 31.8◦ N, 35.2◦ E, 800m (Standard Time) 0.780845 = 18:44:25 0.697551 = 16:44:28 0.735134 = 17:38:36 0.728756 = 17:29:25 0.709014 = 17:00:59 0.774490 = 18:35:16 0.701104 = 16:49:35 0.763008 = 18:18:44 0.777070 = 18:38:59 0.748338 = 17:57:36 0.742778 = 17:49:36 0.753357 = 18:04:50 0.764675 = 18:21:08 0.784340 = 18:49:27 0.722765 = 17:20:47 0.756393 = 18:09:12 0.739904 = 17:45:28 0.739901 = 17:45:27 0.784356 = 18:49:28 0.787384 = 18:53:50 0.782256 = 18:46:27 0.786608 = 18:52:43 0.778414 = 18:40:55 0.749936 = 17:59:54 0.760495 = 18:15:07 0.762173 = 18:17:32 0.730888 = 17:32:29 0.760655 = 18:15:21 0.724250 = 17:22:55 0.745605 = 17:53:40 0.734985 = 17:38:23 0.700049 = 16:48:04 0.784771 = 18:50:04

Appendix C. Sample Data

447

References

[1] A. P. Bloch, Day by Day in Jewish History: A Chronology and Calendar of Historic Events, Ktav Publishing House, New York, 1983. [2] M. Gilbert, Atlas of the Holocaust, Pergamon Press, New York, 1988. [3] H. H. Graetz, History of the Jews, Jewish Publication Society, Philadelphia, 1891. [4] C. Roth, ed., Encyclopædia Judaica, Macmillan, New York, 1971. [5] C. Roth, A Jewish Book of Days, Goldston Ltd., London, 1931. [6] F. E. Peters, Jerusalem: The Holy City in the Eyes of Chroniclers, Visitors, Pilgrims, and Prophets from the Days of Abraham to the Beginnings of Modern Times, Princeton University Press, Princeton, NJ, 1985. [7] I. Singer, ed., The Jewish Encyclopedia, Funk and Wagnalls, New York, 1906.

First page of the index to Joseph Scaliger’s De Emendatione Temporum (Frankfort edition, 1593). (Courtesy of the University of Illinois, Urbana, IL.)

448

Index

. . . there will be few who will consider the industry, labor, vigils which we have bestowed upon [the index], or the profit and utility that may be gathered from our labors. For it is the equivalent of a whole book. —Joseph Scaliger: Letter to Isaac Casaubon (January 7, 1604) It requires more scholarship to make a good index than to write the book that is indexed. —George Foote Moore: Address at a reception of the Harvard Graduate School of Arts and Sciences (1925)

Function and constant names are given in boldface, and page numbers for a function are of four types: The page with the function definition is shown in boldface. The page with the type description is shown underlined. The page with the corresponding Lisp code is shown in italics. Pages of other occurrences are given in roman. Names of people are indexed according to the guidelines of The Chicago Manual of Style: The Essential Guide for Writers, Editors, and Publishers, 14th ed., The University of Chicago Press, Chicago, 1993. Symbols

(list construction), 22

[ ] (list element selection), 22   (ceiling function), xvi, 17   (floor function), xvi, 17 π (pi), xvi | | (absolute value function), xvi || (list concatenation), 22  (summation operator), xvi, 20 * (Lisp function), 361 + (Lisp function), 361 - (Lisp function), 361 / (Lisp function), 361 /= (Lisp relation), 361 < (Lisp relation), 361

(Lisp relation), 361 >= (Lisp relation), 361 1+ (Lisp function), 362 1- (Lisp function), 362 A a.d. (= ante diem), 67 Abdali, S. Kamal, 214, 331 Abdollahy, Reza, 222 Aberration, 189 aberration, 189, 189, 342, 400 Abraham ben David, 441 Absolute value function (| |), xvi Abu’l-Faraj, Gregory (= Bar Hebræus), 85 449

450

Index

Access R , 79 A.D. (= Anno Domini), 10 Adam, 92 Adams, John Quincy, 239 adar, 91, 91, 98, 107, 110, 356, 379 Adar (Hebrew month), 90, 91, 103, 106–108 adarii, 91, 91, 98, 107, 356, 379 Adhika month (Hindu calendar), see Leap months, Hindu Adjusted remainder function ( amod ), xvi, 19 advent, 59, 59, 342, 372 Advent Sunday (Christian holiday), 59, 121 Afghan Calendar, 217 Africa, 5 Afzal, Omar, 331 Age Chinese, 266–267 Japanese, 269 A.H. (= Anno Hegiræ), 84 Ahargan.a (Hindu calendar), 124 Ahmad, Imad ad-Dean, 331 Akrami, M¯us¯a, 214 Al-Azhar University, 328 Alaska, 47 Albumazar, see Falaki, Abu-Ma’shar alAlexandria (Egypt), Church of, 113 Ali, H. Amir, 282 Ali-Ahyaie, Masahallah, 219 Almagest, 25, 92, 282 alt-fixed-from-gregorian, 54, 54–56, 65, 342, 370 alt-gregorian-from-fixed, 55, 55, 65, 342, 370 alt-gregorian-year-from-fixed, 56, 56, 342, 370 alt-hindu-sunrise, 298, 298, 301–303, 342, 429 alt-orthodox-easter, 116, 116, 342, 385 A.M. Anno Martyrum, 74 Anno Mundi, 91 a.m. (= ante meridiem), xv amod, 342, 363 Amod function, see Adjusted remainder function Andhra Pradesh (India), 274 Anggara Kasih (Balinese holiday), 160 angle, 342, 396 angle-from-degrees, 24, 24, 342, 366 Angles function definition

representation, 24 solar depression, 212 Annunciation (Orthodox holiday), 71 Anomaly, 282, 283, 285 lunar, 199, 317 solar, 199, 317 A.P. (= Anno Persico or Anno Persarum), 217 Apogee, 283, 317 apparent-from-local, 184, 184, 326, 342, 397 approx-moment-of-depression, 208, 208, 209, 342, 408 april, 48, 48, 115, 117, 270, 356, 368 Arabian Peninsula, 236 Arc of light, 326 arccos-degrees, 342, 395 arcsin-degrees, 342, 395 arctan, 173, 186, 192, 213 arctan-degrees, 173, 342, 395 Ari the Learned, 80 Aries (constellation), 127, 186 first point of, 174, 185, 186 arithmetic-french-from-fixed, 243, 243, 342, 417 arithmetic-french-leap-year?, 243, 243, 342, 416 arithmetic-persian-from-fixed, 224, 224, 342, 412 arithmetic-persian-leap-year?, 222, 222, 342, 412 arithmetic-persian-year-from-fixed, 224, 224, 342, 412 Arithmetical calendars, 45–169, 221–225, 231–233, 242–244 Armenian calendar, 5–6, 11, 25–26 days, 5 epagomenæ, 26 epoch, 15, 25 Lisp code, 366–367 months, 26 sample dates, 441 armenian-date, 342, 366 armenian-epoch, 25, 25, 26, 356, 366 armenian-from-fixed, 26, 26, 342, 367 Arouet, Franc¸ois Marie (= Voltaire), 48 arya-jovian-period, 125, 125, 126, 356, 386 arya-lunar-day, 129, 129, 133, 134, 356, 387 arya-lunar-month, 129, 129, 131–134, 356, 387 ¯ Arya-Siddh¯ anta (First), 126 function type

Lisp code

Index arya-solar-month, 126, 126–129, 131–134, 356, 386 arya-solar-year, 125, 125–127, 131–133, 356, 386 ¯ Aryabhat a, . 126 Ascension Day (Christian holiday), 119 Ascension of ‘Abdu’l-Bah¯a (Bahá’í holiday), 236 Ascension of the Bah¯a’u’ll¯ah (Bahá’í holiday), 236 Ascensional difference, 293 Ash Wednesday (Christian fast), 59, 119, 121 ‘Ash¯ur¯a’ (Islamic holiday), 87 Aslaksen, Helmer, xxv, 265, 272 asr, 213, 213, 342, 410 Asr (Moslem prayer time), 213 Assumption (Christian holiday), 59 astro-hindu-calendar-year, 300, 300, 302, 342, 430 astro-hindu-lunar-from-fixed, 301, 301, 303, 342, 431 astro-hindu-solar-from-fixed, 300, 300, 342, 430 astro-hindu-sunset, 300, 300, 301, 342, 430 astro-lunar-day-from-moment, 301, 301–303, 342, 431 Astronomical calendars, 170–332 Astronomical day numbers, see Julian day numbers Astronomical lunar calendars, 332 classical Hebrew, 329–331 Lisp code, 437–439 observational Islamic, 328–329 astronomical-easter, 325, 325, 342, 438 Astronomy, 171–213, 281–287 Hindu, 281–287 Asura Maya, 275 A.U.C. (= Ab Urbe Condita), 46, 69 auc-year-from-julian-year, 70, 70, 343, 373 Audette, Rodolphe, xxv august, 48, 48, 74, 76, 146, 270, 356, 368 Augustine, Saint (= Aurelius Augustinus), 174 autumn, 191, 191, 241, 356, 400 av, 90, 90, 104, 356, 379 Avanes, Armond, xxv Aveni, Anthony F., 150 Avron, Haim, xxv ayanamsha, 299, 299, 343, 430 ayyam-i-ha, 231, 231, 233, 235, 236, 356, 413 function definition

451

Ayyappa Jyothi Darshanam (Hindu holiday), 304 Aztec calendar, 11, 29, 30, 138, 145–150, 479 Lisp code, 390–392 nemontemi, 146 sample dates, 441 tonalpohualli, 145, 148–149 xihuitl, 145–147 xiuhmolpilli, 149 aztec-correlation, 146, 146–148, 356, 390 aztec-tonalpohualli-correlation, 148, 148–150, 356, 391 aztec-tonalpohualli-date, 148, 343, 391 aztec-tonalpohualli-from-fixed, 148, 148, 149, 343, 391 aztec-tonalpohualli-name, 148, 343, 391 aztec-tonalpohualli-number, 148, 343, 391 aztec-tonalpohualli-on-or-before, 149, 149, 343, 391 aztec-tonalpohualli-ordinal, 148, 148–150, 343, 391 aztec-xihuitl-correlation, 147, 147, 150, 356, 390 aztec-xihuitl-date, 147, 149, 343, 390 aztec-xihuitl-day, 147, 343, 390 aztec-xihuitl-from-fixed, 147, 147, 149, 343, 390 aztec-xihuitl-month, 147, 149, 343, 390 aztec-xihuitl-on-or-before, 147, 147, 149, 343, 391 aztec-xihuitl-ordinal, 146, 146, 147, 150, 343, 390 aztec-xihuitl-tonalpohualli-on-or-before, 149, 149, 343, 392 aztec-xiuhmolpilli-designation, 343, 391 aztec-xiuhmolpilli-from-fixed, 149, 149, 343, 391 aztec-xiuhmolpilli-name, 343, 391 aztec-xiuhmolpilli-number, 343, 391 B B¯ab (= Mirz¯a Ali Muhammad), 228, 229 Babylonian calendar, 6 Bach, Henri, 479 Bahá’í calendar, 6, 11, 182, 229–237 days, 4, 13 epoch, 15 future, 187, 192, 193, 218, 229, 236–237 holidays, 236–237 implementation, 231–233

function type

Lisp code

452

Index

leap-year rule, 229 Lisp code, 413–415 months, 230 Near Eastern, 236–237 New Year, 236, 237 sample dates, 441 structure, 229–231 weekdays, 229 Western, 231–233 Bahá’í New Year, see Feast of Naw-R¯uz bahai-cycle, 343, 413 bahai-date, 343, 413 bahai-day, 343, 413 bahai-epoch, 231, 231, 232, 235, 237, 356, 413 bahai-from-fixed, 232, 232, 343, 414 bahai-major, 343, 413 bahai-month, 343, 413 bahai-new-year, 236, 236, 343, 415 bahai-year, 344, 413 Bah¯a’u’ll¯ah (= Mirz¯a H.oseyn Ali N¯uri), 229 Bahula, see Month, dark fortnight Bali, 5, 152, 153 bali-asatawara, 344, 392 bali-asatawara-from-fixed, 155, 158, 158, 344, 393 bali-caturwara, 344, 392 bali-caturwara-from-fixed, 155, 158, 158, 344, 393 bali-dasawara, 344, 393 bali-dasawara-from-fixed, 155, 157, 157, 158, 344, 393 bali-day-from-fixed, 155, 155, 157–160, 344, 393 bali-dwiwara, 344, 392 bali-dwiwara-from-fixed, 155, 157, 157, 344, 393 bali-epoch, 155, 155, 356, 393 bali-luang, 344, 392 bali-luang-from-fixed, 155, 158, 158, 344, 393 bali-on-or-before, 159, 159, 344, 394 bali-pancawara, 159, 344, 392 bali-pancawara-from-fixed, 155, 155, 157, 344, 393 bali-pawukon-from-fixed, 155, 155, 344, 394 bali-sadwara, 159, 344, 392 bali-sadwara-from-fixed, 155, 155, 344, 393 bali-sangawara, 344, 392 function definition

bali-sangawara-from-fixed, 155, 158, 158, 344, 393 bali-saptawara, 159, 344, 392 bali-saptawara-from-fixed, 155, 155, 157, 344, 393 bali-triwara, 344, 392 bali-triwara-from-fixed, 155, 155, 344, 393 bali-week-from-fixed, 157, 157, 344, 394 Balinese Pawukon calendar, 5, 11, 28, 29, 153–161 holidays, 155, 159–161 Lisp code, 392–394 sample dates, 441 balinese-date, 344, 392 Balkh (Iran), 216 Ball, John A., 60 Banaras, see V¯ar¯an¯asi Bangladesh, 328 Bar Hebræus, see Abu’l-Faraj, Gregory Bar mitzvah (Jewish event), 105 Bar, Kfir, xxv Bargeloní, Abraham bar H.iyya al- (= Savasorda), 89, 92, 111 Bat mitzvah (Jewish event), 105 B.C. (= Before Christ), 14 B.C.E. (= Before the Common Era), 14 bce, 344, 372 B.E. (= Bahá’í Era), 231 Beckwith, Roger T., 120 Bede, Venerable, 12, 46, 113, 193 Beijing (China), 175, 250–252, 255 Belize, 137 Beltrami, Olivier, xxv Ben-Meir, Aaron, 93 Benediktsson, Jakob, 80 Bengal (India), 288 Berlekamp, Elwyn R., 110, 121 Bernal, Ignacio, 150 Berzin, Alexander, 315 Beyle, Marie-Henri (=Stendhal), 241 Bhutan calendar, 315 Bible Daniel, 441 Exodus, 91 Ezekiel, 166 Leviticus, 90 Psalms, 4 Bien, Reinhold, 121 Bierce, Ambrose, 476 Bihar (India), 277 binary-search, 21, 344, 364 function type

Lisp code

Index binary-search (binary search macro), 364 Birashk, Ahmad, 85, 87, 217–219, 221, 222, 225, 227 Birkath ha-H.ama (Jewish event), 105 birkath-ha-hama, 105, 105, 344, 382 Birth of ‘Abdu’l-Bah¯a (Bahá’í holiday), 236 Birth of the B¯ab (Bahá’í holiday), 236, 237 Birth of the Bah¯a’u’ll¯ah (Bahá’í holiday), 236, 237 Birthday of Krishna (Hindu holiday), 306 Birthday of R¯ama (Hindu holiday), 306, 309 B¯ır¯un¯ı, Ab¯u-Raih.a¯ n Muh.ammad ibn ’Ah.mad al-, 1, 82, 92, 94, 110, 123, 129, 134, 226, 275, 278, 295 Bissextile years, see Leap years Bissextus (leap day), 66 Blackburn, Bonnie, 41, 71 Bloch, Abraham P., 447 Blue moon, 195 Bodde, Derk, 273 bogus, 102, 144, 145, 149, 208–212, 266, 342–346, 352–355, 357, 362, 446 Bohras, 85 Bolshevik Revolution, 47 Bonaparte, Louis Napoleon (= Napoleon III), 239 Bonaparte, Napoleon, 239 Boncompagni, Ugo, see Gregory XIII, Pope Bornstein, H.ayyim Y., 89, 111 Bowditch, Charles P., 150 Brady, John, 244 Brainerd, George W., 150 Bramsen, William, 272 Brand, Stewart, 324 Braude, Morris, 9 Bredon; Juliet, 272 Bresenham, Jack E., 32 Bretagnon, Pierre, 214 Brewer, David, xxi Brisson, James F., 479 Bromberg, Irvin L., xxv, 96 Browne, Gerald M., xxv Brownfield, Marla, xxv Buda-Cemeng (Balinese holiday), 160 Buda-Keliwon (Balinese holiday), 160 Buddha’s Birthday (Buddhist holiday), 264, 306, 321 Buddha’s Descent (Buddhist holiday), 322 Buddha’s Enlightenment (Buddhist holiday), 322 function definition

453

Building of the Cross (Coptic holiday), 77 Burgess, Ebenezer, 282, 312 Burgess, James, 134, 312 Burnaby, Sherrard B., 87, 111 Bushwick, Nathan, 111 C C (computer language), 18, 19, 40, 365 C++ (computer language), 18, 19, 40, 365 Caching, 40 Cæsar, Julius, 46, 62, 69 Cæsarea (Israel), 46 Cairo (Egypt), 328 Cajori, Florian, 112 Calendar Afghan, 217 arithmetical, 45–169, 221–225, 231–233, 242–244 Armenian, 5–6, 11, 15, 25–26 astronomical, 170–332 lunar, 325–332 Aztec, 11, 29, 30, 138, 145–150, 479 tonalpohualli, 145, 148–149 xihuitl, 145–147 xiuhmolpilli, 149 Babylonian, 6 Bahá’í, 4, 6, 11, 15, 182, 229–237 future, 187, 192, 193, 218, 229, 236–237 Near Eastern, 236–237 Western, 231–233 Balinese Pawukon, 5, 11, 28, 29, 153–161 Bhutan, 315 Chinese, xxii, 5–7, 11, 15, 28, 30–32, 89, 182, 187, 193, 195, 207, 247–273, 275, 299, 316, 333–334 Coptic, 6, 7, 9–11, 15, 73–77, 105, 164–165, 217 diurnal, 4 ecclesiastical, 113–121 Egyptian, 6, 7, 10, 11, 15, 24–25, 140 Ethiopic, 6, 7, 9–11, 15, 75–76, 217 French Revolutionary, xxii, 4, 6, 7, 10, 11, 15, 182, 207, 239–244 modified, 242–244 original, 187, 192, 193, 239–242 Generic cyclical, 163–168 Gregorian, xx, 1, 6, 7, 10, 11, 15, 16, 45–61, 70, 94–95, 104, 233, 234, 275 function type

Lisp code

454

Index

Hebrew, 1, 4, 6, 7, 10, 11, 15, 89–112, 123, 182, 207 classical, 326, 329–331 Hindu, xxii, 6, 10, 11, 15, 28, 89, 123–135, 182, 185, 186, 195, 207, 247, 255, 275–313, 315 modern, 7, 182, 185, 195, 275–313 old, 7, 123–135, 275, 277, 289 Icelandic, 80 Islamic, 4, 6, 7, 10, 11, 15, 83–87, 89, 102, 182, 217, 222, 275 observational, 11, 86, 328–329 ISO, 6, 11, 15, 79–81 Jal¯al¯ı, 217 Japanese, 268–269 Julian, 6, 7, 9–11, 15, 48, 57, 63–71, 105, 217, 479 revised, 47, 70 Karaite, 329 Korean, 269–271 lunar, 6, 326–329 lunisolar, 6, 35, 329–331 Mayan, xxii, 10, 11, 15, 28, 29, 137–151 haab, 139–142, 144–145, 147 long count, 138–139 round, 144–145, 149 tzolkin, 5, 30–31, 142–145, 148 Mongolian, 315 Native American, 6, 239 Nepali, 277 Persian, 6, 7, 9–11, 15, 217–227 arithmetic, 221–225 astronomical, 182, 187, 192, 193, 219–221 Roman nomenclature, 11, 65–69 Sherpa, 315 solar, 6, 236 taxonomy, 4–9 Tibetan, 6, 10, 12, 15, 315–322 Tsurphu, 315 Vietnamese, 271–272 Zoroastrian, 15, 26, 217 Casaubon, Isaac, 449 Caso, Alfonso, 150 Cassini, Jacques, 46 Catholic Church, 121 C.E. (= Common Era), 10 ce, 344, 372 Ceiling function ( ), xvi, 17 cfs-alert, 211, 211 Chaˆıne, Marius, 77 function definition

Chakravarty, Apurba K., 312 Chamberlain, Basil H., 268 Chandramana Ugadi, see New Year, Hindu lunisolar Chandran, Sharat, xxv Chatterjee, S. K., 312 Chaturvedi, Anoop, xxv Chen, Jiujin, 272 Chen, Shigang, xxv Chesterfield, Earl of, see Stanhope, Philip D. China, see also Beijing, Nanjing, Shˇanx¯ı, and X¯ıa¯ n, 247, 268 Chinese calendar, xxii, 5–7, 11, 28, 30–32, 89, 182, 187, 193, 195, 207, 247–273, 316, 333–334 age, 266–267 celestial stem names, 260 days, 13 epoch, 15, 258 holidays, 264–266 implementation, 258–260 Lisp code, 417–423 marriage auguries, 267–268 misconceptions, 263–264 month numbering, 252–258 New Year, xxii, 248, 263–264, 266, 271, 332 sample dates, 441 sexagesimal cycle of names, 260–263 solar terms, 248–251 structure, 251–252 terrestrial branch names, 261 chinese-age, 266, 266, 269, 344, 422 chinese-branch, 344, 421 chinese-cycle, 345, 417 chinese-date, 345, 417 chinese-day, 345, 417 chinese-day-name-epoch, 262, 262, 357, 422 chinese-day-name-on-or-before, 262, 262, 345, 422 chinese-epoch, 258, 258–260, 264, 266, 357, 419 chinese-from-fixed, 259, 259, 260, 267, 345, 420 chinese-leap, 345, 417 chinese-location, 248, 248, 250–252, 269, 345, 417 chinese-month, 345, 417 chinese-month-name-epoch, 262, 262, 357, 421

function type

Lisp code

Index chinese-name, 345, 421 chinese-name-difference, 261, 261, 262, 345, 421 chinese-name-of-day, 262, 262, 345, 422 chinese-name-of-month, 262, 262, 345, 421 chinese-name-of-year, 261, 261, 345, 421 chinese-new-moon-before, 252, 252, 255, 258, 259, 345, 418 chinese-new-moon-on-or-after, 251, 251, 253, 258–260, 345, 418 chinese-new-year, 264, 264, 345, 419 chinese-new-year-in-sui, 257, 257–259, 345, 419 chinese-new-year-on-or-before, 258, 258, 260, 264, 345, 419 chinese-no-major-solar-term?, 253, 253, 255, 258, 259, 345, 419 chinese-prior-leap-month?, 255, 255, 259, 345, 421 chinese-sexagesimal-name, 261, 261, 262, 345, 421 chinese-solar-longitude-on-or-after, 250, 250, 251, 271, 345, 418 chinese-stem, 345, 421 chinese-winter-solstice-on-or-before, 251, 251, 258, 259, 345, 419 chinese-year, 345, 417 chinese-year-marriage-augury, 267, 267, 345, 422 christmas, 59, 59, 345, 371 Christmas (Christian holiday), 47, 59, 70–71, 77 Christmas Fast (Orthodox fast), 71 Cicero, Marcus Tullius, 79 Cidenas, 92 Clamen, Stewart M., xxv, xxvi, 137 classical-passover-eve, 331, 331, 345, 439 Clavius, Christopher (= Christoph Clau), 114, 116 clock-from-moment, 23, 23, 24, 345, 366 COBOL (computer language), xx Cody, Aelred, 77 Cohn, Berthold, 212, 214 Common Lisp, see Lisp Compline (Christian prayer time), 213 cond (Lisp function), 364 Conditional expressions, 18 Congo, 5 Congress of the Orthodox Oriental Churches, 47, 70 Conjunction, see Moon, new function definition

455

Constantine the Great (= Flavius Valerius Constantinus), 113 Conversions, time of day of, 12 Conway, John H., 110, 121 Cook, Michael A., 83 Cope, Leona, 41 Copeland, Jeffrey L., xxv Copernicus, Nicolaus (= Mikolaj Kopernik), 179 Coptic calendar, 6, 7, 9–11, 33, 35, 36, 38, 46, 73–77, 105, 164–165, 217 days, 13, 73, 74 epagomenæ, 73, 165 epoch, 15, 74 holidays, 76–77 implementation, 74–75 leap-year rule, 74 Lisp code, 375–376 months, 73 sample dates, 441 structure, 73–74 coptic-christmas, 77, 77, 345, 376 coptic-date, 345, 375 coptic-epoch, 74, 74–76, 357, 375 coptic-from-fixed, 74, 74, 76, 77, 105, 346, 376 coptic-in-gregorian, 76, 76, 77, 105, 346, 376 coptic-leap-year?, 74, 74, 346, 375 Corpus Christi (Christian holiday), 121 Corr, Franz, xxv Cortés, Hernán, 30, 146 cosine-degrees, 346, 395 Cox, Nicholas J., xxv Coyne, George V., 60 Craun, Edwin D., 42 Cross, John, xxv Crossley, John N., 273 current-major-solar-term, 248, 248, 253, 346, 417 current-minor-solar-term, 250, 250, 268, 346, 418 Cycles of days, 27–30, 367 of years, 32–39 simultaneous, 5, 30–32, 142–145, 153–161, 261–262 Cyprus, 101 D function type

Lisp code

456

Index

d’Églantine, Fabre (= Philippe Franc¸ois Nazaire Fabre), 239 da Silva, Hezekiah ben David, 94 Dabal, Ehssan, xxv Daivajna, Gan.esa, 285 Dalai Lama, see Gyatso, Tenzin Danki system (Korean calendar), 270 Dasra (Hindu holiday), 306 Date line, international, 47 Dawn, 25, 207–213 astronomical, 212 Islamic, 212 Jewish, 212 sample dates, 441 dawn, 209, 209, 210, 298, 346, 409 Day, 4–6, 17, 177, 179–185 Armenian, 5 Bahá’í, 13 Chinese, 13 civil, 207 Coptic, 13, 73, 74 ecclesiastical, 13 Ethiopic, 13, 75 expunged, 278, 303, 304, 307, 316 French Revolutionary, 4 Gregorian, 13, 45, 218 Hebrew, 4, 13, 89 Hindu, 4, 13, 124, 276 intercalated, 278 Islamic, 4, 13, 83 Julian, 13, 45 Korean, 270 leap, 49, 64, 66, 278, 281, 289, 290, 303, 316 lunar, 129, 133, 134, 278, 286, 290, 298, 303–305, 307, 309 nautical, 13 of week, determination, 27, 56–57 Persian, 13, 26, 218 sidereal, 185, 187, 207, 294 solar, 174, 177, 185, 187, 294 subdivisions, 207 tropical, 185 day-number, 52, 52, 346, 370 day-of-week-from-fixed, 27, 27, 56, 81, 103, 104, 109, 346, 362 Daylight saving, United States, 59 daylight-saving-end, 59, 59, 346, 371 daylight-saving-start, 59, 59, 346, 371 days-in-hebrew-year, 98, 98, 346, 381 days-remaining, 52, 52, 346, 370 function definition

daytime-temporal-hour, 211, 211, 213, 346, 410 de Blois, Franc¸ois C., 87, 227 de Madariaga, Salvador, 30 de Ossorio, Buenaventura Francisco, 112 de Santillana, Giorgio, 258 december, 48, 48, 50, 59, 64, 71, 80, 316, 357, 368 Deckers, Michael H., xxv, xxvii, 54 Declaration of the B¯ab (Bahá’í holiday), 236, 237 Declercq, Georges, 121 Declination, 174, 186 declination, 186, 186, 205, 209, 213, 346, 400 defconstant (Lisp construct), 361 Deferent, 282, 283, 285 defun (Lisp construct), 362 deg, 346, 395 degrees, 346, 395 degrees-from-radians, 346, 395 degrees-minutes-seconds, 346, 396 Delrina Technology, xxi Deo, Narsingh, 42, 61 Depression angles, 212 Dershowitz, Erga, xxv Dershowitz, Idan, xxv Dershowitz, Nachum, iii, xxvi, 214, 312 Deuteronomy Rabbah, 70 Dharamsala (India), 315 Dickson, Stewart P., 324 Dˆıkshit, S. Bâlkr.ishn.a, 135, 277, 306, 312 Diocletian (Roman emperor), 74 Dionysian cycle, 115 Dionysius Exiguus, 46, 113, 114 direction, 173, 173, 346, 396 Dirichlet box principle, 253 diwali, 308, 308, 346, 434 Diwali (Hindu holiday), 306, 308 Doggett, LeRoy E., 41, 60, 71, 214, 273 Double-ninth Festival (Chinese holiday), 264 Douglass, Robert H., xxv Dragon Festival (Chinese holiday), 264 dragon-festival, 266, 266, 346, 422 Dù, Shírán, 273 Durg¯a Asht.am¯ı (Hindu holiday), 306 Durrani, Muhibullah, 331 Dusk, 207–213 astronomical, 212 Islamic, 212 Jewish, 212 function type

Lisp code

Index dusk, 210, 210, 211, 213, 300, 326, 346, 409 Dutka, Jacques, 60 dynamical-from-universal, 179, 179, 346, 399 E Earth, 4, 173, 174, 177, 179, 185–187, 193, 195, 282, 283, 294, 317 equator, 186 orbit, 182, 186 easter, 117, 117, 121, 346, 385 Easter (Christian holiday), xxii, 7, 10, 47, 59, 70, 77, 112–121, 325–326 astronomical, 117–119, 325–326 Gregorian, 116–117 Lisp code, 385–386 Orthodox, 10, 33, 114–116 sample dates, 441 eastern-orthodox-christmas, 71, 71, 346, 385 Eccentricity, 197 Ecclesiastical calendar, 113–121 days, 13 Lisp code, 385–386 Ecliptic, 174, 186, 276, 278 Eco, Umberto, 22 Edmundson, Munro S., 150 E.E. (= Ethiopic Era), 76 Egypt, see also Alexandria, Cairo, Medinet Habu, and Thebes, 5, 24, 328 Egyptian calendar, 6, 7, 10, 11, 24–25, 140 epagomenæ, 24 epoch, 15, 25 Lisp code, 366–367 sample dates, 441 egyptian-date, 346, 366 egyptian-epoch, 25, 25, 26, 357, 366 egyptian-from-fixed, 25, 25, 26, 346, 366 eighth (Lisp function), 361 Eiseman, Fred B., Jr., 161 Eiseman, Margaret, 161 Ekholm, Gordon F., 150 Election Day (U. S. event), 59 election-day, 59, 59, 346, 371 elevation, 346, 396 Elevation of the Life-giving Cross (Orthodox holiday), 71 Eliyahu ben Shelomo Zalman (= Vilna Gaon), 212 Elkins, James, 41 Elongation, 199, 326 function definition

457

elul, 91, 91, 98, 110, 357, 379 Emerson, Ralph Waldo, 333 end, 346, 365 Epacts, 114 Epagomenæ Armenian calendar, 26 Coptic calendar, 73, 165 Egyptian calendar, 24 Persian calendar, 26 Ephemeris, 299 ephemeris-correction, 177, 177, 179–181, 346, 398 Epicycle, 282, 283, 285, 286, 298, 312 epiphany, 59, 59, 346, 372 Epiphany (Christian holiday), 59, 71, 77 epoch (Lisp constant), 363 Epochs, 12, 14 Armenian, 15, 25 Bahá’í, 15, 231 Chinese, 15, 258 Coptic, 15, 74 Egyptian, 15, 25 Ethiopic, xxii, 15, 76 French Revolutionary, 15, 239, 242 Gregorian, 15, 48 Hebrew, 15, 92, 95 Hindu, 15, 123, 124, 284, 288, 289 Islamic, 15, 84 ISO, 15, 79 Julian, 15, 64 julian day number, 15 Mayan, 15, 138 modified julian day number, 15 Persian, 15, 217 Tibetan, 15, 316 Zoroastrian, 15 equal (Lisp relation), 362 Equation of center, 283 Equation of motion, 286 Equation of time, 182–185, 294 equation-of-time, 183, 183, 184, 346, 397 Equator celestial, 186 Earth, 185 Equinox, 6, 21, 163, 171, 186, 187, 190, 191, 300 autumnal, 105, 239, 241 dynamical, 187 sample dates, 441

function type

Lisp code

458

Index vernal, 46, 105, 113, 114, 119, 185, 192, 217–219, 229, 233, 234, 236, 241, 304, 325, 329

Era Alexander, 16 Seleucid, 16, 89 Esslemont, John E., 229 estimate-prior-solar-longitude, 193, 193, 220, 234, 241, 251, 346, 401 Ethiopic calendar, 6, 7, 9–11, 75–76, 217 days, 13, 75 epoch, xxii, 15, 76 holidays, 77 implementation, 76 Lisp code, 376 months, 75 sample dates, 441 structure, 75–76 ethiopic-date, 347, 376 ethiopic-epoch, 76, 76, 357, 376 ethiopic-from-fixed, 76, 76, 347, 376 Euclid, 31 Europe, 175 Eusebius, 46, 113 Eve, 92 evening, 210, 210, 357, 409 evenp (Lisp function), 361 Everett, Steven M., 42 Excel R , xxi, 79 F Falaki, Abu-Ma’shar al- (= Albumazar), 216 false, 66, 208, 357, 362 Fast of the Apostles (Orthodox fast), 121 Fast of the Repose of the Virgin Mary (Orthodox fast), 71 Fausett, Donald W., xxv Fayy¯umi, Sa’adia ben Joseph al- (= Sa’adia Gaon), 89, 93 Feast of Naw-R¯uz (Bahá’í New Year), 233, 236, 237 Feast of Orthodoxy (Orthodox holiday), 121 Feast of Rid.v¯an (Bahá’í holiday), 236, 237 feast-of-ridvan, 237, 237, 347, 415 february, 48, 48, 68, 124, 258, 357, 367 Feinstein, Moses, 108 Feldman, William M., 111 Fienberg, Richard T., 214 fifth (Lisp function), 361 Filipowski, Herschell, 111 final, 347, 364 function definition

Finland, 115 first (Lisp function), 361 first-kday, 58, 58, 59, 347, 371 first-quarter, 202, 202, 326, 357, 405 Fixed day numbers, 9 fixed-from-arithmetic-french, 243, 243, 244, 347, 416 fixed-from-arithmetic-persian, 223, 223–226, 347, 412 fixed-from-armenian, 25, 25, 347, 366 fixed-from-astro-hindu-lunar, 302, 302, 347, 431 fixed-from-astro-hindu-solar, 301, 301, 347, 431 fixed-from-bahai, 231, 231–233, 347, 413 fixed-from-chinese, 260, 260, 266, 267, 347, 420 fixed-from-coptic, 74, 74–77, 347, 375 fixed-from-egyptian, 25, 25, 347, 366 fixed-from-ethiopic, 76, 76, 347, 376 fixed-from-french, 242, 242, 347, 416 fixed-from-future-bahai, 234, 234, 236, 237, 347, 414 fixed-from-gregorian, see also alt-fixed-from-gregorian, 49, 49–53, 55, 57–59, 64, 117, 179, 191, 211, 231, 232, 236, 242, 258, 264, 266, 270, 316, 347, 368 fixed-from-hebrew, 99, 99–104, 106, 107, 110, 331, 347, 381 fixed-from-hindu-fullmoon, 297, 297, 347, 429 fixed-from-hindu-lunar, 291, 291, 297, 298, 307, 347, 427 fixed-from-hindu-solar, 289, 289, 347, 426 fixed-from-islamic, 85, 85–87, 347, 377 fixed-from-iso, 80, 80, 347, 377 fixed-from-jd, 17, 18, 18, 25, 138, 155, 347, 363 fixed-from-julian, 64, 64, 65, 68, 71, 74, 76, 84, 95, 115, 124, 146, 217, 347, 372 fixed-from-mayan-long-count, 139, 139, 347, 388 fixed-from-mjd, 17, 17, 347, 363 fixed-from-moment, 18, 18, 208, 213, 296, 308, 347, 365 fixed-from-observational-hebrew, 331, 331, 347, 439 fixed-from-observational-islamic, 328, 328, 347, 438 function type

Lisp code

Index fixed-from-old-hindu-lunar, 134, 134, 348, 387 fixed-from-old-hindu-solar, 127, 127, 348, 386 fixed-from-persian, 220, 220, 221, 226, 348, 411 fixed-from-roman, 66, 68, 68, 69, 348, 375 fixed-from-tibetan, 317, 317–319, 321, 348, 436 Fleet, John F., 134 Flesner, Molly, xxv Fliegel, Henry F., 60 floor (Lisp function), 363 Floor function ( ), xvi, 17 Flower Festival (Japanese holiday), 266 Forsythe, George E., 337 Fotheringham, John K., xxvii, 60, 71, 121 fourth (Lisp function), 361 Fractional part function, 18 France, see also Paris, 174 Francou, Gérard, 214 Frazer, James G., 139 Freeman-Grenville, Greville S. P., 87 French Revolutionary calendar, xxii, 6, 7, 10, 11, 182, 207, 239–244 days, 4 decades, 240 epoch, 15, 242 Lisp code, 416–417 modified, 242–244 implementation, 243–244 leap year rule, 242–243 months, 240 original, 187, 192, 193, 239–242 implementation, 241–242 structure, 239–241 sample dates, 441 sansculottides, 240 french-date, 348, 416 french-epoch, 242, 242, 243, 357, 416 french-from-fixed, 242, 242, 348, 416 french-new-year-on-or-before, 241, 241, 242, 348, 416 friday, 27, 27, 60, 104, 109, 110, 357, 362 Friday the Thirteenth, 60 Friedl¨ander, Michael, 111 Frisch, Christian, 119 Fritsche, Hermann P. H., 263, 273 full, 202, 202, 326, 357, 405 future-bahai-from-fixed, 235, 235, 348, 415 function definition

459

future-bahai-new-year-on-or-before, 234, 234–236, 348, 415 G G¨orke, Winfried, xxv Galloway, Thomas, 41 Galungan (Balinese holiday), 160 Galungan Days (Balinese period), 161 Gan¯es´a Chaturth¯ı (Hindu holiday), 306 Gangooly, Phanindralal, 312 Ganz, Solomon, 111, 331 Gardner, Martin, back cover, 185 Gauss, Carl F., xxi, xxvi, 95, 102, 111, 113, 121 Gautama Buddha, 264, 306, 321 Gcd function, see Greatest common divisor function Geertz, Clifford, 153, 159 Gelasius, xxvii Generic cyclical calendars, 163–168 double cycle, 166–167 single cycle, 163–166 George, Alan, 337 Germany, 47, 119 Gezer (Israel), 239 Gilbert, Martin, 447 Gilbert, William S., 45 Gillispie, Charles C., 134, 312 Gingerich, Owen, back cover Ginzel, Friedrich K., 9, 41, 60, 77 GNU Emacs, xix, xxvi, 2, 42 Go-Chosun (Korea), 270 Godman, Frederick D., 150 Goharian, Nazli, xxv Golb, Norman, 111 Goldberg, Mayer, xxv Golden number, 114 Good Friday (Christian holiday), 59, 119 Goodman, John T., 137, 138, 150 Goodman-Martinez-Thompson correlation (Mayan calendar), 137, 138 Graetz, Heinrich H., 447 Grafton, Anthony T., xxvii, 16, 41 Graham, Ronald L., 41 Great Britain, see also Greenwich and London, 47 Great Night of Shiva (Hindu holiday), 306, 309 Greatest common divisor function, xvi, 19 Greaves, John, 14, 85 Greece, 70

function type

Lisp code

460

Index

greenwich, 172, 172 Greenwich (England), xv, 172, 174, 177, 299 Gregorian calendar, xx, 1, 6, 7, 10, 11, 16, 45–61, 70, 94–95, 104, 233, 234, 275 adoption of, 47 days, 13, 45, 218 Easter, 116–117 epoch, 15, 48 history, 46–47 holidays, 57–59 implementation, 48–52 leap-year rule, 45 Lisp code, 367–372 months, 45 New Year, xx, xxi, 47 sample dates, 441 structure, 45 year, 47–48 Gregorian reform, 45, 47, 114 gregorian-date, 348, 367 gregorian-date-difference, 52, 52, 178, 179, 348, 369 gregorian-epoch, 48, 48–50, 55, 56, 357, 367 gregorian-from-fixed, see also alt-gregorian-from-fixed, 51, 51, 53, 60, 67, 348, 369 gregorian-leap-year?, 49, 49, 51, 67, 231, 348, 368 gregorian-new-year, 50, 50, 51, 70, 77, 81, 86, 106, 108, 179, 271, 304, 306, 308, 309, 325, 330, 348, 369 gregorian-year-end, 50, 50, 52, 81, 321, 348, 369 gregorian-year-from-fixed, see also alt-gregorian-year-from-fixed, 50, 50–52, 55, 80, 101–104, 178, 179, 226, 232, 237, 250, 264, 266, 268, 330, 331, 348, 369 gregorian-year-range, 50, 50, 70, 76, 86, 106, 108, 160, 308, 309, 311, 321, 348, 369 Gregory XIII, Pope (= Ugo Boncompagni), 45, 47 Gregory, Ruth W., 60 Guatemala, see also Tikal, 137, 140, 142 Guinot, Bernard, 214 Guy, Richard K., 110, 121 Guyot, Laurent, 238 Gyatso, Tenzin (= Dalai Lama), 315 function definition

H Haab (Mayan calendar), 139–142, 144–145, 147 Hademer, Nathan ben Meir, 479 Hai ben Sherira (= Hai Gaon), 89 haifa, 234, 234, 357, 415 Haifa (Israel), 234, 236 H.alaqim (Hebrew calendar), 92, 207 Hale, Wayne, xx Halevy, Schulamith C., xxv Halkin, Abraham S., xxvii Halmos, Paul, 17 Hamer, Mick, 244 Hania (Crete), 336 Hannah, Robert, xxvii Hanoi (Vietnam), 271 Hansch, Michael G., 119 H.anukkah (Jewish holiday), 101, 103 Harris, Mitchell A., xxv, 41 Harvey, Oswald L., 41 Haryana (India), 277 Hastings, James, 41, 42, 60, 111 Heaslet, Maxwell A., 61, 121 Hebrew calendar, 1, 6, 7, 10, 11, 33, 35, 36, 89–112, 123, 182, 207 bar mitzvah, 105 bat mitzvah, 105 birthdays, 105–106 classical, 326, 329–331 days, 4, 13, 89 delays, 92–93, 96–98, 100–101 epoch, 15, 92, 95 history, 89, 93–95 holidays and fast days, 101–105 implementation, 95–101 Karaite, 329 leap-year rule, 91 Lisp code, 378–385 lo iddo rosh, 92, 108, 109 molad, 92, 95–97, 479 months, 90 nah.ala, 105–108 New Year, see Rosh ha-Shanah possible weekdays, 108–110 sabbatical year, 91 sample dates, 441 structure, 90–93 week, 89 weekdays, 89 yahrzeit, 105–108 hebrew-birthday, 106, 106, 348, 383

function type

Lisp code

Index hebrew-birthday-in-gregorian, 106, 106, 348, 383 hebrew-calendar-elapsed-days, 96, 96–98, 100, 348, 380 hebrew-date, 348, 378 hebrew-epoch, 95, 95, 97–99, 101–104, 357, 379 hebrew-from-fixed, 99, 99, 106, 108, 331, 348, 381 hebrew-leap-year?, 91, 91, 98, 107, 348, 379 hebrew-new-year, 98, 98, 99, 348, 380 hebrew-sabbatical-year?, 91, 91, 348, 379 hebrew-year-length-correction, 97, 97, 98, 348, 380 Heilbron, John L., 121 Henderson, Helene, 42 Henning, Edward, xxv, 315, 322 Herran, Nicolas, xxv Herschel, John W. F., 16, 42 Hezekiah ben David da Silva, 94 Hillel II (= Hillel ben Judah), 89 Hillis, W. Daniel, back cover, 324 Hindu calendar, xxii, 6, 10, 11, 28, 89, 123–135, 182, 185, 186, 195, 207, 247, 255, 275–313 astronomical, 299–303 Lisp code, 429–432 sample dates, 441 days, 4, 13, 124, 276 epoch, 15, 123, 124, 284, 288, 289 holidays, xxiv, 303–312 karan.as, 312 lunisolar, 315, 316 holidays, 304–309 Lisp code, 426–427 lunar day, 129, 133, 134, 278, 286, 290, 298, 303–305, 309 New Year, 133, 285, 305–306 sample dates, 441 modern, 7, 182, 185, 195, 275–313 alternatives, 295–299 expunged day, 278, 303, 304 expunged month, 277, 281, 287, 303, 306 history, 275 implementation, 287–295 intercalated day, 278 leap day, 278, 289 leap month, 277–279, 287, 289, 290, 303, 304, 306, 307 Lisp code, 424–435 function definition

461

structure, 275–281 naks.atras, 312 old, 7, 123–135, 275, 277 history, 123–124 leap month, 123, 128, 129 Lisp code, 386–388 lunisolar, 37–39, 128–134, 167 solar, 7, 126–128 structure, 123–126 old lunisolar implementation, 129–134 Lisp code, 386–388 sample dates, 441 structure, 128–129 old solar implementation, 126–128 Lisp code, 386 sample dates, 441 structure, 126 Panchang, 312 solar holidays, 304 Lisp code, 425–426 New Year, 126, 304, 305 sample dates, 441 tithi, 129, 278, 290, 292, 306, 312 yogas, 312 hindu-anomalistic-month, 285, 285, 286, 357, 425 hindu-anomalistic-year, 285, 285, 286, 294, 295, 357, 425 hindu-arcsin, 283, 283–285, 293, 348, 424 hindu-ascensional-difference, 293, 293, 295, 296, 348, 427 hindu-calendar-year, 287, 287, 288, 290, 349, 426 hindu-creation, 284, 284, 357, 424 hindu-daily-motion, 294, 294, 295, 349, 428 hindu-date-occur, 307, 307, 308, 349, 433 hindu-day-count, 124, 124, 126, 127, 133, 349, 386 hindu-epoch, 124, 124, 127, 134, 284, 287, 289, 291, 293, 300–302, 357, 386 hindu-equation-of-time, 295, 295, 296, 349, 428 hindu-expunged?, 297, 298, 298, 349, 429 hindu-fullmoon-from-fixed, 297, 297, 349, 429 hindu-locale, 292, 292, 295, 296, 298, 300, 357, 429

function type

Lisp code

462

Index

hindu-lunar-date, 349, 426 hindu-lunar-day, 349, 426 hindu-lunar-day-at-or-after, 305, 305, 306, 308, 309, 311, 349, 432 hindu-lunar-day-from-moment, 286, 286, 290–292, 305, 349, 425 hindu-lunar-era, 289, 289–291, 302, 357, 426 hindu-lunar-event, 309, 309, 349, 434 hindu-lunar-from-fixed, 289, 289, 292, 297, 298, 307–309, 312, 349, 426 hindu-lunar-holiday, 308, 308, 349, 434 hindu-lunar-leap-day, 349, 426 hindu-lunar-leap-month, 349, 426 hindu-lunar-longitude, 286, 286, 309, 311, 349, 425 hindu-lunar-month, 349, 426 hindu-lunar-new-year, 305, 305, 349, 433 hindu-lunar-on-or-before?, 307, 307, 349, 433 hindu-lunar-phase, 286, 286, 287, 305, 308, 349, 425 hindu-lunar-station, 309, 309, 349, 432 hindu-lunar-year, 349, 426 hindu-mean-position, 284, 284, 285, 294, 295, 349, 424 hindu-new-moon, 305 hindu-new-moon-before, 287, 287, 290, 349, 425 hindu-rising-sign, 294, 294, 349, 428 hindu-sidereal-month, 276, 276, 286, 357, 424 hindu-sidereal-year, 276, 276, 284, 286, 287, 289, 291, 294, 295, 304, 357, 424 hindu-sine, 283, 283, 285, 293–295, 349, 424 hindu-sine-table, 282, 282–284, 294, 350, 424 hindu-solar-date, 350, 425 hindu-solar-era, 288, 288, 289, 300, 301, 357, 425 hindu-solar-from-fixed, 288, 288, 350, 425 hindu-solar-longitude, 286, 286–288, 291, 293, 304, 311, 350, 425 hindu-solar-longitude-at-or-after, 304, 304, 306, 350, 432 hindu-solar-sidereal-difference, 294, 294–296, 350, 428 hindu-sundial-time, 296, 296, 297, 350, 430 function definition

hindu-sunrise, 288–290, 292, 295, 295, see also alt-hindu-sunrise, 296, 298, 305, 306, 309, 350, 429 hindu-sunset, 296, 296, 350, 430 hindu-synodic-month, 276, 276, 287, 305, 357, 424 hindu-tithi-occur, 308, 308, 309, 350, 434 hindu-tropical-longitude, 293, 293, 294, 350, 428 hindu-true-position, 285, 285, 286, 350, 424 hindu-zodiac, 286, 286–290, 350, 425 Hồ Ngọc Đức, 271, 273 Hoang, Peter (Pierre), 273, 333 Hoffman, Roy E., 331 Hoffrichter, Burghart, xxv Hohenkerk, Catherine Y., 215 Holford-Strevens, Leofranc, 41, 71 Holi (Hindu holiday), 306 Holidays Bahá’í, 236–237 Balinese, 155, 159–161 Chinese, 264–266 Christian, 70–71, 113–121, 325–326 Coptic, 76–77 Easter, 47, 70, 113–121, 325–326 Ethiopic, 77 Gregorian, 57–59 Hindu, xxiv, 303–312 Islamic, 86–87 Jewish, 101–105, 326, 331 Julian, 70–71 Korean, 271 Orthodox, 70–71, 121 Persian, 226 Tibetan, 319–322 Hoot, Charles, xxv Horæ temporales, see Hour, temporal Horizon geometric, 208 visible, 210 Hoshana Rabba (Jewish holiday), 92, 102 Hoskin, Michael A., 60 hour, 350, 365 Hour angle, 185 Hour, temporal (= seasonal), 92, 207, 211, 306 Howse, Derek, 214 hr, 350, 395 Huángdì (Chinese emperor), 263 Hube, Douglas P., 214

function type

Lisp code

Index Hungry Ghosts (Chinese holiday), 264 Husain, Muzhar, 86 I ‘¯Id-al-’Ad.h.a¯ (Islamic holiday), 87 ‘¯Id-al-Fit.r (Islamic holiday), 87 Ides, 65–67 ides, 65, 65, 68, 357, 374 ides-of-month, 66, 66, 68, 350, 374 if (Lisp function), 364 Ilyas, Mohammad, 87, 214 in-range?, 350, 365 Independence Day (U. S. holiday), 57 independence-day, 57, 57, 350, 371 India, see also Andhra Pradesh, Bengal, Bihar, Dharamsala, Haryana, Kashmir, Madhya Pradesh, Nadia, Rajasthan, Ujjain, and Uttar Pradesh, 6, 85, 122, 123, 128, 274, 275, 299, 328 Ingerman, Peter Zilahy, xxv International Astronomical Union (IAU), 172 International Organization for Standardization (ISO), 79 International Telecommunications Union, 175 Interpolation, 282–284, 298 interval, 350, 365 Inui, Shiho, xxv invert-angular, 350, 364 Iran, see also Isfahan, Khurasan, Shiraz, and Tehran, 236 Ise (Japan), 440 Isfahan (Iran), 219 Ishigami, Yoshiyasu, xxv Islamic calendar, 6, 7, 10, 11, 33–36, 83–87, 182, 217, 222, 275 days, 4, 13, 83, 84, 89 epoch, 15, 84 holidays, 86–87 implementation, 85–86 leap-year rule, 85 Lisp code, 377–378 months, 84 New Year, 86, 87, 263 observational, 11, 86, 328–329 sample dates, 441 structure, 83–85 week, 83–84 Islamic Shura Council of North America, 328 function definition

463

islamic-date, 350, 377 islamic-epoch, 84, 84, 85, 329, 357, 377 islamic-from-fixed, 85, 85, 86, 350, 378 islamic-in-gregorian, 86, 86, 87, 350, 378 islamic-leap-year?, 84, 84, 85, 350, 377 islamic-locale, 328, 328, 329, 357, 438 ISO calendar, 6, 11, 79–81 epoch, 15, 79 Lisp code, 376–377 sample dates, 441 iso-date, 350, 376 iso-day, 350, 377 iso-from-fixed, 80, 80, 350, 377 iso-long-year?, 81, 81, 350, 377 iso-week, 350, 376 iso-year, 350, 377 Israel, see also Cæsarea, Haifa, Mount Carmel, and Jerusalem, 93, 105, 228, 236, 237 Israel Independence Day, 104 Italy, see also Rome, 47 iyyar, 90, 90, 98, 104, 357, 378 J j2000, 179, 179, 185, 196, 197, 357, 397 Jacob ben Meir (= Rabbenu Tam), 212 Jacobi, Hermann G., 134, 290, 292, 312 Jacobson, Howard, xxv, xxvii, 10 J.A.D. (= julian astronomical day), 16 jaffa, 330, 330, 331, 357, 439 Jaffa (Israel), 330 Jal¯al¯ı calendar, 217 Janm¯asht.am¯ı, see Birthday of Krishna Janson, Svante, xxv, 315, 322 january, 48, 48, 50, 59, 65, 178, 191, 270, 357, 367 Japan, see also Ise and Tokyo, 5, 268 Japanese calendar, 268–269 age, 269 eras, 268 kigen, 268 Lisp code, 423 neng¯o, 268 japanese-location, 268, 268, 269, 350, 423 Jaritz, Gerhard, 46 JD (= julian day), 16 jd-epoch, 17, 17, 357, 362 jd-from-fixed, 18, 18, 350, 363 jd-from-moment, 17, 17, 18, 350, 363 jerusalem, 173, 173, 326, 357, 396

function type

Lisp code

464

Index

Jerusalem (Israel), 70, 92, 94, 96, 103, 172, 173, 177, 441, 446 Jesus’s Circumcision (Coptic holiday), 77 Jesus’s Transfiguration (Coptic holiday), 77 jewish-dusk, 211, 211, 350, 409 jewish-morning-end, 213, 213, 350, 410 jewish-sabbath-ends, 211, 211, 351, 409 Jiéqì (Chinese calendar), 248, 249 Jimmu Tenn¯o (Japanese Emperor), 269 Johnson, Samuel, xxvi Jones, William, 303 Joshi, Murli Manohar, 123 Jovian cycle (Hindu calendar), 125–126, 316 jovian-year, 126, 126, 351, 386 Julian astronomical day, see Julian day numbers Julian calendar, 6, 7, 9–11, 14, 33–36, 46, 48, 57, 63–71, 105, 217, 479 days, 13, 45 epoch, 15, 64 history, 46–47 holidays, 70–71 implementation, 63–65 leap-year rule, 63 Lisp code, 372–374 months, 45 revised, 47, 70 Roman nomenclature, 65–69 sample dates, 441 structure, 63 Julian century, 179, 184, 189 Julian day numbers, 9, 11, 15–17 modified, 11, 15, 17 sample dates, 441 julian-centuries, 179, 179, 183, 186, 189, 190, 192, 199, 203, 205, 351, 396 julian-date, 351, 372 julian-epoch, 64, 64, 358, 372 julian-from-fixed, 64, 64, 65, 69, 70, 351, 373 julian-in-gregorian, 70, 70, 71, 351, 373 julian-leap-year?, 63, 63–65, 68, 351, 372 julian-year-from-auc-year, 69, 69, 351, 373 Julius Cæsar, see Cæsar, Julius july, 48, 48, 57, 66, 84, 178, 264, 358, 368 june, 48, 48, 358, 368 Jupiter, 5, 124, 125, 199, 282 Justeson, John S., 150 K Kaiss, Daher, xxv function definition

kajeng-keliwon, 160, 160, 351, 394 Kajeng-Keliwon (Balinese holiday), 155, 160 Kak, Subhash, xxv K¯alacakra calendar, see Tibetan calendar Kalends, 65–67, 69, 70 kalends, 65, 65, 68, 69, 358, 374 Kaler, James B., 214 Kali Yuga (Hindu calendar), 15, 123, 124, 129, 284, 288, 289 Kamasan (Bali), 152 Kaneko, Hikotaro, 440 K¯ang X¯ı (Chinese emperor), 332 Kantor, Mattis, 92 Karaite calendar, 329 Karan.a Hindu, 309–312 Tibetan, 319, 320 karana, 309, 309, 310, 351, 434 Karthikai Deepam (Hindu holiday), 306 Kasher, Menahem M., 111 Kashmir (India), 277 Kazoe doshi (Japanese age), 269 kday-after, 29, 29, 58, 115–117, 325, 351, 367 kday-before, 29, 29, 58, 104, 351, 367 kday-nearest, 29, 29, 59, 351, 367 kday-on-or-after, 29, 29, 60, 312, 351, 367 kday-on-or-before, 27, 27, 29, 262, 351, 367 Keiper, Jerry B., 42 Kelly, Richard P., xxv Kepler, Johannes, xxv, 119, 170, 282 Khayyam, Omar, see Omar Khayyam Khinchin, Aleksandr Ya., 42 Khow¯arizm¯ı, Abu Ja‘far Mohammed ibn M¯us¯a al-, 89, 111 Khurasan (Persia), 216 Kielhorn, Franz, 312 Kigen (Japanese calendar), 268 Kinkelin, Hermann, 121 Kirchner, Claude, xxv kislev, 91, 91, 98, 107, 110, 358, 379 Klein, Hyman, 111, 331 Klotz, Irene, xx Knuth, Donald E., xxiv, 41, 47, 121, 361 Koolish, Richard M., xxv Koran, 83, 328 Korea, see also Go-Chosun and Seoul, 269 Korea Astronomy Observatory, 272 Korean calendar, 269–271 celestial stem names, 270 holidays, 271

function type

Lisp code

Index Lisp code, 423 solar terms, 270 terrestrial branch names, 270 korean-location, 269, 269, 351, 423 korean-year, 270, 270, 351, 423 Kratesis (Roman festival), 70 Kshaya month (Hindu calendar), see Month, expunged Kudlek, Manfred, 161 Kull-i-Shay (Bahá’í calendar), 231 Kuningan Day (Balinese holiday), 160 K.Y. (= Kali Yuga), 124 L Labor Day (U. S. holiday), 58 labor-day, 58, 58, 351, 371 Lagrenée, Jean-Jacques, the younger, 238 Lahiri, Nirmal C., 298 Lailat-al-Bar¯a’a (Islamic holiday), 87 Lailat-al-Kadr (Islamic holiday), 87 Lailat-al-Mi‘r¯aj (Islamic holiday), 87 Lalla, 126 Lamport, Leslie, 60 Langermann, Tzvi, 111 Lantern Festival (Chinese holiday), 264 last-day-of-hebrew-month, 98, 98–100, 351, 381 last-kday, 58, 58, 351, 371 last-month-of-hebrew-year, 91, 91, 99, 103, 106, 107, 351, 379 last-quarter, 202, 202, 358, 405 Lata, 275 Latitude celestial, 174, 187 terrestrial, 172, 174, 293 latitude, 351, 396 Laud (Christian prayer time), 213 Lcm function, see Least common multiple function Lê Thành Lân, 273 Leap days Gregorian, 49 Hindu, 278, 281, 289, 290, 303 Julian, 49, 64, 66 Tibetan, 316 Leap months, 7, 35 Chinese, 253–255, 257, 262, 263 Hebrew, 90, 91 Hindu, 123, 128–133, 277–279, 287, 289, 290, 303, 304, 306, 307 Tibetan, 316 function definition

465

Leap seconds, 177 Leap years, 7, 32–39 Coptic, 73, 74, 105 French Revolutionary, 240, 243 Gregorian, xx, 45, 49, 94, 275 Hebrew, 90–94, 97, 100, 103, 105–107, 109 Islamic, 84 Julian, 45, 49, 63, 64 Persian, 218, 223 Least common multiple function, xvi, 19 Jungmin Lee, xxv Leffler, Jonathan, xxv Leiden (The Netherlands), 162 Lent (Christian fast), 121 Lerner, Alon, xxv let* (Lisp construct), 363 Levi, Leo, 111, 214 Levin, Daniel Z., 214 L˘ı Yăn, 273 License, xxviii–xxix Lilius, Aloysius (= Luigi Lilio Ghiraldi), 45, 116 Line drawing, 32 Linnæus, see von Linne, Carl Lisp (computer language), xix, xxvi, 2, 42, 361–364, 382, 424, 439 list-range, 351, 365 Lists, 22–24 concatenation of (||), 22 construction of ( ), 22 element selection ( [ ] ), 22 empty, 22 Liú Bˇaolín, 247, 273 Liu, Chung Laung, 60, 273 Lo iddo rosh (Hebrew calendar rule), 92, 108, 109 local-from-apparent, 184, 184, 185, 208, 351, 397 local-from-standard, 177, 177, 351, 398 local-from-universal, 175, 175, 177, 326, 351, 398 location, 351, 396 Loewinger, Yaaqov, xxv London (England), 172, 182, 207 Long count (Mayan calendar), 138–139 Long Now Foundation, 324 long-marheshvan?, 98, 98, 107, 351, 380 Longitude celestial, 174, 186, 187, 276, 278, 282, 284, 286, 293 function type

Lisp code

466

Index

lunar, 198, 202, 283, 286, 309, 311, 446 sidereal, 186, 191–192 solar, 187–193, 195, 202, 234, 248–250, 286, 304, 311, 441, 446 terrestrial, 172, 174 longitude, 351, 396 losar, 321, 321, 351, 437 Losar (Tibetan holiday), 320–321 Lotus R 1-2-3 R , xxi Lounsbury, Floyd G., 138, 150 Lovering, Joseph, 239 Lozowski, Edward P., 214 Luang (Balinese calendar), 158 Lun, Anthony W.-C., 273 Lunar mansions, see Lunar stations Lunar stations, 216, 278, 309 lunar-altitude, 203, 203, 205–207, 326, 351, 406 lunar-anomaly, 199, 201, 201, 203, 205, 317, 351, 403 lunar-diameter, 328, 328, 351, 438 lunar-distance, 205, 205–207, 328, 351, 407 lunar-elongation, 199, 201, 201, 203, 205, 351, 403 lunar-latitude, 202, 202, 204, 205, 326, 351, 405 lunar-longitude, 199, 199–201, 204, 352, 404 lunar-parallax, 206, 206, 207, 352, 408 lunar-phase, 198, 201, 201, 202, 299, 301, 326, 327, 352, 405 lunar-phase-at-or-after, 202, 202, 326, 352, 405 lunar-phase-at-or-before, 202, 202, 352, 405 Lunation, see Month M McCarthy, Daniel P., 46 McCarthy, Dennis D., 214 Macler, Frédéric, 42 Madhya Pradesh (India), 277 Maha Shivaratri, see Great Night of Shiva Mahler, Eduard, 87 Maimonides, Moses (= Rambam), xix, xxvii, 89, 92, 95, 111, 212, 331 Main, Andrew, xxv major-solar-term-on-or-after, 250, 250, 352, 418 march, 48, 48, 51, 55, 57, 59, 65, 66, 68, 217, 231, 232, 236, 266, 270, 358, 367 function definition

Mardi Gras (Christian holiday), 119 marheshvan, 91, 91, 98, 107, 110, 358, 379 Marriage auguries (Chinese calendar), 267–268 Mars, 5, 124, 282 Marshack, Alexander, 42 Martial (= Marcus Valerius Martialis), 477 Martinez-Hernandez, Juan, 137, 138 Martyrdom of the B¯ab (Bahá’í holiday), 236, 237 Mary’s Announcement (Coptic holiday), 77 Mason, Charles W., 42 Matins (Christian prayer time), 213 Maundy Thursday (Christian holiday), 119 Mawlid an-Nab¯ı (Islamic holiday), 87 mawlid-an-nabi, 87, 87, 352, 378 MAX, xvi, 20, 99, 198, 318, 319, 364 may, 48, 48, 58, 66, 358, 368 Mayan calendar, xxii, 10, 11, 28, 29, 137–151 epoch, 15, 138 Goodman-Martinez-Thompson correlation, 137 haab, 139–142, 144–145, 147 Lisp code, 388–390 long count, 138–139 New Year, 136 round, 144–145, 149 sample dates, 441 Spinden’s correlation, 138 tzolkin, 5, 30–31, 142–145, 148 year bearer, 144, 149 mayan-baktun, 352, 388 mayan-calendar-round-on-or-after, 145 mayan-calendar-round-on-or-before, 145, 145, 352, 390 mayan-epoch, 138, 138–140, 142, 358, 388 mayan-haab-date, 352, 388 mayan-haab-day, 352, 389 mayan-haab-epoch, 140, 140–142, 145, 358, 389 mayan-haab-from-fixed, 140, 140, 144, 352, 389 mayan-haab-month, 352, 389 mayan-haab-on-or-before, 141, 141, 144, 352, 389 mayan-haab-ordinal, 140, 140, 141, 145, 352, 389 mayan-katun, 352, 388 mayan-kin, 352, 388 mayan-long-count-date, 352, 388

function type

Lisp code

Index mayan-long-count-from-fixed, 139, 139, 352, 388 mayan-tun, 352, 388 mayan-tzolkin-date, 352, 389 mayan-tzolkin-epoch, 142, 142, 144, 145, 358, 389 mayan-tzolkin-from-fixed, 142, 142, 144, 352, 389 mayan-tzolkin-name, 352, 389 mayan-tzolkin-number, 352, 389 mayan-tzolkin-on-or-before, 144, 144, 352, 390 mayan-tzolkin-ordinal, 142, 144, 144, 145, 352, 389 mayan-uinal, 352, 388 mayan-year-bearer-from-fixed, 144, 144, 352, 390 Mayr, Joachim, 87 mean-lunar-longitude, 199, 200, 200, 203, 352, 403 mean-sidereal-year, 187, 187, 300–302, 358, 399 mean-synodic-month, 193, 193, 196, 198, 201, 202, 258, 259, 327, 329, 358, 401 mean-tropical-year, 187, 187, 191, 193, 220, 235, 242, 259, 260, 358, 399 mecca, 173, 173, 358, 396 Mecca (Saudi Arabia), 173, 328 Medina (Saudi Arabia), 84 Medinet Habu (Egypt), 72 Meeus, Jean, 60, 121, 214 Meletios IV, 70 Melhado, Evan M., 240 member (Lisp relation), 361 Memoization, 40 Memorial Day (U. S. holiday), xxi, 58 memorial-day, 58, 58, 352, 371 Meng, Zhuo, xxv Mercury, 5, 124, 282 Meridian, 174, 185 lower, 182 upper, 182 Mesha sam . kr¯anti (Hindu Vernal equinox), see New Year, Hindu solar mesha-samkranti, 300, 304, 304, 352, 433 Meton, 7 Metonic cycle, 7, 91, 114, 116, 267 Metz (France), 479 Mexico, 137, 146, 479 Mexico City (Mexico), 146, 479 function definition

467

Michels, Agnes K., 41, 60, 71 Microsoft, 85 Office R , xxi Outlook R , xxi Windows R , xxi Mid-Autumn Festival (Chinese holiday), 264 midday, 185, 185, 213, 219, 352, 397 midday-in-tehran, 219, 219, 220, 352, 411 Midnight, 17, 45, 174, 182, 207, 213 civil, 247 true (= apparent), 4, 184, 241 midnight, 184, 184, 213, 241, 353, 397 midnight-in-china, 250, 251, 251, 252, 353, 419 midnight-in-paris, 241, 241, 353, 416 Midrash Tanh.uma, xxvii Milankovitch, Milutin, 47 Milbrath, Susan, 150 Milford-Lutzker, Mary-Ann, 152 MIN, xvi, xvii, 20–22, 100, 193, 198, 219, 234, 241, 251, 284, 287–289, 292, 301, 303, 307, 327, 364 M¯ına (Hindu month), 129, 133 minor-solar-term-on-or-after, 251, 251, 266, 353, 418 minute, 353, 365 Mitrophanow, Igor, 272 Mizner, Wilson, 42 MJD (= modified julian day), 17 mjd-epoch, 17, 17, 358, 363 mjd-from-fixed, 17, 17, 353, 363 mod (Lisp function), 363 Modified Julian day numbers, 17 sample dates, 441 Modulus function, xvi, 18 Mohammed, 82, 84 molad, 95, 95–97, 353, 379 Molad (Hebrew calendar), see also Moon, new, 92, 95–97, 109, 479 Moment, 10 moment-from-jd, 17, 17, 18, 353, 363 moment-of-depression, 209, 209, 210, 353, 408 monday, 27, 27, 58, 110, 358, 361 Mongolian calendar, 315 Montezuma II (= Moctezuma Xocoyotzin), 30 Month, 4, 6, 193–207 anomalistic, 195 Armenian, 26 Bahá’í, 230 function type

Lisp code

468

Index

bright fortnight, 129, 277 Chinese, 251–258, 262 Coptic, 73 dark fortnight, 129, 277 Ethiopic, 75 expunged, 277, 281, 287, 303, 306 French Revolutionary, 240 Gregorian, 45 Hebrew, 90 Islamic, 84 Korean, 270 leap, 7, 35, 91, 123, 129–133, 195, 253–255, 262, 263, 272, 287, 289, 303, 304, 306, 316 lunar, 7, 123, 124, 128, 129, 133, 247, 248, 252–255, 276–279, 281, 303, 315 Persian, 218 sidereal, 195, 276, 278, 283 solar, 126, 128, 129, 133, 195, 247, 253, 276, 277, 281, 292 synodic, 193, 195, 247, 276, 281 Tibetan, 315 Vietnamese, 272 Moon, 5, 6, 95, 174, 179, 187, 195, 283 blue, 195 first quarter, 202 full, 6, 113–115, 119, 195, 202, 305, 325 last quarter, 202 new, 6, 86, 91, 92, 95, 96, 114, 123, 128, 129, 137, 171, 193, 195–202, 247, 251, 253, 263, 277, 292, 305, 329 sample dates, 441 Paschal, 115 phase, 278 visibility, 326–328 moon-node, 199, 201, 201, 203, 205, 353, 403 Moore, George F., 449 Moreno-Ria˜no, Gerson, 46 Morley, Sylvanus G., 150 morning, 209, 209, 358, 409 Moshe ben Maimon, see Maimonides, Moses Mount Carmel (Israel), 228 Moyer, Gordon, 61, 121 mt, 353, 395 Mumm, Christine, xxv function definition

N Nabonassar (Chaldean king), 25 Nabonassar era, 25 Nadia (India), 303 N¯aga Pancham¯ı (Hindu holiday), 305 Nah.ala (Jewish event), 105–108 Nakayama, Shigeru, 273 Naks.atras, see also Lunar stations Hindu, 312 Tibetan, 319, 320 Nanjing (China), 247 Napoleon, see Bonaparte, Napoleon Napoleon III, see Bonaparte, Louis Napoleon NASA, xx Naser El-deen, Nabeel, xxv National Spiritual Assembly, 233 Native American calendar, 6, 239 Nativity of the Virgin Mary (Orthodox holiday), 71 Naw Ruz Bahá’í, 233, 236, 237 Persian, 123, 226, 237 naw-ruz, 226, 226, 353, 413 Needham, Joseph, 247, 273 Negative years, 12–14 Nemontemi (Aztec calendar), 146 Neng¯o (Japanese calendar), 268 Nepal, 314 Nepali calendar, 277 Neugebauer, Otto, 24, 42, 111, 331 Neumann, Peter G., xxvi new, 202, 202, 326, 358, 405 New moon, see Moon, new New Year Bahá’í, 234, 236, 237 Chinese, xxii, 248, 263–264, 266, 271, 332 Gregorian, xx, xxi, 47, 271 Hebrew, see Rosh ha-Shanah Hindu lunisolar, 133, 285, 305–306 Hindu solar, 126, 304, 305 Islamic, 86, 87, 263 Jewish, see Rosh ha-Shanah Korean, 271 Mayan, 136 Persian, see Naw Ruz Tibetan, see Losar New York City, xxi New Zealand, xxi new-moon-at-or-after, 198, 198, 251, 302, 353, 403

function type

Lisp code

Index new-moon-before, 198, 198, 252, 302, 353, 403 new-year, 39 Newton, Isaac, 293 next, 353, 364 Nián (Chinese calendar), 248 Nicæa, Council of, 113–114 Nievergelt, Jurg, 42, 61 nighttime-temporal-hour, 212, 212, 213, 353, 410 nil (Lisp constant), 361, 362 ninth (Lisp function), 361 nisan, 90, 90, 99, 102, 110, 331, 358, 378 Nisan (Hebrew month), 90, 331 Nishizawa, Y¯us¯o, 273 Nizamiah Observatory, 86 None (Christian prayer time), 213 Nones, 65–67 nones, 65, 65, 68, 358, 374 nones-of-month, 66, 66, 68, 353, 374 Noon, 14, 182, 213, 218, 237 true (= apparent), 184 North Pole, 186, 283 Norway, 360 Nothmann, Gerhard A., xxv november, 48, 48, 59, 358, 368 nth (Lisp function), 361 nth-kday, 58, 58, 59, 79, 80, 353, 371 nth-new-moon, 195, 195, 197, 198, 201, 202, 353, 401 Numa (= Numa Pompilius), 63 Nunavut (Canada), 211 Nutation, 187, 189 nutation, 189, 189, 199, 353, 398 Nyatri Tsenpo, 316 Nychthemeron, see Day Nyepi (Balinese holiday), 153 O O’Beirne, Thomas H., 119, 121 O’Malley, Michael, 214 Obermann, Julian, 111, 331 Obliquity, 182, 184, 186 obliquity, 184, 186, 186, 187, 353, 400 observational-hebrew-from-fixed, 330, 330, 353, 439 observational-hebrew-new-year, 330, 330, 331, 353, 439 observational-islamic-from-fixed, 329, 329, 353, 438 october, 48, 48, 66, 95, 358, 368 function definition

469

October Revolution, 47 old-hindu-lunar-date, 353, 386 old-hindu-lunar-day, 353, 387 old-hindu-lunar-from-fixed, 133, 133, 353, 387 old-hindu-lunar-leap, 353, 387 old-hindu-lunar-leap-year?, 131, 131, 353, 387 old-hindu-lunar-month, 353, 387 old-hindu-lunar-year, 353, 387 old-hindu-solar-from-fixed, 127, 127, 353, 386 Olson, Donald W., 214 Omar Khayyam, 217 omer, 102, 102, 354, 382 Omer (Jewish period), 102 Ore, Øystein, 42, 150 orthodox-easter, see also alt-orthodox-easter, 115, 115, 354, 385 Ottoman Empire, 83 P Pakistan, 328 Palaioemerologitai, 70 Palm Sunday (Christian holiday), 119 Panchang (Hindu calendar), 299, 312 Parallax, 205 paris, 241, 241, 358, 416 Paris (France), 174, 175, 238, 239, 241, 441, 446, 479 Paris Commune, 239 Parise, Frank, xxi, xxvi, 9, 42, 273 Parker, Richard A., 42 Pascal (computer language), 18 Pascal, Blaise, xxvi Passion Sunday (Christian holiday), 119 passover, 102, 102, 354, 382 Passover (Jewish holiday), xxi, xxii, 70, 89, 100–103, 113, 326, 331 Pasternak, Ofer, xxv Patashnik, Oren, 41 Pawukon (Balinese calendar), 153–161 Pedersen, Olaf, 60 Pengembang (Balinese holiday), 160 pentecost, 121, 121, 354, 386 Pentecost (Christian holiday), 119 Pepperdine, Andy, xxv Perigee, 195, 317 Perihelion, 263, 277 Persia, see Iran

function type

Lisp code

470

Index

Persian calendar, 6, 7, 9–11, 33, 217–227 arithmetic, 221–225 arithmetic leap year rule, 221–223 astronomical, 182, 187, 192, 193, 219–221 days, 13, 26, 218 epagomenæ, 26 epoch, 15, 217 holidays, 226 Lisp code, 411–413 months, 218 New Year, 226 sample dates, 441 structure, 217–222 week, 218 Persian Gulf, 236 persian-date, 354, 411 persian-epoch, 217, 217, 220, 223, 226, 358, 411 persian-from-fixed, 220, 220, 354, 411 persian-new-year-on-or-before, 219, 219, 220, 354, 411 Peters, Francis E., 447 Peters, Tom, xxv Peterson, Arthur E., 214 phasis-on-or-after, 327, 327, 330, 354, 437 phasis-on-or-before, 327, 327, 329–331, 354, 437 Philippines, 47 Phugpa calendar, see Tibetan calendar Phukluk calendar, see Tibetan calendar pi, 358 Pigeon-hole principle, 253 Pillai, Dewan Bahadur L. D. Swamikannu, 277, 287, 312 Pingree, David, 134, 312 Pirkei Avoth, 192 Pisces (constellation), 186, 276 Pleiades (star cluster), 6 Plutarch, 69 p.m. (= post meridiem), xv Polaris (star), 186 poly, 354, 364 poly (polynomial evaluation macro), 364 Pongal, see Ayyappa Jyothi Darshanam Poole, Robert, 61 Portugal, 47 Position, 172–174 positions-in-range, 160, 160, 354, 394 possible-hebrew-days, 109, 109, 110, 354, 384 function definition

Pozna´nski, Samuel A., 111 Precession, 185–186, 293 precession, 191, 191, 192, 300, 354, 401 Presentation of Christ in the Temple (Orthodox holiday), 71 Presentation of the Virgin Mary in the Temple (Orthodox holiday), 71 Pridie (= day before), 66 Prime (Christian prayer time), 213 Ptolemy (Claudius Ptolmæus), 25, 92, 282 Ptolemy III Euergetes, 76 Puckett, Barry, 42 Purewal, Pal Singh, xxv purim, 103, 103, 354, 382 Purim (Jewish holiday), 103 Purple Mountain Observatory (Nanjing), 247, 273 Q Qibla, 174 Q¯ıng dynasty, 207, 247 qing-ming, 266, 266, 354, 422 Q¯ıngmíng (Chinese solar term/holiday), 266 Qˇıqiˇao (Chinese holiday), 264 Q¯ıx¯ı (Chinese holiday), 264 Quadragesima, see Lent Quartodecimans, 113 Quiché, 140 Quinn, Terry J., 214 Quintus Curtius Rufus, 217 quotient, 354, 363 R Rabbenu Tam, see Jacob ben Meir radians-from-degrees, 354, 395 Rajasthan (India), 277 rama, 309, 309, 354, 434 R¯ama Navam¯ı, see Birthday of R¯ama Ramad¯an (Islamic fast), 87, 328 Ramasubramanian, K., xxv Rambam, see Maimonides, Moses Ramses III, 72 Rashi, see Solomon ben Isaac Rata Die, 10 R.D. (= Rata Die), 10 rd, 11, 11, 354, 362 rd (Lisp function), 363 Read, Kay, 145, 150 Recursion, 40 Reese, Ronald L., 42 Regulagedda, Akshay, xxv function type

Lisp code

Index Reingold, Deborah H., xxv Reingold, Edward M., iii, xxvi, 41, 42, 61, 214, 227, 312 Reingold, Eve M., xxv Reingold, Leah S., 471 Reingold, Rachel N., xxv Reingold, Ruth N., xxv Remainder function, see Modulus function Repose of the Virgin Mary (Orthodox holiday), 71 Resnikoff, Louis A., 111 rest (Lisp function), 361 Revat¯ı (star), 276, 279 Rhodes, Ida, xxvi Richards, Edward G., back cover, 42, 71 Richards, Nigel, xxv Rickey, V. Frederick, 61 Rieb, Jean-Pierre, 479 Right ascension, 174, 186 right-ascension, 186, 186, 205, 354, 401 Roegel, Denis B., xxv Rogation Sunday (Christian holiday), 119 Rolf, John C., xxvii Rolle, Theodore M., xxv Roman calendar days of the month, 65–69 ides, 65–66 kalends, 65–66 Lisp code, 374–375 nones, 65–66 pridie, 66 sample dates, 441 years, 69–70 Roman Republic, 5 roman-count, 354, 374 roman-date, 354, 374 roman-event, 354, 374 roman-from-fixed, 66, 68, 68, 354, 374 roman-leap, 354, 374 roman-month, 354, 374 roman-year, 354, 374 Rome (Italy), 46, 74 Romme, Gilbert, 242 Rosh ha-Shanah (Jewish holiday), xxi, 90–93, 98–102, 108 Rosh H.odesh (Jewish holiday), 104 Roth, Arthur J., xxv Roth, Cecil, 111, 447 round, 24 Round (Mayan calendar), 144–145, 149 Round function, xvi, 18 function definition

471

Routh, Martin, 168 Ruggles, Clive L. N., 80 Russia, 5, 47, 70 S Sa’adia Gaon, see Fayy¯umi, Sa’adia ben Joseph alSabbath (Jewish), 211 Sachau, C. Edward, 110, 123, 134 sacred-wednesdays, 311, 311, 354, 435 sacred-wednesdays-in-range, 311, 311, 312, 354, 435 Sagarin, Jeff, xxv Sahill˙ıoˇglu, Hal˙ıl, 83 ´ Saka Era (Hindu calendar), 288 Sakai, K¯o, xxv Salama, Ahmed, 331 Salvin, Osbert, 150 Sam . kr¯anti (Hindu calendar), 304 Samoa, 47 Sampson, Russell D., 214 Samuel, Alan E., 71 Samvatsara, see Jovian cycle Sansculottides (French Revolutionary calendar), 240 Sarasvat¯ı (Hindu deity), 306 Sarasvat¯ı Puja (Hindu holiday), 306 Satterwaite, Linton, 150 saturday, 27, 27, 103, 108, 110, 358, 362 Saturn, 5, 124, 282 Saturnalia (Roman festival), 70 Saudi Arabia, see Mecca and Medina, 328 Saunders, Robert A., xxv Savasorda, see Bargeloní, Abraham bar H.iyya alSavoie, Denis, 214 Saw, Swee-Hock, 273 Scaliger, Joseph Justus, xxii, xxvii, 0, 16, 62, 63, 90, 162, 448, 449 Scaliger, Julius Cæsar, 16 Schram, Robert G., 9, 42, 123, 135, 312 Schuh, Dieter, 322 ´ S.E. (= Saka Era), 288 Search, 20–22, 40, 364 bisection, 20–22, 287, 304, 328 linear, 20 Season, 191 sec, 354, 395 second (Lisp function), 361 Second Empire (France), 239 seconds, 354, 365 function type

Lisp code

472

Index

secs, 354, 396 Seidelmann, P. Kenneth, back cover, 41, 60, 71, 214, 215, 273 Sengupta, Prabodh C., 312 Seoul (Korea), 269 september, 48, 48, 58, 242, 358, 368 Septuagesima Sunday (Christian holiday), 119, 121 Serbia, 70 seventh (Lisp function), 361 Sewell, Robert, 134, 135, 277, 306, 312 Sexagesima Sunday (Christian holiday), 119, 121 Sext (Christian prayer time), 213 Sh’ela (Jewish event), 105 sh-ela, 105, 105, 354, 383 Shakespeare, William, 20, 27, 32, 65, 163, 325, 329 Shallit, Jeffery O., 61 Shanks, Thomas G., 214 Shˇanx¯ı (China), 246 Sharma, Shriramana, xxv Shaukat, S. Khalid, xxv, 326–328, 331 Shavuot (Jewish holiday), 70, 102 Shemini Az.eret (Jewish holiday), 102 Sherpa calendar, 315 shevat, 91, 91, 107, 110, 358, 379 shift-days, 109, 109, 354, 385 Shiraz (Persia), 228 shiva, 309, 309, 354, 434 Shiva (Hindu deity), 306 short-kislev?, 98, 98, 107, 354, 380 Shrove Monday (Christian holiday), 119, 121 Shrove Sunday (Christian holiday), 119, 121 Shrove Tuesday (Christian holiday), 119, 121 Shushan Purim (Jewish holiday), 103 sidereal-from-moment, 185, 185, 205, 354, 397 sidereal-solar-longitude, 192, 192, 299, 300, 302, 354, 401 sidereal-start, 192, 300, 300, 358, 430 sidereal-zodiac, 300, 300–302, 355, 430 sigma, 355, 364 sigma (summation macro), 364 Sign function, xvi, 18 Signum, 18 Simh.at Torah (Jewish holiday), 102 Simon, Jean-Louis, 214 sin-degrees, 355, 395 sine-offset, 208, 209, 209, 355, 408 Singer, Isaac Bashevis, 325 function definition

Singer, Isidore, 111, 447 Sinnott, Roger W., 214 Sirius (star), 6 Sivakumar, G., xxv sivan, 90, 90, 358, 378 Sıvıs¸ year (Ottoman Empire), 83 sixth (Lisp function), 361 Skeel, Robert D., 42 Skiena, Steven S., xxv Slonimski, H.ayyim S., 111 Sobel, Dava, 215 Sodhya (Hindu calendar), 285 Sohn, Sangmo, 269 Solar cycle, 105 Solar terms Chinese calendar, 239, 248–251 Japanese pronunciation, 248 Korean calendar, 270 solar-anomaly, 199, 201, 201, 203, 205, 355, 403 solar-longitude, 189, 189–193, 201, 209, 213, 219, 234, 241, 248, 250, 251, 299, 355, 399 solar-longitude-after, 190, 190, 191, 250, 325, 330, 355, 400 Solomon ben Isaac (= Rashi), 185 Solstice, 6, 21, 163, 171, 187, 190, 191, 441 sample dates, 441 winter, 247, 251, 304 Sornes, Rasmus, 360 Sosigenes, 46 Soviet Union, 47 Sowramana Ugadi, see New Year, Hindu solar Spain, 47 Spectrum (of a real number), 36 Spica (star), 276 Spier, Arthur, 111 Spinden, Herbert J., 137, 138, 150, 151 spring, 191, 191, 219, 220, 234, 325, 330, 358, 400 Spuler, Bertold, 87 Stallman, Richard M., xxvi, 42 standard-day, 355, 364, 365 standard-from-local, 177, 177, 184, 185, 209, 210, 355, 398 standard-from-sundial, 212, 212, 213, 296, 308, 355, 410 standard-from-universal, 177, 177, 191, 250–252, 355, 398 standard-month, 355, 364, 364 function type

Lisp code

Index standard-year, 355, 364, 365 Stanhope, Philip D. (= Fourth Earl of Chesterfield), xxiv, 171 start, 355, 365 Stavroulakis, Nicholas, 336 Steel, Duncan, 42 Steele, Guy L., Jr., xxvi, 42, 439 Stein, Michael R., xxv Stendhal, see Beyle, Marie-Henri Stephenson, F. Richard, 215, 273 Stern, Sacha, 89, 111 Stewart, Ian, back cover Stillingfleet, Benjamin, 240 Stolz, Otto, xxv Suddha, see Month, bright fortnight Suì (Chinese calendar), 252 Sukkot (Jewish holiday), 70, 102 Sullivan, Arthur, 45 sum, 355, 363 sum (summation macro),  363, 364 Summation operator ( ), xvi, 20, 40 summer, 191, 191, 358, 400 Sun, 4, 5, 95, 174, 179, 185–187 Sun Yat-sen, 263 sunday, 27, 27, 59, 80, 103, 104, 108–110, 115–117, 325, 358, 361 Sunrise, 4, 12, 124, 126–129, 134, 138, 182, 207–213, 217, 276, 278, 292–295, 298, 305, 309 Hindu, 292–295 sample dates, 441 sunrise, 210, 210, 212, 355, 409 Sunset, 4, 12, 73, 83, 84, 87, 89, 182, 207–213, 229, 233, 237, 441 sample dates, 441 sunset, 210, 210–212, 234, 330, 355, 409 sunset-in-haifa, 234, 234, 355, 415 S¯urya-Siddh¯anta (present), 275, 276, 282, 284, 285, 293, 295, 298, 299, 306, 312 Sweden, 44, 47, 79, 119 Switzerland, 47 T t (Lisp constant), 361 Ta’anit Esther (Jewish fast), 103 ta-anit-esther, 103, 103, 355, 382 Taiwan, 16 Talmud Babylonian, 9, 163, 207 Jerusalem, 101 function definition

473

Tamerlane (Mongol conqueror), 14 tammuz, 90, 90, 98, 358, 378 Táng (Chinese dynasty), 246 tangent-degrees, 355, 395 Tantzen, Robert G., 61 Taqizdeh, Seyyid H., 218, 219, 227 Tarvainen, Tapani, 47 Tasmania, xxi tehran, 219, 219, 358, 411 Tehran (Iran), 192, 219, 233, 236 tenth (Lisp function), 361 Terce (Christian prayer time), 213 Teresi, Dick, 46 tevet, 91, 91, 98, 107, 110, 358, 379 Thanksgiving Day Korean holiday, 271 U. S. holiday, xxi, 27 Thebes (Egypt), 72 third (Lisp function), 361 Thompson, J. Eric S., 136–138, 151 Thompson, Sue E., 42 thursday, 27, 27, 81, 104, 108, 110, 358, 362 Tibetan calendar, 6, 10, 12, 315–322 animal totems, 314, 316 epoch, 15, 316 expunged day, 316 holidays, 319–322 karan.as, 319, 320 leap day, 316 leap month, 316 Lisp code, 435–437 months, 315 naks.atras, 319, 320 sample dates, 441 weekdays, 316 yogas, 319 tibetan-date, 355, 435 tibetan-day, 355, 435 tibetan-epoch, 316, 316–318, 358, 435 tibetan-from-fixed, 318, 318, 321, 355, 436 tibetan-leap-day, 355, 435 tibetan-leap-month, 355, 435 tibetan-leap-month?, 321, 321, 355, 437 tibetan-month, 355, 435 tibetan-moon-equation, 317, 317, 318, 355, 436 tibetan-new-year, 321, 321, 355, 437 tibetan-sun-equation, 317, 317, 318, 355, 435 tibetan-year, 355, 435 Tika (Balinese calendar), 157, 158 function type

Lisp code

474

Index

Tikal (Guatemala), 144 Time, 174–179 apparent, 184 durations, 23–24 Dynamical, 174, 177–179 ephemeris, 174 intervals, 22–23 leap seconds, 175 local mean, 175, 177, 184 sidereal, 174, 185 actual, 187 mean, 187 solar, 174–175, 177 apparent, 182 mean, 182 standard, 175, 177 terrestrial, see Time, Dynamical Universal, 174–175, 177 zones, 175–177 time-from-clock, 23, 23, 355, 365 time-from-moment, 18, 18, 23, 211, 355, 365 time-of-day, 355, 365 Tishah be-Av (Jewish fast), 92, 101, 103 tishah-be-av, 103, 103, 355, 382 tishri, 91, 91, 95, 97, 99, 101, 331, 358, 379 Tishri (Hebrew month), 90–92, 95, 96, 98–103 Tithi (Hindu calendar), 129, 278, 290, 292, 306, 312 Titus Vespasianus, 92 Toe-Wang-Yong-Sa (Korean calendar), 271 Tokyo (Japan), 268 Tonalpohualli (Aztec calendar), 145, 148–149 Tondering, Claus, xxv topocentric-lunar-altitude, 207, 207, 328, 355, 408 Trajan (= Marcus Ulpius Traianus), 101 Trần Đức Ngọc, xxv Trần Tiến Bình, 273 Transfiguration (Orthodox holiday), 71 Trepidation, 293 Trinity Sunday (Christian holiday), 121 Troesch, Albert, 42 true, 66, 208, 359, 362 Tseng, Karen, xxiii Tsuchihashi, Paul Y., 273 Tsurphu calendar, 315 Tsybulsky, Vladimir V., 87 Tu-B’Shevat (Jewish holiday), 103, 110 function definition

tuesday, 27, 27, 59, 108, 110, 359, 361 tumpek, 160, 160, 355, 394 Tumpek (Balinese holiday), 155, 160 Tumpek Kandang (Balinese holiday), 160 Tumpek Krulut (Balinese holiday), 160 Tumpek Kuningan (Balinese holiday), 160 Tumpek Landep (Balinese holiday), 160 Tumpek Ringgit (Balinese holiday), 160 Tumpek Uduh (Balinese holiday), 160 Tun, Li-Ch’en, 273 Turkey, 47 Turning of the Wheel of Dharma (Buddhist holiday), 322 Twilight, 212 Tykocinski, Jehiel M., 212 Type declarations, 337–359, 362 Tzolkin (Mayan calendar), 30–31, 142–145, 148 Tzom Gedaliah (Jewish fast), 103 Tzom Tammuz (Jewish fast), 103 Tzom Tevet (Jewish fast), 103, 104 U Uayeb (Mayan calendar), 139, 140 Uchida, Masao, 273 ujjain, 292, 292, 295, 296, 308, 359, 429 Ujjain (India), 292, 295, 300 Ulisano, Benita, xxv Ulugh Beg, 14, 85 ‘Umar, Caliph, 84 Underhill, Muriel M., 313 United States of America, see also Alaska, Hawaii, New York, and Urbana, 27, 47, 59, 121, 175, 328 Naval Observatory, xxii Universal House of Justice, 233 universal-from-dynamical, 179, 179, 195, 356, 399 universal-from-local, 175, 175, 177, 184, 209, 300, 356, 398 universal-from-standard, 177, 177, 213, 219, 234, 241, 248, 250, 251, 326, 330, 356, 398 Unix, xxii unlucky-fridays-in-range, 60, 60, 356, 372 urbana, 172, 172, 191, 211 Urbana (Illinois), 0, 170, 172, 174, 191, 211, 448 urbana-sunset, 211, 211 urbana-winter, 191, 191 Urip (Balinese calendar), 157 function type

Lisp code

Index Uspensky, James V., 61, 121 Uttar Pradesh (India), 277 V V¯ah.id (Bahá’í calendar), 230 Vaikunta Ekadashi (Hindu holiday), 306 Vai´sa¯ kha (Hindu month), 278, 306, 321 van Dalen, Benno, 87, 227 van der Waerden, Bartel L., 42 van Flandern, Thomas C., 60 van Gent, Robert H., xxv, 119, 180, 181, 188, 194 van Vlijmen, Oscar, xxv van Wijk, Walther E., 124, 126, 128, 135, 275, 292, 299, 313 Varalakshmi Vratam (Hindu holiday), 306 V¯ar¯an¯asi (= Banaras) (India), 303 Varro (= Marcus Terentius Varro), 46 Vatican Council, Second, 121 V.E. (= Vikrama Era), 290 Vedic months, 239 Vega (star), 186 Venus, 5, 124, 199, 282 Verne, Jules, 172 Vesper (Christian prayer time), 213 Victorian cycle, 115 Vietnamese calendar, 271–272 celestial stem names, 272 Lisp code, 423 months, 272 terrestrial branch names, 272 vietnamese-location, 271, 271, 356, 423 Vikrama Era (Hindu calendar), 289 Vilhjálmsson, Porsteinn, 80 Vilna Gaon, see Eliyahu ben Shlomo Zalman Vishnu (Hindu deity), 306 visible-crescent, 326, 326, 327, 356, 438 Vollers, Karl, 326 Voltaire, see Arouet, Franc¸ois Marie von Dechend, Hertha, 258 von Lieven, Carl Christoph, 52 von Linne, Carl, 239 W W¨ustenfeld, Ferdinand, 87 Wada, Eiiti, xxv Wallis, Faith, 46 Wallis, John, 116 Warnings, 39–41 Wassef, Cérès W., 77 Wauchope, Robert, 150 function definition

475

Waupotitsch, Roman, xxv wednesday, 27, 27, 104, 109, 110, 312, 359, 362 Week, 4–5 Hebrew, 89 Islamic, 83–84 Persian, 218 Weekdays Armenian, 5 Bahá’í, 229 Coptic, 74 Ethiopic, 75 Hebrew, 89 Hindu, 124 Islamic, 83, 84 Persian, 218 sample dates, 441 Tibetan, 316 Welch, Windon C., 273 Whitmundy (Christian holiday), 119 Whitney, William D., 312 Whitsunday (Christian holiday), 119 Widiarki, Ni Made, 152 Wiesenberg, Ephraim J., 111, 331 Wildmann, Helmut, xxv Wilhelm, Robert, 479 Willey, Gordon R., 150 winter, 191, 191, 251, 359, 400 Woodworth, Joyce, xxv Woolhouse, Wesley S. B., 41, 87 World Council of Churches, 119, 121, 325, 331 World Wide Web, xxiv, 2, 361 Wynn, Peter, 42 X X¯ıa¯ n (China), 246 Xihuitl (Aztec calendar), 145–147 Xiuhmolpilli (Aztec calendar), 149 Xú X¯ıqí, 247, 273 Y Y10K problem, 39 Y2K problem, xx Yadav, Bhuri S., 312 yahrzeit, 107, 107, 108, 356, 383 Yahrzeit (Jewish event), 105–108 yahrzeit-in-gregorian, 108, 108, 356, 384 Yallop, Bernard D., 215 Yáng Gu¯angxi¯an, 248 Yaqob, Daniel, xxv

function type

Lisp code

476

Index

Yarshater, Ehsan, 227 Year, 4, 6–9, 185–236 A.U.C., 69–70 embolismic (Hebrew calendar), 90 equinoctial, 222, 226 gravid (Hebrew calendar), 90 Gregorian calendar, 47–48 Hebrew sabbatical, 91 leap, 7, 32–39, 45, 49, 63, 64, 73, 74, 90–94, 97, 100, 103, 105–107, 109, 218, 223, 240, 243, 275 negative, 12–14 Roman, 69–70 sıvıs¸ (Ottoman Empire), 83 sabbatical (Hebrew calendar), 91 sidereal, 125, 187, 276, 284 solar, 7, 146, 195, 241 tropical, 46, 105, 140, 187, 195, 247 Year bearer (Mayan calendar), 144, 149 year-rome-founded, 69, 69, 70, 359, 373 Yoga Hindu, 311–312 Tibetan, 319 yoga, 311, 311, 356, 435

Yoh.anan ben Zakkai, 70 Yom ha-Shoah (Holocaust Memorial Day), 104 Yom ha-Zikkaron (Israel Memorial Day), 104 Yom Kippur (Jewish holiday), 92, 101, 103 yom-ha-zikkaron, 104, 104, 356, 383 yom-kippur, 101, 101, 356, 382 Yucatan (Mexico), 137, 140 Z Zarineba, Fariba, xxv Zeller’s congruence, 53, 56–57 Zeller, J. Christian J., 56–57, 61 Zh¯ongqì (Chinese calendar), 248, 249 Zodiac, 6, 88, 123, 126, 127, 130, 186, 195, 248, 274, 276–278, 280, 286, 287, 305 Zomorodian, Afra, xxv zone, 356, 396 zone-from-longitude, 175, 175, 295, 356, 398 Zoroastrian calendar, 26, 217 epoch, 15

The covers of this book are too far apart. —Attributed to Ambrose Bierce function definition

function type

Lisp code

Envoi Ohe, iam satis est, ohe, libelle, Iam pervenimus usque ad umbilicos. Tu procedere adhuc et ire quæris, Nec summa potes in schida teneri, Sic tamquam tibi res peracta non sit, Quae prima quoque pagina peracta est. Iam lector queriturque deficitque, Iam librarius hoc et ipse dicit “Ohe, iam satis est, ohe, libelle.” Martial: Epigrams, IV, 89 (circa 90 C.E.)

477

478

About the Cover

Main image: Photograph of gears from the astronomical clock at the Notre-Dame cathedral of Strasbourg. (Courtesy of Éditions Ronald Hirlé, from Les trois horloges astronomiques de la cathedrale de Strasbourg, by Henri Bach and Jean-Pierre Rieb with collaboration by Robert Wilhelm.) Middle left insert: Movable dials of numbers for computing the Julian season of the Hebrew lunar months for the years 1579–1751. From an autograph of Sefer HaEvronot (1703) by Nathan ben Meir Hademer of Metz. (Courtesy of Bibliothèque National de France, Paris.) The dials are used as follows: To determine the Julian season, add the numbers on each of the three circles (for Metonic cycle number, year within cycle, and season within year) to find how long after the molad of the month the Julian season begins. That is why each ordinary year (for example) contributes 10 days, 21 hours, and 204 parts, the excess of solar over lunar, using the Julian solar year length and 12 mean lunations. The manuscript has other dials for other calculations. Lower right insert: The so-called “Aztec calendar stone,” more properly called “La Piedra del Sol” or “Sun Stone,” showing the 20 day signs of the Aztec calendar calendar. It is made of basalt, is over 11 feet in diameter, weighs 25 tons, and was used as a sacrificial altar to hold human hearts that the Aztecs believed nourished the sun. The stone, discovered in Mexico City in 1790, is the unofficial emblem of Mexico. Cover design by James F. Brisson

479