Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

Archive for August, 2009

Making function calls within gdb.

Posted by peeterjoot on August 31, 2009

Here’s a quick debugging tidbit for the day, somewhat obscure, but it is a cool one and can be useful (I used it today)

Gdb has a particularily nice feature of being able to call arbitrary functions on the gdb command line, and print their output (if any)


(gdb) p getpid()
$8 = 6649
(gdb) p this->SAL_DumpMyStateToAFile()
[New Thread 47323035986240 (LWP 32200)]
$9 = void

You may have to move up and down your stack frames to find the context required to make the call, or to get the parameters you need in scope. You have to think about (or exploit) the side effects of the functions you call.

Somewhat like modification of variables in the debugger, this capability allows you to shoot yourself fairly easily, and but that’s part of the power.

I don’t recall if many other debuggers had this functionality. I have a vague recollection that the sun workshop’s dbx did too, but I could be wrong.

Posted in debugging | Tagged: , | Leave a Comment »

Angular momentum polar form, factoring out the raising and lowering operators, and simultaneous eigenvalues.

Posted by peeterjoot on August 30, 2009

Continuation of ‘Bivector form of quantum angular momentum operator’ notes.

[Click here for a PDF of this sequence of posts with nicer formatting]

After a bit more manipulation we find that the angular momentum operator polar form representation, again using i = \mathbf{e}_1 \mathbf{e}_2, is

\begin{aligned}\mathbf{x} \wedge \boldsymbol{\nabla} = I \hat{\boldsymbol{\phi}} ( \partial_\theta + i \cot\theta \partial_\phi + \mathbf{e}_{23} e^{i\phi} \partial_\phi ) \end{aligned} \quad\quad\quad(54)

Observe how similar the exponential free terms within the braces are to the raising operator as given in Bohm’s equation (14.40)

\begin{aligned}L_x + i L_y &= e^{i\phi} (\partial_\theta + i \cot\theta \partial_\phi ) \\ L_z &= \frac{1}{{i}} \partial_\phi  \end{aligned} \quad\quad\quad(55)

In fact since \mathbf{e}_{23}e^{i\phi} = e^{-i\phi} \mathbf{e}_{23}, the match can be made even closer

\begin{aligned}\mathbf{x} \wedge \boldsymbol{\nabla} = I \hat{\boldsymbol{\phi}} e^{-i\phi} ( \underbrace{e^{i\phi} (\partial_\theta + i \cot\theta \partial_\phi)}_{= L_x + i L_y} + \mathbf{e}_{13} \underbrace{\frac{1}{{i}} \partial_\phi}_{=L_z} ) \end{aligned} \quad\quad\quad(57)

This is a surprising factorization, but noting that \hat{\boldsymbol{\phi}} = \mathbf{e}_2 e^{i\phi} we have

\begin{aligned}\mathbf{x} \wedge \boldsymbol{\nabla} = \mathbf{e}_{31} ( e^{i\phi} (\partial_\theta + i \cot\theta \partial_\phi) + \mathbf{e}_{13} \frac{1}{{i}} \partial_\phi ) \end{aligned} \quad\quad\quad(58)

It appears that the factoring out from the left of a unit bivector (in this case \mathbf{e}_{31}) from the bivector angular momentum operator, leaves as one of the remainders the raising operator.

Similarily, noting that \mathbf{e}_{13} anticommutes with i = \mathbf{e}_{12}, we have the right factorization

\begin{aligned}\mathbf{x} \wedge \boldsymbol{\nabla} = ( e^{-i\phi} (\partial_\theta - i \cot\theta \partial_\phi) - \mathbf{e}_{13} \frac{1}{{i}} \partial_\phi )\mathbf{e}_{31} \end{aligned} \quad\quad\quad(59)

Now in the remainder, we see the polar form representation of the lowering operator L_x - i L_y = e^{-i\phi}(\partial_\theta - i\cot\theta \partial_\phi).

I wasn’t expecting the raising and lowering operators “to fall out” as they did by simply expressing the complete bivector operator in polar form. This is actually fortunitous since it shows why this peculiar combination is of interest.

If we find a zero solution to the raising or lowering operator, that is also a solution of the eigenproblem (\partial_\phi - \lambda) \psi = 0, then this is neccessarily also an eigensolution of \mathbf{x} \wedge \boldsymbol{\nabla}. A secondary implication is that this is then also an eigensolution of \left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle \psi = \lambda' \psi. This was the starting point in Bohm’s quest for the spherical harmonics, but why he started there wasn’t clear to me.

Saying this without the words, let’s look for eigenfunctions for the non-raising portion of (58). That is

\begin{aligned}\mathbf{e}_{31} \mathbf{e}_{13} \frac{1}{{i}} \partial_\phi f = \lambda f \end{aligned} \quad\quad\quad(60)

Since \mathbf{e}_{31} \mathbf{e}_{13} = 1 we want solutions of

\begin{aligned}\partial_\phi f = i \lambda f \end{aligned} \quad\quad\quad(61)

Solutions are

\begin{aligned}f = \kappa(\theta) e^{i\lambda \phi} \end{aligned} \quad\quad\quad(62)

A demand that this is a zero eigenfunction for the raising operator, means we are looking for solutions of

\begin{aligned}\mathbf{e}_{31} e^{i\phi} (\partial_\theta + i \cot\theta \partial_\phi) \kappa(\theta) e^{i\lambda \phi} = 0 \end{aligned} \quad\quad\quad(63)

It is sufficient to find zero eigenfunctions of

\begin{aligned}(\partial_\theta + i \cot\theta \partial_\phi) \kappa(\theta) e^{i\lambda \phi} = 0 \end{aligned} \quad\quad\quad(64)

Evaluation of the \phi partials and rearrangement leaves us with an equation in \theta only

\begin{aligned}\frac{\partial \kappa }{\partial \theta} = \lambda \cot\theta \kappa \end{aligned} \quad\quad\quad(65)

This has solutions \kappa = A(\phi) (\sin\theta)^\lambda, where because of the partial derivatives in (65) we are free to make the integration constant a function of \phi. Since this is the functional dependence that is a zero of the raising operator, including this at the \theta dependence of (62) means that we have a simultaneous zero of the raising operator, and an eigenfunction of eigenvalue \lambda for the remainder of the angular momentum operator.

\begin{aligned}f(\theta,\phi) = (\sin\theta)^\lambda e^{i\lambda \phi} \end{aligned} \quad\quad\quad(66)

This is very similar seeming to the process of adding homogeneous solutions to specific ones, since we augment the specific eigenvalued solutions for one part of the operator by ones that produce zeros for the rest.

As a check lets apply the angular momentum operator to this as a test and see if the results match our expectations.

\begin{aligned}(\mathbf{x} \wedge \boldsymbol{\nabla} ) (\sin\theta)^\lambda e^{i\lambda \phi}&=\hat{\mathbf{r}} \left( \hat{\boldsymbol{\theta}} \partial_\theta + \hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} \partial_\phi \right)  (\sin\theta)^\lambda e^{i\lambda \phi} \\ &=\hat{\mathbf{r}} \left( \hat{\boldsymbol{\theta}} \lambda (\sin\theta)^{\lambda-1} \cos\theta + \hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} (\sin\theta)^\lambda (i\lambda)\right) e^{i\lambda \phi} \\ &=\lambda \hat{\mathbf{r}} \left( \hat{\boldsymbol{\theta}} \cos\theta + \hat{\boldsymbol{\phi}} i \right) e^{i\lambda \phi} (\sin\theta)^{\lambda-1}  \\  \end{aligned}

From (38) we have

\begin{aligned}\hat{\mathbf{r}} \hat{\boldsymbol{\phi}} i &= \mathbf{e}_3 \hat{\boldsymbol{\phi}} i \cos\theta - \sin\theta \\ &= \mathbf{e}_{32} i e^{i\phi} \cos\theta - \sin\theta \\ &= \mathbf{e}_{13} e^{i\phi} \cos\theta - \sin\theta \\  \end{aligned}

and from (37) we have

