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 2 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

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)

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-library Library 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