reserve x,y for Real,
  u,v,w for set,
  r for positive Real;

theorem Th50:
  for X being TopSpace, R being non empty SubSpace of R^1 for f,g
being continuous Function of X,R ex h being continuous Function of X,R st for x
  being Point of X holds h.x = max(f.x,g.x)
proof
  let X be TopSpace;
  let R be non empty SubSpace of R^1;
  let f,g be continuous Function of X,R;
  defpred A[set] means f.$1 >= g.$1;
  consider A being Subset of X such that
A1: for a being set holds a in A iff a in the carrier of X & A[a] from
  SUBSET_1:sch 1;
  defpred B[set] means f.$1 <= g.$1;
  consider B being Subset of X such that
A2: for a being set holds a in B iff a in the carrier of X & B[a] from
  SUBSET_1:sch 1;
  per cases;
  suppose
A3: X is empty;
    set h = the continuous Function of X,R;
    take h;
    let x be Point of X;
A4: f.x = 0 by A3;
A5: g.x = 0 by A3;
    thus thesis by A3,A4,A5;
  end;
  suppose
A6: X is non empty & A is empty;
    take g;
    let x be Point of X;
    f.x < g.x by A6,A1;
    hence thesis by XXREAL_0:def 10;
  end;
  suppose
A7: X is non empty & B is empty;
    take f;
    let x be Point of X;
    g.x < f.x by A7,A2;
    hence thesis by XXREAL_0:def 10;
  end;
  suppose
A8: X is not empty & A is not empty & B is not empty;
    then reconsider X9 = X as non empty TopSpace;
    for x being Point of X9 holds (x in A iff f.x >= g.x) & (x in B iff f
    .x <= g.x) by A1,A2;
    then reconsider A9 = A, B9 = B as non empty closed Subset of X9 by A8,Th49;
    reconsider ff = f, gg = g as continuous Function of X9, R;
A9: the carrier of X9|A9 = [#](X9|A9) .= A9 by PRE_TOPC:def 5;
A10: dom ff = the carrier of X9 by FUNCT_2:def 1;
    then dom (ff|A9) = A9 by RELAT_1:62;
    then reconsider f9 = ff|A9 as continuous Function of X9|A9, R by A9,
FUNCT_2:def 1,RELSET_1:18,TOPMETR:7;
A11: the carrier of X9|B9 = [#](X9|B9) .= B9 by PRE_TOPC:def 5;
A12: dom gg = the carrier of X9 by FUNCT_2:def 1;
    then dom (gg|B9) = B9 by RELAT_1:62;
    then reconsider g9 = gg|B9 as continuous Function of X9|B9, R by A11,
FUNCT_2:def 1,RELSET_1:18,TOPMETR:7;
A13: dom g9 = B by A12,RELAT_1:62;
A14: A9 \/ B9 = the carrier of X9
    proof
      thus A9 \/ B9 c= the carrier of X9;
      let a be object;
       reconsider aa=a as set by TARSKI:1;
      f.aa >= g.aa or f.aa <= g.aa;
      then a in the carrier of X implies a in A9 or a in B9 by A1,A2;
      hence thesis by XBOOLE_0:def 3;
    end;
    then
A15: X9|(A9 \/ B9) = X9 | [#]X9 .= the TopStruct of X by TSEP_1:93;
A16: the TopStruct of R = the TopStruct of R;
A17: dom f9 = A by A10,RELAT_1:62;
A18: f9 tolerates g9
    proof
      let a be object;
      assume
A19:  a in dom f9 /\ dom g9;
      then
A20:  a in A by A17,XBOOLE_0:def 4;
      then
A21:  f.a >= g.a by A1;
A22:  a in B by A19,A13,XBOOLE_0:def 4;
      then f.a <= g.a by A2;
      then f.a = g.a by A21,XXREAL_0:1;
      hence f9.a = g.a by A20,FUNCT_1:49
        .= g9.a by A22,FUNCT_1:49;
    end;
    then f9+*g9 is continuous Function of X9|(A9 \/ B9), R by Th10;
    then reconsider h = f9+*g9 as continuous Function of X,R by A16,A15,
YELLOW12:36;
    take h;
    let x be Point of X;
    x in A9 or x in B9 by A14,XBOOLE_0:def 3;
    then
    x in A9 & f.x >= g.x & h.x = f9.x & f.x = f9.x or x in B9 & f.x <= g.
    x & h.x = g9.x & g.x = g9.x by A1,A17,A13,A18,FUNCT_1:49,FUNCT_4:13,15;
    hence thesis by XXREAL_0:def 10;
  end;
end;
