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

coefficients for QuasiModularFormsElement #36269

Merged
merged 11 commits into from
May 12, 2024

Conversation

seewoo5
Copy link
Contributor

@seewoo5 seewoo5 commented Sep 15, 2023

This patch implements _compute and coefficients methods to QuasiModularFormsElement, which already exists in ModularFormsElement. I made this for my own usage.
(This is my first PR for Sage, so comments are welcome!)

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

@mantepse
Copy link
Contributor

mantepse commented Sep 16, 2023

I am not familiar with modular forms, but wouldn't it be nice to return a (lazy) power series, analogous to molien_series?

            sage: S3 = MatrixGroup(SymmetricGroup(3))
            sage: mol = S3.molien_series(prec=oo); mol
            1 + t + 2*t^2 + 3*t^3 + 4*t^4 + 5*t^5 + 7*t^6 + O(t^7)
            sage: mol.parent()
            Lazy Taylor Series Ring in t over Integer Ring
            sage: mol[100]
            884

With this, it is very natural (and efficient) to get any particular coefficient.

@seewoo5
Copy link
Contributor Author

seewoo5 commented Sep 16, 2023

I am not familiar with modular forms, but wouldn't it be nice to return a (lazy) power series, analogous to molien_series?

            sage: S3 = MatrixGroup(SymmetricGroup(3))
            sage: mol = S3.molien_series(prec=oo); mol
            1 + t + 2*t^2 + 3*t^3 + 4*t^4 + 5*t^5 + 7*t^6 + O(t^7)
            sage: mol.parent()
            Lazy Taylor Series Ring in t over Integer Ring
            sage: mol[100]
            884

With this, it is very natural (and efficient) to get any particular coefficient.

Thank you for letting me know. My code is actually almost a copy & paste of the same methods of ModularFormsElement, where I updated docs & tests with different examples (see the below code). I also don't understand the detailed implementation of q_expansion method well.

def _compute(self, X):
"""
Compute the coefficients of `q^n` of the power series of self,
for `n` in the list `X`. The results are not cached. (Use
coefficients for cached results).
EXAMPLES::
sage: f = ModularForms(18,2).1
sage: f.q_expansion(20)
q + 8*q^7 + 4*q^10 + 14*q^13 - 4*q^16 + 20*q^19 + O(q^20)
sage: f._compute([10,17])
[4, 0]
sage: f._compute([])
[]
"""
if not isinstance(X, list) or not X:
return []
bound = max(X)
q_exp = self.q_expansion(bound + 1)
return [q_exp[i] for i in X]
def coefficients(self, X):
"""
The coefficients a_n of self, for integers n>=0 in the list
X. If X is an Integer, return coefficients for indices from 1
to X.
This function caches the results of the compute function.
TESTS::
sage: e = DirichletGroup(11).gen()
sage: f = EisensteinForms(e, 3).eisenstein_series()[0]
sage: f.coefficients([0,1])
[15/11*zeta10^3 - 9/11*zeta10^2 - 26/11*zeta10 - 10/11,
1]
sage: f.coefficients([0,1,2,3])
[15/11*zeta10^3 - 9/11*zeta10^2 - 26/11*zeta10 - 10/11,
1,
4*zeta10 + 1,
-9*zeta10^3 + 1]
sage: f.coefficients([2,3])
[4*zeta10 + 1,
-9*zeta10^3 + 1]
Running this twice once revealed a bug, so we test it::
sage: f.coefficients([0,1,2,3])
[15/11*zeta10^3 - 9/11*zeta10^2 - 26/11*zeta10 - 10/11,
1,
4*zeta10 + 1,
-9*zeta10^3 + 1]
"""
try:
self.__coefficients
except AttributeError:
self.__coefficients = {}
if isinstance(X, Integer):
X = list(range(1, X + 1))
Y = [n for n in X if n not in self.__coefficients]
v = self._compute(Y)
for i in range(len(v)):
self.__coefficients[Y[i]] = v[i]
return [self.__coefficients[x] for x in X]

@seewoo5
Copy link
Contributor Author

seewoo5 commented Apr 18, 2024

@DavidAyotte Could you check this one (or any suggestions)?

@DavidAyotte
Copy link
Member

@DavidAyotte Could you check this one (or any suggestions)?

Absolutely, I will check it in a couple days!

Copy link
Member

@DavidAyotte DavidAyotte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Seewoo, overall it looks good! I have minor docstring recommendation. Thank you for implementing this.

@DavidAyotte
Copy link
Member

@mantepse Hello Martin! Yes I think it would be feasible and interesting to use the Lazy power series framework for $q$-expansion of modular forms. It would probably require a bit of factoring, but I'm think of something like:

sage: M = ModularForms(1, 12)
sage: f = M.0
sage: f.q_expansion(prec=oo)
# Lazy power series

I will probably open a PR about this soon.

@seewoo5
Copy link
Contributor Author

seewoo5 commented Apr 21, 2024

Updated all the docstrings!

Copy link
Member

@DavidAyotte DavidAyotte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I do have more minor comments.

If X is an Integer, return coefficients for indices from 1
to X. This function caches the results of the `_compute` function.

TESTS::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TESTS::
EXAMPLES::

If you use the "TESTS" block, the doctests will not appear in the reference manual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it would be still tested, right? (is TESTS:: legacy?)

Copy link
Member

@DavidAyotte DavidAyotte Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes both TESTS and EXAMPLES run the doctests, however TESTS block does not show any examples in the Sage reference manual and I think that it is the only difference. I personally think that it is a good thing to present some examples in the manual so the user can better understand how to use the method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add to my previous reply, even though it is a good practice to present some examples, sometimes some doctests aren't that useful for the user (technical or internal doctest) so you might want to hide them. But in your case the doctests are all relevant so that is why I suggested to use the EXAMPLES block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't know that examples would be also tested. Just updated!

seewoo5 and others added 2 commits April 24, 2024 14:01
@DavidAyotte
Copy link
Member

Thank you Seewoo for the changes.

@mkoeppe can you approve the workflows for this PR? Thanks!

Copy link

github-actions bot commented May 8, 2024

Documentation preview for this PR (built with commit f055a04; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@DavidAyotte
Copy link
Member

Hello sorry for the delay, but I wanted to see the build jobs before setting this to postive review. There's a single doctest that does not pass and I believe it is not related with this PR, so I'm setting this to postive review. Thank you for this contribution!

vbraun pushed a commit to vbraun/sage that referenced this pull request May 12, 2024
sagemathgh-36269: `coefficients` for `QuasiModularFormsElement`
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

This patch implements `_compute` and `coefficients` methods to
`QuasiModularFormsElement`, which already exists in
`ModularFormsElement`. I made this for my own usage.
(This is my first PR for Sage, so comments are welcome!)

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [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.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36269
Reported by: Seewoo Lee
Reviewer(s): David Ayotte, Seewoo Lee
@vbraun vbraun merged commit 68fe91d into sagemath:develop May 12, 2024
13 of 14 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone May 12, 2024
@seewoo5 seewoo5 deleted the feature/quasimod-coeff branch July 20, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants