From 9bcc10b6362a5390735bbbf4ef8351b150847359 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 21 Aug 2019 10:50:55 -0400 Subject: [PATCH] eja: add "normalize" argument to matrix algebra constructors. This is useful for two reasons: 1. It's nice to be able to test that some things are invariant under changes of basis. 2. The min/charpoly computations will be a lot faster if we can use the basis over QQ (i.e. if the properties that we're testing in the first item hold). --- mjo/eja/eja_algebra.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 05dea56..adf9581 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -802,7 +802,7 @@ def random_eja(): -def _real_symmetric_basis(n, field): +def _real_symmetric_basis(n, field, normalize): """ Return a basis for the space of real symmetric n-by-n matrices. @@ -814,7 +814,7 @@ def _real_symmetric_basis(n, field): sage: set_random_seed() sage: n = ZZ.random_element(1,5) - sage: B = _real_symmetric_basis(n, QQbar) + sage: B = _real_symmetric_basis(n, QQbar, False) sage: all( M.is_symmetric() for M in B) True @@ -829,13 +829,13 @@ def _real_symmetric_basis(n, field): Sij = Eij else: Sij = Eij + Eij.transpose() - # Now normalize it. - Sij = Sij / _real_symmetric_matrix_ip(Sij,Sij).sqrt() + if normalize: + Sij = Sij / _real_symmetric_matrix_ip(Sij,Sij).sqrt() S.append(Sij) return tuple(S) -def _complex_hermitian_basis(n, field): +def _complex_hermitian_basis(n, field, normalize): """ Returns a basis for the space of complex Hermitian n-by-n matrices. @@ -854,7 +854,7 @@ def _complex_hermitian_basis(n, field): sage: set_random_seed() sage: n = ZZ.random_element(1,5) sage: field = QuadraticField(2, 'sqrt2') - sage: B = _complex_hermitian_basis(n, field) + sage: B = _complex_hermitian_basis(n, field, False) sage: all( M.is_symmetric() for M in B) True @@ -884,15 +884,17 @@ def _complex_hermitian_basis(n, field): 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 ) + # Since we embedded these, we can drop back to the "field" that we + # started with instead of the complex extension "F". + S = [ s.change_ring(field) for s in S ] + if normalize: + S = [ s / _complex_hermitian_matrix_ip(s,s).sqrt() for s in S ] + + return tuple(S) -def _quaternion_hermitian_basis(n, field): +def _quaternion_hermitian_basis(n, field, normalize): """ Returns a basis for the space of quaternion Hermitian n-by-n matrices. @@ -910,7 +912,7 @@ def _quaternion_hermitian_basis(n, field): sage: set_random_seed() sage: n = ZZ.random_element(1,5) - sage: B = _quaternion_hermitian_basis(n, QQ) + sage: B = _quaternion_hermitian_basis(n, QQ, False) sage: all( M.is_symmetric() for M in B ) True @@ -1307,7 +1309,7 @@ class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra): True """ - def __init__(self, n, field=QQ, **kwargs): + def __init__(self, n, field=QQ, normalize_basis=True, **kwargs): if n > 1: # We'll need sqrt(2) to normalize the basis, and this # winds up in the multiplication table, so the whole @@ -1318,7 +1320,7 @@ class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra): if p.is_irreducible(): field = NumberField(p, 'sqrt2', embedding=RLF(2).sqrt()) - S = _real_symmetric_basis(n, field) + S = _real_symmetric_basis(n, field, normalize_basis) Qs = _multiplication_table_from_matrix_basis(S) fdeja = super(RealSymmetricEJA, self) @@ -1405,7 +1407,7 @@ class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra): True """ - def __init__(self, n, field=QQ, **kwargs): + def __init__(self, n, field=QQ, normalize_basis=True, **kwargs): if n > 1: # We'll need sqrt(2) to normalize the basis, and this # winds up in the multiplication table, so the whole @@ -1416,7 +1418,7 @@ class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra): if p.is_irreducible(): field = NumberField(p, 'sqrt2', embedding=RLF(2).sqrt()) - S = _complex_hermitian_basis(n, field) + S = _complex_hermitian_basis(n, field, normalize_basis) Qs = _multiplication_table_from_matrix_basis(S) fdeja = super(ComplexHermitianEJA, self) @@ -1487,8 +1489,8 @@ class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra): True """ - def __init__(self, n, field=QQ, **kwargs): - S = _quaternion_hermitian_basis(n, field) + def __init__(self, n, field=QQ, normalize_basis=True, **kwargs): + S = _quaternion_hermitian_basis(n, field, normalize_basis) Qs = _multiplication_table_from_matrix_basis(S) fdeja = super(QuaternionHermitianEJA, self) -- 2.43.2