Skip to content

Improve the _repr_() method of lazy series to ignore undecidable errors #34405

@tscrim

Description

@tscrim
sage: L.<q> = LazyLaurentSeriesRing(QQ)
sage: R.<a> = LazyLaurentSeriesRing(L)
sage: f = R(lambda n: (1-q)/(1-q^(n+1)), valuation=0)
sage: f
1 + (1 - q + q^2 - q^3 + q^4 - q^5 + q^6 + O(q^7))*a + (1 - q + q^3 - q^4 + q^6 + O(q^7))*a^2 + (1 - q + q^4 - q^5 + O(q^7))*a^3 + (1 - q + q^5 - q^6 + O(q^7))*a^4 + (1 - q + q^6 + O(q^7))*a^5 + (1 - q + O(q^7))*a^6 + O(a^7)

Then let's compute something simple:

sage: temp = f - f(a^2)
sage: temp
<repr(<sage.rings.lazy_series_ring.LazyLaurentSeriesRing_with_category.element_class at 0x7f9c05e9c680>) failed: ValueError: undecidable as lazy Laurent series>
sage: temp = f - f(a^2)
sage: temp
<repr(<sage.rings.lazy_series_ring.LazyLaurentSeriesRing_with_category.element_class at 0x7f9c064e2c00>) failed: ValueError: undecidable as lazy Laurent series>
sage: temp._repr_()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[snip]
File ~/sage-build/src/sage/rings/polynomial/polynomial_element.pyx:11177, in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.__init__()
  11175 if check:
  11176     self.__coeffs = [R(t) for t in x]
> 11177     self.__normalize()
  11178 else:
  11179     self.__coeffs = x

File ~/sage-build/src/sage/rings/polynomial/polynomial_element.pyx:11348, in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.__normalize()
  11346 cdef list x = self.__coeffs
  11347 cdef Py_ssize_t n = len(x) - 1
> 11348 while n >= 0 and not x[n]:
  11349     del x[n]
  11350     n -= 1

File ~/sage-build/src/sage/rings/lazy_series.py:618, in LazyModuleElement.__bool__(self)
    616 if self[self._coeff_stream._approximate_order]:
    617     return True
--> 618 raise ValueError("undecidable as lazy Laurent series")

ValueError: undecidable as lazy Laurent series

The issue is because we are (necessarily) very strict about checking if a series is zero because we do not want things to run for forever:

sage: temp[:10]
[0,
 1 - q + q^2 - q^3 + q^4 - q^5 + q^6 + O(q^7),
 -q^2 + 2*q^3 - 2*q^4 + q^5 + O(q^7),
 1 - q + q^4 - q^5 + O(q^7),
 -q^3 + q^4 + q^5 - 2*q^6 + O(q^7),
 1 - q + q^6 + O(q^7),
 -q^4 + q^5 + O(q^7),
 1 - q + O(q^7),
 -q^5 + q^6 + O(q^7),
 1 - q + O(q^7)]
sage: temp
(1 - q + q^2 - q^3 + q^4 - q^5 + q^6 + O(q^7))*a + (-q^2 + 2*q^3 - 2*q^4 + q^5 + O(q^7))*a^2 + (1 - q + q^4 - q^5 + O(q^7))*a^3 + (-q^3 + q^4 + q^5 - 2*q^6 + O(q^7))*a^4 + (1 - q + q^6 + O(q^7))*a^5 + (-q^4 + q^5 + O(q^7))*a^6 + O(a^7)

So we probably need to refactor out the representation for Laurent polynomials to avoid the normalization call.

CC: @mantepse

Component: algebra

Issue created by migration from https://trac.sagemath.org/ticket/34405

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions