# 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
|
|
118 | 118 | (x + 1)/(x^2 + x + 1) |
119 | 119 | sage: K(355/113) |
120 | 120 | 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 | |
121 | 127 | """ |
122 | 128 | FieldElement.__init__(self, parent) |
123 | 129 | if coerce: |
diff -r 9df05e1ec17a -r d1a55eb60e1a sage/rings/polynomial/polynomial_ring.py
a
|
b
|
|
307 | 307 | raise TypeError, "denominator must be a unit" |
308 | 308 | |
309 | 309 | elif isinstance(x, pari_gen): |
| 310 | if x.type() == 't_RFRAC': |
| 311 | raise TypeError, "denominator must be a unit" |
310 | 312 | if x.type() != 't_POL': |
311 | 313 | x = x.Polrev() |
312 | 314 | |
diff -r 9df05e1ec17a -r d1a55eb60e1a sage/rings/power_series_poly.pyx
a
|
b
|
|
751 | 751 | sage: g(f) |
752 | 752 | t + O(t^4) |
753 | 753 | |
| 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 |
754 | 764 | |
755 | 765 | If the leading coefficient is not a unit, we pass to its fraction |
756 | 766 | field if possible:: |
… |
… |
|
846 | 856 | f2 = f._pari_() |
847 | 857 | g = f2.serreverse() |
848 | 858 | return PowerSeries_poly(f.parent(),g.Vecrev(),out_prec) |
849 | | except (TypeError,ValueError,AttributeError): |
| 859 | except (TypeError,ValueError,AttributeError,PariError): |
850 | 860 | # if pari fails, continue with Lagrange inversion |
851 | 861 | from sage.misc.all import verbose |
852 | 862 | verbose("passing to pari failed; trying Lagrange inversion") |
… |
… |
|
864 | 874 | return rev_lift.change_ring(f.base_ring()) |
865 | 875 | |
866 | 876 | t = f.parent().gen() |
| 877 | R = f.parent().base_ring() |
867 | 878 | |
868 | 879 | h = t/f |
869 | 880 | k = 1 |
870 | 881 | g = 0 |
871 | 882 | for i in range(1, out_prec): |
872 | 883 | 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 |
874 | 885 | g = g.add_bigoh(out_prec) |
875 | 886 | return PowerSeries_poly(out_parent, g, out_prec, check=False) |
876 | 887 | |