. dsimp at hgo
  cases Nat.eq_or_lt_of_le hidx2 with
  | inl heq =>
    split at hgo
    . next hsplit =>
      rw [heq] at hsplit
      simp only [hsplit, ↓reduceDite]
      rw [← hgo]
      rw [go_getRef]
      rw [AIG.RefStream.getRef_push_ref_eq']
      . rw [go_denote_mem_prefix]
        . simp [heq]
        . simp [Ref.hgate]
      . omega
    . next hsplit =>
      rw [heq] at hsplit
      simp only [hsplit, ↓reduceDite]
      rw [← hgo]
      rw [go_getRef]
      rw [AIG.RefStream.getRef_push_ref_eq']
      . rw [go_denote_mem_prefix]
        . simp [heq]
        . simp [Ref.hgate]
      . omega
  | inr =>
    split at hgo
    . rw [← hgo]
      rw [go_eq_eval_getLsb]
      omega
    . rw [← hgo]
      rw [go_eq_eval_getLsb]
      . split
        . omega
        . rfl
      . omega
case isTrue
α : Type
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefStream w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefStream curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefStreamEntry α newWidth
h✝ : curr < newWidth
hgo :
  (if hcurr2 : curr < w then
      let s := s.pushRef (input.getRef 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.pushRef zeroRef;
      go aig_1 w input newWidth (curr + 1) ⋯ s) =
    res
⊢ ⟦{ aig := res.aig, ref := res.stream.getRef idx hidx1 }, assign⟧ =
    if hidx : idx < w then ⟦{ aig := aig, ref := input.getRef idx hidx }, assign⟧ else false

case isFalse
α : Type
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefStream w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefStream curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefStreamEntry α newWidth
h✝ : ¬curr < newWidth
hgo :
  (let_fun hcurr := ⋯;
    { aig := aig, stream := hcurr ▸ s }) =
    res
⊢ ⟦{ aig := res.aig, ref := res.stream.getRef idx hidx1 }, assign⟧ =
    if hidx : idx < w then ⟦{ aig := aig, ref := input.getRef idx hidx }, assign⟧ else false
case isFalse
α : Type
inst✝² : BEq α
inst✝¹ : Hashable α
inst✝ : DecidableEq α
aig : AIG α
w : Nat
input : aig.RefStream w
newWidth curr : Nat
hcurr : curr ≤ newWidth
s : aig.RefStream curr
assign : α → Bool
idx : Nat
hidx1 : idx < newWidth
hidx2 : curr ≤ idx
res : RefStreamEntry α newWidth
h✝ : ¬curr < newWidth
hgo :
  (let_fun hcurr := ⋯;
    { aig := aig, stream := hcurr ▸ s }) =
    res
⊢ ⟦{ aig := res.aig, ref := res.stream.getRef idx hidx1 }, assign⟧ =
    if hidx : idx < w then ⟦{ aig := aig, ref := input.getRef idx hidx }, assign⟧ else false