本文整理汇总了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)
示例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
示例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)
示例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)]))
示例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])