Ask Your Question

Laurent series error q^2+O(q) is not O(q)

asked 2017-10-18 15:13:58 -0600

Ant gravatar image

updated 2017-10-20 08:52:03 -0600

I get an error for the following code:


Any explanation? (works for PowerSeriesRing) Here is the error:

Error in lines 2-2 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/", line 996, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "sage/structure/element.pyx", line 1192, in sage.structure.element.Element.__add__ (/ext/sage/sage-8.0/src/build/cythonized/sage/structure/element.c:10640) return (<element>left)._add_(right) File "sage/rings/laurent_series_ring_element.pyx", line 622, in sage.rings.laurent_series_ring_element.LaurentSeries._add_ (/ext/sage/sage-8.0/src/build/cythonized/sage/rings/laurent_series_ring_element.c:8637) return right.add_bigoh(self.prec()) File "sage/rings/laurent_series_ring_element.pyx", line 691, in sage.rings.laurent_series_ring_element.LaurentSeries.add_bigoh (/ext/sage/sage-8.0/src/build/cythonized/sage/rings/laurent_series_ring_element.c:9742) u = self.__u.add_bigoh(prec - self.__n) File "sage/rings/power_series_ring_element.pyx", line 797, in sage.rings.power_series_ring_element.PowerSeries.add_bigoh (/ext/sage/sage-8.0/src/build/cythonized/sage/rings/power_series_ring_element.c:9029) return self._parent(v, prec) File "sage/structure/parent.pyx", line 936, in sage.structure.parent.Parent.__call__ (/ext/sage/sage-8.0/src/build/cythonized/sage/structure/parent.c:9826) return mor._call_with_args(x, args, kwds) File "sage/structure/coerce_maps.pyx", line 173, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args (/ext/sage/sage-8.0/src/build/cythonized/sage/structure/coerce_maps.c:5322) raise File "sage/structure/coerce_maps.pyx", line 166, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args (/ext/sage/sage-8.0/src/build/cythonized/sage/structure/coerce_maps.c:5161) return C._element_constructor(x, *args) File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sage/rings/", line 783, in _element_constructor_ raise ValueError("prec (= %s) must be non-negative" % prec) ValueError: prec (= -1) must be non-negative

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-19 06:13:12 -0600

dan_fulea gravatar image

What is the expectation?

Default precision has an other sense here... For instance:

sage: R.<q>=LaurentSeriesRing(QQ, default_prec=10)
sage: R(q^100)
sage: R(q^100)/R(1+q)
q^100 - q^101 + q^102 - q^103 + q^104 - q^105 + q^106 - q^107 + q^108 - q^109 + O(q^110)
sage: R(q^-100)/R(1+q)
q^-100 - q^-99 + q^-98 - q^-97 + q^-96 - q^-95 + q^-94 - q^-93 + q^-92 - q^-91 + O(q^-90)

The word default precision tells just how many significant terms should be computed and shown. It is not about an ideal, computations may show O(q^110) . Which is not O(q^10).

The initialization of an element of the ring is an other story, and sage assume the user knows what makes sense, and what not.

So q^2 + O(q) simply makes no sense. The error ValueError: prec (= -1) must be non-negative is telling enough. Same for q^2017 + O(q) where the error is of course ValueError: prec (= -2016) must be non-negative.

edit flag offensive delete link more


The expectation is O(q). The same code works for power series and gives the desired result O(q)

Ant gravatar imageAnt ( 2017-10-19 09:08:25 -0600 )edit

OK, right, this should not happen.

But there is a good way to prevent thing going wrong like the above. Simply use

R.<q>=LaurentSeriesRing(QQ, default_prec=10)
a = R(q^2)

and there is no problem to work inside this ring. For instance:

sage: a
sage: a.precision_absolute()
sage: a.precision_relative()

The big problem i see is related to a bug (rather than feature) in the function add_bigoh, which crashes in a.add_bigoh(1) or in (a^3).add_bigoh(5) ... I think it is simple to fix the code. (I would fix it, but am still new in sage devel, no git use so far...)

Thanks for the post!

dan_fulea gravatar imagedan_fulea ( 2017-10-23 15:45:45 -0600 )edit

Sorry, I don't really understand your way of preventing. I showed a simple example of how things can go wrong, which makes computations in Laurent series rings impossible because you can't even perform addition in there. For example,

print a+b+c

gives an error. I think you are right about the function add_bigoh. I tried to understand how to report bugs in here, but it seems overly complicated tbh, so if you or anyone could report that, it would be great! Also, it just seems that the whole LaurentSeriesRing is underdeveloped (earlier I asked about lifting homomorphisms from the base ring to Laurent series, which is implemented for polynomials but not for series),which is weird because Laurent series are better than power

Ant gravatar imageAnt ( 2017-10-23 18:22:34 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-10-18 15:13:58 -0600

Seen: 84 times

Last updated: Oct 20