Opened 8 years ago
Last modified 5 years ago
#14685 needs_work defect
error in the computing of the approximate order in LazyPowerSeries — at Version 5
Reported by: | MatthieuDien | Owned by: | sage-combinat |
---|---|---|---|
Priority: | major | Milestone: | sage-6.6 |
Component: | combinatorics | Keywords: | LazyPowerSeries aorder approximate order |
Cc: | mantepse | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
Hi,
I found a bug in the LazyPowerSeries? class of package combinat. There is mistake in the computing of the approximate order of a serie. A demonstration of the bug :
sage: R = LazyPowerSeriesRing(QQ) sage: B = R([0,0,0,1,0]) sage: B.aorder 0 sage: B.coefficients(10) [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] sage: B.aorder 1
The good result should be 3 and not 1 (the order of the series B = x^{3} is 3 not 1 )
Here, a patch which fix that:
--- series_old.py 2013-06-08 13:48:40.490566975 +0200 +++ series.py 2013-06-08 14:00:41.903399503 +0200 @@ -624,17 +624,17 @@ c = self._stream n = c.number_computed() + while ao < n: + if self._stream[ao] == 0: + self.aorder += 1 + ao += 1 + else: + self.order = ao + break - if ao == 0 and n > 0: - while ao < n: - if self._stream[ao] == 0: - self.aorder += 1 - ao += 1 - else: - break #Try to recognize the zero series - if ao == n: + if ao == n and n > 0: #For non-constant series, we cannot do anything if not c.is_constant(): return @@ -642,11 +642,7 @@ self.aorder = inf self.order = inf return - - if ao < n: - self.order = ao - - + if hasattr(self, '_reference') and self._reference is not None: self._reference._copy(self)
The bug is that the aorder is computed one time and never updated. This is because the order was assigned the first time then the condition self.order != unk becomes false and the update never comes.
After the patch, we obtain :
sage: R = LazyPowerSeriesRing(QQ) sage: B = R([0,0,0,1,0]) sage: B.aorder 0 sage: B.coefficients(10) [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] sage: B.aorder 3
What we expected.
PS : Thanks you for the commment, I tried to answer it.
Change History (5)
comment:1 Changed 8 years ago by
- Description modified (diff)
- Type changed from PLEASE CHANGE to defect
comment:2 Changed 8 years ago by
comment:3 Changed 8 years ago by
- Description modified (diff)
comment:4 Changed 8 years ago by
- Description modified (diff)
comment:5 Changed 8 years ago by
- Description modified (diff)
Bienvenue à bord !
Your patch does not looks good: it contains three times the same thing. It is necessary to make it again in a more clean way.
It is not clear to me what the expected result should be in the example given above. Which answer is correct and which one is not ?
Apart from that, it would be good to add a test to check that the error is corrected. Something like
and then the appropriate example.