Skip to content

Commit 0a00c38

Browse files
Xavier Carusotscrim
authored andcommitted
fix caching of reduced_norm
1 parent e0cf1e4 commit 0a00c38

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/sage/rings/polynomial/skew_polynomial_finite_order.pyx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ cdef class SkewPolynomial_finite_order_dense(SkewPolynomial_generic_dense):
382382
polynomial is ``x`` and the name of central variable is usually ``z``
383383
(see :meth:`~sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_finite_order.center`
384384
for more details about this).
385-
The user can speciify different names if desired::
385+
The user can specify different names if desired::
386386
387387
sage: a.reduced_charpoly(var='T') # variable name for the caracteristic polynomial
388388
T^3 + (2*z + 1)*T^2 + (3*z^2 + 4*z)*T + 4*z^3 + z^2 + 1
@@ -393,15 +393,30 @@ cdef class SkewPolynomial_finite_order_dense(SkewPolynomial_generic_dense):
393393
.. SEEALSO::
394394
395395
:meth:`reduced_trace`, :meth:`reduced_norm`
396+
397+
TESTS:
398+
399+
We test that the cache works correctly::
400+
401+
sage: f = u^5 + t*u^4 + t^2*u^3 + t^3*u^2 + t^4*u + t^5
402+
sage: f.reduced_norm()
403+
z^5 + 2*z^4 + 4*z^3 + z^2 + 4*z + 2
404+
sage: f.reduced_charpoly()
405+
x^3 + z*x^2 + (2*z + 3)*x + 4*z^5 + 3*z^4 + z^3 + 4*z^2 + z + 3
406+
sage: f.reduced_norm()
407+
z^5 + 2*z^4 + 4*z^3 + z^2 + 4*z + 2
396408
"""
397409
if self._charpoly is None:
398410
parent = self._parent
399411
section = parent._embed_constants.section()
400412
M = self._matmul_c()
401413
chi = M.charpoly()
402414
self._charpoly = [tuple(c.list()) for c in chi.list()]
403-
if self._norm is not None:
404-
self._norm = self._charpoly[-1]
415+
if self._norm is None:
416+
if len(self._charpoly) % 2:
417+
self._norm = self._charpoly[0]
418+
else:
419+
self._norm = tuple((-chi[0]).list())
405420
varcenter = None
406421
if var is None:
407422
varcharpoly = 'x'

0 commit comments

Comments
 (0)