Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

series yields wrong result #12589

Open
dkrenn opened this issue Feb 26, 2012 · 17 comments
Open

series yields wrong result #12589

dkrenn opened this issue Feb 26, 2012 · 17 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Feb 26, 2012

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)

CC: @cheuberg @rwst

Component: symbolics

Keywords: series, order, symbolics

Stopgaps: todo

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

@dkrenn dkrenn added this to the sage-5.11 milestone Feb 26, 2012
@dkrenn

This comment has been minimized.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 16, 2015

comment:6

Still there in 6.6.

@sagetrac-jakobkroeker
Copy link
Mannequin

sagetrac-jakobkroeker mannequin commented Aug 25, 2015

Stopgaps: todo

@rwst
Copy link

rwst commented Aug 31, 2015

comment:9

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...

@rwst
Copy link

rwst commented Dec 19, 2015

comment:10

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.

@dkrenn
Copy link
Contributor Author

dkrenn commented Jan 5, 2016

comment:11

Replying to @rwst:

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.

Being stucked with this bug is not an option either... What else can we do?

@rwst
Copy link

rwst commented Jan 6, 2016

comment:12

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.

@rwst
Copy link

rwst commented Jan 9, 2016

comment:13

I wrote earlier:

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.

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.

@nbruin
Copy link
Contributor

nbruin commented Jan 9, 2016

comment:14

Replying to @rwst:

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.

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.

@rwst

This comment has been minimized.

@rwst rwst modified the milestones: sage-6.4, sage-7.0 Jan 10, 2016
@rwst
Copy link

rwst commented May 31, 2016

comment:16

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

@rwst
Copy link

rwst commented Sep 26, 2017

comment:17

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.

@rwst
Copy link

rwst commented Sep 29, 2017

comment:18

Replying to @dkrenn:

Replying to @rwst:

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.

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.

@rwst
Copy link

rwst commented Sep 29, 2017

comment:19

Replying to @rwst:

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.

@rwst

This comment has been minimized.

@rwst
Copy link

rwst commented Sep 30, 2017

comment:21

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

@rwst
Copy link

rwst commented Oct 1, 2017

comment:22

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.

@mkoeppe mkoeppe removed this from the sage-7.0 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants