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 Th51:
  (Z c= dom ((id Z)+cot+cosec) & for x st x in Z holds (1+cos.x)<>
0 & (1-cos.x)<>0) implies (id Z)+cot+cosec is_differentiable_on Z & for x st x
  in Z holds ((id Z+cot+cosec)`|Z).x = cos.x/(cos.x-1)
proof
  assume that
A1: Z c= dom ((id Z)+cot+cosec) and
A2: for x st x in Z holds 1+cos.x<>0 & 1-cos.x<>0;
A3: Z c= dom ((id Z)+cot) /\ dom cosec by A1,VALUED_1:def 1;
  then
A4: Z c= dom (id Z+cot) by XBOOLE_1:18;
  then
 Z c= dom id Z /\ dom cot by VALUED_1:def 1;
  then
A5: Z c= dom cot by XBOOLE_1:18;
A6: for x st x in Z holds (id Z).x = 1*x+0 by FUNCT_1:18;
A7: Z c= dom id Z;
  then
A8: (id Z) is_differentiable_on Z by A6,FDIFF_1:23;
  for x st x in Z holds cot is_differentiable_in x
  proof
    let x;
    assume x in Z;
    then sin.x<>0 by A5,FDIFF_8:2;
    hence thesis by FDIFF_7:47;
  end;
  then
A9: cot is_differentiable_on Z by A5,FDIFF_1:9;
  then
A10: id Z + cot is_differentiable_on Z by A4,A8,FDIFF_1:18;
A11: Z c= dom cosec by A3,XBOOLE_1:18;
  then
A12: cosec is_differentiable_on Z by FDIFF_9:5;
A13: for x st x in Z holds (((id Z) + cot)`|Z).x = -(cos.x)^2/(sin.x)^2
  proof
    let x;
    assume
A14: x in Z;
    then
A15: sin.x<>0 by A5,FDIFF_8:2;
    then
A16: (sin.x)^2 >0 by SQUARE_1:12;
    ((id Z + cot)`|Z).x = diff((id Z),x) + diff(cot,x) by A4,A9,A8,A14,
FDIFF_1:18
      .=((id Z)`|Z).x + diff(cot,x) by A8,A14,FDIFF_1:def 7
      .=1+diff(cot,x) by A7,A6,A14,FDIFF_1:23
      .=1+(-1/(sin.x)^2) by A15,FDIFF_7:47
      .=1-1/(sin.x)^2
      .=(sin.x)^2/(sin.x)^2-1/(sin.x)^2 by A16,XCMPLX_1:60
      .=((sin.x)^2-1)/(sin.x)^2 by XCMPLX_1:120
      .=((sin.x)^2-((sin.x)^2+(cos.x)^2))/(sin.x)^2 by SIN_COS:28
      .=(-(cos.x)^2)/(sin.x)^2
      .=-(cos.x)^2/(sin.x)^2 by XCMPLX_1:187;
    hence thesis;
  end;
  for x st x in Z holds ((id Z + cot+cosec)`|Z).x = cos.x/(cos.x-1)
  proof
    let x;
    assume
A17: x in Z;
    then
A18: 1+cos.x<>0 by A2;
    ((id Z + cot+cosec)`|Z).x=diff((id Z + cot),x) +diff(cosec,x) by A1,A12,A10
,A17,FDIFF_1:18
      .=((id Z + cot)`|Z).x+diff(cosec,x) by A10,A17,FDIFF_1:def 7
      .=-(cos.x)^2/(sin.x)^2+diff(cosec,x) by A13,A17
      .=-(cos.x)^2/(sin.x)^2+((cosec)`|Z).x by A12,A17,FDIFF_1:def 7
      .=-(cos.x)^2/(sin.x)^2+(-cos.x/(sin.x)^2) by A11,A17,FDIFF_9:5
      .=-((cos.x)^2/(sin.x)^2+cos.x/(sin.x)^2)
      .=-((cos.x)*(cos.x)+cos.x)/(sin.x)^2 by XCMPLX_1:62
      .=-(cos.x)*(cos.x+1)/((sin.x)^2+(cos.x)^2-(cos.x)^2)
      .=-(cos.x)*(cos.x+1)/(1-(cos.x)^2) by SIN_COS:28
      .=-(cos.x)*(cos.x+1)/((1+cos.x)*(1-cos.x))
      .=-(cos.x)*(cos.x+1)/(1+cos.x)/(1-cos.x) by XCMPLX_1:78
      .=-(cos.x)*((1+cos.x)/(1+cos.x))/(1-cos.x) by XCMPLX_1:74
      .=-(cos.x)*1/(1-cos.x) by A18,XCMPLX_1:60
      .=(cos.x)/(-(1-cos.x)) by XCMPLX_1:188
      .=(cos.x)/(cos.x-1);
    hence thesis;
  end;
  hence thesis by A1,A12,A10,FDIFF_1:18;
end;
