11

I'm just getting tucked into fortran 95 for some quantum mechanics simulations. Honestly, I've been spoiled by Octave so I've taken matrix exponentiation for granted. Given a (small, $n\leq 36$) skew-Hermitian matrix of size $n\times n$, what is the most efficient way of using LAPACK to solve this problem? I'm not using the LAPACK95 wrapper, just direct calls to LAPACK.

David Ketcheson
  • 16,522
  • 4
  • 54
  • 105
qubyte
  • 491
  • 4
  • 15

4 Answers4

16

Matrix exponentials of skew-Hermitian matrices are cheap to compute:

Suppose $A$ is your skew-Hermitian matrix, then $iA$ is Hermitian, and via zheevd and friends you can get the decomposition

$$iA = U \Lambda U^H,$$

where $U$ is the unitary eigenvector matrix and $\Lambda$ is real and diagonal. Then, trivially,

$$A = U (-i \Lambda) U^H.$$

Once you have $U$ and $\Lambda$, it is easy to compute

$$\exp(A)=\exp(U (-i\Lambda) U^H)=U \exp(-i\Lambda) U^H$$

by first exponentiating the eigenvalues, setting $B := U$ via zcopy, performing $B := B \exp(-i \Lambda)$ by running zscal on each column with an exponentiated eigenvalue, and finally setting your result to

$$ \exp(A) := B U^H$$

via zgemm.

Jack Poulson
  • 7,599
  • 32
  • 40
  • Thanks! I missed an obvious trick there with the $i$. You've put me onto the specific LAPACK subroutines that I need, so extra thanks for that. I won't mark this as correct yet (want to test it out first). – qubyte Feb 08 '12 at 15:56
  • 1
    No rush. I've actually implemented it before, so I'm pretty confident :-) – Jack Poulson Feb 08 '12 at 16:02
  • This is going to be one of those magical bits of code I use all over the place. For what it's worth, I'll also put a thank you in a comment line that probably nobody else will ever see. – qubyte Feb 08 '12 at 16:04
  • @MarkS.Everitt: There was an important typo in my original version, make sure to call the Hermitian eigensolver, zheevd, not the general complex one, zgeev. – Jack Poulson Feb 08 '12 at 16:38
  • 3
    @JackPoulson: Well played, sir. This is what I get for picking a major that doesn't believe in imaginary numbers (other than in eigenvalues). – Geoff Oxberry Feb 08 '12 at 18:44
  • @GeoffOxberry: I just noticed that I had been missing a minus sign (introduced at a 'trivial' equality), so I will continue to eat humble pie. – Jack Poulson Feb 08 '12 at 19:23
  • 1
    @JackPoulson: It works beautifully. Thanks again for this. Especially the zscal bit. I had most of the rest of the code in another subroutine, but this was something I'd overlooked. – qubyte Feb 09 '12 at 02:54
  • @JackPoulson: Naive question; is there a reason to use zcopy rather than B = U in this instance? – qubyte Feb 09 '12 at 06:20
  • @MarkS.Everitt: Not really, but there is a small possibility that zcopy is more optimized than the built in function. Also, despite knowing BLAS and LAPACK pretty well, I know very little Fortran and did not know one could do that :-) – Jack Poulson Feb 09 '12 at 06:40
  • Matrix valued stuff is one of the reasons I started using fortran recently. In it's newer incarnations fortran makes everything a lot more readable than (my admittedly dodgy) C. – qubyte Feb 09 '12 at 06:56
  • As an additional +1, I'd like to say that this is very slick. – Mikola Jun 27 '12 at 09:28
5

Since I'm on my phone, I can't link things easily, and will add links later. You'll probably want to look at the paper "19 Dubious Ways to Calculate the Matrix Exponential", the Fortran library EXPOKIT, Jitse Niesen's paper on Krylov methods for calculating the Matrix exponential, and some of Nick Higham's recent papers on matrix exponentials. It's more common to need the product of a matrix exponential and a vector than the matrix exponential alone, and here, Krylov methods can be quite helpful. For smaller, dense matrices like the ones you describe, Padé methods might be better, but I've had a lot of success with Krylov methods when used inside exponential methods for numerical integration of ODEs.

Geoff Oxberry
  • 30,394
  • 9
  • 64
  • 127
  • Thanks. I'm aware of 19 dubious ways, and also expokit, but some of the people I'm working with are in industry, so I want to avoid it for copyright reasons. I'm keen on implementing it with LAPACK/BLAS since I already link to these libraries.

    One thing though; I do need the matrix exponential itself. I'm working on a variant of quantum process tomography, and the process in question is embodied by the matrix. Later I'll be dealing with an integrator in combination with this matrix exponential, which is when it gets really interesting!

    – qubyte Feb 08 '12 at 15:50
1

The complex eigensolution approach is mathematically correct, but it does more work than necessary. Unfortunately, the improved approach I'm about to describe cannot be implemented with LAPACK calls.

Look at R. C. Ward and L. J. Gray, ACM Trans. Math. Soft. 4, 278, (1978). This describes the software that is available in TOMS algorithm 530, and which you can download from netlib. This describes how to factor the skew symmetric matrix $X$ as

$$X = U D U^T$$

where $U$ is real orthogonal and $D$ is real skew-symmetric and block diagonal. The diagonal subblocks are either $2\times 2$ or $1\times 1$. Because it is block diagonal, you can exponentiate each subblock separately. The $1\times 1$ blocks are zero, and $\exp(0)=1$, so those are trivial. The $2\times 2$ subblocks are done with

$$\exp \begin{pmatrix} 0 & -t \\ t & 0 \end{pmatrix} = \begin{pmatrix} \cos t & -\sin t \\ \sin t & \cos t \end{pmatrix}$$

The exponential matrix that you want is then given by

$$\exp(X) = U \exp(D) U^T$$

I have used this approach in my quantum chemistry codes for several decades and I have never had any problems with any of the software involved.

  • Hello @Ron Shepard, and welcome to Computational Exchange SE. Can you edit your second and third equations? They are a little hard to understand. – nicoguaro Aug 15 '14 at 22:19
0

If all you need is the matrix exponential multiplied by a vector, then this fortran subroutine may be of some use to you. It computes:

$(e^A)v$

where v is a vector, and A is a regular hermitian matrix. It is a subroutine from the EXPOKIT library

Otherwise, you may want to consider this subroutine, which works for any general complex matrix A.

Paul
  • 12,045
  • 7
  • 56
  • 129
  • That does not look like a reference to Fortran libraries. – Geoff Oxberry Feb 08 '12 at 15:19
  • @GeoffOxberry: I rewrote it to include the fortran subroutines – Paul Feb 08 '12 at 15:34
  • @Paul: No good I'm afraid. What I'm doing is an all-matrix variation on process tomography. In addition *skew*-Hermitian! – qubyte Feb 08 '12 at 15:40
  • I appreciate that you rewrote your answer, but based on the edit trail, it looks like you completely changed your answer, took elements of my chronologically earlier answer, and added links. – Geoff Oxberry Feb 08 '12 at 15:43
  • @GeoffOxberry: On the contrary... My results came independently of yours, but you posted before I got a chance to re-write my answer:) – Paul Feb 08 '12 at 15:46