From: Michael Orlitzky Date: Sun, 14 Mar 2021 21:38:53 +0000 (-0400) Subject: eja: renumber coordinate variables from zero. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=8fd6cc17cd935e5537bcea3aed8892c3ca65b40d eja: renumber coordinate variables from zero. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 2bad32c..c0dc408 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -367,7 +367,7 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): if orthonormalize: # Now "self._matrix_span" is the vector space of our - # algebra coordinates. The variables "X1", "X2",... refer + # algebra coordinates. The variables "X0", "X1",... refer # to the entries of vectors in self._matrix_span. Thus to # convert back and forth between the orthonormal # coordinates and the given ones, we need to stick the @@ -871,7 +871,7 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): sage: J = JordanSpinEJA(3) sage: p = J.characteristic_polynomial_of(); p - X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2 + X0^2 - X1^2 - X2^2 + (-2*t)*X0 + t^2 sage: xvec = J.one().to_vector() sage: p(*xvec) t^2 - 2*t + 1 @@ -920,13 +920,13 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): sage: J = HadamardEJA(2) sage: J.coordinate_polynomial_ring() - Multivariate Polynomial Ring in X1, X2... + Multivariate Polynomial Ring in X0, X1... sage: J = RealSymmetricEJA(3,field=QQ,orthonormalize=False) sage: J.coordinate_polynomial_ring() - Multivariate Polynomial Ring in X1, X2, X3, X4, X5, X6... + Multivariate Polynomial Ring in X0, X1, X2, X3, X4, X5... """ - var_names = tuple( "X%d" % z for z in range(1, self.dimension()+1) ) + var_names = tuple( "X%d" % z for z in range(self.dimension()) ) return PolynomialRing(self.base_ring(), var_names) def inner_product(self, x, y): @@ -1771,7 +1771,7 @@ class RationalBasisEJA(FiniteDimensionalEJA): sage: J = JordanSpinEJA(3) sage: J._charpoly_coefficients() - (X1^2 - X2^2 - X3^2, -2*X1) + (X0^2 - X1^2 - X2^2, -2*X0) sage: a0 = J._charpoly_coefficients()[0] sage: J.base_ring() Algebraic Real Field diff --git a/mjo/eja/eja_cache.py b/mjo/eja/eja_cache.py index b5743ec..81ea398 100644 --- a/mjo/eja/eja_cache.py +++ b/mjo/eja/eja_cache.py @@ -5,8 +5,10 @@ sense to cache them and then only test that the cached values are correct every once in a while. And they're in this separate file because they are visually horrific. -The function used to turn SageMath's output into the appropriate input -can be found in the eja_utils module. +SageMath's output can be converted back into "input form" using a sed +script, for example: + + $ sed -e 's/\^/\*\*/g' -e 's/X\([0-9][0-9]*\)/X\[\1\]/g' The simple algebras _not_ represented here all have rank two or less, and are "easy" to compute even over the algebraic reals. diff --git a/mjo/eja/eja_utils.py b/mjo/eja/eja_utils.py index 79d8ecf..1e10943 100644 --- a/mjo/eja/eja_utils.py +++ b/mjo/eja/eja_utils.py @@ -1,41 +1,5 @@ from sage.structure.element import is_Matrix -def _charpoly_sage_input(s): - r""" - Helper function that you can use on the string output from sage - to convert a charpoly coefficient into the corresponding input - to be cached. - - SETUP:: - - sage: from mjo.eja.eja_algebra import JordanSpinEJA - sage: from mjo.eja.eja_utils import _charpoly_sage_input - - EXAMPLES:: - - sage: J = JordanSpinEJA(4,QQ) - sage: a = J._charpoly_coefficients() - sage: a[0] - X1^2 - X2^2 - X3^2 - X4^2 - sage: _charpoly_sage_input(str(a[0])) - 'X[0]**2 - X[1]**2 - X[2]**2 - X[3]**2' - - """ - import re - - exponent_out = r"\^" - exponent_in = r"**" - - digit_out = r"X([0-9]+)" - - def replace_digit(m): - # m is a match object - return "X[" + str(int(m.group(1)) - 1) + "]" - - s = re.sub(exponent_out, exponent_in, s) - return re.sub(digit_out, replace_digit, s) - - def _scale(x, alpha): r""" Scale the vector, matrix, or cartesian-product-of-those-things