-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ZeroExtend.lean
theorem go_denote_eq (aig : AIG α) (w : Nat) (input : AIG.RefVec aig w) (newWidth curr : Nat)
    (hcurr : curr ≤ newWidth) (s : AIG.RefVec aig curr) (assign : α → Bool) :
    ∀ (idx : Nat) (hidx1 : idx < newWidth),
        curr ≤ idx
          →
        ⟦
          (go aig w input newWidth curr hcurr s).aig,
          (go aig w input newWidth curr hcurr s).vec.get idx hidx1,
          assign
        ⟧
          =
        if hidx : idx < w then
           ⟦aig, input.get idx hidx, assign⟧
        else
           false

Proof state:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ⟦assign,
      {
        aig :=
          (go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
              ((s.cast ⋯).push (aig.mkConstCached false).ref)).aig,
        ref := (aig.mkConstCached false).ref.cast ⋯ }⟧ =
    false

Tactic:
rw [go_denote_mem_prefix]

Result:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ⟦assign,
      { aig := (aig.mkConstCached false).aig,
        ref := { gate := ((aig.mkConstCached false).ref.cast ⋯).gate, hgate := ?hstart } }⟧ =
    false

case hstart
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ((aig.mkConstCached false).ref.cast ⋯).gate < (aig.mkConstCached false).aig.decls.size

Proof state:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = false

Tactic:
rw [← hgo]

Result:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ⟦assign,
      {
        aig :=
          (go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
              ((s.cast ⋯).push (aig.mkConstCached false).ref)).aig,
        ref :=
          (go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
                  ((s.cast ⋯).push (aig.mkConstCached false).ref)).vec.get
            idx hidx1 }⟧ =
    false

Proof state:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    if hidx : idx < w then ⟦assign, { aig := aig, ref := input.get idx hidx }⟧ else false

Tactic:
simp only [hsplit, ↓reduceDIte]

Result:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
heq : curr = idx
hsplit : ¬idx < w
hgo :
  go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
      ((s.cast ⋯).push (aig.mkConstCached false).ref) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ = false

Proof state:
case isTrue.inr.isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝² : curr < newWidth
h✝¹ : curr < idx
h✝ : curr < w
hgo : go aig w input newWidth (curr + 1) ⋯ (s.push (input.get curr h✝)) = res
⊢ ⟦assign,
      { aig := (go aig w input newWidth (curr + 1) ⋯ (s.push (input.get curr h✝))).aig,
        ref := (go aig w input newWidth (curr + 1) ⋯ (s.push (input.get curr h✝))).vec.get idx hidx1 }⟧ =
    if hidx : idx < w then ⟦assign, { aig := aig, ref := input.get idx hidx }⟧ else false

Tactic:
rw [go_denote_eq]

Result:
case isTrue.inr.isTrue.a
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝² : curr < newWidth
h✝¹ : curr < idx
h✝ : curr < w
hgo : go aig w input newWidth (curr + 1) ⋯ (s.push (input.get curr h✝)) = res
⊢ curr + 1 ≤ idx

Proof state:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
hgo :
  (if hcurr2 : curr < w then
      let s := s.push (input.get curr hcurr2);
      go aig w input newWidth (curr + 1) ⋯ s
    else
      let res := aig.mkConstCached false;
      let aig_1 := res.aig;
      let zeroRef := res.ref;
      let_fun hcast := ⋯;
      let input := input.cast hcast;
      let s := s.cast hcast;
      let s := s.push zeroRef;
      go aig_1 w input newWidth (curr + 1) ⋯ s) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    if hidx : idx < w then ⟦assign, { aig := aig, ref := input.get idx hidx }⟧ else false

Tactic:
dsimp only at hgo

Result:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefVec w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefVec curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefVecEntry α newWidth
h✝ : curr < newWidth
hgo :
  (if hcurr2 : curr < w then go aig w input newWidth (curr + 1) ⋯ (s.push (input.get curr hcurr2))
    else
      go (aig.mkConstCached false).aig w (input.cast ⋯) newWidth (curr + 1) ⋯
        ((s.cast ⋯).push (aig.mkConstCached false).ref)) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    if hidx : idx < w then ⟦assign, { aig := aig, ref := input.get idx hidx }⟧ else false