@@ -28,6 +28,9 @@ AUTHORS:
28
28
29
29
- David Zureick-Brown (2017-09): Added is_weil_polynomial.
30
30
31
+ - Sebastian Oehms (2018-10): made :meth:`roots` and :meth:`factor` work over more
32
+ cases of proper integral domains (see :trac:`26421`)
33
+
31
34
TESTS::
32
35
33
36
sage: R.<x> = ZZ[]
@@ -4195,6 +4198,14 @@ cdef class Polynomial(CommutativeAlgebraElement):
4195
4198
sage: x2 = ZZ['x' ]['x' ]. gen( )
4196
4199
sage: ( x1 - x2) . factor( )
4197
4200
-x + x
4201
+
4202
+ Check that :trac:`26421' is fixed::
4203
+
4204
+ sage: R. <t> = LaurentPolynomialRing( ZZ)
4205
+ sage: P. <x> = R[]
4206
+ sage: p = x** 3 -( t** 3+ t** ( -3)) * x** 2 -t** 2* x + ~t + t** 5
4207
+ sage: p. factor( )
4208
+ ( t^ -3) * ( t^ 3* x - 1 - t^ 6) * ( x - t) * ( x + t)
4198
4209
"""
4199
4210
# PERFORMANCE NOTE:
4200
4211
# In many tests with SMALL degree PARI is substantially
@@ -4341,6 +4352,16 @@ cdef class Polynomial(CommutativeAlgebraElement):
4341
4352
F.sort()
4342
4353
return F
4343
4354
except (TypeError , AttributeError ):
4355
+ if R.is_integral_domain() and not R.is_field():
4356
+ from sage.rings.fraction_field import FractionField_generic
4357
+ try :
4358
+ F = FractionField_generic(R)
4359
+ PF = F[self .variable_name()]
4360
+ pol_frac = PF(self )
4361
+ return pol_frac.factor(** kwargs).base_change(self .parent())
4362
+ except :
4363
+ pass
4364
+
4344
4365
raise NotImplementedError
4345
4366
4346
4367
return self ._factor_pari_helper(G, n)
@@ -7605,9 +7626,19 @@ cdef class Polynomial(CommutativeAlgebraElement):
7605
7626
sage: eq = x^6+x-17
7606
7627
sage: eq.roots(multiplicities=False)
7607
7628
[3109038, 17207405]
7629
+
7630
+ Check that :trac:`26421' is fixed::
7631
+
7632
+ sage: R.<t> = LaurentPolynomialRing(ZZ)
7633
+ sage: P.<x> = R[]
7634
+ sage: p = x**3 -(t**3+t**(-3))*x**2 -t**2*x + ~t +t**5
7635
+ sage: p.roots()
7636
+ [(t^-3 + t^3, 1), (t, 1), (-t, 1)]
7608
7637
"""
7609
7638
from sage.rings.finite_rings.finite_field_constructor import GF
7610
7639
K = self ._parent.base_ring()
7640
+
7641
+
7611
7642
# If the base ring has a method _roots_univariate_polynomial,
7612
7643
# try to use it. An exception is raised if the method does not
7613
7644
# handle the current parameters
@@ -7818,10 +7849,14 @@ cdef class Polynomial(CommutativeAlgebraElement):
7818
7849
# get rid of the content of self since we don't need it
7819
7850
# and we really don't want to factor it if it's a huge
7820
7851
# integer
7821
- c = self .content ()
7852
+ c = self .content_ideal().gen ()
7822
7853
self = self // c
7823
- except AttributeError :
7824
- pass
7854
+ except (AttributeError , NotImplementedError ):
7855
+ try :
7856
+ c = lcm(self .coefficients())
7857
+ self = self / c
7858
+ except :
7859
+ pass
7825
7860
return self ._roots_from_factorization(self .factor(), multiplicities)
7826
7861
else :
7827
7862
raise NotImplementedError
@@ -9076,7 +9111,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
9076
9111
# Be careful with the content: return the
9077
9112
# radical of the content times the radical of
9078
9113
# (self/content)
9079
- content = self .content ()
9114
+ content = self .content_ideal().gen ()
9080
9115
self_1 = (self // content)
9081
9116
return (self_1 // self_1.gcd(self_1.derivative())) * content.radical()
9082
9117
else : # The above method is not always correct (see Trac 8736)
@@ -10156,6 +10191,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
10156
10191
phi = SpecializationMorphism(self ._parent,D)
10157
10192
return phi(self )
10158
10193
10194
+
10159
10195
def _log_series (self , long n ):
10160
10196
r """
10161
10197
Return the power series expansion of logarithm of this polynomial,
0 commit comments