reserve r,x,x0,a,b for Real;
reserve n,m for Element of NAT;
reserve A for non empty closed_interval Subset of REAL;
reserve Z for open Subset of REAL;
reserve f, f1, f2, f3 for PartFunc of REAL, REAL;

theorem Th41:
  (Z c= dom (-cot+cosec) & for x st x in Z holds (1+cos.x)<>0 & (1
-cos.x)<>0) implies -cot+cosec is_differentiable_on Z & for x st x in Z holds (
  (-cot+cosec)`|Z).x = 1/(1+cos.x)
proof
  assume that
A1: Z c= dom (-cot+cosec) and
A2: for x st x in Z holds 1+cos.x<>0 & 1-cos.x<>0;
  Z c= dom (-cot) /\ dom (sin^) by A1,VALUED_1:def 1;
  then
A3: Z c= dom (-cot) by XBOOLE_1:18;
  then
A4: Z c= dom cot by VALUED_1:8;
  for x st x in Z holds cot is_differentiable_in x
  proof
    let x;
    assume x in Z;
    then sin.x<>0 by A4,FDIFF_8:2;
    hence thesis by FDIFF_7:47;
  end;
  then
A5: cot is_differentiable_on Z by A4,FDIFF_1:9;
  then
A6: (-1)(#)cot is_differentiable_on Z by A3,FDIFF_1:20;
A7: for x st x in Z holds sin.x<>0 by A4,FDIFF_8:2;
  then
A8: sin^ is_differentiable_on Z by FDIFF_4:40;
  for x st x in Z holds ((-cot+cosec)`|Z).x = 1/(1+cos.x)
  proof
    let x;
    assume
A9: x in Z;
    then
A10: sin.x<>0 by A4,FDIFF_8:2;
A11: 1-cos.x<>0 by A2,A9;
    ((-cot+cosec)`|Z).x = diff(-cot,x) + diff(sin^,x) by A1,A8,A6,A9,FDIFF_1:18
      .=(((-1)(#)cot)`|Z).x + diff(sin^,x) by A6,A9,FDIFF_1:def 7
      .=(-1)*diff(cot,x) + diff(sin^,x) by A3,A5,A9,FDIFF_1:20
      .=(-1)*(-1/(sin.x)^2)+ diff(sin^,x) by A10,FDIFF_7:47
      .=1/(sin.x)^2 + ((sin^)`|Z).x by A8,A9,FDIFF_1:def 7
      .=1/(sin.x)^2 + (-cos.x/(sin.x)^2) by A7,A9,FDIFF_4:40
      .=1/(sin.x)^2 - cos.x/(sin.x)^2
      .=(1-cos.x)/((sin.x)^2+(cos.x)^2-(cos.x)^2) by XCMPLX_1:120
      .=(1-cos.x)/(1-(cos.x)^2) by SIN_COS:28
      .=(1-cos.x)/((1-cos.x)*(1+cos.x))
      .=(1-cos.x)/(1-cos.x)/(1+cos.x) by XCMPLX_1:78
      .=1/(1+cos.x) by A11,XCMPLX_1:60;
    hence thesis;
  end;
  hence thesis by A1,A8,A6,FDIFF_1:18;
end;
