-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Var.lean
theorem go_get_aux (aig : AIG BVBit) (a : Nat) (curr : Nat) (hcurr : curr ≤ w)
    (s : AIG.RefVec aig curr) :
    -- `hfoo` makes it possible to `generalize` below. With a concrete proof term this
    -- `generalize` would produce a type incorrect term as the proof term would talk about
    -- a `go` application instead of the fresh variable.
    ∀ (idx : Nat) (hidx : idx < curr) (hfoo),
        (go aig w a curr s hcurr).vec.get idx (by omega) = (s.get idx hidx).cast hfoo

Proof state:
case isTrue
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ (((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref).get idx ?isTrue.hidx).cast ?isTrue.hfoo =
    (s.get idx hidx).cast hfoo

case isTrue.hidx
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ idx < curr + 1

case isTrue.hfoo
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size

Tactic:
rw [AIG.RefVec.get_push_ref_lt]

Result:
case isTrue
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ ((s.cast ⋯).get idx ?isTrue.hidx).cast ?isTrue.hfoo = (s.get idx hidx).cast hfoo

case isTrue.hidx
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ idx < curr

case isTrue.hfoo
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size

Proof state:
case isTrue
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ ((s.cast ⋯).get idx ?isTrue.hidx).cast ?isTrue.hfoo = (s.get idx hidx).cast hfoo

Tactic:
simp only [Ref.cast, Ref.mk.injEq]

Result:
case isTrue
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ ((s.cast ⋯).get idx ?isTrue.hidx).gate = (s.get idx hidx).gate

Proof state:
case isFalse
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
rw [← hgo]

Result:
case isFalse
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : aig.decls.size ≤ { aig := aig, vec := ⋯ ▸ s }.aig.decls.size),
    { aig := aig, vec := ⋯ ▸ s }.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Proof state:
case isTrue.hidx
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯ =
    res
hfoo :
  aig.decls.size ≤
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
            ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).aig.decls.size
⊢ idx < curr

Tactic:
assumption

Result:
no goals

Proof state:
case isFalse
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : aig.decls.size ≤ { aig := aig, vec := ⋯ ▸ s }.aig.decls.size),
    { aig := aig, vec := ⋯ ▸ s }.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
simp only [Nat.le_refl, get, Ref.gate_cast, Ref.mk.injEq, true_implies]

Result:
case isFalse
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : True), (⋯ ▸ s).get idx ⋯ = (s.get idx hidx).cast ⋯