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 Th50:
  for i being Nat
  for p, q being FinSequence of NAT holds
  primrec(e1,e2,i,p) tolerates primrec(e1,e2,i,q)
proof let i be Nat;
  set f1 = e1, f2 = e2;
  let p1,p2 be FinSequence of NAT;
  per cases;
  suppose
    not i in dom p1 or not i in dom p2;
    then primrec(f1,f2,i, p1) = {} or primrec(f1,f2,i, p2) = {} by Th49;
    hence thesis;
  end;
  suppose
A1: i in dom p1 & i in dom p2;
    reconsider m = p1/.i, n = p2/.i as Element of NAT;
    consider F2 being sequence of  HFuncs NAT such that
A2: primrec(f1,f2,i,p2) = F2.(p2/.i) and
A3: i in dom p2 & Del(p2,i) in dom f1 implies F2.0 = p2+*(i,0) .--> (
    f1.Del(p2,i)) and
A4: not i in dom p2 or not Del(p2,i) in dom f1 implies F2.0 = {} and
A5: for m being Nat holds Q[m, F2.m qua Element of HFuncs
    NAT, F2.(m+1)qua Element of HFuncs NAT, p2, i, f2] by Def10;
    consider F1 being sequence of  HFuncs NAT such that
A6: primrec(f1,f2,i,p1) = F1.(p1/.i) and
A7: i in dom p1 & Del(p1,i) in dom f1 implies F1.0 = p1+*(i,0) .--> (
    f1.Del(p1,i)) and
A8: not i in dom p1 or not Del(p1,i) in dom f1 implies F1.0 = {} and
A9: for m being Nat holds Q[m, F1.m qua Element of HFuncs
    NAT, F1.(m+1)qua Element of HFuncs NAT, p1, i, f2] by Def10;
    defpred p[Nat] means for x being set st x in dom (F1.$1) ex n
    being Element of NAT st x = p1+*(i,n) & n <= $1;
A10: now
      let m be Nat such that
A11:  p[m];
      thus p[m+1]
      proof
        set p1c = (p1+*(i,m))^<*(F1.m).(p1+*(i,m))*>;
        let x be set such that
A12:    x in dom (F1.(m+1));
A13:    m <= m+1 by NAT_1:11;
        per cases;
        suppose
          i in dom p1 & p1+*(i,m) in dom (F1.m) & p1c in dom f2;
          then F1.(m+1) = (F1.m)+*(p1+*(i,m+1).--> f2.(p1c)) by A9;
          then dom (F1.(m+1)) = dom (F1.m) \/ dom (p1+*(i,m+1).--> f2.(p1c))
          by FUNCT_4:def 1
            .= dom (F1.m) \/ {p1+*(i,m+1)};
          then
A14:      x in dom (F1.m) or x in {p1+*(i,m+1)} by A12,XBOOLE_0:def 3;
          thus ex n being Element of NAT st x = p1+*(i,n) & n <= m+1
          proof
            per cases by A14,TARSKI:def 1;
            suppose
              x in dom (F1.m);
              then ex n being Element of NAT st x = p1+*(i,n) & n <= m by A11;
              hence thesis by A13,XXREAL_0:2;
            end;
            suppose
              x = p1+*(i,m+1);
              hence thesis;
            end;
          end;
        end;
        suppose
          not i in dom p1 or not p1+*(i,m) in dom (F1.m) or not p1c in dom f2;
          then F1.(m+1) = F1.m by A9;
          then ex n being Element of NAT st x = p1+*(i,n) & n <= m by A11,A12;
          hence thesis by A13,XXREAL_0:2;
        end;
      end;
    end;
A15: now
      defpred r[Nat] means F1.$1 = F2.$1;
      assume
A16:  p1+*(i,0) = p2+*(i,0);
A17:  r[0]
      proof
        per cases;
        suppose
          i in dom p1 & Del(p1,i) in dom f1;
          hence thesis by A1,A7,A3,A16,Th4;
        end;
        suppose
          not i in dom p1 or not Del(p1, i) in dom f1;
          hence thesis by A1,A8,A4,A16,Th4;
        end;
      end;
A18:  now
        let m be Nat such that
A19:    r[m];
A20:    Q[m, F1.m qua Element of HFuncs NAT, F1.(m+1)qua Element of
        HFuncs NAT, p1, i, f2] by A9;
A21:    Q[m, F2.m qua Element of HFuncs NAT, F2.(m+1)qua Element of
        HFuncs NAT, p2, i, f2] by A5;
        p1+*(i,m) = p2+*(i,m) by A16,Th2;
        hence r[m+1] by A1,A19,A20,A21,Th2;
      end;
      thus for m being Nat holds r[m] from NAT_1:sch 2(A17, A18);
    end;
