match Nat.lt_trichotomy i nfa.nodes.size with
| .inl lt =>
  have : nfa'[i] = nfa[i] := by
    have : i < placeholder.val.nodes.size :=
      Nat.lt_trans lt placeholder.property
    have : i < compiled.val.nodes.size :=
      Nat.lt_trans this compiled.property
    calc nfa'[i]
      _ = compiled.val[i] := by
        simp [eq₄, NFA.get_eq_nodes_get, eq₃]
        rw [Array.get_set_ne]
        simp
        exact Nat.ne_of_gt lt
      _ = placeholder.val[i] := by apply pushRegex_get_lt eq₂.symm
      _ = nfa[i] := by
        simp [eq₁]
        apply pushNode_get_lt
  rw [this]
  exact h₂ i lt
| .inr (.inl eq) =>
  have : nfa'[i] = .split compiled.val.start next := by
    simp [eq₄, NFA.get_eq_nodes_get, eq₃]
    rw [Array.get_set]
    . simp [eq]
    . calc
        i = nfa.nodes.size := eq
        _ < placeholder.val.nodes.size := placeholder.property
        _ < compiled.val.nodes.size := compiled.property
  simp [this]
  exact Nat.ne_of_gt (eq ▸ h₁)
| .inr (.inr gt) =>
  have : i < compiled.val.nodes.size := by
    simp [eq₄, eq₃] at isLt
    exact isLt
  have : nfa'[i] = compiled.val[i] := by
    simp [eq₄, NFA.get_eq_nodes_get, eq₃]
    rw [Array.get_set_ne]
    simp
    exact Nat.ne_of_lt gt
  rw [this]
  apply ih eq₂.symm (Nat.zero_lt_of_lt placeholder.property) ?_ i (by assumption)
  intro i isLt
  simp [eq₁] at isLt
  cases Nat.eq_or_lt_of_le isLt with
  | inl eq =>
    simp at eq
    simp [eq₁, eq, -List.length_eq_zero]
    exact Nat.ne_zero_iff_zero_lt.mpr h₁
  | inr lt =>
    have lt := Nat.lt_of_succ_lt_succ lt
    simp [eq₁, pushNode_get_lt _ lt]
    exact h₂ i lt
r : Data.Expr
ih :
  ∀ {nfa : NFA} {next : Fin nfa.nodes.size} {result : { nfa' // nfa.nodes.size < nfa'.nodes.size }},
    nfa.pushRegex next r = result →
      0 < nfa.nodes.size →
        (∀ (i : ℕ) (isLt : i < nfa.nodes.size), nfa[i] = Node.done ↔ i = 0) →
          ∀ (i : ℕ) (isLt : i < (↑result).nodes.size), (↑result)[i] = Node.done ↔ i = 0
nfa : NFA
next : Fin nfa.nodes.size
h₁ : 0 < nfa.nodes.size
h₂ : ∀ (i : ℕ) (isLt : i < nfa.nodes.size), nfa[i] = Node.done ↔ i = 0
placeholder : { nfa' // nfa.nodes.size < nfa'.nodes.size }
compiled : { nfa' // (↑placeholder).nodes.size < nfa'.nodes.size }
patched : Array Node
nfa' : NFA
isLt✝ : nfa.nodes.size < patched.size
inBounds : ∀ (i : Fin patched.size), patched[↑i].inBounds patched.size
property : nfa.nodes.size < nfa'.nodes.size
eq₁ : placeholder = nfa.pushNode Node.fail ⋯
eq₂ : compiled = (↑placeholder).pushRegex ⟨nfa.nodes.size, ⋯⟩ r
eq₃ : patched = (↑compiled).nodes.set ⟨nfa.nodes.size, ⋯⟩ (Node.split ↑(↑compiled).start ↑next)
eq₄ : nfa' = { nodes := patched, start := ⟨nfa.nodes.size, isLt✝⟩, inBounds := inBounds }
eq : nfa.pushRegex next r.star = ⟨nfa', property⟩
i : ℕ
isLt : i < nfa'.nodes.size
⊢ nfa'[i] = Node.done ↔ i = 0
no goals