From: Michael Orlitzky Date: Fri, 30 Aug 2019 00:32:55 +0000 (-0400) Subject: eja: add "check" parameter to check if our field is real. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=49f266e16de87af712beb680570ff39e2ae87de4 eja: add "check" parameter to check if our field is real. --- diff --git a/mjo/eja/TODO b/mjo/eja/TODO index 51c2a33..b2495b5 100644 --- a/mjo/eja/TODO +++ b/mjo/eja/TODO @@ -17,5 +17,3 @@ 7. Do we really need to orthonormalize the basis in a subalgebra? So long as we can decompose the operator (which is invariant under changes of basis), who cares? - -8. Check that our field is a subring of RLF. diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 430f233..7a65fab 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -16,12 +16,9 @@ from sage.misc.cachefunc import cached_method 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.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.rational_field import QQ -from sage.rings.real_lazy import CLF, RLF - +from sage.rings.all import (ZZ, QQ, RR, RLF, CLF, + PolynomialRing, + QuadraticField) from mjo.eja.eja_element import FiniteDimensionalEuclideanJordanAlgebraElement from mjo.eja.eja_utils import _mat2vec @@ -40,11 +37,12 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): rank, prefix='e', category=None, - natural_basis=None): + natural_basis=None, + check=True): """ SETUP:: - sage: from mjo.eja.eja_algebra import random_eja + sage: from mjo.eja.eja_algebra import (JordanSpinEJA, random_eja) EXAMPLES: @@ -56,7 +54,23 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): sage: x*y == y*x True + TESTS: + + The ``field`` we're given must be real:: + + sage: JordanSpinEJA(2,QQbar) + Traceback (most recent call last): + ... + ValueError: field is not real + """ + if check: + if not field.is_subring(RR): + # Note: this does return true for the real algebraic + # field, and any quadratic field where we've specified + # a real embedding. + raise ValueError('field is not real') + self._rank = rank self._natural_basis = natural_basis