本文整理汇总了Python中sage.rings.all.Integer.digits方法的典型用法代码示例。如果您正苦于以下问题:Python Integer.digits方法的具体用法?Python Integer.digits怎么用?Python Integer.digits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.rings.all.Integer
的用法示例。
在下文中一共展示了Integer.digits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __pow__
# 需要导入模块: from sage.rings.all import Integer [as 别名]
# 或者: from sage.rings.all.Integer import digits [as 别名]
def __pow__(self, n):
"""
Returns this species to the power n. This uses a binary
exponentiation algorithm to perform the powering.
EXAMPLES::
sage: X = species.SingletonSpecies()
sage: (X^2).generating_series().coefficients(4)
[0, 0, 1, 0]
sage: X^1 is X
True
sage: A = X^32
sage: A.digraph()
Multi-digraph on 6 vertices
"""
from sage.rings.all import Integer
import operator
n = Integer(n)
if n <= 0:
raise ValueError, "only positive exponents are currently supported"
digits = n.digits(2)
squares = [self]
for i in range(len(digits)-1):
squares.append(squares[-1]*squares[-1])
return reduce(operator.add, (s for i,s in zip(digits, squares) if i != 0))
示例2: __pow__
# 需要导入模块: from sage.rings.all import Integer [as 别名]
# 或者: from sage.rings.all.Integer import digits [as 别名]
def __pow__(self, n):
r"""
Returns this species to the power `n`.
This uses a binary exponentiation algorithm to perform the
powering.
EXAMPLES::
sage: One = species.EmptySetSpecies()
sage: X = species.SingletonSpecies()
sage: X^2
Product of (Singleton species) and (Singleton species)
sage: X^5
Product of (Singleton species) and (Product of (Product of
(Singleton species) and (Singleton species)) and (Product
of (Singleton species) and (Singleton species)))
sage: (X^2).generating_series().coefficients(4)
[0, 0, 1, 0]
sage: (X^3).generating_series().coefficients(4)
[0, 0, 0, 1]
sage: ((One+X)^3).generating_series().coefficients(4)
[1, 3, 3, 1]
sage: ((One+X)^7).generating_series().coefficients(8)
[1, 7, 21, 35, 35, 21, 7, 1]
sage: x = QQ[['x']].gen()
sage: coeffs = ((1+x+x+x**2)**25+O(x**10)).padded_list()
sage: T = ((One+X+X+X^2)^25)
sage: T.generating_series().coefficients(10) == coeffs
True
sage: X^1 is X
True
sage: A = X^32
sage: A.digraph()
Multi-digraph on 6 vertices
TESTS::
sage: X**(-1)
Traceback (most recent call last):
...
ValueError: only positive exponents are currently supported
"""
from sage.rings.all import Integer
import operator
n = Integer(n)
if n <= 0:
raise ValueError("only positive exponents are currently supported")
digits = n.digits(2)
squares = [self]
for i in range(len(digits) - 1):
squares.append(squares[-1] * squares[-1])
return reduce(operator.mul, (s for i, s in zip(digits, squares)
if i != 0))