A22: p[0]
    proof
      let x be set such that
A23:  x in dom (F1.0);
      dom (F1.0) = {p1+*(i,0)} by A7,A8,A23;
      then x = p1+*(i,0) by A23,TARSKI:def 1;
      hence thesis;
    end;
A24: for m being Nat holds p[m] from NAT_1:sch 2(A22, A10);
A25: for m, n being Nat holds F1.m c= F1.(m+n)
    proof
      let m be Nat;
      defpred r[Nat] means F1.m c= F1.(m+$1);
A26:  now
        let n be Nat such that
A27:    r[n];
        set k = m+n;
        F1.k qua set c= F1.(k+1) qua set
        proof
          set p1c = (p1+*(i,k))^<*(F1.k).(p1+*(i,k))*>;
          let x be object such that
A28:      x in F1.k;
          per cases;
          suppose
A29:        i in dom p1 & p1+*(i,k) in dom (F1.k) & p1c in dom f2;
A30:        dom (F1.k) misses dom (p1+*(i,k+1).--> f2.(p1c))
            proof
              assume not thesis;
              then consider x being object such that
A31:          x in dom (F1.k) /\ dom({p1+*(i,k+1)}--> f2.(p1c)) by XBOOLE_0:4;
              x in dom (F1.k) by A31,XBOOLE_0:def 4;
              then consider n1 being Element of NAT such that
A32:          x = p1+*(i,n1) and
A33:          n1 <= k by A24;
A34:          k+1 = (p1+*(i,k+1)).i by A1,FUNCT_7:31;
A35:          x = p1+*(i,k+1) by A31,TARSKI:def 1;
              n1 = (p1+*(i,n1)).i by A1,FUNCT_7:31;
              hence contradiction by A35,A32,A33,A34,NAT_1:13;
            end;
            F1.(k+1) = (F1.k)+*(p1+*(i,k+1).--> f2.(p1c)) by A9,A29;
            then F1.k c= F1.(k+1) by A30,FUNCT_4:32;
            hence thesis by A28;
          end;
          suppose
            not i in dom p1 or not p1+*(i,k) in dom (F1.k) or not p1c
            in dom f2;
            hence thesis by A9,A28;
          end;
        end;
        hence r[n+1] by A27,XBOOLE_1:1;
      end;
A36:  r[0];
      thus for n being Nat holds r[n] from NAT_1:sch 2(A36, A26);
    end;
    defpred p[Nat] means for x being set st x in dom (F2.$1) ex n
    being Element of NAT st x = p2+*(i,n) & n <= $1;
A37: now
      let m be Nat such that
A38:  p[m];
      thus p[m+1]
      proof
        set p2c = (p2+*(i,m))^<*(F2.m).(p2+*(i,m))*>;
        let x be set such that
A39:    x in dom (F2.(m+1));
A40:    m <= m+1 by NAT_1:11;
        per cases;
        suppose
          i in dom p2 & p2+*(i,m) in dom (F2.m) & p2c in dom f2;
          then F2.(m+1) = (F2.m)+*(p2+*(i,m+1).--> f2.(p2c)) by A5;
          then dom (F2.(m+1)) = dom (F2.m) \/ dom (p2+*(i,m+1).--> f2.(p2c))
          by FUNCT_4:def 1
            .= dom (F2.m) \/ {p2+*(i,m+1)};
          then
A41:      x in dom (F2.m) or x in {p2+*(i,m+1)} by A39,XBOOLE_0:def 3;
          thus ex n being Element of NAT st x = p2+*(i,n) & n <= m+1
          proof
            per cases by A41,TARSKI:def 1;
            suppose
              x in dom (F2.m);
              then ex n being Element of NAT st x = p2+*(i,n) & n <= m by A38;
              hence thesis by A40,XXREAL_0:2;
            end;
            suppose
              x = p2+*(i,m+1);
              hence thesis;
            end;
          end;
        end;
        suppose
          not i in dom p2 or not p2+*(i,m) in dom (F2.m) or not p2c in dom f2;
          then F2.(m+1) = F2.m by A5;
          then ex n being Element of NAT st x = p2+*(i,n) & n <= m by A38,A39;
          hence thesis by A40,XXREAL_0:2;
        end;
      end;
    end;
A42: p[0]
    proof
      let x be set such that
A43:  x in dom (F2.0);
      dom (F2.0) = {p2+*(i,0)} by A3,A4,A43;
      then x = p2+*(i,0) by A43,TARSKI:def 1;
      hence thesis;
    end;
