reserve i, j, k, c, m, n for Nat,
  a, x, y, z, X, Y for set,
  D, E for non empty set,
  R for Relation,
  f, g for Function,
  p, q for FinSequence;
reserve f1, f2 for non empty homogeneous to-naturals NAT*-defined Function,
  e1, e2 for homogeneous to-naturals NAT*-defined Function,
  p for Element of (arity f1+1)-tuples_on NAT;

theorem Th51:
  for i being Nat
  for p being FinSequence of NAT holds
   dom primrec(e1,e2,i,p) c= (1+arity e1)-tuples_on NAT
proof let i be Nat;
  set f1 = e1, f2 = e2;
  let p be FinSequence of NAT;
  per cases;
  suppose
A1: i in dom p;
    consider F being sequence of  HFuncs NAT such that
A2: primrec(f1,f2,i,p) = F.(p/.i) and
A3: i in dom p & Del(p,i) in dom f1 implies F.0 = p+*(i,0) .--> (f1.
    Del(p,i)) and
A4: not i in dom p or not Del(p,i) in dom f1 implies F.0 = {} and
A5: for m being Nat holds Q[m, F.m qua Element of HFuncs
    NAT, F.(m+1)qua Element of HFuncs NAT, p, i, f2] by Def10;
    defpred p[Nat] means dom (F.$1) c= (1+arity f1)-tuples_on NAT;
A6: now
      let m be Nat such that
A7:   p[m];
      set pc = (p+*(i,m))^<*(F.m).(p+*(i,m))*>;
      per cases;
      suppose
A8:     p+*(i,m) in dom (F.m) & pc in dom f2;
        dom (p+*(i,m)) = dom p by FUNCT_7:30
          .= dom (p+*(i,m+1)) by FUNCT_7:30;
        then
A9:     len (p+*(i,m)) = len (p+*(i,m+1)) by FINSEQ_3:29;
        len (p+*(i,m)) = 1+arity f1 by A7,A8,CARD_1:def 7;
        then p+*(i,m+1)is Element of (1+arity f1)-tuples_on NAT by A9,
FINSEQ_2:92;
        then
A10:    {p+*(i,m+1)} c= (1+arity f1)-tuples_on NAT by ZFMISC_1:31;
        F.(m+1) = (F.m)+*(p+*(i,m+1).--> f2.(pc)) by A1,A5,A8;
        then dom (F.(m+1)) = dom (F.m) \/ dom (p+*(i,m+1).--> f2.(pc)) by
FUNCT_4:def 1;
        then dom (F.(m+1)) = dom (F.m) \/ {p+*(i,m+1)};
        hence p[m+1] by A7,A10,XBOOLE_1:8;
      end;
      suppose
        not p+*(i,m) in dom (F.m) or not pc in dom f2;
        hence p[m+1] by A5,A7;
      end;
    end;
A11: p[0]
    proof
      per cases;
      suppose
A12:    Del(p,i) in dom f1;
        dom f1 c= (arity f1)-tuples_on NAT by Th20;
        then
A13:    len Del(p,i) = arity f1 by A12,CARD_1:def 7;
A14:    dom p = dom (p+*(i,0)) by FUNCT_7:30;
        p <> <*>NAT by A1;
        then consider n being Nat such that
A15:    len p = n+1 by NAT_1:6;
        len Del(p,i) = n by A1,A15,FINSEQ_3:109;
        then len (p+*(i,0)) = 1+arity f1 by A13,A15,A14,FINSEQ_3:29;
        then
A16:    (p+*(i,0)) is Element of (1+arity f1)-tuples_on NAT by FINSEQ_2:92;
        dom (F.0) = {p+*(i,0)} by A1,A3,A12;
        hence thesis by A16,ZFMISC_1:31;
      end;
      suppose
        not Del(p,i) in dom f1;
        hence thesis by A4,XBOOLE_1:2;
      end;
    end;
    for m being Nat holds p[m] from NAT_1:sch 2(A11,A6);
    hence thesis by A2;
  end;
  suppose
    not i in dom p;
    then primrec(f1,f2,i,p) = {} by Th49;
    hence thesis;
  end;
end;
