Ticket #7711: trac7711.patch
File trac7711.patch, 5.1 KB (added by , 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 b 267 267 sage: f = (x + y)/x; f 268 268 (x + y)/x 269 269 sage: f.parent() 270 Fraction Field of Multivariate Polynomial Ring in x, y over Complex Field with 53 bits of precision 270 Fraction Field of Multivariate Polynomial Ring in x, y over 271 Complex Field with 53 bits of precision 272 273 If dividing by a scalar, there is no need to go to the fraction 274 field of the polynomial ring:: 275 276 sage: f = (x + y)/2; f 277 0.500000000000000*x + 0.500000000000000*y 278 sage: f.parent() 279 Multivariate Polynomial Ring in x, y over Complex Field with 280 53 bits of precision 271 281 """ 282 if right in self.base_ring(): 283 inv = 1/self.base_ring()(right) 284 return inv*self 272 285 return self.parent().fraction_field()(self, right, coerce=False) 273 286 274 287 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 b 2369 2369 sage: f = R(2).integral(); f 2370 2370 2*x 2371 2371 2372 Note that since the integral is defined over the same base ring the 2373 integral is actually in the base ring. 2374 2375 :: 2372 Note that the integral lives over the fraction field of the 2373 scalar coefficients:: 2376 2374 2377 2375 sage: f.parent() 2378 Univariate Polynomial Ring in x over Integer Ring 2379 2380 If the integral isn't defined over the same base ring, then the 2381 base ring is extended:: 2376 Univariate Polynomial Ring in x over Rational Field 2377 sage: R(0).integral().parent() 2378 Univariate Polynomial Ring in x over Rational Field 2382 2379 2383 2380 sage: f = x^3 + x - 2 2384 2381 sage: g = f.integral(); g 2385 2382 1/4*x^4 + 1/2*x^2 - 2*x 2386 2383 sage: g.parent() 2387 2384 Univariate Polynomial Ring in x over Rational Field 2385 2386 This shows that the issue at trac #7711 is resolved:: 2387 2388 sage: P.<x,z> = PolynomialRing(GF(2147483647)) 2389 sage: Q.<y> = PolynomialRing(P) 2390 sage: p=x+y+z 2391 sage: p.integral() 2392 -1073741823*y^2 + (x + z)*y 2393 2394 sage: P.<x,z> = PolynomialRing(GF(next_prime(2147483647))) 2395 sage: Q.<y> = PolynomialRing(P) 2396 sage: p=x+y+z 2397 sage: p.integral() 2398 1073741830*y^2 + (x + z)*y 2399 2400 A truly convoluted example:: 2401 2402 sage: A.<a1, a2> = PolynomialRing(ZZ) 2403 sage: B.<b> = PolynomialRing(A) 2404 sage: C.<c> = PowerSeriesRing(B) 2405 sage: R.<x> = PolynomialRing(C) 2406 sage: f = a2*x^2 + c*x - a1*b 2407 sage: f.parent() 2408 Univariate Polynomial Ring in x over Power Series Ring in c 2409 over Univariate Polynomial Ring in b over Multivariate Polynomial 2410 Ring in a1, a2 over Integer Ring 2411 sage: f.integral() 2412 1/3*a2*x^3 + 1/2*c*x^2 - a1*b*x 2413 sage: f.integral().parent() 2414 Univariate Polynomial Ring in x over Power Series Ring in c 2415 over Univariate Polynomial Ring in b over Multivariate Polynomial 2416 Ring in a1, a2 over Rational Field 2417 sage: g = 3*a2*x^2 + 2*c*x - a1*b 2418 sage: g.integral() 2419 a2*x^3 + c*x^2 - a1*b*x 2420 sage: g.integral().parent() 2421 Univariate Polynomial Ring in x over Power Series Ring in c 2422 over Univariate Polynomial Ring in b over Multivariate Polynomial 2423 Ring in a1, a2 over Rational Field 2388 2424 """ 2389 2425 cdef Py_ssize_t n, degree = self.degree() 2390 if degree < 0: 2391 return self.parent().zero_element() 2392 2426 R = self.parent() 2427 Q = (self.constant_coefficient()/1).parent() 2393 2428 coeffs = self.list() 2394 v = [0, coeffs[0]] + [coeffs[n]/(n+1) for n from 1 <= n <= degree] 2395 try: 2396 return self._parent(v) 2397 except TypeError: 2398 R = self.parent() 2399 try: 2400 S = R.change_ring(R.base_ring().fraction_field()) 2401 return S(v) 2402 except (TypeError, AttributeError): 2403 raise ArithmeticError("coefficients of integral cannot be coerced into the base ring or its fraction field") 2404 2405 2429 v = [0] + [coeffs[n]/(n+1) for n from 0 <= n <= degree] 2430 S = R.change_ring(Q) 2431 return S(v) 2432 2406 2433 def dict(self): 2407 2434 """ 2408 2435 Return a sparse dictionary representation of this univariate