A44: for m being Nat holds p[m] from NAT_1:sch 2(A42, A37);
A45: for m, n being Nat holds F2.m c= F2.(m+n)
    proof
      let m be Nat;
      defpred r[Nat] means F2.m c= F2.(m+$1);
A46:  now
        let n be Nat such that
A47:    r[n];
        set k = m+n;
        F2.k c= F2.(k+1)
        proof
          set p2c = (p2+*(i,k))^<*(F2.k).(p2+*(i,k))*>;
          let x be object such that
A48:      x in F2.k;
          per cases;
          suppose
A49:        i in dom p2 & p2+*(i,k) in dom (F2.k) & p2c in dom f2;
A50:        dom (F2.k) misses dom (p2+*(i,k+1).--> f2.(p2c))
            proof
              assume not thesis;
              then consider x being object such that
A51:          x in dom (F2.k) /\ dom({p2+*(i,k+1)}--> f2.(p2c)) by XBOOLE_0:4;
              x in dom (F2.k) by A51,XBOOLE_0:def 4;
              then consider n2 being Element of NAT such that
A52:          x = p2+*(i,n2) and
A53:          n2 <= k by A44;
A54:          k+1 = (p2+*(i,k+1)).i by A1,FUNCT_7:31;
A55:          x = p2+*(i,k+1) by A51,TARSKI:def 1;
              n2 = (p2+*(i,n2)).i by A1,FUNCT_7:31;
              hence contradiction by A55,A52,A53,A54,NAT_1:13;
            end;
            F2.(k+1) = (F2.k)+*(p2+*(i,k+1).--> f2.(p2c)) by A5,A49;
            then F2.k c= F2.(k+1) by A50,FUNCT_4:32;
            hence thesis by A48;
          end;
          suppose
            not i in dom p2 or not p2+*(i,k) in dom (F2.k) or not
            p2c in dom f2;
            hence thesis by A5,A48;
          end;
        end;
        hence r[n+1] by A47,XBOOLE_1:1;
      end;
A56:  r[0];
      thus for n being Nat holds r[n] from NAT_1:sch 2(A56, A46);
    end;
    reconsider F1m = F1.m, F1n = F1.n, F2m = F2.m, F2n = F2.n as Element of
    HFuncs NAT;
A57: now
      assume
A58:  p1+*(i,0) <> p2+*(i,0);
      let m be Element of NAT;
      assume dom (F1.m) /\ dom (F2.m) <> {};
      then consider x being object such that
A59:  x in dom(F1.m) /\ dom(F2.m) by XBOOLE_0:def 1;
      x in dom(F2.m) by A59,XBOOLE_0:def 4;
      then
A60:  ex n2 being Element of NAT st x = p2+*(i,n2) & n2 <= m by A44;
      x in dom(F1.m) by A59,XBOOLE_0:def 4;
      then ex n1 being Element of NAT st x = p1+*(i,n1) & n1 <= m by A24;
      hence contradiction by A58,A60,Th2;
    end;
    thus thesis
    proof
      per cases;
      suppose
        m <= n;
        then consider k being Nat such that
A61:    n = m+k by NAT_1:10;
        reconsider k as Element of NAT by ORDINAL1:def 12;
A62:    n = m+k by A61;
        thus primrec(f1,f2,i,p1) tolerates primrec(f1,f2,i,p2)
        proof
          per cases by A15,A57;
          suppose
            F1n = F2n;
            hence thesis by A6,A2,A25,A62,PARTFUN1:58;
          end;
          suppose
            dom (F1n) /\ dom (F2n) = {};
            then dom (F1n) misses dom (F2n) by XBOOLE_0:def 7;
            then F1n tolerates F2n by PARTFUN1:56;
            hence thesis by A6,A2,A25,A62,PARTFUN1:58;
          end;
        end;
      end;
      suppose
        m >= n;
        then consider k being Nat such that
A63:    m = n+k by NAT_1:10;
        reconsider k as Element of NAT by ORDINAL1:def 12;
A64:    m = n+k by A63;
        thus primrec(f1,f2,i,p1) tolerates primrec(f1,f2,i,p2)
        proof
          per cases by A15,A57;
          suppose
            F1m = F2m;
            hence thesis by A6,A2,A45,A64,PARTFUN1:58;
          end;
          suppose
            dom (F1m) /\ dom (F2m) = {};
            then dom (F1m) misses dom (F2m) by XBOOLE_0:def 7;
            then F1m tolerates F2m by PARTFUN1:56;
            hence thesis by A6,A2,A45,A64,PARTFUN1:58;
          end;
        end;
      end;
    end;
  end;
end;
