

> {-# OPTIONS -fno-warn-missing-methods #-}





> data Matrix a = M [[a]] deriving (Eq,Show)



> instance Functor Matrix where

> fmap f (M a) = M $ map (map f) a



> instance Num a => Num (Matrix a) where

> M a * M b = M $ mult a b



A Lie Group



> rx theta = M $ [[1,0,0],

> [0,cos theta,-sin theta],

> [0,sin theta,cos theta]]



> ry theta = M $ [[cos theta,0,sin theta],

> [0,1,0],

> [-sin theta,0,cos theta]]



> rz theta = M $ [[cos theta,-sin theta,0],

> [sin theta,cos theta,0],

> [0,0,1]]





> euler [a,b,c] = rx a*ry b*rz c



euler



> euler' [a,b,c] = rz c*ry b*rx a



euler

euler'

rx theta*rx (-theta)



> commutator a b = inverse a*inverse b*a*b



inverse a*inverse b*b*a

inverse



> inverse = transpose



commutator (rx 1) (ry 2)

euler

A Lie Algebra



> d :: Num a => Dual a

> d = D 0 1



d*d



> rot1 = euler [d,2*d,3*d]



rot1

fmap im rot1

euler

rot2



> rot2 = euler' [d,2*d,3*d]





> rot3 = euler [5*d,-d,2*d]



fmap im (rot1*rot3)

fmap im rot1

fmap im rot3



> star [a,b,c] = M $ [[0, -c, b],

> [c,0,-a],

> [-b,a,0]]



fmap im (euler [a*d,b*d,c*d]) == star [a,b,c]

fmap im (euler [a*d,b*d,c*d]*euler [u*d,v*d,w*d]) == fmap im (euler [(a+u)*d,(b+v)*d,(c+w)*d])

d

Dual



> e :: Num a => Dual (Dual a)

> e = D (D 0 1) (D 1 0)



Dual

e^2

e^3



> comm1 = commutator (euler [e,0,0]) (euler [0,e,0])



fmap re comm1

fmap im comm2

d

e^2

(im . im) (e^2)

e^2

comm1



> im2 x = im (im x)/2



fmap im2 comm1 == star [0,0,1]



> shrink u = fmap (e*) u



fmap im2 (commutator (euler (shrink u)) (euler (shrink v))) == star (u `cross` v)

f

f^4

f^3

euler

Appendix (the bits of code I left out above)



> data Dual a = D a a deriving (Show,Eq)





> re (D a _) = a

> im (D _ b) = b



> instance Num a => Num (Dual a) where

> fromInteger i = D (fromInteger i) 0

> (D a a')+(D b b') = D (a+b) (a'+b')

> (D a a')-(D b b') = D (a-b) (a'-b')

> (D a a')*(D b b') = D (a*b) (a*b'+a'*b)



> instance Floating a => Floating (Dual a) where

> cos (D a a') = D (cos a) (-sin a*a')

> sin (D a a') = D (sin a) (cos a*a')



> instance Fractional a => Fractional (Dual a)





> mult a ([]:_) = map (const []) a

> mult a b = zipWith (:) (map (dot (map head b)) a) (mult a (map tail b))



> transpose (M a) = M $ transpose' a where

> transpose' [] = repeat []

> transpose' (xs : xss) = zipWith (:) xs (transpose' xss)





> dot a b = foldr (+) 0 $ zipWith (*) a b

> cross [a,b,c] [d,e,f] = [b*f-c*e,c*d-a*f,a*e-b*d]



