- TESTS:
-
- The dimension of this algebra is `n^2`::
-
- sage: set_random_seed()
- sage: n_max = ComplexHermitianEJA._max_random_instance_size()
- sage: n = ZZ.random_element(1, n_max)
- sage: J = ComplexHermitianEJA(n)
- sage: J.dimension() == n^2
- True
-
- The Jordan multiplication is what we think it is::
-
- sage: set_random_seed()
- sage: J = ComplexHermitianEJA.random_instance()
- sage: x,y = J.random_elements(2)
- sage: actual = (x*y).to_matrix()
- sage: X = x.to_matrix()
- sage: Y = y.to_matrix()
- sage: expected = (X*Y + Y*X)/2
- sage: actual == expected
- True
- sage: J(expected) == x*y
- True
-
- We can change the generator prefix::
-
- sage: ComplexHermitianEJA(2, prefix='z').gens()
- (z0, z1, z2, z3)
-
- We can construct the (trivial) algebra of rank zero::
-
- sage: ComplexHermitianEJA(0)
- Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
-
- """
-
- @classmethod
- def _denormalized_basis(cls, n, field):
- """
- Returns a basis for the space of complex Hermitian n-by-n matrices.
-
- Why do we embed these? Basically, because all of numerical linear
- algebra assumes that you're working with vectors consisting of `n`
- entries from a field and scalars from the same field. There's no way
- to tell SageMath that (for example) the vectors contain complex
- numbers, while the scalar field is real.
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
-
- TESTS::
-
- sage: set_random_seed()
- sage: n = ZZ.random_element(1,5)
- sage: field = QuadraticField(2, 'sqrt2')
- sage: B = ComplexHermitianEJA._denormalized_basis(n, field)
- sage: all( M.is_symmetric() for M in B)
- True
-
- """
- R = PolynomialRing(field, 'z')
- z = R.gen()
- F = field.extension(z**2 + 1, 'I')
- I = F.gen()
-
- # This is like the symmetric case, but we need to be careful:
- #
- # * We want conjugate-symmetry, not just symmetry.
- # * The diagonal will (as a result) be real.
- #
- S = []
- for i in range(n):
- for j in range(i+1):
- Eij = matrix(F, n, lambda k,l: k==i and l==j)
- if i == j:
- Sij = cls.real_embed(Eij)
- S.append(Sij)
- else:
- # The second one has a minus because it's conjugated.
- Sij_real = cls.real_embed(Eij + Eij.transpose())
- S.append(Sij_real)
- Sij_imag = cls.real_embed(I*Eij - I*Eij.transpose())
- S.append(Sij_imag)
-
- # Since we embedded these, we can drop back to the "field" that we
- # started with instead of the complex extension "F".
- return tuple( s.change_ring(field) for s in S )
-
-
- def __init__(self, n, field=AA, **kwargs):
- basis = self._denormalized_basis(n,field)
- super(ComplexHermitianEJA, self).__init__(field,
- basis,
- self.jordan_product,
- self.trace_inner_product,
- **kwargs)
- self.rank.set_cache(n)
- # TODO: pre-cache the identity!
-
- @staticmethod
- def _max_random_instance_size():
- return 3 # Dimension 9
-
- @classmethod
- def random_instance(cls, field=AA, **kwargs):
- """
- Return a random instance of this type of algebra.
- """
- n = ZZ.random_element(cls._max_random_instance_size() + 1)
- return cls(n, field, **kwargs)
-
-class QuaternionMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra):
- @staticmethod
- def real_embed(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 \
- ....: QuaternionMatrixEuclideanJordanAlgebra
-
- 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: QuaternionMatrixEuclideanJordanAlgebra.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 = QuaternionMatrixEuclideanJordanAlgebra.real_embed(X)
- sage: Ye = QuaternionMatrixEuclideanJordanAlgebra.real_embed(Y)
- sage: XYe = QuaternionMatrixEuclideanJordanAlgebra.real_embed(X*Y)
- sage: Xe*Ye == XYe
- True
-
- """
- quaternions = M.base_ring()
- n = M.nrows()
- if M.ncols() != n:
- raise ValueError("the matrix 'M' must be square")
-
- 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 = ComplexMatrixEuclideanJordanAlgebra.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)
-
-
-
- @staticmethod
- def real_unembed(M):
- """
- The inverse of _embed_quaternion_matrix().
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import \
- ....: QuaternionMatrixEuclideanJordanAlgebra
-
- EXAMPLES::
-
- sage: M = matrix(QQ, [[ 1, 2, 3, 4],
- ....: [-2, 1, -4, 3],
- ....: [-3, 4, 1, -2],
- ....: [-4, -3, 2, 1]])
- sage: QuaternionMatrixEuclideanJordanAlgebra.real_unembed(M)
- [1 + 2*i + 3*j + 4*k]
-
- TESTS: