This repository was archived by the owner on Jan 30, 2023. It is now read-only.
File tree 1 file changed +42
-0
lines changed
src/sage/rings/polynomial
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -8496,6 +8496,48 @@ cdef class Polynomial(CommutativeAlgebraElement):
8496
8496
raise ValueError (" not a %s power" % m.ordinal_str())
8497
8497
8498
8498
8499
+ def divides (self , p ):
8500
+ r """
8501
+ Return `True` if this polynomial divides `p`.
8502
+
8503
+ EXAMPLES::
8504
+
8505
+ sage: R. <x> = ZZ[]
8506
+ sage: ( 2* x + 1) . divides( 4* x** 2 - 1)
8507
+ True
8508
+ sage: ( 2* x + 1) . divides( 4* x** 2 + 1)
8509
+ False
8510
+ sage: ( 2* x + 1) . divides( R( 0))
8511
+ True
8512
+ sage: R( 0) . divides( 2* x + 1)
8513
+ False
8514
+ sage: R( 0) . divides( R( 0))
8515
+ True
8516
+ sage: R. <x> = PolynomialRing( ZZ, implementation="NTL")
8517
+ sage: ( 2* x + 1) . divides( 4* x** 2 + 1)
8518
+ False
8519
+ """
8520
+ parent = self .parent()
8521
+ if p.parent() is parent:
8522
+ if p.is_zero(): return True # everything divides 0
8523
+ if self .is_zero(): return False # 0 only divides 0
8524
+ try :
8525
+ if self .is_unit(): return True # units divide everything
8526
+ except NotImplementedError :
8527
+ pass
8528
+ if self .is_one(): return True # if is_unit is not implemented
8529
+
8530
+ try :
8531
+ return (p % self ) == 0 # if quo_rem is defined
8532
+ except ArithmeticError :
8533
+ return False # if division is not exact
8534
+
8535
+ else :
8536
+ cm = sage.structure.element.get_coercion_model()
8537
+ a, b = cm.canonical_coercion(self , p)
8538
+ return a.divides(b)
8539
+
8540
+
8499
8541
# ----------------- inner functions -------------
8500
8542
# Cython can't handle function definitions inside other function
8501
8543
You can’t perform that action at this time.
0 commit comments