. cases Nat.eq_or_lt_of_le hidx2 with
  | inl heq =>
    split at hgo
    . next hlt =>
      rw [heq] at hlt
      simp only [hlt, ↓reduceDite]
      dsimp at hgo
      rw [← hgo]
      rw [go_getRef]
      rw [AIG.RefStream.getRef_push_ref_eq']
      . simp [heq]
      . omega
    . next hlt =>
      rw [heq] at hlt
      simp only [hlt, ↓reduceDite]
      dsimp at hgo
      rw [← hgo]
      rw [go_getRef]
      rw [AIG.RefStream.getRef_push_ref_eq']
      . simp [heq]
  | inr =>
    split at hgo
    all_goals
      split
      all_goals
        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 : aig.RefStream w
h✝ : curr < w
hgo :
  (if hdist : distance + curr < w then
      let s := s.pushRef (input.getRef (distance + curr) ⋯);
      go input distance (curr + 1) ⋯ s
    else
      let s := s.pushRef (input.getRef (w - 1) ⋯);
      go input distance (curr + 1) ⋯ s) =
    res
⊢ ⟦{ aig := aig, ref := res.getRef idx hidx1 }, assign⟧ =
    if hidx : distance + idx < w then ⟦{ aig := aig, ref := input.getRef (distance + idx) ⋯ }, assign⟧
    else ⟦{ aig := aig, ref := input.getRef (w - 1) ⋯ }, assign⟧

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 : aig.RefStream w
h✝ : ¬curr < w
hgo :
  (let_fun hcurr := ⋯;
    hcurr ▸ s) =
    res
⊢ ⟦{ aig := aig, ref := res.getRef idx hidx1 }, assign⟧ =
    if hidx : distance + idx < w then ⟦{ aig := aig, ref := input.getRef (distance + idx) ⋯ }, assign⟧
    else ⟦{ aig := aig, ref := input.getRef (w - 1) ⋯ }, assign⟧
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 : aig.RefStream w
h✝ : ¬curr < w
hgo :
  (let_fun hcurr := ⋯;
    hcurr ▸ s) =
    res
⊢ ⟦{ aig := aig, ref := res.getRef idx hidx1 }, assign⟧ =
    if hidx : distance + idx < w then ⟦{ aig := aig, ref := input.getRef (distance + idx) ⋯ }, assign⟧
    else ⟦{ aig := aig, ref := input.getRef (w - 1) ⋯ }, assign⟧