]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: don't adjoin roots to the field if we're not normalizing the basis.
[sage.d.git] / mjo / eja / eja_algebra.py
index f7983c857d8fdceffac3dbdfeaa6bf70fd7e811e..a7e56187550111a928823d536dc3ff88347b7424 100644 (file)
@@ -15,7 +15,7 @@ from sage.misc.prandom import choice
 from sage.misc.table import table
 from sage.modules.free_module import FreeModule, VectorSpace
 from sage.rings.integer_ring import ZZ
-from sage.rings.number_field.number_field import NumberField
+from sage.rings.number_field.number_field import NumberField, QuadraticField
 from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
 from sage.rings.rational_field import QQ
 from sage.rings.real_lazy import CLF, RLF
@@ -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.
 
@@ -853,10 +853,8 @@ def _complex_hermitian_basis(n, field):
 
         sage: set_random_seed()
         sage: n = ZZ.random_element(1,5)
-        sage: R = PolynomialRing(QQ, 'z')
-        sage: z = R.gen()
-        sage: field = NumberField(z**2 - 2, 'sqrt2', embedding=RLF(2).sqrt())
-        sage: B = _complex_hermitian_basis(n, field)
+        sage: field = QuadraticField(2, 'sqrt2')
+        sage: B = _complex_hermitian_basis(n, field, False)
         sage: all( M.is_symmetric() for M in  B)
         True
 
@@ -886,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.
 
@@ -912,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
 
@@ -989,9 +989,7 @@ def _embed_complex_matrix(M):
 
     EXAMPLES::
 
-        sage: R = PolynomialRing(QQ, 'z')
-        sage: z = R.gen()
-        sage: F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt())
+        sage: F = QuadraticField(-1, 'i')
         sage: x1 = F(4 - 2*i)
         sage: x2 = F(1 + 2*i)
         sage: x3 = F(-i)
@@ -1010,9 +1008,7 @@ def _embed_complex_matrix(M):
 
         sage: set_random_seed()
         sage: n = ZZ.random_element(5)
-        sage: R = PolynomialRing(QQ, 'z')
-        sage: z = R.gen()
-        sage: F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt())
+        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)
@@ -1059,9 +1055,7 @@ def _unembed_complex_matrix(M):
     Unembedding is the inverse of embedding::
 
         sage: set_random_seed()
-        sage: R = PolynomialRing(QQ, 'z')
-        sage: z = R.gen()
-        sage: F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt())
+        sage: F = QuadraticField(-1, 'i')
         sage: M = random_matrix(F, 3)
         sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
         True
@@ -1137,9 +1131,7 @@ def _embed_quaternion_matrix(M):
     if M.ncols() != n:
         raise ValueError("the matrix 'M' must be square")
 
-    R = PolynomialRing(QQ, 'z')
-    z = R.gen()
-    F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt())
+    F = QuadraticField(-1, 'i')
     i = F.gen()
 
     blocks = []
@@ -1317,8 +1309,8 @@ class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra):
         True
 
     """
-    def __init__(self, n, field=QQ, **kwargs):
-        if n > 1:
+    def __init__(self, n, field=QQ, normalize_basis=True, **kwargs):
+        if n > 1 and normalize_basis:
             # We'll need sqrt(2) to normalize the basis, and this
             # winds up in the multiplication table, so the whole
             # algebra needs to be over the field extension.
@@ -1328,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)
@@ -1415,8 +1407,8 @@ class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
         True
 
     """
-    def __init__(self, n, field=QQ, **kwargs):
-        if n > 1:
+    def __init__(self, n, field=QQ, normalize_basis=True, **kwargs):
+        if n > 1 and normalize_basis:
             # We'll need sqrt(2) to normalize the basis, and this
             # winds up in the multiplication table, so the whole
             # algebra needs to be over the field extension.
@@ -1426,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)
@@ -1497,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)