def __init__(self, parent, polynomial, check=True): """ Create an element of the quotient of a polynomial ring. INPUT: - ``parent`` - a quotient of a polynomial ring - ``polynomial`` - a polynomial - ``check`` - bool (optional): whether or not to verify that x is a valid element of the polynomial ring and reduced (mod the modulus). """ from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic from sage.rings.polynomial.polynomial_element import Polynomial CommutativeRingElement.__init__(self, parent) if check: if not isinstance(parent, PolynomialQuotientRing_generic): raise TypeError("parent must be a polynomial quotient ring") if not isinstance(polynomial, Polynomial): raise TypeError("polynomial must be a polynomial") if not polynomial in parent.polynomial_ring(): raise TypeError( "polynomial must be in the polynomial ring of the parent") f = parent.modulus() if polynomial.degree() >= f.degree() and polynomial.degree() >= 0: try: polynomial %= f except AttributeError: A = polynomial B = f R = A P = B.parent() Q = P(0) X = P.gen() while R.degree() >= B.degree(): S = P((R.leading_coefficient() / B.leading_coefficient() )) * X**(R.degree() - B.degree()) Q = Q + S R = R - S * B polynomial = R self._polynomial = polynomial
def __init__(self, parent, polynomial, check=True): """ Create an element of the quotient of a polynomial ring. INPUT: - ``parent`` - a quotient of a polynomial ring - ``polynomial`` - a polynomial - ``check`` - bool (optional): whether or not to verify that x is a valid element of the polynomial ring and reduced (mod the modulus). """ from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic from sage.rings.polynomial.polynomial_element import Polynomial CommutativeRingElement.__init__(self, parent) if check: if not isinstance(parent, PolynomialQuotientRing_generic): raise TypeError("parent must be a polynomial quotient ring") if not isinstance(polynomial, Polynomial): raise TypeError("polynomial must be a polynomial") if not polynomial in parent.polynomial_ring(): raise TypeError("polynomial must be in the polynomial ring of the parent") f = parent.modulus() if polynomial.degree() >= f.degree() and polynomial.degree() >= 0: try: polynomial %= f except AttributeError: A = polynomial B = f R = A P = B.parent() Q = P(0) X = P.gen() while R.degree() >= B.degree(): S = P((R.leading_coefficient()/B.leading_coefficient())) * X**(R.degree()-B.degree()) Q = Q + S R = R - S*B polynomial = R self._polynomial = polynomial