-- Module: Mathlib.Computability.PartrecCode
Goal:
x : Unit
p n : ℕ
this : List.range p = List.range (Nat.pair (unpair p).1 (encode (ofNat Code (unpair p).2)))
k : ℕ
generalize :
  ∀ (c : Code),
    n ∈ List.range k →
      Nat.rec (motive := fun (x : ℕ) ↦ Option ℕ) Option.none
          (fun (n_1 : ℕ) (n_ih : Option ℕ) ↦
            rec (motive := fun (x : Code) ↦ Option ℕ) (some 0) (some n.succ) (some (unpair n).1) (some (unpair n).2)
              (fun (cf cg : 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 (encode c))))
                      (k, cf) 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 (encode c))))
                      (k, cg) n
                some (Nat.pair x y))
              (fun (cf cg : 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 (encode c))))
                      (k, cg) 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 (encode c))))
                    (k, cf) x)
              (fun (cf cg : 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 (encode c))))
                    (k, cf) (unpair n).1)
                  (fun (n_2 : ℕ) (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 (encode c))))
                          (n_1, c) (Nat.pair (unpair n).1 n_2)
                    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 c))))
                        (k, cg) (Nat.pair (unpair n).1 (Nat.pair n_2 i)))
                  (unpair n).2)
              (fun (cf : 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 (encode c))))
                      (k, cf) n
                Nat.rec (motive := fun (x : ℕ) ↦ Option ℕ) (some (unpair n).2)
                    (fun (n_2 : ℕ) (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 (encode c))))
                        (n_1, c) (Nat.pair (unpair n).1 ((unpair n).2 + 1)))
                    x)
              c)
          k =
        evaln k c n
⊢ n ∈ List.range k →
    Nat.rec (motive := fun (x : ℕ) ↦ Option ℕ) Option.none
        (fun (n_1 : ℕ) (n_ih : Option ℕ) ↦
          rec (motive := fun (x : Code) ↦ Option ℕ) (some 0) (some n.succ) (some (unpair n).1) (some (unpair n).2)
            (fun (cf cg : 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 (encode (ofNat Code (unpair p).2)))))
                    (k, cf) 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 (encode (ofNat Code (unpair p).2)))))
                    (k, cg) n
              some (Nat.pair x y))
            (fun (cf cg : 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 (encode (ofNat Code (unpair p).2)))))
                    (k, cg) 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 (encode (ofNat Code (unpair p).2)))))
                  (k, cf) x)
            (fun (cf cg : 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 (encode (ofNat Code (unpair p).2)))))
                  (k, cf) (unpair n).1)
                (fun (n_2 : ℕ) (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 (encode (ofNat Code (unpair p).2)))))
                        (n_1, ofNat Code (unpair p).2) (Nat.pair (unpair n).1 n_2)
                  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 (ofNat Code (unpair p).2)))))
                      (k, cg) (Nat.pair (unpair n).1 (Nat.pair n_2 i)))
                (unpair n).2)
            (fun (cf : 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 (encode (ofNat Code (unpair p).2)))))
                    (k, cf) n
              Nat.rec (motive := fun (x : ℕ) ↦ Option ℕ) (some (unpair n).2)
                  (fun (n_2 : ℕ) (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 (encode (ofNat Code (unpair p).2)))))
                      (n_1, ofNat Code (unpair p).2) (Nat.pair (unpair n).1 ((unpair n).2 + 1)))
                  x)
            (ofNat Code (unpair p).2))
        k =
      evaln k (ofNat Code (unpair p).2) n

Tactic:
generalize ofNat Code p.unpair.2 = c

Premises used: Nat.unpair, Nat.Partrec.Code, Prod.snd, Denumerable.ofNat