本文整理汇总了Python中sage.rings.all.ZZ.sum方法的典型用法代码示例。如果您正苦于以下问题:Python ZZ.sum方法的具体用法?Python ZZ.sum怎么用?Python ZZ.sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.rings.all.ZZ
的用法示例。
在下文中一共展示了ZZ.sum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cardinality
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import sum [as 别名]
def cardinality(self):
"""
Return the cardinality of ``self``.
EXAMPLES::
sage: IntegerVectors(3, 3, min_part=1).cardinality()
1
sage: IntegerVectors(5, 3, min_part=1).cardinality()
6
sage: IntegerVectors(13, 4, max_part=4).cardinality()
20
sage: IntegerVectors(k=4, max_part=3).cardinality()
256
sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality()
27
sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality()
16
"""
if self.k is None:
if self.n is None:
return PlusInfinity()
if ('max_length' not in self.constraints
and self.constraints.get('min_part', 0) <= 0):
return PlusInfinity()
elif ('max_part' in self.constraints
and self.constraints['max_part'] != PlusInfinity()):
if (self.n is None and len(self.constraints) == 2
and 'min_part' in self.constraints
and self.constraints['min_part'] >= 0):
num = self.constraints['max_part'] - self.constraints['min_part'] + 1
return Integer(num ** self.k)
if len(self.constraints) == 1:
m = self.constraints['max_part']
if self.n is None:
return Integer((m + 1) ** self.k)
if m >= self.n:
return Integer(binomial(self.n + self.k - 1, self.n))
# do by inclusion / exclusion on the number
# i of parts greater than m
return Integer(sum( (-1)**i * binomial(self.n+self.k-1-i*(m+1), self.k-1) \
* binomial(self.k,i) for i in range(self.n/(m+1)+1) ))
return ZZ.sum(ZZ.one() for x in self)