{"id":881,"date":"2015-09-30T21:55:08","date_gmt":"2015-09-30T20:55:08","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/?p=881"},"modified":"2015-09-30T21:55:08","modified_gmt":"2015-09-30T20:55:08","slug":"quantum-scheme","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2015\/09\/30\/quantum-scheme\/","title":{"rendered":"Quantum Scheme"},"content":{"rendered":"<p>I&#8217;m doing the Stanford <a href=\"http:\/\/quantum.class.stanford.edu\/\">&#8220;Quantum Physics for Engineers&#8221;<\/a> online course just now.  Separately, a few months ago I was reading the Sussman <a href=\"http:\/\/mitpress.mit.edu\/sites\/default\/files\/titles\/content\/sicm\/book.html\">&#8220;Structure And Interpretation of Classical Mechanics&#8221;<\/a> book which is notable for using scheme as a mathematical notation, thereby avoiding a lot of the ambiguities of &#8216;normal&#8217; maths notation (a big win in Lagrangian mechanics, which makes heavy use of partial derivatives).<\/p>\n<p>Anyhow, the Stanford Quantum course requires you to do various exercises, such as the following:<\/p>\n<blockquote><p>\nAn 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)?\n<\/p><\/blockquote>\n<p>As usual, this requires plugging the supplied numbers and a bunch of physics constants into the right equation.  At school, I would&#8217;ve done this by hand &#8211; hopefully remembering constants like &#8216;c&#8217; (3e8 m\/s) and h (6.62e-34).<\/p>\n<p>But I can also do this using scheme, as per the SICM book.  The &#8216;scmutils&#8217; library comes with a bunch of built-in constants, with the correct units:<\/p>\n<pre>\r\n:c\r\n=> (& 299792458. (* &meter (expt &second -1)))\r\n\r\n:h\r\n=> (& 6.62606896e-34 (* (expt &meter 2) &kilogram (expt &second -1)))\r\n<\/pre>\n<p>In scmutils, the ampersand function attaches units to a number. <\/p>\n<p>So now I can use de Broglie&#8217;s wavelength relation to find velocity as a function of mass and wavelength:<\/p>\n<pre>\r\n(define (velocity mass wavelength) (\/ :h (* mass wavelength)))\r\n<\/pre>\n<p>then plug in the appropriate values to find the velocity:<\/p>\n<pre>\r\n(velocity :m_e (& 1e-9 &meter))\r\n=> (& 727389.4676462485 (* &meter (expt &second -1)))\r\n<\/pre>\n<p>The question actually asked &#8220;can you treat it as non-relativistic&#8221; so we want to know if it&#8217;s close to the speed of light or not:<\/p>\n<pre>\r\n(\/ (velocity :m_e (& 1e-9 &meter)) :c)\r\n=> 2.43e-3\r\n<\/pre>\n<p>So it&#8217;s much slower than the speed of light, and the answer is &#8220;yes, it&#8217;s reasonable to treat this as a non-relativistic particle).  But thanks to scheme\/scmutils, I&#8217;m also pretty confident I haven&#8217;t made errors with units (because scheme tracked them for me) or constants (because I didn&#8217;t have to enter them).<\/p>\n<p>Although not required for this exercise, the scmutils package also handles symbolic differentiation which is pretty nifty!  For example:<\/p>\n<pre>\r\n(define (foo x) (log x))\r\n\r\n(foo 'a)\r\n => (log a)\r\n\r\n((D foo) 'x)\r\n => (\/ 1 x)\r\n<\/pre>\n<p>The scmutils library is very elegant once you realise how it works.  The definition of the scheme &#8216;foo&#8217; function is just that &#8211; a scheme function.  You can use it in one of two ways.  You can pass a number to it &#8211; eg. (foo 5) &#8211; and it&#8217;ll evaluate it numerically &#8211; eg. 1.609.  Or you can pass that same function a symbol, such as &#8216;a, and it&#8217;ll give you back a symbolic expression &#8211; eg. &#8220;log a&#8221;.  It has a built-in simplifier too, as seen here:<\/p>\n<pre>\r\n(define (addaddadd x) (+ x x x))\r\n=> #| addaddadd |#\r\n\r\n(addaddadd 'a)\r\n=> #| (* 3 a) |#\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m doing the Stanford &#8220;Quantum Physics for Engineers&#8221; online course just now. Separately, a few months ago I was reading the Sussman &#8220;Structure And Interpretation of Classical Mechanics&#8221; book which is notable for using scheme as a mathematical notation, thereby avoiding a lot of the ambiguities of &#8216;normal&#8217; maths notation (a big win in Lagrangian [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-881","post","type-post","status-publish","format-standard","hentry","category-general"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=881"}],"version-history":[{"count":2,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/881\/revisions"}],"predecessor-version":[{"id":883,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/881\/revisions\/883"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}