-- 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:
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
⊢ (extract.loop as size (start + 1) (bs.push as[start]))[bs.size] = as[start + bs.size - bs.size]

Tactic:
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]

Result:
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]
⊢ (extract.loop as size (start + 1) (bs.push as[start]))[bs.size] = as[start + bs.size - bs.size]

Proof state:
α : 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]
⊢ bs.size < (bs.push as[start]).size

Tactic:
rw [size_push]

Result:
α : 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]
⊢ bs.size < bs.size + 1

Proof state:
α : 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]
⊢ bs.size < bs.size + 1

Tactic:
exact Nat.lt_succ_self ..

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
this : i < (extract.loop as size (start + 1) (bs.push as[start])).size
heq : (extract.loop as (size + 1) start bs)[i] = (extract.loop as size (start + 1) (bs.push as[start]))[i]
hi : ¬bs.size = i
hge : bs.size + 1 ≤ i
⊢ as[start + 1 + i - (bs.push as[start]).size] = as[start + i - bs.size]

Tactic:
congr 1

Result:
case e_i
α : 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
this : i < (extract.loop as size (start + 1) (bs.push as[start])).size
heq : (extract.loop as (size + 1) start bs)[i] = (extract.loop as size (start + 1) (bs.push as[start]))[i]
hi : ¬bs.size = i
hge : bs.size + 1 ≤ i
⊢ start + 1 + i - (bs.push as[start]).size = start + i - bs.size

Proof state:
case succ
α : 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
this : i < (extract.loop as size (start + 1) (bs.push as[start])).size
heq : (extract.loop as (size + 1) start bs)[i] = (extract.loop as size (start + 1) (bs.push as[start]))[i]
⊢ (extract.loop as size (start + 1) (bs.push as[start]))[i] = as[start + i - bs.size]

Tactic:
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