- super(RealSymmetricEJA, self).__init__(self._denormalized_basis(n),
- self.jordan_product,
- self.trace_inner_product,
- **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))
-
-
-
-class ComplexMatrixEJA(MatrixEJA):
- # A manual dictionary-cache for the complex_extension() method,
- # since apparently @classmethods can't also be @cached_methods.
- _complex_extension = {}
-
- @classmethod
- def complex_extension(cls,field):
- r"""
- The complex field that we embed/unembed, as an extension
- of the given ``field``.
- """
- if field in cls._complex_extension:
- return cls._complex_extension[field]
-
- # Sage doesn't know how to adjoin the complex "i" (the root of
- # x^2 + 1) to a field in a general way. Here, we just enumerate
- # all of the cases that I have cared to support so far.
- if field is AA:
- # Sage doesn't know how to embed AA into QQbar, i.e. how
- # to adjoin sqrt(-1) to AA.
- F = QQbar
- elif not field.is_exact():
- # RDF or RR
- F = field.complex_field()
- else:
- # Works for QQ and... maybe some other fields.
- R = PolynomialRing(field, 'z')
- z = R.gen()
- F = field.extension(z**2 + 1, 'I', embedding=CLF(-1).sqrt())
-
- cls._complex_extension[field] = F
- return F
-
- @staticmethod
- def dimension_over_reals():
- return 2
-
- @classmethod
- def real_embed(cls,M):
- """
- Embed the n-by-n complex matrix ``M`` into the space of real
- matrices of size 2n-by-2n via the map the sends each entry `z = a +
- bi` to the block matrix ``[[a,b],[-b,a]]``.
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import ComplexMatrixEJA
-
- EXAMPLES::
-
- sage: F = QuadraticField(-1, 'I')
- sage: x1 = F(4 - 2*i)
- sage: x2 = F(1 + 2*i)
- sage: x3 = F(-i)
- sage: x4 = F(6)
- sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
- sage: ComplexMatrixEJA.real_embed(M)
- [ 4 -2| 1 2]
- [ 2 4|-2 1]
- [-----+-----]
- [ 0 -1| 6 0]
- [ 1 0| 0 6]
-
- TESTS:
-
- Embedding is a homomorphism (isomorphism, in fact)::
-
- sage: set_random_seed()
- sage: n = ZZ.random_element(3)
- sage: F = QuadraticField(-1, 'I')
- sage: X = random_matrix(F, n)
- sage: Y = random_matrix(F, n)
- sage: Xe = ComplexMatrixEJA.real_embed(X)
- sage: Ye = ComplexMatrixEJA.real_embed(Y)
- sage: XYe = ComplexMatrixEJA.real_embed(X*Y)
- sage: Xe*Ye == XYe
- True
-
- """
- super(ComplexMatrixEJA,cls).real_embed(M)
- n = M.nrows()
-
- # We don't need any adjoined elements...
- field = M.base_ring().base_ring()
-
- blocks = []
- for z in M.list():
- a = z.real()
- b = z.imag()
- blocks.append(matrix(field, 2, [ [ a, b],
- [-b, a] ]))