The Group SU(2)

325 days ago by sweetser

r""" su2 - makes 3 parameter quaternions with a norm of one. Takes a quaternion, tosses away the scalar, then uses an exponential function to get the norm to one. Can be fed different streams of the 3 quaternions, so there is no "correct" look, other than it must be a subgroup of the completely random quaternions fed into this function. AUTHORS: -- Doug Sweetser (2009): Initial version. EXAMPLES: Test the group U(1). sage: q1 = q(2, 1, 2, 0); q2 = q(-79/81, -8/81, -16/81, 0) sage: q1.group_u1(2) == q2 True """ #***************************************************************************** # Copyright (C) 2009 Doug Sweetser <sweetser@alum.mit.edu> # # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #***************************************************************************** 
       
class q(list): def __init__(self,t,x,y,z): self.t = t self.x = x self.y = y self.z = z self.qn = [] list.__init__(self,[t,x,y,z]) def __repr__(self): return "The group U(1)." def show(self): print self.t, self.x, self.y, self.z def vector(self): return q(0, self.x, self.y, self.z) def n_random(self, n): self.qn[:]=[] for i in range(n): self.qn.append(q(2 * random() - 1, 2 * random() - 1, 2 * random() - 1, 2 * random() - 1)) return self # exp(q) = (exp(t) cos(|R|), exp(t) sin(|R|) R/|R|) def exp(self): abs_vector = sqrt(self.x^2 + self.y^2 + self.z^2) if abs_vector == 0: return q(exp(self.t), 0, 0, 0) k = exp(self.t) * sin(abs_vector) / abs_vector return q(exp(self.t) * cos(abs_vector), k * self.x, k * self.y, k * self.z) def su2(self): return self.vector().exp() #auto 
       
# Test - note: y = 0 for all members with this starting element. q1 = q(1, 4, 0, 3); q2 = q(cos(5), 4 * sin(5)/5, 0, 3 * sin(5)/5) q1.su2() == q2 
       
True
q1 = q(1., 2., 3., 4.) q1.su2().show() 
       
.6231593449762197 
                              - .2904627534478825 
                              - .4356941301718237 
                              - .5809255068957649
q1.n_random(5); for r in q1.qn: r.su2().show() 
       
.5262536883523027 
                             - 0.0155427275346411 
                              - .2275411494312164 
                              - .8191706198539485

                               .5467222067483892 
                              - .4240485929797214 
                               .7217556407203103 
                             - .01861221449760107

                               .4186463521978034 
                              - .1106727975564307 
                              - .4750303817968784 
                              - .7660501942055873

                               0.733954197248557 
                              - .5507467099359195 
                               .1341587419843532 
                               .3741533506266678

                               .2613732821649298 
                              - .3204537648151394 
                               0.702825469703495 
                              - .5788175456240049
r""" Elements of the group SU(2) can be generated by discarding the scalar and taking the exponential of the 3-vector. This is known as the unitary quaternions. What the group looks like depends on what stream of quaternions it is fed. """