Opened 9 years ago
Last modified 3 years ago
#12589 new defect
series yields wrong result
Reported by: | dkrenn | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-7.0 |
Component: | symbolics | Keywords: | series, order, symbolics |
Cc: | cheuberg, rws | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: | todo |
Description (last modified by )
The following was posted on the public bug reports from the notebook interface by Clemens Heuberger on 1/4/2011 and on sage-support. In the latter other code examples were posted.
f.series(q,2)
for the f
defined below yields Order(q^2)
which is incorrect, as f.subs(q=0)
equals 1
(which is correct).
sage: var('q') sage: f=(q^13362120470/((q - 1)*(q^5 - 1)*(q^21 - 1)*(q^85 - 1)*(q^341 - 1)*(q^1365 - 1)*(q^5461 - 1)*(q^21845 - 1)*(q^87381 - 1)*(q^349525 - 1)*(q^1398101 - 1)*(q^5592405 - 1)*(q^22369621 - 1)*(q^89478485 - 1)*(q^357913941 - 1)*(q^1431655765 - 1)*(q^5726623061 - 1)) + 1)/(q^7635497409/((q - 1)*(q^5 - 1)*(q^21 - 1)*(q^85 - 1)*(q^341 - 1)*(q^1365 - 1)*(q^5461 - 1)*(q^21845 - 1)*(q^87381 - 1)*(q^349525 - 1)*(q^1398101 - 1)*(q^5592405 - 1)*(q^22369621 - 1)*(q^89478485 - 1)*(q^357913941 - 1)*(q^1431655765 - 1)*(q^5726623061 - 1)) + 1) sage: f.subs(q=0) 1 sage: f.series(q,2)
Change History (22)
comment:1 Changed 9 years ago by
- Description modified (diff)
comment:2 Changed 7 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:3 Changed 7 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:4 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:5 Changed 6 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:6 Changed 6 years ago by
- Cc cheuberg added
comment:7 Changed 5 years ago by
- Stopgaps set to todo
comment:8 Changed 5 years ago by
- Cc rws added
comment:9 Changed 5 years ago by
This looks like an int overflow problem. A more minimal case is:
sage: f=(q^13362120470/((q - 1)) +1)/(q^7635497409/((q - 1)) + 1) sage: f.series(q,2) Order(q^2) sage: f=(q^1336212047/((q - 1)) +1)/(q^763549741/((q - 1)) + 1) sage: f.series(q,2) 1 + Order(q^2)
EDIT: Note that log_2(7635497409) = 32.8...
comment:10 follow-ups: ↓ 11 ↓ 13 ↓ 14 Changed 5 years ago by
Note that in Pynac/GiNaC the degree
/ldegree
member functions of basic
returns an int
and since that is virtual =0
, all other objects do as well. So changing this would be major enhancement with performance repercussions.
comment:11 in reply to: ↑ 10 ; follow-ups: ↓ 12 ↓ 16 ↓ 18 Changed 5 years ago by
Replying to rws:
Note that in Pynac/GiNaC the
degree
/ldegree
member functions ofbasic
returns anint
and since that isvirtual =0
, all other objects do as well. So changing this would be major enhancement with performance repercussions.
Being stucked with this bug is not an option either... What else can we do?
comment:12 in reply to: ↑ 11 Changed 5 years ago by
Replying to dkrenn:
Being stucked with this bug is not an option either... What else can we do?
Mathematically you are dealing with so-called "lacunar" or "super-sparse" series. Changing from 32bit to 64bit does not resolve it in principle if it were possible with existing Sage functionality, try this:
sage: R.<a>=QQ[[]] sage: 2^33 8589934592 sage: a^8589934592-1 versus sage: R.<x>=PolynomialRing(QQ,sparse=True) sage: 2^65 36893488147419103232 sage: x^36893488147419103232-1 x^36893488147419103232 - 1 versus sage: R.<x>=PowerSeriesRing(QQ,sparse=True) sage: x^36893488147419103232-1 -1 + x^36893488147419103232 sage: x^36893488147419103232-1+O(x^5555555555555555555555) OverflowError: Python int too large to convert to C long sage: R.<q>=PowerSeriesRing(QQ,sparse=True) sage: f=(q^13362120470/((q - 1)) +1)/(q^7635497409/((q - 1)) + 1) MemoryError
so apparently Sage's sparse power series ring can represent monomials with bigint degree but not a bigint series order term. Representing or computing a full series lastly can involve memory problems for whatever reason.
However, if you request f.series(q,2)
you do not want a full series so maybe lazy series could be your solution.
comment:13 in reply to: ↑ 10 Changed 5 years ago by
I wrote earlier:
Note that in Pynac/GiNaC the
degree
/ldegree
member functions ofbasic
returns anint
and since that isvirtual =0
, all other objects do as well. So changing this would be major enhancement with performance repercussions.
Maybe it is possible to check the expression for bigint exponents and, if so, call a special algorithm like lazy series. There are likely to be special cases of series expansion algorithms in the future, anyway, e.g. a call to fast univariate expansion via flint.
comment:14 in reply to: ↑ 10 Changed 5 years ago by
Replying to rws:
Note that in Pynac/GiNaC the
degree
/ldegree
member functions ofbasic
returns anint
and since that isvirtual =0
, all other objects do as well. So changing this would be major enhancement with performance repercussions.
Presently, we are silently getting wrong results, though. A good step forward would be if we'd get an "overflow error" rather than a series expansion that seems to have 0-terms in order 0, 1.
comment:15 Changed 5 years ago by
- Description modified (diff)
- Milestone changed from sage-6.4 to sage-7.0
comment:16 in reply to: ↑ 11 Changed 5 years ago by
Replying to dkrenn:
Being stucked with this bug is not an option either... What else can we do?
We could adapt a polynomial/series package that supports unlimited exponents: http://bluescarni.github.io/piranha/sphinx/polynomials.html
comment:17 follow-up: ↓ 19 Changed 3 years ago by
The behaviour of this test case changed somewhat. With Sage-8.1.beta6 it takes minutes to output (-1)*q^(-1) + 1 + Order(q^2)
. The time is spent in FLINT manipulating huge dense polynomials. The change is because Pynac no longer uses differentiation for these kind of series. It looks like the way to go here is therefore to 1. recognize rational expressions; 2. normalize them (this needs a new algorithm for sparse polynomials); 3. add a new algorithm to compute the sparse series. As to 2. this is also needed for correct handling of the test case of #23925.
comment:18 in reply to: ↑ 11 Changed 3 years ago by
Replying to dkrenn:
Replying to rws:
Note that in Pynac/GiNaC the
degree
/ldegree
member functions ofbasic
returns anint
and since that isvirtual =0
, all other objects do as well. So changing this would be major enhancement with performance repercussions.Being stucked with this bug is not an option either... What else can we do?
Actually, Pynac master now supports taking any non-symbolic real degree. I'm not sure atm how this can be used to make progress with this ticket.
comment:19 in reply to: ↑ 17 Changed 3 years ago by
Replying to rws:
The behaviour of this test case changed somewhat. With Sage-8.1.beta6 it takes minutes to output
(-1)*q^(-1) + 1 + Order(q^2)
. The time is spent in FLINT manipulating huge dense polynomials. The change is because Pynac no longer uses differentiation for these kind of series. It looks like the way to go here is therefore to 1. recognize rational expressions; 2. normalize them (this needs a new algorithm for sparse polynomials); 3. add a new algorithm to compute the sparse series. As to 2. this is also needed for correct handling of the test case of #23925.
However 2. can only be resolved with a dedicated sparse polynomial package. Actually if 1. #23925 is done; and 2. Pynac normalizes rational functions before developing series; then this ticket can be considered done because we will get a SIGABRT exception because of memory error from Singular+FLINT. This would avoid setting a hard limit on exponents, shifting the responsibility to the polynomial package.
comment:20 Changed 3 years ago by
- Description modified (diff)
comment:21 Changed 3 years ago by
There is need for a hard limit.
FLINT allows only long exponents in functions accessing their fmpz_t
polynomials, so there is a size restriction when using FLINT, i.e. in Pynac series and polynomial manipulation via Singular (which uses FLINT as default).
Note that expansion of polynomials only uses Singular above a certain size, so e.g. expansion of small products with less than 400 terms overall works fine:
sage: ((1+x^(2^100))*(1-x^(2^100))).expand() -x^2535301200456458802993406410752 + 1 sage: 2^101 2535301200456458802993406410752
comment:22 Changed 3 years ago by
With pynac-0.7.12 we have now:
sage: f.series(q,2) Exception (FLINT memory_manager). Unable to allocate memory. ... RuntimeError: Aborted sage: (1/(x^3689348814741910323-1)).series(x) ... RuntimeError: exponent too big
Note that f.series(q,2)
crashes inside the step where rational functions are normalized. This step is however not necessary in principle, and a smarter series functionality is needed to resolve this ticket. At least there is an error message now.
Still there in 6.6.