-- Mathlib/.lake/packages/lean4/src/lean/Init/Data/Array/Lemmas.lean
theorem getElem_extract_loop_ge (as bs : Array α) (size start : Nat) (hge : i ≥ bs.size)
    (h : i < (extract.loop as size start bs).size)
    (h' := getElem_extract_loop_ge_aux as bs size start hge h) :
    (extract.loop as size start bs)[i] = as[start + i - bs.size]

Proof state:
α : Type u_1
i : Nat
as : Array α
size : Nat
ih :
  ∀ (bs : Array α) (start : Nat) (hge : i ≥ bs.size) (h : i < (extract.loop as size start bs).size)
    (h' : optParam (start + i - bs.size < as.size) ⋯), (extract.loop as size start bs)[i] = as[start + i - bs.size]
bs : Array α
start : Nat
hge : i ≥ bs.size
h : i < (extract.loop as (size + 1) start bs).size
h' : optParam (start + i - bs.size < as.size) ⋯
⊢ start < as.size

Tactic:
apply Nat.lt_of_le_of_lt (Nat.le_add_right start (i - bs.size))

Result:
α : Type u_1
i : Nat
as : Array α
size : Nat
ih :
  ∀ (bs : Array α) (start : Nat) (hge : i ≥ bs.size) (h : i < (extract.loop as size start bs).size)
    (h' : optParam (start + i - bs.size < as.size) ⋯), (extract.loop as size start bs)[i] = as[start + i - bs.size]
bs : Array α
start : Nat
hge : i ≥ bs.size
h : i < (extract.loop as (size + 1) start bs).size
h' : optParam (start + i - bs.size < as.size) ⋯
⊢ start + (i - bs.size) < as.size

Proof state:
case refl.e_i
α : Type u_1
as : Array α
size : Nat
bs : Array α
start : Nat
this✝ : start < as.size
ih :
  ∀ (bs_1 : Array α) (start : Nat) (hge : bs.size ≥ bs_1.size) (h : bs.size < (extract.loop as size start bs_1).size)
    (h' : optParam (start + bs.size - bs_1.size < as.size) ⋯),
    (extract.loop as size start bs_1)[bs.size] = as[start + bs.size - bs_1.size]
hge : bs.size ≥ bs.size
h✝ : bs.size < (extract.loop as (size + 1) start bs).size
h' : optParam (start + bs.size - bs.size < as.size) ⋯
this : bs.size < (extract.loop as size (start + 1) (bs.push as[start])).size
heq : (extract.loop as (size + 1) start bs)[bs.size] = (extract.loop as size (start + 1) (bs.push as[start]))[bs.size]
h₁ : bs.size < (bs.push as[start]).size
h₂ : bs.size < (extract.loop as size (start + 1) (bs.push as[start])).size
h : (extract.loop as size (start + 1) (bs.push as[start]))[bs.size] = as[start]
⊢ start = start + bs.size - bs.size

Tactic:
rw [Nat.add_sub_cancel]

Result:
no goals

Proof state:
α : Type u_1
i : Nat
as bs : Array α
size start : Nat
hge : i ≥ bs.size
h : i < (extract.loop as size start bs).size
h' : optParam (start + i - bs.size < as.size) ⋯
⊢ (extract.loop as size start bs)[i] = as[start + i - bs.size]

Tactic:
induction size using Nat.recAux generalizing start bs with
| zero =>
  rw [size_extract_loop, Nat.zero_min, Nat.add_zero] at h
  omega
| succ size ih =>
  have : start < as.size := by
    apply Nat.lt_of_le_of_lt (Nat.le_add_right start (i - bs.size))
    rwa [← Nat.add_sub_assoc hge]
  have : i < (extract.loop as size (start+1) (bs.push as[start])).size := by
    rwa [← extract_loop_succ]
  have heq : (extract.loop as (size+1) start bs)[i] =
      (extract.loop as size (start+1) (bs.push as[start]))[i] := by
    congr 1; rw [extract_loop_succ]
  rw [heq]
  if hi : bs.size = i then
    cases hi
    have h₁ : bs.size < (bs.push as[start]).size := by rw [size_push]; exact Nat.lt_succ_self ..
    have h₂ : bs.size < (extract.loop as size (start+1) (bs.push as[start])).size := by
      rw [size_extract_loop]; apply Nat.lt_of_lt_of_le h₁; exact Nat.le_add_right ..
    have h : (extract.loop as size (start + 1) (push bs as[start]))[bs.size] = as[start] := by
      rw [getElem_extract_loop_lt as (bs.push as[start]) size (start+1) h₁ h₂, getElem_push_eq]
    rw [h]; congr; rw [Nat.add_sub_cancel]
  else
    have hge : bs.size + 1 ≤ i := Nat.lt_of_le_of_ne hge hi
    rw [ih (bs.push as[start]) (start+1) ((size_push ..).symm ▸ hge)]
    congr 1; rw [size_push, Nat.add_right_comm, Nat.add_sub_add_right]

Result:
no goals

Proof state:
α : Type u_1
i : Nat
as : Array α
size : Nat
ih :
  ∀ (bs : Array α) (start : Nat) (hge : i ≥ bs.size) (h : i < (extract.loop as size start bs).size)
    (h' : optParam (start + i - bs.size < as.size) ⋯), (extract.loop as size start bs)[i] = as[start + i - bs.size]
bs : Array α
start : Nat
hge : i ≥ bs.size
h : i < (extract.loop as (size + 1) start bs).size
h' : optParam (start + i - bs.size < as.size) ⋯
this : start < as.size
⊢ i < (extract.loop as size (start + 1) (bs.push as[start])).size

Tactic:
rwa [← extract_loop_succ]

Result:
no goals

Proof state:
case refl
α : Type u_1
as : Array α
size : Nat
bs : Array α
start : Nat
this✝ : start < as.size
ih :
  ∀ (bs_1 : Array α) (start : Nat) (hge : bs.size ≥ bs_1.size) (h : bs.size < (extract.loop as size start bs_1).size)
    (h' : optParam (start + bs.size - bs_1.size < as.size) ⋯),
    (extract.loop as size start bs_1)[bs.size] = as[start + bs.size - bs_1.size]
hge : bs.size ≥ bs.size
h✝ : bs.size < (extract.loop as (size + 1) start bs).size
h' : optParam (start + bs.size - bs.size < as.size) ⋯
this : bs.size < (extract.loop as size (start + 1) (bs.push as[start])).size
heq : (extract.loop as (size + 1) start bs)[bs.size] = (extract.loop as size (start + 1) (bs.push as[start]))[bs.size]
h₁ : bs.size < (bs.push as[start]).size
h₂ : bs.size < (extract.loop as size (start + 1) (bs.push as[start])).size
h : (extract.loop as size (start + 1) (bs.push as[start]))[bs.size] = as[start]
⊢ as[start] = as[start + bs.size - bs.size]

Tactic:
congr

Result:
case refl.e_i
α : Type u_1
as : Array α
size : Nat
bs : Array α
start : Nat
this✝ : start < as.size
ih :
  ∀ (bs_1 : Array α) (start : Nat) (hge : bs.size ≥ bs_1.size) (h : bs.size < (extract.loop as size start bs_1).size)
    (h' : optParam (start + bs.size - bs_1.size < as.size) ⋯),
    (extract.loop as size start bs_1)[bs.size] = as[start + bs.size - bs_1.size]
hge : bs.size ≥ bs.size
h✝ : bs.size < (extract.loop as (size + 1) start bs).size
h' : optParam (start + bs.size - bs.size < as.size) ⋯
this : bs.size < (extract.loop as size (start + 1) (bs.push as[start])).size
heq : (extract.loop as (size + 1) start bs)[bs.size] = (extract.loop as size (start + 1) (bs.push as[start]))[bs.size]
h₁ : bs.size < (bs.push as[start]).size
h₂ : bs.size < (extract.loop as size (start + 1) (bs.push as[start])).size
h : (extract.loop as size (start + 1) (bs.push as[start]))[bs.size] = as[start]
⊢ start = start + bs.size - bs.size

Proof state:
α : Type u_1
i : Nat
as : Array α
size : Nat
ih :
  ∀ (bs : Array α) (start : Nat) (hge : i ≥ bs.size) (h : i < (extract.loop as size start bs).size)
    (h' : optParam (start + i - bs.size < as.size) ⋯), (extract.loop as size start bs)[i] = as[start + i - bs.size]
bs : Array α
start : Nat
hge : i ≥ bs.size
h : i < (extract.loop as (size + 1) start bs).size
h' : optParam (start + i - bs.size < as.size) ⋯
⊢ start + (i - bs.size) < as.size

Tactic:
rwa [← Nat.add_sub_assoc hge]

Result:
no goals