当前位置: 首页>>代码示例>>Python>>正文


Python Integer.digits方法代码示例

本文整理汇总了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))
开发者ID:bgxcpku,项目名称:sagelib,代码行数:28,代码来源:species.py

示例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))
开发者ID:amitjamadagni,项目名称:sage,代码行数:58,代码来源:species.py


注:本文中的sage.rings.all.Integer.digits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。