-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Add.lean
theorem go_get_aux (aig : AIG α) (curr : Nat) (hcurr : curr ≤ w) (cin : Ref aig)
    (s : AIG.RefVec aig curr) (lhs rhs : AIG.RefVec aig w) :
    -- `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 lhs rhs curr hcurr cin s).vec.get idx (by omega)
          =
        (s.get idx hidx).cast hfoo

Proof state:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
hgo :
  (if hidx : curr < w then
      let lin := lhs.get curr hidx;
      let rin := rhs.get curr hidx;
      let res := mkFullAdder aig { lhs := lin, rhs := rin, cin := cin };
      let aig_1 := res.aig;
      let outRef := res.out;
      let carryRef := res.cout;
      let s := s.cast ⋯;
      let lhs := lhs.cast ⋯;
      let rhs := rhs.cast ⋯;
      let s := s.push outRef;
      go aig_1 lhs rhs (curr + 1) ⋯ carryRef 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:
dsimp only at hgo

Result:
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
hgo :
  (if hidx : curr < w then
      go (mkFullAdder aig { lhs := lhs.get curr hidx, rhs := rhs.get curr hidx, cin := cin }).aig (lhs.cast ⋯)
        (rhs.cast ⋯) (curr + 1) ⋯
        (mkFullAdder aig { lhs := lhs.get curr hidx, rhs := rhs.get curr hidx, cin := cin }).cout
        ((s.cast ⋯).push (mkFullAdder aig { lhs := lhs.get curr hidx, rhs := rhs.get curr hidx, cin := cin }).out)
    else { 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 isFalse
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : aig.decls.size ≤ { aig := aig, vec := ⋯ ▸ s }.aig.decls.size),
    { aig := aig, vec := ⋯ ▸ s }.vec.get idx ⋯ = (s.get idx hidx).cast hfoo

Tactic:
simp only [Nat.le_refl, get, Ref.gate_cast, Ref.mk.injEq, true_implies]

Result:
case isFalse
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : True), (⋯ ▸ s).get idx ⋯ = (s.get idx hidx).cast ⋯

Proof state:
case isTrue.hidx
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
h✝ : curr < w
hgo :
  go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
      ((s.cast ⋯).push (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out) =
    res
hfoo :
  aig.decls.size ≤
    (go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
            (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
            ((s.cast ⋯).push
              (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out)).aig.decls.size
⊢ idx < curr

Tactic:
assumption

Result:
no goals

Proof state:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
h✝ : curr < w
hgo :
  go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
      ((s.cast ⋯).push (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out) =
    res
⊢ ∀
    (hfoo :
      aig.decls.size ≤
        (go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯)
                (rhs.cast ⋯) (curr + 1) ⋯
                (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
                ((s.cast ⋯).push
                  (mkFullAdder aig
                      { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out)).aig.decls.size),
    (go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
              (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
              ((s.cast ⋯).push
                (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out)).vec.get
        idx ⋯ =
      (s.get idx hidx).cast hfoo

Tactic:
intro hfoo

Result:
case isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
h✝ : curr < w
hgo :
  go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
      (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
      ((s.cast ⋯).push (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out) =
    res
hfoo :
  aig.decls.size ≤
    (go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
            (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
            ((s.cast ⋯).push
              (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out)).aig.decls.size
⊢ (go (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).aig (lhs.cast ⋯) (rhs.cast ⋯)
            (curr + 1) ⋯ (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).cout
            ((s.cast ⋯).push
              (mkFullAdder aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝, cin := cin }).out)).vec.get
      idx ⋯ =
    (s.get idx hidx).cast hfoo

Proof state:
case isFalse
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w : Nat
aig : AIG α
curr : Nat
hcurr : curr ≤ w
cin : aig.Ref
s : aig.RefVec curr
lhs rhs : aig.RefVec w
idx : Nat
hidx : idx < curr
res : RefVecEntry α w
h✝ : ¬curr < w
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : True), (⋯ ▸ s).get idx ⋯ = (s.get idx hidx).cast ⋯

Tactic:
obtain rfl : curr = w := by omega

Result:
case isFalse
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
curr : Nat
cin : aig.Ref
s : aig.RefVec curr
idx : Nat
hidx : idx < curr
hcurr : curr ≤ curr
lhs rhs : aig.RefVec curr
res : RefVecEntry α curr
h✝ : ¬curr < curr
hgo : { aig := aig, vec := ⋯ ▸ s } = res
⊢ ∀ (hfoo : True), (⋯ ▸ s).get idx ⋯ = (s.get idx hidx).cast ⋯