Ticket #13895: sage-trac_13895.patch

File sage-trac_13895.patch, 2.5 KB (added by mjo, 8 years ago)
  • sage/rings/polynomial/polynomial_modn_dense_ntl.pyx

    # HG changeset patch
    # User Michael Orlitzky <michael@orlitzky.com>
    # Date 1357062862 18000
    # Node ID 6600b298080b89da51f203b98b03efa2a21dbb87
    # Parent  5843a384f289819727f25fec93c5358fc73ee4a1
    Trac #13895: Fix ArithmeticError: 0^0 in sage/rings/polynomial/polynomial_modn_dense_ntl.pyx
    
    diff --git a/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx
    a b  
    825825            sage: R.<x> = Integers(101)[]
    826826            sage: (x-1)^(-5)
    827827            1/(x^5 + 96*x^4 + 10*x^3 + 91*x^2 + 5*x + 100)
     828
     829        We define ``0^0`` to be unity, :trac:`13895`::
     830
     831            sage: R.<x> = PolynomialRing(Integers(100), implementation='NTL')
     832            sage: R(0)^0
     833            1
     834
     835        The value returned from ``0^0`` should belong to our ring::
     836
     837            sage: R.<x> = PolynomialRing(Integers(100), implementation='NTL')
     838            sage: type(R(0)^0) == type(R(0))
     839            True
     840
    828841        """
    829842        cdef bint recip = 0, do_sig
    830843        cdef long e = ee
     
    833846        elif e < 0:
    834847            recip = 1
    835848            e = -e
    836         if not self:
    837             if e == 0:
    838                 raise ArithmeticError("0^0 is undefined.")
     849        if self == 0 and e == 0:
     850            return self.parent(1)
     851
    839852        cdef Polynomial_dense_modn_ntl_zz r = self._new()
    840853        cdef zz_pX_Modulus_c *mod
    841854
     
    13751388            sage: R.<x> = Integers(10^30)[]
    13761389            sage: (x+1)^5
    13771390            x^5 + 5*x^4 + 10*x^3 + 10*x^2 + 5*x + 1
     1391
     1392        We define ``0^0`` to be unity, :trac:`13895`::
     1393
     1394            sage: R.<x> = PolynomialRing(Integers(10^30), implementation='NTL')
     1395            sage: R(0)^0
     1396            1
     1397
     1398        The value returned from ``0^0`` should belong to our ring::
     1399
     1400            sage: R.<x> = PolynomialRing(Integers(10^30), implementation='NTL')
     1401            sage: type(R(0)^0) == type(R(0))
     1402            True
     1403
    13781404        """
    13791405        cdef bint recip = 0, do_sig
    13801406        cdef long e = ee
     
    13831409        elif e < 0:
    13841410            recip = 1 # delay because powering frac field elements is slow
    13851411            e = -e
    1386         if not self:
    1387             if e == 0:
    1388                 raise ArithmeticError("0^0 is undefined.")
     1412        if self == 0 and e == 0:
     1413            return self.parent(1)
    13891414        cdef Polynomial_dense_modn_ntl_ZZ r = self._new()
    13901415        cdef ZZ_pX_Modulus_c *mod
    13911416