
theorem
  for R being non empty RelStr holds R is well_founded iff for V being
non empty set, H being Function of [:the carrier of R, PFuncs(the carrier of R,
  V):], V ex F being Function of the carrier of R, V st F
  is_recursively_expressed_by H
proof
  let R be non empty RelStr;
  set c = the carrier of R, r = the InternalRel of R;
  defpred PDR[ ] means for V being non empty set, H being Function of [:c,
PFuncs(c, V):], V ex F being Function of c, V st F is_recursively_expressed_by
  H;
  reconsider ac = omega +` card c as infinite Cardinal;
  set V = nextcard ac;
  deffunc F(Element of c, Element of PFuncs(c, V)) = sup rng $2;
A1: for x being Element of c, p being Element of PFuncs(c, V) holds F(x,p) in V
  proof
    let x be Element of c, p be Element of PFuncs(c, V);
    card dom p c= card c & card rng p c= card dom p by CARD_1:11,12;
    then
A2: card rng p c= card c;
    card c c= ac by CARD_2:94;
    then card rng p c= ac by A2;
    then
A3: card rng p in V by CARD_1:18,ORDINAL1:12;
    V is regular by CARD_5:30;
    hence thesis by A3,Th2;
  end;
  consider H being Function of [:c, PFuncs(c, V):], V such that
A4: for x being Element of c, p being Element of PFuncs(c, V) holds H.
  (x,p) = F(x,p) from FUNCT_7:sch 1(A1);
  thus R is well_founded implies PDR[ ]
  proof
    assume
A5: R is well_founded;
    let V be non empty set, H be Function of [:c, PFuncs(c, V):], V;
    defpred P[PartFunc of c, V] means dom $1 is lower & for x being set st x
    in dom $1 holds $1.x = H.[x, $1 | r-Seg x];
    consider fs being Subset of PFuncs(c, V) such that
A6: for f being PartFunc of c, V holds f in fs iff P[f] from
    PFSeparation;
    now
      let f, g be Function;
      assume that
A7:   f in fs and
A8:   g in fs;
      reconsider ff = f, gg = g as PartFunc of c,V by A7,A8,PARTFUN1:46;
      defpred P[set] means $1 in dom ff & $1 in dom gg & ff.$1 <> gg.$1;
      assume not f tolerates g;
      then consider x being object such that
A9:   x in dom ff /\ dom gg and
A10:  ff.x <> gg.x by PARTFUN1:def 4;
      reconsider x as Element of R by A9;
A11:  P[x] by A9,A10,XBOOLE_0:def 4;
      consider x0 being Element of R such that
A12:  P[x0] and
A13:  not ex y being Element of R st x0 <> y & P[y] & [y,x0] in the
      InternalRel of R from WFMin(A11, A5 );
      ff | r-Seg x0 = gg | r-Seg x0
      proof
        set fr = ff | r-Seg x0, gr = gg | r-Seg x0;
        assume
A14:    not thesis;
A15:    dom ff is lower by A6,A7;
        then
A16:    dom fr = r-Seg x0 by A12,Th4,RELAT_1:62;
A17:    dom gg is lower by A6,A8;
        then dom fr = dom gr by A12,A16,Th4,RELAT_1:62;
        then consider x1 being object such that
A18:    x1 in dom fr and
A19:    fr.x1 <> gr.x1 by A14;
A20:    [x1, x0] in r by A16,A18,WELLORD1:1;
        reconsider x1 as Element of R by A18;
A21:    fr.x1 = ff.x1 & gr.x1 = gg.x1 by A16,A18,FUNCT_1:49;
A22:    x1 <> x0 by A16,A18,WELLORD1:1;
A23:    x1 in dom gg by A12,A17,A20;
        x1 in dom ff by A12,A15,A20;
        hence contradiction by A13,A19,A20,A21,A22,A23;
      end;
      then ff.x0 = H.[x0, gg | r-Seg x0] by A6,A7,A12
        .= gg.x0 by A6,A8,A12;
      hence contradiction by A12;
    end;
    then reconsider ufs=union fs as Function by Th1;
A24: now
      let x be set;
      assume x in dom ufs;
      then [x, ufs.x] in ufs by FUNCT_1:1;
      then consider fx being set such that
A25:  [x, ufs.x] in fx and
A26:  fx in fs by TARSKI:def 4;
      reconsider ff = fx as PartFunc of c, V by A26,PARTFUN1:46;
A27:  x in dom ff by A25,FUNCT_1:1;
A28:  dom ff is lower & ff c= ufs by A6,A26,ZFMISC_1:74;
      thus ufs.x = ff.x by A25,FUNCT_1:1
        .= H.[x, ff | r-Seg x] by A6,A26,A27
        .= H.[x, ufs | r-Seg x] by A27,A28,Th4,GRFUNC_1:27;
    end;
A29: dom ufs c= c
    proof
      let y be object;
      assume y in dom ufs;
      then [y, ufs.y] in ufs by FUNCT_1:1;
      then consider fx being set such that
A30:  [y, ufs.y] in fx and
A31:  fx in fs by TARSKI:def 4;
      consider ff being Function such that
A32:  ff = fx and
A33:  dom ff c= c and
      rng ff c= V by A31,PARTFUN1:def 3;
      y in dom ff by A30,A32,XTUPLE_0:def 12;
      hence thesis by A33;
    end;
A34: rng ufs c= V
    proof
      let y be object;
      assume y in rng ufs;
      then consider x being object such that
A35:  x in dom ufs & y = ufs.x by FUNCT_1:def 3;
      [x, y] in ufs by A35,FUNCT_1:1;
      then consider fx being set such that
A36:  [x, y] in fx and
A37:  fx in fs by TARSKI:def 4;
      consider ff being Function such that
A38:  ff = fx and
      dom ff c= c and
A39:  rng ff c= V by A37,PARTFUN1:def 3;
      y in rng ff by A36,A38,XTUPLE_0:def 13;
      hence thesis by A39;
    end;
A40: now
      let x, y be object;
      assume that
A41:  x in dom ufs and
A42:  [y, x] in r;
      [x, ufs.x] in ufs by A41,FUNCT_1:1;
      then consider fx being set such that
A43:  [x, ufs.x] in fx and
A44:  fx in fs by TARSKI:def 4;
      reconsider ff = fx as PartFunc of c, V by A44,PARTFUN1:46;
      ff c= ufs by A44,ZFMISC_1:74;
      then
A45:  dom ff c= dom ufs by GRFUNC_1:2;
      dom ff is lower & x in dom ff by A6,A43,A44,FUNCT_1:1;
      then y in dom ff by A42;
      hence y in dom ufs by A45;
    end;
A46: dom ufs = c
    proof
      defpred P[set] means $1 in c & not $1 in dom ufs;
      assume dom ufs <> c;
      then consider x being object such that
A47:  not (x in dom ufs iff x in c) by TARSKI:2;
      reconsider x as Element of R by A29,A47;
A48:  P[x] by A47;
      consider x0 being Element of R such that
A49:  P[x0] and
A50:  not ex y being Element of R st x0 <> y & P[y] & [y,x0] in the
      InternalRel of R from WFMin(A48, A5 );
      set nv = x0 .--> H.[x0, ufs | r-Seg x0], nf = ufs +* nv;
A51:  dom nv = {x0};
A52:  rng nf c= V
      proof
        ufs in PFuncs(c, V) by A29,A34,PARTFUN1:def 3;
        then ufs is PartFunc of c, V by PARTFUN1:46;
        then ufs | r-Seg x0 is PartFunc of c, V by PARTFUN1:11;
        then
A53:    ufs | r-Seg x0 in PFuncs(c, V) by PARTFUN1:45;
        let x be object;
        assume
A54:    x in rng nf;
        assume
A55:    not x in V;
        then rng nf c= rng ufs \/ rng nv & not x in rng ufs by A34,FUNCT_4:17;
        then
A56:    x in rng nv by A54,XBOOLE_0:def 3;
        rng nv = {H.[x0, ufs | r-Seg x0]} by FUNCOP_1:8;
        then x = H.(x0, ufs | r-Seg x0) by A56,TARSKI:def 1;
        hence contradiction by A55,A53,BINOP_1:17;
      end;
A57:  dom nf = dom ufs \/ dom nv by FUNCT_4:def 1;
      dom nf c= c
      proof
        let x be object;
        assume that
A58:    x in dom nf and
A59:    not x in c;
        not x in dom ufs by A29,A59;
        then x in dom nv by A57,A58,XBOOLE_0:def 3;
        hence contradiction by A51,A59;
      end;
      then
A60:  nf in PFuncs(c, V) by A52,PARTFUN1:def 3;
      x0 in dom nv by TARSKI:def 1;
      then x0 in dom nf by A57,XBOOLE_0:def 3;
      then
A61:  [x0, nf.x0] in nf by FUNCT_1:1;
      reconsider nf as PartFunc of c, V by A60,PARTFUN1:46;
A62:  now
        let x be set;
        assume
A63:    x in dom nf;
        per cases by A57,A63,XBOOLE_0:def 3;
        suppose
A64:      x in dom ufs;
A65:      {x0} misses r-Seg x
          proof
            assume {x0} meets r-Seg x;
            then consider y being object such that
A66:        y in {x0} and
A67:        y in r-Seg x by XBOOLE_0:3;
            y = x0 by A66,TARSKI:def 1;
            then [x0, x] in r by A67,WELLORD1:1;
            hence contradiction by A40,A49,A64;
          end;
          not x in dom nv by A49,A64,TARSKI:def 1;
          hence nf.x = ufs.x by FUNCT_4:11
            .= H.[x, ufs | r-Seg x] by A24,A64
            .= H.[x, nf | r-Seg x] by A51,A65,FUNCT_4:72;
        end;
        suppose
A68:      x in dom nv;
A69:      {x0} misses r-Seg x0
          proof
            assume {x0} meets r-Seg x0;
            then consider x being object such that
A70:        x in {x0} and
A71:        x in r-Seg x0 by XBOOLE_0:3;
            x = x0 by A70,TARSKI:def 1;
            hence contradiction by A71,WELLORD1:1;
          end;
A72:      x = x0 by A68,TARSKI:def 1;
          hence nf.x = nv.x0 by A68,FUNCT_4:13
            .= H.[x0, ufs | r-Seg x0] by FUNCOP_1:72
            .= H.[x, nf | r-Seg x] by A51,A72,A69,FUNCT_4:72;
        end;
      end;
      dom nf is lower
      proof
        let x, y be object;
        assume that
A73:    x in dom nf and
A74:    [y,x] in r;
        assume
A75:    not y in dom nf;
        then
A76:    not y in dom ufs by A57,XBOOLE_0:def 3;
        then not x in dom ufs by A40,A74;
        then x in dom nv by A57,A73,XBOOLE_0:def 3;
        then
A77:    x = x0 by TARSKI:def 1;
        reconsider y as Element of R by A74,ZFMISC_1:87;
        not y in dom nv by A57,A75,XBOOLE_0:def 3;
        then y <> x0 by TARSKI:def 1;
        hence contradiction by A50,A74,A76,A77;
      end;
      then nf in fs by A6,A62;
      then [x0, nf.x0] in ufs by A61,TARSKI:def 4;
      hence contradiction by A49,FUNCT_1:1;
    end;
    then reconsider ufs as Function of c, V by A34,FUNCT_2:def 1,RELSET_1:4;
    take ufs;
    let x be Element of c;
    thus thesis by A24,A46;
  end;
  assume PDR[ ];
  then consider rk being Function of c, V such that
A78: rk is_recursively_expressed_by H;
  let Y be set;
  assume that
A79: Y c= c and
A80: Y <> {};
  set m = inf (rk.:Y);
  consider b being object such that
A81: b in Y by A80,XBOOLE_0:def 1;
A82: dom rk = c by FUNCT_2:def 1;
  then rk.b in rk.:Y by A79,A81,FUNCT_1:def 6;
  then m in rk.:Y by ORDINAL2:17;
  then consider a being object such that
A83: a in dom rk and
A84: a in Y and
A85: rk.a = m by FUNCT_1:def 6;
   reconsider a as set by TARSKI:1;
  take a;
  thus a in Y by A84;
  assume r-Seg(a) /\ Y <> {};
  then consider e being object such that
A86: e in r-Seg(a) /\ Y by XBOOLE_0:def 1;
A87: e in r-Seg a by A86,XBOOLE_0:def 4;
  reconsider a as Element of c by A83;
  reconsider rkra = rk | r-Seg a as Element of PFuncs(c,V) by PARTFUN1:45;
A88: rk.a = H.(a, rkra) by A78
    .= sup rng rkra by A4;
A89: e in Y by A86,XBOOLE_0:def 4;
  then reconsider rke = rk.e as Ordinal by A79,FUNCT_2:5,ORDINAL1:13;
  rke in rk.:Y by A82,A79,A89,FUNCT_1:def 6;
  then
A90: m c= rk.e by ORDINAL2:14;
  rke in rng rkra by A82,A79,A87,A89,FUNCT_1:50;
  hence contradiction by A85,A90,A88,ORDINAL1:5,ORDINAL2:19;
end;
