# 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
|
|
113 | 113 | |
114 | 114 | K = v[0].parent().base_ring() |
115 | 115 | 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] |
117 | 117 | if basis: |
118 | 118 | M = V.span_of_basis(B) |
119 | 119 | else: |
diff -r fe244f94ad95 -r 556649e63232 sage/rings/laurent_series_ring_element.pyx
a
|
b
|
|
423 | 423 | """ |
424 | 424 | return iter(self.__u) |
425 | 425 | |
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 | |
427 | 450 | def list(self): |
428 | 451 | """ |
429 | 452 | EXAMPLES:: |
… |
… |
|
611 | 634 | |
612 | 635 | def add_bigoh(self, prec): |
613 | 636 | """ |
| 637 | Add ``O(t^prec)`` to ``self``. |
| 638 | |
| 639 | INPUT: |
| 640 | |
| 641 | prec -- integer, the precision to obtain |
| 642 | |
614 | 643 | EXAMPLES:: |
615 | 644 | |
616 | 645 | sage: R.<t> = LaurentSeriesRing(QQ) |
… |
… |
|
618 | 647 | t^2 + t^3 + O(t^10) |
619 | 648 | sage: f.add_bigoh(5) |
620 | 649 | 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) |
621 | 657 | """ |
622 | 658 | if prec == infinity or prec >= self.prec(): |
623 | 659 | 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) |
625 | 664 | return LaurentSeries(self._parent, u, self.__n,check=False) |
626 | 665 | |
627 | 666 | def degree(self): |
… |
… |
|
685 | 724 | return self |
686 | 725 | |
687 | 726 | 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) |
689 | 733 | |
690 | 734 | 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) |
692 | 737 | |
693 | 738 | cpdef ModuleElement _ilmul_(self, RingElement c): |
694 | 739 | self.__u *= c |
diff -r fe244f94ad95 -r 556649e63232 sage/rings/power_series_ring.py
a
|
b
|
|
433 | 433 | from sage.categories.pushout import CompletionFunctor |
434 | 434 | return CompletionFunctor(self._names[0], self.default_prec()), self._poly_ring() |
435 | 435 | |
| 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 | |
436 | 453 | def _coerce_impl(self, x): |
437 | 454 | """ |
438 | 455 | Return canonical coercion of x into self. |
diff -r fe244f94ad95 -r 556649e63232 sage/rings/power_series_ring_element.pyx
a
|
b
|
|
886 | 886 | try: |
887 | 887 | u = ~(self>>v) # inverse of unit part |
888 | 888 | 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() |
891 | 894 | from sage.all import LaurentSeries |
892 | 895 | return LaurentSeries(R,u,-v,check=False)# R(u, -self.valuation()) |
893 | 896 | |
… |
… |
|
1005 | 1008 | |
1006 | 1009 | TEST: |
1007 | 1010 | |
1008 | | The following tests against a bug that was fixed in |
| 1011 | The following tests against bugs that were fixed in |
1009 | 1012 | ticket #8972:: |
1010 | 1013 | |
1011 | 1014 | sage: P.<t> = ZZ[] |
1012 | 1015 | sage: R.<x> = P[[]] |
1013 | 1016 | sage: 1/(t*x) |
1014 | 1017 | 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. |
1015 | 1025 | |
1016 | 1026 | """ |
1017 | | F = self._parent.fraction_field() |
1018 | 1027 | denom = <PowerSeries>denom_r |
1019 | 1028 | if denom.is_zero(): |
1020 | 1029 | 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 |
1021 | 1037 | # Algorithm: Cancel common factors of q from top and bottom, |
1022 | 1038 | # then invert the denominator. We do the cancellation first |
1023 | 1039 | # because we can only invert a unit (and remain in the ring |
diff -r fe244f94ad95 -r 556649e63232 sage/schemes/elliptic_curves/ell_wp.py
a
|
b
|
|
321 | 321 | True |
322 | 322 | |
323 | 323 | """ |
324 | | a_recip = 1/a |
| 324 | a_recip = ~a # 1/a |
325 | 325 | B = b * a_recip |
326 | 326 | C = c * a_recip |
327 | 327 | int_B = B.integral() |
328 | 328 | J = int_B.exp() |
329 | | J_recip = 1/J |
| 329 | J_recip = ~J # 1/J |
330 | 330 | CJ = C * J |
331 | 331 | int_CJ = CJ.integral() |
332 | 332 | f = J_recip * (alpha + int_CJ) |
diff -r fe244f94ad95 -r 556649e63232 sage/schemes/elliptic_curves/formal_group.py
a
|
b
|
|
300 | 300 | return y + O(t**prec) |
301 | 301 | w = self.w(prec+6) # XXX why 6? |
302 | 302 | t = w.parent().gen() |
303 | | y = -(w**(-1)) + O(t**prec) |
| 303 | y = O(t**prec) - (~w) |
| 304 | #y = -(w**(-1)) + O(t**prec) |
304 | 305 | self.__y = (prec, y) |
305 | 306 | return self.__y[1] |
306 | 307 | |
diff -r fe244f94ad95 -r 556649e63232 sage/schemes/elliptic_curves/padics.py
a
|
b
|
|
1562 | 1562 | ... g = [R.random_element() for i in range(N)] |
1563 | 1563 | ... g[0] = R(1) |
1564 | 1564 | ... g = Rx(g, len(g)) |
1565 | | ... f = g.derivative() / g |
| 1565 | ... f = g.derivative() * ~g |
1566 | 1566 | ... # perturb f by something whose integral is in I |
1567 | 1567 | ... err = [R.random_element() * p**(N-i) for i in range(N+1)] |
1568 | 1568 | ... err = Rx(err, len(err)) |
… |
… |
|
1590 | 1590 | G = Rx(G.list(), s) |
1591 | 1591 | |
1592 | 1592 | # extend current approximation to be correct to s terms |
1593 | | H = G.derivative() / G - F |
| 1593 | H = G.derivative() * ~G - F# / G - F |
1594 | 1594 | # Do the integral of H over QQ[x] to avoid division by p problems |
1595 | 1595 | H = Rx(Qx(H).integral()) |
1596 | 1596 | G = G * (1 - H) |
diff -r fe244f94ad95 -r 556649e63232 sage/structure/element.pyx
a
|
b
|
|
1537 | 1537 | raise ZeroDivisionError, "Cannot divide by zero" |
1538 | 1538 | else: |
1539 | 1539 | 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 | |
1540 | 1552 | |
1541 | 1553 | def __idiv__(self, right): |
1542 | 1554 | """ |