- @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] ]))
-
- return matrix.block(field, n, blocks)
-
-
- @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(ComplexMatrixEJA,cls).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(ConcreteEJA, ComplexMatrixEJA):