Skip to content

chore(AlgebraicGeometry/EllipticCurve/Projective): remove erw in Formula.lean - #45670

Open
user202729 wants to merge 1 commit into
leanprover-community:masterfrom
user202729:elliptic-curve-erw
Open

user202729 wants to merge 1 commit into
leanprover-community:masterfrom
user202729:elliptic-curve-erw

Conversation

@user202729

@user202729 user202729 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Reducing tech debt.

The main reason why erw was needed in this file instead of rw is the following.

  • Background: Each point is represented by a function P : Fin 3 → R, and there's local notation x being (0 : Fin 3), similar for y and z. So P x is the first coordinate of P. For a curve W' and a point P, W'.dblXYZ P is another point, its double i.e. 2 • P.
  • There are functions to compute various operations on elliptic curves, for example, W.dblY P computes the Y-coordinate of 2 • P. Of course, this can be equivalently written as W.dblXYZ P y.
  • The two forms W.dblY P and W.dblXYZ P y are not definitionally equal at the default transparency level. Depends on which lemma we want to apply, we need to convert the goal to use one form or the other.

Personally, I think it's a better idea to normalize on the W.dblXYZ P y form, and keep the W.dblY P form as strictly an implementation detail if needed. In this case, the XYZ suffix wouldn't be needed either, and the main definitions would be:

* `WeierstrassCurve.Projective.neg`: The negation `-P` of a point `P`.
* `WeierstrassCurve.Projective.dbl`: The double `2 • P` of a point `P`.
* `WeierstrassCurve.Projective.negDbl`: The negated double `-(2 • P)` of a point `P`.

etc. Thoughts? Note that W.dbl P y is only 1 character longer than W.dblY P.

Most lemmas that we want to apply are already stated in term of the point (except that many use W.negY P instead of W.neg P y, though currently W.neg doesn't exist).

Also, there are (very) long rw chains. (#mathlib4 > Is long `rw` chain bad?) Ideas?

Another idea: have a array_index tactic that evaluates ![a, b, c, d] 2 to c when the index is a known constant, for example. Currently there is simp only [fin3_def_ext] which obviously only works on length-3 arrays.

@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to Zulip and join the Lean community.
Thank you again for joining our community.

@github-actions github-actions Bot added the tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

PR summary bec15c3a23

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ negAddXYZ
+ negAddXYZ_X
+ negAddXYZ_Y
+ negAddXYZ_Z
+ negDblXYZ
+ negDblXYZ_X
+ negDblXYZ_Y
+ negDblXYZ_Z

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit bec15c3).

  • +8 new declarations
  • −0 removed declarations
+WeierstrassCurve.Projective.negAddXYZ
+WeierstrassCurve.Projective.negAddXYZ_X
+WeierstrassCurve.Projective.negAddXYZ_Y
+WeierstrassCurve.Projective.negAddXYZ_Z
+WeierstrassCurve.Projective.negDblXYZ
+WeierstrassCurve.Projective.negDblXYZ_X
+WeierstrassCurve.Projective.negDblXYZ_Y
+WeierstrassCurve.Projective.negDblXYZ_Z

Decrease in strong tech debt: (relative, absolute) = (7.00, 0.01)
Current number Change Type (strong)
486 -7 erw
No changes to weak technical debt.

Current commit bec15c3a23
Reference commit c1cc962aa0

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-algebraic-geometry Algebraic geometry label Nov 4, 2026
@user202729 user202729 changed the title chore(AlgebraicGeometry/EllipticCurve/Projective): remove all erw chore(AlgebraicGeometry/EllipticCurve/Projective): remove erw in Formula.lean Nov 4, 2026
@tb65536

tb65536 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

FYI @Multramate has big plans for this part of the library. He might have thoughts on this.

@Multramate

Copy link
Copy Markdown
Collaborator

Thanks for this. You may have seen #25988 which was my attempt a long time ago to remove the erws. My answer today is that, while I welcome technical debt removals for Projective, they will likely be completely overwritten when I do the massive refactor, so I suggest that you don't worry about them for now. The refactor will begin early next year.

If you're interested in helping out: here is the link to my refactor post in Zulip

@Multramate Multramate left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you insist to get this merged, I think it's largely fine, but I believe Jacobian may also have similar formulae, and it's in our best interest for them to mirror each other.

Comment on lines +451 to +455
rw [dblY, ← negDblXYZ, ← negDblXYZ_Z]
rw [negY_of_Z_ne_zero <| dblZ_ne_zero_of_Y_ne' hP hQ hPz hQz hx hy]
rw [negDblXYZ_X, negDblXYZ_Y, negDblXYZ_Z, dblX_of_Z_ne_zero hP hQ hPz hQz hx hy]
rw [negDblY_of_Z_ne_zero hP hQ hPz hQz hx hy]
rw [Affine.addY]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess these can be combined into one rw? It's still a long chain...

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-algebraic-geometry Algebraic geometry tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants