@@ -959,6 +959,54 @@ def polynomial_root(self, poly, interval, multiplicity=1):
959
959
960
960
return AlgebraicReal (ANRoot (poly , interval , multiplicity ))
961
961
962
+ def _factor_univariate_polynomial (self , f ):
963
+ """
964
+ Factor the univariate polynomial ``f``.
965
+
966
+ INPUT:
967
+
968
+ - ``f`` -- a univariate polynomial defined over the real algebraic field
969
+
970
+ OUTPUT:
971
+
972
+ - A factorization of ``f`` over the real algebraic numbers into a unit
973
+ and monic irreducible factors
974
+
975
+ .. NOTE::
976
+
977
+ This is a helper method for
978
+ :meth:`sage.rings.polynomial.polynomial_element.Polynomial.factor`.
979
+
980
+ TESTS::
981
+
982
+ sage: R.<x> = AA[]
983
+ sage: AA._factor_univariate_polynomial(x)
984
+ x
985
+ sage: AA._factor_univariate_polynomial(2*x)
986
+ (2) * x
987
+ sage: AA._factor_univariate_polynomial((x^2 + 1)^2)
988
+ (x^2 + 1)^2
989
+ sage: AA._factor_univariate_polynomial(x^8 + 1)
990
+ (x^2 - 1.847759065022574?*x + 1.000000000000000?) * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 1.847759065022574?*x + 1.000000000000000?)
991
+ sage: AA._factor_univariate_polynomial(R(3))
992
+ 3
993
+ sage: AA._factor_univariate_polynomial(12*x^2 - 4)
994
+ (12) * (x - 0.5773502691896258?) * (x + 0.5773502691896258?)
995
+ sage: AA._factor_univariate_polynomial(12*x^2 + 4)
996
+ (12) * (x^2 + 0.3333333333333334?)
997
+ sage: AA._factor_univariate_polynomial(EllipticCurve('11a1').change_ring(AA).division_polynomial(5))
998
+ (5) * (x - 16.00000000000000?) * (x - 5.000000000000000?) * (x - 1.959674775249769?) * (x + 2.959674775249769?) * (x^2 - 2.854101966249685?*x + 15.47213595499958?) * (x^2 + 1.909830056250526?*x + 1.660606461254312?) * (x^2 + 3.854101966249685?*x + 6.527864045000421?) * (x^2 + 13.09016994374948?*x + 93.33939353874569?)
999
+
1000
+ """
1001
+ rr = f .roots ()
1002
+ cr = [(r ,e ) for r ,e in f .roots (QQbar ) if r .imag ()> 0 ]
1003
+
1004
+ from sage .structure .factorization import Factorization
1005
+ return Factorization (
1006
+ [(f .parent ()([- r ,1 ]),e ) for r ,e in rr ] +
1007
+ [(f .parent ()([r .norm (),- 2 * r .real (),1 ]),e ) for r ,e in cr ],
1008
+ unit = f .leading_coefficient ())
1009
+
962
1010
def is_AlgebraicRealField (F ):
963
1011
r"""
964
1012
Check whether ``F`` is an :class:`~AlgebraicRealField` instance. For internal use.
@@ -1355,6 +1403,46 @@ def random_element(self, poly_degree=2, *args, **kwds):
1355
1403
m = sage .misc .prandom .randint (0 , len (roots )- 1 )
1356
1404
return roots [m ]
1357
1405
1406
+ def _factor_univariate_polynomial (self , f ):
1407
+ """
1408
+ Factor the univariate polynomial ``f``.
1409
+
1410
+ INPUT:
1411
+
1412
+ - ``f`` -- a univariate polynomial defined over the algebraic field
1413
+
1414
+ OUTPUT:
1415
+
1416
+ - A factorization of ``f`` over the algebraic numbers into a unit and
1417
+ monic irreducible factors
1418
+
1419
+ .. NOTE::
1420
+
1421
+ This is a helper method for
1422
+ :meth:`sage.rings.polynomial.polynomial_element.Polynomial.factor`.
1423
+
1424
+ TESTS::
1425
+
1426
+ sage: R.<x> = QQbar[]
1427
+ sage: QQbar._factor_univariate_polynomial(x)
1428
+ x
1429
+ sage: QQbar._factor_univariate_polynomial(2*x)
1430
+ (2) * x
1431
+ sage: QQbar._factor_univariate_polynomial((x^2 + 1)^2)
1432
+ (x - I)^2 * (x + I)^2
1433
+ sage: QQbar._factor_univariate_polynomial(x^8 - 1)
1434
+ (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) * (x + 0.7071067811865475? - 0.7071067811865475?*I) * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1)
1435
+ sage: QQbar._factor_univariate_polynomial(12*x^2 - 4)
1436
+ (12) * (x - 0.5773502691896258?) * (x + 0.5773502691896258?)
1437
+ sage: QQbar._factor_univariate_polynomial(R(-1))
1438
+ -1
1439
+ sage: QQbar._factor_univariate_polynomial(EllipticCurve('11a1').change_ring(QQbar).division_polynomial(5))
1440
+ (5) * (x - 16) * (x - 5) * (x - 1.959674775249769?) * (x - 1.427050983124843? - 3.665468789467727?*I) * (x - 1.427050983124843? + 3.665468789467727?*I) * (x + 0.9549150281252629? - 0.8652998037182486?*I) * (x + 0.9549150281252629? + 0.8652998037182486?*I) * (x + 1.927050983124843? - 1.677599044300515?*I) * (x + 1.927050983124843? + 1.677599044300515?*I) * (x + 2.959674775249769?) * (x + 6.545084971874737? - 7.106423590645660?*I) * (x + 6.545084971874737? + 7.106423590645660?*I)
1441
+
1442
+ """
1443
+ from sage .structure .factorization import Factorization
1444
+ return Factorization ([(f .parent ()([- r ,1 ]),e ) for r ,e in f .roots ()], unit = f .leading_coefficient ())
1445
+
1358
1446
def is_AlgebraicField (F ):
1359
1447
r"""
1360
1448
Check whether ``F`` is an :class:`~AlgebraicField` instance.
0 commit comments