-- Mathlib/.lake/packages/lean4/src/lean/Std/Sat/AIG/RefVecOperator/Zip.lean
theorem denote_go {aig : AIG α} (curr : Nat) (hcurr : curr ≤ len) (s : RefVec aig curr)
    (lhs rhs : RefVec aig len) (f : (aig : AIG α) → BinaryInput aig → Entrypoint α)
    [LawfulOperator α BinaryInput f] [chainable : LawfulZipOperator α f] :
    ∀ (idx : Nat) (hidx1 : idx < len),
      curr ≤ idx
        →
      ⟦
        (go aig curr s hcurr lhs rhs f).aig,
        (go aig curr s hcurr lhs rhs f).vec.get idx hidx1,
        assign
      ⟧
        =
      ⟦f aig ⟨lhs.get idx hidx1, rhs.get idx hidx1⟩, assign⟧

Proof state:
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
hgo :
  (if hidx : curr < len then
      let res := f aig { lhs := lhs.get curr hidx, rhs := rhs.get curr hidx };
      let aig_1 := res.aig;
      let newRef := res.ref;
      let_fun this := ⋯;
      let s := s.cast this;
      let s := s.push newRef;
      go aig_1 (curr + 1) s ⋯ (lhs.cast this) (rhs.cast this) f
    else
      let_fun this := ⋯;
      { aig := aig, vec := this ▸ s }) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    ⟦assign, f aig { lhs := lhs.get idx hidx1, rhs := rhs.get idx hidx1 }⟧

Tactic:
split at hgo

Result:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : curr < len
hgo :
  (let res := f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ };
    let aig_1 := res.aig;
    let newRef := res.ref;
    let_fun this := ⋯;
    let s := s.cast this;
    let s := s.push newRef;
    go aig_1 (curr + 1) s ⋯ (lhs.cast this) (rhs.cast this) f) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    ⟦assign, f aig { lhs := lhs.get idx hidx1, rhs := rhs.get idx hidx1 }⟧

case isFalse
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : ¬curr < len
hgo :
  (let_fun this := ⋯;
    { aig := aig, vec := this ▸ s }) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    ⟦assign, f aig { lhs := lhs.get idx hidx1, rhs := rhs.get idx hidx1 }⟧

Proof state:
case isTrue.inr
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : curr < len
hgo :
  go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
      ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯) f =
    res
hlt : curr < idx
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx1 }⟧ =
    ⟦assign, f aig { lhs := lhs.get idx hidx1, rhs := rhs.get idx hidx1 }⟧

Tactic:
rw [← hgo]

Result:
case isTrue.inr
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : curr < len
hgo :
  go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
      ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯) f =
    res
hlt : curr < idx
⊢ ⟦assign,
      {
        aig :=
          (go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
              ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯)
              (rhs.cast ⋯) f).aig,
        ref :=
          (go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
                  ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯)
                  (rhs.cast ⋯) f).vec.get
            idx hidx1 }⟧ =
    ⟦assign, f aig { lhs := lhs.get idx hidx1, rhs := rhs.get idx hidx1 }⟧

Proof state:
case isTrue.inl
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : curr < len
hgo :
  go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
      ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯) f =
    res
heq : curr = idx
⊢ ⟦assign,
      {
        aig :=
          (go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
              ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯)
              (rhs.cast ⋯) f).aig,
        ref := (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref.cast ⋯ }⟧ =
    ⟦assign, f aig { lhs := lhs.get curr ⋯, rhs := rhs.get curr ⋯ }⟧

Tactic:
rw [go_denote_mem_prefix]

Result:
case isTrue.inl
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : curr < len
hgo :
  go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
      ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯) f =
    res
heq : curr = idx
⊢ ⟦assign,
      { aig := (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig,
        ref :=
          { gate := ((f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref.cast ⋯).gate,
            hgate := ?isTrue.inl.hstart } }⟧ =
    ⟦assign, f aig { lhs := lhs.get curr ⋯, rhs := rhs.get curr ⋯ }⟧

case isTrue.inl.hstart
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
assign : α → Bool
aig : AIG α
curr : Nat
hcurr : curr ≤ len
s : aig.RefVec curr
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
idx : Nat
hidx1 : idx < len
hidx2 : curr ≤ idx
res : RefVecEntry α len
h✝ : curr < len
hgo :
  go (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig (curr + 1)
      ((s.cast ⋯).push (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯) f =
    res
heq : curr = idx
⊢ ((f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).ref.cast ⋯).gate <
    (f aig { lhs := lhs.get curr h✝, rhs := rhs.get curr h✝ }).aig.decls.size