A little while back I tried to give a rough idea of what Lie algebras were about. What I want to do now is show how with a bit of Haskell code we can directly get our hands on one. I'm going to assume you know how to make matrices for rotations, and multiply them, and some knowledge from previous posts, for which I'll give links.Firstly a bit of Haskell administration:Now we need some quick and dirty matrix code:What I'm going to do is start by constructing elements of the group of 3D rotations, otherwise known as SO(3), and show how there's another algebraic structure hidden inside it. So let's make some rotation matrices:These are the three rotations around the x-, y- and z-axes. It's traditional to build arbitrary rotations through the use of Euler angles The 3D rotations form an example of a Lie group . (A Lie group is essentially a group where the operations like multiplication are differentiable.)Any 3D rotation can be constructed from a single application of. But notice how there's a bit of ugliness in this function. I've made an arbitrary choice of which order to apply the rotations in. I could have defined:And it's easy to show that. This is because rotations don't commute . In other words, for rotations, a*b≠b*a.We can measure the non-commutativity. Remember that any rotation has an inverse. For examplegives us the identity matrix because one of these two rotations 'undoes' the other. Given any two rotations we can construct what is known as their commutator The idea is that we first perform b, then a, then undo b and then undo a. If a and b commute then this expression can be rearranged toand then the inverses cancel leaving us with the identity matrix. If they don't commute then we end up with a non-identity matrix. So the comuutator measures the extent to which matrices don't commute.As I'm feeling lazy, I don't feel like writing. Instead, as I'm only going to work with rotations, I'll use the fact that the inverse of a rotation matrix is the transpose and define:Try playing with expressions like. Note how the numbers quickly get messy. Try to write down closed form expressions for applications ofand you'll see how complex things can get.But there's another way to approach the rotation group - through 'infinitesimal' rotations. In my earlier article I just talked about infinitesimal group operations in a hand-wavey way. Now I'm going to make the notion more rigorous. We just need to introduce an infinitesimal number, d, whose square is zero. I've talked about this a lot before so I'm borrowing my earlier code and defining:If you try it you'll see thatis zero.Now we can try making infinitesimal rotations:Note how when we evaluate this we get 'nice' numbers. No need to worry about those trig functions any more. And if you look closely atyou'll see that it's essentially the identity matrix plus an infinitesimal part. We can pull the infinitesimal part out using. You may be able to guess how to build it from the arguments to. But first, try evaluatingIt's the same! Try other infiitesimal rotations. When dealing with infinitesimal rotations it doesn't matter what order you apply them in, you get the same result. Working with infinitesimal rotations is looking much easier than working with full=size rotations. In fact, it gets better. Try definingNow look atand compare withand. We can multiply infinitesimal rotations simply by adding their infinitesimal parts. In fact, we can defineSo we have:andNot a single trig expression anywhere!So we have a simplified way of viewing rotations by looking at infinitesimal rotations. A triple [a,b,c] can be thought of as representing an infinitesimal rotation through star and instead of multiplying matrices we just add the triples elementwise. These triples, together with the binary operation of addition form an example of a Lie algebra. But there's a piece missing. We have lost all information about the non-commutativity of the rotations. It's one thing to simplify, but it's another to lose an important feature of what you're looking at.The problem is thatis 'too small'. We need an infinitesimal that doesn't go to zero the moment you square it, but is still, in some sense, infinitesimally small. We could rewrite thetype. But there's a trick. Define:(If you think ofas forming a tensor product as I described here then e=1⊗d+d⊗1.)You can check thatis non-zero butis zero.Now when we compute a commutator we get something a little different:is essentially the identity as before. But if we look atthere's a non-zero infinitesimal piece which is different from what we had when we worked with. This infinitesimal piece is in fact proportional to. Asis a half, we can extract the coefficient offromusingIn fact, we have. So by choosing infinitesimals that aren't too small, we haven't lost information about non-commutativity. In fact, a bit of experimentation may convince you that with:we have:So let's step back a bit and recapitulate all this in something approaching English:Given a tiny rotation we can represent it as three Euler angles a, b, c, all of which are tiny. We can think of a, b and c as forming a vector [a,b,c]. When we do this, apart from an even smaller error, multiplication of rotations becomes ordinary addition of vectors and the order of rotations isn't significant. But if we choose not to ignore this small error we see that a rotation represented by u and a rotation represented by v don't quite commute and the order does matter. The size of this error is measured by the cross product of u and v. This is intuitively plausible, we'd expect that rotations defined by vectors in a similar direction would be closer to commuting, and this is reflected in the fact that the cross product is zero for parallel vectors.So now I can fill in the missing piece from the description of the Lie algebra I gave above. The Lie algebra so(3) consists of the 3d vectors (representing infinitesimal rotations), addition of vectors (representing multiplcation of infinitesimal rotations) and the cross product (measuring the amount by which small rotations fail to commute). This picture doesn't just apply to the rotations, a similar one applies for any Lie group. We get the same pattern of a simplified form of multiplication and a binary operation that measures non-commutativity.But you might still ask if there's something missing. What if we definedso thatis zero butisn't? Would we extract more information about the non-commutativity of rotations? Well the interesting fact, which I won't prove here, is that it doesn't. Almost everything you need to know about a Lie group can be extracted from its Lie algebra. In fact, from a group's Lie algebra you can almost recover the original group. (In fact, what you recover is its universal cover .) But notice how there are no trig formulae involved when talking about Lie algebras. Lie algebras give a really nice way to study Lie groups without getting your hands too dirty. But this isn't the only reason to study Lie algebras, many physical properties arising from symmetries are more naturally studied through the Lie algebra because Lie algebras arise from Lie groups as soon as you start differentiating things. In particular, Lie algebras play a major role in Noether's theorem , one of the cornerstones of modern theoretical physics.In summary then, I hope I've given some flavour of Lie algebras. Using infinitesimals you can get your hands on them directly without the use of a large amount of mathematical machinery . There has been some difficult stuff here, but I'm hoping that the freedom you now have at the Haskell prompt to play with the things I've been talking about will make up for the inadequacies of my explanations.One last word: in principle we could do the same with E8. But we'd need 248 by 248 matrices, and the equivalent ofwould need 248 parameters. (That's a coincidence, in general the number of parameters needed to define an element of a Lie group isn't equal to the dimension of the matrix, but it is for SO(3) and E8).Defining the infinitesimals:Extract the 'full-size' and 'infinitesimal' parts of a number:Some useful matrix and vector operations:Some simple vector operations

Labels: haskell, mathematics, physics