-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Var.lean
theorem go_denote_eq (aig : AIG BVBit) (a : Nat) (assign : Assignment) (curr : Nat)
    (hcurr : curr ≤ w) (s : AIG.RefVec aig curr) :
    ∀ (idx : Nat) (hidx1 : idx < w),
        curr ≤ idx
          →
        ⟦
          (go aig w a curr s hcurr).aig,
          (go aig w a curr s hcurr).vec.get idx hidx1,
          assign.toAIGAssignment
        ⟧
          =
        ((BVExpr.var (w := w) a).eval assign).getLsbD idx

Proof state:
case inr.a
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
h✝ : curr < idx
⊢ curr + 1 ≤ idx

Tactic:
omega

Result:
no goals

Proof state:
case inr
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
h✝ : curr < idx
⊢ ⟦assign.toAIGAssignment,
      {
        aig :=
          (go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
              ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯).aig,
        ref :=
          (go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
                  ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯).vec.get
            idx hidx1 }⟧ =
    (BitVec.truncate w (assign.get a).bv).getLsbD idx

Tactic:
rw [go_denote_eq]

Result:
case inr
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
h✝ : curr < idx
⊢ (eval assign (var a)).getLsbD idx = (BitVec.truncate w (assign.get a).bv).getLsbD idx

case inr.a
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
h✝ : curr < idx
⊢ curr + 1 ≤ idx

Proof state:
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
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
⊢ ⟦assign.toAIGAssignment, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = (eval assign (var a)).getLsbD idx

Tactic:
split at hgo

Result:
case isTrue
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
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
⊢ ⟦assign.toAIGAssignment, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = (eval assign (var a)).getLsbD idx

case isFalse
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
h✝ : ¬curr < w
hgo :
  (let_fun hcurr := ⋯;
    { aig := aig, vec := hcurr ▸ s }) =
    res
⊢ ⟦assign.toAIGAssignment, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = (eval assign (var a)).getLsbD idx

Proof state:
case inl
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
heq : curr = idx
⊢ ⟦assign.toAIGAssignment,
      {
        aig :=
          (go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
              ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯).aig,
        ref := (((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref).get idx ?inl.hidx).cast ⋯ }⟧ =
    (eval assign (var a)).getLsbD idx

case inl.hidx
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
heq : curr = idx
⊢ idx < curr + 1

Tactic:
rw [AIG.RefVec.get_push_ref_eq']

Result:
case inl
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
heq : curr = idx
⊢ ⟦assign.toAIGAssignment,
      {
        aig :=
          (go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
              ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯).aig,
        ref := (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref.cast ⋯ }⟧ =
    (eval assign (var a)).getLsbD idx

case inl.hidx
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
heq : curr = idx
⊢ idx = curr

Proof state:
case inl
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
heq : curr = idx
⊢ ⟦assign.toAIGAssignment, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = (eval assign (var a)).getLsbD idx

Tactic:
rw [← hgo]

Result:
case inl
w : Nat
aig : AIG BVBit
a : Nat
assign : Assignment
curr : Nat
hcurr : curr ≤ w
s : aig.RefVec curr
idx : Nat
hidx1 : idx < w
hidx2 : curr ≤ idx
res : RefVecEntry BVBit w
hlt : curr < w
hgo :
  go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
      ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯ =
    res
heq : curr = idx
⊢ ⟦assign.toAIGAssignment,
      {
        aig :=
          (go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
              ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯).aig,
        ref :=
          (go (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig w a (curr + 1)
                  ((s.cast ⋯).push (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref) ⋯).vec.get
            idx hidx1 }⟧ =
    (eval assign (var a)).getLsbD idx