X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fhurwitz.py;h=ff84b51f8e3923ef7a8a93cb7d42ea1cfe6e3d32;hb=928b7d49fda98ff105c92293b5797bb7a2b9873a;hp=a1a6af06e944e97ea49536b8b9f76e1ecf54cde6;hpb=37ab2f97b6f8b64360045a1db4c74b6c38651317;p=sage.d.git diff --git a/mjo/hurwitz.py b/mjo/hurwitz.py index a1a6af0..ff84b51 100644 --- a/mjo/hurwitz.py +++ b/mjo/hurwitz.py @@ -23,7 +23,6 @@ class Octonion(IndexedFreeModuleElement): Conjugating twice gets you the original element:: - sage: set_random_seed() sage: O = Octonions() sage: x = O.random_element() sage: x.conjugate().conjugate() == x @@ -58,7 +57,6 @@ class Octonion(IndexedFreeModuleElement): This method is idempotent:: - sage: set_random_seed() sage: O = Octonions() sage: x = O.random_element() sage: x.real().real() == x.real() @@ -91,7 +89,6 @@ class Octonion(IndexedFreeModuleElement): This method is idempotent:: - sage: set_random_seed() sage: O = Octonions() sage: x = O.random_element() sage: x.imag().imag() == x.imag() @@ -121,7 +118,6 @@ class Octonion(IndexedFreeModuleElement): The norm is nonnegative and belongs to the base field:: - sage: set_random_seed() sage: O = Octonions() sage: n = O.random_element().norm() sage: n >= 0 and n in O.base_ring() @@ -129,7 +125,6 @@ class Octonion(IndexedFreeModuleElement): The norm is homogeneous:: - sage: set_random_seed() sage: O = Octonions() sage: x = O.random_element() sage: alpha = O.base_ring().random_element() @@ -167,7 +162,6 @@ class Octonion(IndexedFreeModuleElement): TESTS:: - sage: set_random_seed() sage: O = Octonions() sage: x = O.random_element() sage: x.is_zero() or ( x*x.inverse() == O.one() ) @@ -241,7 +235,6 @@ class Octonions(CombinatorialFreeModule): This gives the correct unit element:: - sage: set_random_seed() sage: O = Octonions() sage: x = O.random_element() sage: x*O.one() == x and O.one()*x == x @@ -306,22 +299,61 @@ class Octonions(CombinatorialFreeModule): class HurwitzMatrixAlgebraElement(MatrixAlgebraElement): + def conjugate_transpose(self): + r""" + Return the conjugate-transpose of this matrix. + + SETUP:: + + sage: from mjo.hurwitz import ComplexMatrixAlgebra + + EXAMPLES:: + + sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ) + sage: M = A([ [ I, 2*I], + ....: [ 3*I, 4*I] ]) + sage: M.conjugate_transpose() + +------+------+ + | -I | -3*I | + +------+------+ + | -2*I | -4*I | + +------+------+ + sage: M.conjugate_transpose().to_vector() + (0, -1, 0, -3, 0, -2, 0, -4) + + """ + entries = [ [ self[j,i].conjugate() + for j in range(self.ncols())] + for i in range(self.nrows()) ] + return self.parent()._element_constructor_(entries) + def is_hermitian(self): r""" SETUP:: - sage: from mjo.hurwitz import HurwitzMatrixAlgebra + sage: from mjo.hurwitz import (ComplexMatrixAlgebra, + ....: HurwitzMatrixAlgebra) EXAMPLES:: - sage: A = HurwitzMatrixAlgebra(2, QQbar, ZZ) + sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ) sage: M = A([ [ 0,I], ....: [-I,0] ]) sage: M.is_hermitian() True + :: + + sage: A = HurwitzMatrixAlgebra(2, AA, QQ) + sage: M = A([ [1, 1], + ....: [1, 1] ]) + sage: M.is_hermitian() + True + """ + # A tiny bit faster than checking equality with the conjugate + # transpose. return all( self[i,j] == self[j,i].conjugate() for i in range(self.nrows()) for j in range(self.ncols()) ) @@ -440,6 +472,31 @@ class OctonionMatrixAlgebra(HurwitzMatrixAlgebra): +---------------------+ | 1.00000000000000*e0 | +---------------------+ + sage: A.gens() + (+---------------------+ + | 1.00000000000000*e0 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e1 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e2 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e3 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e4 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e5 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e6 | + +---------------------+, + +---------------------+ + | 1.00000000000000*e7 | + +---------------------+) :: @@ -465,7 +522,6 @@ class OctonionMatrixAlgebra(HurwitzMatrixAlgebra): TESTS:: - sage: set_random_seed() sage: A = OctonionMatrixAlgebra(ZZ.random_element(10)) sage: x = A.random_element() sage: x*A.one() == x and A.one()*x == x @@ -519,6 +575,19 @@ class QuaternionMatrixAlgebra(HurwitzMatrixAlgebra): +-----+ | 1.0 | +-----+ + sage: A.gens() + (+-----+ + | 1.0 | + +-----+, + +---+ + | i | + +---+, + +---+ + | j | + +---+, + +---+ + | k | + +---+) :: @@ -545,7 +614,6 @@ class QuaternionMatrixAlgebra(HurwitzMatrixAlgebra): TESTS:: - sage: set_random_seed() sage: A = QuaternionMatrixAlgebra(ZZ.random_element(10)) sage: x = A.random_element() sage: x*A.one() == x and A.one()*x == x @@ -561,6 +629,32 @@ class QuaternionMatrixAlgebra(HurwitzMatrixAlgebra): entry_algebra = QuaternionAlgebra(scalars,-1,-1) super().__init__(n, entry_algebra, scalars, **kwargs) + def _entry_algebra_element_to_vector(self, entry): + r""" + + SETUP:: + + sage: from mjo.hurwitz import QuaternionMatrixAlgebra + + EXAMPLES:: + + sage: A = QuaternionMatrixAlgebra(2) + sage: u = A.entry_algebra().one() + sage: A._entry_algebra_element_to_vector(u) + (1, 0, 0, 0) + sage: i,j,k = A.entry_algebra().gens() + sage: A._entry_algebra_element_to_vector(i) + (0, 1, 0, 0) + sage: A._entry_algebra_element_to_vector(j) + (0, 0, 1, 0) + sage: A._entry_algebra_element_to_vector(k) + (0, 0, 0, 1) + + """ + from sage.modules.free_module import FreeModule + d = len(self.entry_algebra_gens()) + V = FreeModule(self.entry_algebra().base_ring(), d) + return V(entry.coefficient_tuple()) class ComplexMatrixAlgebra(HurwitzMatrixAlgebra): r""" @@ -598,6 +692,13 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra): +------------------+ | 1.00000000000000 | +------------------+ + sage: A.gens() + (+------------------+ + | 1.00000000000000 | + +------------------+, + +--------------------+ + | 1.00000000000000*I | + +--------------------+) :: @@ -605,11 +706,11 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra): sage: (I,) = A.entry_algebra().gens() sage: A([ [1+I, 1], ....: [-1, -I] ]) - +-------+----+ - | I + 1 | 1 | - +-------+----+ - | -1 | -I | - +-------+----+ + +---------+------+ + | 1 + 1*I | 1 | + +---------+------+ + | -1 | -1*I | + +---------+------+ :: @@ -622,7 +723,6 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra): TESTS:: - sage: set_random_seed() sage: A = ComplexMatrixAlgebra(ZZ.random_element(10)) sage: x = A.random_element() sage: x*A.one() == x and A.one()*x == x @@ -634,3 +734,24 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra): from sage.rings.all import QQbar entry_algebra = QQbar super().__init__(n, entry_algebra, scalars, **kwargs) + + def _entry_algebra_element_to_vector(self, entry): + r""" + + SETUP:: + + sage: from mjo.hurwitz import ComplexMatrixAlgebra + + EXAMPLES:: + + sage: A = ComplexMatrixAlgebra(2, QQbar, QQ) + sage: A._entry_algebra_element_to_vector(QQbar(1)) + (1, 0) + sage: A._entry_algebra_element_to_vector(QQbar(I)) + (0, 1) + + """ + from sage.modules.free_module import FreeModule + d = len(self.entry_algebra_gens()) + V = FreeModule(self.entry_algebra().base_ring(), d) + return V((entry.real(), entry.imag()))