-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Carry.lean
theorem go_decl_eq {aig : AIG α} {cin} {lhs rhs : AIG.RefVec aig w} :
    ∀ (idx : Nat) (h1) (h2),
        (go aig lhs rhs curr cin).aig.decls[idx]'h2 = aig.decls[idx]'h1

Proof state:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
h✝ : curr < w
hgo :
  go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref =
    res
⊢ ∀ (idx : Nat) (h1 : idx < aig.decls.size) (h2 : idx < res.aig.decls.size), res.aig.decls[idx] = aig.decls[idx]

Tactic:
rw [← hgo]

Result:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
h✝ : curr < w
hgo :
  go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref =
    res
⊢ ∀ (idx : Nat) (h1 : idx < aig.decls.size)
    (h2 :
      idx <
        (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
                (rhs.cast ⋯) (curr + 1)
                (mkFullAdderCarry aig
                    { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls.size),
    (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
              (rhs.cast ⋯) (curr + 1)
              (mkFullAdderCarry aig
                  { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls[idx] =
      aig.decls[idx]

Proof state:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
⊢ ∀ (idx : Nat) (h1 : idx < aig.decls.size) (h2 : idx < (go aig lhs rhs curr cin).aig.decls.size),
    (go aig lhs rhs curr cin).aig.decls[idx] = aig.decls[idx]

Tactic:
generalize hgo : go aig lhs rhs curr cin = res

Result:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
hgo : go aig lhs rhs curr cin = res
⊢ ∀ (idx : Nat) (h1 : idx < aig.decls.size) (h2 : idx < res.aig.decls.size), res.aig.decls[idx] = aig.decls[idx]

Proof state:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
hgo :
  (if hidx : curr < w then
      let lin := lhs.get curr hidx;
      let rin := rhs.get curr hidx;
      let res := mkFullAdderCarry aig { lhs := lin, rhs := rin, cin := cin };
      let_fun this := ⋯;
      let aig_1 := res.aig;
      let carryRef := res.ref;
      let lhs := lhs.cast this;
      let rhs := rhs.cast this;
      go aig_1 lhs rhs (curr + 1) carryRef
    else { aig := aig, ref := cin }) =
    res
⊢ ∀ (idx : Nat) (h1 : idx < aig.decls.size) (h2 : idx < res.aig.decls.size), res.aig.decls[idx] = aig.decls[idx]

Tactic:
dsimp only at hgo

Result:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
hgo :
  (if hidx : curr < w then
      go (mkFullAdderCarry aig { lhs := lhs.get curr hidx, rhs := rhs.get curr hidx, cin := cin }).aig (lhs.cast ⋯)
        (rhs.cast ⋯) (curr + 1)
        (mkFullAdderCarry aig { lhs := lhs.get curr hidx, rhs := rhs.get curr hidx, cin := cin }).ref
    else { aig := aig, ref := cin }) =
    res
⊢ ∀ (idx : Nat) (h1 : idx < aig.decls.size) (h2 : idx < res.aig.decls.size), res.aig.decls[idx] = aig.decls[idx]

Proof state:
case isTrue.h2.h
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
h✝ : curr < w
hgo :
  go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref =
    res
idx✝ : Nat
h1✝ : idx✝ < aig.decls.size
h2✝ :
  idx✝ <
    (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
            (rhs.cast ⋯) (curr + 1)
            (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls.size
⊢ idx✝ < aig.decls.size

Tactic:
assumption

Result:
no goals

Proof state:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
h✝ : curr < w
hgo :
  go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref =
    res
idx✝ : Nat
h1✝ : idx✝ < aig.decls.size
h2✝ :
  idx✝ <
    (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
            (rhs.cast ⋯) (curr + 1)
            (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls.size
⊢ (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
            (rhs.cast ⋯) (curr + 1)
            (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls[idx✝] =
    aig.decls[idx✝]

Tactic:
rw [go_decl_eq]

Result:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
h✝ : curr < w
hgo :
  go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref =
    res
idx✝ : Nat
h1✝ : idx✝ < aig.decls.size
h2✝ :
  idx✝ <
    (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
            (rhs.cast ⋯) (curr + 1)
            (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls.size
⊢ (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig.decls[idx✝] =
    aig.decls[idx✝]

case isTrue.h1
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w curr : Nat
aig : AIG α
cin : aig.Ref
lhs rhs : aig.RefVec w
res : AIG.Entrypoint α
h✝ : curr < w
hgo :
  go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref =
    res
idx✝ : Nat
h1✝ : idx✝ < aig.decls.size
h2✝ :
  idx✝ <
    (go (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
            (rhs.cast ⋯) (curr + 1)
            (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).ref).aig.decls.size
⊢ idx✝ < (mkFullAdderCarry aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig.decls.size