\begin{aligned}\hat{\mathbf{r}} \hat{\boldsymbol{\theta}}&= I \hat{\boldsymbol{\phi}}  \\ &= \mathbf{e}_{31} e^{i\phi} \end{aligned}

Putting these together shows that (\sin\theta)^\lambda e^{i\lambda \phi} is an eigenfunction of \mathbf{x} \wedge \boldsymbol{\nabla},

\begin{aligned}(\mathbf{x} \wedge \boldsymbol{\nabla} ) (\sin\theta)^\lambda e^{i\lambda \phi} = -\lambda (\sin\theta)^\lambda e^{i\lambda \phi} \end{aligned} \quad\quad\quad(67)

This negation suprised me at first, but I don’t see any errors here in the arithmetic. Observe that if this is correct, then it provides a demonstration that the previous suspected calculation leading to (7) is in fact wrong as guessed. That suspected incorrect result, a product of very messy calculation, was

\begin{aligned}\left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle \stackrel{?}{=} \left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) (\mathbf{x} \wedge \boldsymbol{\nabla})  \end{aligned} \quad\quad\quad(68)

the one half factor seemed unasthetic, with the following somehow preferable

\begin{aligned}\left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle \stackrel{?}{=} \left( \mathbf{x} \wedge \boldsymbol{\nabla} - 1 \right) (\mathbf{x} \wedge \boldsymbol{\nabla})  \end{aligned} \quad\quad\quad(69)

If (67) is the correct version then calculating the operator effect of \left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle for the eigenvalue we have

\begin{aligned}\left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle (\sin\theta)^\lambda e^{i\lambda \phi}&=\left( \mathbf{x} \wedge \boldsymbol{\nabla} - 1 \right) (\mathbf{x} \wedge \boldsymbol{\nabla}) (\sin\theta)^\lambda e^{i\lambda \phi} \\ &=((-\lambda)^2 - (-\lambda)) (\sin\theta)^\lambda e^{i\lambda \phi} \\  \end{aligned}

So the eigenvalue is \lambda(\lambda + 1). This we do know to be the case in fact, so a second look at the messy algebra leading to (68) is justified (or an attempt at a coordinate free expansion).

Posted in Math and Physics Learning. | Tagged: , , , , | Leave a Comment »

Bivector form of quantum angular momentum operator (3D Quantum Hamiltonian)

Posted by peeterjoot on August 29, 2009

[Click here for a PDF of this sequence of posts with nicer formatting]

Going back to the quantum Hamiltonian we do still have the angular momentum operator as one of the distinct factors of the Laplacian. As operators we have something akin to the projection of the gradient onto the radial direction, as well as terms that project the gradient onto the tangential plane to the sphere at the radial point

\begin{aligned}-\frac{\hbar^2}{2m} \boldsymbol{\nabla}^2 + V &=-\frac{\hbar^2}{2m} \left( \frac{1}{{\mathbf{x}^2}} (\mathbf{x} \cdot \boldsymbol{\nabla})^2 - \frac{1}{{\mathbf{x}^2}} \left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle + \frac{1}{{\mathbf{x}}} \cdot \boldsymbol{\nabla} \right) + V \end{aligned}

Using the result of (7) and the radial formulation for the rest, we can write this

\begin{aligned}0 &= \left( \boldsymbol{\nabla}^2 - \frac{2m}{\hbar^2} (V - E) \right) \psi \\ &= \frac{1}{{r}}\frac{\partial}{\partial r} r \frac{\partial \psi}{\partial r}- \frac{1}{{r^2}} \left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) (\mathbf{x} \wedge \boldsymbol{\nabla}) \psi - \frac{2m}{\hbar^2} (V - E) \psi \\  \end{aligned}

If V = V(r), then a radial split by separation of variables is possible. Writing \psi = R(r) Y, we get

\begin{aligned}\frac{r}{R} \frac{\partial}{\partial r} r \frac{\partial R}{\partial r} - \frac{2m r^2}{\hbar^2} (V(r) - E) = \frac{1}{{Y}} \left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) (\mathbf{x} \wedge \boldsymbol{\nabla}) Y = \text{constant} \end{aligned} \quad\quad\quad(49)

For the constant, lets use c, and split this into a pair of equations

\begin{aligned}r \frac{\partial}{\partial r} r \frac{\partial R}{\partial r} - \frac{2m r^2 R}{\hbar^2} (V(r) - E) = c R \end{aligned} \quad\quad\quad(50)

\begin{aligned}\left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) (\mathbf{x} \wedge \boldsymbol{\nabla}) Y &= c Y \end{aligned} \quad\quad\quad(51)

In this last we can examine simultaneous eigenvalues of \mathbf{x} \wedge \boldsymbol{\nabla}, and \left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle. Suppose that
Y_\lambda is an eigenfunction of \mathbf{x} \wedge \boldsymbol{\nabla} with eigenvalue \lambda. We then have

\begin{aligned}\left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle Y_\lambda &= \left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) (\mathbf{x} \wedge \boldsymbol{\nabla}) Y_\lambda \\ &= \left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) \lambda Y_\lambda  \\ &= \lambda \left(\lambda - \frac{1}{{2}} \right) Y_\lambda  \end{aligned}

