gh-37972: Fix comparison for divisors of curves (and FormalSum commutativity)
Fixes #37966.
### :memo: 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: https://github.com/sagemath/sage/pull/37972
Reported by: Vincent Macri
Reviewer(s): Travis Scrimshaw, Vincent Macri