tag:blogger.com,1999:blog-44706665176476338222018-03-06T06:43:47.139+00:00Physical ThoughtA blog of physics, mathematics, programming and photography...Andrew J. Benniestonhttp://www.blogger.com/profile/11705217909278393670noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-4470666517647633822.post-39310075412428850852010-05-23T01:41:00.000+01:002010-05-23T01:41:07.338+01:00The MoonThis is the best image from fifteen photographs of the Moon that I took this evening. My flat has a skylight thing in the roof, which opens and tilts in various ways (it would be great for using a telescope, actually...) so I decided to set up my camera and tripod and take some photos of the moon, since it was a clear night.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_zi39n2uYgqg/S_h5hHGsDuI/AAAAAAAAAR4/jLLc5jp0ir8/s1600/IMG_5454_fb.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="http://3.bp.blogspot.com/_zi39n2uYgqg/S_h5hHGsDuI/AAAAAAAAAR4/jLLc5jp0ir8/s400/IMG_5454_fb.jpg" width="400" /></a></div>Andrew J. Benniestonnoreply@blogger.com2tag:blogger.com,1999:blog-4470666517647633822.post-88364305173051484112010-03-04T20:14:00.000+00:002010-03-04T20:14:32.093+00:00The Road To Quantum Field Theory: Updated Post ListOnce again, I'm posting an index, essentially, of the posts in the `Road to QFT' series, so far. The previous list was <a href="http://physical-thought.blogspot.com/2009/01/road-to-quantum-field-theory.html">here</a>, but I'll reproduce all of the links in this post too.<br /><br /><b>Pre-Series Posts</b><br />These were posts on related topics (special relativity, quantum mechanics and particle physics)<br /><ul><li><b> </b><a href="http://physical-thought.blogspot.com/2008/04/introduction-to-relativity.html">An Introduction to Relativity</a> </li><li><a href="http://physical-thought.blogspot.com/2008/04/relativistic-velocity-transformations.html">Relativistic Velocity Transformations</a></li><li><a href="http://physical-thought.blogspot.com/2008/04/four-vector-relativistic-velocity.html">Four-Vector Relativistic Velocity Transformations</a> </li><li><a href="http://physical-thought.blogspot.com/2008/04/classical-electrodynamics.html">Classical Electrodynamics</a> </li><li><a href="http://physical-thought.blogspot.com/2008/04/relativistic-quantum-mechanics-klein.html">Relativistic Quantum Mechanics - The Klein-Gordon Equation</a> </li><li><a href="http://physical-thought.blogspot.com/2008/05/quantum-mechanics-of-neutrino.html">The Quantum Mechanics of Neutrino Oscillations</a> </li></ul><b>The `Road To Quantum Field Theory' Series</b><br />Posts in the `Road to QFT' series, in chronological order.<br /><ul><li><a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-principle-of.html">Lagrangian Mechanics: From the Principle of Least Action to the Euler-Lagrange Equation</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler.html">Lagrangian Mechanics: From the Euler-Lagrange Equation to Newton's Laws</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler_20.html">Lagrangian Mechanics: From the Euler-Lagrange Equation to Simple Harmonic Motion</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/from-lagrangian-to-hamiltonian.html">From Lagrangian to Hamiltonian Mechanics</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/symmetries-conserved-quantities-and.html">Symmetries, Conserved Quantities and Noether's Theorem</a></li><li><a href="http://physical-thought.blogspot.com/2009/01/mathematics-of-special-relativity.html">The Mathematics of Special Relativity</a></li><li><a href="http://physical-thought.blogspot.com/2009/12/lorentz-covariant-and-gauge-invariant.html">Lorentz-Covariant and Gauge-Invariant Electrodynamics</a> </li><li><a href="http://physical-thought.blogspot.com/2010/03/gauge-invariance-in-quantum-mechanics.html">Gauge Invariance in Quantum Mechanics</a> </li></ul><b>Out-of-Series Posts</b><br />Posts on related topics which were not intended as part of the `Road to QFT' series, but may be of interest anyway.<b> </b><br /><ul><li><b> </b> <a href="http://physical-thought.blogspot.com/2008/11/basic-relativity.html">Basic Relativity</a> </li></ul><b>Roadmap</b><br />As before, I'll post a rough list of things still to be covered. By comparing the previous roadmap to the most recent two posts, you'll notice I've done things slightly out of the order I mentioned there, so this is really a very approximate guide.<br /><ul><li>Relativistic QM: The Klein-Gordon Equation & Spin-Zero Particles</li><li>Relativistic QM 2: The Dirac Equation & Spin-Half Particles</li><li>Quantum Electrodynamics (QED)</li><li>Quantum Chromodynamics (QCD)</li><li>SU(2) and Electroweak Unification</li><li>Quark Flavour Mixing </li><li>Spontaneous Symmetry Breaking and the Higgs Mechanism </li><li>Beyond the Standard Model: Neutrino Mass Terms & Neutrino Mixing</li></ul>This is still a very ambitious set of things to cover. In particular, the posts so far have only brushed the surface, providing the background needed to understand relativistic quantum mechanics and gauge theories. The real work is yet to come! Note also that I am not a theorist, so my coverage of some of the more advanced topics may be less than completely thorough! I've added sections on quark flavour mixing and neutrino masses & mixing to the roadmap since they are of particular interest to me. <br /><ul></ul>Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-66345284298158377022010-03-02T21:37:00.070+00:002010-03-02T22:28:05.482+00:00Gauge Invariance in Quantum Mechanics<i>This post continues the 'Road to Quantum Field Theory' series.</i><br /><br />The Lorentz force law for a non-relativistic particle of charge q, moving with velocity v in both electric (<b>E</b>) and magnetic (<b>B</b>) fields, is given by: <pre lang="eq.latex">\mathbf{F} = q\mathbf{E} + q\mathbf{v}\times\mathbf{B}</pre>This can be derived from Hamilton's equations using the classical Hamiltonian given below.<br /><pre lang="eq.latex">H = \frac{1}{2m}\left(\mathbf{p}-q\mathbf{A}\right)^2 + qV</pre>The Schrödinger equation for a charged particle in an EM field is,<br /><pre lang="eq.latex">\left[\frac{1}{2m}\left(-i\nabla - q\mathbf{A}\right)^2 + qV \right] \psi(\mathbf{x},t) = i\frac{\partial \psi(\mathbf{x},t)}{\partial t}</pre>obtained from the Hamiltonian through the substitution <pre lang="eq.latex">\mathbf{p} \rightarrow -i\nabla</pre>as is usual for the quantum mechanical momentum operator. We can identify operator combinations:<br /><pre lang="eq.latex">\mathbf{D} = \nabla - iq\mathbf{A}</pre><pre lang="eq.latex">D^0 = \frac{\partial}{\partial t} + iqV</pre>which replace the operators <pre lang="eq.latex" style="display: inline;">\nabla, \frac{\partial}{\partial t}</pre>when we move from the free-particle Schrödinger equation to the electromagnetic field case.<br /><br />The solutions for the wavefunctions of the Schrödinger equation describe completely the behaviour of a particle under the influence of the potentials <b>A</b> and V, but these potentials are not unique, as I showed in the previous post in this series. Instead, they can be changed by a gauge transformation:<br /><pre lang="eq.latex">\mathbf{A}\rightarrow\mathbf{A}^\prime=\mathbf{A}+\nabla\chi</pre><pre lang="eq.latex">V\rightarrow V^\prime = V - \frac{\partial\chi}{\partial t}</pre>Maxwell's equations for <b>E</b> and <b>B</b> will remain invariant under these transformations (this was the topic of the previous post), but will the physics described by the Schrödinger equation be the same if we make these changes to the potentials there?<br /><br />The answer is <b>no</b>! The Schrödinger equation is not gauge invariant, since the same wavefunction cannot satisfy both the original and transformed versions! All is not lost, however. The wavefunction itself is not directly observable, whereas <b>E</b> and <b>B</b> are. If we do not require the wavefunction to remain invariant when the potentials undergo a transformation, then we are free to change the wavefunction such that we retain invariance of physical observables. Write the Schrödinger equation in terms of some transformed wavefunction,<br /><pre lang="eq.latex">\psi\rightarrow\psi^\prime</pre>i.e.<br /><pre lang="eq.latex">\left[\frac{1}{2m}\left(-i\nabla - q\mathbf{A}^\prime\right)^2 + qV^\prime\right] \psi^\prime(\mathbf{x},t) = i\frac{\partial \psi^\prime (\mathbf{x},t)}{\partial t}</pre><br />Now, the <i>form</i> in which we have written the equation above is identical to that of the original Schrödinger equation, except that we are writing it in terms of primed quantities (psi', <b>A'</b>, V') instead of unprimed (psi, <b>A</b>, V). Both equations describe the same physics, so if we can find such a psi', then the Schrödinger equation is <i>gauge covariant</i>; that is, it maintains the same form under a gauge transformation.<br /><br />We know the relationship between <b>A</b>, V and <b>A'</b>, V', so we can write down the transformation for psi':<br /><pre lang="eq.latex">\psi^\prime (\mathbf{x},t) = e^{iq\chi(\mathbf{x},t)}\psi(\mathbf{x},t)</pre>where <pre lang="eq.latex" style="display: inline;">\chi</pre>is the <i>same</i> space- and time- dependent function appearing in the transformations of <b>A</b> and V. We can verify that this results in the gauge covariance of the Schrödinger equation:<br /><pre lang="eq.latex">(-i\nabla - q\mathbf{A}^\prime)\psi^\prime=\left[-i\nabla-q\mathbf{A}-q(\nabla\chi)\right]e^{iq\chi}\psi</pre><pre lang="eq.latex">=q(\nabla\chi)e^{iq\chi}\psi + e^{iq\chi}(-i\nabla\psi) + e^{iq\chi}(-q\mathbf{A}\psi) - q(\nabla\chi)e^{iq\chi}\psi</pre>The first and last terms cancel, leaving:<br /><pre lang="eq.latex">(-i\nabla - q\mathbf{A}^\prime)\psi^\prime = e^{iq\chi}(-i\nabla - qA)\psi</pre>which can be written as:<br /><pre lang="eq.latex">(-i\mathbf{D}^\prime \psi^\prime) = e^{iq\chi}(-i\mathbf{D}\psi)</pre><br /><br />The space-time dependent phase factor feels the action of <pre lang="eq.latex" style="display: inline;">\nabla</pre>, but passes through the combined <b>D'</b> operator, converting it to <b>D</b>, so it becomes clear that <b>D'</b>psi' is related to <b>D</b>psi in the same way psi' is related to psi! Similarly,<br /><pre lang="eq.latex">(iD^{0\prime}\psi^\prime = e^{iq\chi}(iD^0\psi)</pre><br />We can now erite:<br /><pre lang="eq.latex">\frac{1}{2m}(-i\mathbf{D}^\prime)^2 \psi\prime = e^{iq\chi}\frac{1}{2m}(-i\mathbf{D})^2 \psi = e^{iq\chi}iD^0\psi = iD^{0\prime}\psi^\prime</pre>which demonstrates the correct relationship between psi and psi'. The question remains whether the same physics is described by both psi and psi'. We can see that it is in a number of ways:<br /><br />1. The probability density is given by <pre lang="eq.latex" style="display: inline;">|\psi|^2 = \psi^\dagger \psi</pre>, which is equivalent to <pre lang="eq.latex">|\psi\prime|^2 = \psi^{\prime\dagger} \psi^\prime = \psi^\dagger e^{-iq\chi}e^{+iq\chi}\psi = \psi^\dagger \psi</pre><br />2. The probability current, <pre lang="eq.latex">\psi^\dagger(\nabla\psi) - (\nabla\psi)\psi^\dagger</pre>is <i>not</i> invariant under a gauge transformation, but when we replace <pre lang="eq.latex" style="display: inline;">\nabla \rightarrow \mathbf{D} ~~,~~ \frac{\partial}{\partial t} \rightarrow D^0</pre>then,<br /><pre lang="eq.latex">\psi^\dagger\prime(\mathbf{D}\psi^\prime = \psi^\dagger e^{-iq\chi} e^{iq\chi}(\mathbf{D}\psi) = \psi^\dagger\mathbf{D}\psi</pre>(and similarly for the other term).<br /><br />Hence, identical physics is described by both the wavefunction psi, and the gauge transformed wavefunction psi'; the gauge invariance of Maxwell's equations presents as a <i>gauge covariance</i> in quantum mechanics, provided that we transform not only the potentials, but the wavefunction also:<br /><pre lang="eq.latex">\mathbf{A}\rightarrow \mathbf{A}^\prime = \mathbf{A} + \nabla\chi</pre><pre lang="eq.latex">V\rightarrow V^\prime = V - \frac{\partial \chi}{\partial x}</pre><pre lang="eq.latex">\psi\rightarrow \psi^\prime = i^{iq\chi}\psi</pre><br />Finally, we note that the new differential operators,<br /><pre lang="eq.latex">\mathbf{D} = \nabla - iq\mathbf{A} ~~,~~D^0 = \frac{\partial}{\partial t} + iqV</pre>can be written in a <i>Lorentz covariant</i> form:<br /><pre lang="eq.latex">D^\mu = \partial^\mu + iqA^\mu</pre><br />This allows us to write:<br /><pre lang="eq.latex">-iD^{\prime\mu}\psi^\prime = e^{iq\chi}(-iD^\mu \psi)</pre>and it follows that an equation can involving the operator <pre lang="eq.latex" style="display: inline;">\partial^\mu</pre>can be made to be gauge invariant by under the combined transformations:<br /><pre lang="eq.latex">A^\mu \rightarrow A^{\prime\mu} = A^\mu - \partial^\mu \chi</pre><pre lang="eq.latex">\psi \rightarrow \psi^\prime = e^{iq\chi}\psi</pre>provided the <i>minimal substitution</i> is also made:<br /><pre lang="eq.latex">\partial^\mu \rightarrow D^\mu = \partial^\mu + iqA^\mu</pre><br />This provides a simple mechanism to get the wave equation for a particle in an electromagnetic field from the equation for a free particle - by making the above substitution. This forms the basis of the <i>gauge principle</i>, i.e. the form of an interaction is determined by an insistence on <i>local gauge invariance</i>.<br /><br />That's enough for now; next time we'll move on to study the Klein-Gordon equation for relativistic spin-zero particles.Andrew J. Benniestonnoreply@blogger.com2tag:blogger.com,1999:blog-4470666517647633822.post-36872693508416069742010-02-08T15:01:00.000+00:002010-02-08T15:01:50.928+00:00Farscape Intro RandomiserWhile watching Farscape Season 2, Episode 4 (Crackers Don't Matter) last night, I wrote a Python script to randomise elements of the Farscape intro. Here's an example:<div><br /></div><div><i>My name is John Crichton, a wormhole hit and I got shot through a military commander. Now I'm lost in some distant part of the universe on an insane radiation wave, full of escaped prisoners. I'm being hunted by a living ship. Doing everything I can. I'm just looking for a way home.</i></div><div><i><br /></i></div><div><i><br /></i></div><br /><pre name="code" class="python">import random<br /><br />adjectives = [<br /> ('insane', 'an'),<br /> ('living', 'a'),<br /> ('escaped', 'an'),<br /> ]<br /><br />nouns = [<br /> ('ship', 'a'),<br /> ('radiation wave', 'a'),<br /> ('military commander', 'a'),<br /> ('prisoner', 'a'),<br /> ('wormhole', 'a')<br /> ]<br /><br /><br />parts = []<br />parts.append(random.choice(nouns))<br />nouns.remove(parts[0])<br />parts.append(random.choice(nouns))<br />nouns.remove(parts[1])<br />parts.append(random.choice(adjectives))<br />adjectives.remove(parts[2])<br />parts.append(random.choice(nouns))<br />nouns.remove(parts[3])<br />parts.append(random.choice(adjectives))<br />adjectives.remove(parts[4])<br />parts.append(random.choice(nouns))<br />nouns.remove(parts[5])<br />parts.append(random.choice(adjectives))<br />adjectives.remove(parts[6])<br />parts.append(random.choice(nouns))<br />nouns.remove(parts[7])<br /><br />result = 'My name is John Crichton, '<br />result += parts[0][1] + ' ' + parts[0][0]<br />result += " hit and I got shot through "<br />result += parts[1][1] + ' ' + parts[1][0]<br />result += ". Now I'm lost in some distant part of the universe on "<br />result += parts[2][1] + ' ' + parts[2][0] + ' ' <br />result += parts[3][0]<br />result += ", full of "<br />result += parts[4][0] + ' ' + parts[5][0] + 's'<br />result += ". I'm being hunted by "<br />result += parts[6][1] + ' ' + parts[6][0] + ' ' + parts[7][0]<br />result += ". Doing everything I can. I'm just looking for a way home."<br /><br />print result<br /></pre>Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-7052954825076330912009-12-08T21:38:00.000+00:002009-12-08T21:38:41.202+00:00Lorentz-Covariant and Gauge-Invariant ElectrodynamicsOver a year ago I started a series of blog posts aimed at describing quantum field theory, beginning with Lagrangian mechanics and working all the way up. It's been a while since I made any posts in that series. Indeed, the last post was a roadmap of sorts; a list of the topics still to be covered.<br /><br />The roadmap hinted that the next step is a relativistic description of electromagnetism. Actually, what we really want to do is describe electromagnetism as a gauge theory. That is, a theory which is gauge invariant. By the end of this post, what we mean by <i>gauge invariance</i> will become obvious.<br /><br />So, here goes.<br /><br /><b>Maxwell's Equations</b><br />Any treatment of electromagnetism must start with Maxwell's equations, presented below.<br /><br /><pre lang="eq.latex">(1)\,\,\,\,\,\nabla\cdot\mathbf{E} = \rho_{em}</pre><br /><pre lang="eq.latex">(2)\,\,\,\,\,\nabla\times\mathbf{E} = -\frac{\partial\mathbf{B}}{\partial t}</pre><br /><pre lang="eq.latex">(3)\,\,\,\,\,\nabla\cdot\mathbf{B} = 0</pre><br /><pre lang="eq.latex">(4)\,\,\,\,\,\nabla\times\mathbf{B} = \mathbf{j}_{em}</pre><br /><br />Here, <pre lang="eq.latex" style="display: inline;">\rho_{em}</pre>and <pre lang="eq.latex" style="display: inline;">\mathbf{j}_{em}</pre>are the electric charge density and electric current density, respectively, and we are working in Heaviside-Lorentz units. The densities act as the sources of the electric and magnetic fields.<br /><br />Taking the divergence of (4) leads to a problem; the continuity equation for electric charge states that<br /><pre lang="eq.latex">(5)\,\,\,\,\,\frac{\partial \rho}{\partial t} + \nabla\cdot\mathbf{j} = 0</pre><br />(note that I will omit the "em" subscript on the densities from now on).<br /><br />Since <pre lang="eq.latex">\nabla\cdot\nabla\times\mathbf{B} = 0\Rightarrow\nabla\cdot\mathbf{j}=0</pre><br />This is only true when the charge density does not vary with time. In general, Ampere's law must be modified to be<br /><pre lang="eq.latex">(6)\,\,\,\,\,\nabla\times\mathbf{B}=\mathbf{j}+\frac{\partial\mathbf{E}}{\partial t}</pre><br />This is now consistent with (5), the continuity equation.<br /><br />The continuity equation states that the rate of change of charge in some volume is due entirely to the flux of current through its surface. That is to say, <i>electric charge is conserved</i>. Since this volume can be made arbitrarily small, we can say that electric charge is <i>locally</i> conserved. This means that we can't balance things out by having a negative charge appear out of nowhere, as long as a positive charge is made the other side of the universe (or a negative charge disappears on the other side of the universe); this conservation law has to apply on an arbitrarily small scale.<br /><br />We can introduce the vector potential <pre lang="eq.latex" style="display: inline;">A_\mu</pre>in place of the fields <b>E</b> and <b>B</b>:<br /><pre lang="eq.latex">(7)\,\,\,\,\,\mathbf{B}=\nabla\times\mathbf{A}</pre><br /><pre lang="eq.latex">(8)\,\,\,\,\,\mathbf{E}=-\nabla V-\frac{\partial \mathbf{A}}{\partial t}</pre><br /><br />This defines the three-vector potential <b>A</b>, and the scalar potential <b>V</b> (sometimes called the electrostatic potential, and sometimes denoted <pre lang="eq.latex" style="display: inline;">\phi</pre>. Equations (2) and (3) are then satisified automatically.<br /><br />The gauge invariance of electromagnetism is based on the fact that, for a given <b>E</b> and <b>B</b>, the equations above do not uniquely determine <b>A</b> and V. In fact, one can apply transformations to <b>A</b> and V which leave <b>E</b> and <b>B</b> completely unchanged; and therefore leave all of the physics unchanged. These are known as <i>gauge transformations</i>, and the invariance of Maxwell's equations under these transformations is known as <i>gauge invariance</i><br /><br />We are free to change <b>A</b> as follows;<br /><pre lang="eq.latex">(9)\,\,\,\,\,\mathbf{A}\rightarrow \mathbf{A}^\prime = \mathbf{A}+\nabla\chi</pre><br />where <pre lang="eq.latex" style="display: inline;">\chi</pre>is an arbitrary scalar function. Since <pre lang="eq.latex" style="display: inline;">\nabla\times(\nabla\chi) = 0</pre>, this does not change <b>B</b>.<br /><br />To preserve <b>E</b> when making the above transformation, we must simultaneously transform the scalar potential V:<br /><pre lang="eq.latex">(10)\,\,\,\,\,V\rightarrow V^\prime=V-\frac{\partial\chi}{\partial t}</pre><br /><br />The transformations (9) and (10) can be written in a single expression using the four-potential,<br /><pre lang="eq.latex">(11)\,\,\,\,\,A^\mu = (V, \mathbf{A})</pre><br /><br />Note now that the differential operators,<br /><pre lang="eq.latex">(12)\,\,\,\,\,\left(\frac{\partial}{\partial t}, -\nabla\right)</pre><br />form a four-vector operator <pre lang="eq.latex" style="display: inline;">\partial^\mu</pre>. The gauge transformation can then be specified by:<br /><pre lang="eq.latex">(13)\,\,\,\,\,A^\mu \rightarrow A^{\prime\mu} = A^\mu - d^\mu\chi</pre><br /><br />Maxwell's equations can be written in a <i>manifestly Lorentz covariant</i> form (meaning, they have the same form under Lorentz transformations) using the four-current:<br /><pre lang="eq.latex">(14)\,\,\,\,\,\mathbf{j}^\mu = (\rho,\mathbf{j})</pre><br /><br />The continuity equation can then be written:<br /><pre lang="eq.latex">(15)\,\,\,\,\,\partial_\mu j^\mu = 0</pre><br />which in turn allows us to write equations (1) and (6) as:<br /><pre lang="eq.latex">(16)\,\,\,\,\,\partial_\mu F^{\mu\nu} = j^\nu</pre><br /><br />The equation above introduced the <i>Field Strength tensor</i> (or the <i>Faraday tensor</i>),<br /><pre lang="eq.latex">(17)\,\,\,\,\,F^{\mu\nu}=\partial^\mu A^\nu - \partial^\nu A^\mu</pre><br /><br />Under a gauge transformation (13), the Faraday tensor (17) remains unchanged; it is <i>gauge invariant</i>, and so, therefore, are Maxwell's equations in the form (16). As I already said above, Maxwell's equations are <i>Lorentz covariant</i> in the form (16), leading to a <i>Lorentz covariant and Gauge invariant</i> theory.<br /><br />Now, one can write<br /><pre lang="eq.latex">(18)\,\,\,\,\,\Box A^\nu - \partial^\nu(\partial_\mu A^\mu) = j^\nu</pre><br /><br />Equation (6) can be inferred (and indeed, was inferred by Maxwell) from the local charge conservation requirement expressed by the continuity equation (15). The field equations (16) automatically include the continuity equation. Mathematically speaking, the Faraday tensor (17) is a sort of "four-dimensional curl". This is unchanged by the gauge transformation (13), suggesting that gauge invariance in electromagnetism is related to charge conservation. The reality is a little more complicated.<br /><br />It was shown in 1949 by Wigner that the principle that no physical quantity can depend on the absolute value of the electrostatic potential V, combined with conservation of energy, implies that charge conservation holds. This relates charge and energy conservation to an invariance under the transformation of the electrostatic potential by a constant. Charge conservation alone does not require the more general space-time dependent transformation of the gauge invariance we've discussed above.<br /><br />Changing the electrostatic potential by a constant amount is an example of a <i>global</i> transformation. Invariance under this global transformation is related to the conservation of electric charge, but it is not sufficient to obtain all of electromagnetism. Instead, we must impose a <i>local</i> change in the electrostatic potential V (the time-derivative term in (10), which is <i>compensated</i> by a simultaneous change in the vector potential <b>A</b>, leaving Maxwell's equations ultimately unchanged. By including these magnetic effects, the global invariance under a change in V, related to conservation of electric charge, can be extended to a local invariance.<br /><br />The concept of local gauge invariance is important for the development of quantum field theory in subsequent posts. Next time, a tour of gauge invariance in quantum mechanics, and the <i>gauge principle</i>.<br /><br />Much of this post was based on Chapter 3 of Aitchison & Hey (Gauge Theories in Particle Physics, 3rd Edition, Vol. I - From Relativistic Quantum Mechanics to QED). It is a book I strongly recommend purchasing if you have an interest in quantum field theory. The second volume discusses QCD and Electroweak theory, and is another good purchase.Andrew J. Benniestonnoreply@blogger.com1tag:blogger.com,1999:blog-4470666517647633822.post-91535298756524171862009-07-15T11:50:00.002+01:002009-07-15T11:56:41.594+01:00Reversing Lines In A FileAs is often the case, an interesting little text manipulation task came up in the office today; given a file containing lines of text, reverse it (i.e. put the last line first, the penultimate line second, etc.)<br /><br />I have a feeling there's a neat little command-line utility that already does this (but can't remember what it is...), but my mind soon went to a short Python script. Here's my first stab at this:<br /><pre name="code" class="python"><br />#!/usr/bin/env python<br />import sys<br /><br />lines = []<br />for line in open(sys.argv[1]):<br /> lines.append(line.strip())<br /><br />lines.reverse()<br />for line in lines:<br /> print line<br /></pre><br /><br />After this, I tried to shorten it a bit. Putting the lines into a list could be done nicely with a list comprehension,<br /><pre name="code" class="python"><br />#!/usr/bin/env python<br />import sys<br /><br />lines = [line.strip() for line in open(sys.argv[1])]<br /><br />lines.reverse()<br />for line in lines:<br /> print line<br /></pre><br /><br />Finally, I discovered the <span style="color: rgb(0, 102, 0);">reversed()</span> function, which allows you to create reverse iterators for any Python sequence. Here's where the list comprehension and Python's iteration stuff really comes into its own, leading to a wonderful two-liner (not counting the module import and the #!)<br /><br /><pre name="code" class="python"><br />#!/usr/bin/env python<br />import sys<br />for line in reversed([line.strip() for line in open(sys.argv[1])]):<br /> print line<br /></pre>Andrew J. Benniestonnoreply@blogger.com6tag:blogger.com,1999:blog-4470666517647633822.post-36185512926612025472009-02-19T14:30:00.003+00:002009-02-19T14:35:25.184+00:00Writing Scientific Documents Using LaTeX: UpdatedI submitted a fifth edition (5/E) of `Writing Scientific Documents Using LaTeX` to CTAN yesterday (and another version today which fixes a couple of minor mistakes in the examples given).<br /><br />As usual, the document and associated files can be found at:<br /><a href="http://www.ctan.org/tex-archive/info/intro-scientific/">http://www.ctan.org/tex-archive/info/intro-scientific/</a>Andrew J. Benniestonnoreply@blogger.com2tag:blogger.com,1999:blog-4470666517647633822.post-89951311116765289952009-01-12T17:29:00.007+00:002009-02-19T10:22:00.454+00:00sed Magic: Removing LinesProblem: Remove lines from a file f2 if they contain a word in file f1.<br /><br />Solution:<br /><pre style="color: rgb(0, 153, 0);">for word in `cat f1`; do<br />sed -i "/$word/d" f2;<br />done</pre>sed is a stream editor, the -i option performs the editing in-place (i.e. in the original file).<br /><br />This came up in the office today and I thought the solution was rather neat (if equally straightforward). Alternatives in most scripting languages (except maybe Perl?) are longer and/or uglier.Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-17715651795923261912009-01-05T14:31:00.002+00:002009-01-05T14:52:46.922+00:00The Road To Quantum Field TheoryDedicated readers will know that I've been presenting topics from theoretical physics with the goal of leading from Lagrangian mechanics all the way to quantum field theories. There were a few posts I made on special relativity and relativistic quantum mechanics before the 'QFT Series' of posts really began, and a number of other posts interspersed with those in the series. The most recent post introduced a mathematical notation useful in special relativity and relativistic quantum mechanics, notably four-vectors, tensors, etc.<br /><br />Near the beginning I presented a list of topics I was going to cover. At this stage, I think it is appropriate to present a list of topics I've already covered, with links to the posts covering them, then to briefly outline the steps which still remain.<br /><br /><span style="font-weight: bold;">Pre-Series posts on Special Relativity, Quantum Mechanics and Particle Physics</span><br /><ul><li><a href="http://physical-thought.blogspot.com/2008/04/introduction-to-relativity.html">An Introduction to Relativity</a></li><li><a href="http://physical-thought.blogspot.com/2008/04/relativistic-velocity-transformations.html">Relativistic Velocity Transformations</a></li><li><a href="http://physical-thought.blogspot.com/2008/04/four-vector-relativistic-velocity.html">Four-Vector Relativistic Velocity Transformations</a></li><li><a href="http://physical-thought.blogspot.com/2008/04/classical-electrodynamics.html">Classical Electrodynamics</a></li><li><a href="http://physical-thought.blogspot.com/2008/04/relativistic-quantum-mechanics-klein.html">Relativistic Quantum Mechanics: The Klein-Gordon Equation</a></li><li><a href="http://physical-thought.blogspot.com/2008/05/quantum-mechanics-of-neutrino.html">The Quantum Mechanics of Neutrino Oscillations</a></li></ul><span style="font-weight: bold;"><br />The 'Road to QFT' Series</span><br /><ul><li><a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-principle-of.html">Lagrangian Mechanics: From the Principle of Least Action to the Euler-Lagrange Equation</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler.html">Lagrangian Mechanics: From the Euler-Lagrange Equation to Newton's Laws</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler_20.html">Lagrangian Mechanics: From the Euler-Lagrange Equation to Simple Harmonic Motion</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/from-lagrangian-to-hamiltonian.html">From Lagrangian to Hamiltonian Mechanics</a></li><li><a href="http://physical-thought.blogspot.com/2008/09/symmetries-conserved-quantities-and.html">Symmetries, Conserved Quantities and Noether's Theorem</a></li><li><a href="http://physical-thought.blogspot.com/2009/01/mathematics-of-special-relativity.html">The Mathematics of Special Relativity</a></li></ul><span style="font-weight: bold;"><br />Out-of-Series Posts</span><br /><ul><li><a href="http://physical-thought.blogspot.com/2008/11/basic-relativity.html">Basic Relativity</a></li></ul><span style="font-weight: bold;"><br />Roadmap<br /></span><ul><li>Relativistic Electrodynamics (Covariant Formulation of Maxwell's Equations)</li><li>Relativistic Quantum Mechanics: From Schrödinger to Klein-Gordon</li><li>Relativistic Quantum Mechanics II: The Dirac Equation and Spin</li><li>Symmetries and the Gauge Principle</li><li>Quantum Electrodynamics (QED)<br /></li><li>Aside on Quantum Chromodynamics (QCD)<br /></li><li>SU(2) and Electroweak Unification</li><li>Aside on Superconductivity (maybe...)<br /></li><li>Spontaneous Symmetry Breaking and the Higgs Mechanism</li></ul>You may notice that the imminent parts of the roadmap are becoming more clearly defined, while the still-distant final topics are broad and loosely defined. For example, there's likely to be more than one post on QED, but until I get there I don't know how many posts it will take!Andrew J. Benniestonnoreply@blogger.com5tag:blogger.com,1999:blog-4470666517647633822.post-44598774015844273312009-01-03T16:49:00.013+00:002009-01-05T13:17:21.733+00:00The Mathematics of Special RelativityAs promised, here is a post outlining the mathematical objects used in special relativity (SR). I'm not going to present fully formal definitions, and I'll almost certainly miss out some things I'll later rely on to explain more advanced concepts, but I'll get to those when the time comes. As for the formal definitions, find a good text on special relativity.<br /><br /><span style="font-weight:bold;">Contravariant Four-Vectors</span><br />A <span style="font-style:italic;">contravariant four-vector</span> is a four-component object which transforms according to the rule<br /><pre lang="eq.latex">x^{\prime\mu}=L^\mu_\nu x^\nu</pre><br />where L is the Lorentz transformation (LT) matrix.<br /><br />For a transformation from a frame <span style="font-weight:bold;">S</span> to a frame <span style="font-weight:bold;">S'</span> moving with respect to <span style="font-weight:bold;">S</span> with velocity <span style="font-style:italic;">v</span> in the positive <span style="font-style:italic;">x</span> direction, define<br /><pre lang="eq.latex">\begin{align*}<br />\beta &= \frac{v}{c}\\ \gamma &= \frac{1}{\sqrt{1-\beta^2}}\\ L &= \left(\begin{array}{cccc}\gamma&-\gamma\beta&0&0\\ -\gamma\beta&\gamma&0&0\\0&0&1&0\\0&0&0&1\end{array}\right)\end{align*}</pre><br /><br />For example, the space-time four-vector <pre lang="eq.latex">x^\mu = \left(\begin{array}{c}ct\\x\\y\\z\end{array}\right)</pre> transforms as <pre lang="eq.latex">x^{\prime\mu} = \left(\begin{array}{c}\gamma ct-\gamma\beta x\\-\gamma\beta ct+\gamma x\\y\\z\end{array}\right)</pre><br /><pre lang="eq.latex">= \left(\begin{array}{c}c\gamma\left(t-\frac{vx}{c^2}\right)\\\gamma\left(x-vt\right)\\y\\z\end{array}\right)</pre><br />i.e. the usual form of the SR Lorentz transforms.<br /><br />Contravariant four-vectors are represented with a greek-letter index in the superscript position. In particle physics and quantum field theory it is conventional for time to be the zeroth component, as in all of my posts. In some areas of relativistic quantum mechanics, one will see time as the fourth component. This alters the definition of the LT matrix and the metric tensor, but of course the physics remains the same. I will always use time as the zeroth component in these posts.<br /><br /><span style="font-weight:bold;">Covariant Four-Vectors and Rank-Two Tensors</span><br />In addition to contravariant four-vectors, there are mathematical objects called covariant four-vectors (sometimes also called one-forms). It is possible to convert between covariant and contravariant vectors using an object known as a metric tensor.<br /><br />Covariant vectors are written with a single greek-letter index in the subscript position. Covariant and contravariant vectors are both rank-one tensors; objects where the rank is defined by the number of indices (equivalently the number of times one must apply the Lorentz transforms).<br /><br />A metric tensor defines the structure of the space-time in which we are working. For special relativity, we use Minkowski space, and the metric tensor is defined as g:<br /><pre lang="eq.latex">g = \left(\begin{array}{cccc}1&0&0&0\\0&-1&0&0\\0&0&-1&0\\0&0&0&-1\end{array}\right)</pre><br /><br />g is a rank-two tensor representing the structure of space-time. In general relativity (GR) different metric tensors can be used for different space-time geometries.<br /><br />The metric tensor allows us to convert contravariant vectors into covariant vectors, and vice versa:<br /><pre lang="eq.latex">\begin{align*}<br />x_\mu &= g_{\mu\nu}x^\nu\\<br />x^\mu &= g^{\mu\nu}x_\nu\end{align*}</pre><br /><br />Note that in these cases, <pre lang="eq.latex" style="display: inline;">g_{\mu\nu}</pre> has both indices either raised or lowered, whereas in the Lorentz transforms, L has one raised index and one lowered index. The positions of the indices determine the result (covariant or contravariant) and whether the result is physically meaningful. The Einstein summation convention states that one should sum over repeated indices where one is raised and the other is lowered.<br /><br />In Minkowski space, the conversion between co- and contra-variant vectors is simple:<br /><pre lang="eq.latex">x^\mu = \left(\begin{array}{c}ct\\x\\y\\z\end{array}\right)</pre><br /><pre lang="eq.latex">x_\mu = \left(\begin{array}{cccc}ct&-x&-y&-z\end{array}\right)</pre><br /><br />Note that this leads to the useful property that the contraction of a covariant and a contravariant four-vector is a Lorentz-invariant scalar quantity. For example, using the space-time four-vector:<br /><pre lang="eq.latex">x^\mu x_\mu = x^\mu g_{\mu\nu}x^\nu = c^2 t^2 - x^2 - y^2 - z^2</pre><br />which should be recognisable as the Lorentz-invariant space-time interval of special relativity.<br /><br />This property holds for all four-vectors and in all inertial reference frames.<br /><br /><span style="font-weight:bold;">Rapidity</span><br />Special Relativity is sometimes formulated in terms of <span style="font-style:italic;">rapidity</span> <pre lang="eq.latex" style="display: inline;">\theta</pre> rather than velocity <span style="font-style:italic;">v</span>.<br /><br />Here, <pre lang="eq.latex">\mathrm{tanh}\,\theta = \beta</pre><pre lang="eq.latex">\Rightarrow \mathrm{cosh}\,\theta = \gamma = \frac{1}{\sqrt{1-\beta^2}}</pre>.<br /><br />The Lorentz transformation matrix is then written (often called <pre lang="eq.latex" style="display: inline;">\Lambda</pre> rather than L):<br /><pre lang="eq.latex">\Lambda =\left(\begin{array}{cccc}\mathrm{cosh}\,\theta&-\mathrm{sinh}\,\theta&0&0\\-\mathrm{sinh}\,\theta&\mathrm{cosh}\,\theta&0&0\\0&0&1&0\\0&0&0&1\end{array}\right)</pre><br />for the equivalent of<br /><pre lang="eq.latex">L = \left(\begin{array}{cccc}\gamma&-\gamma\beta&0&0\\-\gamma\beta&\gamma&0&0\\0&0&1&0\\0&0&0&1\end{array}\right)</pre><br /><br />The usefulness of this approach lies in the fact that while velocities in SR do not add linearly, i.e.<br /><pre lang="eq.latex">v_{12} \neq v_1 + v_2</pre><br />Rapidities <span style="font-style:italic;">do</span> add linearly:<br /><pre lang="eq.latex">\theta_{12} = \theta_1 + \theta_2</pre><br /><br /><span style="font-weight:bold;">Useful Objects</span><br />I'm going to list a few of the vectors and tensors which appear often in particle physics, so that when I need to use them in future posts, they won't look completely new. I won't explain much about them here.<br /><br /><span style="font-style:italic;">Energy-Momentum four-vector</span><br /><pre lang="eq.latex">p^\mu = \left(\begin{array}{c}\frac{E}{c}\\p_x\\p_y\\p_z\end{array}\right) = \left(\begin{array}{c}\frac{E}{c}\\\mathbf{p}\end{array}\right)</pre><br /><br /><span style="font-style:italic;">Four-Current</span><br /><pre lang="eq.latex">j^\mu = \left(\begin{array}{c}\rho\\\mathbf{j}\end{array}\right)</pre><br /><br /><span style="font-style:italic;">(Electromagnetic) Four-Potential</span><br /><pre lang="eq.latex">A^\mu = \left(\begin{array}{c}\frac{\phi}{c}\\\mathbf{A}\end{array}\right)</pre><br />where <span style="font-weight:bold;">A</span> is the vector potential of electromagnetism.<br /><br /><span style="font-style:italic;">Covariant Derivative</span><br /><pre lang="eq.latex">\partial_\mu = \left(\begin{array}{c}\frac{1}{c}\frac{\partial}{\partial t}\\ \nabla\end{array}\right)</pre><br /><br /><span style="font-style:italic;">Faraday Tensor</span><br /><pre lang="eq.latex">F^{\mu\nu} = \partial^\mu A^\nu - \partial^\nu A^\mu</pre><br /><pre lang="eq.latex">F = \left(\begin{array}{cccc}0&-\frac{E_1}{c}&-\frac{E_2}{c}&-\frac{E_3}{c}\\<br />\frac{E_1}{c}&0&-B_3&B_2\\<br />\frac{E_2}{c}&B_3&0&-B_1\\<br />\frac{E_3}{c}&-B_2&B_1&0\end{array}\right)</pre><br /><br />Note that <pre lang="eq.latex">F^{\mu\nu}F_{\mu\nu} = 2\left(B^2 - \frac{E^2}{c^2}\right)</pre> is Lorentz invariant!Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-25353354415447754122008-11-10T22:57:00.012+00:002008-11-19T09:26:00.094+00:00Basic RelativityI realise I haven't made any posts here recently; I've been far too busy with my Ph.D. and various other commitments. In lieu of the post I wanted to make on special relativity, defining everything carefully and introducing the tensor formulation, I'm going to present some basic concepts of Special Relativity, almost exactly as I taught them to a first year undergraduate examples class. These people had lectures on relativity already, so the stuff below is really a recap and a worked example.<br /><br /><span style="font-weight: bold;">Lorentz Transforms</span><br />Consider a coordinate frame S' moving with velocity v in the positive x-direction of a frame S. The Lorentz transforms between the two frames (x, y, z, t in S and x', y', z', t' in S') are given by:<br /><pre lang="eq.latex"><br />\begin{align*}<br />x^\prime &= \gamma(x-vt) = \frac{1}{\sqrt{1-\frac{v^2}{c^2}}}(x - vt)\\<br />y^\prime &= y\\<br />z^\prime &= z\\<br />t^\prime &= \gamma\left(t - \frac{vx}{c^2}\right) = \frac{1}{\sqrt{1-\frac{v^2}{c^2}}}\left(t - \frac{vx}{c^2}\right)<br />\end{align*}<br /></pre><br /><br />The reverse transforms, from S' back to S, are given by:<br /><pre lang="eq.latex"><br />\begin{align*}<br />x &= \gamma(x^\prime+vt^\prime) = \frac{1}{\sqrt{1-\frac{v^2}{c^2}}}(x^\prime + vt^\prime)\\<br />y &= y^\prime\\<br />z &= z^\prime\\<br />t &= \gamma\left(t^\prime + \frac{vx^\prime}{c^2}\right) = \frac{1}{\sqrt{1-\frac{v^2}{c^2}}}\left(t^\prime + \frac{vx^\prime}{c^2}\right)<br />\end{align*}<br /></pre><br /><br /><span style="font-weight: bold;">Velocity Transformation</span><br />If an object is moving with a velocity u' in frame S' (as defined above), we need to determine a transform for the velocity in frame S. Start out with the fact that the velocity in S is <pre style="display: inline;" lang="eq.latex">u = \frac{\Delta x}{\Delta t}</pre> and substitute in the transforms above:<br /><pre lang="eq.latex"><br />u = \frac{\Delta x}{\Delta t} &= \frac{\gamma(\Delta x^\prime + v\Delta t^\prime)}{\gamma\left(\Delta t^\prime + \frac{v\Delta x^\prime}{c^2}\right)}<br /></pre><br />Divide through by <pre style="display: inline;" lang="eq.latex">\Delta t^\prime</pre>:<br /><pre lang="eq.latex"><br />u= \frac{\frac{\Delta x^\prime}{\Delta t^\prime} + v}{1+\frac{v\Delta x^\prime}{\Delta t^\prime c^2}}<br /></pre><br /><br />Since <pre style="display: inline;" lang="eq.latex">\frac{\Delta x^\prime}{\Delta t^\prime}=u^\prime</pre>,<br /><br /><pre lang="eq.latex"><br />u = \frac{u^\prime + v}{1+\frac{u^\prime v}{c^2}}<br /></pre><br />which is the velocity transform between u and u'!<br /><br /><span style="font-weight: bold;">Time Dilation</span><br />Consider a particle with a lifetime <pre style="display: inline;" lang="eq.latex">\tau</pre> in its rest frame (i.e. in an inertial frame in which the particle has zero momentum). The lifetime t, in a frame moving with velocity v is given by:<br /><pre lang="eq.latex"><br />t = \gamma\tau<br /></pre><br /><br />Since <pre style="display: inline;" lang="eq.latex">\gamma</pre> is always greater than or equal to 1, t is always as large as, or larger than, <pre style="display: inline;" lang="eq.latex">\tau</pre>. This is the phenomenon of time dilation and the relationship can be used to determine the time dilation in any inertial frame.<br /><br /><span style="font-weight: bold;">Length Contraction</span><br />If the length measured in the lab frame is given by <pre style="display: inline;" lang="eq.latex">L_0</pre>, the length seen by a particle moving at speed v in the lab frame is given by:<br /><pre lang="eq.latex"><br />L = \frac{L_0}{\gamma}<br /></pre><br />The length is therefore always smaller than (or exactly the same as) the length in the lab frame, and this is the phenomenon of length contraction.<br /><br />Be careful never to use both time dilation and length contraction in the same (part of a) physics problem! If you're working in the lab frame, use time dilation to alter the particle lifetime, and leave the length as measured in the lab frame. If you're in the particle rest frame, use the particle lifetime as given (since they are defined as lifetime in a particle rest frame) and use length contraction to determine the length seen by the particle from the length as measured in the lab.<br /><br />The classic atmospheric muon problem, below, illustrates how to use these concepts.<br /><br /><span style="font-weight: bold;">The Atmospheric Muon Problem</span><br />Muons are produced in cosmic-ray interactions high in the Earth's atmosphere (at, say 8000m). The muon lifetime is <pre style="display: inline;" lang="eq.latex">2.2\times 10^{-6}~\mathrm{s}</pre>.<br /><br />Muons produced in this way are detected at the Earth's surface. For a muon travelling at 0.998 times the speed of light,<br /><span style="font-weight: bold;">(a)</span> Calculate how far the muon would travel using only classical (non-relativistic) physics.<br /><br />Here, we use the classical <pre style="display: inline;" lang="eq.latex">s = ut</pre> relationship. The maximum distance the muon can travel is given by:<br /><pre lang="eq.latex"><br />s = 0.998c \tau = 0.998\times 3\times 10^{8} \times 2.2\times 10^{-6} = 658.68~\mathrm{m}</pre><br /><br />In this situation, the muon cannot reach the Earth's surface.<br /><br /><span style="font-weight: bold;">(b)</span> In the rest frame of the muon, use relativistic physics to show that the muon can indeed reach the surface.<br /><br />In the muon rest frame, the lifetime is still <pre style="display: inline;" lang="eq.latex">2.2\times 10^{-6}~\mathrm{s}</pre>, but the length it has to travel is shortened by length contraction:<br /><pre lang="eq.latex"><br />L_\mu = \frac{1}{\gamma}L_E<br /></pre><br />The Lorentz factor is given by:<br /><pre lang="eq.latex"><br />\gamma = \frac{1}{\sqrt{1-\frac{v^2}{c^2}}} = 15.8<br /></pre><br />giving the length seen by the muon as:<br /><pre lang="eq.latex"><br />L_\mu = \frac{8000}{15.8} = 506.32~\mathrm{m}<br /></pre><br /><br />We already worked out that a muon travelling at 0.998c can travel over 600m before it decays using its lifetime as stated, in part a, so now the muons will make it to the surface of the Earth!<br /><br /><span style="font-weight: bold;">(c)</span> In the Earth frame, use relativistic physics to show that the muon can make it to the surface.<br /><br />Here, the length is as measured, 8000m, but the lifetime of the muon must be dilated:<br /><pre style="display: inline;" lang="eq.latex">t = \gamma \tau</pre><br /><br />We worked out the Lorentz factor above as 15.8, so now we have:<br /><pre lang="eq.latex"><br />t = 15.8 \times 2.2\times 10^{-6} = 3.48 \times 10^{-5}</pre><br /><br />The maximum distance such a muon can travel is then:<br /><pre lang="eq.latex"><br />s = u t = 0.998\times 3\times 10^8 \times 3.48\times 10^{-5} = 10419~\mathrm{m}</pre><br /><br />The muon can now travel over 10 km in the Earth frame, well over the 8 km it needs to hit the surface, so again we can detect such muons on the Earth.<br /><br />This example demonstrates several interesting aspects of relativistic physics. Firstly, that it works! We can detect muons produced in this way, which we wouldn't be able to detect if those relativistic effects didn't occur! Secondly, you can analyse a problem using either length contraction or time dilation, but you need to choose your frame carefully. Don't contract or dilate quantities that were measured in the frame you're using; only alter those measured in other frames. Note that lengths are often (but not <span style="font-style: italic;">always</span>) measured in a lab frame, and that particle lifetimes are <span style="font-style: italic;">always</span> given in the rest frame of the particle concerned!Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-82474116880370145442008-10-07T12:02:00.001+01:002008-10-07T12:02:56.591+01:00Contraction of Four-Vectors: A C++ Exercise<span style="color: rgb(204, 0, 0);">NOTE: The examples as typed have not been compiled or checked, however they are directly based on examples I talked through while teaching C++, so there should not be any particularly glaring errors or omissions. Note that I've avoided talking too much about object-oriented design, advanced concepts or why certain things are done the way they are. This article is intended mainly as an introduction to the abstraction mechanisms available with C++ class-based design, and is not intended to introduce any new concepts to the world of C++. In particular, I do not claim to be the first person to have thought of such concepts (as a number of comments have suggested in the past); I'm merely providing an example for those interested!</span><br /><br />Without going into the physics behind it, if we have two objects A and B, each with four components, we can define their contraction as:<br /><pre lang="eq.latex">A_{\mu}B^{\mu} = A_0 B_0 - (A_1 B_1 + A_2 B_2 + A_3 B_3)</pre><br /><br />I intend now to use this concept to develop a C++ program from a `first draft' to a finished object-oriented program. This is indented primarily as an introductory-level tutorial for those new to C++ but familiar with many aspects of C or similar languages, so I will not go into a lot of detail about the basics, instead focussing on the C++ specific stuff.<br /><br />The first approach could look something like this:<br /><pre name="code" class="cpp"><br />#include <iostream><br /><br />int main()<br />{<br /> // Create some variables<br /> double a0, a1, a2, a3;<br /> double b0, b1, b2, b3;<br /> <br /> // Prompt and read eight components<br /> std::cout << "Enter the four components of A, separated by spaces:" << std::endl;<br /> std::cin >> a0 >> a1 >> a2 >> a3;<br /> std::cout << "Enter the four components of B, separated by spaces:" << std::endl;<br /> std::cin >> b0 >> b1 >> b2 >> b3;<br /> <br /> // Calculate contraction and display result<br /> double result = a0*b0 - a1*b1 - a2*b2 - a3*b3;<br /> std::cout << "A.B = " << result << std::endl;<br /> <br /> return 0; <br />}<br /></pre><br /><br />This is a fairly simple program, achieving exactly what we set out to do. However, from the perspective of simplicity, there's a lot of overhead in the main program which detracts from the understanding of what is actually going on. We can make things slightly clearer by writing the contraction as a function; then we'll be able to call it repeatedly from our code, instead of defining what a contraction of four-vectors means at every point it is used:<br /><pre name="code" class="cpp"><br />double contract(double a0, double a1, double a2, double a3,<br /> double b0, double b1, double b2, double b3)<br />{<br /> return a0*b0 - a1*b1 - a2*b2 - a3*b3;<br />}</pre><br /><br />Now, our main() looks like this:<br /><pre name="code" class="cpp"><br />int main()<br />{<br /> // Create some variables<br /> double a0, a1, a2, a3;<br /> double b0, b1, b2, b3;<br /> <br /> // Prompt and read eight components<br /> std::cout << "Enter the four components of A, separated by spaces:" << std::endl;<br /> std::cin >> a0 >> a1 >> a2 >> a3;<br /> std::cout << "Enter the four components of B, separated by spaces:" << std::endl;<br /> std::cin >> b0 >> b1 >> b2 >> b3;<br /> <br /> // Calculate contraction and display result<br /> double result = contract(a0, a1, a2, a3, b0, b1, b2, b3);<br /> std::cout << "A.B = " << result << std::endl;<br /> <br /> return 0; <br />}<br /></pre><br />No major improvement there, but we've moved the contraction code out into a function so that we can reuse it. Still, it's pretty ugly to pass eight doubles into the function. Much nicer would be to pass two four-vectors; after all, that is what the contraction works with, at a higher level:<br /><pre name="code" class="cpp"><br />#include <iostream><br /><br />class FourVector {<br /> public:<br /> double x0;<br /> double x1;<br /> double x2;<br /> double x3;<br />};<br /><br />double contract(FourVector a, FourVector b)<br />{<br /> return a.x0*b.x0 - a.x1*b.x1 - a.x2*b.x2 - a.x3*b.x3;<br />}<br /><br />int main()<br />{<br /> // Create some variables<br /> Fourvector a, b;<br /> <br /> // Prompt and read eight components<br /> std::cout << "Enter the four components of A, separated by spaces:" << std::endl;<br /> std::cin >> a.x0 >> a.x1 >> a.x2 >> a.x3;<br /> std::cout << "Enter the four components of B, separated by spaces:" << std::endl;<br /> std::cin >> b.x0 >> b.x1 >> b.x2 >> b.x3;<br /> <br /> // Calculate contraction and display result<br /> double result = contract(a, b);<br /> std::cout << "A.B = " << result << std::endl;<br /> <br /> return 0;<br />}</pre><br /><br />Things are a little neater now, but still not ideal. For a start, we have public member variables in our class. This is generally considered bad design, so we should make them private and instead provide alternative mechanisms for accessing them. In this case, the class lends itself perfectly towards the use of operator overloading. The idea here is to define what it means to "multiply" two four-vectors together. We can define operator*() as a member-function of the FourVector class:<br /><pre name="code" class="cpp"><br />#include <iostream><br /><br />class FourVector {<br /> public:<br /> double x0;<br /> double x1;<br /> double x2;<br /> double x3;<br /> double operator*(const FourVector& b);<br />};<br /><br />double FourVector::operator*(const FourVector& b)<br />{<br /> return x0*b.x0 - x1*b.x1 - x2*b.x2 - x3*b.x3;<br />}<br /><br />int main()<br />{<br /> // Create some variables<br /> Fourvector a, b;<br /> <br /> // Prompt and read eight components<br /> std::cout << "Enter the four components of A, separated by spaces:" << std::endl;<br /> std::cin >> a.x0 >> a.x1 >> a.x2 >> a.x3;<br /> std::cout << "Enter the four components of B, separated by spaces:" << std::endl;<br /> std::cin >> b.x0 >> b.x1 >> b.x2 >> b.x3;<br /> <br /> // Calculate contraction and display result<br /> double result = a * b;<br /> std::cout << "A.B = " << result << std::endl;<br /> <br /> return 0;<br />}</pre><br /><br />As you can see, we have now defined enough code that the statement result = a * b; works as expected, producing the contraction of the two. The member function, when called, is bound to object a (in this case), so x0, x1, x2, x3 all refer to a's variables. We have to refer to the variables in b (passed as an argument to the operator) explicitly as b.x0 etc.<br /><br />We still haven't hidden the member variables. To do this, we need to add a couple more things: a constructor, and a stream operator.<br /><pre name="code" class="cpp"><br />#include <iostream><br /><br />class FourVector {<br /> public:<br /> FourVector() : x0(0), x1(0), x2(0), x3(0) {};<br /> FourVector(double i0, double i1, double i2, double i3)<br /> : x0(i0), x1(i1), x2(i2), x3(i3) {};<br /> double operator*(const FourVector& b);<br /> friend std::istream& operator>>(std::istream& in, FourVector& v);<br /> private:<br /> double x0;<br /> double x1;<br /> double x2;<br /> double x3;<br />};<br /><br />double FourVector::operator*(const FourVector& b)<br />{<br /> return x0*b.x0 - x1*b.x1 - x2*b.x2 - x3*b.x3;<br />}<br /><br />std::istream& operator>>(std::istream& in, FourVector& v)<br />{<br /> in >> v.x0 >> v.x1 >> v.x2 >> v.x3;<br /> return in;<br />}<br /><br />int main()<br />{<br /> // Create some variables<br /> Fourvector a, b;<br /> <br /> // Prompt and read eight components<br /> std::cout << "Enter the four components of A, separated by spaces:" << std::endl;<br /> std::cin >> a;<br /> std::cout << "Enter the four components of B, separated by spaces:" << std::endl;<br /> std::cin >> b;<br /> <br /> // Calculate contraction and display result<br /> double result = a * b;<br /> std::cout << "A.B = " << result << std::endl;<br /> <br /> return 0;<br />}<br /></pre><br />There are a few things to note here. First, the default constructor:<br /><pre name="code" class="cpp">FourVector() : x0(0), x1(0), x2(0), x3(0) {};</pre><br /><br />Constructors are named identically to the class they construct, and have no return type. This particular one takes no arguments, has an initialiser list which sets all the member variables to zero, and has an empty function body -- {};<br /><br />The other constructor allows one to construct a FourVector object by passing four doubles into the constructor:<br /><pre name="code" class="cpp"><br />double E, px, py, pz;<br />// Some code which sets E and p goes here<br />FourVector EnergyMomentum(E, px, py, pz);</pre><br /><br />Finally, operator>> is a little different. Because the order is stream >> FourVector, we can't make the operator>> a member of FourVector (since it would expect the FourVector object to be passed first!). Furthermore, we need access to the private member variables, or we have nothing to read into. This is a bit of a dilemma, until we use the `friend' statement. This tells the compiler to let a function which is defined outside the class have access to internal class members; precisely what we want here!<br /><br />You'll notice that the mechanism by which we got here is quite convoluted; we've added constructors and defined operators, and the class is far from complete -- for it to be generally useful we'd need an output operator, other mathematical operations and more. The amount of code has increased, as has the complexity of the overall solution. But look at the code inside main()... this is now considerably simpler. If we ignore comments and don't prompt the user, we can now write exactly the code which corresponds to the mathematical concept:<br /><pre name="code" class="cpp"><br />int main()<br />{<br /> FourVector a, b;<br /> std::cin >> a >> b;<br /> double result = a * b;<br /> std::cout >> result >> std::endl;<br /> return 0;<br />}</pre><br /><br />The best part is that the FourVector class is reusable, and sufficiently powerful to allow this abstraction to be carried forward to develop a whole system for tensor calculus, expressed in terms of the mathematical objects involved!Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-75928291085020889182008-09-24T08:23:00.015+01:002008-09-24T11:51:40.968+01:00Symmetries, Conserved Quantities and Noether's TheoremFollowing on from my posts on Lagrangian and Hamiltonian Mechanics [<a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-principle-of.html">1</a>, <a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler.html">2</a>, <a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler_20.html">3</a>, <a href="http://physical-thought.blogspot.com/2008/09/from-lagrangian-to-hamiltonian.html">4</a>], I'd like to discuss one of the most amazing topics in physics. The consideration of the symmetries of physical laws and how those symmetries relate to conserved quantities, the fundamentally beautiful mathematics lying beneath, and the extent to which we can develop theories of the world around us from such simple concepts; these things continually inspire me and provoke my interest.<br /><br />I'll start by showing that the formulation of Lagrangian and Hamiltonian Mechanics, thus far, allows us to determine several conservation laws. Consider, for example, the <span style="font-style: italic;">homogeneity</span> of space. Space is homogeneous if the motion (or time-evolution) of a particle (or system thereof) is independent of absolute position. That is, the potential does not vary with absolute position (it can still vary with the vector distance between two particles, as an interaction potential, for example!)<br /><br />If we make a transformation <pre style="display: inline;" lang="eq.latex">\mathbf{r}\rightarrow\mathbf{r}+\delta\mathbf{r}</pre>, then the Lagrangian will also transform as <pre style="display: inline;" lang="eq.latex">L \rightarrow L+\delta L</pre>. For a single particle, we can Taylor expand as follows:<br /><pre lang="eq.latex"><br />L(\mathbf{r}+\delta\mathbf{r},\mathbf{v}) = L(\mathbf{r},\mathbf{v})+\frac{\partial L}{\partial x}\delta x+\frac{\partial L}{\partial y}\delta y+\frac{\partial L}{\partial z}\delta z</pre><br />Which we can use to write<br /><pre lang="eq.latex">\delta L = \frac{\partial L}{\partial \mathbf{r}}\cdot\delta\mathbf{r}</pre><br /><pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial \mathbf{r}}</pre> is a vector quantity; each component is the derivative of L with respect to the corresponding coordinate of <span style="font-weight: bold;">r</span>. For a single particle, then, <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial \mathbf{r}}=\nabla L</pre>.<br /><br />Homogeneity of space requires that <pre style="display: inline;" lang="eq.latex">\delta L = 0</pre>. Since <pre style="display: inline;" lang="eq.latex">\delta \mathbf{r}</pre> is arbitrary (and therefore not necessarily zero), we have that<br /><pre lang="eq.latex"><br />\frac{\partial L}{\partial q_i} = 0 ~~~~~~ (\star)<br /></pre><br /><br />This holds only if L does not depend on absolute position, otherwise there would be a contribution <pre style="display: inline;" lang="eq.latex">\delta L</pre> from many of the possible choices of <pre style="display: inline;" lang="eq.latex">\delta\mathbf{r}</pre>. Spatial dependence of e.g. V(x) implies spatial variation of L, and momentum would not be conserved.<br /><br />The Euler-Lagrange Equation applies for each coordinate in the vector <span style="font-weight: bold;">r</span>. The sum of these Euler-Lagrange Equations (ELEs) means that <pre style="display: inline;" lang="eq.latex">(\star)</pre> requires that:<br /><pre lang="eq.latex"><br />\begin{multiline*}<br />\frac{d}{dt}\frac{\partial L}{\partial \dot{q}_i} = 0 \\<br />\Rightarrow p_i = \frac{\partial L}{\partial \dot{q}_i} ~~\mathrm{remains~constant}<br />\end{multiline*}<br /></pre><br /><br />We have, therefore, demonstrated the conservation of momentum as a result of requiring translational invariance. That is, <span style="font-style: italic;">any canonical momenta whose conjugate coordinates do not appear explicitly in the Lagrangian are conserved.</span><br /><br />Turning once again to time symmetries, let us re-derive the conservation of energy. If the Lagrangian is homogeneous in time, i.e. <pre style="display: inline;" lang="eq.latex">L(q,\dot{q})~~\mathrm{not}~~L(q,\dot{q},t)</pre>, then:<br /><pre lang="eq.latex"><br />\frac{dL}{dt} = \sum_i \frac{\partial L}{\partial q_i}\dot{q}_i + \sum_i\frac{\partial L}{\partial \dot{q}_i}\ddot{q}_i</pre><br />As L does not depend explicitly on time, there is no term <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial t}</pre> on the RHS. Sunstituting <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial q_i}</pre> from the ELE,<br /><pre lang="eq.latex"><br />\frac{dL}{dt} = \sum_i\dot{q}_i\frac{d}{dt}\frac{\partial L}{\partial\dot{q}_i}+\sum_i\frac{\partial L}{\partial\dot{q}_i}\ddot{q}_i = \sum_i\frac{d}{dt}\left(\dot{q}_i\frac{\partial L}{\partial\dot{q}_i}\right)</pre><pre lang="eq.latex"><br />\begin{multiline*}<br />\Rightarrow \frac{d}{dt}\sum_i\left( \dot{q}_i\frac{\partial L}{\partial\dot{q}_i}-L \right) = 0 \\<br />\Rightarrow H = \sum_i \dot{q}_i\frac{\partial L}{\partial \dot{q}_i} - L~~~\mathrm{remains~constant}</pre><br /><br /><span style="font-style: italic;">The conservation of energy holds for any motion in a non-time-varying external field V(x)</span><br /><br />We turn now to the isotropy of space, and show that angular momentum is conserved due to rotational invariance of the Lagrangian. Consider rotation by an angle <pre style="display: inline;" lang="eq.latex">|\delta\theta|</pre> (with a direction given by <pre style="display: inline;" lang="eq.latex">\delta\theta</pre>) about a vector. For small rotations, <pre style="display: inline;" lang="eq.latex">\mathbf{r}\rightarrow \mathbf{r}+\delta\mathbf{r}</pre>, with <pre style="display: inline;" lang="eq.latex">\delta\mathbf{r} = \delta\theta\times r</pre>. Each component of the velocity is also transformed by this rotation, <pre style="display: inline;" lang="eq.latex">\delta\mathbf{v}=\delta\theta\times\mathbf{v}</pre>.<br /><br />For a single body, we now impose the requirement that the Lagrangian be unchanged under such a rotation (i.e. we require space to be isotropic).<br /><pre lang="eq.latex">\delta L = \sum_i\left( \frac{\partial L}{\partial q_i}\cdot\delta r_i + \frac{\partial L}{\partial\dot{q}_i}\cdot\delta v_i \right) = 0</pre><br /><br />We can replace <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial v_i}</pre> by the vector canonical momentum <pre style="display: inline;" lang="eq.latex">p_i</pre>, and <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial q_i}</pre> by <pre style="display: inline;" lang="eq.latex">\dot{p}_i</pre>, leaving:<br /><pre lang="eq.latex">\begin{multiline*}<br />\left(\dot{\mathbf{p}}\cdot\delta\mathbf{r} + \mathbf{p}\cdot\delta\mathbf{v}\right) = 0 \\<br />\Rightarrow \dot{\mathbf{p}}\cdot\left(\delta\theta\times \mathbf{r}\right) + \mathbf{p}\cdot\left(\delta\theta\times\mathbf{v}\right) = 0<br />\end{multiline*}<br /></pre><br /><br />Since <pre style="display: inline;" lang="eq.latex">\mathbf{a}\cdot\left(\mathbf{b}\times\mathbf{c}\right) = \mathbf{b}\cdot\left(\mathbf{c}\times\mathbf{a}\right)</pre>,<br /><pre lang="eq.latex"><br />\begin{multiline*}<br />\delta\theta\cdot\left(\left[\mathbf{r}\times\dot{\mathbf{p}}\right]+\left[\mathbf{v}\times\mathbf{p}\right]\right)=0\\<br />\Rightarrow\delta\theta\cdot\frac{d}{dt}\left(\mathbf{r}\times\mathbf{p}\right)=0\end{multiline*}</pre><br /><br />Since <pre style="display: inline;" lang="eq.latex">\delta\theta</pre> is arbitrary, this requires that <pre style="display: inline;" lang="eq.latex">\mathbf{r}\times\mathbf{p}</pre> does not change in time, hence angular momentum is a conserved quantity.<br /><br /><span style="font-weight: bold;">Hamilton's Equations</span><br />Using the ideas presented above, I'm going to take a moment to derive Hamilton's Equations, which will prove useful later on.<br /><br />Consider changes in the Lagrangian L, according to<br /><pre lang="eq.latex">dL = \sum_i\frac{\partial L}{\partial\dot{q}_i}\,d\dot{q}_i + \sum_i\frac{\partial L}{\partial q_i}\,dq_i</pre><br />This can be written:<br /><pre lang="eq.latex">dL=\sum_ip_i\,d\dot{q}_i+\sum_i\dot{p}_i\,dq_i</pre><br />since <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial q_i}=\dot{p}_i</pre> and <pre style="display: inline;" lang="eq.latex">\frac{\partial L}{\partial\dot{q}_i}=p_i</pre>.<br />Using,<br /><pre lang="eq.latex">\sum_i p_i\,d\dot{q}_i = d\left(\sum_i p_i q_i\right) - \sum_i\dot{q}_i\,dp_i</pre>,<br /><pre lang="eq.latex"><br />d\left(\sum_i p_i\dot{q}_i - L\right) = -\sum_i\dot{p}_i\,dq_i+\sum_i\dot{q}_i\,dp_i</pre><br />The argument of the differential on the left is the Hamiltonian, H, <pre style="display: inline;" lang="eq.latex">H(q,p,t)=\sum_i p_i\dot{q}_i - L</pre>, therefore:<br /><pre lang="eq.latex">dH = -\sum_i\dot{p}_i\,dq_i + \sum_i\dot{q}_i\,dp_i</pre><br /><br />From here, we can obtain Hamilton's Equations:<br /><pre lang="eq.latex">\begin{align*}<br />\dot{q}_i &= \frac{\partial H}{\partial p_i}\\<br />\dot{p_i} &= \frac{\partial H}{\partial q_i}<br />\end{align*}</pre><br /><br />For m coordinates (and m momenta), Hamilton's Equations form a system of 2m first-order differential equations, compared to the m second-order equations in the Lagrangian treatment.<br /><br />The total time derivative,<br /><pre lang="eq.latex"><br />\frac{dH}{dt}=\frac{\partial H}{\partial t}+\sum_i\frac{\partial H}{\partial q_i}\dot{q}_i+\sum_i\frac{\partial H}{\partial p_i}\dot{p}_i</pre><br />Substituting Hamilton's equations for <pre style="display: inline;" lang="eq.latex">\dot{q}_i, \dot{p}_i</pre>, the last two terms cancel, so<br /><pre lang="eq.latex">\frac{dH}{dt} = \frac{\partial H}{\partial t}</pre><br />and if H does not depend <span style="font-style: italic;">explicitly</span> on time, <pre style="dispay: inline;" lang="eq.latex">\frac{dH}{dt}=0</pre> and energy is conserved!<br /><br /><span style="font-weight: bold;">Noether's Theorem</span><br />The three conserved quantities above were shown to be related to the invariance of the Lagrangian under some symmetry transformation:<br /><ul><li>Translational invariance (homogeneity of space) ==> Conservation of momentum</li><li>Rotational invariance (isotropy of space) ==> Conservation of angular momentum</li><li>Time invariance (homogeneity of time) ==> Conservation of energy</li></ul><br />Noether's Theorem states that any differentiable symmetry of the Action (integral of the Lagrangian) of a physical system has a corresponding conservation law.<br /><br /><span style="font-style:italic;">To every differentiable symmetry generated by local actions, there corresponds a conserved current.</span><br /><br />`Symmetry' here, refers to the covariance of the form of a physical law with respect to a Lie group of transformations; the conserved quantity is known as a <span style="font-style:italic;">charge</span> and the flow carrying it as a <span style="font-style:italic;">current</span> (c.f. electrodynamics).<br /><br />Noether's Theorem, which I will discuss in more detail at a later date, is another critical component used to build gauge theories. The key thing to remember right now is that a symmetry (invariance) of the Lagrangian corresponds to a conserved quantity; we can use this result to look for the underlying symmetry behind quantities we know to be conserved (for example, electric charge).Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-35013102515437452312008-09-22T14:38:00.002+01:002008-09-22T15:06:43.365+01:00Feedback on `Writing Scientific Documents Using LaTeX'Since I submitted my article <span style="font-style: italic;">Writing Scientific Documents Using LaTeX</span> to CTAN, I've had several emails offering comments, suggestions and improvements. I plan on taking all of these into account for the next edition, which should be available sometime soon. Meanwhile, I thought I'd just post a little about some of the suggestions here.<br /><br />The single most common suggestion was that I replace the use of <span style="color: rgb(153, 0, 0);">$$ ... $$</span> to delimit displayed mathematics with the <span style="color: rgb(153, 0, 0);">\[ ... \]</span> form. The dollar-variant is apparently deprecated, and the newer square bracket style preferred. The reason for this, as given in <a href="http://www.ctan.org/tex-archive/info/l2tabu/">http://www.ctan.org/tex-archive/info/l2tabu/</a>, is that the <span style="color: rgb(153, 0, 0);">$$ </span>form is a plain TeX command, and should be avoided in LaTeX due to inconsistencies. Check the l2tabu document for more details.<br /><br />Another frequent comment was that the <span style="font-style: italic;">eqnarray</span> environment is bad, and should always be replaced by the <span style="font-style: italic;">align</span> or similar, from the <span style="font-style: italic;">amsmath</span> package. I originally thought I'd leave a discussion of <span style="font-style: italic;">eqnarray</span> in there for reference, but now it seems better to remove it entirely.<br /><br />Other comments related to minor corrections and requests for additional explanation in some sections, expanded coverage of BibTeX and more details on table design.<br /><br />As I said above, I plan to incorporate all of these suggestions into the 5th Edition of the article.Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-46580888766520409172008-09-22T13:19:00.011+01:002008-09-22T14:32:27.367+01:00From Lagrangian to Hamiltonian MechanicsIf the Lagrangian L does not depend explicitly on time, and varies with time only through the time-dependence of the coordinate q (and its time derivative), then we can define a constant of motion known as the Hamiltonian, H.<br /><br />That is, if<br /><pre lang="eq.latex"><br />\begin{align*}<br />L = L(q(t),\dot{q}(t)) \\<br />\mathrm{not}~~L = L(q(t), \dot{q}(t), t)<br />\end{align*}<br /></pre><br />then the Hamiltonian H can be defined as<br /><pre lang="eq.latex">H = \dot{q}\frac{\partial L}{\partial \dot{q}} - L</pre><br /><br />For the simplest example of a particle of mass m, moving through a potential V(x), with velocity v = dx/dt, we have <pre style="display: inline;" lang="eq.latex">L = \frac{m\dot{x}^2}{2} - V(x) = T - V</pre>. Using the above definition of the Hamiltonian, <pre style="display: inline;" lang="eq.latex">H = \frac{m\dot{x}^2}{2} + V(x)</pre> which can be identified as the <span style="font-style: italic;">total energy</span>. Since H is a constant of motion, this result corresponds to <span style="font-style: italic;">conservation of energy!</span><br /><br />More generally,<br /><pre lang="eq.latex">\frac{dH}{dt}=\frac{d}{dt}\left(\dot{x}\frac{\partial L}{\partial\dot{x}}\right)-\frac{\partial L}{\partial\dot{x}}\frac{d\dot{x}}{dt}-\frac{\partial L}{\partial x}\frac{dx}{dt}</pre><pre lang="eq.latex">= v\left( \frac{d}{dt}\frac{\partial L}{\partial \dot{x}} - \frac{\partial L}{\partial x}\right) = 0</pre><br />since the last term inside the brackets vanishes (it's the Euler-Lagrange Equation!)<br /><br />Note that if L depends explicitly on time, the above does not hold, and we lose conservation of energy; here, energy can be `used' in thermodynamically irreversible processes. Of course, if we expanded the Lagrangian to take into account a large enough system, we regain conservation of energy for the universe as a whole!<br /><br />The Hamiltonian H is an <span style="font-style: italic;">integral of the motion</span>, since<br /><pre lang="eq.latex">\frac{dH}{dt} = 0 \Rightarrow \int_{t_0}^{t_1}\frac{dH}{dt}\,dt = \left[H\right]_{t_0}^{t_1} = 0</pre><br />It contains only first-order time derivatives of the coordinate q, whereas the Euler-Lagrange equation contains second-order time derivatives, <pre style="display: inline;" lang="eq.latex">\frac{d}{dt}\frac{\partial L}{\partial \dot{q}}</pre>.<br /><br />As an example of determining the Hamiltonian from a Lagrangian, I'd like to look at the case of Special Relativity (SR). There are two reasons for this... first, the SR Lagrangian looks a bit different from the usual T - V form of classical mechanics. Secondly, Special Relativity will feature prominently in a number of future posts as I start to direct the methods of Lagrangian and Hamiltonian mechanics towards describing gauge theories.<br /><br />The SR Lagrangian in a potential V(x) is given by<br /><pre lang="eq.latex">L = \frac{-mc^2}{\gamma} - V(x) = -mc^2\sqrt{1-\frac{v^2}{c^2}} - V(x)</pre><br />where I have used <pre style="display: inline;" lang="eq.latex">v = \dot{x} = \frac{dx}{dt}</pre> and have referred to the rest mass as simply m, while many books use the notation m_0.<br /><br />The Hamiltonian H can be found as<br /><pre lang="eq.latex">\begin{multiline*}<br />H = v\frac{\partial L}{\partial v} - L\\<br />= \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}} + V(x)\\<br />= \gamma mc^2 + V(x)<br />\end{multiline*}</pre><br />The last line is readily identified as the total relativistic energy of a particle of rest mass m in a potential V(x), so our interpretation of the Hamiltonian holds!<br /><br /><span style="font-weight: bold;">Canonical Momenta</span><br />I'd like to take a moment now to introduce some new nomenclature and notation, and to explain why it is useful here.<br /><br />First, a reminder that the Euler-Lagrange equation for a coordinate q can be written as<br /><pre lang="eq.latex">\frac{d}{dt}\frac{\partial L}{\partial \dot{q}} = \frac{\partial L}{\partial q}</pre><br /><br />We can define a quantity p, known as the <span style="font-style: italic;">canonical momentum conjugate to the coordinate q</span>, as follows<br /><pre lang="eq.latex">p=\frac{\partial L}{\partial \dot{q}}</pre><br /><br />and a quantity F, known as the <span style="font-style: italic;">canonical force conjugate to the momentum p</span>, as<br /><pre lang="eq.latex">F = \frac{\partial L}{\partial q}</pre><br />These follow the usual definitions such that <pre style="display: inline;" lang="eq.latex">T = \frac{p^2}{2m}</pre> and <pre style="display: inline;" lang="eq.latex">F = -\nabla V</pre>, since the Lagrangian L = T - V.<br /><br />Written in this form, the Euler-Lagrange Equation directly represents Newton's 2nd Law:<br /><pre lang="eq.latex">F = \dot{\mathbf{p}}</pre><br /><br />For multiple coordinates <pre style="display: inline;" lang="eq.latex">q_i</pre>, the Hamiltonian H is given by<br /><pre lang="eq.latex"><br />H = \sum_i p_i \dot{q}_i - L<br /></pre><br />where <pre style="display: inline;" lang="eq.latex">p_i</pre> is the canonical momentum conjugate to the coordinate <pre style="display: inline;" lang="eq.latex">q_i</pre>.<br /><br />Introducing the concept of canonical momentum conjugate to a coordinate is essential for the future posts I'd like to make on this blog. The reason for this is that when I discuss quantum field theory, the concepts introduced above will play an essential role in the procedure. More on this later!<br /><br />Meanwhile, although I provided a couple of classical mechanics examples for the use of the Lagrangian, in order to introduce the concept at a level that most people can understand from the world around them, I will refrain from posting similar examples making use of the Hamiltonian, since I wish to progress to more complicated topics.<br /><br />In order to illuminate the path from here to a discussion of gauge theories, I'd like now to simply list some of the topics I must first cover. As such, the interested reader will notice any such posts! I anticipate that this list will be incomplete, and that I will need to cover certain topics in a lot more detail than others.<br /><ol><li>Symmetries and Noether's Theorem (some of this)<br /></li><li>Special Relativity in four-vector formulation (lots of this)<br /></li><li>Relativistic electrodynamics (not much of this)</li><li>Relativistic Quantum Mechanics (I've already discussed the Klein-Gordon equation, but I'll go over this and other aspects, again)</li><li>Spin & Relativity (Pauli matrices and the gamma matrices)</li><li>The Dirac Equation (in some detail!)</li><li>U(1) symmetries and the Gauge Principle</li><li>Quantum Electrodynamics</li><li>SU(2) and Electroweak Unification</li><li>Aside on Superconductivity (which may be omitted)<br /></li><li>Spontaneous Symmetry Breaking and the Higgs Mechanism</li></ol><br /><br />I expect those posts to take some considerable time. I've spent at least two weeks discussing Lagrangian mechanics, and we have a long way to go before I can introduce the Higgs mechanism, which is the ultimate goal of this entire series of posts. The idea is that anyone with a basic grounding in physics and mathematics should be able to learn enough about Lagrangian & Hamiltonian Mechanics, Quantum Mechanics and Special Relativity to be able to appreciate the formulation of the gauge theories of the Standard Model of Particle Physics, and to go a little beyond that and get a look at the Higgs mechanism. Let's hope I make it to the end!Andrew J. Benniestonnoreply@blogger.com1tag:blogger.com,1999:blog-4470666517647633822.post-70320866670985665772008-09-20T12:06:00.008+01:002008-09-21T21:22:02.785+01:00Lagrangian Mechanics: From the Euler-Lagrange Equation to Simple Harmonic MotionI already wrote about <a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-euler.html">obtaining Newton's Laws from the Principle of Least Action</a>. Now I'm going to analyse a simple mass-spring system; effectively just a case of substituting in a suitable potential for the spring.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zi39n2uYgqg/SNTZmdsm93I/AAAAAAAAAMo/KyX6IuJ0x6M/s1600-h/spring.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_zi39n2uYgqg/SNTZmdsm93I/AAAAAAAAAMo/KyX6IuJ0x6M/s400/spring.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5248058720623458162" /></a><br /><br />Let us go through all of the steps, once more. We'll choose our coordinate x to be the displacement from the equilibrium length of the spring, as shown on the diagram. The kinetic energy of the moving mass is then just <pre lang="eq.latex" style="display: inline;">T=\frac{m\dot{x}^2}{2}</pre>. The potential of a spring stretched (or compressed) x metres from its equilibrium length is given by <pre lang="eq.latex" style="display: inline;">V=\frac{kx^2}{2}</pre>, where k is the spring constant (N m^-1).<br /><br />So, for our mass-spring system, the Lagrangian is<br /><pre lang="eq.latex"><br />L = \frac{1}{2}\left(m\dot{x}^2 - kx^2\right)}<br /></pre><br /><br />Applying the Euler-Lagrange equation, we obtain<br /><pre lang="eq.latex"><br />\begin{multiline*}<br />-kx - \frac{d}{dt}\left(m\dot{x}\right) = 0 \\<br />\Rightarrow \ddot{x} - \frac{k}{m}x = 0<br />\end{multiline*}<br /></pre><br /><br />Comparing the last line above with the general form of <a href="http://en.wikipedia.org/wiki/Simple_harmonic_motion">Simple Harmonic Motion</a> (SHM), <pre lang="eq.latex" style="display: inline;">\ddot{q} - \omega^2 q = 0</pre> we can see that the equation of motion rendered by applying the Euler-Lagrange equation to the Lagrangian of a mass-spring system provides Simple Harmonic Motion with a frequency<br /><pre lang="eq.latex"><br />\omega = \sqrt{\frac{k}{m}}<br /></pre><br /><br />This is as expected for the case of a mass-spring system!Andrew J. Benniestonnoreply@blogger.com3tag:blogger.com,1999:blog-4470666517647633822.post-76069134647838413432008-09-19T14:08:00.006+01:002008-09-19T14:37:14.206+01:00Lagrangian Mechanics: From the Euler-Lagrange Equation to Newton's LawsLast week I <a href="http://physical-thought.blogspot.com/2008/09/lagrangian-mechanics-from-principle-of.html">wrote about the Euler-Lagrange Equation</a>, and how it can be obtained from the Principle of Least Action. Today, I'd like to show that this equation is consistent with Newtonian Mechanics.<br /><br />For reference, the Euler-Lagrange equation for some arbitrary coordinate q is:<pre lang="eq.latex"><br />\frac{\partial L}{\partial q} - \frac{d}{dt}\frac{\partial L}{\partial \dot{q}} = 0<br /></pre><br /><br />L, the Lagrangian, is the kinetic energy of a system minus the potential.<br /><br />Let us now consider the case of a free particle of mass m, moving in a potential V(x). The particle's instantaneous speed is given by <pre lang="eq.latex" style="display: inline;">v = \frac{dx}{dt}=\dot{x}</pre>. The kinetic energy is the familiar <pre lang="eq.latex" style="display: inline;">T=\frac{1}{2}m\dot{x}^2</pre>.<br /><br />Applying the Euler-Lagrange Equation, we have:<br /><pre lang="eq.latex"><br />\begin{align*}<br />\frac{\partial L}{\partial x} = -\frac{\partial V(x)}{\partial x} \\<br />\mathrm{and}~~\frac{\partial L}{\partial \dot{x}} = m\dot{x} \\<br />\Rightarrow \frac{d}{dt}\frac{\partial L}{\partial \dot{x}} = m\ddot{x}<br />\end{align*}<br /></pre><br /><br />Putting these together, we have:<br /><pre lang="eq.latex"><br />\begin{align*}<br />-\frac{\partial V(x)}{\partial x} - m\ddot{x} = 0 \\<br />\Rightarrow m\ddot{x} = -\frac{\partial V}{\partial x}<br />\end{align*}<br /></pre><br /><br />The right-hand side is the gradient of a potential energy (in 1D). Force can be defined in terms of the gradient of a potential V:<br /><pre lang="eq.latex"><br />F = -\nabla V<br /></pre><br />And since <pre lang="eq.latex" style="display: inline;">\ddot{x} = \frac{d^2 x}{dt^2}</pre> is acceleration, a, the result of applying the Euler-Lagrange equation to a classical-mechanical Lagrangian is the familiar form of Newton's Second Law:<br /><pre lang="eq.latex"><br />F = ma<br /></pre><br /><br />In other words, applying the Euler-Lagrange equation to a suitable Lagrangian provides an equation of motion!Andrew J. Benniestonnoreply@blogger.com1tag:blogger.com,1999:blog-4470666517647633822.post-41065521912318925002008-09-16T23:53:00.003+01:002008-09-16T23:57:37.515+01:00Writing Scientific Documents Using LaTeX: Permanent home on CTANFollowing the suggestion of someone who commented on my <a href="http://physical-thought.blogspot.com/2008/09/writing-scientific-documents-using.html">previous post</a> about my article <span style="font-style:italic;">Writing Scientific Documents Using LaTeX</span>, I submitted the PDF and TeX source to <a href="http://www.ctan.org/">CTAN</a>, the Comprehensive Tex Archive Network. After changing the license to the <a href="http://www.latex-project.org/lppl/">LPPL</a>, it was accepted into the archive.<br /><br />As a result, the PDF can now be found permanently at the following location:<br /><a href="http://www.ctan.org/get/info/intro-scientific/scidoc.pdf">http://www.ctan.org/get/info/intro-scientific/scidoc.pdf</a><br /><br />The CTAN entry is at <a href="http://www.ctan.org/tex-archive/info/intro-scientific/">http://www.ctan.org/tex-archive/info/intro-scientific/</a>Andrew J. Benniestonnoreply@blogger.com2tag:blogger.com,1999:blog-4470666517647633822.post-41546521750615970132008-09-14T23:40:00.005+01:002008-09-15T00:01:53.070+01:00Lagrangian Mechanics: From the Principle of Least Action to the Euler-Lagrange EquationA quantity known as the Action, A is defined as<br /><pre lang="eq.latex"><br />A = \int L \,dt<br /></pre><br />where L is known as the Lagrangian. The simplest Lagrangian is given as the kinetic energy T of a system minus the potential energy V of the system:<br /><pre lang="eq.latex"><br />L(x,t) = T(x,t) - V(x,t)<br /></pre><br /><br />By extremising the Action (minimising it, in this case) we can obtain the Euler-Lagrange Equation, a key equation for Lagrangian and Hamiltonian mechanics. The concept is also used extensively in quantum mechanics and particle physics, particularly when dealing with gauge theories.<br /><br />Consider an extremised path x(t) from a point x(t0) to a point x(t1), and some excursion from this path, as shown in the figure below. The excursion is given by some small function a(t), and the velocity is changed accordingly:<br /><pre lang="eq.latex"><br />\begin{align*}<br />x(t) \rightarrow x(t) + a(t) \\<br />v(t) \rightarrow v(t) + \dot{a}(t)<br />\end{align*}<br /></pre><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_zi39n2uYgqg/SM2UZHRV5mI/AAAAAAAAAMg/pU_OkTw1J-c/s1600-h/paths.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_zi39n2uYgqg/SM2UZHRV5mI/AAAAAAAAAMg/pU_OkTw1J-c/s400/paths.jpg" alt="" id="BLOGGER_PHOTO_ID_5246012300125922914" border="0" /></a><br /><br />If we take x(t) to be the extremal path from x(t0) to x(t1), with the end-points fixed, and a(t) to be some small but general excursion from that path which must pass through the end-points, we can assert that:<br /><pre lang="eq.latex"><br />a(t_0) = a(t_1) = 0<br /></pre><br /><br />The Lagrangian will be changed as a result of these excursions. To first-order in small a(t), the Lagrangian transforms as:<br /><pre lang="eq.latex"><br />\begin{align*}<br />L(x,v) \rightarrow L(x+a, v+\dot{a}) \\<br />= L(x, v) + a(t)\frac{\partial L}{\partial x} + \dot{a}(t)\frac{\partial L}{\partial v}<br />\end{align*}<br /></pre><br /><br />The Action therefore transforms according to <pre lang="eq.latex" style="display: inline;">A \rightarrow A + \delta A</pre> where:<br /><pre lang="eq.latex"><br />\delta A = \int_{t_0}^{t_1}\,dt \left( a(t)\frac{\partial L}{\partial x} + \frac{da}{dt}\frac{\partial L}{\partial v} \right)<br /></pre><br /><br />The second term in the brackets above can be integrated by parts:<br /><pre lang="eq.latex"><br />\int_{t_0}^{t_1}\,dt \frac{da}{dt}\frac{\partial L}{\partial v} = \left[ a(t)\frac{\partial L}{\partial v} \right]_{t_0}^{t_1} - \int_{t_0}^{t_1}dt\,a(t)\frac{d}{dt}\frac{\partial L}{\partial v}<br /></pre><br />Since a(t0) = a(t1) = 0, the integrated part (in square brackets) vanishes, leaving the following form for delta A:<br /><pre lang="eq.latex"><br />\delta A = \int dt\,a(t)\left(\frac{\partial L}{\partial x} - \frac{d}{dt}\frac{\partial L}{\partial v}\right)<br /></pre><br /><br />For arbitrary a(t), to minimise the action (by having delta A zero), the part in brackets must be zero. This is the Euler-Lagrange Equation, rewritten for a generalised coordinate q (in place of x) and using the time-derivative of q in place of the velocity v, above:<br /><pre lang="eq.latex"><br />\frac{\partial L}{\partial q} - \frac{d}{dt}\frac{\partial L}{\partial \dot{q}} = 0<br /></pre><br /><br />As I mentioned above, the Euler-Lagrange Equation is critical for the understanding of several aspects of quantum mechanics and gauge theories. Since I plan on making posts about some of these topics in the future, I felt I should begin by explaining Lagrangian mechanics, rather than jumping in at the deep end.Andrew J. Benniestonnoreply@blogger.com2tag:blogger.com,1999:blog-4470666517647633822.post-5592682022785291292008-09-14T00:33:00.006+01:002008-09-14T22:53:05.272+01:00Two-Column Layouts in LaTeXI was recently asked about using LaTeX to create the two-column layout often seen in scientific journals. I used this layout in some lab reports and project reports.<br /><br />The first thing to do is to include the <a href="http://www.ctan.org/tex-archive/help/Catalogue/entries/multicol.html"><span style="font-style: italic;">multicol</span></a> package in your preamble:<pre>\usepackage{multicol}</pre><br />After that, to place text within a multi-column layout, start the <span style="font-style: italic;">multicols</span> environment (note the s at the end!) and specify the number of columns you'd like:<pre>\begin{multicols}{2}</pre><br />Finally, end the multi-column layout with:<pre>\end{multicols}<br /></pre><br />It's as simple as that! Any sections, subsections, equations etc. between the two will now be automatically formatted into two columns.<br /><br />There are, however, a few caveats and points to note for formatting considerations.<br /><br />The first thing to note is that the abstract is often formatted as a single column. To do this, simply place the <span style="color: rgb(153, 0, 0);">\begin{multicols}{2}</span> command below your abstract, but above the first <span style="color: rgb(153, 0, 0);">\section</span> command.<br /><br />Secondly, I usually typeset references within the two-column layout. To do this, end the <span style="font-style: italic;">multicols</span> environment after your references section.<br /><br />Finally, and most importantly, graphics and tables do not always work well with multi-column environments. In order to achieve reasonable results, I used a few workarounds.<br /><br />If the graphic is large, or has small text, set it normally and it will float outside of the column layout, spanning both columns. For smaller figures, you can create an adjusted figure or table environment which forces LaTeX to set the figure in the column, at the point you typed it in the source text. This is not always what you want, but a reasonable layout can usually be obtained by playing with the exact positioning of the table or graphic commands in the source.<br /><br />The following, inserted into the preamble, defines two new environments, <span style="font-style: italic;">tablehere</span> and <span style="font-style: italic;">figurehere</span>, which insert tables and figures inline with the column text.<br /><pre>% Figures within a column...<br />\makeatletter<br />\newenvironment{tablehere}<br />{\def\@captype{table}}<br />{}<br />\newenvironment{figurehere}<br />{\def\@captype{figure}}<br />{}<br />\makeatother<br /></pre>In addition to this, you'll probably need to scale graphics to the column width. This can be achieved with the \resizebox command inside a <span style="font-style: italic;">figure</span> or our new <span style="font-style: italic;">figurehere</span> environment. For example,<br /><pre>\begin{figurehere}<br />\centering<br />\resizebox{\columnwidth}{!}{\includegraphics{gf-graphs.eps}}<br />\caption{\label{gf-graphs}Graph showing applied RF frequency against magnetic field from the sweep coils, the gradient of the lines reveals information about $g_f$ for each isotope. The left gradient, corresponding to \chem{^{85}{Rb}} is $7.73 \times 10^9 (\pm 1.5 \times 10^8)$. The right gradient, corresponding to \chem{^{87}{Rb}}, is $5.24 \times 10^9 (\pm 6.00 \times 10^7)$ }<br />\end{figurehere}<br /></pre><br /><span style="color: rgb(153, 0, 0);">\columnwidth</span> is defined by the <span style="font-style: italic;">multicol</span> package to be the width of a text-column!Andrew J. Benniestonnoreply@blogger.com13tag:blogger.com,1999:blog-4470666517647633822.post-31476996252563616122008-09-13T23:33:00.002+01:002008-09-13T23:40:04.069+01:00Writing Scientific Documents Using LaTeXBack in 2007, I wrote a short document describing some of the basic LaTeX commands and explaining how to go about creating a document using LaTeX. I did this because I was writing third year lab reports collaboratively with my lab partners (as per the regulations for the third year lab at Warwick) and I wanted us all to be using LaTeX, so the reports would look good and so that editing the sections together would be easier. In order to do this, though, I had to educate my lab partners in the use of LaTeX.<br /><br />Since then, the document has been read (and requested!) by other physicists, scientists and mathematicians at Warwick and in the wider world. I've updated it several times to add content and to correct minor mistakes. It was not until this week, however, that someone suggested I put it online and make it freely available to anyone who wants it (and can find it).<br /><br />So, I spent a while tonight polishing it up, adding a few more subsections, and creating what is now the 13-page Fourth Edition. It is available online at <a href="http://www.physical-thought.com/scidoc.pdf">http://www.physical-thought.com/scidoc.pdf</a>Andrew J. Benniestonnoreply@blogger.com2tag:blogger.com,1999:blog-4470666517647633822.post-81600299715662767042008-08-17T14:43:00.003+01:002008-08-17T17:10:13.887+01:00Surf Photography: Rip Curl Boardmasters 2008I took this on Thursday August 7th, 2008 at Fistral Beach, Newquay Cornwall. The Rip Curl Boardmasters is a surf competition and festival which has been at Fistral for as long as I can remember, and it's a great atmosphere.<br /><br />This was taken at the 300mm end of my 70-300mm lens with a shutter speed of 1/640 s, aperture f/8.0 and ISO 200. It was subsequently adjusted in Photoshop to improve the contrast a little, then cropped to remove a bit of empty sea.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_zi39n2uYgqg/SKgsD9ulTZI/AAAAAAAAALk/gFTtmbYqf18/s1600-h/img_3673-cropped.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_zi39n2uYgqg/SKgsD9ulTZI/AAAAAAAAALk/gFTtmbYqf18/s400/img_3673-cropped.jpg" alt="" id="BLOGGER_PHOTO_ID_5235483013439376786" border="0" /></a>Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-6151819659759025832008-08-17T13:12:00.003+01:002008-08-17T13:26:36.833+01:00Pebble v1 Call GraphFollowing up on my recent post about a C++ implementation of the Mersenne Twister pseudo-random number generator (PRNG), I decided to find out just how much the performance of the PRNG actually affects a Monte Carlo system such as Pebble. Clearly, the random number generation is a critical part of the procedure, but as I'm about to show, it is definitely not the slowest part of Pebble, by a long way.<br /><br />The <a href="http://valgrind.org/">valgrind</a> tool allows a programmer to check their programs for many things, including memory leaks (the original goal of the valgrind project). One of the neat things it does is function call profiling and graphing. The idea is simple, you run a program inside valgrind using the <span style="font-style: italic;">callgrind</span> option, and it tracks every function call made within the program. This lets you figure out how many times a function is being called, and how much of the program execution time is spent within a given function, allowing you to easily profile the code and determine functions or classes which are good candidates for optimisation.<br /><br />Here is the call graph for Pebble v1, which uses a C++ implementation of the Mersenne Twister which I wrote last summer, rather than the new one I have recently posted about.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zi39n2uYgqg/SKgXCoVV7HI/AAAAAAAAALc/RZksgZOfUzo/s1600-h/pebble.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_zi39n2uYgqg/SKgXCoVV7HI/AAAAAAAAALc/RZksgZOfUzo/s400/pebble.png" alt="" id="BLOGGER_PHOTO_ID_5235459900772314226" border="0" /></a><br /><span style="font-size:85%;">(Click for larger version)<br /></span></div><br /><br />The random number generation, performed by <span style="color: rgb(0, 102, 0);">Pebble::Math::Random::MersenneTwister::getDouble</span> and <span style="color: rgb(0, 102, 0);">getLong</span>, account for a mere 3.33% of the time spent in the event generator function <span style="color: rgb(0, 102, 0);">Pebble::EventGenerator::generate</span>. In contrast, finding minima of the probability distribution functions (using <span style="color: rgb(0, 102, 0);">Pebble::Math::Utility::Minimiser::getMinimum</span>) accounts for 31.29%, and integrating the PDFs for normalisation purposes (using <span style="color: rgb(0, 102, 0);">Pebble::Math::Calculus::RombergIntegrator::integrate</span>) accounts for 50.82% of the time spent generating events.<br /><br />It is clear from this that, if I want to improve on the speed of generation in "Pebble v2", I need to focus my efforts on efficient minimia-finding and numerical integration functions.<br /><br />There is also 7.47% of the time taken to generate events spent adding particles to an Event object, using the <span style="color: rgb(0, 102, 0);">Pebble::Event::addParticle</span> function. A lot of this time is accounted for by the memory allocation, and as I mentioned in my previous post, eliminating such object-oriented extravagances, while maintaining a sensible object-oriented design for the important parts of the program, should help to boost the speed of any new version.Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-33040060693692955132008-08-15T16:21:00.004+01:002008-08-15T16:51:19.250+01:00Mersenne TwisterA key part of the Pebble program was the ability to generate lots of good-quality pseudo-random numbers for Monte Carlo (MC). The <a href="http://www.math.sci.hiroshima-u.ac.jp/%7Em-mat/MT/emt.html">Mersenne Twister</a> (MT) algorithm is ideally suited to this, and is indeed the algorithm we used. The original author, Makoto Matsumoto, has published C source for the algorithm, which I converted into a C++ class for the project, using the same interface as several other random number generators (RNGs) provided within Pebble.<br /><br />So, following my post yesterday about considering building a "Pebble v2" or similar, I've spent the afternoon looking back into Mersenne Twister. The C code is fairly small, and reasonably easy to understand (surprisingly for something as complicated as a PRNG!) and I had no difficulty converting it to C++ the first time around. This time, I've ignored a lot of the complicated interface I built in the first time, since I no longer intend to provide other RNGs -- Mersenne Twister is more than good enough for any MC purposes.<br /><br />Anyway, I modified the MT code to encapsulate it in a C++ class (code below), then ran some timing tests against the C version. In order to get useful timing data, I had to generate 1 million integers and 1 million real numbers, timing the program run for the entire thing. A real number is generated from a single integer, so this is roughly equivalent to two million integer number generations, plus a little overhead in converting half of them to a number between 0 and 1.<br /><br />For the purposes of this test, I removed all the program output code from both the original C code and my new C++ version, timing the programs as they generated and threw away two million random numbers. The reason for removing output code was to prevent any skew in the results from the different output systems used by C and C++.<br /><br />The test itself consisted of running a program to generate 1M integers and 1M reals, using the C or C++ versions of the MT algorithm, respectively. Each test was run ten times, using the bash <span style="font-style: italic;">time</span> command to provide timing details. I discarded the <span style="font-style: italic;">real</span> time taken, which refers to what is known as wall time -- the amount of actual elapsed time according to a clock on the wall -- and focused only on the user and system times, which are the number of seconds the CPU actually spent running the program in user-space and in system-calls, respectively.<br /><br />The graph below shows the results. Both are incredibly fast, with the slowest taking a mere 0.156 seconds of CPU time. If I can generate two million random numbers in 0.2 seconds, this will certainly not be a bottleneck in any MC system!<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_zi39n2uYgqg/SKWij9yJTtI/AAAAAAAAALU/EWdB85NQC0U/s1600-h/mt-graph.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_zi39n2uYgqg/SKWij9yJTtI/AAAAAAAAALU/EWdB85NQC0U/s400/mt-graph.png" alt="" id="BLOGGER_PHOTO_ID_5234768880652078802" border="0" /></a><br /><span style="font-size:85%;">(Click image for larger version)<br /></span></div><br />The comparison, however, is slightly discouraging. The system times are incredibly low, 0.002 and 0.001 seconds for C and C++ respectively, averaged over ten runs. This is almost certainly because I removed all of the I/O, so the only time spent in the "system" would be the initial memory allocation and the final deallocation. In fact, I'd expect the C++ variant to take longer here, as the MersenneTwister object must be constructed. Still, these times are so close to zero it's hard to talk about them meaningfully.<br /><br />The "user" times tell a different story. These are also averaged over ten runs, and show that the C++ version took almost twice as long as the C version. I expected there to be a little overhead from dynamically allocating the array used to store the internal state of the MT generator, but that should be a one-time thing, and the rest of the code is almost identical. I can only assume that the discrepancy arises from the function calls being mapped to member functions in C++ rather than global functions in C.<br /><br />Many would argue that the factor of 2 slowdown is completely unacceptable, even if the C++ version does hide the details of MT (no defines, no global variables, just a few member variables). I agree that the reduction in speed is quite dramatic here, but compared to other components of a functioning Monte Carlo system, this overhead is negligible, and for any program written predominantly in C++, encapsulating the functionality and hiding the details is a good idea. This is where the hardcore C fans would argue that no system which requires speed or efficiency should be written in C++, but I disagree, backed up by plenty of evidence for C++ development in the physical sciences, and in particle physics in particular!<br /><br /><span style="font-weight: bold; color: rgb(204, 0, 0);">MersenneTwister.hpp</span><br /><pre name="code" class="cpp"><br />/*<br /> A C++ program for MT19937, with initialization improved 2002/1/26.<br /> Original C Coded by Takuji Nishimura and Makoto Matsumoto.<br /> Converted to a C++ class by Andrew J. Bennieston<br /><br /> Before using, initialize the state by using init(seed)<br /> or initArray(init_key, key_length).<br /><br /> Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,<br /> All rights reserved.<br /> C++ Class modifications copyright (C) 2008, Andrew J. Bennieston.<br /><br /> Redistribution and use in source and binary forms, with or without<br /> modification, are permitted provided that the following conditions<br /> are met:<br /><br /> 1. Redistributions of source code must retain the above copyright<br /> notice, this list of conditions and the following disclaimer.<br /><br /> 2. Redistributions in binary form must reproduce the above copyright<br /> notice, this list of conditions and the following disclaimer in the<br /> documentation and/or other materials provided with the distribution.<br /><br /> 3. The names of its contributors may not be used to endorse or promote<br /> products derived from this software without specific prior written<br /> permission.<br /><br /> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS<br /> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br /> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR<br /> A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR<br /> CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,<br /> EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,<br /> PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR<br /> PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF<br /> LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING<br /> NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS<br /> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br /><br /><br /> Any feedback is very welcome.<br /> http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html<br /> email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)<br /><br /> Feedback on the C++ modifications to andrew @ physical - thought . com (remove spaces)<br />*/<br /><br /><br />class MersenneTwister {<br /> private:<br /> const int N;<br /> const int M;<br /> const unsigned long MATRIX_A;<br /> const unsigned long UPPER_MASK;<br /> const unsigned long LOWER_MASK;<br /> int mti;<br /> unsigned long* mt;<br /> public:<br /> // Constructors<br /> MersenneTwister()<br /> : N(624), M(397), MATRIX_A(0x9908b0dfUL),<br /> UPPER_MASK(0x80000000UL), LOWER_MASK(0x7fffffffUL),<br /> mti(N+1)<br /> { mt = new unsigned long[N]; };<br /><br /> // Destructor<br /> ~MersenneTwister() { delete[] mt; };<br /> <br /> // Initialisation<br /> void init(unsigned long s);<br /> void initArray(unsigned long init_key[], int key_length);<br /><br /> // Random number generation<br /> unsigned long genInt32(); // Random integer on [0,0xffffffff]<br /> long genInt31(); // Random integer on [0,0x7fffffff]<br /> double genRealClosed(); // Random real on closed range [0,1]<br /> double genReal(); // Random real on half-open range [0,1) (i.e. not including 1)<br /> double genRealOpen(); // Random real on open range (0,1) (i.e. not including 0 or 1)<br /> double genReal53(); // Random 53-bit real on [0,1)<br />};<br /></pre><br /><br /><span style="color: rgb(204, 0, 0); font-weight: bold;">MersenneTwister.cpp</span><br /><pre name="code" class="cpp"><br />#include "MersenneTwister.hpp"<br /><br />/*<br />* Initialise mt[N] with a seed<br />*/<br />void MersenneTwister::init(unsigned long s)<br />{<br />mt[0] = s & 0xffffffffUL;<br /> for (mti=1; mti<N; mti++) {<br /> mt[mti] =<br /> (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);<br /> /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.<br /> * In the previous versions, MSBs of the seed affect<br /> * only MSBs of the array mt[]. <br /> * 2002/01/09 modified by Makoto Matsumoto<br /> */<br /> mt[mti] &= 0xffffffffUL;<br /> /* for >32 bit machines */<br /> }<br />}<br /><br />/*<br />* Initialise by an array with length given by key_length<br />*/<br />void MersenneTwister::initArray(unsigned long init_key[], int key_length)<br />{<br />int i, j, k;<br /> init(19650218UL);<br /> i=1; j=0;<br /> k = (N>key_length ? N : key_length);<br /> for (; k; k--) {<br /> mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))<br /> + init_key[j] + j; /* non linear */<br /> mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */<br /> i++; j++;<br /> if (i>=N) { mt[0] = mt[N-1]; i=1; }<br /> if (j>=key_length) j=0;<br /> }<br /> for (k=N-1; k; k--) {<br /> mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))<br /> - i; /* non linear */<br /> mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */<br /> i++;<br /> if (i>=N) { mt[0] = mt[N-1]; i=1; }<br /> }<br /><br /> mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */<br />}<br /><br />/*<br />* Generate random number on [0,0xffffffff]<br />*/<br />unsigned long MersenneTwister::genInt32()<br />{<br />unsigned long y;<br /> static unsigned long mag01[2]={0x0UL, MATRIX_A};<br /> /* mag01[x] = x * MATRIX_A for x=0,1 */<br /><br /> if (mti >= N) { /* generate N words at one time */<br /> int kk;<br /><br /> if (mti == N+1) /* if init() has not been called, */<br /> init(5489UL); /* a default initial seed is used */<br /><br /> for (kk=0;kk<N-M;kk++) {<br /> y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);<br /> mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];<br /> }<br /> for (;kk<N-1;kk++) {<br /> y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);<br /> mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];<br /> }<br /> y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);<br /> mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];<br /><br /> mti = 0;<br /> }<br /><br /> y = mt[mti++];<br /><br /> /* Tempering */<br /> y ^= (y >> 11);<br /> y ^= (y << 7) & 0x9d2c5680UL;<br /> y ^= (y << 15) & 0xefc60000UL;<br /> y ^= (y >> 18);<br /><br /> return y;<br />}<br /><br />/*<br />* Generate a random number on [0,0x7fffffff]<br />*/<br />long MersenneTwister::genInt31()<br />{<br />return (long)(genInt32() >> 1);<br />}<br /><br />/*<br />* Generate a random number on [0,1]-real<br />*/<br />double MersenneTwister::genRealClosed()<br />{<br />return genInt32() * (1.0 / 4294967295.0);<br /> /* divided by 2^32 - 1 */<br />}<br /><br />/*<br />* Generate a random number on [0,1)-real<br />*/<br />double MersenneTwister::genReal()<br />{<br />return genInt32() * (1.0 / 4294967296.0);<br /> /* divided by 2^32 */<br />}<br /><br />/*<br />* Generate a random number on (0,1)-real<br />*/<br />double MersenneTwister::genRealOpen()<br />{<br />return (((double)genInt32()) + 0.5) * (1.0 / 4294967296.0);<br /> /* divided by 2^32 */<br />}<br /><br />/*<br />* Generate a random number on [0,1)-real with 53-bit resolution<br />*/<br />double MersenneTwister::genReal53()<br />{<br />unsigned long a = genInt32() >> 5;<br />unsigned long b = genInt32() >> 6;<br /> return(a * 67108864.0 + b) * (1.0 / 9007199254740992.0);<br />}<br /></pre>Andrew J. Benniestonnoreply@blogger.com0tag:blogger.com,1999:blog-4470666517647633822.post-34791934255741954452008-07-12T22:59:00.004+01:002008-07-12T23:10:09.752+01:00Close-Up PhotographyThe company I ordered my step-up ring adapter from, <a href="http://www.srb-griturn.com/">SRB-Griturn</a>, sell adapters which I'd never even considered before. Amongst them are adapters to reverse-mount a lens to a camera body, supposedly for close-up photography. The idea is that you take your lens off the camera body, and reverse mount it to the body using the lens filter thread into one side of this adapter, and the other side fits into the camera where the lens would normally go.<br /><br />And they recommend you "try it first", by holding the lens in reverse up against the body and taking a photo of something.<br /><br />Now, here is a photo taken using my Canon 18-55mm lens mounted normally. This is about the closest focus I can get to an object:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_zi39n2uYgqg/SHkqV9x5bbI/AAAAAAAAAHQ/USyI1h2lG1A/s1600-h/IMG_3193-smaller.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_zi39n2uYgqg/SHkqV9x5bbI/AAAAAAAAAHQ/USyI1h2lG1A/s400/IMG_3193-smaller.jpg" alt="" id="BLOGGER_PHOTO_ID_5222251799762267570" border="0" /></a><br /><br />After taking that photo, I removed the lens, turned it round, and put it up against the hole in the camera. There are a number of obstacles to overcome here.<br /><br /><ol><li>You lose autofocus functionality, meaning you have to manually focus the lens</li><li>The lens focussing isn't really sufficient in this configuration, so you end up moving the camera backwards and forwards anyway</li><li>While holding the lens against the body with one hand, and leaving the other hand poised over the shutter button, you need a third hand to change the lens focus</li><li>With the camera so close to the subject, light is an issue. There's not enough of it. I switched on a spot-light to get enough light in</li></ol>After all that, I managed to take the photo below. This was with the lens rather close to the phone, and the results speak for themselves:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_zi39n2uYgqg/SHkrUMS_3iI/AAAAAAAAAHY/EmwGQ4U0hnA/s1600-h/IMG_3197-smaller.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_zi39n2uYgqg/SHkrUMS_3iI/AAAAAAAAAHY/EmwGQ4U0hnA/s400/IMG_3197-smaller.jpg" alt="" id="BLOGGER_PHOTO_ID_5222252868811087394" border="0" /></a><br /><br />There's a fairly small area which is in focus. This is to be expected, given this configuration, and could probably be improved if I had enough hands. I suspect that is what these reverse-mounting adapters are for; freeing up the hand that is holding the lens, so you can focus with it instead!<br /><br />Even so, I'm amazed by how close this gets you, and of the image quality resulting from it (fuzzy focus aside!)Andrew J. Benniestonnoreply@blogger.com0