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 go aig input distance (curr + 1) ⋯ (s.pushRef (input.getRef (distance + curr) ⋯))
    else
      go (aig.mkConstCached false).aig (input.cast ⋯) distance (curr + 1) ⋯
        ((s.cast ⋯).pushRef (aig.mkConstCached false).ref)) =
    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
no goals