Quantum Scheme

I’m doing the Stanford “Quantum Physics for Engineers” online course just now. Separately, a few months ago I was reading the Sussman “Structure And Interpretation of Classical Mechanics” book which is notable for using scheme as a mathematical notation, thereby avoiding a lot of the ambiguities of ‘normal’ maths notation (a big win in Lagrangian mechanics, which makes heavy use of partial derivatives).

Anyhow, the Stanford Quantum course requires you to do various exercises, such as the following:

An electron has a 1nm wavelength. Is it reasonable to treat this electron as an approximately non-relativistic particle (i.e. traveling much slower than the speed of light)?

As usual, this requires plugging the supplied numbers and a bunch of physics constants into the right equation. At school, I would’ve done this by hand – hopefully remembering constants like ‘c’ (3e8 m/s) and h (6.62e-34).

But I can also do this using scheme, as per the SICM book. The ‘scmutils’ library comes with a bunch of built-in constants, with the correct units:

=> (& 299792458. (* &meter (expt &second -1)))

=> (& 6.62606896e-34 (* (expt &meter 2) &kilogram (expt &second -1)))

In scmutils, the ampersand function attaches units to a number.

So now I can use de Broglie’s wavelength relation to find velocity as a function of mass and wavelength:

(define (velocity mass wavelength) (/ :h (* mass wavelength)))

then plug in the appropriate values to find the velocity:

(velocity :m_e (& 1e-9 &meter))
=> (& 727389.4676462485 (* &meter (expt &second -1)))

The question actually asked “can you treat it as non-relativistic” so we want to know if it’s close to the speed of light or not:

(/ (velocity :m_e (& 1e-9 &meter)) :c)
=> 2.43e-3

So it’s much slower than the speed of light, and the answer is “yes, it’s reasonable to treat this as a non-relativistic particle). But thanks to scheme/scmutils, I’m also pretty confident I haven’t made errors with units (because scheme tracked them for me) or constants (because I didn’t have to enter them).

Although not required for this exercise, the scmutils package also handles symbolic differentiation which is pretty nifty! For example:

(define (foo x) (log x))

(foo 'a)
 => (log a)

((D foo) 'x)
 => (/ 1 x)

The scmutils library is very elegant once you realise how it works. The definition of the scheme ‘foo’ function is just that – a scheme function. You can use it in one of two ways. You can pass a number to it – eg. (foo 5) – and it’ll evaluate it numerically – eg. 1.609. Or you can pass that same function a symbol, such as ‘a, and it’ll give you back a symbolic expression – eg. “log a”. It has a built-in simplifier too, as seen here:

(define (addaddadd x) (+ x x x))
=> #| addaddadd |#

(addaddadd 'a)
=> #| (* 3 a) |#


A while ago, I wrote an emacs ‘reading mode’. It highlights a single sentence at a time, fading the rest of the text into a gentle grey, and a keypress moves onto the next sentence. It retains the familiarity and consistency of normal text layout, but provides additional cues about the extent of the current sentence.

Tonight, I played with the idea of including smarter parsing into this reading mode. The Stanford Parser parses english sentences. It tells you about the grammatical structure (noun phrases, verb phrases, etc) and dependencies between words. This is just about enough to do what I had in mind – a “superfluous word” highlighter. The whole world is absolutely packed full of so many documents with wholly unnecessary words. Ideally, I’d like to just delete the pointless words. But it’s rare for a word to be completely devoid of semantic meaning. So, my compromise is just to highlight those decorative words – adjectival and adverbial modifiers – which are commonly guilty.

Here’s some examples, not completely perfect, but useful nonetheless:

I REALLY want some SUPER TASTY chocolate.
The system has been VERY CAREFULLY designed, and will cope admirably with all 
  CONCEIVABLE combinations of circumstances.
I wanted to leave my SMALL pond and see HOW I'd fare in a BIG one, with some 
  of the BEST developers in the world.
You define HOW you want your data to be structured ONCE, THEN you can 
  use SPECIAL GENERATED source code to EASILY write and read your STRUCTURED data.


“Wald applied his statistical skills in World War II to the problem of bomber losses to enemy fire. A study had been made of the damage to returning aircraft and it had been proposed that armor be added to those areas that showed the most damage. Wald’s unique insight was that the holes from flak and bullets on the bombers that did return represented the areas where they were able to take damage. The data showed that there were similar patches on each returning bomber where there was no damage from enemy fire, leading Wald to conclude that these patches were the weak spots that led to the loss of a plane if hit, and that must be reinforced.”

– http://en.wikipedia.org/wiki/Abraham_Wald


I was mucking about in javascript, simulating geostationary satellites orbiting around the earth. Then I started thinking about simulating moon missions – ie. properly simulating the thrust of (say) the Saturn 5 rocket at various stages of the launch, how the fuel mass decreased and so resulted in increasing acceleration at fixed thrust. There’s plenty of data available about when they lit engines and started roll programmes for the Apollo missions.

Anyhow, this lead me to realise that I’m too earth-centric in my coordinate systems. I need to know where the moon was in 1969 when Apollo 11 took off. Actually, I’m wasn’t even sure which coordinate system you’d measure that in. WGS84, used by GPS sysems, ain’t so much use if you’re flying to the moon! The ICRF is what you need.

It also made me think about a location-a-pedia. Ie. something which tells you where objects were at a certain time. Where was the moon at the instant when Apollo 11 took off? Where was it when Apollo 11 landed? Perhaps for flying sims, you might have historical data about where different commercial flights were at different times. For space sims, you need to know where the objects of the solar system were. Newton’s laws will tell you how they move, but you need a starting point.

(Update: Omg, it’s 2013 and I just used a telnet interface to an online system).

Maybe in 20 years, all objects will be reporting their coordinates (in some galactic coordinate system) to a central database. That way, if you lose your keys, you’d have an easy way to find them. Even if you were on Mars.

I’ve read a lot of engineering history books in my time, but rarely have they evoked Mills & Boon so strongly as this gem:

“He realized a machine to draw the wire from the reel, cut and shape it, pierce the holes in the leather, and place the staples in the sheet; but the forming of the second and final bend in the teeth was a problem that vexed his very soul as one of insurmountable difficulty. Hope was followed by despair, and the most glorious prize of all that would crown his machine with perfection, hovered around him like a phantom, enticing him on to further exertion, yet eluding his grasp. He did not lack, however, the support of encouraging friends, who believed in his ultimate success if he would only persevere believingly and courageously. To the cheerful assurances of his friends may be attributed much of his resolution and unremitting ardor in forcing his scheme to a successful finality.

While in this maze of doubt, his brain hot with feverish uncertainty, his thoughts dwelling vaguely on a theory of possibilities, his exhausted strength permitted the solution to come to him in a dream. Such is the testimony of some, and, whether it be true or not, it is not outside a common experience of many, to retire at night with a mind confused and mystified by unabated application to a single idea, and wake up in the morning with it fresh and clear with the mystery revealed and elucidated, as if it were the work of a vision. He arose at early dawn with a heart full of emotion, and a face beaming with joy, and eagerly sought his workshop to place on his machine the last piece of mechanism that was to transform it into a magnificent consummation”

(from the 1885 book, History of the American card-clothing industry)