#20561: Return cycle type of a permutation
-------------------------------------+-------------------------------------
       Reporter:  andrew.mathas      |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.2
      Component:  group theory       |   Resolution:
       Keywords:  permutation,       |    Merged in:
  cycle type                         |    Reviewers:
        Authors:  Andrew Mathas      |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:                     |  35145b98cacc56bdee36bc8836218d6c4dec5e06
  u/andrew.mathas/return_cycle_type_of_a_permutation|     Stopgaps:
   Dependencies:                     |
-------------------------------------+-------------------------------------

Comment (by andrew.mathas):

 I am amused how much bandwidth such a trivial ticket can generate:)

 I agree with vdelecroix that allowing singletons to be ignored will
 probably be useful, is more consistent with the other `cycle_*` methods
 and that it is trivial to implement. For all of these reasons, it should
 be implemented so I have added an optional `singletons` argument for this.

 I also agree with Travis that the casual user will expect that
 `cycle_type` will return a partition so I have made this the default,
 using `_Partitions` as Travis recommends. The non-casual user may well not
 want a partition so I have added a second optional argument `as_list` that
 , when `True`, will cause a list to be returned.

 Here are some new timings with these changes:

 {{{#!python
 sage: S = SymmetricGroup(100)
 sage: p = S.random_element()
 sage:  %timeit c = p.cycle_type()
 10000 loops, best of 3: 47.5 µs per loop
 sage: %timeit c = p.cycle_type(singletons=True)
 10000 loops, best of 3: 50.2 µs per loop
 sage: %timeit c = p.cycle_type(as_list=True)
 100000 loops, best of 3: 11.9 µs per loop
 sage: %timeit c = p.cycle_type(singletons=True, as_list=True)
 100000 loops, best of 3: 11.6 µs per loop
 sage: %timeit c = p.cycle_tuples()
 100000 loops, best of 3: 9.83 µs per loop
 }}}

 So it seems that returning a partition is relatively costly but I think
 that it is more user friendly so should be the default. I have added a
 remark in the documentation that `as_list=True` should be used when speed
 is an issue.
 ----
 New commits:
 
||[http://git.sagemath.org/sage.git/commit/?id=18f179963a10ef1b0facb71591f88080f3f0ba1a
 18f1799]||{{{Merge branch 'develop' into
 t/20561/return_cycle_type_of_a_permutation}}}||
 
||[http://git.sagemath.org/sage.git/commit/?id=35145b98cacc56bdee36bc8836218d6c4dec5e06
 35145b9]||{{{Adding comment about using as_list for speed}}}||

--
Ticket URL: <http://trac.sagemath.org/ticket/20561#comment:16>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to