Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from formal series to lazy power/LaurentSeriesRing give confusing error message #39840

Open
2 tasks done
user202729 opened this issue Mar 31, 2025 · 6 comments
Open
2 tasks done
Labels

Comments

@user202729
Copy link
Contributor

user202729 commented Mar 31, 2025

Steps To Reproduce

sage: var("x")
....: f = (1/x+sqrt(x+1)).series(x)
x
sage: f
1*x^(-1) + 1 + 1/2*x + (-1/8)*x^2 + 1/16*x^3 + (-5/128)*x^4 + 7/256*x^5 + (-21/1024)*x^6 + 33/2048*x^7 + (-429/32768)*x^8 + 715/65536*x^9 + (-2431/262144)*x^10 + 4199/524288*x^11 + (-29393/4194304)*x^12 + 52003/8388608*x^13 + (-185725/33554432)*x^14 + 334305/67108864*x^15 + (-9694845/2147483648)*x^16 + 17678835/4294967296*x^17 + (-64822395/17179869184)*x^18 + 119409675/34359738368*x^19 + Order(x^20)


sage: LazyPowerSeriesRing(QQ, "x")(f)
<repr(<sage.rings.lazy_series_ring.LazyPowerSeriesRing_with_category.element_class at 0x712d8ec95f40>) failed: TypeError: Substitution using function-call syntax and unnamed arguments has been removed. You can use named arguments instead, like EXPR(x=..., y=...)>
sage: LazyLaurentSeriesRing(QQ, "x")(f)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
ValueError: the valuation must be specified

Related but different: #39839, #39809

Expected Behavior

The conversion should redirect the user to use PowerSeriesRing or LaurentSeriesRing instead

Environment

  • OS: Linux
  • Sage Version: latest

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@tscrim
Copy link
Collaborator

tscrim commented Apr 9, 2025

This actually doesn't make sense because the input is not exact; it truncates the data to a finite amount. As such, @mantepse should we forbid it and similar such things (e.g., finite precision power series) as input?

@mantepse
Copy link
Contributor

mantepse commented Apr 9, 2025

I agree with @tscrim. I encountered various issues with the element constructors in the lazy series framework, I think it would be good to make them more uniform and possibly a bit stricter.

This term I won't be able to work on it, though.

@user202729
Copy link
Contributor Author

What do you mean it doesn't make sense? Elements of LazyPowerSeriesRing can have finite precision too.

sage: LazyPowerSeriesRing(QQ, "x").zero().add_bigoh(3)
O(x^3)
sage: LazyPowerSeriesRing(QQ, "x").zero().add_bigoh(3)[5]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 LazyPowerSeriesRing(QQ, "x").zero().add_bigoh(Integer(3))[Integer(5)]

File power_series_poly.pyx:463, in sage.rings.power_series_poly.PowerSeries_poly.__getitem__()

IndexError: coefficient not known

(Granted you can ask why doesn't the user not just use PowerSeriesRing instead? Still it doesn't seem too far-fetched to support this, one possible use case is because some other lazy series is used elsewhere)

@tscrim
Copy link
Collaborator

tscrim commented Apr 9, 2025

No, they have infinite precision. You should look at the type/parent after the add_bigoh() call.

@tscrim
Copy link
Collaborator

tscrim commented Apr 9, 2025

Or to put it another way, if you do not call add_bigoh() (which would keep the power series computed lazily), then you would not get an error.

@user202729
Copy link
Contributor Author

You're right here. I suppose we can improve the error message to inform the user to use normal PowerSeriesRing instead.

@user202729 user202729 changed the title Conversion from formal series to lazy power/LaurentSeriesRing errors Conversion from formal series to lazy power/LaurentSeriesRing give confusing error message Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants