You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-39485: Implement conversion from laurent series to rational function field
As in the title. I think this behavior makes sense because `QQ(RR(…))`
currently uses `.simplest_rational()` instead of like exact value (like
`x / 2^53` for some integer `x`), so it makes sense for similar
conversions to compute a good approximation too.
I cannot prove that this round-trips, however.
Note that currently conversion from power series `QQ[[x]]` to polynomial
ring `QQ[x]` truncates, because of implementation detail this leads to
conversion from `QQ[[x]]` to `Frac(QQ[x])` also truncates. I think this
is undesirable behavior because identical-looking elements in `QQ[[x]]`
versus `Frac(QQ[[x]]) = LaurentSeriesRing(QQ, "x")` has different
conversion behavior.
Elements which are already Laurent polynomial are preserved.
Side note: `.one()` is faster because it's cached
```sage
sage: R.<x> = QQ[]
sage: S = Frac(R)
sage: %timeit S.one() # fast because it's cached
90.6 ns ± 1.27 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops
each)
sage: ring_one = S.ring().one()
sage: %timeit S._element_class(S, ring_one, ring_one, coerce=False,
reduce=False)
3.42 μs ± 75 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops
each)
```
Maybe this doesn't need to be explicitly written in the documentation
(users trying to do the conversion will just see the result)
There exists also <code>:meth:\`.PowerSeries_poly.pade\`</code> which
should probably be mentioned in the documentation.
Reverse direction (that one is a morphism):
#39365
Possible caveat:
```
sage: S(Frac(V)(1/(x+1))/(x^10))
1/(x^11 + x^10)
sage: S(Frac(V)(1/(x+1))/(x^30))
(-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)/x^30
```
It could be argued the latter would be simpler as `1/(x^31+x^30)`, but
then that way gives higher denominator degree.
### 📝 Checklist
<!-- Put an `x` in all the boxes that apply. -->
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
### ⌛ Dependencies
<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
URL: #39485
Reported by: user202729
Reviewer(s): Travis Scrimshaw, user202729
0 commit comments