Skip to content

fix: ReducibilityHints.lt - #2750

Closed
digama0 wants to merge 1 commit into
leanprover:masterfrom
digama0:reducibility_hints
Closed

digama0 wants to merge 1 commit into
leanprover:masterfrom
digama0:reducibility_hints

Conversation

@digama0

@digama0 digama0 commented Oct 25, 2023

Copy link
Copy Markdown
Collaborator

The implementation of ReducibilityHints.lt was previously giving the ordering

.abbrev < .regular 1 < .regular 10 < .opaque

while the kernel is using a three-way comparison function compare(reducibility_hints, reducibility_hints) which returns -1 when the first argument should be unfolded and 1 when the second argument should be unfolded, where the one that should be unfolded is larger in the following ranking:

.opaque < .regular 1 < .regular 10 < .abbrev

Both of these are a bit weird (the compare function has reversed interpretation compared to strcmp, and the lean function gets the roles of .abbrev and .opaque mixed up). What is more, the interpretation of the lean ordering is also reversed in ExprDefEq, meaning that it actually implements the ordering

.opaque < .regular 10 < .regular 1 < .abbrev

which is almost but not quite the same as the kernel ordering.

My fix is to make the .lt function clearly represent "more reducible" with .abbrev at the top and .opaque at the bottom, and covariant in the definitional height (higher = more reducible). I have chosen not to negate the output values of compare, although this would also be a reasonable refactor. Should lean just have a three-way comparison as well?

@digama0
digama0 force-pushed the reducibility_hints branch from a125325 to ff1bcc9 Compare October 25, 2023 10:17
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Oct 25, 2023
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Oct 25, 2023
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Oct 25, 2023
@ghost

ghost commented Oct 25, 2023 •

Copy link
Copy Markdown
  • 💥 Mathlib branch lean-pr-testing-2750 build failed against this PR. (2023-10-25 12:33:58) View Log
  • ❗ Mathlib CI can not be attempted yet, as the 'nightly-testing-2023-11-04' branch does not exist there yet. We will retry when you push more commits. It may be necessary to rebase onto 'nightly' tomorrow. (2023-11-04 14:35:57)
  • 💥 Mathlib branch lean-pr-testing-2750 build failed against this PR. (2023-11-05 02:05:21) View Log
  • 💥 Mathlib branch lean-pr-testing-2750 build failed against this PR. (2023-11-06 15:17:46) View Log
  • 🟡 Mathlib branch lean-pr-testing-2750 build against this PR was cancelled. (2023-11-09 10:09:26) View Log
  • ✅ Mathlib branch lean-pr-testing-2750 has successfully built against this PR. (2023-11-09 10:52:17) View Log

@kim-em

kim-em commented Oct 26, 2023

Copy link
Copy Markdown
Collaborator

Apologies for the breaks-mathlib. Until #2734 hits a nightly release anything on top of that is going to break mathlib. After the next nightly release, touching this PR should be sufficient to make the Mathlib CI come good.

@kim-em
kim-em force-pushed the reducibility_hints branch from ff1bcc9 to 9bbafb7 Compare November 4, 2023 12:46
kim-em added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 5, 2023
@kim-em
kim-em force-pushed the reducibility_hints branch from 9bbafb7 to 03c2436 Compare November 6, 2023 11:25
@kim-em kim-em removed the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Nov 6, 2023
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 6, 2023
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Nov 6, 2023
@kim-em

kim-em commented Nov 9, 2023

Copy link
Copy Markdown
Collaborator

Apparently there is a small breakage in Mathlib (a dsimp fixes a universe unification problem)? This seems slightly surprising to me; @digama0, could you please check it out? leanprover-community/mathlib4#8289

@ghost ghost added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Nov 9, 2023
@Kha
Kha requested review from Kha and leodemoura as code owners November 20, 2023 08:15
@kim-em

kim-em commented Apr 22, 2024

Copy link
Copy Markdown
Collaborator

@digama0, Leo has merged #3964 which also addresses this. Do we need to keep this PR?

@digama0

digama0 commented Apr 22, 2024 •

Copy link
Copy Markdown
Collaborator Author

No, this PR and #3964 are identical up to a global flip of the ordering relation. Although I would like to ask @leodemoura to comment on this choice explicitly: If a.lt b are reducibilities then intuitively b should be "more reducible" and a should be "less reducible", such that when deciding between them we would prefer to unfold b. #3964 makes the opposite choice without comment. However it is consistent with the reducibility_hints::compare and clearly a smaller diff, so in any case this PR is no longer needed.

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

Labels

builds-mathlib CI has verified that Mathlib builds against this PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants