Ticket #8972: 8972_elliptic_doctest_fix.patch

File 8972_elliptic_doctest_fix.patch, 10.3 KB (added by Simon King, 13 years ago)

Fixing some remaining bugs of Laurent/power series arithmetic; fixing doc tests on elliptic curves.

  • sage/modular/modform/find_generators.py

    # HG changeset patch
    # User Simon King <simon.king@nuigalway.ie>
    # Date 1275934215 -3600
    # Node ID 556649e632322a8e97eaf43c62a7d7a8e35f0a35
    # Parent  fe244f94ad954fe5a32785ec8f2c20d4434c17f8
    Fixing some remaining bugs of Laurent/power series arithmetic; fixing doc tests on elliptic curves.
    
    diff -r fe244f94ad95 -r 556649e63232 sage/modular/modform/find_generators.py
    a b  
    113113       
    114114    K = v[0].parent().base_ring()
    115115    V = K**n
    116     B = [V(g.padded_list(n)) for g in v]
     116    B = [V(g.padded_list(n) if hasattr(g,'padded_list') else g.power_series().padded_list(n)) for g in v]
    117117    if basis:
    118118        M = V.span_of_basis(B)
    119119    else:
  • sage/rings/laurent_series_ring_element.pyx

    diff -r fe244f94ad95 -r 556649e63232 sage/rings/laurent_series_ring_element.pyx
    a b  
    423423        """
    424424        return iter(self.__u)
    425425
    426        
     426    def exp(self):
     427        """
     428        Return the exponential of ``self``.
     429
     430        ASSUMPTION:
     431
     432        ``self`` must in fact be a power series
     433        (non-negative valuation).
     434
     435        EXAMPLES::
     436
     437            sage: R.<t> = ZZ[[]]
     438            sage: p = t/(2+t)
     439            sage: p.exp()
     440            1 + 1/2*t - 1/8*t^2 + 1/48*t^3 + 1/384*t^4 - 19/3840*t^5 + 151/46080*t^6 - 1091/645120*t^7 + 7841/10321920*t^8 - 56519/185794560*t^9 + 396271/3715891200*t^10 - 2442439/81749606400*t^11 + 7701409/1961990553600*t^12 + 145269541/51011754393600*t^13 - 4833158329/1428329123020800*t^14 + 104056218421/42849873690624000*t^15 - 2002667085119/1371195958099968000*t^16 + 37109187217649/46620662575398912000*t^17 - 679877731030049/1678343852714360832000*t^18 + 12440309297451121/63777066403145711616000*t^19 + O(t^20)
     441            sage: q = 2/(2*t+t^3)
     442            sage: q.exp()
     443            Traceback (most recent call last):
     444            ...
     445            ArithmeticError: self is a not a power series
     446
     447        """
     448        return self.parent()(self.power_series().exp())
     449
    427450    def list(self):
    428451        """
    429452        EXAMPLES::
     
    611634
    612635    def add_bigoh(self, prec):
    613636        """
     637        Add ``O(t^prec)`` to ``self``.
     638
     639        INPUT:
     640
     641        prec -- integer, the precision to obtain
     642
    614643        EXAMPLES::
    615644       
    616645            sage: R.<t> = LaurentSeriesRing(QQ)
     
    618647            t^2 + t^3 + O(t^10)
    619648            sage: f.add_bigoh(5)
    620649            t^2 + t^3 + O(t^5)
     650
     651        TEST:
     652
     653            sage: P = QQ['t']
     654            sage: p = P('2+t^3+4*t^15')
     655            sage: p + O(t^10)     # indirect doctest
     656            2 + t^3 + O(t^10)
    621657        """
    622658        if prec == infinity or prec >= self.prec():
    623659            return self
    624         u = self.__u.add_bigoh(prec - self.__n)
     660        try:
     661            u = self.__u.add_bigoh(prec - self.__n)
     662        except AttributeError: # perhaps self.__u is just a polynomial
     663            u = self.power_series().add_bigoh(prec - self.__n)
    625664        return LaurentSeries(self._parent, u, self.__n,check=False)
    626665
    627666    def degree(self):
     
    685724        return self
    686725                             
    687726    cpdef ModuleElement _rmul_(self, RingElement c):
    688         return LaurentSeries(self._parent, self.__u._rmul_(c), self.__n)
     727        # This is incorrect, since self.__u is not necessarily
     728        # an element of self.parent.power_series_ring() (though
     729        # there is a coercion). Hence, it is not safe to call
     730        # _rmul_ directly.
     731        #return LaurentSeries(self._parent, self.__u._rmul_(c), self.__n)
     732        return LaurentSeries(self._parent, self.__u*c, self.__n)
    689733                             
    690734    cpdef ModuleElement _lmul_(self, RingElement c):
    691         return LaurentSeries(self._parent, self.__u._lmul_(c), self.__n)
     735        #return LaurentSeries(self._parent, self.__u._lmul_(c), self.__n)
     736        return LaurentSeries(self._parent, c*self.__u, self.__n)
    692737                             
    693738    cpdef ModuleElement _ilmul_(self, RingElement c):
    694739        self.__u *= c
  • sage/rings/power_series_ring.py

    diff -r fe244f94ad95 -r 556649e63232 sage/rings/power_series_ring.py
    a b  
    433433        from sage.categories.pushout import CompletionFunctor
    434434        return CompletionFunctor(self._names[0], self.default_prec()),  self._poly_ring()
    435435
     436    def fraction_field(self):
     437        """
     438        Return the fraction field of this power series ring, which
     439        is the same as the Laurent series ring over the fraction
     440        field of the base ring of ``self``.
     441
     442        EXAMPLE::
     443
     444            sage: R.<x> = ZZ.quo(53)[[]]
     445            sage: FractionField(R)
     446            Laurent Series Ring in x over Ring of integers modulo 53
     447            sage: 1/x in FractionField(R)
     448            True
     449        """
     450        from sage.all import LaurentSeriesRing
     451        return LaurentSeriesRing(self.base().fraction_field(),self.variable_names())
     452
    436453    def _coerce_impl(self, x):
    437454        """
    438455        Return canonical coercion of x into self.
  • sage/rings/power_series_ring_element.pyx

    diff -r fe244f94ad95 -r 556649e63232 sage/rings/power_series_ring_element.pyx
    a b  
    886886            try:
    887887                u = ~(self>>v)    # inverse of unit part
    888888            except:
    889                 u = ~((self>>v)*self._parent.base().fraction_field())
    890             R = self._parent.fraction_field()#_parent.laurent_series_ring()
     889                u = ~((self>>v)*self._parent.base().fraction_field()(1))
     890            try:
     891                R = self._parent.fraction_field()
     892            except TypeError: # no integral domain
     893                R = self._parent.laurent_series_ring()
    891894            from sage.all import LaurentSeries
    892895            return LaurentSeries(R,u,-v,check=False)# R(u, -self.valuation())
    893896
     
    10051008
    10061009        TEST:
    10071010
    1008         The following tests against a bug that was fixed in
     1011        The following tests against bugs that were fixed in
    10091012        ticket #8972::
    10101013
    10111014            sage: P.<t> = ZZ[]
    10121015            sage: R.<x> = P[[]]
    10131016            sage: 1/(t*x)
    10141017            1/t*x^-1
     1018            sage: R.<t> = PowerSeriesRing(ZZ.quo(15))
     1019            sage: t/(1+t)
     1020            t + 14*t^2 + t^3 + 14*t^4 + t^5 + 14*t^6 + t^7 + 14*t^8 + t^9 + 14*t^10 + t^11 + 14*t^12 + t^13 + 14*t^14 + t^15 + 14*t^16 + t^17 + 14*t^18 + t^19 + 14*t^20 + O(t^21)
     1021            sage: t/(3+t)
     1022            Traceback (most recent call last):
     1023            ...
     1024            ZeroDivisionError: Inverse does not exist.
    10151025
    10161026        """
    1017         F = self._parent.fraction_field()
    10181027        denom = <PowerSeries>denom_r
    10191028        if denom.is_zero():
    10201029            raise ZeroDivisionError, "Can't divide by something indistinguishable from 0"
     1030        try:
     1031            F = self._parent.fraction_field()
     1032        except:
     1033            # Inverses may not always exist. So, we try,
     1034            # and if the result exists, it will be in the
     1035            # parent of self.
     1036            return self* ~denom
    10211037        # Algorithm: Cancel common factors of q from top and bottom,
    10221038        # then invert the denominator.  We do the cancellation first
    10231039        # because we can only invert a unit (and remain in the ring
  • sage/schemes/elliptic_curves/ell_wp.py

    diff -r fe244f94ad95 -r 556649e63232 sage/schemes/elliptic_curves/ell_wp.py
    a b  
    321321        True
    322322
    323323    """
    324     a_recip = 1/a
     324    a_recip = ~a # 1/a
    325325    B =  b * a_recip
    326326    C =  c * a_recip
    327327    int_B = B.integral()
    328328    J = int_B.exp()
    329     J_recip = 1/J
     329    J_recip = ~J # 1/J
    330330    CJ = C * J
    331331    int_CJ = CJ.integral()
    332332    f =  J_recip * (alpha + int_CJ)
  • sage/schemes/elliptic_curves/formal_group.py

    diff -r fe244f94ad95 -r 556649e63232 sage/schemes/elliptic_curves/formal_group.py
    a b  
    300300            return y + O(t**prec)
    301301        w = self.w(prec+6) # XXX why 6?
    302302        t = w.parent().gen()
    303         y = -(w**(-1)) + O(t**prec)
     303        y = O(t**prec) - (~w)
     304        #y = -(w**(-1)) + O(t**prec)
    304305        self.__y = (prec, y)
    305306        return self.__y[1]
    306307
  • sage/schemes/elliptic_curves/padics.py

    diff -r fe244f94ad95 -r 556649e63232 sage/schemes/elliptic_curves/padics.py
    a b  
    15621562        ...         g = [R.random_element() for i in range(N)]
    15631563        ...         g[0] = R(1)
    15641564        ...         g = Rx(g, len(g))
    1565         ...         f = g.derivative() / g
     1565        ...         f = g.derivative() * ~g
    15661566        ...         # perturb f by something whose integral is in I
    15671567        ...         err = [R.random_element() * p**(N-i) for i in range(N+1)]
    15681568        ...         err = Rx(err, len(err))
     
    15901590        G = Rx(G.list(), s)
    15911591       
    15921592        # extend current approximation to be correct to s terms
    1593         H = G.derivative() / G - F
     1593        H = G.derivative() * ~G - F# / G - F
    15941594        # Do the integral of H over QQ[x] to avoid division by p problems
    15951595        H = Rx(Qx(H).integral())
    15961596        G = G * (1 - H)
  • sage/structure/element.pyx

    diff -r fe244f94ad95 -r 556649e63232 sage/structure/element.pyx
    a b  
    15371537                raise ZeroDivisionError, "Cannot divide by zero"
    15381538            else:
    15391539                raise TypeError, arith_error_message(self, right, div)
     1540        except TypeError:
     1541            try:
     1542                if self._parent.fraction_field() is not self._parent:
     1543                    return self._parent.fraction_field()(self)/self._parent.fraction_field()(right)
     1544                else:
     1545                    raise RuntimeError
     1546            except:
     1547                if not right:
     1548                    raise ZeroDivisionError, "Cannot divide by zero"
     1549                else:
     1550                    raise TypeError, arith_error_message(self, right, div)
     1551
    15401552
    15411553    def __idiv__(self, right):
    15421554        """