Anyone who's seen my You Used Python For What? talk knows that I often try to implement stuff in Python to better understand it.
I've often found that writing implementation for computer often forces a greater understanding of concepts in part because you have to be so explicit.
Gerry Sussman wrote:
It is surprisingly easy to get the right answer with unclear and informal symbol manipulation. To address this problem we use computer programs to communicate a precise understanding of the computations... Expressing the methods ... in a computer language forces them to be unambiguous and computationally effective. The task of formulating a method as a computer-executable program and debugging that program is a powerful exercise in the learning process.
(elided to make the general point)
One example from physics is my little attempt at quantum computing in Python: quantumpy.
Back in 2005, I bought Sussman's Structure and Interpretation of Classical Mechanics (SICM) which is an extensive exploration of Lagrangian and Hamiltonian classical mechanics using Scheme.
Recently I found out Sussman had been working on doing the same for General Relativity. I eagerly awaited Functional Differential Geometry, co-authored, like SICM, by Jack Wisdom. My copy arrived early August (although versions had been available online for a while).
I decided to try implementing the same ideas myself in Python starting with some of the foundational mathematical stuff in Appendix B.
The initial work is available at https://github.com/jtauber/functional-differential-geometry.
The first thing I tackled what was Sussman and Wisdom call "tuples".
Their tuples come in two varieties, up and down. These basically correspond to contravariant and covariant vectors in differential geometry except that they are recursive (a component of a vector may be another vector).
A literate doctest explaining how the tuples
modules works is at https://github.com/jtauber/functional-differential-geometry/blob/master/tuples.rst
As I mention in the README, the tuples module (or at least up tuples) are how I wish tuples worked in Python.
Next up was an implementation of functions such that you can do things like take f(x)
and g(x)
and do f+g
such that (f+g)(x) == f(x) + g(x)
.
See the functions
module literate doctest at https://github.com/jtauber/functional-differential-geometry/blob/master/functions.rst.
There is also a compose
function there that I guess could be associated with an operator if I could think of a binary operator that wouldn't otherwise make sense to apply to the results of two functions.