Zulip Chat Archive

Stream: lean4

Topic: max recursion depth reached on `simp [getElem]`


David Renshaw (Jul 07 2024 at 23:25):

def a : Array Nat := #[1,2,3,4,5]

example : a[2] = 3 := by
  simp [getElem]
  -- tactic 'simp' failed, nested error:
  -- maximum recursion depth has been reached

What is going on here?

David Renshaw (Jul 07 2024 at 23:28):

(I know that rfl or decide close the goal. I want to understand why this simp seems to get in an infinite loop.)

Eric Wieser (Jul 07 2024 at 23:32):

I think it's because there is a lemma that turns get back into getElem

Eric Wieser (Jul 07 2024 at 23:33):

Try doing simp only [getElem] followed by simp? to find it

Kim Morrison (Jul 08 2024 at 00:33):

Does set_option diagnostics true show you the theorems involved in the infinite loop?

David Renshaw (Jul 08 2024 at 01:22):

[reduction] unfolded declarations (max: 57, num: 2): 
  List.rec  57
  List.concat  30
[reduction] unfolded reducible declarations (max: 57, num: 2): 
  List.casesOn  57
  outParam  24

David Renshaw (Jul 08 2024 at 01:26):

Eric Wieser said:

Try doing simp only [getElem] followed by simp? to find it

Ah. The simp theorem Array.get_eq_getElem is doing it.

David Renshaw (Jul 08 2024 at 01:27):

The reason that I was adding getElem was that simp does not close the goal (which seems a bit surprising to me).

David Renshaw (Jul 08 2024 at 01:28):

This works:

  simp only [getElem, Array.get, List.get]

Kim Morrison (Jul 16 2024 at 19:14):

@David Renshaw, the original problem will be solved after lean#4765 "feat: simprocs for #[1,2,3,4,5][2] ".


Last updated: May 02 2025 at 03:31 UTC