Ticket #14461: cardinality_for_standard_tableaux-gc.patch

File cardinality_for_standard_tableaux-gc.patch, 3.6 KB (added by g.chatel, 10 years ago)
  • sage/combinat/tableau.py

    # HG changeset patch
    # User Gregory Chatel <gchatel@univ-mlv.fr>
    # Date 1366192849 -7200
    # Node ID 4c7e6a1f009dc459854de711d72939d5c90f7659
    # Parent  4381a8e9f0c8d5d481433f3e670c8de9ddeadc4f
    trac 14461 : change cardinality for standard tableaux of fixed size
    
    diff --git a/sage/combinat/tableau.py b/sage/combinat/tableau.py
    a b from sage.misc.classcall_metaclass impor 
    7878from sage.misc.decorators import rename_keyword
    7979from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
    8080from sage.rings.infinity import PlusInfinity
    81 from sage.rings.arith import factorial
     81from sage.rings.arith import factorial, binomial
    8282from sage.rings.integer import Integer
    8383from sage.combinat.combinat import CombinatorialObject
    8484import sage.combinat.skew_tableau
    import copy 
    8989import permutation
    9090from sage.misc.flatten import flatten
    9191from sage.groups.perm_gps.permgroup import PermutationGroup
    92 from sage.misc.misc import uniq
     92from sage.misc.misc import uniq, prod
    9393from sage.misc.sage_unittest import TestSuite
    9494from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
    9595from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
    class StandardTableaux_size(StandardTabl 
    42264226            for st in StandardTableaux(p):
    42274227                yield self.element_class(self, st)
    42284228
    4229 
    42304229    def cardinality(self):
    4231         """
     4230        r"""
    42324231        Return the cardinality of ``self``.
    42334232
    42344233        EXAMPLES::
    class StandardTableaux_size(StandardTabl 
    42394238            sage: sts = [StandardTableaux(n) for n in ns]    # indirect doctest
    42404239            sage: all([st.cardinality() == len(st.list()) for st in sts])
    42414240            True
    4242         """
    4243         c = 0
    4244         for p in sage.combinat.partition.Partitions(self.size):
    4245             c += StandardTableaux(p).cardinality()
    4246         return c
     4241            sage: StandardTableaux(50).cardinality()
     4242            27886995605342342839104615869259776
     4243
     4244        TESTS::
     4245
     4246            sage: def cardinality_using_hook_formula(n):
     4247            ...       c = 0
     4248            ...       for p in sage.combinat.partition.Partitions(n):
     4249            ...           c += StandardTableaux(p).cardinality()
     4250            ...       return c
     4251            sage: all([cardinality_using_hook_formula(i) == StandardTableaux(i).cardinality() for i in range(21)])
     4252            True
     4253        """
     4254        # The algorithm uses the fact that Standard Tableaux of size n
     4255        # are in bijection with involutions of size n and it is easier
     4256        # to count involutions.  First we set the number of fixed
     4257        # points and then we count the number of perfect matchings on
     4258        # the remaining values.
     4259        if self.size % 2 == 0:
     4260            tableaux_number = 0
     4261            # even number of fixed point
     4262            fixed_point_numbers = [2 * x for x in range(0, (self.size / 2) + 1)]
     4263        else:
     4264            tableaux_number = 1 # identity involution
     4265            # odd number of fixed point
     4266            fixed_point_numbers = [(2 * x) + 1 for x in range(0, self.size / 2)]
     4267
     4268        # number of involution of size "size" (number of way to put
     4269        # "fixed_point_number" in "size" box * number of involutions
     4270        # without fixed point of size "size" - "fixed_point_number"
     4271        for fixed_point_number in fixed_point_numbers:
     4272            tableaux_number += binomial(self.size, fixed_point_number) * \
     4273                prod(i for i in range(self.size - fixed_point_number) if i%2==1)
     4274
     4275        return tableaux_number
    42474276
    42484277
    42494278class StandardTableaux_shape(StandardTableaux):