From 6b5e01f0f520475a7de60757a6c70511254ec2c6 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 20 Aug 2019 17:28:06 -0400 Subject: [PATCH] eja: use NumberField instead of QuadraticField everywhere. This will be more extensible when we need a field containing both sqrt(2) and sqrt(-1). QuadraticField can't handle that, so we have to use NumberField anyway at that point. Might as well get it out of the way. --- mjo/eja/eja_algebra.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 992174e..1216626 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -15,9 +15,10 @@ 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 QuadraticField +from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ +from sage.rings.real_lazy import CLF from sage.structure.element import is_Matrix from mjo.eja.eja_element import FiniteDimensionalEuclideanJordanAlgebraElement @@ -851,7 +852,9 @@ def _complex_hermitian_basis(n, field): True """ - F = QuadraticField(-1, 'I') + 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: @@ -965,7 +968,9 @@ def _embed_complex_matrix(M): EXAMPLES:: - sage: F = QuadraticField(-1,'i') + sage: R = PolynomialRing(QQ, 'z') + sage: z = R.gen() + sage: F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt()) sage: x1 = F(4 - 2*i) sage: x2 = F(1 + 2*i) sage: x3 = F(-i) @@ -984,7 +989,9 @@ def _embed_complex_matrix(M): sage: set_random_seed() sage: n = ZZ.random_element(5) - sage: F = QuadraticField(-1, 'i') + sage: R = PolynomialRing(QQ, 'z') + sage: z = R.gen() + sage: F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt()) sage: X = random_matrix(F, n) sage: Y = random_matrix(F, n) sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y) @@ -1031,7 +1038,9 @@ def _unembed_complex_matrix(M): Unembedding is the inverse of embedding:: sage: set_random_seed() - sage: F = QuadraticField(-1, 'i') + sage: R = PolynomialRing(QQ, 'z') + sage: z = R.gen() + sage: F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt()) sage: M = random_matrix(F, 3) sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M True @@ -1043,7 +1052,9 @@ def _unembed_complex_matrix(M): if not n.mod(2).is_zero(): raise ValueError("the matrix 'M' must be a complex embedding") - F = QuadraticField(-1, 'i') + R = PolynomialRing(QQ, '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 @@ -1104,7 +1115,9 @@ def _embed_quaternion_matrix(M): if M.ncols() != n: raise ValueError("the matrix 'M' must be square") - F = QuadraticField(-1, 'i') + R = PolynomialRing(QQ, 'z') + z = R.gen() + F = NumberField(z**2 + 1, 'i', embedding=CLF(-1).sqrt()) i = F.gen() blocks = [] @@ -1277,11 +1290,13 @@ class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra): """ def __init__(self, n, field=QQ, **kwargs): - if n > 1 and field is QQ: + if n > 1: # 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. - field = QuadraticField(2, 'sqrt2') + R = PolynomialRing(field, 'z') + z = R.gen() + field = NumberField(z**2 - 2, 'sqrt2') S = _real_symmetric_basis(n, field) Qs = _multiplication_table_from_matrix_basis(S) -- 2.43.2