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


Python PolynomialRing._unsafe_mutate方法代码示例

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


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

示例1: Polynomial_padic_capped_relative_dense

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import _unsafe_mutate [as 别名]

#.........这里部分代码省略.........
        sage: R.<t> = K[]
        sage: a = t^2 + K(13,3)*t + 169; a
        (1 + O(13^4))*t^2 + (13 + O(13^3))*t + (13^2 + O(13^6))
        sage: b = a.rshift_coeffs(1); b
        (O(13^3))*t^2 + (1 + O(13^2))*t + (13 + O(13^5))
        sage: b.list()
        [13 + O(13^5), 1 + O(13^2), O(13^3)]
        sage: b = a.rshift_coeffs(2); b
        (O(13^2))*t^2 + (O(13))*t + (1 + O(13^4))
        sage: b.list()
        [1 + O(13^4), O(13), O(13^2)]
        """
        if shift < 0:
            return self.lshift_coeffs(-shift, no_list) # We can't just absorb this into the next if statement because we allow rshift to preserve _normalized
        if self.base_ring().is_field() or shift <= self._valbase:
            if no_list or self._list is None:
                return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase - shift, self._relprecs, self._normalized, self._valaddeds, None), construct = True)
            else:
                return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase - shift, self._relprecs, self._normalized, self._valaddeds, [c.__rshift__(shift) for c in self._list]), construct = True)
        else:
            shift = shift - self._valbase
            fdiv = self.base_ring().prime_pow(shift)
            return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly // fdiv, 0, [0 if a <= shift else a - shift for a in self._relprecs], False, None, None), construct = True)

    #def __floordiv__(self, right):
    #    if is_Polynomial(right) and right.is_constant() and right[0] in self.base_ring():
    #        d = self.base_ring()(right[0])
    #    elif (right in self.base_ring()):
    #        d = self.base_ring()(right)
    #    else:
    #        raise NotImplementedError
    #    return self._rmul_(self.base_ring()(~d.unit_part())).rshift_coeffs(d.valuation())

    def _unsafe_mutate(self, n, value):
        """
        It's a really bad idea to use this function for p-adic polynomials.  There are speed issues, and it may not be bug-free currently.
        """
        n = int(n)
        value = self.base_ring()(value)
        if self.is_gen():
            raise ValueError, "cannot modify generator"
        if n < 0:
            raise IndexError, "n must be >= 0"
        if self._valbase is infinity:
            if value._is_exact_zero():
                return
            self._valbase = value.valuation()
            if value != 0:
                self._poly._unsafe_mutate(self, n, value.unit_part().lift())
                self._relprecs = [infinity] * n + [value.precision_relative()]
            else:
                self._relprecs = [infinity] * n + [0]
            self._valaddeds = [infinity] * n + [0]
            zero = self.base_ring()(0)
            self._list = [zero] * n + [value]
            self._normalized = True
        elif value.valuation() >= self._valbase:
            # _valbase and _normalized stay the same
            if value != 0:
                self._poly._unsafe_mutate(self, n, (value.__rshift__(self._valbase)).lift())
            else:
                self._poly._unsafe_mutate(self, n, 0)
            if n < len(self._relprecs):
                self._relprecs[n] = value.precision_absolute() - self._valbase
                if not self._valaddeds is None:
                    self._valaddeds[n] = value.valuation() - self._valbase
开发者ID:chos9,项目名称:sage,代码行数:70,代码来源:polynomial_padic_capped_relative_dense.py

示例2: Polynomial_padic_capped_relative_dense

# 需要导入模块: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing [as 别名]
# 或者: from sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing import _unsafe_mutate [as 别名]

#.........这里部分代码省略.........
            sage: R.<t> = K[]
            sage: a = t^2 + K(13,3)*t + 169; a
            (1 + O(13^4))*t^2 + (13 + O(13^3))*t + (13^2 + O(13^6))
            sage: b = a.rshift_coeffs(1); b
            (O(13^3))*t^2 + (1 + O(13^2))*t + (13 + O(13^5))
            sage: b.list()
            [13 + O(13^5), 1 + O(13^2), O(13^3)]
            sage: b = a.rshift_coeffs(2); b
            (O(13^2))*t^2 + (O(13))*t + (1 + O(13^4))
            sage: b.list()
            [1 + O(13^4), O(13), O(13^2)]
        """
        if shift < 0:
            return self.lshift_coeffs(-shift, no_list) # We can't just absorb this into the next if statement because we allow rshift to preserve _normalized
        if self.base_ring().is_field() or shift <= self._valbase:
            if no_list or self._list is None:
                return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase - shift, self._relprecs, self._normalized, self._valaddeds, None), construct = True)
            else:
                return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase - shift, self._relprecs, self._normalized, self._valaddeds, [c.__rshift__(shift) for c in self._list]), construct = True)
        else:
            shift = shift - self._valbase
            fdiv = self.base_ring().prime_pow(shift)
            return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly // fdiv, 0, [0 if a <= shift else a - shift for a in self._relprecs], False, None, None), construct = True)

    #def __floordiv__(self, right):
    #    if is_Polynomial(right) and right.is_constant() and right[0] in self.base_ring():
    #        d = self.base_ring()(right[0])
    #    elif (right in self.base_ring()):
    #        d = self.base_ring()(right)
    #    else:
    #        raise NotImplementedError
    #    return self._rmul_(self.base_ring()(~d.unit_part())).rshift_coeffs(d.valuation())

    def _unsafe_mutate(self, n, value):
        """
        It's a really bad idea to use this function for p-adic polynomials.  There are speed issues, and it may not be bug-free currently.
        """
        n = int(n)
        value = self.base_ring()(value)
        if self.is_gen():
            raise ValueError("cannot modify generator")
        if n < 0:
            raise IndexError("n must be >= 0")
        if self._valbase is infinity:
            if value._is_exact_zero():
                return
            self._valbase = value.valuation()
            if value != 0:
                self._poly._unsafe_mutate(self, n, value.unit_part().lift())
                self._relprecs = [infinity] * n + [value.precision_relative()]
            else:
                self._relprecs = [infinity] * n + [0]
            self._valaddeds = [infinity] * n + [0]
            zero = self.base_ring()(0)
            self._list = [zero] * n + [value]
            self._normalized = True
        elif value.valuation() >= self._valbase:
            # _valbase and _normalized stay the same
            if value != 0:
                self._poly._unsafe_mutate(self, n, (value.__rshift__(self._valbase)).lift())
            else:
                self._poly._unsafe_mutate(self, n, 0)
            if n < len(self._relprecs):
                self._relprecs[n] = value.precision_absolute() - self._valbase
                if not self._valaddeds is None:
                    self._valaddeds[n] = value.valuation() - self._valbase
开发者ID:Findstat,项目名称:sage,代码行数:70,代码来源:polynomial_padic_capped_relative_dense.py


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