Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork15
Exercises and notes on Structure and Interpretation of Classical Mechanics.
License
perceptual-ai/sicm-scheme-exercises
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Welcome to my solution and notes repository for Sussman and Wisdom'sTheStructure and Interpretation of Classical Mechanics.You can get a copy of the book onAmazon, or followalong using this beautifulHTML version.
I'm working through the exercises for each chapter usingMITScheme, and thescmutils library(also calledmechanics by the authors and me) that Sussman and Wisdomdeveloped for the textbook.
Each chapter gets its own folder, namedch1,ch2, etc. Inside each folderI've included a file for each exercise that required code or benefited fromexploration in Scheme.
I've also worked hard to make sure that it's easy foryou to run any of thiscode, and recreate my work in any of the exercises. I've provided a working copyof themechanics library in this repository inbin/mechanics. There's asmall amount of work you'll have to do to make the script run, but I've coveredthat below under"Running the Code".
If you like this sort of thing, you might also consider subscribing to"TheRoad to Reality", a newsletter where Ipost primers and lessons on interesting topics in math, physics, machinelearning or artificial intelligence, with a heavy emphasis on locking down theintuition behind the ideas over mere symbol shuffling.
Check it out here:https://roadtoreality.substack.com
- Thecourse website forMIT's 6.946,"Classical Mechanics: A ComputationalApproach". This is agraduate level course in classical mechanics that uses this textbook. Thecourse page has excellent materials, links to errata, all the goods.
- Errata for the 2nd edition ofSICM. I've foundsome more, which I'll add to this page as I go.
- The SICM Textbook on Amazon
- Beautiful HTML version of the SICMTextbook. You have to read this!
- MIT OpenCourseware page for the Fall 2008 version of thecourse.This uses the first edition of the textbook. I haven't gone through this pagein any detail.
- Documentation for
scmutils, akamechanics - SICMUtils a Clojureimplementation of the
scmutils/mechanicslibrary. Clojure is brilliant.I may include some examples of code using this library as I go. - My Dockerhub pages for the
mit-schemeandmechanicsDocker images.
You can interact with any of the utilities or solutions I've written using thebin/mechanics program in this repository.bin/mechanics holds a full,working installation ofmechanics and MIT Scheme, packaged up inside of aDocker container. To make this work, you'll need, at minimum, a workinginstallation ofDocker.
If you want to see graphics (which of course you do!), you'll need an X11 windowsystem installed. For LaTeX rendering, you'll need thexdvi program, whichcomes with installations ofLaTeX.
If you're on a Mac, installDocker Desktop forMac byclicking the "Get Docker" button on the right side of that page.
XQuartz will cover the X11 requirement. Download thefilehere and install it in the usual way.
Finally, installMacTeX andafterward make sure that typingxdvi at the terminal makes something happen.
Once you have XQuartz and MacTeX installed, you'll need to configure it to letbin/mechanics make graphics on your computer from inside the Docker containerwhere it runs. To set this up,
- launch XQuartz from
/Applications/Utilities/Xquartz, - go into the Preferences menu and navigate to the Security tab
- make sure that both "Authenticate Connections" and "Allow connections fromnetwork clients** is checked
This page has a nice guide onhow to get Docker installed on Linux. I think the X11 requirement might justwork? If you try this, please let me know, or send a PR updating this README.
TheLaTeX Project main page describes howto get LaTeX on Linux. They recommend installing theTeXLive distribution.
Once you have Docker installed and running, clone this repository onto your machine,navigate into the folder and runbin/mechanics:
git clone https://github.com/sritchie/sicm.git && cd sicmbin/mechanicsThe first time you run this it should take a while, as you'll have to downloadall of the Docker image requirements. Eventually you'll see an MIT Scheme REPLwith the wholemechanics library loaded:
127.0.0.1 being added to access control listMIT/GNU Scheme running under GNU/LinuxType `^C' (control-C) followed by `H' to obtain information about interrupts.Copyright (C) 2019 Massachusetts Institute of TechnologyThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Image saved on Friday August 30, 2019 at 11:20:36 PM Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || SOS 1.8 || XML 1.0 || Edwin 3.117 || X11 1.3 || X11-Screen 1.0 || ScmUtils Mechanics.Summer 20191 ]=>Go ahead and try evaluating some Lisp, using functions from themechanics library:
1 ]=> (square (up'x'y'z))#|(+ (expt x2) (expt y2) (expt z2))|#
You're all set!
If you set up XQuartz / X11, you should be able to get LaTeX expressions printing.
To test this out, run thebin/mechanics script and try entering an expressionlike(show-expression (+ 'alpha 't)) at the REPL.
$ bin/mechanics127.0.0.1 being added to access control listMIT/GNU Scheme running under GNU/LinuxType `^C' (control-C) followed by `H' to obtain information about interrupts.Copyright (C) 2019 Massachusetts Institute of TechnologyThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Image saved on Friday August 30, 2019 at 11:20:36 PM Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || SOS 1.8 || XML 1.0 || Edwin 3.117 || X11 1.3 || X11-Screen 1.0 || ScmUtils Mechanics.Summer 20191 ]=> (show-expression (+ 'alpha 't))(+ alpha t)You should see a window pop up in XQuartz with a nicely rendered LaTeXexpression:
The REPL will hang until you close the XQuartz window, so go ahead and do thatnow.
The exercises for each chapter live in their own folder, namedch1,ch2,etc. Inside each folder I've included a file for each exercise that requiredcode or benefited from exploration in Scheme.
You can run any code in these folders by starting the REPLbin/mechanics fromthe repository root folder, and calling, for example:
(load"ch1/ex1-29.scm")
This will execute all code in the file located atch1/ex1-29.scm, includingall side effects and graphics that the file generated. If you see LaTeXexpressions pop up, you'll have to close each one to move to the next one.
If you want to interact more heavily with the code, add more exercises and workon it yourself, I suggest you switch to a proper text editor with nice supportfor Scheme. I useEmacs, specificallySpacemacs,these days. (Here's mySpacemacsconfiguration, ifthat phrase means anything to you.)
I won't go into a whole spiel about how to set up Emacs, but I will note aconfiguration options that I've found very helpful when working on theseexercises. (If you have guides you like, let me know and I'll link them here.)
Emacs has amazing built-in support for working with Scheme. I've added amechanics function to my Emacs config:
(defunmechanics () (interactive) (run-scheme"mechanics"))
(This works because I've added thesicm/bin directory to my path. You'll needto do that too, or give this command the full path to thebin/mechanicsprogram.)
When I'm in a file in the project, I can typeM-x mechanics, and Emacs willstart up a REPL running themechanics code, with X11 support and everything.Then, when I'm working on a file,C-c C-z will switch to the repl.
MAKE SURE you run this from the root of the project!! Go toREADME.md orsomething and run it there. All of theload statements in all of the codeassume your main directory is the project root, so you'll run into problems ifyou don't do this.
I actually use a slightly better version of the function above. If you use theincredibleProjectile library for Emacsproject navigation (and why wouldn't you??) you can makemechanics startScheme from the project root every time.
Here's the better version:
(defunmechanics-local () (interactive) (run-scheme"mechanics"))(defunmechanics () (interactive) (let ((default-directory (or (projectile-project-root) default-directory))) (call-interactively#'mechanics-local)))
This will attempt to use Projectile to launch Scheme in the root of yourproject, and fall back to the current folder if you're not in a project when yourunM-x mechanics. Total gold!
There are a few other customizations that I've found helpful working withMIT-Scheme and mechanics. I'll detail them here.
This block of configuration code that, in Scheme, changes "lambda" appearancesinto nice, pretty greek symbols. This is calledprettify-symbols-mode,and looks great.
;; This enables nice greek-letter lambdas whenever you type "lambda";; anywhere in a Scheme file.(global-prettify-symbols-mode1);; Some bonus code to get this working in other language modes:(defunenable-pretty-lambdas ()"Make them beautiful!" (setq prettify-symbols-alist '(("lambda".955))));; I'm using Racket for a different project, so I wanted the good there too.(add-hook'racket-mode-hook'enable-pretty-lambdas)(add-hook'racket-repl-mode-hook'enable-pretty-lambdas)
I usesmartparens to make sure that myparentheses never get out of balance. This is absolutely essential when workingwith Lisp.
I'm used to thePareditkeybindings from years back, so I run this setting to make sure that all of thechords burned into my fingers don't have to change:
(sp-use-paredit-bindings)
To learn how to use these bindings, and what this library can do for you, checkout Dan Midwood's amazingAnimated Guide toParedit.
Here's aguide comparing Paredit andSmartparens,so you don't get caught out by the differences.
This method of installation is a little more involved, but if you decide thatyou want to skip the Docker route and installmechanics and MIT Schemenatively on OS X, these are the steps.
The instructions arehere, butlet's get through them more carefully.
- Install MIT Scheme:https://www.gnu.org/software/mit-scheme/
- Rename the ``MIT-Scheme
application in the Applications folder toMIT-Scheme`, so we don't have to worry about escaping spaces in the terminal. - Create a
~/binfolder and get it on your$PATH.
Run the following command to make themit-scheme binary available:
ln -s /Applications/MIT-Scheme.app/Contents/Resources/mit-scheme~/bin/mit-schemeAdd this line to your~/.bashrc or~/.bash_profile, so that Scheme can see its libraries:
export MITSCHEME_LIBRARY_PATH=/Applications/MIT-Scheme.app/Contents/ResourcesTest that this all worked by runningmit-scheme at a fresh terminal. You should see the following:
$ mit-schemeMIT/GNU Scheme running under OS XType `^C' (control-C) followed by `H' to obtain information about interrupts.Copyright (C) 2019 Massachusetts Institute of TechnologyThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Image saved on Saturday August 10, 2019 at 6:28:48 PM Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.1181 ]=>Once that's working, it's time to install the SCMUtils / Mechanics library.
The download link for the library lives at theSICM coursewebsite, atstep 4. Here's thedirect downloadlinkif you prefer that.
The next few steps come from the instructions at the course site:
- Expand this gzipped tar archive by executing
tar xzf scmutils-20190830.tar.gz. This will make a directory namedscmutils-20190830. - Run
cd scmutils-20190830 && ./install.shto installscmutilsinto yourlocal Scheme installation's resource directory. - Copy the starter script into
~/binby runningcp mechanics.sh ~/bin/mechanics.
Test it all out by runningmechanics. You should see the following:
$ mechanicsMIT/GNU Scheme running under OS XType `^C' (control-C) followed by `H' to obtain information about interrupts.Copyright (C) 2019 Massachusetts Institute of TechnologyThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Image saved on Friday August 30, 2019 at 11:20:36 PM Release 10.1.10 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || SOS 1.8 || XML 1.0 || Edwin 3.117 || X11 1.3 || X11-Screen 1.0 || ScmUtils Mechanics.Summer 20191 ]=>You're all set now, and can refer back to previous sections for instructions onhow to install X11 and LaTeX, work with the exercises, or configure Emacs.
Thanks for following along! If you run into any issues, please file a ticket viaGithub Issues.
If you have any questions, or want to send me a note, you can do that atsritchie09 at gmail.com.
Copyright 2020, Sam Ritchie.
Licensed under theApache License, Version2.0.
About
Exercises and notes on Structure and Interpretation of Classical Mechanics.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.

