-class QuaternionMatrixEJA(MatrixEJA):
-
- # A manual dictionary-cache for the quaternion_extension() method,
- # since apparently @classmethods can't also be @cached_methods.
- _quaternion_extension = {}
-
- @classmethod
- def quaternion_extension(cls,field):
- r"""
- The quaternion field that we embed/unembed, as an extension
- of the given ``field``.
- """
- if field in cls._quaternion_extension:
- return cls._quaternion_extension[field]
-
- Q = QuaternionAlgebra(field,-1,-1)
-
- cls._quaternion_extension[field] = Q
- return Q
-
- @staticmethod
- def dimension_over_reals():
- return 4
-
- @classmethod
- def real_embed(cls,M):
- """
- Embed the n-by-n quaternion matrix ``M`` into the space of real
- matrices of size 4n-by-4n by first sending each quaternion entry `z
- = a + bi + cj + dk` to the block-complex matrix ``[[a + bi,
- c+di],[-c + di, a-bi]]`, and then embedding those into a real
- matrix.
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import QuaternionMatrixEJA
-
- EXAMPLES::
-
- sage: Q = QuaternionAlgebra(QQ,-1,-1)
- sage: i,j,k = Q.gens()
- sage: x = 1 + 2*i + 3*j + 4*k
- sage: M = matrix(Q, 1, [[x]])
- sage: QuaternionMatrixEJA.real_embed(M)
- [ 1 2 3 4]
- [-2 1 -4 3]
- [-3 4 1 -2]
- [-4 -3 2 1]
-
- Embedding is a homomorphism (isomorphism, in fact)::
-
- sage: set_random_seed()
- sage: n = ZZ.random_element(2)
- sage: Q = QuaternionAlgebra(QQ,-1,-1)
- sage: X = random_matrix(Q, n)
- sage: Y = random_matrix(Q, n)
- sage: Xe = QuaternionMatrixEJA.real_embed(X)
- sage: Ye = QuaternionMatrixEJA.real_embed(Y)
- sage: XYe = QuaternionMatrixEJA.real_embed(X*Y)
- sage: Xe*Ye == XYe
- True
-
- """
- super(QuaternionMatrixEJA,cls).real_embed(M)
- quaternions = M.base_ring()
- n = M.nrows()
-
- F = QuadraticField(-1, 'I')
- i = F.gen()
-
- blocks = []
- for z in M.list():
- t = z.coefficient_tuple()
- a = t[0]
- b = t[1]
- c = t[2]
- d = t[3]
- cplxM = matrix(F, 2, [[ a + b*i, c + d*i],
- [-c + d*i, a - b*i]])
- realM = ComplexMatrixEJA.real_embed(cplxM)
- blocks.append(realM)
-
- # We should have real entries by now, so use the realest field
- # we've got for the return value.
- return matrix.block(quaternions.base_ring(), n, blocks)
-
-
-
- @classmethod
- def real_unembed(cls,M):
- """
- The inverse of _embed_quaternion_matrix().
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import QuaternionMatrixEJA
-
- EXAMPLES::
-
- sage: M = matrix(QQ, [[ 1, 2, 3, 4],
- ....: [-2, 1, -4, 3],
- ....: [-3, 4, 1, -2],
- ....: [-4, -3, 2, 1]])
- sage: QuaternionMatrixEJA.real_unembed(M)
- [1 + 2*i + 3*j + 4*k]
-
- TESTS:
-
- Unembedding is the inverse of embedding::
-
- sage: set_random_seed()
- sage: Q = QuaternionAlgebra(QQ, -1, -1)
- sage: M = random_matrix(Q, 3)
- sage: Me = QuaternionMatrixEJA.real_embed(M)
- sage: QuaternionMatrixEJA.real_unembed(Me) == M
- True