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

Unable to extract a particular coefficient of a multivariate power series #39314

Open
2 tasks done
maxale opened this issue Jan 11, 2025 · 4 comments
Open
2 tasks done

Comments

@maxale
Copy link
Contributor

maxale commented Jan 11, 2025

Steps To Reproduce

We have

sage: R.<x,y> = QQ[]
sage: ((x+y)^3)[2,1]
3

but

sage: R.<x,y> = QQ[[]]
sage: ((x+y)^3)[2,1]
[...]
TypeError: unsupported operand parent(s) for <=: 'The Infinity Ring' and '<class 'tuple'>'

Expected Behavior

There should be a simple interface (including indexing via []) for accessing a particular coefficient of a power series, similarly to that of multivariate polynomials.

Actual Behavior

Functionality for accessing individual coefficients is missing.

Additional Information

No response

Environment

  • OS: Ubuntu 24.04.1 LTS
  • Sage Version: 10.6.beta1

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
@DaveWitteMorris
Copy link
Member

As far as I know, there is nothing in the documentation that says this should work, so it seems to be an enhancement request, not a bug.

@maxale
Copy link
Contributor Author

maxale commented Jan 11, 2025

Well, it also works for univariate series:

sage: R.<x> = QQ[[]]
sage: ((x+1)^3)[2]
3

So, the absence of this core functionality for multivariate series is a clear deficiency, if not a bug.

@mantepse
Copy link
Collaborator

Let me remark that, currently, __getitem__ extracts the piece of given degree for you:

sage: R.<x,y> = QQ[[]]
sage: (1/(1-x+y)^3)[4]
15*x^4 - 60*x^3*y + 90*x^2*y^2 - 60*x*y^3 + 15*y^4

This also works, and more generally, for lazy series:

sage: s = SymmetricFunctions(QQ).s()
sage: L = LazySymmetricFunctions(s)
sage: f = 1/(1-L(s[1]))
sage: f[4]
s[1, 1, 1, 1] + 3*s[2, 1, 1] + 2*s[2, 2] + 3*s[3, 1] + s[4]

We can now extract a single coefficient - note that providing an index of the wrong type silently returns 0.

sage: f[4][2,1,1]
0
sage: f[4][Partition([2,1,1])]
3

And, although, slightly abusing terminology,

sage: D = LazyDirichletSeriesRing(QQ, "s")
sage: D(lambda n: n)
1 + 2/2^s + 3/3^s + 4/4^s + 5/5^s + 6/6^s + 7/7^s + O(1/(8^s))
sage: f = D(lambda n: n)
sage: f[4]
4

@maxale
Copy link
Contributor Author

maxale commented Jan 15, 2025

Let me remark that, currently, __getitem__ extracts the piece of given degree for you:

Perhaps, for the uniformity of interface __getitem__ should support both an integer argument (the current behavior) and a tuple/list (of length equal the number of variables) argument, which will also eliminate the unnecessary step of extracting a homogeneous component when only a particular coefficient is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants