case succ n h_ind =>
  unfold Nat.fold
  conv =>
    lhs; arg 1;
    change UInt.when (x &&& bitmask (OfNat.ofNat n) ≠ 0) ((1 : α) <<< OfNat.ofNat n) ||| Nat.fold f n 0
  rw [UInt.getBit_lor]
  have : n < length α := Nat.lt_of_succ_lt hn
  have : n < 2^length α := trans this (Nat.exp_lt_pow _ .refl)
  cases hk
  case step hlt =>
    rw [h_ind (Nat.lt_of_succ_lt hn) k hlt]
    cases decide (x &&& bitmask (OfNat.ofNat n) ≠ 0)
    case false => rw [UInt.when_false_eq, UInt.getBit_zero, Bool.false_or]
    case true =>
      simp only [
        UInt.when_true_eq, UInt.getBit_shiftLeft, UInt.toNat_ofNat,
        Nat.mod_eq_of_lt ‹n < 2^length α›,
        Nat.mod_eq_of_lt ‹n < length α›
      ]
      rw [decide_eq_false (Nat.not_le_of_lt hlt)]
      simp only [Bool.false_and, Bool.and_false, Bool.false_or]
  case refl =>
    rw [foldf_high n n .refl, Bool.or_false]
    have : ∀ b, UInt.getBit (UInt.when b ((1 : α) <<< OfNat.ofNat n)) n = b := by
      intro b; cases b
      case true =>
        simp only [
          UInt.when_true_eq, UInt.getBit_shiftLeft,
          UInt.toNat_ofNat,
          Nat.mod_eq_of_lt ‹n < 2^length α›,
          Nat.mod_eq_of_lt ‹n < length α›
        ]
        rw [decide_eq_true ‹n < length α›, decide_eq_true (p:=n≥n) .refl]
        rw [Nat.sub_self, UInt.getBit_one, decide_eq_true ‹0 < length α›, decide_eq_true rfl]
        simp only [Bool.true_and]
      case false => rw [UInt.when_false_eq, UInt.getBit_zero]
    rw [this]; clear this
    suffices ∀ y, decide ((x &&& y) ≠ 0) = UInt.getBit y i by
      rw [this]
      have hgetbit := UInt.getBit_bitmask (OfNat.ofNat (α:=α) n) i
      simp only [UInt.toNat_ofNat, Nat.mod_eq_of_lt ‹n < 2^length α›] at hgetbit
      rw [decide_eq_true ‹i < length α›, Bool.true_and] at hgetbit
      exact hgetbit ‹n < length α›
    intro y
    cases hyi : UInt.getBit y i
    case true =>
      apply decide_eq_true; intro hcontra
      have := calc
        true = (true && true) := rfl
        _    = (UInt.getBit x i && UInt.getBit y i) := by rw [hi i, decide_eq_true rfl, hyi]
        _    = UInt.getBit (x &&& y) i := by rw [UInt.getBit_land]
        _    = UInt.getBit (α:=α) 0 i := by rw [hcontra]
        _    = false := UInt.getBit_zero i
      cases this
    case false =>
      apply decide_eq_false; apply not_not_intro
      apply UInt.bitext; intro j hj
      rw [UInt.getBit_zero, UInt.getBit_land, hi j]
      if hij : i = j
      then cases hij; rw [hyi, Bool.and_false]
      else rw [decide_eq_false hij, Bool.false_and]
α : Type
inst✝² : (n : Nat) → OfNat α n
inst✝¹ : UInt α
inst✝ : DecidableEq α
i : Nat
x : α
hi : ∀ (j : Nat), UInt.getBit x j = decide (i = j)
f : Nat → α → α := fun i y => UInt.when (decide (x &&& bitmask (OfNat.ofNat i) ≠ 0)) (1 <<< OfNat.ofNat i) ||| y
this✝¹ : UInt.getBit x i = true
this✝ : i < length α
this : 0 < length α
foldf_high : ∀ (n k : Nat), k ≥ n → UInt.getBit (Nat.fold f n 0) k = false
n : Nat
h_ind : n < length α → ∀ (k : Nat), k < n → UInt.getBit (Nat.fold f n 0) k = Nat.getBit i k
hn : Nat.succ n < length α
k : Nat
hk : k < Nat.succ n
⊢ UInt.getBit (Nat.fold f (Nat.succ n) 0) k = Nat.getBit i k
no goals