-- Lean 4 proof step from Mathlib.Computability.PartrecCode (goal)
Goal:
x : Unit
p n : ℕ
this : List.range p = List.range (Nat.pair (unpair p).1 (encode (ofNat Code (unpair p).2)))
k' : ℕ
k : ℕ := k' + 1
nk : n ≤ k'
cf cg : Code
hg :
  ∀ {k' : ℕ} {c' : Code} {n : ℕ},
    Nat.pair k' (encode c') < Nat.pair k (encode (cf.pair cg)) →
      lup
          (List.map (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
            (List.range (Nat.pair k (encode (cf.pair cg)))))
          (k', c') n =
        evaln k' c' n
⊢ rec (motive := fun (x : Code) ↦ Option ℕ) (some 0) (some n.succ) (some (unpair n).1) (some (unpair n).2)
      (fun (cf_1 cg_1 : Code) (x x_1 : Option ℕ) ↦ do
        let x ←
          lup
              (List.map
                (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
              (k' + 1, cf_1) n
        let y ←
          lup
              (List.map
                (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
              (k' + 1, cg_1) n
        some (Nat.pair x y))
      (fun (cf_1 cg_1 : Code) (x x_1 : Option ℕ) ↦ do
        let x ←
          lup
              (List.map
                (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
              (k' + 1, cg_1) n
        lup
            (List.map (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
              (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
            (k' + 1, cf_1) x)
      (fun (cf_1 cg_1 : Code) (x x_1 : Option ℕ) ↦
        Nat.rec (motive := fun (x : ℕ) ↦ Option ℕ)
          (lup
            (List.map (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
              (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
            (k' + 1, cf_1) (unpair n).1)
          (fun (n_1 : ℕ) (n_ih : Option ℕ) ↦ do
            let i ←
              lup
                  (List.map
                    (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                    (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
                  (k', cf.pair cg) (Nat.pair (unpair n).1 n_1)
            lup
                (List.map
                  (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                  (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
                (k' + 1, cg_1) (Nat.pair (unpair n).1 (Nat.pair n_1 i)))
          (unpair n).2)
      (fun (cf_1 : Code) (x : Option ℕ) ↦ do
        let x ←
          lup
              (List.map
                (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
              (k' + 1, cf_1) n
        Nat.rec (motive := fun (x : ℕ) ↦ Option ℕ) (some (unpair n).2)
            (fun (n_1 : ℕ) (n_ih : Option ℕ) ↦
              lup
                (List.map
                  (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
                  (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
                (k', cf.pair cg) (Nat.pair (unpair n).1 ((unpair n).2 + 1)))
            x)
      (cf.pair cg) =
    evaln (k' + 1) (cf.pair cg) n
have succ : Eq (α := Option ℕ)
  ((lup
        (List.map (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
          (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
        (k' + 1, cf) n).bind
    fun (a : ℕ) ↦
    (lup
          (List.map (fun (n : ℕ) ↦ List.map (evaln (unpair n).1 (ofNat Code (unpair n).2)) (List.range (unpair n).1))
            (List.range (Nat.pair (k' + 1) (encode (cf.pair cg)))))
          (k' + 1, cg) n).bind
      fun (y : ℕ) ↦ some (Nat.pair a y))
  ((Option.map Nat.pair (evaln (k' + 1) cf n)).bind fun (a : ℕ → ℕ) ↦ Option.map a (evaln (k' + 1) cg n))
Tactic: simp [evaln, nk, Bind.bind, Functor.map, Seq.seq, pure]