-- 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 ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
rw [← hgo]

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),
    (go (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).aig w a (curr + 1)
              ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩)).ref) ⋯).vec.get
        idx ⋯ =
      (s.get idx hidx).cast hfoo

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 :
  (let_fun hcurr := ⋯;
    { aig := aig, vec := hcurr ▸ s }) =
    res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
dsimp only at 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 ≤ res.aig.decls.size), res.vec.get idx ⋯ = (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 ⋯).get idx ?isTrue.hidx).gate = (s.get idx hidx).gate

Tactic:
rw [AIG.RefVec.get_cast]

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.get idx ?isTrue.hidx).cast ⋯).gate = (s.get idx hidx).gate

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

Proof state:
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
hgo :
  (if hcurr : curr < w then
      let res := aig.mkAtomCached (BVBit.mk a ⟨curr, hcurr⟩);
      let aig_1 := res.aig;
      let bitRef := res.ref;
      let s := s.cast ⋯;
      let s := s.push bitRef;
      go aig_1 w a (curr + 1) s ⋯
    else
      let_fun hcurr := ⋯;
      { aig := aig, vec := hcurr ▸ s }) =
    res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
split at hgo

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 :
  (let res := aig.mkAtomCached (BVBit.mk a ⟨curr, h✝⟩);
    let aig_1 := res.aig;
    let bitRef := res.ref;
    let s := s.cast ⋯;
    let s := s.push bitRef;
    go aig_1 w a (curr + 1) s ⋯) =
    res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

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 :
  (let_fun hcurr := ⋯;
    { aig := aig, vec := hcurr ▸ s }) =
    res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Proof state:
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
⊢ ∀ (hfoo : aig.decls.size ≤ (go aig w a curr s hcurr).aig.decls.size),
    (go aig w a curr s hcurr).vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
generalize hgo : go aig w a curr s hcurr = res

Result:
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
hgo : go aig w a curr s hcurr = res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Proof state:
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
hfoo : aig.decls.size ≤ (go aig w a curr s hcurr).aig.decls.size
⊢ idx < w

Tactic:
omega

Result:
no goals

Proof state:
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
hgo : go aig w a curr s hcurr = res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
unfold go at hgo

Result:
w : Nat
aig : AIG BVBit
a curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
res : RefVecEntry BVBit w
hgo :
  (if hcurr : curr < w then
      let res := aig.mkAtomCached (BVBit.mk a ⟨curr, hcurr⟩);
      let aig_1 := res.aig;
      let bitRef := res.ref;
      let s := s.cast ⋯;
      let s := s.push bitRef;
      go aig_1 w a (curr + 1) s ⋯
    else
      let_fun hcurr := ⋯;
      { aig := aig, vec := hcurr ▸ s }) =
    res
⊢ ∀ (hfoo : aig.decls.size ≤ res.aig.decls.size), res.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Proof state:
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:
apply go_le_size

Result:
no goals