Opened 8 years ago

Closed 8 years ago

#15698 closed enhancement (fixed)

conversion from polynomial fraction to its power series expansion

Reported by: rws Owned by: rws
Priority: major Milestone: sage-6.2
Component: algebra Keywords: power series, expansion, fraction
Cc: Merged in:
Authors: Ralf Stephan, Marc Mezzarobba Reviewers: Marc Mezzarobba, Ralf Stephan
Report Upstream: N/A Work issues:
Branch: 25f819f (Commits, GitHub, GitLab) Commit: 25f819f748f64634177097da20cc9bbf1c2a68df
Dependencies: Stopgaps:

Status badges

Description (last modified by rws)

Original description was:

The following behaviour is not implemented, example:

  sage: R.<t> = QQ[]; A=1/(1-t)
  sage: A.expand(5)
  1+t+t^2+t^3+t^4+t^5+O(t^6)
  sage: A+O(t^6)
  1+t+t^2+t^3+t^4+t^5+O(t^6)

Add a parameter to specify the respective series variable (for derivation) then multivariate polynomial fractions can be handled. Result type being a power series. The pari function Ser() implements the same behaviour. Note: I would like to implement this.

Change History (30)

comment:1 Changed 8 years ago by rws

  • Description modified (diff)

comment:2 Changed 8 years ago by pbruin

The "canonical" syntax for this kind of conversion would be

sage: S = QQ[['t']]  # construct power series ring
sage: S(A)           # convert A into it, using default precision
sage: S(A, prec=6)   # or using specified precision

However, the last two lines currently fail with

TypeError: denominator must be a unit

The following does work:

sage: L=S.laurent_series_ring()
sage: L(A)
1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + t^10 + t^11 + t^12 + t^13 + t^14 + t^15 + t^16 + t^17 + t^18 + t^19 + O(t^20)

Unfortunately, this does not currently accept a precision argument.

I think the easiest solution for S(A) is to fix PowerSeriesRing._element_constructor_() to accept rational functions.

comment:3 Changed 8 years ago by rws

  • Branch set to u/rws/ticket/15698
  • Created changed from 01/20/14 11:00:32 to 01/20/14 11:00:32
  • Modified changed from 01/22/14 17:10:05 to 01/22/14 17:10:05

comment:4 Changed 8 years ago by git

  • Commit set to 307871686f1f8be1ffe7ed0169b9bfa550878aef

Branch pushed to git repo; I updated commit sha1. New commits:

3078716Trac #15698: we pass through all parameters; documentation added

comment:5 Changed 8 years ago by rws

Why is the first commit (creation of branch plus first patch) not viewable?

Anyway, pbruin's example works now. A.expand() is then no longer necessary. The only thing that still does not work is addition of power series to fraction, where coercion is needed. I'll leave that for now and ask for your review.

comment:6 Changed 8 years ago by rws

  • Status changed from new to needs_review

comment:7 Changed 8 years ago by git

  • Commit changed from 307871686f1f8be1ffe7ed0169b9bfa550878aef to ae77b79a1bcd0cb1f69b5b5219814b9d9ccad028

Branch pushed to git repo; I updated commit sha1. New commits:

ae77b79remove superfluous doc line

comment:8 Changed 8 years ago by rws

  • Status changed from needs_review to needs_work

comment:9 Changed 8 years ago by rws

  • Status changed from needs_work to positive_review

comment:10 Changed 8 years ago by rws

  • Status changed from positive_review to needs_review

comment:11 Changed 8 years ago by rws

  • Description modified (diff)
  • Summary changed from univariate polynomial ring fraction expansion to power series to conversion from polynomial fraction to its power series expansion

comment:12 Changed 8 years ago by mmezzarobba

  • Status changed from needs_review to needs_work

Shouldn't the following example throw an error?

sage: R.<x> = QQ[]
sage: S = R.completion(x)
sage: S(1/x)
x^-1

comment:13 Changed 8 years ago by git

  • Commit changed from ae77b79a1bcd0cb1f69b5b5219814b9d9ccad028 to 58396dea4393b297b4c3d549156e010915eaaa33

Branch pushed to git repo; I updated commit sha1. New commits:

58396detrac #15698: use coercion to catch errors; with doctest

comment:14 Changed 8 years ago by rws

  • Keywords power added; ogf removed
  • Status changed from needs_work to needs_review

comment:15 Changed 8 years ago by mmezzarobba

  • Branch changed from u/rws/ticket/15698 to u/mmezzarobba/15698-series_of_ratpoly
  • Commit changed from 58396dea4393b297b4c3d549156e010915eaaa33 to 7913b6f9951e051e7f53e825e0e6d2de95af3730
  • Reviewers set to Marc Mezzarobba
  • Status changed from needs_review to positive_review

Ok, LGTM. I took the liberty of squashing your three patches and rebasing the whole on top of develop; please protest if you disagree.

I had a doubt about the fact of computing the quotient (possibly as a Laurent series) in all cases and then checking that it was in fact a power series, but at least it helps keeping the logic that decides whether the quotient fo two power series is a power series in a single place.


New commits:

7913b6f15698: Allow construction of power series from fractions

comment:16 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:17 Changed 8 years ago by rws

  • Authors set to rws, mmezzarobba

