reserve a,b,p,r,r1,r2,s,s1,s2,x0,x for Real;
reserve f,g for PartFunc of REAL,REAL;
reserve X,Y for set;

theorem
  for X, f st X c= dom f holds f is_upper_semicontinuous_on X & f
  is_lower_semicontinuous_on X iff f|X is continuous
proof
  let X, f such that
A1: X c= dom f;
A2: f|X is continuous implies f is_upper_semicontinuous_on X & f
  is_lower_semicontinuous_on X
  proof
    assume
A3: f|X is continuous;
A4: for x0 st x0 in X holds f|X is_lower_semicontinuous_in x0
    proof
      let x0;
      assume x0 in X;
      then
A5:   x0 in dom(f|X) by A1,RELAT_1:57;
      then f|X is_continuous_in x0 by A3,FCONT_1:def 2;
      hence thesis by A5,Th21;
    end;
    for x0 st x0 in X holds f|X is_upper_semicontinuous_in x0
    proof
      let x0;
      assume x0 in X;
      then
A6:   x0 in dom(f|X) by A1,RELAT_1:57;
      then f|X is_continuous_in x0 by A3,FCONT_1:def 2;
      hence thesis by A6,Th21;
    end;
    hence thesis by A1,A4;
  end;
  f is_upper_semicontinuous_on X & f is_lower_semicontinuous_on X implies
  f|X is continuous
  proof
    assume that
A7: f is_upper_semicontinuous_on X and
A8: f is_lower_semicontinuous_on X;
    X c= dom f & for x0 be Real st x0 in dom(f|X) holds f|X
    is_continuous_in x0
    proof
      thus X c= dom f by A7;
      let x0 be Real such that
A9:   x0 in dom(f|X);
      x0 in X by A9,RELAT_1:57;
      then f|X is_upper_semicontinuous_in x0 & f|X is_lower_semicontinuous_in
      x0 by A7,A8;
      hence thesis by Th21;
    end;
    hence thesis by FCONT_1:def 2;
  end;
  hence thesis by A2;
end;
