Ticket #14461: trac_14461-review-mh.patch

File trac_14461-review-mh.patch, 3.5 KB (added by mhansen, 10 years ago)
  • sage/combinat/tableau.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1366211077 -3600
    # Node ID 469755f95eaf0795b56154d4c5a10715b771767d
    # Parent  8aa03a6f70cb50c55970c2f4985b87f4789bc243
    #14461: review patch
    
    diff --git a/sage/combinat/tableau.py b/sage/combinat/tableau.py
    a b  
    41804180        """
    41814181        super(StandardTableaux_size, self).__init__(
    41824182              category = FiniteEnumeratedSets())
    4183         self.size = n
     4183        self.size = Integer(n)
    41844184
    41854185
    41864186    def _repr_(self):
     
    42454245
    42464246    def cardinality(self):
    42474247        r"""
    4248         Return the cardinality of ``self``.
     4248        Return the cardinality of number of standard tableaux of size
     4249        ``n``.
     4250
     4251        ALGORITHM:
     4252
     4253        The algorithm uses the fact that standard tableaux of size
     4254        ``n`` are in bijection with the involutions of size ``n``,
     4255        (see page 41 in section 4.1 of [Ful1997]_).  For each number of
     4256        fixed points, you count the number of ways to choose those
     4257        fixed points multiplied by the number of perfect matchings on
     4258        the remaining values.
     4259
     4260        REFERENCES:
     4261
     4262        .. [Ful1997] Fulton, William.  Young Tableaux.
     4263           Cambridge University Press, 1997
    42494264
    42504265        EXAMPLES::
    42514266
    42524267            sage: StandardTableaux(3).cardinality()
    42534268            4
    42544269            sage: ns = [1,2,3,4,5,6]
    4255             sage: sts = [StandardTableaux(n) for n in ns]    # indirect doctest
     4270            sage: sts = [StandardTableaux(n) for n in ns]
    42564271            sage: all([st.cardinality() == len(st.list()) for st in sts])
    42574272            True
    42584273            sage: StandardTableaux(50).cardinality()
     
    42654280            ...       for p in sage.combinat.partition.Partitions(n):
    42664281            ...           c += StandardTableaux(p).cardinality()
    42674282            ...       return c
    4268             sage: all([cardinality_using_hook_formula(i) == StandardTableaux(i).cardinality() for i in range(21)])
     4283            sage: all([cardinality_using_hook_formula(i) == StandardTableaux(i).cardinality() for i in range(10)])
    42694284            True
    42704285        """
    4271         # The algorithm uses the fact that Standard Tableaux of size n
    4272         # are in bijection with involutions of size n and it is easier
    4273         # to count involutions.  First we set the number of fixed
    4274         # points and then we count the number of perfect matchings on
    4275         # the remaining values.
    4276         if self.size % 2 == 0:
    4277             tableaux_number = 0
    4278             # even number of fixed point
    4279             fixed_point_numbers = [2 * x for x in range(0, (self.size / 2) + 1)]
    4280         else:
    4281             tableaux_number = 1 # identity involution
    4282             # odd number of fixed point
    4283             fixed_point_numbers = [(2 * x) + 1 for x in range(0, self.size / 2)]
     4286        tableaux_number = self.size % 2  # identity involution
     4287        fixed_point_numbers = xrange(tableaux_number, self.size + 1 - tableaux_number, 2)
    42844288
    42854289        # number of involution of size "size" (number of way to put
    42864290        # "fixed_point_number" in "size" box * number of involutions
    42874291        # without fixed point of size "size" - "fixed_point_number"
    42884292        for fixed_point_number in fixed_point_numbers:
    4289             tableaux_number += binomial(self.size, fixed_point_number) * \
    4290                 prod(i for i in range(self.size - fixed_point_number) if i%2==1)
     4293            tableaux_number += (self.size.binomial(fixed_point_number) *
     4294                                prod(range(1, self.size - fixed_point_number, 2)))
    42914295
    42924296        return tableaux_number
    42934297