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

Equality comparison gives incorrect result in divisor group of a curve #37966

Open
2 tasks done
vincentmacri opened this issue May 8, 2024 · 2 comments · May be fixed by #37972
Open
2 tasks done

Equality comparison gives incorrect result in divisor group of a curve #37966

vincentmacri opened this issue May 8, 2024 · 2 comments · May be fixed by #37972

Comments

@vincentmacri
Copy link

vincentmacri commented May 8, 2024

Steps To Reproduce

Example code:

E = EllipticCurve([1, 2])

# Two points on E
P = E(-1, 0)
Q = E(1, 2)

# Get the points as divisors
Pd = E.divisor(P)
Qd = E.divisor(Q)

# These should be equal, but they aren't
Pd + Qd == Qd + Pd

# Nevertheless, their difference is calculated to be 0
(Pd + Qd) - (Qd + Pd)

The same thing happens with HyperellipticCurve and Curve.

This example in particular violates commutativity of the divisor group, despite the divisor group being marked in Sage as part of the "Category of commutative additive groups".

Expected Behavior

Comparison in the divisor group should give the correct result or at the very least return a not implemented error.

Actual Behavior

Comparison in the divisor group gives an incorrect result.

Additional Information

__eq__ needs to be implemented for divisors. Something like this should work:

def __eq__(self, other):
    return self - other == 0

but I'm not familiar enough with the internals of Sage to know where this should go.

Environment

- **OS**: Fedora 40
- **Sage Version**: 10.3, built from source in a conda environment

I ran make ptestlong and all tests passed, so I doubt it's an issue with my environment.

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
@vincentmacri
Copy link
Author

vincentmacri commented May 9, 2024

I'm willing to try to submit a patch. I poked around in the code and it looks like divisors inherit from FormalSum. So I think implementing __eq__ in FormalSum seems like a good way to fix this (and probably also fix some similar issues with other formal sums in Sage) unless there is some situation I'm not thinking of where you wouldn't want a - b = 0 to mean a = b for a formal sum.

@vincentmacri
Copy link
Author

vincentmacri commented May 9, 2024

FormalSum seemed to have some more complicated comparison behaviour (richcmp) than I thought it would, so I ended up implementing the change just for divisors.

See discussion in linked PR for how this was solved.

vbraun pushed a commit to vbraun/sage that referenced this issue May 18, 2024
…m commutativity)

    
Fixes sagemath#37966.



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [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.
    
URL: sagemath#37972
Reported by: Vincent Macri
Reviewer(s): Travis Scrimshaw, Vincent Macri
vbraun pushed a commit to vbraun/sage that referenced this issue May 18, 2024
…m commutativity)

    
Fixes sagemath#37966.



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [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.
    
URL: sagemath#37972
Reported by: Vincent Macri
Reviewer(s): Travis Scrimshaw, Vincent Macri
vbraun pushed a commit to vbraun/sage that referenced this issue May 24, 2024
…m commutativity)

    
Fixes sagemath#37966.



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [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.
    
URL: sagemath#37972
Reported by: Vincent Macri
Reviewer(s): Travis Scrimshaw, 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 a pull request may close this issue.

2 participants