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

Implement EllipticCurve_with_order #37119

Merged
merged 20 commits into from
Apr 12, 2024
Merged

Conversation

grhkm21
Copy link
Contributor

@grhkm21 grhkm21 commented Jan 21, 2024

This function returns a curve / an iterator of curves with a given order. These are generated using the CM method.

Also fix #37131 (13 year old bug).

Co-authored-by: @GiacomoPope #sd123 🚀

sage: from sage.schemes.elliptic_curves.ell_finite_field import EllipticCurve_with_order
sage: E = EllipticCurve_with_order(1234); E
Elliptic Curve defined by y^2 = x^3 + 8*x over Finite Field of size 1229
sage: E.order() == 1234
True

@grhkm21
Copy link
Contributor Author

grhkm21 commented Jan 21, 2024

The function can be sped up on some small edge cases when #37110 is finished, but it works as is.

Someone that's experienced with CM method should check whether my
implementation truly returns all curves (over a prime finite field) with
the given order. In particular, I might be missing $p = 2$?
@grhkm21
Copy link
Contributor Author

grhkm21 commented Jan 22, 2024

I believe this is ready for review :)

@grhkm21 grhkm21 requested a review from yyyyx4 January 26, 2024 19:46
@@ -1596,17 +1596,20 @@ def small_prime_value(self, Bmax=1000):
raise ValueError("Unable to find a prime value of %s" % self)
B += 10

def solve_integer(self, n, *, algorithm="general"):
def solve_integer(self, n, *, algorithm="general", flag=2):
Copy link
Member

Choose a reason for hiding this comment

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

In my opinion we shouldn't expose PARI's non-human-readable APIs: Can flag be passed by a sensible choice of keyword arguments instead?

src/sage/schemes/elliptic_curves/ell_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
@GiacomoPope
Copy link
Contributor

Is this being held up because of the pari flag?

@grhkm21
Copy link
Contributor Author

grhkm21 commented Feb 28, 2024

No, I deferred it to another issue already #37364

@GiacomoPope
Copy link
Contributor

I'm a coauthor, so I dont think I should review it further, but if @yyyyx4's only comment left is about the PARI flag and this is being delayed then maybe a positive review is OK?

Copy link
Member

@yyyyx4 yyyyx4 left a comment

Choose a reason for hiding this comment

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

Sorry, the reason this was stuck is simply because I hadn't managed to get back to it yet. Here are some comments.

src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/quadratic_forms/binary_qf.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
Copy link
Contributor

@GiacomoPope GiacomoPope left a comment

Choose a reason for hiding this comment

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

just some comments which could be included / ignored.

src/sage/schemes/elliptic_curves/ell_field.py Outdated Show resolved Hide resolved
src/sage/quadratic_forms/binary_qf.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
@@ -1741,7 +1753,7 @@ def twists(self):

sage: # needs sage.rings.finite_rings
sage: K = GF(2**7)
sage: [E.ainvs() for E in EllipticCurve(j=K(1)).twists()]
sage: [E.ainvs() for E in EllipticCurve(j=K(1)).twists()] # random
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Lorenz that this could be sorted and random could be removed, or is the issue that the twists themselves are random. Maybe im being stupid here.

src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
src/sage/schemes/elliptic_curves/ell_finite_field.py Outdated Show resolved Hide resolved
@grhkm21
Copy link
Contributor Author

grhkm21 commented Mar 28, 2024

Sorry for the snail pace work. I've reverted the changes related to precomputing order, since they don't affect correctness, only speed. They're at #37110 anyways.

Next, I'll work on your reviews

@grhkm21
Copy link
Contributor Author

grhkm21 commented Mar 29, 2024

Conda failure is a real bug, I will make a new PR #37488

Copy link

Documentation preview for this PR (built with commit a1eb6c2; changes) is ready! 🎉

Copy link
Contributor

@GiacomoPope GiacomoPope left a comment

Choose a reason for hiding this comment

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

LGTM

@grhkm21
Copy link
Contributor Author

grhkm21 commented Apr 10, 2024

Thanks!

@vbraun vbraun merged commit 94c4b27 into sagemath:develop Apr 12, 2024
16 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone Apr 12, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 14, 2024
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Me and @grhkm21 suggest this diff against develop that implements the
`EllipticCurve_with_prime_order(N)` constructor. Using the prime order
`N` in input, this method finds another prime `p` and constructs an
elliptic curve `E/Fp` with `#E(Fp) = N`.

It follows Algorithm 2.2 of the paper [Constructing Elliptic Curves of
prime order](https://arxiv.org/abs/0712.2022) by Bröker and Stevenhagen.
The running time is quite random depending on the input parameter but
can turn out to be fast for some larger values (≃ 256 bits primes). It's
also worth noticing that some values will make this function run for a
**very** long time.

There had been a [PR](sagemath#37119) by
@grhkm21 and @GiacomoPope that implements the
`EllipticCurve_with_order()` method. This PR would intuitively fit nice
into their work but I felt uncomfortable with it returning an iterator.
I felt like returning a single curve was more handy so I implemented
this method in a separate function that does so but I'm open to
suggestions if this is of any interest to the community.

Fixes sagemath#38342

### 📝 Checklist
- [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.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38341
Reported by: grnx
Reviewer(s): grhkm21, grnx, Vincent Macri
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.

Incorrect doctest in set_order
5 participants