Skip to content

Commit 05d9cda

Browse files
author
Matthias Koeppe
committed
Move _test_subs to superclass MPolynomial
1 parent 6b20467 commit 05d9cda

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

src/sage/rings/polynomial/multi_polynomial.pyx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,43 @@ cdef class MPolynomial(CommutativeRingElement):
25752575
d = self.dict()
25762576
return all(c.is_nilpotent() for c in d.values())
25772577

2578+
def _test_subs(self, tester=None, **options):
2579+
r"""
2580+
Run some tests using the ``subs`` method.
2581+
2582+
TESTS::
2583+
2584+
sage: R.<x,y> = QQbar[]
2585+
sage: (x + y)._test_subs()
2586+
"""
2587+
if tester is None:
2588+
tester = self._tester(**options)
2589+
2590+
gens = self.parent().gens()
2591+
2592+
if gens:
2593+
# substituting all variables (in a polynomial ring with variables) with 0
2594+
d = {str(gen): 0 for gen in gens}
2595+
tester.assertEqual(self.subs(**d).parent(), self.parent().base_ring())
2596+
2597+
# substituting all variables (in a polynomial ring with variables)
2598+
# with elements of another ring
2599+
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
2600+
other = PolynomialRing(self.parent().base_ring(), 'other', len(gens))
2601+
other_gens = other.gens()
2602+
d = {str(gen): other_gen for gen, other_gen in zip(gens, other_gens)}
2603+
tester.assertEqual(self.subs(**d).parent(), other)
2604+
2605+
if len(gens) > 1:
2606+
# substituting one variable (in a polynomial ring with variables) with 0
2607+
d = {str(gens[0]): 0}
2608+
tester.assertEqual(self.subs(**d).parent(), self.parent())
2609+
2610+
# test error checking: partial substitution by elements
2611+
# from another ring is not allowed
2612+
d = {str(gens[0]): other_gens[0]}
2613+
with tester.assertRaises((ValueError, TypeError)):
2614+
self.subs(**d)
25782615

25792616
cdef remove_from_tuple(e, int ind):
25802617
w = list(e)

src/sage/rings/polynomial/multi_polynomial_element.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -379,44 +379,6 @@ def change_ring(self, R):
379379
else:
380380
return self.parent().change_ring(R)(self)
381381

382-
def _test_subs(self, tester=None, **options):
383-
r"""
384-
Run some tests using the ``subs`` method.
385-
386-
TESTS::
387-
388-
sage: R.<x,y> = QQbar[]
389-
sage: (x + y)._test_subs()
390-
"""
391-
if tester is None:
392-
tester = self._tester(**options)
393-
394-
gens = self.parent().gens()
395-
396-
if gens:
397-
# substituting all variables (in a polynomial ring with variables) with 0
398-
d = {str(gen): 0 for gen in gens}
399-
tester.assertEqual(self.subs(**d).parent(), self.parent().base_ring())
400-
401-
# substituting all variables (in a polynomial ring with variables)
402-
# with elements of another ring
403-
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
404-
other = PolynomialRing(self.parent().base_ring(), 'other', len(gens))
405-
other_gens = other.gens()
406-
d = {str(gen): other_gen for gen, other_gen in zip(gens, other_gens)}
407-
tester.assertEqual(self.subs(**d).parent(), other)
408-
409-
if len(gens) > 1:
410-
# substituting one variable (in a polynomial ring with variables) with 0
411-
d = {str(gens[0]): 0}
412-
tester.assertEqual(self.subs(**d).parent(), self.parent())
413-
414-
# test error checking: partial substitution by elements
415-
# from another ring is not allowed
416-
d = {str(gens[0]): other_gens[0]}
417-
with tester.assertRaises((ValueError, TypeError)):
418-
self.subs(**d)
419-
420382

421383
class MPolynomial_polydict(Polynomial_singular_repr, MPolynomial_element):
422384
r"""

0 commit comments

Comments
 (0)