Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
darijgr committed Oct 28, 2014
1 parent c8de1be commit 74b18f4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/sage/combinat/tableau.py
Expand Up @@ -5650,10 +5650,11 @@ def random_element(self):
# We compute the number of involutions of size ``size``.
from sage.misc.prandom import randrange
involution_index = randrange(0, StandardTableaux(self.size).cardinality())
# ``involution_index`` is our random integer `r`.
partial_sum = 0
fixed_point_number = self.size % 2

from sage.functions.other import binomial
# ``fixed_point_number`` will become `k`.
from sage.rings.arith import binomial
while True:
# We add the number of involutions with ``fixed_point_number``
# fixed points.
Expand All @@ -5668,10 +5669,12 @@ def random_element(self):
# We generate a subset of size "fixed_point_number" of the set {1,
# ..., size}.
from sage.misc.prandom import sample
fixed_point_positions = set(sample(range(1, self.size + 1), fixed_point_number))
# We generate a list of tuples with the first part being the fixed
# points of the permutation and the second part being a perfect
# matching on the remaining values.
fixed_point_positions = set(sample(xrange(1, self.size + 1), fixed_point_number))
# We generate a list of tuples which will form the cycle
# decomposition of our random involution. This list contains
# singletons (corresponding to the fixed points of the
# involution) and pairs (forming a perfect matching on the
# remaining values).
from sage.combinat.perfect_matching import PerfectMatchings
permutation_cycle_rep = [(fixed_point,) for fixed_point in fixed_point_positions] + \
list(PerfectMatchings(set(range(1, self.size + 1)) - set(fixed_point_positions)).random_element())
Expand Down

0 comments on commit 74b18f4

Please sign in to comment.