#17248: Rewriting the method cardinality in the SetPartitions_setparts
-------------------------------------+-------------------------------------
Reporter: g.chatel | Owner: gchatel
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-6.4
Component: combinatorics | Resolution:
Keywords: cardinality, set | Merged in:
partitions | Reviewers:
Authors: Grégory Châtel | Work issues:
Report Upstream: N/A | Commit:
Branch: public/combinat | a18a343ec6d0192f75d399047df373e5862e3208
/set-partition-cardinality-17248 | Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Changes (by vdelecroix):
* status: needs_review => needs_work
Comment:
Hello,
That's cool you worked on this!
1. To avoid the if/else inside your loop you can use the method
`to_exp_dict` of partitions:
{{{
sage: S = SetPartitions(13, Partition([4,3,3,2,1]))
sage: p = S.parts; p
[4, 3, 3, 2, 1]
sage: d = p.to_exp_dict(); d
{1: 1, 2: 1, 3: 2, 4: 1}
}}}
2. Minor remark: if you write
{{{
a = 1
}}}
in the source code this is a Python integer. It is not bad to use it but
it is confusing if you start to mix them with Sage integer which do not
behave the same (especially with respect to division).
3. If you use only Sage integer, there is no need to import `factorial`
and `binomial` as they are methods of Sage integers
{{{
sage: 10.factorial()
3628800
sage: 10.binomial(2)
45
}}}
Using directly those will significantly improve the timings (the
`import` takes time and the function in `sage.rings.arith` are much more
complicated and ends in calling these methods).
4. It would be nice to have a test like the following:
{{{
sage: SetPartitions(13).cardinality()
27644437
sage: sage: sum(SetPartitions(13,p).cardinality() for p in
Partitions(13))
27644437
}}}
Vincent
--
Ticket URL: <http://trac.sagemath.org/ticket/17248#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.