Conjugating twice gets you the original element::
- sage: set_random_seed()
sage: O = Octonions()
sage: x = O.random_element()
sage: x.conjugate().conjugate() == x
This method is idempotent::
- sage: set_random_seed()
sage: O = Octonions()
sage: x = O.random_element()
sage: x.real().real() == x.real()
This method is idempotent::
- sage: set_random_seed()
sage: O = Octonions()
sage: x = O.random_element()
sage: x.imag().imag() == x.imag()
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()
The norm is homogeneous::
- sage: set_random_seed()
sage: O = Octonions()
sage: x = O.random_element()
sage: alpha = O.base_ring().random_element()
TESTS::
- sage: set_random_seed()
sage: O = Octonions()
sage: x = O.random_element()
sage: x.is_zero() or ( x*x.inverse() == O.one() )
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
class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
+ def conjugate(self):
+ r"""
+ Return the entrywise conjugate of this matrix.
+
+ SETUP::
+
+ sage: from mjo.hurwitz import ComplexMatrixAlgebra
+
+ EXAMPLES::
+
+ sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+ sage: M = A([ [ I, 1 + 2*I],
+ ....: [ 3*I, 4*I] ])
+ sage: M.conjugate()
+ +------+----------+
+ | -I | -2*I + 1 |
+ +------+----------+
+ | -3*I | -4*I |
+ +------+----------+
+
+ """
+ entries = [ [ self[i,j].conjugate()
+ for j in range(self.ncols())]
+ for i in range(self.nrows()) ]
+ return self.parent()._element_constructor_(entries)
+
def conjugate_transpose(self):
r"""
Return the conjugate-transpose of this matrix.
SETUP::
- sage: from mjo.hurwitz import HurwitzMatrixAlgebra
+ sage: from mjo.hurwitz import ComplexMatrixAlgebra
EXAMPLES::
- sage: A = HurwitzMatrixAlgebra(2, QQbar, ZZ)
+ sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
sage: M = A([ [ I, 2*I],
....: [ 3*I, 4*I] ])
sage: M.conjugate_transpose()
+------+------+
- | -1*I | -3*I |
+ | -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()
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.
for j in range(self.ncols()) )
+ def is_skew_symmetric(self):
+ r"""
+ Return whether or not this matrix is skew-symmetric.
+
+ SETUP::
+
+ sage: from mjo.hurwitz import (ComplexMatrixAlgebra,
+ ....: HurwitzMatrixAlgebra)
+
+ EXAMPLES::
+
+ sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+ sage: M = A([ [ 0,I],
+ ....: [-I,1] ])
+ sage: M.is_skew_symmetric()
+ False
+
+ ::
+
+ sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+ sage: M = A([ [ 0, 1+I],
+ ....: [-1-I, 0] ])
+ sage: M.is_skew_symmetric()
+ True
+
+ ::
+
+ sage: A = HurwitzMatrixAlgebra(2, AA, QQ)
+ sage: M = A([ [1, 1],
+ ....: [1, 1] ])
+ sage: M.is_skew_symmetric()
+ False
+
+ ::
+
+ sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+ sage: M = A([ [2*I , 1 + I],
+ ....: [-1 + I, -2*I] ])
+ sage: M.is_skew_symmetric()
+ False
+
+ """
+ # A tiny bit faster than checking equality with the negation
+ # of the transpose.
+ return all( self[i,j] == -self[j,i]
+ for i in range(self.nrows())
+ for j in range(self.ncols()) )
+
+
class HurwitzMatrixAlgebra(MatrixAlgebra):
r"""
A class of matrix algebras whose entries come from a Hurwitz
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
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
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"""
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 |
+ +---------+------+
::
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
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()))