Skip to content

Commit 428abde

Browse files
committed
Implement conversion from laurent series to rational function field
1 parent 3f48052 commit 428abde

File tree

1 file changed

+50
-15
lines changed

1 file changed

+50
-15
lines changed

src/sage/rings/fraction_field.py

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,30 @@ def is_exact(self):
557557
"""
558558
return self.ring().is_exact()
559559

560+
def _convert_from_finite_precision_laurent_series(self, x):
561+
"""
562+
Construct an element of this fraction field approximating a Laurent series.
563+
564+
INPUT:
565+
566+
- ``x`` -- a Laurent series, must have finite precision
567+
568+
OUTPUT: Element of ``self``
569+
570+
This internal method should not be used directly, use :meth:`__call__` instead,
571+
which will delegates to :meth:`_element_constructor_`. There are some tests there.
572+
573+
.. NOTE::
574+
575+
Uses the algorithm described in `<https://mathoverflow.net/a/14874>`_.
576+
This may be changed to use Berlekamp--Massey algorithm or something else
577+
to compute Padé approximant in the future.
578+
"""
579+
integral_part, fractional_part = self(x.truncate(1)), x.truncate_neg(1)
580+
if fractional_part.is_zero():
581+
return integral_part
582+
return integral_part + ~self._convert_from_finite_precision_laurent_series(~fractional_part)
583+
560584
def _element_constructor_(self, x, y=None, coerce=True):
561585
"""
562586
Construct an element of this fraction field.
@@ -662,6 +686,9 @@ def _element_constructor_(self, x, y=None, coerce=True):
662686
sage: f.parent()
663687
Power Series Ring in x over Rational Field
664688
sage: F(f)
689+
doctest:warning...
690+
DeprecationWarning: Conversion from power series to rational function field is deprecated, use .truncate() instead
691+
See https://github.com/sagemath/sage/issues/39485 for details.
665692
-x^19 + x^18 - x^17 + x^16 - x^15 + x^14 - x^13 + x^12 - x^11 + x^10 - x^9 + x^8 - x^7 + x^6 - x^5 + x^4 - x^3 + x^2 - x + 1
666693
667694
Conversion from Laurent series to rational function field gives an approximation::
@@ -672,48 +699,56 @@ def _element_constructor_(self, x, y=None, coerce=True):
672699
sage: f.parent()
673700
Laurent Series Ring in x over Rational Field
674701
sage: F(f)
675-
Traceback (most recent call last):
676-
...
677-
TypeError: cannot convert 1 - x + x^2 - x^3 + x^4 - x^5 + x^6 - x^7 + x^8 - x^9 + x^10 - x^11 + x^12 - x^13 + x^14 - x^15 + x^16 - x^17 + x^18 - x^19 + O(x^20)/1 to an element of Fraction Field of Univariate Polynomial Ring in x over Rational Field
702+
1/(x + 1)
678703
sage: f = f.truncate(20); f # infinite precision
679704
1 - x + x^2 - x^3 + x^4 - x^5 + x^6 - x^7 + x^8 - x^9 + x^10 - x^11 + x^12 - x^13 + x^14 - x^15 + x^16 - x^17 + x^18 - x^19
680705
sage: f.parent()
681706
Laurent Series Ring in x over Rational Field
682707
sage: F(f)
683-
Traceback (most recent call last):
684-
...
685-
TypeError: cannot convert 1 - x + x^2 - x^3 + x^4 - x^5 + x^6 - x^7 + x^8 - x^9 + x^10 - x^11 + x^12 - x^13 + x^14 - x^15 + x^16 - x^17 + x^18 - x^19/1 to an element of Fraction Field of Univariate Polynomial Ring in x over Rational Field
708+
-x^19 + x^18 - x^17 + x^16 - x^15 + x^14 - x^13 + x^12 - x^11 + x^10 - x^9 + x^8 - x^7 + x^6 - x^5 + x^4 - x^3 + x^2 - x + 1
686709
sage: f = 1/(x*(x+1))
687710
sage: f.parent()
688711
Laurent Series Ring in x over Rational Field
689712
sage: F(f)
690-
Traceback (most recent call last):
691-
...
692-
TypeError: cannot convert x^-1 - 1 + x - x^2 + x^3 - x^4 + x^5 - x^6 + x^7 - x^8 + x^9 - x^10 + x^11 - x^12 + x^13 - x^14 + x^15 - x^16 + x^17 - x^18 + O(x^19)/1 to an element of Fraction Field of Univariate Polynomial Ring in x over Rational Field
713+
1/(x^2 + x)
693714
694715
::
695716
696717
sage: K.<x> = FunctionField(QQ)
697718
sage: R.<x> = QQ[[]]
698719
sage: f = 1/(x+1)
699720
sage: K(f)
721+
doctest:warning...
722+
DeprecationWarning: Conversion from power series to rational function field is deprecated, use .truncate() instead
723+
See https://github.com/sagemath/sage/issues/39485 for details.
700724
-x^19 + x^18 - x^17 + x^16 - x^15 + x^14 - x^13 + x^12 - x^11 + x^10 - x^9 + x^8 - x^7 + x^6 - x^5 + x^4 - x^3 + x^2 - x + 1
701725
sage: f = Frac(R)(1/(x+1))
702726
sage: K(f)
703-
Traceback (most recent call last):
704-
...
705-
TypeError: cannot convert 1 - x + x^2 - x^3 + x^4 - x^5 + x^6 - x^7 + x^8 - x^9 + x^10 - x^11 + x^12 - x^13 + x^14 - x^15 + x^16 - x^17 + x^18 - x^19 + O(x^20)/1 to an element of Fraction Field of Univariate Polynomial Ring in x over Rational Field
727+
1/(x + 1)
706728
sage: f = 1/(x*(x+1))
707729
sage: K(f)
708-
Traceback (most recent call last):
709-
...
710-
TypeError: cannot convert x^-1 - 1 + x - x^2 + x^3 - x^4 + x^5 - x^6 + x^7 - x^8 + x^9 - x^10 + x^11 - x^12 + x^13 - x^14 + x^15 - x^16 + x^17 - x^18 + O(x^19)/1 to an element of Fraction Field of Univariate Polynomial Ring in x over Rational Field
730+
1/(x^2 + x)
711731
"""
712732
if isinstance(x, (list, tuple)) and len(x) == 1:
713733
x = x[0]
714734
if y is None:
715735
if parent(x) is self:
716736
return x
737+
from sage.rings.polynomial.polynomial_ring import PolynomialRing_generic
738+
if isinstance(self.ring(), PolynomialRing_generic):
739+
from sage.rings.power_series_ring_element import PowerSeries
740+
from sage.rings.laurent_series_ring_element import LaurentSeries
741+
if isinstance(x, PowerSeries):
742+
from sage.misc.superseded import deprecation
743+
deprecation(
744+
39485,
745+
"Conversion from power series to rational function field is deprecated, use .truncate() instead",
746+
)
747+
if isinstance(x, LaurentSeries):
748+
from sage.rings.infinity import infinity
749+
if x.prec() == infinity:
750+
return self(x.laurent_polynomial())
751+
return self._convert_from_finite_precision_laurent_series(x)
717752
ring_one = self.ring().one()
718753
try:
719754
return self._element_class(self, x, ring_one, coerce=coerce)

0 commit comments

Comments
 (0)