# Ticket #7711: trac7711.patch

File trac7711.patch, 5.1 KB (added by AlexGhitza, 10 years ago)
• ## sage/rings/polynomial/multi_polynomial_element.py

```# HG changeset patch
# User Alexandru Ghitza <aghitza@alum.mit.edu>
# Date 1332630992 -39600
# Node ID 384f334d345f31200d7cf3106dca4d82824a20eb
# Parent  66e568c3d082ee389659bd257efa500e5a8e5955
Trac 7711: fix field of coefficients for integral of a polynomial

diff --git a/sage/rings/polynomial/multi_polynomial_element.py b/sage/rings/polynomial/multi_polynomial_element.py```
 a sage: f = (x + y)/x; f (x + y)/x sage: f.parent() Fraction Field of Multivariate Polynomial Ring in x, y over Complex Field with 53 bits of precision Fraction Field of Multivariate Polynomial Ring in x, y over Complex Field with 53 bits of precision If dividing by a scalar, there is no need to go to the fraction field of the polynomial ring:: sage: f = (x + y)/2; f 0.500000000000000*x + 0.500000000000000*y sage: f.parent() Multivariate Polynomial Ring in x, y over Complex Field with 53 bits of precision """ if right in self.base_ring(): inv = 1/self.base_ring()(right) return inv*self return self.parent().fraction_field()(self, right, coerce=False) def __rpow__(self, n):
• ## sage/rings/polynomial/polynomial_element.pyx

`diff --git a/sage/rings/polynomial/polynomial_element.pyx b/sage/rings/polynomial/polynomial_element.pyx`
 a sage: f = R(2).integral(); f 2*x Note that since the integral is defined over the same base ring the integral is actually in the base ring. :: Note that the integral lives over the fraction field of the scalar coefficients:: sage: f.parent() Univariate Polynomial Ring in x over Integer Ring If the integral isn't defined over the same base ring, then the base ring is extended:: Univariate Polynomial Ring in x over Rational Field sage: R(0).integral().parent() Univariate Polynomial Ring in x over Rational Field sage: f = x^3 + x - 2 sage: g = f.integral(); g 1/4*x^4 + 1/2*x^2 - 2*x sage: g.parent() Univariate Polynomial Ring in x over Rational Field This shows that the issue at trac #7711 is resolved:: sage: P. = PolynomialRing(GF(2147483647)) sage: Q. = PolynomialRing(P) sage: p=x+y+z sage: p.integral() -1073741823*y^2 + (x + z)*y sage: P. = PolynomialRing(GF(next_prime(2147483647))) sage: Q. = PolynomialRing(P) sage: p=x+y+z sage: p.integral() 1073741830*y^2 + (x + z)*y A truly convoluted example:: sage: A. = PolynomialRing(ZZ) sage: B. = PolynomialRing(A) sage: C. = PowerSeriesRing(B) sage: R. = PolynomialRing(C) sage: f = a2*x^2 + c*x - a1*b sage: f.parent() Univariate Polynomial Ring in x over Power Series Ring in c over Univariate Polynomial Ring in b over Multivariate Polynomial Ring in a1, a2 over Integer Ring sage: f.integral() 1/3*a2*x^3 + 1/2*c*x^2 - a1*b*x sage: f.integral().parent() Univariate Polynomial Ring in x over Power Series Ring in c over Univariate Polynomial Ring in b over Multivariate Polynomial Ring in a1, a2 over Rational Field sage: g = 3*a2*x^2 + 2*c*x - a1*b sage: g.integral() a2*x^3 + c*x^2 - a1*b*x sage: g.integral().parent() Univariate Polynomial Ring in x over Power Series Ring in c over Univariate Polynomial Ring in b over Multivariate Polynomial Ring in a1, a2 over Rational Field """ cdef Py_ssize_t n, degree = self.degree() if degree < 0: return self.parent().zero_element() R = self.parent() Q = (self.constant_coefficient()/1).parent() coeffs = self.list() v = [0, coeffs] + [coeffs[n]/(n+1) for n from 1 <= n <= degree] try: return self._parent(v) except TypeError: R = self.parent() try: S = R.change_ring(R.base_ring().fraction_field()) return S(v) except (TypeError, AttributeError): raise ArithmeticError("coefficients of integral cannot be coerced into the base ring or its fraction field") v =  + [coeffs[n]/(n+1) for n from 0 <= n <= degree] S = R.change_ring(Q) return S(v) def dict(self): """ Return a sparse dictionary representation of this univariate