Skip to content

[Merged by Bors] - chore(Data/List/Rotate): add simp attributes - #33214

Closed
JJYYY-JJY wants to merge 6 commits into
leanprover-community:masterfrom
JJYYY-JJY:sc-data-list-rotate-simp
Closed

JJYYY-JJY wants to merge 6 commits into
leanprover-community:masterfrom
JJYYY-JJY:sc-data-list-rotate-simp

Conversation

@JJYYY-JJY

@JJYYY-JJY JJYYY-JJY commented Dec 23, 2025 •

Copy link
Copy Markdown
Contributor
  • Refs Small TODOs to do! #7987 (SC: Data/List/Rotate)
  • Add @[simp] to: rotate_mod, rotate'_rotate', rotate'_mod, rotate_rotate, getElem_rotate, head?_rotate, map_rotate.
  • Verification: lake build Mathlib.Data.List.Rotate.

@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 Dec 23, 2025
@github-actions

github-actions Bot commented Dec 23, 2025 •

Copy link
Copy Markdown

PR summary 570ff68990

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for scripts/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh 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-data Data (lists, quotients, numbers, etc) label Dec 23, 2025
Comment on lines +218 to 221
@[simp]
theorem getElem_rotate (l : List α) (n : ℕ) (k : Nat) (h : k < (l.rotate n).length) :
(l.rotate n)[k] =
l[(k + n) % l.length]'(mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt h)) := by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the only one I'm not entirely sure if this is a simp-lemma, and if it should be a simp-lemma, why is getElem?_rotate above not marked as simp?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the slow reply — I got pulled away for a while.

In an earlier revision of this PR, I had marked both getElem_rotate and getElem?_rotate (and also rotate'_nil) with [simp]. That revision did not pass Mathlib CI, so in a follow-up I removed [simp] from getElem?_rotate and rotate'_nil, but kept [simp] on getElem_rotate.

I still think [simp] on getElem_rotate is reasonable: it is a normalization lemma for defined indexing, rewriting (l.rotate n)[k] to indexing on l, i.e. it eliminates rotate from getElem terms.

By contrast, getElem?_rotate requires the side condition m < l.length. That extra hypothesis is often not available to simp, so using it as a global simp rule is less robust and can make simp behavior less predictable. This is similar to the pattern in List.Iterate, where getElem_iterate is [simp] but getElem?_iterate is not.

I will also update the PR description so it matches the final code state.

@joneugster joneugster Feb 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, the LHS of getElem?_rotate is not in simp-NF, and there is the simp lemma getElem?_pos : c[i]? = some (c[i]'h) which takes care of the getElem?. (which the simpNF linter reports) 👍

As for rotate'_simp it does not need to be simp as "simp can prove this"

@joneugster joneugster assigned joneugster and unassigned TwoFX Jan 23, 2026
@joneugster joneugster added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Jan 23, 2026
Copilot AI review requested due to automatic review settings February 22, 2026 11:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds @[simp] attributes to several theorems in Mathlib/Data/List/Rotate.lean to improve automation when working with list rotations. The changes allow the simplifier to automatically apply these lemmas when simplifying expressions involving rotated lists.

Changes:

  • Added @[simp] to 7 theorems involving list rotation operations
  • Enables automatic simplification of nested rotations, modulo operations, indexing, and functor laws

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Mathlib/Data/List/Rotate.lean Resolved
@joneugster joneugster added awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. and removed awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. labels Feb 27, 2026

@joneugster joneugster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR and thank you for updating the PR description!

Remember to comment

-awaiting-author

on the PR once you addressed all comments to ensure reviewers see the PR again!

I suggest

maintainer merge

Comment on lines +218 to 221
@[simp]
theorem getElem_rotate (l : List α) (n : ℕ) (k : Nat) (h : k < (l.rotate n).length) :
(l.rotate n)[k] =
l[(k + n) % l.length]'(mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt h)) := by

@joneugster joneugster Feb 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, the LHS of getElem?_rotate is not in simp-NF, and there is the simp lemma getElem?_pos : c[i]? = some (c[i]'h) which takes care of the getElem?. (which the simpNF linter reports) 👍

As for rotate'_simp it does not need to be simp as "simp can prove this"

Comment thread Mathlib/Data/List/Rotate.lean Resolved
@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by joneugster.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Feb 27, 2026
@joneugster

Copy link
Copy Markdown
Member

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Feb 27, 2026

@bryangingechen bryangingechen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!
bors r+

@mathlib-triage mathlib-triage Bot added ready-to-merge This PR has been sent to bors. and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Feb 27, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Feb 27, 2026
* Refs #7987 (SC: Data/List/Rotate)
* Add `@[simp]` to: `rotate_mod`, `rotate'_rotate'`, `rotate'_mod`, `rotate_rotate`, `getElem_rotate`, `head?_rotate`, `map_rotate`.
* Verification: `lake build Mathlib.Data.List.Rotate`.

Co-authored-by: Junye Ji <[email protected]>
@mathlib-bors

mathlib-bors Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title chore(Data/List/Rotate): add simp attributes [Merged by Bors] - chore(Data/List/Rotate): add simp attributes Feb 27, 2026
@mathlib-bors mathlib-bors Bot closed this Feb 27, 2026
@JJYYY-JJY
JJYYY-JJY deleted the sc-data-list-rotate-simp branch February 28, 2026 08:24
pfaffelh pushed a commit to pfaffelh/mathlib4 that referenced this pull request Mar 2, 2026
)

* Refs leanprover-community#7987 (SC: Data/List/Rotate)
* Add `@[simp]` to: `rotate_mod`, `rotate'_rotate'`, `rotate'_mod`, `rotate_rotate`, `getElem_rotate`, `head?_rotate`, `map_rotate`.
* Verification: `lake build Mathlib.Data.List.Rotate`.

Co-authored-by: Junye Ji <[email protected]>
xroblot pushed a commit to xroblot/mathlib4 that referenced this pull request Mar 10, 2026
)

* Refs leanprover-community#7987 (SC: Data/List/Rotate)
* Add `@[simp]` to: `rotate_mod`, `rotate'_rotate'`, `rotate'_mod`, `rotate_rotate`, `getElem_rotate`, `head?_rotate`, `map_rotate`.
* Verification: `lake build Mathlib.Data.List.Rotate`.

Co-authored-by: Junye Ji <[email protected]>
pevogam pushed a commit to pevogam/mathlib4 that referenced this pull request Mar 19, 2026
)

* Refs leanprover-community#7987 (SC: Data/List/Rotate)
* Add `@[simp]` to: `rotate_mod`, `rotate'_rotate'`, `rotate'_mod`, `rotate_rotate`, `getElem_rotate`, `head?_rotate`, `map_rotate`.
* Verification: `lake build Mathlib.Data.List.Rotate`.

Co-authored-by: Junye Ji <[email protected]>
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! ready-to-merge This PR has been sent to bors. t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants