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

make EllipticCurvePoint_field inherit from EllipticCurvePoint #37415

Merged
merged 4 commits into from
May 25, 2024

Conversation

pjbruin
Copy link
Contributor

@pjbruin pjbruin commented Feb 21, 2024

The method EllipticCurve_generic.__contains__() checks for inheritance from EllipticCurvePoint; however, the other classes for points on elliptic curves do not inherit from this class. This pull request fixes this. Note that there is some overlap with #33228.

This change makes P in E much faster:

  • Over Q:
E = EllipticCurve('37a1')
P = E((0, -1))
%timeit P in E

Before: 35.3 µs ± 186 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
After: 324 ns ± 0.535 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

  • Over a finite field:
F.<a> = FiniteField((23, 2), modulus='random')
E = EllipticCurve_from_j(F.random_element())
P = E.random_point()
%timeit P in E

Before: 36.4 µs ± 542 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
After: 333 ns ± 5.03 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

@yyyyx4
Copy link
Member

yyyyx4 commented Feb 22, 2024

I agree that points over extension fields should be in a curve in principle, but I'm a bit worried that tons of code has been written (by people such as myself) under the assumption that this check only returns True when the base field is the same...

@pjbruin
Copy link
Contributor Author

pjbruin commented Feb 22, 2024

I looked at how you dealt with this in #33228; I think this is a neat solution and I'm happy to simplify __contains__() in the same way you did it there.

@yyyyx4
Copy link
Member

yyyyx4 commented Feb 22, 2024

Eventually we should still make the machinery for points over extension fields work. But I believe this will need some larger adjustments, in particular within some of the isogeny-related code...

Copy link

github-actions bot commented Feb 22, 2024

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

@pjbruin
Copy link
Contributor Author

pjbruin commented Feb 22, 2024

Indeed, there is definitely some work to be done. I ran into a bug with point homsets over extension fields: #37427

Copy link
Collaborator

@kwankyu kwankyu left a comment

Choose a reason for hiding this comment

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

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request May 15, 2024
…CurvePoint

    
The method `EllipticCurve_generic.__contains__()` checks for inheritance
from `EllipticCurvePoint`; however, the other classes for points on
elliptic curves do not inherit from this class.  This pull request fixes
this. Note that there is some overlap with sagemath#33228.

This change makes `P in E` much faster:
- Over **Q**:
```python
E = EllipticCurve('37a1')
P = E((0, -1))
%timeit P in E
```
Before: `35.3 µs ± 186 ns per loop (mean ± std. dev. of 7 runs, 10,000
loops each)`
After: `324 ns ± 0.535 ns per loop (mean ± std. dev. of 7 runs,
1,000,000 loops each)`

- Over a finite field:
```python
F.<a> = FiniteField((23, 2), modulus='random')
E = EllipticCurve_from_j(F.random_element())
P = E.random_point()
%timeit P in E
```
Before: `36.4 µs ± 542 ns per loop (mean ± std. dev. of 7 runs, 10,000
loops each)`
After: `333 ns ± 5.03 ns per loop (mean ± std. dev. of 7 runs, 1,000,000
loops each)`
    
URL: sagemath#37415
Reported by: Peter Bruin
Reviewer(s): Kwankyu Lee, Peter Bruin
vbraun pushed a commit to vbraun/sage that referenced this pull request May 18, 2024
…CurvePoint

    
The method `EllipticCurve_generic.__contains__()` checks for inheritance
from `EllipticCurvePoint`; however, the other classes for points on
elliptic curves do not inherit from this class.  This pull request fixes
this. Note that there is some overlap with sagemath#33228.

This change makes `P in E` much faster:
- Over **Q**:
```python
E = EllipticCurve('37a1')
P = E((0, -1))
%timeit P in E
```
Before: `35.3 µs ± 186 ns per loop (mean ± std. dev. of 7 runs, 10,000
loops each)`
After: `324 ns ± 0.535 ns per loop (mean ± std. dev. of 7 runs,
1,000,000 loops each)`

- Over a finite field:
```python
F.<a> = FiniteField((23, 2), modulus='random')
E = EllipticCurve_from_j(F.random_element())
P = E.random_point()
%timeit P in E
```
Before: `36.4 µs ± 542 ns per loop (mean ± std. dev. of 7 runs, 10,000
loops each)`
After: `333 ns ± 5.03 ns per loop (mean ± std. dev. of 7 runs, 1,000,000
loops each)`
    
URL: sagemath#37415
Reported by: Peter Bruin
Reviewer(s): Kwankyu Lee, Peter Bruin
vbraun pushed a commit to vbraun/sage that referenced this pull request May 18, 2024
…CurvePoint

    
The method `EllipticCurve_generic.__contains__()` checks for inheritance
from `EllipticCurvePoint`; however, the other classes for points on
elliptic curves do not inherit from this class.  This pull request fixes
this. Note that there is some overlap with sagemath#33228.

This change makes `P in E` much faster:
- Over **Q**:
```python
E = EllipticCurve('37a1')
P = E((0, -1))
%timeit P in E
```
Before: `35.3 µs ± 186 ns per loop (mean ± std. dev. of 7 runs, 10,000
loops each)`
After: `324 ns ± 0.535 ns per loop (mean ± std. dev. of 7 runs,
1,000,000 loops each)`

- Over a finite field:
```python
F.<a> = FiniteField((23, 2), modulus='random')
E = EllipticCurve_from_j(F.random_element())
P = E.random_point()
%timeit P in E
```
Before: `36.4 µs ± 542 ns per loop (mean ± std. dev. of 7 runs, 10,000
loops each)`
After: `333 ns ± 5.03 ns per loop (mean ± std. dev. of 7 runs, 1,000,000
loops each)`
    
URL: sagemath#37415
Reported by: Peter Bruin
Reviewer(s): Kwankyu Lee, Peter Bruin
@vbraun vbraun merged commit 5c0dd60 into sagemath:develop May 25, 2024
13 of 15 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone May 25, 2024
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