Ticket #11780: trac11780_unique_auxiliar_polyring.patch

File trac11780_unique_auxiliar_polyring.patch, 3.8 KB (added by SimonKing, 11 years ago)

Avoid the creation of a non-unique auxiliary polynomial ring in singular_ring_new and in MPolynomial_libsingular.numerator

  • sage/libs/singular/ring.pyx

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1315242749 -7200
    # Node ID 6308b3e4469a5e9d7a0c20316bfe36428e7b145e
    # Parent  32c6b4a32e9bfefb47e9c66308e24206dbf50883
    #11780: Do not create a non-unique auxiliary polynomial ring in singular_ring_new and in numerator()
    
    diff --git a/sage/libs/singular/ring.pyx b/sage/libs/singular/ring.pyx
    a b  
    3535
    3636from sage.rings.polynomial.term_order import TermOrder
    3737from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular, MPolynomialRing_libsingular
     38from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    3839
    3940
    4041from sage.misc.misc_c import is_64_bit
     
    172173        else:
    173174            raise TypeError, "characteristic must be <= 2147483647."
    174175        # TODO: This is lazy, it should only call Singular stuff not MPolynomial stuff
    175         k = MPolynomialRing_libsingular(base_ring.prime_subfield(), 1, base_ring.variable_name(), 'lex')
     176        try:
     177            k = PolynomialRing(base_ring.prime_subfield(), 1, [base_ring.variable_name()], 'lex')
     178        except TypeError:
     179            raise TypeError, "The multivariate polynomial ring in a single variable %s in lex order over %s is supposed to be of type %s"%(base_ring.variable_name(), base_ring,MPolynomialRing_libsingular)
    176180        minpoly = base_ring.polynomial()(k.gen())
    177181        is_extension = True
    178182
    179183    elif PY_TYPE_CHECK(base_ring, NumberField) and base_ring.is_absolute():
    180184        characteristic = 1
    181         k = MPolynomialRing_libsingular(RationalField(), 1, base_ring.variable_name(), 'lex')
     185        try:
     186            k = PolynomialRing(RationalField(), 1, [base_ring.variable_name()], 'lex')
     187        except TypeError:
     188            raise TypeError, "The multivariate polynomial ring in a single variable %s in lex order over Rational Field is supposed to be of type %s"%(base_ring.variable_name(), MPolynomialRing_libsingular)
    182189        minpoly = base_ring.polynomial()(k.gen())
    183190        is_extension = True
    184191
  • sage/rings/polynomial/multi_polynomial_libsingular.pyx

    diff --git a/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/sage/rings/polynomial/multi_polynomial_libsingular.pyx
    a b  
    47814781            sage: f.numerator().base_ring()
    47824782            Integer Ring
    47834783   
    4784         We check that the computation the numerator and denominator
    4785         are valid
     4784        We check that the computation of numerator and denominator
     4785        is valid.
    47864786   
    47874787        ::
    47884788   
     
    47904790            sage: f=K.random_element()
    47914791            sage: f.numerator() / f.denominator() == f
    47924792            True
     4793
     4794        The following tests against a bug that has been fixed in trac ticket #11780::
     4795
     4796            sage: P.<foo,bar> = ZZ[]
     4797            sage: Q.<foo,bar> = QQ[]
     4798            sage: f = Q.random_element()
     4799            sage: f.numerator().parent() is P
     4800            True
    47934801        """
    47944802        if self.base_ring() == RationalField():
    47954803            #This part is for compatibility with the univariate case,
    47964804            #where the numerator of a polynomial over RationalField
    47974805            #is a polynomial over IntegerRing
    4798             integer_polynomial_ring = MPolynomialRing_libsingular(ZZ,\
     4806            #
     4807            # Trac ticket #11780: Create the polynomial ring over
     4808            # the integers using the (cached) polynomial ring constructor:
     4809            from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
     4810            integer_polynomial_ring = PolynomialRing(ZZ,\
    47994811            self.parent().ngens(), self.parent().gens(), order =\
    48004812            self.parent().term_order())
    48014813            return integer_polynomial_ring(self * self.denominator())