- @classmethod
- def real_unembed(cls,M):
- """
- The inverse of _embed_complex_matrix().
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import ComplexMatrixEJA
-
- EXAMPLES::
-
- sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
- ....: [-2, 1, -4, 3],
- ....: [ 9, 10, 11, 12],
- ....: [-10, 9, -12, 11] ])
- sage: ComplexMatrixEJA.real_unembed(A)
- [ 2*I + 1 4*I + 3]
- [ 10*I + 9 12*I + 11]
-
- TESTS:
-
- Unembedding is the inverse of embedding::
-
- sage: set_random_seed()
- sage: F = QuadraticField(-1, 'I')
- sage: M = random_matrix(F, 3)
- sage: Me = ComplexMatrixEJA.real_embed(M)
- sage: ComplexMatrixEJA.real_unembed(Me) == M
- True
-
- """
- super().real_unembed(M)
- n = ZZ(M.nrows())
- d = cls.dimension_over_reals()
- F = cls.complex_extension(M.base_ring())
- i = F.gen()
-
- # Go top-left to bottom-right (reading order), converting every
- # 2-by-2 block we see to a single complex element.
- elements = []
- for k in range(n/d):
- for j in range(n/d):
- submat = M[d*k:d*k+d,d*j:d*j+d]
- if submat[0,0] != submat[1,1]:
- raise ValueError('bad on-diagonal submatrix')
- if submat[0,1] != -submat[1,0]:
- raise ValueError('bad off-diagonal submatrix')
- z = submat[0,0] + submat[0,1]*i
- elements.append(z)
-
- return matrix(F, n/d, elements)
-
-
-class ComplexHermitianEJA(RationalBasisEJA, ConcreteEJA, ComplexMatrixEJA):
- """
- The rank-n simple EJA consisting of complex Hermitian n-by-n
- matrices over the real numbers, the usual symmetric Jordan product,
- and the real-part-of-trace inner product. It has dimension `n^2` over
- the reals.
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
-
- EXAMPLES:
-
- In theory, our "field" can be any subfield of the reals::
-
- sage: ComplexHermitianEJA(2, field=RDF, check_axioms=True)
- Euclidean Jordan algebra of dimension 4 over Real Double Field
- sage: ComplexHermitianEJA(2, field=RR, check_axioms=True)
- Euclidean Jordan algebra of dimension 4 over Real Field with
- 53 bits of precision
-
- 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: B = ComplexHermitianEJA._denormalized_basis(n,ZZ)
- sage: all( M.is_symmetric() for M in B)
- True
-
- """
- R = PolynomialRing(ZZ, 'z')
- z = R.gen()
- F = ZZ.extension(z**2 + 1, 'I')
- I = F.gen(1)
-
- # 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 = []
- Eij = matrix.zero(F,n)
- for i in range(n):
- for j in range(i+1):
- # "build" E_ij
- Eij[i,j] = 1
- if i == j:
- Sij = cls.real_embed(Eij)
- S.append(Sij)
- else:
- # The second one has a minus because it's conjugated.
- Eij[j,i] = 1 # Eij = Eij + Eij.transpose()
- Sij_real = cls.real_embed(Eij)
- S.append(Sij_real)
- # Eij = I*Eij - I*Eij.transpose()
- Eij[i,j] = I
- Eij[j,i] = -I
- Sij_imag = cls.real_embed(Eij)
- S.append(Sij_imag)
- Eij[j,i] = 0
- # "erase" E_ij
- Eij[i,j] = 0
-
- # Since we embedded the entries, we can drop back to the
- # desired real "field" instead of the extension "F".
- return tuple( s.change_ring(field) for s in S )
-
-
- def __init__(self, n, field=AA, **kwargs):
- # We know this is a valid EJA, but will double-check
- # if the user passes check_axioms=True.
- if "check_axioms" not in kwargs: kwargs["check_axioms"] = False
-
- associative = False
- if n <= 1:
- associative = True
-
- super().__init__(self._denormalized_basis(n,field),
- self.jordan_product,
- self.trace_inner_product,
- field=field,
- associative=associative,
- **kwargs)
- # TODO: this could be factored out somehow, but is left here
- # because the MatrixEJA is not presently a subclass of the
- # FDEJA class that defines rank() and one().
- self.rank.set_cache(n)
- idV = matrix.identity(ZZ, self.dimension_over_reals()*n)
- self.one.set_cache(self(idV))