Skip to content

Commit

Permalink
refactor: remove @[simp] from List.modifyHead
Browse files Browse the repository at this point in the history
At present, the simplifier always unfolds the definition of
`List.modifyHead`. This behavior hinders the simplifier from using
lemmas about the function, hence the following changes:

* Remove the `simp` attribute from the function `modifyHead`.
* Add two `simp` lemmas for `modifyHead`.
  • Loading branch information
chabulhwi committed May 9, 2024
1 parent cda1910 commit 92ad41e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Batteries/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,15 @@ modifyNthTail f 2 [a, b, c] = [a, b] ++ f [c]
| n+1, a :: l => a :: modifyNthTail f n l

/-- Apply `f` to the head of the list, if it exists. -/
@[simp, inline] def modifyHead (f : α → α) : List α → List α
@[inline] def modifyHead (f : α → α) : List α → List α
| [] => []
| a :: l => f a :: l

@[simp] theorem modifyHead_nil (f : α → α) : [].modifyHead f = [] := by rw [modifyHead]

@[simp] theorem modifyHead_cons (a : α) (l : List α) (f : α → α) :
(a :: l).modifyHead f = f a :: l := by rw [modifyHead]

/-- Apply `f` to the nth element of the list, if it exists. -/
def modifyNth (f : α → α) : Nat → List α → List α :=
modifyNthTail (modifyHead f)
Expand Down

0 comments on commit 92ad41e

Please sign in to comment.