- TESTS::
-
- sage: set_random_seed()
- sage: n = ZZ.random_element(1,5)
- sage: field = QuadraticField(2, 'sqrt2')
- sage: B = _complex_hermitian_basis(n, field)
- sage: all( M.is_symmetric() for M in B)
- True
-
- """
- R = PolynomialRing(field, 'z')
- z = R.gen()
- F = NumberField(z**2 + 1, 'I', embedding=CLF(-1).sqrt())
- 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 xrange(n):
- for j in xrange(i+1):
- Eij = matrix(F, n, lambda k,l: k==i and l==j)
- if i == j:
- Sij = _embed_complex_matrix(Eij)
- S.append(Sij)
- else:
- # Beware, orthogonal but not normalized! The second one
- # has a minus because it's conjugated.
- Sij_real = _embed_complex_matrix(Eij + Eij.transpose())
- S.append(Sij_real)
- Sij_imag = _embed_complex_matrix(I*Eij - I*Eij.transpose())
- S.append(Sij_imag)
-
- # Normalize these with our inner product before handing them back.
- # And since we embedded them, we can drop back to the "field" that
- # we started with instead of the complex extension "F".
- return tuple( (s / _complex_hermitian_matrix_ip(s,s).sqrt()).change_ring(field)
- for s in S )
-
-
-
-def _quaternion_hermitian_basis(n, field):
- """
- Returns a basis for the space of quaternion 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 _quaternion_hermitian_basis
-
- TESTS::
-
- sage: set_random_seed()
- sage: n = ZZ.random_element(1,5)
- sage: B = _quaternion_hermitian_basis(n, QQ)
- sage: all( M.is_symmetric() for M in B )
- True
-
- """
- Q = QuaternionAlgebra(QQ,-1,-1)
- I,J,K = Q.gens()
-
- # 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 xrange(n):
- for j in xrange(i+1):
- Eij = matrix(Q, n, lambda k,l: k==i and l==j)
- if i == j:
- Sij = _embed_quaternion_matrix(Eij)
- S.append(Sij)
- else:
- # Beware, orthogonal but not normalized! The second,
- # third, and fourth ones have a minus because they're
- # conjugated.
- Sij_real = _embed_quaternion_matrix(Eij + Eij.transpose())
- S.append(Sij_real)
- Sij_I = _embed_quaternion_matrix(I*Eij - I*Eij.transpose())
- S.append(Sij_I)
- Sij_J = _embed_quaternion_matrix(J*Eij - J*Eij.transpose())
- S.append(Sij_J)
- Sij_K = _embed_quaternion_matrix(K*Eij - K*Eij.transpose())
- S.append(Sij_K)
- return tuple(S)
-
-
-
-def _multiplication_table_from_matrix_basis(basis):
- """
- At least three of the five simple Euclidean Jordan algebras have the
- symmetric multiplication (A,B) |-> (AB + BA)/2, where the
- multiplication on the right is matrix multiplication. Given a basis
- for the underlying matrix space, this function returns a
- multiplication table (obtained by looping through the basis
- elements) for an algebra of those matrices.
- """
- # In S^2, for example, we nominally have four coordinates even
- # though the space is of dimension three only. The vector space V
- # is supposed to hold the entire long vector, and the subspace W
- # of V will be spanned by the vectors that arise from symmetric
- # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
- field = basis[0].base_ring()
- dimension = basis[0].nrows()
-
- V = VectorSpace(field, dimension**2)
- W = V.span_of_basis( _mat2vec(s) for s in basis )
- n = len(basis)
- mult_table = [[W.zero() for j in range(n)] for i in range(n)]
- for i in range(n):
- for j in range(n):
- mat_entry = (basis[i]*basis[j] + basis[j]*basis[i])/2
- mult_table[i][j] = W.coordinate_vector(_mat2vec(mat_entry))
-
- return mult_table
-
-
-def _embed_complex_matrix(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 _embed_complex_matrix
-
- 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: _embed_complex_matrix(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(5)
- sage: F = QuadraticField(-1, 'i')
- sage: X = random_matrix(F, n)
- sage: Y = random_matrix(F, n)
- sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
- sage: expected = _embed_complex_matrix(X*Y)
- sage: actual == expected
- True
-
- """
- n = M.nrows()
- if M.ncols() != n:
- raise ValueError("the matrix 'M' must be square")
- field = M.base_ring()
- blocks = []
- for z in M.list():
- a = z.vector()[0] # real part, I guess
- b = z.vector()[1] # imag part, I guess
- blocks.append(matrix(field, 2, [[a,b],[-b,a]]))
-
- # We can drop the imaginaries here.
- return matrix.block(field.base_ring(), n, blocks)
-
-
-def _unembed_complex_matrix(M):
- """
- The inverse of _embed_complex_matrix().
-
- SETUP::
-
- sage: from mjo.eja.eja_algebra import (_embed_complex_matrix,
- ....: _unembed_complex_matrix)
-
- EXAMPLES::
-
- sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
- ....: [-2, 1, -4, 3],
- ....: [ 9, 10, 11, 12],
- ....: [-10, 9, -12, 11] ])
- sage: _unembed_complex_matrix(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: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
- True
-
- """
- n = ZZ(M.nrows())
- if M.ncols() != n:
- raise ValueError("the matrix 'M' must be square")
- if not n.mod(2).is_zero():
- raise ValueError("the matrix 'M' must be a complex embedding")
-
- field = M.base_ring() # This should already have sqrt2
- R = PolynomialRing(field, 'z')
- z = R.gen()
- F = NumberField(z**2 + 1,'i', embedding=CLF(-1).sqrt())
- 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 xrange(n/2):
- for j in xrange(n/2):
- submat = M[2*k:2*k+2,2*j:2*j+2]
- 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/2, elements)
-
-
-def _embed_quaternion_matrix(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::