Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168740
Image: ubuntu2004
r""" real and complex numbers - As elements of the quaternion manifold H^1 This is all done with conjugates. AUTHORS: -- Doug Sweetser (2009): Initial version. EXAMPLES: Test the various conjugates. sage: q1 = q(1, 2, 3, 4) sage: q1.real()==q(1, 0, 0, 0) True sage: q1.complex_x()==q(1, 2, 0, 0) True sage: q1.complex_y()==q(1, 0, 3, 0) True sage: q1.complex_z()==q(1, 0, 0, 4) True """ #***************************************************************************** # Copyright (C) 2009 Doug Sweetser <[email protected]> # # 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 list.__init__(self,[t,x,y,z]) def __repr__(self): return "Quaternion tools." def show(self): print self.t, self.x, self.y, self.z def add(self, q2): return(q(self.t + q2.t, self.x + q2.x, self.y + q2.y, self.z + q2.z)); def scalar_div(self, d): return(q(self.t/d, self.x/d, self.y/d, self.z/d)); def scalar_x(self, d): return(q(self.t * d, self.x * d, self.y * d, self.z * d)); def conj(self): return q(self.t, -self.x, -self.y, -self.z) def conj_1(self): return q(-self.t, self.x, -self.y, -self.z) def conj_2(self): return q(-self.t, -self.x, self.y, -self.z) def conj_3(self): return q(-self.t, -self.x, -self.y, self.z) def real(self): t = self.add(self.conj()).scalar_div(2) return q(t.t, t.x, t.y, t.z) def complex_x(self): tx =self.add(self).add(self.conj()).add(self.conj_1()).scalar_div(2) return q(tx.t, tx.x, tx.y, tx.z) def complex_y(self): ty = self.add(self).add(self.conj()).add(self.conj_2()).scalar_div(2) return q(ty.t, ty.x, ty.y, ty.z) def complex_z(self): tz = self.add(self).add(self.conj()).add(self.conj_3()).scalar_div(2) return q(tz.t, tz.x, tz.y, tz.z)
q1=q(1,2,3,4) q1.real().show() q1.complex_x().show() q1.complex_y().show() q1.complex_z().show()
1 0 0 0 1 2 0 0 1 0 3 0 1 0 0 4
q(1, 2, 3, 4).complex_x()==q(1, 2, 0, 0)
True
q(1, 2, 3, 4).complex_y()==q(1, 0, 3, 0)
True
q(1, 2, 3, 4).complex_z()==q(1, 0, 0, 4)
True
r"""It is neat that the three familiar complex planes are created by doubling the input and adding in two conjugates before dividing by half. This is how one can see the complex manifold C^1 is embedded in the quaternion manifold H^1. """