I am very excited to announce that I’ve published the first executable Road to Reality essay! I open with a promise that you may find familiar:
Over the course of this essay series, you are going to build a workshop full of the tools required to create and explore simulated worlds that behave like our most advanced models of reality.
In contrast to the newsletter, this essay is full of strong computational medicine. I’ve got an embedded 3D physics simulation showing off geodesics of the torus; code, math, and interactive 2D plots, generated from high-level code that I typed into a Markdown file, barely breaking away from prose to do it.
Crucially, you can read these essays in the same environment that I used to write them. Follow these instructions and open up the introduction.md
file in your text editor, and any change you make will show up immediately in the Clerk-rendered version of the essay at http://localhost:7777.
Here’s a video of me playing around with the system while writing.
Because each essay lives in a Clojure source code file, essays can pull in code defined in other essays and build on top, and a whole tree of literate, interactive work can grow out of these initial attempts.
The ability to publish, play and use modern browser technologies to render everything is wild.
The essays live at the Road to Reality GitHub repository. See https://reality.mentat.org for the project’s index and links to a few extra pages like “Tools” and “FAQ”.
Breakthrough
Up until a week ago I didn’t know if any of this was going to work. I gave a talk at the annual Clojure conference (Clojure/Conj 2023) at the end of April, titled “Emmy: Moldable Physics and Lispy Microworlds”, and showed off demos like these:
The dirty secret of these demos is that it was very difficult to write each interactive scene. I had no way to build up the scenes as a composition of pieces. You want to start with a blank canvas, then add a particle, then make it stick to the donut… this did not work.
The other issue was that everything interesting involves sending a function over from my computer to the browser, where I can use it to animate a physics demo or pass it to the plotter to draw a graph. The way I did this for the demos worked well, but was unacceptably difficult. No one else would never be able to do it.
Martin Kavalar and I cracked this problem open last week, using a trick Martin suggested that uses Emmy to create fragments of code and serialize functions over to the browser. I’ll write up the trick at some point, but only the upshot matters. I can now write out a form like this in my Clojure file:
(plot/mafs
(plot/cartesian)
(plot/of-y sin {:color :blue})
(plot/of-x tanh {:color :green})
(plot/of-x ((square D) tanh) {:color :violet}))
and Clerk will slurp it up and render it as this:
Duh, you might say. How else would it work?
Ah! I would reply. You’re right. But notice the ((square D) tanh)
on the final line. We’re doing calculus here, and Emmy is compiling that function down into this fast JavaScript function before passing it to the browser:
(js/Function.
"y0001"
"
const _0002 = Math.sinh(y0001);
const _0003 = Math.cosh(y0001);
return (2.0 * Math.pow(_0002, 3.0) - 2.0 * _0002 * Math.pow(_0003, 2.0)) / Math.pow(_0003, 3.0);")
This is totally transparent to the writer, and probably faster than anything you’d write by hand.
Using Emmy for these little surgical strikes of compilation means that we can build faster-than-handwritten-JavaScript by writing code that looks like it must be slow, but actually makes sense. See this notebook exploring (p, q) torus knots for an example of high-level code paired with speed. I haven’t converted the scene description to this new style yet, but that’s coming.
Clojure/Conj 2023
I had a wonderful time in Durham meeting old friends from the Clojure community. There’s so much good energy, the talks were wonderful, and I think I managed to get at least a few people excited about making art with Emmy.
Here is a video of my talk from the conference:
In the next update, I’ll write about my visit to MIT, meeting Colin Smith and Gerald Jay Sussman in person for the first time and sharing a cup of tea I’ve been waiting on for years, and the possibility of a bigger future for this executable textbook project than I had hoped.
For now, please enjoy this first executable essay. I hope you’ll try out the exercises; if you run into trouble, or if you get everything working smoothly, please send me a note to let me know how it went.