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

Tactic:
rw [← heq]

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 curr

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
hlt : curr < w
hgo :
  (let res := aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩);
    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

Tactic:
dsimp only at hgo

Result:
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
⊢ ⟦assign.toAIGAssignment, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = (eval assign (var a)).getLsbD 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),
    curr ≤ idx →
      ⟦assign.toAIGAssignment,
          { aig := (go aig w a curr s hcurr).aig, ref := (go aig w a curr s hcurr).vec.get idx hidx1 }⟧ =
        (eval assign (var a)).getLsbD idx

Tactic:
intro idx hidx1 hidx2

Result:
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
⊢ ⟦assign.toAIGAssignment,
      { aig := (go aig w a curr s hcurr).aig, ref := (go aig w a curr s hcurr).vec.get idx hidx1 }⟧ =
    (eval assign (var a)).getLsbD idx

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 := res.aig, ref := res.vec.get idx hidx1 }⟧ = (eval assign (var a)).getLsbD idx

Tactic:
rw [← hgo]

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
⊢ ⟦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

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 }⟧ =
    (eval assign (var a)).getLsbD idx

Tactic:
simp only [eval_var]

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
⊢ ⟦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

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 := (aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).aig,
        ref := { gate := ((aig.mkAtomCached (BVBit.mk a ⟨curr, hlt⟩)).ref.cast ⋯).gate, hgate := ?inl.hstart } }⟧ =
    (eval assign (var a)).getLsbD curr

Tactic:
simp [hlt]

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
⊢ (eval assign (var a)).getLsbD idx = (BitVec.truncate w (assign.get a).bv).getLsbD idx

Tactic:
simp

Result:
no goals