Skip to content

Commit

Permalink
gh-37499: use sparse polynomials for generating functions
Browse files Browse the repository at this point in the history
    
Currently, the findstat interfaces uses dense polynomials to store the
generating functions for a statistic.  However, some generating
functions are extremely sparse, for example
https://www.findstat.org/StatisticsDatabase/St000001/ has

```
q^292864 + q^68640 + 2*q^64064 + 2*q^48048 + 4*q^21450 + q^16016 +
4*q^15015 + 2*q^12870 + 2*q^11583 + q^8580 + 4*q^7700 + 8*q^5775 +
4*q^4455 + 4*q^4158 + 2*q^3520 + q^3080 + 4*q^2970 + q^2640 + 16*q^2310
+ 2*q^2145 + 2*q^2112 + 4*q^1540 + 8*q^1320 + 4*q^1188 + 4*q^1155 +
4*q^1092 + 4*q^1017 + 4*q^990 + 2*q^825 + 16*q^768 + 2*q^660 + 8*q^567 +
2*q^552 + 8*q^525 + 4*q^471 + 2*q^462 + 8*q^450 + 3*q^448 + 4*q^432 +
8*q^384 + 2*q^309 + 4*q^300 + 6*q^288 + 2*q^282 + 4*q^252 + q^244 +
24*q^216 + 4*q^210 + 12*q^189 + 16*q^168 + 12*q^162 + 4*q^146 + 2*q^132
+ 4*q^126 + 4*q^120 + 2*q^112 + 4*q^99 + 4*q^98 + 4*q^92 + 12*q^90 +
6*q^84 + q^80 + 4*q^77 + 25*q^70 + 14*q^64 + 14*q^56 + 8*q^55 + 8*q^49 +
8*q^42 + 4*q^40 + 2*q^36 + 32*q^35 + 4*q^30 + 6*q^29 + 4*q^28 + 8*q^26 +
16*q^21 + 8*q^20 + 12*q^19 + 19*q^16 + 14*q^15 + 18*q^14 + 10*q^11 +
14*q^10 + 16*q^9 + 10*q^8 + 14*q^6 + 30*q^5 + 20*q^4 + 32*q^3 + 19*q^2 +
26*q}
```
Storing this in a dense polynomial is not a good idea.
    
URL: #37499
Reported by: Martin Rubey
Reviewer(s): nadialafreniere
  • Loading branch information
Release Manager committed Mar 29, 2024
2 parents dc915ec + e5d6f95 commit 65e6d63
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sage/databases/findstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def _generating_functions_from_dict(gfs, style):
if style == "polynomial":
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.integer_ring import ZZ
P = PolynomialRing(ZZ, "q")
P = PolynomialRing(ZZ, "q", sparse=True)
q = P.gen()
return {level: sum(coefficient * q**exponent
for exponent, coefficient in gen_dict.items())
Expand Down

0 comments on commit 65e6d63

Please sign in to comment.