Skip to content

chore: replace custom List.slice with upstream List.extract - #885

Open
oliver-butterley wants to merge 8 commits into
AeneasVerif:mainfrom
oliver-butterley:slice-->-extract
Open

chore: replace custom List.slice with upstream List.extract#885
oliver-butterley wants to merge 8 commits into
AeneasVerif:mainfrom
oliver-butterley:slice-->-extract

Conversation

@oliver-butterley

@oliver-butterley oliver-butterley commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

List.slice -> List.extract refactor

Replaced the custom List.slice definition with Lean's built-in List.extract (identical semantics, different arg order: slice start stop ls -> ls.extract start stop).

Changes:

  • List.lean: Removed def slice, added a deprecated abbrev slice alias. Renamed 8 theorems (slice_nil → extract_nil, etc.) with deprecated aliases for the old names. Simplified proofs since extract unfolds via simp.
  • Slice.lean: Slice.slice body updated to delegate to List.extract. Updated internal theorem references.
  • Array.lean: Array.slice body updated to delegate to List.extract.
  • ArraySlice.lean, Vec.lean: Updated theorem statements from .val.slice to .val.extract.
  • Slice.slice and Array.slice keep their names (This is the desired behaviour since it matches the Rust terminology?).

fixes #814

@oliver-butterley
oliver-butterley marked this pull request as ready for review March 27, 2026 13:37
@sonmarcho

sonmarcho commented Mar 27, 2026

Copy link
Copy Markdown
Member

Thanks for this! Yes, this is the appropriate workflow for deprecation.
And yes, don't hesitate to upstream the relevant lemmas (as long as you retag them with the proper attributes inside the Aeneas library).

On a side note: I need to check that some internal projects still build before merging this PR.

@oliver-butterley

Copy link
Copy Markdown
Collaborator Author

On a side note: I need to check that some internal projects still build before merging this PR.

Yes, very wise check! On our side I'll just see what happens and hope that our infrastructure is sufficiently robust that my colleagues deal with possible issues without any pain! 🤣

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

This looks good to me! There are a few renamed Slice lemmas that weren't aded to the deprecation list. I'm not sure if it's super important, but it's the only thing I noticed. (looking closer I actually didn't catch everything, everything looks good to me!)

Comment on lines 248 to +251
@[simp, simp_lists_safe, grind =]
theorem getElem?_slice (i j k : Nat) (ls : List α)
theorem getElem?_extract (i j k : Nat) (ls : List α)
(_ : j ≤ ls.length ∧ i + k < j) :
(ls.slice i j)[k]? = ls[i + k]? := by
revert i j
induction ls
. intro i j; simp_all
. intro i j h
simp_all [slice]
have : k < j - i := by scalar_tac
simp [*]
(ls.extract i j)[k]? = ls[i + k]? := by grind

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.

Do we actually still need this theorem (as grind solves the goal)?
In particular: I'm wondering whether we should mark it as grind =
It is very likely that we just need to mark a Lean std lemma with simp_lists_safe

(ls.slice i j)[k]! = ls[i + k]! := by
have := getElem?_slice i j k ls
simp_all
(ls.extract i j)[k]! = ls[i + k]! := by grind

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.

same remark as above

have h1 := getElem?_slice i j k ls (by grind)
rw [getElem?_eq_getElem hk, getElem?_eq_getElem hik] at h1
exact Option.some.inj h1
(ls.extract i j)[k] = ls[i + k] := by grind

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.

Same remark

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

Labels

awaiting author A reviewer has asked the author a question or requested changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove List.slice and use List.extract instead

3 participants