reserve f,g for PartFunc of REAL,REAL,
  r,r1,r2,g1,g2,g3,g4,g5,g6,x,x0,t,c for Real,
  a,b,s for Real_Sequence,
  n,k for Element of NAT;

theorem
  x0 in dom f /\ dom g & (ex r st r>0 & [.x0,x0+r.] c= dom f & [.x0,x0+r
.] c= dom g & f is_differentiable_on ].x0,x0+r.[ & g is_differentiable_on ].x0,
x0+r.[ & ].x0,x0+r.[ c= dom (f/g) & [.x0,x0+r.] c= dom ((f`|(].x0,x0+r.[))/(g`|
  (].x0,x0+r.[))) & f.x0 = 0 & g.x0 = 0 & f is_continuous_in x0 & g
  is_continuous_in x0 & (f`|(].x0,x0+r.[))/(g`|(].x0,x0+r.[))
is_right_convergent_in x0) implies f/g is_right_convergent_in x0 & ex r st r>0
  & lim_right(f/g,x0) = lim_right(((f`|(].x0,x0+r.[))/(g`|(].x0,x0+r.[))),x0)
proof
  assume
A1: x0 in dom f /\ dom g;
  given r such that
A2: r>0 and
A3: [.x0,x0+r.] c= dom f and
A4: [.x0,x0+r.] c= dom g and
A5: f is_differentiable_on ].x0,x0+r.[ and
A6: g is_differentiable_on ].x0,x0+r.[ and
A7: ].x0,x0+r.[ c= dom (f/g) and
A8: [.x0,x0+r.] c= dom ((f`|(].x0,x0+r.[))/(g`|(].x0,x0+r.[))) and
A9: f.x0 = 0 & g.x0 = 0 and
A10: f is_continuous_in x0 and
A11: g is_continuous_in x0 and
A12: (f`|(].x0,x0+r.[))/(g`|(].x0,x0+r.[)) is_right_convergent_in x0;
A13: ].x0,x0+r.[ c= [.x0,x0+r.] by XXREAL_1:25;
  then
A14: ].x0,x0+r.[ c= dom g by A4;
A15: ].x0,x0+r.[ c= dom f by A3,A13;
A16: for x st x0<x & x<x0+r ex c st c in ].x0,x.[ & (f/g).x=((f`|].x0,x0+r.[
  )/(g`|].x0,x0+r.[)).c
  proof
    let x;
    assume that
A17: x0<x and
A18: x<x0+r;
    set f1 = (f.x)(#)g - (g.x)(#)f;
A19: dom((g.x)(#)f) = dom f by VALUED_1:def 5;
A20: dom((f.x)(#)g) = dom g by VALUED_1:def 5;
    then
A21: dom((f.x)(#)g - (g.x)(#)f) = dom f /\ dom g by A19,VALUED_1:12;
A22: [.x0,x.] c= [.x0,x0+r.]
    proof
      let y be object;
      assume
A23:  y in [.x0,x.];
      then reconsider y as Real;
      y <= x by A23,XXREAL_1:1;
      then
A24:  y <= x0+r by A18,XXREAL_0:2;
      x0 <= y by A23,XXREAL_1:1;
      hence thesis by A24,XXREAL_1:1;
    end;
    then
A25: [.x0,x.] c= dom f & [.x0,x.] c= dom g by A3,A4;
    then
A26: [.x0,x.] c= dom f1 by A21,XBOOLE_1:19;
A27: x in [.x0,x.] by A17,XXREAL_1:1;
    then x in dom f1 by A26;
    then
A28: x in dom ((f.x)(#)g) /\ dom ((g.x) (#)f) by VALUED_1:12;
    then
A29: x in dom ((f.x) (#)g) by XBOOLE_0:def 4;
A30: x in dom ((g.x)(#)f) by A28,XBOOLE_0:def 4;
A31: f1.x = ((f.x)(#)g).x - ((g.x)(#)f).x by A26,A27,VALUED_1:13
      .= (f.x)*(g.x) - ((g.x)(#)f).x by A29,VALUED_1:def 5
      .= (g.x)*(f.x) - (g.x)*(f.x) by A30,VALUED_1:def 5
      .= 0;
A32: ].x0,x0+r.[ c= dom f by A3,A13;
    not x in {x0} by A17,TARSKI:def 1;
    then
A33: x in [.x0,x.]\{x0} by A27,XBOOLE_0:def 5;
    x in {g1:x0<g1 & g1<x0+r} by A17,A18;
    then
A34: x in ].x0,x0+r.[ by RCOMP_1:def 2;
A35: x0 in [.x0,x.] by A17,XXREAL_1:1;
    then x0 in dom f1 by A26;
    then
A36: x0 in dom ((f.x)(#)g) /\ dom ((g.x)(#)f) by VALUED_1:12;
    then
A37: x0 in dom ((f.x)(#)g) by XBOOLE_0:def 4;
A38: [.x0,x.] c= dom((f.x)(#)g - (g.x)(#)f) by A25,A21,XBOOLE_1:19;
A39: x0 in dom ((g.x)(#)f) by A36,XBOOLE_0:def 4;
A40: ].x0,x0+r.[ c= dom g by A4,A13;
A41: ].x0,x.[ c= ].x0,x0+r.[
    proof
      let y be object;
      assume y in ].x0,x.[;
      then y in {g2:x0<g2 & g2<x} by RCOMP_1:def 2;
      then consider g2 such that
A42:  g2=y & x0<g2 and
A43:  g2<x;
      g2<x0+r by A18,A43,XXREAL_0:2;
      then y in {g3:x0<g3 & g3<x0+r} by A42;
      hence thesis by RCOMP_1:def 2;
    end;
    then
A44: ].x0,x.[ c= dom ((f.x)(#)g) by A14,A20;
    x0 in dom f by A1,XBOOLE_0:def 4;
    then
A45: {x0,x} c= dom f by A34,A32,ZFMISC_1:32;
    ].x0,x.[ c= dom f by A41,A32;
    then ].x0,x.[ \/ {x0,x} c= dom f by A45,XBOOLE_1:8;
    then
A46: [.x0,x.] c= dom f by A17,XXREAL_1:128;
    x0 in dom g by A1,XBOOLE_0:def 4;
    then
A47: {x0,x} c= dom g by A34,A40,ZFMISC_1:32;
    ].x0,x.[ c= dom g by A41,A40;
    then ].x0,x.[ \/ {x0,x} c= dom g by A47,XBOOLE_1:8;
    then
A48: [.x0,x.] c= dom g by A17,XXREAL_1:128;
    g is_differentiable_in x by A6,A34,FDIFF_1:9;
    then
A49: g is_continuous_in x by FDIFF_1:24;
    for s st rng s c= [.x0,x.] & s is convergent & lim s in [.x0,x.]
    holds g/*s is convergent & g.(lim s) = lim (g/*s)
    proof
      let s such that
A50:  rng s c= [.x0,x.] and
A51:  s is convergent and
A52:  lim s in [.x0,x.];
      set z = lim s;
A53:  rng s c= dom g by A48,A50;
A54:  z in ].x0,x.[ \/ {x0,x} by A17,A52,XXREAL_1:128;
      now
        per cases by A54,XBOOLE_0:def 3;
        suppose
          z in ].x0,x.[;
          then g is_differentiable_in z by A6,A41,FDIFF_1:9;
          then g is_continuous_in z by FDIFF_1:24;
          hence thesis by A51,A53,FCONT_1:def 1;
        end;
        suppose
A55:      z in {x0,x};
          now
            per cases by A55,TARSKI:def 2;
            suppose
              z = x0;
              hence thesis by A11,A51,A53,FCONT_1:def 1;
            end;
            suppose
              z = x;
              hence thesis by A49,A51,A53,FCONT_1:def 1;
            end;
          end;
          hence thesis;
        end;
      end;
      hence thesis;
    end;
    then g|[.x0,x.] is continuous by A48,FCONT_1:13;
    then
A56: ((f.x)(#)g)|[.x0,x.] is continuous by A4,A22,FCONT_1:20,XBOOLE_1:1;
    f is_differentiable_in x by A5,A34,FDIFF_1:9;
    then
A57: f is_continuous_in x by FDIFF_1:24;
    for s st rng s c= [.x0,x.] & s is convergent & lim s in [.x0,x.]
    holds f/*s is convergent & f.(lim s) = lim (f/*s)
    proof
      let s;
      assume that
A58:  rng s c= [.x0,x.] and
A59:  s is convergent and
A60:  lim s in [.x0,x.];
      set z = lim s;
A61:  rng s c= dom f by A46,A58;
A62:  z in ].x0,x.[ \/ {x0,x} by A17,A60,XXREAL_1:128;
      now
        per cases by A62,XBOOLE_0:def 3;
        suppose
          z in ].x0,x.[;
          then f is_differentiable_in z by A5,A41,FDIFF_1:9;
          then f is_continuous_in z by FDIFF_1:24;
          hence thesis by A59,A61,FCONT_1:def 1;
        end;
        suppose
A63:      z in {x0,x};
          now
            per cases by A63,TARSKI:def 2;
            suppose
              z = x0;
              hence thesis by A10,A59,A61,FCONT_1:def 1;
            end;
            suppose
              z = x;
              hence thesis by A57,A59,A61,FCONT_1:def 1;
            end;
          end;
          hence thesis;
        end;
      end;
      hence thesis;
    end;
    then f|[.x0,x.] is continuous by A46,FCONT_1:13;
    then ((g.x)(#)f)|[.x0,x.] is continuous by A3,A22,FCONT_1:20,XBOOLE_1:1;
    then
A64: ((f.x)(#)g - (g.x)(#)f)|[.x0,x.] is continuous by A20,A19,A21,A38,A56,
FCONT_1:18;
    g is_differentiable_on ].x0,x.[ by A6,A41,FDIFF_1:26;
    then
A65: (f.x)(#)g is_differentiable_on ].x0,x.[ by A44,FDIFF_1:20;
A66: ].x0,x.[ c= dom ((g.x)(#)f) by A15,A41,A19;
    then ].x0,x.[ c= dom ((f.x)(#)g) /\ dom ((g.x)(#)f) by A44,XBOOLE_1:19;
    then
A67: ].x0,x.[ c= dom ((f.x)(#)g - (g.x)(#)f) by VALUED_1:12;
    f is_differentiable_on ].x0,x.[ by A5,A41,FDIFF_1:26;
    then
A68: (g.x)(#)f is_differentiable_on ].x0,x.[ by A66,FDIFF_1:20;
    f1.x0 = ((f.x)(#)g).x0 - ((g.x)(#)f).x0 by A26,A35,VALUED_1:13
      .= (f.x)*(g.x0) - ((g.x)(#)f).x0 by A37,VALUED_1:def 5
      .= 0 - (g.x)*0 by A9,A39,VALUED_1:def 5
      .= 0;
    then consider t such that
A69: t in ].x0,x.[ and
A70: diff(f1,t)=0 by A17,A64,A68,A67,A65,A26,A31,FDIFF_1:19,ROLLE:1;
A71: (g.x)(#)f is_differentiable_in t by A68,A69,FDIFF_1:9;
A72: f is_differentiable_in t by A5,A41,A69,FDIFF_1:9;
    (f.x)(#)g is_differentiable_in t by A65,A69,FDIFF_1:9;
    then 0=diff((f.x)(#)g,t) - diff((g.x)(#)f,t) by A70,A71,FDIFF_1:14;
    then
A73: 0=diff((f.x)(#)g,t) - (g.x)*diff(f,t) by A72,FDIFF_1:15;
A74: dom (f`|].x0,x0+r.[) /\ (dom (g`|].x0,x0+r.[) \ (g`|].x0,x0+r.[)"{0}
    ) c= dom (g`|].x0,x0+r.[)\(g`|].x0,x0+r.[)"{0} by XBOOLE_1:17;
A75: dom f /\ (dom g\g"{0}) c= dom g\g"{0} by XBOOLE_1:17;
    now
      let y be object;
      assume
A76:  y in [.x0,x.]\{x0};
      then y in [.x0,x.] by XBOOLE_0:def 5;
      then y in {g4: x0<=g4 & g4<=x} by RCOMP_1:def 1;
      then consider g4 such that
A77:  g4=y and
A78:  x0<=g4 and
A79:  g4<=x;
      not y in {x0} by A76,XBOOLE_0:def 5;
      then x0<>g4 by A77,TARSKI:def 1;
      then
A80:  x0<g4 by A78,XXREAL_0:1;
      g4<x0+r by A18,A79,XXREAL_0:2;
      then y in {g5: x0<g5 & g5<x0+r} by A77,A80;
      hence y in ].x0,x0+r.[ by RCOMP_1:def 2;
    end;
    then [.x0,x.]\{x0} c= ].x0,x0+r.[;
    then
A81: [.x0,x.]\{x0} c= dom(f/g) by A7;
    then [.x0,x.]\{x0} c= dom f /\ (dom g\g"{0}) by RFUNCT_1:def 1;
    then [.x0,x.]\{x0} c= dom g\g"{0} by A75;
    then
A82: x in dom g & not x in g"{0} by A33,XBOOLE_0:def 5;
A83: now
      assume g.x=0;
      then g.x in {0} by TARSKI:def 1;
      hence contradiction by A82,FUNCT_1:def 7;
    end;
    take t;
    ].x0,x.[ c= [.x0,x.] by XXREAL_1:25;
    then
A84: t in [.x0,x.] by A69;
    x0<=x0+r by A2,XREAL_1:29;
    then x0 in {g6: x0<=g6 & g6<=x0+r};
    then ].x0,x0+r.[ c= [.x0,x0+r.] & x0 in [.x0,x0+r.] by RCOMP_1:def 1
,XXREAL_1:25;
    then [.x0,x.] c= [.x0,x0+r.] by A34,XXREAL_2:def 12;
    then
A85: [.x0,x.] c= dom ((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)) by A8;
    then [.x0,x.] c= dom (f`|].x0,x0+r.[) /\ (dom (g`|].x0,x0+r.[)\(g`|].x0,
    x0+r.[)"{0}) by RFUNCT_1:def 1;
    then [.x0,x.] c= dom (g`|].x0,x0+r.[)\(g`|].x0,x0+r.[)"{0} by A74;
    then
A86: t in dom (g`|].x0,x0+r.[) & not t in (g`|].x0,x0+r.[)"{0} by A84,
XBOOLE_0:def 5;
A87: now
      assume diff(g,t)=0;
      then (g`|].x0,x0+r.[).t=0 by A6,A41,A69,FDIFF_1:def 7;
      then (g`|].x0,x0+r.[).t in {0} by TARSKI:def 1;
      hence contradiction by A86,FUNCT_1:def 7;
    end;
    g is_differentiable_in t by A6,A41,A69,FDIFF_1:9;
    then 0=(f.x)*diff(g,t) - (g.x)*diff(f,t) by A73,FDIFF_1:15;
    then (f.x)/(g.x) = diff(f,t)/diff(g,t) by A83,A87,XCMPLX_1:94;
    then (f.x)*(g.x)" = diff(f,t)/diff(g,t) by XCMPLX_0:def 9;
    then (f.x)*(g.x)" = diff(f,t)*diff(g,t)" by XCMPLX_0:def 9;
    then (f/g).x = diff(f,t)*diff(g,t)" by A81,A33,RFUNCT_1:def 1;
    then (f/g).x = ((f`|].x0,x0+r.[).t)*diff(g,t)" by A5,A41,A69,FDIFF_1:def 7;
    then (f/g).x = ((f`|].x0,x0+r.[).t)*((g`|].x0,x0+r.[).t)" by A6,A41,A69,
FDIFF_1:def 7;
    hence thesis by A69,A85,A84,RFUNCT_1:def 1;
  end;
A88: for a st a is convergent & lim a = x0 & rng a c= dom (f/g) /\
  right_open_halfline(x0) holds (f/g)/*a is convergent & lim((f/g)/*a) =
  lim_right(((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)),x0)
  proof
    reconsider xx0 = x0 as Element of REAL by XREAL_0:def 1;
    set d = seq_const x0;
    let a;
    assume that
A89: a is convergent and
A90: lim a = x0 and
A91: rng a c= dom (f/g) /\ right_open_halfline(x0);
    consider k such that
A92: for n st k<=n holds x0-r<a.n & a.n<x0+r by A2,A89,A90,LIMFUNC3:7;
    set a1 = a^\k;
    defpred X[Element of NAT,Real] means $2 in ].x0,a1.$1.[ & (((f/g)/*
    a)^\k).$1=((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)).$2;
A93: now
      let n;
      a.(n+k) in rng a by VALUED_0:28;
      then a.(n+k) in right_open_halfline(x0) by A91,XBOOLE_0:def 4;
      then a.(n+k) in {g1:x0<g1} by XXREAL_1:230;
      then ex g1 st a.(n+k)=g1 & x0<g1;
      hence x0<a1.n by NAT_1:def 3;
      a1.n = a.(n+k) & k<=n+k by NAT_1:12,def 3;
      hence a1.n<x0+r by A92;
    end;
A94: for n ex c be Element of REAL st X[n,c]
    proof
      let n;
A95:  rng a1 c= rng a by VALUED_0:21;
      x0<a1.n & a1.n<x0+r by A93;
      then consider c such that
A96:  c in ].x0,a1.n.[ and
A97:  (f/g).(a1.n)=((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)).c by A16;
      take c;
A98:  dom (f/g) /\ right_open_halfline(x0) c= dom (f/g) by XBOOLE_1:17;
      then rng a c= dom (f/g) by A91;
      then ((f/g)/*(a^\k)).n=((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)).c by A97,A95,
FUNCT_2:108,XBOOLE_1:1;
      hence thesis by A91,A96,A98,VALUED_0:27,XBOOLE_1:1;
    end;
    consider b such that
A99: for n holds X[n,b.n] from FUNCT_2:sch 3(A94);
A100: rng b c= dom ((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)) /\
    right_open_halfline(x0)
    proof
      let x be object;
      assume x in rng b;
      then consider n such that
A101: x=b.n by FUNCT_2:113;
      x0<=x0+r by A2,XREAL_1:29;
      then x0 in {g3: x0<=g3 & g3<=x0+r};
      then
A102: x0 in [.x0,x0+r.] by RCOMP_1:def 1;
      x0<a1.n & a1.n<x0+r by A93;
      then a1.n in {g4: x0<=g4 & g4<=x0+r};
      then a1.n in [.x0,x0+r.] by RCOMP_1:def 1;
      then ].x0,a1.n.[ c= [.x0,a1.n.] & [.x0,a1.n.] c= [.x0,x0+r.] by A102,
XXREAL_1:25,XXREAL_2:def 12;
      then ].x0,a1.n.[ c= [.x0,x0+r.];
      then
A103: ].x0,a1.n.[ c= dom ((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)) by A8;
A104: x in ].x0,a1.n.[ by A99,A101;
      then x in {g1:x0<g1 & g1<a1.n} by RCOMP_1:def 2;
      then ex g1 st g1 = x & x0<g1 & g1<a1.n;
      then x in {g2: x0<g2};
      then x in right_open_halfline(x0) by XXREAL_1:230;
      hence thesis by A104,A103,XBOOLE_0:def 4;
    end;
A105: now
      let n be Nat;
A106:    n in NAT by ORDINAL1:def 12;
      b.n in ].x0,a1.n.[ by A99,A106;
      then b.n in {g1:x0<g1 & g1<a1.n} by RCOMP_1:def 2;
      then ex g1 st g1=b.n & x0<g1 & g1<a1.n;
      hence d.n<=b.n & b.n<=a1.n by SEQ_1:57;
    end;
A107: lim d=d.0 by SEQ_4:26
      .=x0 by SEQ_1:57;
    lim a1=x0 by A89,A90,SEQ_4:20;
    then
A108: b is convergent & lim b=x0 by A89,A107,A105,SEQ_2:19,20;
A109: dom ((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)) /\ right_open_halfline(x0)
    c= dom ((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)) by XBOOLE_1:17;
A110: now
      reconsider m = 0 as Nat;
      take m;
      let n be Nat such that
      m <=n;
A111:    n in NAT by ORDINAL1:def 12;
      (((f/g)/*a)^\k).n=((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)).(b.n) by A99,A111;
      hence (((f/g)/*a)^\k).n = (((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[))/*b).n by
A100,A109,FUNCT_2:108,XBOOLE_1:1,A111;
    end;
    lim_right(((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)),x0)= lim_right(((f`|].
    x0,x0+r.[)/(g`|].x0,x0+r.[)),x0);
    then
A112: ((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[))/*b is convergent by A12,A108,A100,
LIMFUNC2:def 8;
    then
A113: ((f/g)/*a)^\k is convergent by A110,SEQ_4:18;
    lim (((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[))/*b) = lim_right(((f`|].x0,
    x0+ r.[)/(g`|].x0,x0+r.[)),x0) by A12,A108,A100,LIMFUNC2:def 8;
    then lim (((f/g)/*a)^\k) = lim_right(((f`|].x0,x0+r.[)/(g`|].x0,x0+r.[)),
    x0) by A112,A110,SEQ_4:19;
    hence thesis by A113,SEQ_4:21,22;
  end;
A114: for r1 st x0<r1 ex t st t<r1 & x0<t & t in dom (f/g) by A2,A7,LIMFUNC2:4;
  hence f/g is_right_convergent_in x0 by A88,Th2;
  take r;
  thus r>0 by A2;
  thus thesis by A114,A88,Th2;
end;
