- @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().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
-
- """
- super().real_unembed(M)
- n = ZZ(M.nrows())
- d = cls.dimension_over_reals()
-
- # Use the base ring of the matrix to ensure that its entries can be
- # multiplied by elements of the quaternion algebra.
- Q = cls.quaternion_extension(M.base_ring())
- i,j,k = Q.gens()
-
- # Go top-left to bottom-right (reading order), converting every
- # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
- # quaternion block.
- elements = []
- for l in range(n/d):
- for m in range(n/d):
- submat = ComplexMatrixEJA.real_unembed(
- M[d*l:d*l+d,d*m:d*m+d] )
- if submat[0,0] != submat[1,1].conjugate():
- raise ValueError('bad on-diagonal submatrix')
- if submat[0,1] != -submat[1,0].conjugate():
- raise ValueError('bad off-diagonal submatrix')
- z = submat[0,0].real()
- z += submat[0,0].imag()*i
- z += submat[0,1].real()*j
- z += submat[0,1].imag()*k
- elements.append(z)
-
- return matrix(Q, n/d, elements)
-
-
-class QuaternionHermitianEJA(ConcreteEJA,
- RationalBasisEJA,
- QuaternionMatrixEJA):