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

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