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


Python QQ.coerce方法代码示例

本文整理汇总了Python中sage.rings.all.QQ.coerce方法的典型用法代码示例。如果您正苦于以下问题:Python QQ.coerce方法的具体用法?Python QQ.coerce怎么用?Python QQ.coerce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.rings.all.QQ的用法示例。


在下文中一共展示了QQ.coerce方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _element_constructor_

# 需要导入模块: from sage.rings.all import QQ [as 别名]
# 或者: from sage.rings.all.QQ import coerce [as 别名]
    def _element_constructor_(self, x):
        r"""
        Create an element from ``x``.

        INPUT:

        - ``x`` -- a rational number or `\infty`

        TESTS::

            sage: from sage.rings.valuation.value_group import DiscreteValuationCodomain
            sage: DiscreteValuationCodomain()(0)
            0
            sage: DiscreteValuationCodomain()(infinity)
            +Infinity
            sage: DiscreteValuationCodomain()(-infinity)
            -Infinity

        """
        if x is infinity:
            return x
        if x is -infinity:
            return x
        if x not in QQ:
            raise ValueError("must be a rational number or infinity")
        return QQ.coerce(x)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:28,代码来源:value_group.py

示例2: create_key

# 需要导入模块: from sage.rings.all import QQ [as 别名]
# 或者: from sage.rings.all.QQ import coerce [as 别名]
    def create_key(self, base, s):
        r"""
        Create a key which uniquely identifies a valuation.

        TESTS::

            sage: 3*ZZ.valuation(2) is 2*(3/2*ZZ.valuation(2)) # indirect doctest
            True
            
        """
        from sage.rings.all import infinity, QQ
        if s is infinity or s not in QQ or s <= 0:
            # for these values we can not return a TrivialValuation() in
            # create_object() because that would override that instance's
            # _factory_data and lead to pickling errors
            raise ValueError("s must be a positive rational")
        if base.is_trivial():
            # for the same reason we can not accept trivial valuations here
            raise ValueError("base must not be trivial")
        s = QQ.coerce(s)
        if s == 1:
            # we would override the _factory_data of base if we just returned
            # it in create_object() so we just refuse to do so
            raise ValueError("s must not be 1")

        if isinstance(base, ScaledValuation_generic):
            return self.create_key(base._base_valuation, s*base._scale)

        return base, s
开发者ID:saraedum,项目名称:sage-renamed,代码行数:31,代码来源:scaled_valuation.py

示例3: __classcall__

# 需要导入模块: from sage.rings.all import QQ [as 别名]
# 或者: from sage.rings.all.QQ import coerce [as 别名]
    def __classcall__(cls, generator):
        r"""
        Normalizes ``generator`` to a positive rational so that this is a
        unique parent.

        TESTS::

            sage: from sage.rings.valuation.value_group import DiscreteValueGroup
            sage: DiscreteValueGroup(1) is DiscreteValueGroup(-1)
            True

        """
        generator = QQ.coerce(generator)
        generator = generator.abs()
        return super(DiscreteValueGroup, cls).__classcall__(cls, generator)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:17,代码来源:value_group.py

示例4: some_elements

# 需要导入模块: from sage.rings.all import QQ [as 别名]
# 或者: from sage.rings.all.QQ import coerce [as 别名]
    def some_elements(self):
        r"""
        Return some typical elements in this semigroup.

        EXAMPLES::

            sage: from sage.rings.valuation.value_group import DiscreteValueSemigroup
            sage: list(DiscreteValueSemigroup([-3/8,1/2]).some_elements())
            [0, -3/8, 1/2, ...]

        """
        yield self(0)
        if self.is_trivial():
            return
        for g in self._generators:
            yield g
        from sage.rings.all import ZZ
        for x in (ZZ**len(self._generators)).some_elements():
            yield QQ.coerce(sum([abs(c)*g for c,g in zip(x,self._generators)]))
开发者ID:saraedum,项目名称:sage-renamed,代码行数:21,代码来源:value_group.py

示例5: _mul_

# 需要导入模块: from sage.rings.all import QQ [as 别名]
# 或者: from sage.rings.all.QQ import coerce [as 别名]
    def _mul_(self, other, switch_sides=False):
        r"""
        Return the semigroup generated by ``other`` times the generators of this
        semigroup.

        INPUT:

        - ``other`` -- a rational number

        EXAMPLES::

            sage: from sage.rings.valuation.value_group import DiscreteValueSemigroup
            sage: D = DiscreteValueSemigroup(1/2)
            sage: 1/2 * D
            Additive Abelian Semigroup generated by 1/4
            sage: D * (1/2)
            Additive Abelian Semigroup generated by 1/4
            sage: D * 0
            Trivial Additive Abelian Semigroup

        """
        other = QQ.coerce(other)
        return DiscreteValueSemigroup([g*other for g in self._generators])
开发者ID:saraedum,项目名称:sage-renamed,代码行数:25,代码来源:value_group.py


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