This is a translation to Python and Sagemath of (most of) the Scheme code of the book `Structure and interpretation of classical mechanics’ by Sussman and Wisdom. When referring to the book, I mean their book. I expect the reader to read the related parts of the book, and use the Python code to understand the Scheme code of the book (and vice versa). I therefore don’t explain much of the logic of the code in this document. I’ll try to stick to the naming of functions and variables as used in the book. I also try to keep the functional programming approach of the book; consequently, I don’t strive to the most pythonic code possible. To keep the code clean, I never protect functions against stupid input; realize that this is research project, the aim is not to produce a fool-proof software product.
- The file
sicm_sagemath.pdf
shows all code samples together with the output when running the code. - The directory
org
contains the org files. - The directory
sage
contains all sage files obtained from tangling the org files.
In the pdf file I tend to place explanations, comments, and observations about the code and the results above the code blocks.
I wrote this document in Emacs and Org mode.
When developing, I first made a sage file with all code for a specific section of the book.
Once everything worked, I copied the code to an Org file and make code blocks.
Then I tangled, for instance, generally useful code of section1.4.org
to utils1.4.sage
and code specific for Section 1.4 to section1.4.sage
.
A util
file does not contain code that will be executed when loading the util
file.
This way I can load the utils files at later stages, and by runnning, for instance sage section1.4.sage
I can test all functionality offered by the `module’ utils1.4.sage
.
I found it convenient to test things in a tests.sage
file.
I can edit tests.sage
within Emacs and see the consequences directly in the sage session by opening a sage session on the command prompt and attaching the session to the file like so:
sage: attach("tests.sage")
Finally, here are some resources that were helpful to me:
- An online version of the book: https://tgvaughan.github.io/sicm/
- An org file of the book with Scheme: https://github.com/mentat-collective/sicm-book/blob/main/org/chapter001.org
- A port to Clojure: https://github.com/sicmutils/sicmutils
- The Sagemath reference guide: https://doc.sagemath.org/html/en/reference/
- Handy tuples: https://github.com/jtauber/functional-differential-geometry
- ChatGPT proved to be a great help in the process of becoming familiar with Scheme and Sagemath.
- Some solutions to problems: https://github.com/hnarayanan/sicm