Ticket #4376: 4376_reversion_fixes.patch

File 4376_reversion_fixes.patch, 3.1 KB (added by fwclarke, 12 years ago)

Apply after previous two patches

  • sage/rings/fraction_field_element.pyx

    # HG changeset patch
    # User Francis Clarke <F.Clarke@Swansea.ac.uk>
    # Date 1296500735 0
    # Node ID d1a55eb60e1a00b1f15d5bbdeb476a616543f215
    # Parent  9df05e1ec17a11c903cfca758ab7fc3d28c4b70e
    4376: make reversion work with better pari conversion
    
    diff -r 9df05e1ec17a -r d1a55eb60e1a sage/rings/fraction_field_element.pyx
    a b  
    118118            (x + 1)/(x^2 + x + 1)
    119119            sage: K(355/113)
    120120            355/113
     121
     122        The next example failed before #4376::
     123
     124            sage: K(pari((x + 1)/(x^2 + x + 1)))
     125            (x + 1)/(x^2 + x + 1)
     126
    121127        """
    122128        FieldElement.__init__(self, parent)
    123129        if coerce:
  • sage/rings/polynomial/polynomial_ring.py

    diff -r 9df05e1ec17a -r d1a55eb60e1a sage/rings/polynomial/polynomial_ring.py
    a b  
    307307                raise TypeError, "denominator must be a unit"
    308308           
    309309        elif isinstance(x, pari_gen):
     310            if x.type() == 't_RFRAC':
     311                raise TypeError, "denominator must be a unit"
    310312            if x.type() != 't_POL':
    311313                x = x.Polrev()
    312314
  • sage/rings/power_series_poly.pyx

    diff -r 9df05e1ec17a -r d1a55eb60e1a sage/rings/power_series_poly.pyx
    a b  
    751751            sage: g(f)
    752752            t + O(t^4)
    753753
     754            sage: A.<t> = PowerSeriesRing(ZZ)
     755            sage: B.<s> = A[[]]
     756            sage: f = (1 - 3*t + 4*t^3 + O(t^4))*s + (2 + t + t^2 + O(t^3))*s^2 + O(s^3)
     757            sage: set_verbose(1)
     758            sage: g = f.reversion(); g
     759            verbose 1 (<module>) passing to pari failed; trying Lagrange inversion
     760            (1 + 3*t + 9*t^2 + 23*t^3 + O(t^4))*s + (-2 - 19*t - 118*t^2 + O(t^3))*s^2 + O(s^3)
     761            sage: set_verbose(0)
     762            sage: f(g) == g(f) == s
     763            True
    754764
    755765        If the leading coefficient is not a unit, we pass to its fraction
    756766        field if possible::
     
    846856            f2 = f._pari_()
    847857            g = f2.serreverse()
    848858            return PowerSeries_poly(f.parent(),g.Vecrev(),out_prec)
    849         except (TypeError,ValueError,AttributeError):
     859        except (TypeError,ValueError,AttributeError,PariError):
    850860            # if pari fails, continue with Lagrange inversion
    851861            from sage.misc.all import verbose
    852862            verbose("passing to pari failed; trying Lagrange inversion")
     
    864874            return rev_lift.change_ring(f.base_ring())
    865875       
    866876        t = f.parent().gen()
     877        R = f.parent().base_ring()
    867878
    868879        h = t/f
    869880        k = 1
    870881        g = 0
    871882        for i in range(1, out_prec):
    872883            k *= h
    873             g += k.padded_list(i)[i - 1]/i*t**i
     884            g += R(k.padded_list(i)[i - 1]/i)*t**i
    874885        g = g.add_bigoh(out_prec)
    875886        return PowerSeries_poly(out_parent, g, out_prec, check=False)
    876887