Skip to content

feat: Add getElem_swapIfInBounds* lemmas and deprecate getElem_swap' #8406

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

linesthatinterlace
Copy link

@linesthatinterlace linesthatinterlace commented May 19, 2025

This PR adds lemmas of the form getElem_swapIfInBounds* and deprecates getElem_swap'.

@linesthatinterlace
Copy link
Author

changelog-library

@github-actions github-actions bot added the changelog-library Library label May 19, 2025
@linesthatinterlace linesthatinterlace changed the title feat: Add getElem_swapIfInBounds* lemmas and deprecate getElem_swap' feat: Add getElem_swapIfInBounds* lemmas and deprecate getElem_swap' May 19, 2025
@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 May 19, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented May 19, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f40d72ea4795561b7e656898482ca022bf013d0f --onto efe2ab4c04e81fe2a3edcc0d861449490b4431b2. You can force Mathlib CI using the force-mathlib-ci label. (2025-05-19 17:18:56)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 74d87463569cca5a63e38ca087cb96ee558adc08 --onto c12159b51982221bdd66f0c5997f85e1f9d91772. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-05 13:59:04)

@linesthatinterlace
Copy link
Author

The alternative incidentally would be something like:

theorem getElem_swapIfInBounds {as : Array α} {i j k : ℕ} (hk : k < (as.swapIfInBounds i j).size) :
    (as.swapIfInBounds i j)[k] =
    if h : i < as.size ∧ j < as.size then (as.swap i j)[k]'
      (hk.trans_eq ((as.size_swapIfInBounds).trans (as.size_swap).symm))
    else as[k]'(hk.trans_eq as.size_swapIfInBounds) := by
  unfold swapIfInBounds
  split
  · split <;> simp_all
  · simp_all

I think this is a more compact form but it will generally result in more rewrites. There are places where this is what you'd want though.

@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-library Library P-medium We may work on this issue if we find the time 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.

4 participants