本文整理汇总了Python中sage.rings.polynomial.polynomial_element.Polynomial.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Polynomial.__init__方法的具体用法?Python Polynomial.__init__怎么用?Python Polynomial.__init__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.rings.polynomial.polynomial_element.Polynomial
的用法示例。
在下文中一共展示了Polynomial.__init__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sage.rings.polynomial.polynomial_element import Polynomial [as 别名]
# 或者: from sage.rings.polynomial.polynomial_element.Polynomial import __init__ [as 别名]
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False):
"""
TESTS::
sage: PolynomialRing(RIF, 'z', sparse=True)([RIF(-1, 1), RIF(-1,1)])
0.?*z + 0.?
sage: PolynomialRing(CIF, 'z', sparse=True)([CIF(RIF(-1,1), RIF(-1,1)), RIF(-1,1)])
0.?*z + 0.? + 0.?*I
"""
Polynomial.__init__(self, parent, is_gen=is_gen)
if x is None:
self.__coeffs = {}
return
R = parent.base_ring()
if isinstance(x, Polynomial):
if x.parent() == self.parent():
x = dict(x.dict())
elif x.parent() == R:
x = {0:x}
else:
w = {}
for n, c in x.dict().iteritems():
w[n] = R(c)
# The following line has been added in trac ticket #9944.
# Apparently, the "else" case has never occured before.
x = w
elif isinstance(x, list):
x = dict((i, c) for (i, c) in enumerate(x) if c)
elif isinstance(x, pari_gen):
y = {}
for i in range(len(x)):
y[i] = R(x[i])
x = y
check = True
elif not isinstance(x, dict):
x = {0:x} # constant polynomials
if check:
self.__coeffs = {}
for i, z in x.iteritems():
self.__coeffs[i] = R(z)
else:
self.__coeffs = x
if check:
self.__normalize()
示例2: __init__
# 需要导入模块: from sage.rings.polynomial.polynomial_element import Polynomial [as 别名]
# 或者: from sage.rings.polynomial.polynomial_element.Polynomial import __init__ [as 别名]
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False):
Polynomial.__init__(self, parent, is_gen=is_gen)
if x is None:
self.__coeffs = {}
return
R = parent.base_ring()
if isinstance(x, Polynomial):
if x.parent() == self.parent():
x = dict(x.dict())
elif x.parent() == R:
x = {0:x}
else:
w = {}
for n, c in x.dict().iteritems():
w[n] = R(c)
# The following line has been added in trac ticket #9944.
# Apparently, the "else" case has never occured before.
x = w
elif isinstance(x, list):
y = {}
for i in xrange(len(x)):
if x[i] != 0:
y[i] = x[i]
x = y
elif isinstance(x, pari_gen):
y = {}
for i in range(len(x)):
y[i] = R(x[i])
x = y
check = True
elif not isinstance(x, dict):
x = {0:x} # constant polynomials
if check:
self.__coeffs = {}
for i, z in x.iteritems():
self.__coeffs[i] = R(z)
else:
self.__coeffs = x
if check:
self.__normalize()
示例3: __init__
# 需要导入模块: from sage.rings.polynomial.polynomial_element import Polynomial [as 别名]
# 或者: from sage.rings.polynomial.polynomial_element.Polynomial import __init__ [as 别名]
def __init__(self, parent, x=None, check=True, is_gen=False, construct = False, absprec = infinity, relprec = infinity):
"""
TESTS:
sage: K = Qp(13,7)
sage: R.<t> = K[]
sage: R([K(13), K(1)])
(1 + O(13^7))*t + (13 + O(13^8))
sage: T.<t> = ZZ[]
sage: R(t + 2)
(1 + O(13^7))*t + (2 + O(13^7))
"""
Polynomial.__init__(self, parent, is_gen=is_gen)
parentbr = parent.base_ring()
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
if construct:
(self._poly, self._valbase, self._relprecs, self._normalized, self._valaddeds, self._list) = x #the last two of these may be None
return
elif is_gen:
self._poly = PolynomialRing(ZZ, parent.variable_name()).gen()
self._valbase = 0
self._valaddeds = [infinity, 0]
self._relprecs = [infinity, parentbr.precision_cap()]
self._normalized = True
self._list = None
return
#First we list the types that are turned into Polynomials
if isinstance(x, ZZX):
x = Polynomial_integer_dense(PolynomialRing(ZZ, parent.variable_name()), x, construct = True)
elif isinstance(x, fraction_field_element.FractionFieldElement) and \
x.denominator() == 1:
#Currently we ignore precision information in the denominator. This should be changed eventually
x = x.numerator()
#We now coerce various types into lists of coefficients. There are fast pathways for some types of polynomials
if isinstance(x, Polynomial):
if x.parent() is self.parent():
if not absprec is infinity or not relprec is infinity:
x._normalize()
self._poly = x._poly
self._valbase = x._valbase
self._valaddeds = x._valaddeds
self._relprecs = x._relprecs
self._normalized = x._normalized
self._list = x._list
if not absprec is infinity or not relprec is infinity:
self._adjust_prec_info(absprec, relprec)
return
elif x.base_ring() is ZZ:
self._poly = x
self._valbase = Integer(0)
p = parentbr.prime()
self._relprecs = [c.valuation(p) + parentbr.precision_cap() for c in x.list()]
self._comp_valaddeds()
self._normalized = len(self._valaddeds) == 0 or (min(self._valaddeds) == 0)
self._list = None
if not absprec is infinity or not relprec is infinity:
self._adjust_prec_info(absprec, relprec)
return
else:
x = [parentbr(a) for a in x.list()]
check = False
elif isinstance(x, dict):
zero = parentbr.zero_element()
n = max(x.keys())
v = [zero for _ in xrange(n + 1)]
for i, z in x.iteritems():
v[i] = z
x = v
elif isinstance(x, pari_gen):
x = [parentbr(w) for w in x.list()]
check = False
#The default behavior if we haven't already figured out what the type is is to assume it coerces into the base_ring as a constant polynomial
elif not isinstance(x, list):
x = [x] # constant polynomial
# In contrast to other polynomials, the zero element is not distinguished
# by having its list empty. Instead, it has list [0]
if not x:
x = [parentbr.zero_element()]
if check:
x = [parentbr(z) for z in x]
# Remove this -- for p-adics this is terrible, since it kills any non exact zero.
#if len(x) == 1 and not x[0]:
# x = []
self._list = x
self._valaddeds = [a.valuation() for a in x]
self._valbase = sage.rings.padics.misc.min(self._valaddeds)
if self._valbase is infinity:
self._valaddeds = []
self._relprecs = []
self._poly = PolynomialRing(ZZ, parent.variable_name())()
self._normalized = True
if not absprec is infinity or not relprec is infinity:
self._adjust_prec_info(absprec, relprec)
else:
self._valaddeds = [c - self._valbase for c in self._valaddeds]
self._relprecs = [a.precision_absolute() - self._valbase for a in x]
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from sage.rings.polynomial.polynomial_element import Polynomial [as 别名]
# 或者: from sage.rings.polynomial.polynomial_element.Polynomial import __init__ [as 别名]
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False):
Polynomial.__init__(self, parent, is_gen, construct)