We see immediately that Y_\lambda is then also an eigenfunction of \left\langle{{(\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle, with eigenvalue
\lambda \left(\lambda - \frac{1}{{2}} \right).

Now, I was hoping to use an argument like this to confirm or deny the correctness of the 1/2, by comparing to the scalar coordinate results in Bohm. Looking again though, I see this is something entirely different. There are three eigenvalue results. One for individual simultaneous eigenfunctions of L_x, L_y, or L_z with L^2 (with matching eigenvalues), and the other was for the raising and lowering operators, L_x \pm iL_y also eigenfunctions of L^2, but having m(m \pm 1) eigenvalues.

So, if there is an error in the messy algebraic split of (\mathbf{x} \wedge \boldsymbol{\nabla})^2 into its scalar and bivector components, I’ll assume that this error is only a scalar factor. If there is no such numeric error, and even if there is, it appears the next order of business is figuring out how to solve the multivector eigenvalue problem

\begin{aligned}(\mathbf{x} \wedge \boldsymbol{\nabla}) Y_\lambda = \lambda Y_\lambda \end{aligned} \quad\quad\quad(52)

Posted in Math and Physics Learning. | Tagged: , , , | Leave a Comment »

Bivector form of quantum angular momentum operator (On the bivector and quadvector components of the squared angular momentum operator.)

Posted by peeterjoot on August 29, 2009

[Click here for a PDF of this sequence of posts with nicer formatting]

We found that we could by something similar to “factoring” the gradient into radial and non-radial terms express the Laplacian as

\begin{aligned}\nabla^2 &= \frac{1}{{x^2}} (x \cdot \nabla)^2 - \frac{1}{{x^2}} \left\langle{{(x \wedge \nabla)^2}}\right\rangle + (n - 2) \frac{1}{{x}} \cdot \nabla  \end{aligned} \quad\quad\quad(3)

The requirement for a scalar selection on all the (x \wedge \nabla)^2 terms is a bit ugly, but omitting it would be incorrect for two reasons. One reason is that this is a bivector operator and not a bivector (where the squaring operates on itself). The other is that we derived a result for arbitrary dimension, and the product of two bivectors in a general space has grade 2 and grade 4 terms in addition to the scalar terms. Without taking only the scalar parts, lets expand this product a bit more carefully, starting with

\begin{aligned}(x \wedge \nabla)^2 &=(\gamma_\mu \wedge \gamma_\nu) (\gamma^\alpha \wedge \gamma^\beta)x^\mu \partial^\nu x_\alpha \partial_\beta \end{aligned}

Just expanding the multivector factor for now, we have

\begin{aligned}2 (\gamma_\mu \wedge \gamma_\nu) (\gamma^\alpha \wedge \gamma^\beta)&=\gamma_\mu \gamma_\nu (\gamma^\alpha \wedge \gamma^\beta)- \gamma_\nu \gamma_\mu (\gamma^\alpha \wedge \gamma^\beta) \\ &=\gamma_\mu \left( {\delta_\nu}^\alpha \gamma^\beta - {\delta_\nu}^\beta \gamma^\alpha+ \gamma_\nu \wedge \gamma^\alpha \wedge \gamma^\beta \right)- \gamma_\nu \left({\delta_\mu}^\alpha \gamma^\beta - {\delta_\mu}^\beta \gamma^\alpha+ \gamma_\mu \wedge \gamma^\alpha \wedge \gamma^\beta \right)\\ &={\delta_\nu}^\alpha {\delta_\mu}^\beta - {\delta_\nu}^\beta {\delta_\mu}^\alpha-{\delta_\mu}^\alpha {\delta_\nu}^\beta + {\delta_\mu}^\beta {\delta_\nu}^\alpha \\ &+ \gamma_\mu \wedge \gamma_\nu \wedge \gamma^\alpha \wedge \gamma^\beta - \gamma_\nu \wedge \gamma_\mu \wedge \gamma^\alpha \wedge \gamma^\beta \\ &+ \gamma_\mu \cdot (\gamma_\nu \wedge \gamma^\alpha \wedge \gamma^\beta )-\gamma_\nu \cdot (\gamma_\mu \wedge \gamma^\alpha \wedge \gamma^\beta ) \\  \end{aligned}

Our split into grades for this operator is then, the scalar

\begin{aligned}\left\langle{{(x \wedge \nabla)^2 }}\right\rangle &= (x \wedge \nabla) \cdot (x \wedge \nabla) \\ &= \left( {\delta_\nu}^\alpha {\delta_\mu}^\beta - {\delta_\nu}^\beta {\delta_\mu}^\alpha \right)x^\mu \partial^\nu x_\alpha \partial_\beta \\  \end{aligned}

the pseudoscalar (or grade 4 term in higher than 4D spaces).

\begin{aligned}{\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{4} &= (x \wedge \nabla) \wedge (x \wedge \nabla) \\ &= \left( \gamma_\mu \wedge \gamma_\nu \wedge \gamma^\alpha \wedge \gamma^\beta  \right)x^\mu \partial^\nu x_\alpha \partial_\beta \\  \end{aligned}

If we work in dimensions less than or equal to three, we’ll have no grade four term since this wedge product is zero (irrespective of the operator action), so in 3D we have only a bivector term in excess of the scalar part of this operator.

The bivector term deserves some reduction. As expanded so far it is

\begin{aligned}{\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{2} &= \frac{1}{{2}} \left(  \gamma_\mu \cdot (\gamma_\nu \wedge \gamma^\alpha \wedge \gamma^\beta )-\gamma_\nu \cdot (\gamma_\mu \wedge \gamma^\alpha \wedge \gamma^\beta ) \right)x^\mu \partial^\nu x_\alpha \partial_\beta \end{aligned}

Lets expand this bivector term more completely.

\begin{aligned}2 {\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{2} &=\gamma_\mu \cdot \gamma_\nu (\gamma^\alpha \wedge \gamma^\beta ) x^\mu \partial^\nu x_\alpha \partial_\beta-\gamma_\mu \cdot \gamma^\alpha (\gamma_\nu \wedge \gamma^\beta ) x^\mu \partial^\nu x_\alpha \partial_\beta+\gamma_\mu \cdot \gamma^\beta (\gamma_\nu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\alpha \partial_\beta \\ &- \gamma_\nu \cdot \gamma_\mu ( \gamma^\alpha \wedge \gamma^\beta ) x^\mu \partial^\nu x_\alpha \partial_\beta+ \gamma_\nu \cdot \gamma_\alpha ( \gamma_\mu \wedge \gamma^\beta ) x^\mu \partial^\nu x_\alpha \partial_\beta- \gamma_\nu \cdot \gamma_\beta ( \gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\alpha \partial_\beta \\ &=(\gamma^\alpha \wedge \gamma^\beta ) x^\mu \partial_\mu x_\alpha \partial_\beta-(\gamma_\nu \wedge \gamma^\beta ) x^\mu \partial^\nu x_\mu \partial_\beta+(\gamma_\nu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\alpha \partial_\mu \\ &- ( \gamma^\alpha \wedge \gamma^\beta ) x^\mu \partial_\mu x_\alpha \partial_\beta+ ( \gamma_\mu \wedge \gamma^\beta ) x^\mu \partial^\nu x_\nu \partial_\beta- ( \gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\alpha \partial_\nu \\  \end{aligned}

The first and fourth terms cancel, and a change of dummy indexes on the remainder, eliminating \beta, gives us

\begin{aligned}2 {\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{2} &=-(\gamma_\nu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\mu \partial_\alpha+(\gamma_\nu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\alpha \partial_\mu + ( \gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\nu \partial_\alpha- ( \gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial^\nu x_\alpha \partial_\nu \\ &=(\gamma_\nu \wedge \gamma^\alpha ) x^\mu \partial^\nu (x_\alpha \partial_\mu - x_\mu \partial_\alpha)+( \gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial^\nu (x_\nu \partial_\alpha - x_\alpha \partial_\nu) \\ &=(\gamma_\nu \wedge \gamma^\alpha ) x^\mu (x_\alpha \partial^\nu \partial_\mu - x_\mu \partial^\nu \partial_\alpha)+( \gamma_\mu \wedge \gamma^\alpha ) x^\mu (x_\nu \partial^\nu \partial_\alpha - x_\alpha \partial^\nu \partial_\nu) \\ &+(\gamma_\nu \wedge \gamma^\nu ) x^\mu \partial_\mu -(\gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial_\alpha+n ( \gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial_\alpha -( \gamma_\mu \wedge \gamma^\nu ) x^\mu \partial_\nu \\ &=(\gamma_\nu \wedge \gamma^\alpha ) x^\mu x_\alpha \partial^\nu \partial_\mu +( \gamma_\mu \wedge \gamma^\alpha ) x^\mu x_\nu \partial^\nu \partial_\alpha -(\gamma_\mu \wedge \gamma^\alpha ) ( x^2 \partial^\mu \partial_\alpha + x^\mu x_\alpha \nabla^2 ) \\ &+(n-1)(\gamma_\mu \wedge \gamma^\alpha ) x^\mu \partial_\alpha-( \gamma_\mu \wedge \gamma^\nu ) x^\mu \partial_\nu \\ &=(\gamma_\nu \wedge \gamma^\mu ) ( x^\alpha x_\mu \partial^\nu \partial_\alpha + x^\nu x_\alpha \partial^\alpha \partial_\mu )- ( x^2 (\nabla \wedge \nabla) + ( x \wedge x ) \nabla^2 ) +(n-2) x \wedge \nabla\\  \end{aligned}

The self wedges for both \nabla and x are zero, and we are left with

\begin{aligned}2 {\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{2} &=(\gamma_\nu \wedge \gamma^\mu ) ( x_\mu (x \cdot \nabla) \partial^\nu + x^\nu (x \cdot \nabla) \partial_\mu )+(n-2) x \wedge \nabla\\  \end{aligned}

Swapping \mu with \nu and raising and lowering we have exact cancellation of the first two terms

\begin{aligned}2 {\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{2} &=(\gamma_\nu \wedge \gamma^\mu ) x_\mu (x \cdot \nabla) \partial^\nu (\gamma^\mu \wedge \gamma_\nu ) x_\mu (x \cdot \nabla) \partial^\nu +(n-2) x \wedge \nabla\\  \end{aligned}

So are left, almost mystically simplified, with just

\begin{aligned}{\left\langle{{(x \wedge \nabla)^2 }}\right\rangle}_{2} &=\frac{n-2}{2} x \wedge \nabla \end{aligned} \quad\quad\quad(4)

We can now write for the squared operator

\begin{aligned}(x \wedge \nabla)^2 &=\frac{n-2}{2} (x \wedge \nabla)+(x \wedge \nabla) \wedge (x \wedge \nabla) +(x \wedge \nabla) \cdot (x \wedge \nabla)  \end{aligned} \quad\quad\quad(5)

and then eliminate the scalar selection from the (3)

\begin{aligned}\nabla^2 &= \frac{1}{{x^2}} (x \cdot \nabla)^2 + (n - 2) \frac{1}{{x}} \cdot \nabla - \frac{1}{{x^2}} \left((x \wedge \nabla)^2 - \frac{n-2}{2} (x \wedge \nabla) - (x \wedge \nabla) \wedge (x \wedge \nabla) \right) \end{aligned} \quad\quad\quad(6)

In 3D this is

\begin{aligned}\boldsymbol{\nabla}^2 &= \frac{1}{{\mathbf{x}^2}} (\mathbf{x} \cdot \boldsymbol{\nabla})^2 + \frac{1}{{\mathbf{x}}} \cdot \boldsymbol{\nabla} - \frac{1}{{\mathbf{x}^2}} \left( \mathbf{x} \wedge \boldsymbol{\nabla} - \frac{1}{{2}} \right) (\mathbf{x} \wedge \boldsymbol{\nabla})  \end{aligned} \quad\quad\quad(7)

Wow, that was an ugly mess of algebra, and presented lots of potential possibilities for error. There is likely a more clever coordinate free way to do the same expansion, and some verification of correctness of this result seems justified. I suspect that the factor of 1/2 will allow for verification by considering of the Quantum eigenvalue problem, and simultaneous eigenvalues of \mathbf{x} \wedge \boldsymbol{\nabla}, and \left\langle{{\mathbf{x} \wedge \boldsymbol{\nabla})^2}}\right\rangle.

Posted in Math and Physics Learning. | Tagged: , , , | Leave a Comment »

Bivector form of quantum angular momentum operator (squaring the bivector angular momentum operator)

Posted by peeterjoot on August 28, 2009

[Click here for a PDF of this sequence of posts with nicer formatting]

It is expected that we have the equivalence of the squared bivector form of angular momentum with the classical scalar form in terms of spherical angles \phi, and \theta. Specifically, if no math errors have been made playing around with this GA representation, we should have the following identity for the scalar part of the squared angular momentum operator

\begin{aligned}-\left\langle{{ (\mathbf{x} \wedge \boldsymbol{\nabla})^2 }}\right\rangle =\frac{1}{{\sin\theta}} \frac{\partial {}}{\partial {\theta}} \sin\theta \frac{\partial {}}{\partial {\theta}} + \frac{1}{{\sin^2\theta}} \frac{\partial^2}{\partial \phi^2} \end{aligned} \quad\quad\quad(40)

To finally attempt to verify this we write the angular momentum operator in polar form, using i = \mathbf{e}_1 \mathbf{e}_2 as

\begin{aligned}\mathbf{x} \wedge \boldsymbol{\nabla} &=\hat{\mathbf{r}} \left( \hat{\boldsymbol{\theta}} \partial_\theta + \hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} \partial_\phi \right)  \\  \end{aligned}

Expressing the unit vectors in terms of \hat{\boldsymbol{\phi}} and after some rearranging we have

\begin{aligned}\mathbf{x} \wedge \boldsymbol{\nabla} &=I \hat{\boldsymbol{\phi}} \left( \partial_\theta + i e^{I\hat{\boldsymbol{\phi}} \theta} \frac{1}{{\sin\theta}} \partial_\phi \right) \end{aligned} \quad\quad\quad(41)

Using this lets now compute the partials. First for the \theta partials we have

\begin{aligned}\partial_\theta (\mathbf{x} \wedge \boldsymbol{\nabla})&=I \hat{\boldsymbol{\phi}} \left( \partial_{\theta\theta} + i I \hat{\boldsymbol{\phi}} e^{I\hat{\boldsymbol{\phi}} \theta} \frac{1}{{\sin\theta}} \partial_\phi + i e^{I\hat{\boldsymbol{\phi}} \theta} \frac{\cos\theta}{\sin^2\theta} \partial_\phi + i e^{I\hat{\boldsymbol{\phi}} \theta} \frac{1}{{\sin\theta}} \partial_{\theta\phi}\right) \\ &=I \hat{\boldsymbol{\phi}} \left( \partial_{\theta\theta} + i ( I \hat{\boldsymbol{\phi}} e^{I\hat{\boldsymbol{\phi}} \theta} \sin\theta +  e^{I\hat{\boldsymbol{\phi}} \theta} \cos\theta ) \frac{1}{{\sin^2\theta}} \partial_\phi + i e^{I\hat{\boldsymbol{\phi}} \theta} \frac{1}{{\sin\theta}} \partial_{\theta\phi}\right) \\ &=I \hat{\boldsymbol{\phi}} \left( \partial_{\theta\theta} + i e^{2 I\hat{\boldsymbol{\phi}} \theta} \frac{1}{{\sin^2\theta}} \partial_\phi + i e^{I\hat{\boldsymbol{\phi}} \theta} \frac{1}{{\sin\theta}} \partial_{\theta\phi}\right) \\  \end{aligned}

Premultiplying by I\hat{\boldsymbol{\phi}} and taking scalar parts we have the first part of the application of (41) on itself,

\begin{aligned}\left\langle{{ I \hat{\boldsymbol{\phi}} \partial_\theta (\mathbf{x} \wedge \boldsymbol{\nabla}) }}\right\rangle = -\partial_{\theta\theta}  \end{aligned} \quad\quad\quad(42)

For the \phi partials it looks like the simplest option is using the computed bivector \phi partials \partial_\phi (\hat{\mathbf{r}} \hat{\boldsymbol{\theta}}) = \mathbf{e}_3 \hat{\boldsymbol{\phi}}, \partial_\phi (\hat{\mathbf{r}} \hat{\boldsymbol{\phi}}) = -I \hat{\boldsymbol{\phi}} \cos\theta. Doing so we have

\begin{aligned}\partial_\phi (\mathbf{x} \wedge \boldsymbol{\nabla})&=\partial_\phi \left( \hat{\mathbf{r}} \hat{\boldsymbol{\theta}} \partial_\theta + \hat{\mathbf{r}} \hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} \partial_\phi \right)  \\ &=\mathbf{e}_3 \hat{\boldsymbol{\phi}} \partial_\theta + +\hat{\mathbf{r}} \hat{\boldsymbol{\theta}} \partial_{\phi\theta} -I \hat{\boldsymbol{\phi}} \cot\theta \partial_\phi + \hat{\mathbf{r}} \hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} \partial_{\phi\phi} \end{aligned}

So the remaining terms of the squared angular momentum operator follow by premultiplying by \hat{\mathbf{r}} \hat{\boldsymbol{\phi}}/\sin\theta, and taking scalar parts. This is

\begin{aligned}\left\langle{{ \hat{\mathbf{r}}\hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} \partial_\phi (\mathbf{x} \wedge \boldsymbol{\nabla}) }}\right\rangle&=\frac{1}{{\sin\theta}} \left\langle{{-\hat{\mathbf{r}} \mathbf{e}_3 \partial_\theta + -\hat{\boldsymbol{\phi}} \hat{\boldsymbol{\theta}} \partial_{\phi\theta} -\hat{\mathbf{r}} I \cot\theta \partial_\phi }}\right\rangle- \frac{1}{{\sin^2\theta}} \partial_{\phi\phi} \end{aligned}

The second and third terms in the scalar selection have only bivector parts, but since \hat{\mathbf{r}} = \mathbf{e}_3 \cos\theta + \mathbf{e}_1 \sin\theta e^{\mathbf{e}_{12}\phi} has component in the \mathbf{e}_3 direction, we have

\begin{aligned}\left\langle{{ \hat{\mathbf{r}}\hat{\boldsymbol{\phi}} \frac{1}{{\sin\theta}} \partial_\phi (\mathbf{x} \wedge \boldsymbol{\nabla}) }}\right\rangle=-\cot\theta \partial_\theta - \frac{1}{{\sin^2\theta}} \partial_{\phi\phi} \end{aligned} \quad\quad\quad(43)

Adding results from (42), and (43) we have

\begin{aligned}-\left\langle{{ (\mathbf{x} \wedge \boldsymbol{\nabla})^2 }}\right\rangle=\partial_{\theta\theta} +\cot\theta \partial_\theta + \frac{1}{{\sin^2\theta}} \partial_{\phi\phi} \end{aligned} \quad\quad\quad(44)

A final verification of (40) now only requires a simple calculus expansion

\begin{aligned}\frac{1}{{\sin\theta}} \frac{\partial {}}{\partial {\theta}} \sin\theta \frac{\partial {}}{\partial {\theta}} \psi&=\frac{1}{{\sin\theta}} \frac{\partial {}}{\partial {\theta}} \sin\theta \partial_\theta \psi \\ &=\frac{1}{{\sin\theta}} (\cos\theta \partial_\theta \psi + \sin\theta \partial_{\theta\theta} \psi) \\ &=\cot\theta \partial_\theta \psi + \partial_{\theta\theta} \psi \end{aligned}

Voila. This exercise demonstrating that what was known to have to be true, is in fact explicitly true, is now done. There’s no new or interesting results in this in and of itself, but we get some additional confidence in the new methods being experimented with.

Posted in Math and Physics Learning. | Tagged: , , , | Leave a Comment »

gdb on linux. Finding your damn thread.

Posted by peeterjoot on August 28, 2009

Suppose you are debugging a threaded process, and know that somewhere in there you have one of many threads that’s running the code you want to debug. How do you find it?

Listing the running threads isn’t terribly helpful if you’ve got a lot of them. You may see something unhelpful like:

(gdb) info threads
  30 Thread 47529939401216 (LWP 13827)  0x00002b3a5ff8e5c5 in pthread_join () from /lib64/
  29 Thread 47529945196864 (LWP 13831)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  17 Thread 47530159106368 (LWP 14065)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  16 Thread 47530150717760 (LWP 14067)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  15 Thread 47530154912064 (LWP 14559)  0x00002b3a5ff94231 in __gxx_personality_v0 ()
    at ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/
  14 Thread 47530146523456 (LWP 14561)  0x00002b3a66fc9476 in poll () from /lib64/
  13 Thread 47530142329152 (LWP 14564)  0x00002b3a66fc9476 in poll () from /lib64/
  12 Thread 47530138134848 (LWP 14580)  0x00002b3a66fc9476 in poll () from /lib64/
  11 Thread 47530133940544 (LWP 14581)  0x00002b3a66fc9476 in poll () from /lib64/
  10 Thread 47530129746240 (LWP 14582)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  9 Thread 47530125551936 (LWP 14583)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  8 Thread 47530121357632 (LWP 14584)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  7 Thread 47530117163328 (LWP 14585)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  6 Thread 47530112969024 (LWP 14586)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  5 Thread 47530108774720 (LWP 14587)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  4 Thread 47530104580416 (LWP 14588)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  3 Thread 47530100386112 (LWP 14589)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  2 Thread 47530096191808 (LWP 14590)  0x00002b3a66fd2baa in semtimedop () from /lib64/
  1 Thread 47530091997504 (LWP 14591)  0x00002b3a66fd2baa in semtimedop () from /lib64/

Unless you are running on a 128 way (and god help you if you have to actively debug with that kind of concurrency), most of your threads will be blocked all the time, stuck in a kernel or C runtime function, and only that shows at the top of the stack.

You can list the top frames of all your functions easily enough, doing something like:

(gdb) thread apply all where 4

Thread 30 (Thread 47529939401216 (LWP 13827)):
#0  0x00002b3a5ff8e5c5 in pthread_join () from /lib64/
#1  0x00002b3a6312e635 in sqloSpawnEDU (FuncPtr=0x2b3a6312bd7e ,
    pcArguments=0x7fff4ac3c380 "4'A", ulArgSize=24, pEDUInfo=0x7fff4ac3c340, pEDUid=0x7fff4ac3c3a0) at sqloedu.C:2206
#2  0x00002b3a6312e928 in sqloRunMainAsEDU (pFncPtr=0x412734 , argc=2, argv=0x7fff4ac3c4b8) at sqloedu.C:2445
#3  0x000000000041272c in main (argc=2, argv=0x7fff4ac3c4b8) at sqlesysc.C:1495

Thread 29 (Thread 47529945196864 (LWP 13831)):
#0  0x00002b3a66fd2baa in semtimedop () from /lib64/
#1  0x00002b3a63050880 in sqlo_waitlist::timeoutWait (this=0x2004807e0, timeout=10000)
    at /view/peeterj_kseq/vbs/engn/include/sqlowlst_inlines.h:557
#2  0x00002b3a6304eb1c in sqloWaitEDUWaitPost (pEDUWaitPostArea=0x200e90528, pUserPostCode=0x2b3a6d7d9170, timeOut=10000, flags=0)
    at sqlowaitpost.C:942
#3  0x00002b3a61b95e13 in sqeSyscQueueEdu::syscWaitRequest (this=0x200e904c0, reason=@0x2b3a6d7d9590) at sqlesyscqueue.C:510
(More stack frames follow...)

Thread 28 (Thread 47530205243712 (LWP 13894)):
#0  0x00002b3a5ff94231 in __gxx_personality_v0 () at ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/
#1  0x00002b3a66722625 in ossSleep (milliseconds=1000) at osstime.C:204
#2  0x00002b3a6305f69d in sqloAlarmThreadEntry (pArgs=0x0, argSize=0) at sqloalarm.C:453
#3  0x00002b3a63131703 in sqloEDUEntry (parms=0x2b3a6d7d91d0) at sqloedu.C:3402
(More stack frames follow...)

then page through that output, and find what you are looking for, set breakpoints and start debugging, but that can be tedious.

A different way, which requires some preparation, is by dumping to a log file, the thread id. There’s still a gotcha for that though, and you can see in the ‘info threads’ output that the thread ids (what’s you’d get if you call and log the value of pthread_self()) are big ass hexadecimal values that aren’t particularily easy to find in the ‘info threads’ output. Note that pthread_self() will return the base address of the stack itself (or something close to it) on a number of platforms since this can be used as a unique identifier, and linux currently appears to do this (AIX no longer does since around 4.3).

Also observe that gdb prints out (LWP ….) values in the ‘info threads’ output. These are the Linux kernel Task values, roughly equivalent to a threads’s pid as far as the linux kernel is concerned (linux threads and processes are all types of “tasks” … threads just happen to share more than processes, like virtual memory and signal handlers and file descriptors). At the time of this writing there isn’t a super easy way to dump this task id, but a helper function of the following form will do the trick:

#include <sys/syscall.h>
      int GetMyKernelThreadId(void)
         return syscall(__NR_gettid);

You’ll probably have to put this code in a separate module from other stuff since kernel headers and C runtime headers don’t get along well. Having done that you can call this in your dumping code, like the output below tagged with the prefix KTID (i.e. what a DB2 developer will find in n-builds in the coral project db2diag.log).

2009-08-28- I735590E1447          LEVEL: Severe
PID     : 13827                TID  : 47530154912064 KTID : 14559
PROC    : db2sysc 0

This identifier is much easier to pick out in the ‘info threads’ output (and is in this case thread 15), so get to yourself up and debugging now requires just:

(gdb) thread 15
[Switching to thread 15 (Thread 47530154912064 (LWP 14559))]#0  0x00002b3a5ff94231 in __gxx_personality_v0 ()
    at ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/
351     ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/ No such file or directory.
        in ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/
(gdb) where 5
#0  0x00002b3a5ff94231 in __gxx_personality_v0 () at ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/
#1  0x00002b3a66722625 in ossSleep (milliseconds=100) at osstime.C:204
#2  0x00002b3a6a29e674 in traceCrash () from /home/hotel77/peeterj/sqllib/lib64/
#3  0x00002b3a66732b66 in _gtraceEntryVar (threadID=47530154912064, ecfID=423100446, eduID=25, eduIndex=3, pNargs=3)
    at gtrace.C:2130
#4  0x00002b3a61145ade in pdtEntry3 (ecfID=423100446, t1=423100418, s1=16, p1=0x2b3a8a01c478, t2=36, s2=8, p2=0x2b3a79fde418,
    t3=3, s3=8, p3=0x2b3a79fde410) at pdtraceapi.C:2012
(More stack frames follow...)

Posted in debugging | Tagged: , , | 3 Comments »

Bivector form of quantum angular momentum operator (derivatives of spherical polar unit vectors and bivectors)

Posted by peeterjoot on August 27, 2009

[Click here for a PDF of this sequence of posts with nicer formatting]

Applying the vector derivative commutator (or not).

Let’s express the \hat{\boldsymbol{\theta}} and \hat{\boldsymbol{\phi}} unit vectors explicitly in terms of the standard basis. Starting with \hat{\boldsymbol{\theta}} we have

\begin{aligned}\hat{\boldsymbol{\theta}} &= \tilde{R} \mathbf{e}_1 R \\ &= e^{-\mathbf{e}_{12}\phi/2} e^{-\mathbf{e}_{31}\theta/2} \mathbf{e}_1 e^{\mathbf{e}_{31}\theta/2} e^{\mathbf{e}_{12}\phi/2} \\ &= e^{-\mathbf{e}_{12}\phi/2} \mathbf{e}_1 e^{\mathbf{e}_{31}\theta} e^{\mathbf{e}_{12}\phi/2} \\ &= e^{-\mathbf{e}_{12}\phi/2} (\mathbf{e}_1 \cos\theta -\mathbf{e}_3 \sin\theta) e^{\mathbf{e}_{12}\phi/2} \\ &= \mathbf{e}_1 \cos\theta e^{\mathbf{e}_{12}\phi} -\mathbf{e}_3 \sin\theta \end{aligned}

Explicitly in vector form, eliminating the exponential, this is \hat{\boldsymbol{\theta}} = \mathbf{e}_1 \cos\theta \cos\phi + \mathbf{e}_2 \cos\theta\sin\phi - \mathbf{e}_3\sin\theta, but it is more convenient to keep the exponential as is.

For \hat{\boldsymbol{\phi}} we have

\begin{aligned}\hat{\boldsymbol{\phi}} &= \tilde{R} \mathbf{e}_2 R \\ &= e^{-\mathbf{e}_{12}\phi/2} e^{-\mathbf{e}_{31}\theta/2} \mathbf{e}_2 e^{\mathbf{e}_{31}\theta/2} e^{\mathbf{e}_{12}\phi/2} \\ &= e^{-\mathbf{e}_{12}\phi/2} \mathbf{e}_2 e^{\mathbf{e}_{12}\phi/2} \\ &= \mathbf{e}_2 e^{\mathbf{e}_{12}\phi} \\  \end{aligned}

Again, explicitly this is \hat{\boldsymbol{\phi}} = \mathbf{e}_2 \cos\phi - \mathbf{e}_1 \sin\phi, but we’ll use the exponential form above. Last we want \hat{\mathbf{r}}

\begin{aligned}\hat{\mathbf{r}} &= \tilde{R} \mathbf{e}_3 R \\ &= e^{-\mathbf{e}_{12}\phi/2} e^{-\mathbf{e}_{31}\theta/2} \mathbf{e}_3 e^{\mathbf{e}_{31}\theta/2} e^{\mathbf{e}_{12}\phi/2} \\ &= e^{-\mathbf{e}_{12}\phi/2} \mathbf{e}_3 e^{\mathbf{e}_{31}\theta} e^{\mathbf{e}_{12}\phi/2} \\ &= e^{-\mathbf{e}_{12}\phi/2} (\mathbf{e}_3 \cos\theta + \mathbf{e}_1 \sin\theta) e^{\mathbf{e}_{12}\phi/2} \\ &= \mathbf{e}_3 \cos\theta + \mathbf{e}_1 \sin\theta e^{\mathbf{e}_{12}\phi} \\  \end{aligned}

Summarizing we have

\begin{aligned}\hat{\boldsymbol{\theta}} &= \mathbf{e}_1 \cos\theta e^{\mathbf{e}_{12}\phi} -\mathbf{e}_3 \sin\theta \\ \hat{\boldsymbol{\phi}} &= \mathbf{e}_2 e^{\mathbf{e}_{12}\phi} \\ \hat{\mathbf{r}} &= \mathbf{e}_3 \cos\theta + \mathbf{e}_1 \sin\theta e^{\mathbf{e}_{12}\phi}  \end{aligned} \quad\quad\quad(22)

Or without exponentials

\begin{aligned}\hat{\boldsymbol{\theta}} &= \mathbf{e}_1 \cos\theta \cos\phi + \mathbf{e}_2 \cos\theta\sin\phi - \mathbf{e}_3\sin\theta \\ \hat{\boldsymbol{\phi}} &= \mathbf{e}_2 \cos\phi - \mathbf{e}_1 \sin\phi \\ \hat{\mathbf{r}} &= \mathbf{e}_3 \cos\theta + \mathbf{e}_1 \sin\theta \cos\phi + \mathbf{e}_2 \sin\theta \sin\phi \end{aligned} \quad\quad\quad(25)

Now, having worked out the cool commutator result, it appears that it will actually be harder to use it, then to just calculate the derivatives directly (at least for the \hat{\boldsymbol{\phi}} derivatives). For those we have

\begin{aligned}\partial_\theta \hat{\boldsymbol{\phi}} &= \partial_\theta \mathbf{e}_2 e^{\mathbf{e}_{12}\phi} \\ &= 0 \end{aligned}


\begin{aligned}\partial_\phi \hat{\boldsymbol{\phi}} &= \partial_\phi \mathbf{e}_2 e^{\mathbf{e}_{12}\phi} \\ &= \mathbf{e}_2 \mathbf{e}_{12} e^{\mathbf{e}_{12}\phi} \\ &= -\mathbf{e}_{12} \hat{\boldsymbol{\phi}} \end{aligned}

This multiplication takes \hat{\boldsymbol{\phi}} a vector in the x,y plane and rotates it 90 degrees, leaving an inwards facing radial unit vector in the x,y plane.

Now, having worked out the commutator method, lets at least verify that it works.

\begin{aligned}\partial_\theta \hat{\boldsymbol{\phi}} &= \left[{\hat{\boldsymbol{\phi}}},{\Omega_\theta}\right] \\ &= \hat{\boldsymbol{\phi}} \Omega_\theta - \Omega_\theta \hat{\boldsymbol{\phi}} \\ &= \frac{1}{{2}} (\hat{\boldsymbol{\phi}} \mathbf{e}_{31} e^{\mathbf{e}_{12}\phi} - \mathbf{e}_{31} e^{\mathbf{e}_{12}\phi} \hat{\boldsymbol{\phi}})  \\ &= \frac{1}{{2}} (\mathbf{e}_2 \mathbf{e}_3 \mathbf{e}_1 e^{-\mathbf{e}_{12}\phi} e^{\mathbf{e}_{12}\phi} - \mathbf{e}_{3} \mathbf{e}_{1} \mathbf{e}_{2} e^{-\mathbf{e}_{12}\phi} e^{\mathbf{e}_{12}\phi})  \\ &= \frac{1}{{2}} (-\mathbf{e}_3 \mathbf{e}_2 \mathbf{e}_1 - \mathbf{e}_{3} \mathbf{e}_{1} \mathbf{e}_{2} )  \\ &= 0 \end{aligned}

Much harder this way compared to taking the derivative directly, but we at least get the right answer. For the \phi derivative using the commutator we have

\begin{aligned}\partial_\phi \hat{\boldsymbol{\phi}} &= \left[{\hat{\boldsymbol{\phi}}},{\Omega_\phi}\right] \\ &= \hat{\boldsymbol{\phi}} \Omega_\phi - \Omega_\phi \hat{\boldsymbol{\phi}} \\ &= \frac{1}{{2}} (\hat{\boldsymbol{\phi}} \mathbf{e}_{12} - \mathbf{e}_{12} \hat{\boldsymbol{\phi}})  \\ &= \frac{1}{{2}} (\mathbf{e}_2 e^{\mathbf{e}_{12}\phi} \mathbf{e}_{12} - \mathbf{e}_{12} \mathbf{e}_2 e^{\mathbf{e}_{12}\phi})  \\ &= \frac{1}{{2}} (-\mathbf{e}_{12} \mathbf{e}_2 e^{\mathbf{e}_{12}\phi} - \mathbf{e}_{12} \mathbf{e}_2 e^{\mathbf{e}_{12}\phi})  \\ &= -\mathbf{e}_{12} \hat{\boldsymbol{\phi}} \end{aligned}

Good, also consistent with direct calculation. How about our \hat{\boldsymbol{\theta}} derivatives? Lets just calculate these directly without bothering at all with the commutator. This is

\begin{aligned}\partial_\phi \hat{\boldsymbol{\theta}} &= \mathbf{e}_1 \cos\theta \mathbf{e}_12 e^{\mathbf{e}_{12}\phi}  \\ &= \mathbf{e}_2 \cos\theta e^{\mathbf{e}_{12}\phi}  \\ &= \cos\theta \hat{\boldsymbol{\phi}} \end{aligned}


\begin{aligned}\partial_\theta \hat{\boldsymbol{\theta}} &= -\mathbf{e}_1 \sin\theta e^{\mathbf{e}_{12}\phi} -\mathbf{e}_3 \cos\theta \\ &= -\mathbf{e}_{12} \sin\theta \hat{\boldsymbol{\phi}} -\mathbf{e}_3 \cos\theta \\  \end{aligned}

Finally, last we have the derivatives of \hat{\mathbf{r}}. Those are

\begin{aligned}\partial_\phi \hat{\mathbf{r}} &= \mathbf{e}_2 \sin\theta e^{\mathbf{e}_{12}\phi} \\ &= \sin\theta \hat{\boldsymbol{\phi}} \end{aligned}


\begin{aligned}\partial_\theta \hat{\mathbf{r}} &= -\mathbf{e}_3 \sin\theta + \mathbf{e}_1 \cos\theta e^{\mathbf{e}_{12}\phi} \\ &= -\mathbf{e}_3 \sin\theta + \mathbf{e}_{12} \cos\theta \hat{\boldsymbol{\phi}} \\  \end{aligned}

Summarizing, all the derivatives we need to evaluate the square of the angular momentum operator are

\begin{aligned}\partial_\theta \hat{\boldsymbol{\phi}} &= 0 \\ \partial_\phi \hat{\boldsymbol{\phi}} &= -\mathbf{e}_{12} \hat{\boldsymbol{\phi}} \\ \partial_\theta \hat{\boldsymbol{\theta}} &= -\mathbf{e}_{12} \sin\theta \hat{\boldsymbol{\phi}} -\mathbf{e}_3 \cos\theta  \\ \partial_\phi \hat{\boldsymbol{\theta}} &= \cos\theta \hat{\boldsymbol{\phi}} \\ \partial_\theta \hat{\mathbf{r}} &= -\mathbf{e}_3 \sin\theta + \mathbf{e}_{12} \cos\theta \hat{\boldsymbol{\phi}} \\ \partial_\phi \hat{\mathbf{r}} &= \sin\theta \hat{\boldsymbol{\phi}}  \end{aligned} \quad\quad\quad(28)

Bugger. We actually want the derivatives of the bivectors \hat{\mathbf{r}}\hat{\boldsymbol{\theta}} and \hat{\mathbf{r}}\hat{\boldsymbol{\phi}} so we aren’t ready to evaluate the squared angular momentum. There’s three choices, one is to use these results and apply the chain rule, or start over and directly take the derivatives of these bivectors, or use the commutator result (which didn’t actually assume vectors and we can apply it to bivectors too if we really wanted to).

An attempt to use the chain rule get messy, but it looks like the bivectors reduce nicely, making it pointless to even think about the commutator method. Introducing some notational conveniences, first write i = \mathbf{e}_{12}. We’ll have to be a bit careful with this since it commutes with \mathbf{e}_3, but anticommutes with \mathbf{e}_1 or \mathbf{e}_2 (and therefore \hat{\boldsymbol{\phi}}). As usual we also write I = \mathbf{e}_1 \mathbf{e}_2 \mathbf{e}_3 for the Euclidean pseudoscalar (which commutes with all vectors and bivectors).

\begin{aligned}\hat{\mathbf{r}} \hat{\boldsymbol{\theta}}&= (\mathbf{e}_3 \cos\theta + i \sin\theta \hat{\boldsymbol{\phi}})(\cos\theta i \hat{\boldsymbol{\phi}} - \mathbf{e}_3 \sin\theta) \\ &= \mathbf{e}_3 \cos^2\theta i \hat{\boldsymbol{\phi}} -i \sin^2\theta \hat{\boldsymbol{\phi}} \mathbf{e}_3 +(i \hat{\boldsymbol{\phi}} i \hat{\boldsymbol{\phi}} -\mathbf{e}_3 \mathbf{e}_3 ) \cos\theta \sin\theta \\ &= i \mathbf{e}_3 (\cos^2\theta + \sin^2\theta) \hat{\boldsymbol{\phi}} +(-\hat{\boldsymbol{\phi}} i^2 \hat{\boldsymbol{\phi}} - 1) \cos\theta \sin\theta \\  \end{aligned}

This gives us just

\begin{aligned}\hat{\mathbf{r}} \hat{\boldsymbol{\theta}} = I \hat{\boldsymbol{\phi}} \end{aligned} \quad\quad\quad(34)

and calculation of the bivector partials will follow exclusively from the \hat{\boldsymbol{\phi}} partials tabulated above.

Our other bivector doesn’t reduce quite as cleanly. We have

\begin{aligned}\hat{\mathbf{r}} \hat{\boldsymbol{\phi}} &=(\mathbf{e}_3 \cos\theta + i \sin\theta \hat{\boldsymbol{\phi}}) \hat{\boldsymbol{\phi}} \\  \end{aligned}

So for this one we have

\begin{aligned}\hat{\mathbf{r}} \hat{\boldsymbol{\phi}} = \mathbf{e}_3 \hat{\boldsymbol{\phi}} \cos\theta + i \sin\theta  \end{aligned} \quad\quad\quad(35)

Tabulating all the bivector derivatives (details omitted) we have

\begin{aligned}\partial_\theta (\hat{\mathbf{r}} \hat{\boldsymbol{\theta}}) &= 0 \\ \partial_\phi (\hat{\mathbf{r}} \hat{\boldsymbol{\theta}}) &= \mathbf{e}_3 \hat{\boldsymbol{\phi}} \\ \partial_\theta (\hat{\mathbf{r}} \hat{\boldsymbol{\phi}}) &= -\mathbf{e}_3 \hat{\boldsymbol{\phi}} \sin\theta + i \cos\theta = i e^{I\hat{\boldsymbol{\phi}}\theta} \\ \partial_\phi (\hat{\mathbf{r}} \hat{\boldsymbol{\phi}}) &= -I \hat{\boldsymbol{\phi}} \cos\theta \end{aligned} \quad\quad\quad(36)

Okay, we are now armed to do the squaring of the angular momentum, but once again it’s late to start now. To be continued.

Posted in Math and Physics Learning. | Tagged: , , , | Leave a Comment »

perl regex tricks. Non capturing expressions and alternatives.

Posted by peeterjoot on August 27, 2009

Have two sets of dump output to compare, and both have the occasional pointer dumped which messes up the diff. I want to mask the pointer output (all starting with 0x) on all the lines like:

 List Entry Address:           0x...
 List Tail (primary):             0x...
 List Tail (secondary):           0x...
 Next entry name collision:    0x...
 Next entry PLEID collision:   0x...
 Next entry (primary):         0x...
 Next entry (secondary):       0x...
 Previous entry (primary):     0x...
 Previous entry (secondary):   0x...

An easy way would be to run ‘grep -v’ and just filter these out completely, but I wanted the original line numbers to stay intact for reference.

Here’s a one liner perl script, executed with ‘perl -pi ./myScript *.fmt’ (where the files *.fmt are what I’m mucking with) :

$ cat myScript
s/((?i:Next|List|previous) (?i:entry|head|tail).*0x).*/$1................/;

Since I had to lookup (man perlre) how to do this once again, it’s a good blog topic for self reference. Let’s break it down. First thing is an outermost capturing pattern


this says match ‘stuff.*0x’, namely ‘stuff’ followed by anything (the .* part), then ‘0x’, then anything. All of this within the braces goes into $1, so the replacement is everything on the line except whatever follows 0x (and for that I replaced with 16 dots). Now look at the nested expression before the .*0x part:

(?i:Next|List|previous) (?i:entry|head|tail)

More perl ASCII barf starting things off, but it’s not so bad. If you have an expression like (?:stuff) it means match ‘stuff’ but don’t capture it (i.e. don’t put it in $2 or $3, …). Only slightly more complex is having alternatives in the pattern, so something like (?:Next|List) means match Next or match List, but also don’t put anything into a $N variable. There’s one more bit in there unexplained, the ‘i’ modifier flag. This is a way to add case Insensitive to the pattern. In this case I could have made that a global flag at the end of the replace specification so it would apply to the whole pattern:

s/((?:Next|List|previous) (?:entry|head|tail).*0x).*/$1................/i;

but initially I had the case Insensitive modifier only on one of the patterns, so the final result ended up with some redundancy.

Posted in perl and general scripting hackery | Tagged: , | Leave a Comment »

Bivector form of quantum angular momentum operator (derivatives of the unit vectors)

Posted by peeterjoot on August 26, 2009

[Click here for a PDF of this post with nicer formatting]

Derivatives of the unit vectors

To properly evaluate the angular momentum square we’ll need to examine the \partial_\theta and \partial_\phi variation of the unit vectors \hat{\mathbf{r}}, \hat{\boldsymbol{\theta}}, and \hat{\boldsymbol{\phi}}. Some part of this question can be evaluated without reference to the specific vector or even which derivative is being evaluated. Writing e for one of \mathbf{e}_1, \mathbf{e}_2, or \mathbf{e}_k, and \sigma = \tilde{R} e R for the mapping of this vector under rotation, and \partial for the desired \theta or \phi partial derivative, we have

\begin{aligned}\partial (\tilde{R} e R)&=(\partial \tilde{R}) e R + \tilde{R} e (\partial R) \end{aligned} \quad\quad\quad(18)

Since \tilde{R} R = 1, we have

\begin{aligned}0 &= \partial (\tilde{R} R) \\ &=(\partial \tilde{R}) R + \tilde{R} (\partial R) \end{aligned}

So substitution of (\partial \tilde{R}) = -\tilde{R} (\partial R) \tilde{R}, back into (18) supplies

\begin{aligned}\partial (\tilde{R} e R)&=-\tilde{R} (\partial R) \tilde{R} e R + \tilde{R} e (\partial R) \\ &=-\tilde{R} (\partial R) (\tilde{R} e R) + (\tilde{R} e R) \tilde{R} (\partial R) \\ &=-\tilde{R} (\partial R) \sigma + \sigma \tilde{R} (\partial R) \\  \end{aligned}

Writing the bivector term as

\begin{aligned}\Omega = \tilde{R} (\partial R)  \end{aligned} \quad\quad\quad(19)

The change in the rotated vector is seen to be entirely described by the commutator of that vectors image under rotation with \Omega. That is

\begin{aligned}\partial \sigma = \left[{\sigma},{\Omega}\right] \end{aligned} \quad\quad\quad(20)

Our spherical polar rotor was given by

\begin{aligned}R = e^{\mathbf{e}_{31}\theta/2} e^{\mathbf{e}_{12}\phi/2} \end{aligned} \quad\quad\quad(21)

Lets calculate the \Omega bivector for each of the \theta and \phi partials. For \theta we have

\begin{aligned}\Omega_\theta &= \tilde{R} \partial_\theta R \\ &= \frac{1}{2} e^{-\mathbf{e}_{12}\phi/2} e^{-\mathbf{e}_{31}\theta/2} \mathbf{e}_{31} e^{\mathbf{e}_{31}\theta/2} e^{\mathbf{e}_{12}\phi/2} \\ &= \frac{1}{2} e^{-\mathbf{e}_{12}\phi/2} \mathbf{e}_{31} e^{\mathbf{e}_{12}\phi/2} \\ &= \frac{1}{2} \mathbf{e}_3 e^{-\mathbf{e}_{12}\phi/2} \mathbf{e}_{1} e^{\mathbf{e}_{12}\phi/2} \\ &= \frac{1}{2} \mathbf{e}_{31} e^{\mathbf{e}_{12}\phi} \\  \end{aligned}

Explicitly, this is the bivector \Omega_\theta = (\mathbf{e}_{31} \cos\theta + \mathbf{e}_{32} \sin\theta)/2, a wedge product of a vectors in \hat{\mathbf{z}} direction with one in the perpendicular x-y plane (curiously a vector in the x-y plane rotated by polar angle \theta, not the equatorial angle \phi).

FIXME: picture. Draw this plane cutting through the sphere.

For the \phi partial variation of any of our unit vectors our bivector rotation generator is

\begin{aligned}\Omega_\phi &= \tilde{R} \partial_\phi R \\ &= \frac{1}{2} e^{-\mathbf{e}_{12}\phi/2} e^{-\mathbf{e}_{31}\theta/2} e^{\mathbf{e}_{31}\theta/2} \mathbf{e}_{12} e^{\mathbf{e}_{12}\phi/2} \\ &= \frac{1}{2} \mathbf{e}_{12} \\  \end{aligned}

This one has no variation at all with angle whatsoever. If this is all correct so far perhaps that is not surprising given the fact that we expect an extra \cot\theta in the angular momentum operator square, so a lack of \phi dependence in the rotation generator likely means that any additional \phi dependence will cancel out. Next step (for a different day) is to take these rotation generator bivectors, apply them via commutator products to the \hat{\mathbf{r}}, \hat{\boldsymbol{\theta}}, and \hat{\boldsymbol{\phi}} vectors, and see what we get.

Posted in Math and Physics Learning. | Tagged: , , , | Leave a Comment »

another good regex trick. Matching a word boundary.

Posted by peeterjoot on August 26, 2009

Task: Have a badly named variable, in this case caKeyValue, and want to change this in a number of files to caKeySample.

I’ve also got variables named m_caKeyValue that I don’t want to change. Once I’m done this replacement, all the variables left with caKeyValue in their names will be the ones I’m interested in, and I can examine all of those in sequence to make sure that I’m treating those right.

A regular expression with a word boundary pattern is the trick. Here’s a sample command, starting with a small file that has my search and replace patterns:

$ cat myPatterns
# if there are trailing spaces then try not to mess up indenting:
s/\bcaKeyValue\b  /caKeySample /g;

# but mess up indenting if there's no option:

and here’s the perl command line invocation to do the replacement:

$ perl -pi ./myPatterns `cat listOfFiles`

Let’s break it down. First the command. We use -p -i perl command line flags as explained in previous posts, this treats the perl script like it’s a while loop and modifies all the files (in this case without backup since I’ve just checked them out of the version control system).

If the perl script containing the search and replace patterns I want were to contain just:


Then all instances of caKeyValue would be replaced. I only want this if they aren’t embedded in something else (like m_caKeyValue). If I only cared about not mucking with variables named m_caKeyValue then a sufficient replacement expression would be:


This says it’s okay to do the replacement if something trails “caKeyValue” without spaces, so caKeyValues, say, would be replaced by caKeySamples. To be careful I’m telling perl to be stricter, requiring something that is recognized as a separator (like whitespace) at both the beginning and the end of the expression. That is:


Now, a diff of the results with the originals in the version control system (something to _always_ do with automated code changes) showed that I was messing up the indentation in some cases, as in the following diff fragment:

-   SAL_ENCODED_CA_STATE                caKeyValue        = m_caKey.SAL_SampleCaKeyValue() ;
+   SAL_ENCODED_CA_STATE                caKeySample        = m_caKey.SAL_SampleCaKeyValue() ;

So, to compensate, I undid my automated change and added a first replacement pattern to keep things pretty:

s/\bcaKeyValue\b  /caKeySample /g;

This one is match the expression with two trailing spaces and replace it with the desired, plus one trailing space. Note that the trailing \b is spurious in this case, but since I was cut and pasting the regex based on the initial try, I had this extra bit and it doesn’t change the desired result.

Posted in perl and general scripting hackery | Tagged: , | Leave a Comment »