Ticket #14461: cardinality_for_standard_tableaux-gc.patch
File cardinality_for_standard_tableaux-gc.patch, 3.6 KB (added by , 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 78 78 from sage.misc.decorators import rename_keyword 79 79 from sage.rings.finite_rings.integer_mod_ring import IntegerModRing 80 80 from sage.rings.infinity import PlusInfinity 81 from sage.rings.arith import factorial 81 from sage.rings.arith import factorial, binomial 82 82 from sage.rings.integer import Integer 83 83 from sage.combinat.combinat import CombinatorialObject 84 84 import sage.combinat.skew_tableau … … import copy 89 89 import permutation 90 90 from sage.misc.flatten import flatten 91 91 from sage.groups.perm_gps.permgroup import PermutationGroup 92 from sage.misc.misc import uniq 92 from sage.misc.misc import uniq, prod 93 93 from sage.misc.sage_unittest import TestSuite 94 94 from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets 95 95 from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets … … class StandardTableaux_size(StandardTabl 4226 4226 for st in StandardTableaux(p): 4227 4227 yield self.element_class(self, st) 4228 4228 4229 4230 4229 def cardinality(self): 4231 """4230 r""" 4232 4231 Return the cardinality of ``self``. 4233 4232 4234 4233 EXAMPLES:: … … class StandardTableaux_size(StandardTabl 4239 4238 sage: sts = [StandardTableaux(n) for n in ns] # indirect doctest 4240 4239 sage: all([st.cardinality() == len(st.list()) for st in sts]) 4241 4240 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 4247 4276 4248 4277 4249 4278 class StandardTableaux_shape(StandardTableaux):