Liking cljdoc? Tell your friends :D

Introduction to SICMUtils

sicmutils

A Clojure(script) implementation of the Scmutils system for math and physics investigations in the Clojure language.

Scmutils is extensively used in the textbooks The Structure and Interpretation of Classical Mechanics and Functional Differential Geometry by G.J. Sussman and J. Wisdom.

Need help getting started? Say hi on Twitter or Clojurians Slack in #sicmutils.

Build Status Codecov branch cljdoc badge Clojars Project

Quickstart

Install SICMUtils into your Clojure(script) project using the instructions at its Clojars page:

Clojars Project

Initialize a REPL and simplify a trigonometric identity:

user=> (require '[sicmutils.env :as env])
user=> (env/bootstrap-repl!)
user=> (def render (comp ->infix simplify))
user=> (render
        (+ (square (sin 'x))
           (square (cos 'x))))
1

Define a Lagrangian and generate the Lagrange equations of motion for the physical system it describes, rendered in polar coordinates:

(defn L-central-polar [m U]
  (fn [[_ [r] [rdot φdot]]]
    (- (* 1/2 m
          (+ (square rdot)
             (square (* r φdot))))
       (U r))))
#'user/L-central-polar

user=>
(let [potential-fn (literal-function 'U)
      L     (L-central-polar 'm potential-fn)
      state (up (literal-function 'r)
                (literal-function 'φ))]
  (render
   (((Lagrange-equations L) state) 't)))
"down(- m (Dφ(t))² r(t) + m D²r(t) + DU(r(t)), 2 m Dφ(t) r(t) Dr(t) + m (r(t))² D²φ(t))"

Confused? You’re not alone! This is a very dense library, and not well documented (yet). Some suggested next steps, for now:

Background

SICM and FDG can be thought of as spiritual successors to The Structure and Interpretation of Computer Programs, a very influential text—as I can attest, since carefully reading this book in my 30s changed my life as a programmer. To see the same techniques applied to differential geometry and physics is an irresistible lure.

Scmutils is an excellent system, but it is written in an older variant of LISP (Scheme) and is tied to a particular implementation of Scheme—MIT/GNU Scheme. (There is a port to Guile, but due to the fact that Guile does not support MIT Scheme’s apply hooks some glue code is required to run examples from the book in that environment.)

Having the system in Clojure offers a number of advantages. It is not necessary to obtain or prepare a MIT/GNU Scheme executable to execute: only a Java runtime is required. It does not require the X Window System for graphics, as MIT Scheme does. All of the standard tooling for Java and Clojure become available, and this is a lot compared to what we get with MIT/GNU scheme. Clojure support is now extensive in any number of editors and IDEs. Even better, you can interact with the system in the context of a Jupyter notebook.

You can invoke the system from within Java or JS code, or use any Java or JS packages you like together with the mathematics system. It’s my hope that continuing this project will extend the reach of SICM and FDG by allowing experimentation and collaboration with them in modern environments.

Next Steps

Please explore the documentation, and send us (@sritchie, @colins) in particular a note in the #sicmutils channel on Clojurians slack if you’d like to talk or have any questions at all!

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close