comment:18 follow-up: Changed 8 years ago by vbraun

Please fill in real names under authors.

comment:19 in reply to: ↑ 18 Changed 8 years ago by mmezzarobba

  • Authors changed from rws, mmezzarobba to Ralf Stephan

Replying to vbraun:

Please fill in real names under authors.

Done. I also removed myself since I only reorganized the patches without changing the code at all.

comment:20 Changed 8 years ago by vbraun

doctests fail with

sage -t --long src/sage/rings/power_series_poly.pyx
**********************************************************************
File "src/sage/rings/power_series_poly.pyx", line 987, in sage.rings.power_series_poly.PowerSeries_poly.__richcmp__.reversion
Failed example:
    g(f)
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 480, in _run
        self.execute(example, compiled, test.globs)
      File "/home/release/Sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 839, in execute
        exec compiled in globs
      File "<doctest sage.rings.power_series_poly.PowerSeries_poly.__richcmp__.reversion[32]>", line 1, in <module>
        g(f)
      File "power_series_poly.pyx", line 373, in sage.rings.power_series_poly.PowerSeries_poly.__call__ (sage/rings/power_series_poly.c:4951)
      File "polynomial_element.pyx", line 655, in sage.rings.polynomial.polynomial_element.Polynomial.__call__ (sage/rings/polynomial/polynomial_element.c:8408)
      File "element.pyx", line 1539, in sage.structure.element.RingElement.__add__ (sage/structure/element.c:13873)
      File "coerce.pyx", line 782, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:7311)
      File "coerce.pyx", line 900, in sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion (sage/structure/coerce.c:8549)
...
      File "/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_element_generic.py", line 734, in __init__
        Polynomial_generic_dense.__init__(self, parent, x, check, is_gen)
      File "polynomial_element.pyx", line 6914, in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.__init__ (sage/rings/polynomial/polynomial_element.c:48031)
      File "polynomial_element.pyx", line 209, in sage.rings.polynomial.polynomial_element.Polynomial.__init__ (sage/rings/polynomial/polynomial_element.c:4700)
    RuntimeError: maximum recursion depth exceeded while calling a Python object

comment:21 Changed 8 years ago by mmezzarobba

  • Status changed from positive_review to needs_work

comment:22 Changed 8 years ago by git

  • Commit changed from 7913b6f9951e051e7f53e825e0e6d2de95af3730 to 4c16ab0a03bcf158df0caa956863a0a805dcdba5

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

d9e5c7715698: Allow construction of power series from fractions
4c16ab0Fraction to power series conversion when the fraction coerces into the base ring

comment:23 Changed 8 years ago by git

  • Commit changed from 4c16ab0a03bcf158df0caa956863a0a805dcdba5 to 50defe27ea0129109f5c42213f98bd83b6d10eb8

Branch pushed to git repo; I updated commit sha1. New commits:

50defe2Fraction to power series: doctests

comment:24 Changed 8 years ago by mmezzarobba

  • Authors changed from Ralf Stephan to Ralf Stephan, Marc Mezzarobba
  • Status changed from needs_work to needs_review

comment:25 follow-up: Changed 8 years ago by rws

Patchbot says:

File "src/sage/rings/power_series_ring.py", line 671, in sage.rings.power_series_ring.PowerSeriesRing_generic._element_constructor_
Failed example:
    PowerSeriesRing(PowerSeriesRing(QQ,'x'),'y')(1/(1+x), 5)
Expected:
    1 - x + x^2 - x^3 + x^4 + O(x^5)
Got:
    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) + O(y^5)

comment:26 Changed 8 years ago by rws

  • Status changed from needs_review to needs_work

comment:27 Changed 8 years ago by git

  • Commit changed from 50defe27ea0129109f5c42213f98bd83b6d10eb8 to 25f819f748f64634177097da20cc9bbf1c2a68df

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

c52306815698: Allow construction of power series from fractions
f38e82fFraction to power series conversion when the fraction coerces into the base ring
25f819fFraction to power series: doctests

comment:28 in reply to: ↑ 25 Changed 8 years ago by mmezzarobba

  • Status changed from needs_work to needs_review

Replying to rws:

Patchbot says:

File "src/sage/rings/power_series_ring.py", line 671, in sage.rings.power_series_ring.PowerSeriesRing_generic._element_constructor_
Failed example:
    PowerSeriesRing(PowerSeriesRing(QQ,'x'),'y')(1/(1+x), 5)
Expected:
    1 - x + x^2 - x^3 + x^4 + O(x^5)
Got:
    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) + O(y^5)

Thanks. That was a stupid copy-paste mistake, I believe.


New commits:

c52306815698: Allow construction of power series from fractions
f38e82fFraction to power series conversion when the fraction coerces into the base ring
25f819fFraction to power series: doctests

comment:29 Changed 8 years ago by rws

  • Reviewers changed from Marc Mezzarobba to Marc Mezzarobba, Ralf Stephan
  • Status changed from needs_review to positive_review

Thanks, it tested --long okay in rings/ so let's roll.

comment:30 Changed 8 years ago by vbraun

  • Branch changed from u/mmezzarobba/15698-series_of_ratpoly to 25f819f748f64634177097da20cc9bbf1c2a68df
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.