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

Use FLINT to compute the partition function #13199

Closed
fredrik-johansson opened this issue Jul 4, 2012 · 24 comments
Closed

Use FLINT to compute the partition function #13199

fredrik-johansson opened this issue Jul 4, 2012 · 24 comments

Comments

@fredrik-johansson
Copy link

Before:

sage: %timeit number_of_partitions(1)   
625 loops, best of 3: 2.09 µs per loop
sage: %timeit number_of_partitions(10^3)
625 loops, best of 3: 197 µs per loop
sage: %timeit number_of_partitions(10^6)
25 loops, best of 3: 32.8 ms per loop
sage: %time number_of_partitions(10^9); 
CPU times: user 37.92 s, sys: 0.00 s, total: 37.92 s
Wall time: 37.93 s

After:

sage: %timeit number_of_partitions(1)
625 loops, best of 3: 1.94 µs per loop
sage: %timeit number_of_partitions(10^3)
625 loops, best of 3: 51.4 µs per loop
sage: %timeit number_of_partitions(10^6)
125 loops, best of 3: 2.66 ms per loop
sage: %time number_of_partitions(10^9); 
CPU times: user 0.47 s, sys: 0.00 s, total: 0.47 s
Wall time: 0.48 s

TODO: should add a 64-bit only test to check that evaluation works with n >= 2^32.


Apply:

Component: combinatorics

Author: Fredrik Johansson

Reviewer: Andrew Mathas, Frédéric Chapoton, Travis Scrimshaw

Merged: sage-5.11.beta1

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

@fredrik-johansson
Copy link
Author

Attachment: flint_partition_function.patch.gz

@AndrewMathas
Copy link
Member

comment:2

I am happy to review this, although it is not clear to me what the status of #12173 is and until this patch is merged it seems rather cumbersome to load the current patch on top of #12173 in order play around with this patch and check to see that it actually works.

Assuming that it is OK, I would like to see some more explicit tests inside the new number_of_partitions to show that it is working. I'd suggest simply reusing the ones that are in sage.combinat.partition.number_of_partitions. That is, adding the following tests to the doc-string for your number_of_partitions:

        sage: from sage.combinat.partitions import number_of_partitions
        sage: number_of_partitions(3)
        3
        sage: number_of_partitions(10)
        42
        sage: number_of_partitions(40)
        37338
        sage: number_of_partitions(100)
        190569292
        sage: number_of_partitions(100000)
        27493510569775696512677516320986352688173429315980054758203125984302147328114964173055050741660736621590157844774296248940493063070200461792764493033510116079342457190155718943509725312466108452006369558934464248716828789832182345009262853831404597021307130674510624419227311238999702284408609370935531629697851569569892196108480158600569421098519

    TESTS::

        sage: n = 500 + randint(0,500)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1500 + randint(0,1500)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1000000 + randint(0,1000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1000000 + randint(0,1000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1000000 + randint(0,1000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1000000 + randint(0,1000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1000000 + randint(0,1000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 1000000 + randint(0,1000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0
        True
        sage: n = 100000000 + randint(0,100000000)
        sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0  # long time (4s on sage.math, 2011)
        True

@AndrewMathas
Copy link
Member

Reviewer: Andrew Mathas

@fchapoton
Copy link
Contributor

Changed dependencies from #12173 to none

@fchapoton
Copy link
Contributor

comment:4

I removed the dependency to #12173, since this has been closed in 5.10.beta3, and since a dependency on spkg makes the bot unhappy.

for the bot:

apply flint_partition_function.patch

@fchapoton
Copy link
Contributor

Work Issues: needs rebase

@fchapoton
Copy link
Contributor

comment:5

this needs to be rebased on 5.10beta4

@fchapoton
Copy link
Contributor

comment:6

Attachment: trac_13199_flint_partition_function_v2.patch.gz

for the bot:

apply trac_13199_flint_partition_function_v2.patch

I have made a rebased patch, passing all tests.

@AndrewMathas
Copy link
Member

comment:8

Hi. As I said on the ticket above, can you please add some more tests to the new partition function.

@fchapoton
Copy link
Contributor

comment:9

ok, I will add the tests. But there is an annoying doctest failure concerning cached functions, see bot report.

@tscrim

This comment has been minimized.

@tscrim
Copy link
Collaborator

tscrim commented Jun 10, 2013

Changed reviewer from Andrew Mathas to Andrew Mathas, Frederic Chapoton, Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Jun 10, 2013

comment:10

Here's a review patch which should fix the problem, which was the Bober's implementation was cached (since it was the default). I changed this to the FLINT.

sage -t ../misc/cachefunc.pyx
    [593 tests, 78.50 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 79.6 seconds
    cpu time: 8.1 seconds
    cumulative wall time: 78.5 seconds

I also added the additional tests Andrew wanted and fixed the docstrings.

For patchbot:

Apply: trac_13199_flint_partition_function_v2.patch, trac_13199-flint_partition-review-ts.patch

@fchapoton
Copy link
Contributor

comment:11

Looks good to me, but the bot complains about the new module. Is there a way to avoid that, or should we just forget this warning ?

@tscrim
Copy link
Collaborator

tscrim commented Jun 11, 2013

comment:12

The new module can't really be avoided, plus it doesn't (significantly) add to the startup time, so I ignore these.

@tscrim
Copy link
Collaborator

tscrim commented Jun 11, 2013

comment:13

I'm going to set this to positive review now since I don't think either of you (Andrew, Frederic) have any other objections. Feel free to set this to needs work if I'm wrong.

@jdemeyer
Copy link

Changed work issues from needs rebase to none

@jdemeyer jdemeyer removed this from the sage-5.10 milestone Jun 11, 2013
@jdemeyer jdemeyer added this to the sage-5.11 milestone Jun 11, 2013
@tscrim
Copy link
Collaborator

tscrim commented Jun 12, 2013

@tscrim
Copy link
Collaborator

tscrim commented Jun 12, 2013

comment:15

I've uploaded a new version of my review patch which removes the unneeded include_dirs from module_list.py.

@tscrim
Copy link
Collaborator

tscrim commented Jun 12, 2013

comment:16

Because of the type of change, this needs another (quick) review.

@fchapoton
Copy link
Contributor

comment:17

ok, looks good to me.

@AndrewMathas
Copy link
Member

comment:18

Replying to @fchapoton:

ok, looks good to me.

Thanks Travis. I'm happy too.

@jdemeyer
Copy link

Merged: sage-5.11.beta1

@jdemeyer
Copy link

jdemeyer commented Aug 1, 2013

Changed reviewer from Andrew Mathas, Frederic Chapoton, Travis Scrimshaw to Andrew Mathas, Frédéric Chapoton, Travis Scrimshaw

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

5 participants