reserve n for Nat,
  a, b, r, w for Real,
  x, y, z for Point of TOP-REAL n,
  e for Point of Euclid n;
reserve V for RealLinearSpace,
        p,q,x for Element of V;
reserve p, q, x for Point of TOP-REAL n;

theorem Th36:
  for S, T, Y being Element of REAL n st S = 1/2*y + 1/2*z & T = z
  & Y = x & y <> z & y in Sphere(x,r) & z in cl_Ball(x,r) ex e being Point of
TOP-REAL n st e <> y & {y,e} = halfline(y,z) /\ Sphere(x,r) & (z in Sphere(x,r)
implies e = z) & (not z in Sphere(x,r) & a = (-(2*|(z-(1/2*y + 1/2*z),1/2*y + 1
/2*z-x)|) + sqrt delta (Sum sqr (T-S), 2 * |(z-(1/2*y + 1/2*z),1/2*y + 1/2*z-x
)|, Sum sqr (S-Y) - r^2)) / (2 * Sum sqr (T-S)) implies e = (1-a)*(1/2*y + 1/2*
  z) + a*z)
proof
  let S, T, Y be Element of REAL n such that
A1: S = 1/2*y + 1/2*z & T = z & Y = x;
  reconsider G = x as Point of Euclid n by TOPREAL3:8;
  set s = y, t = z;
  set X = 1/2 * s + 1/2 * t;
  assume that
A2: s <> t and
A3: s in Sphere(x,r) and
A4: t in cl_Ball(x,r);
A5: Ball(G,r) = Ball(x,r) by Th11;
A6: Sphere(x,r) c= cl_Ball(x,r) by Th15;
  per cases;
  suppose
A7: t in Sphere(x,r);
    take t;
    thus thesis by A2,A3,A7,Th34;
  end;
  suppose
A8: not t in Sphere(x,r);
A9: now
      assume
A10:     X = t;
      t +- 1/2 * s +- 1/2 * t = t - 1/2 * s - 1/2 * t
        .= t - t by A10,RLVECT_1:27
        .= 0.TOP-REAL n by RLVECT_1:5;
      then 0.TOP-REAL n
         = t +- 1/2 * t +- 1/2 * s by RLVECT_1:def 3
        .= 1 * t - 1/2 * t - 1/2 * s by RLVECT_1:def 8
        .= (1-1/2) * t - 1/2 * s by RLVECT_1:35
        .= 1/2 * (t-s) by RLVECT_1:34;
      then t-s = 0.TOP-REAL n by RLVECT_1:11;
      hence contradiction by A2,RLVECT_1:21;
    end;
    Ball(x,r) \/ Sphere(x,r) = cl_Ball(x,r) by Th16;
    then
A11: t in Ball(G,r) by A4,A5,A8,XBOOLE_0:def 3;
    set a = (-(2*|(t-X,X-x)|) + sqrt delta (Sum sqr (T-S), 2 * |(t-X,X-x)|,
    Sum sqr (S-Y) - r^2)) / (2 * Sum sqr (T-S));
A12: 1/2 + 1/2 = 1 & |.1/2.| = 1/2 by ABSVALUE:def 1;
    Ball(G,r) = Ball(x,r) by Th11;
    then X in Ball(G,r) by A3,A6,A12,A11,Th22;
    then consider e1 being Point of TOP-REAL n such that
A13: {e1} = halfline(X,t) /\ Sphere(x,r) and
A14: e1 = (1-a)*X + a*t by A1,A5,A9,Th35;
    take e1;
A15: e1 in {e1} by TARSKI:def 1;
    then e1 in halfline(X,t) by A13,XBOOLE_0:def 4;
    then consider l being Real such that
A16: e1 = (1-l)*X + l*t and
A17: 0 <= l;
    hereby
      assume e1 = s;
      then 0.TOP-REAL n = (1-l)*X + l*t - s by A16,RLVECT_1:5
        .= (1-l)*(1/2*s) + (1-l)*(1/2*t) + l*t - s by RLVECT_1:def 5
        .= (1-l)*(1/2*s) + ((1-l)*(1/2*t) + l*t) - s by RLVECT_1:def 3
        .= (1-l)*(1/2*s) - s + ((1-l)*(1/2*t) + l*t) by RLVECT_1:def 3
        .= (1-l)*(1/2*s) - 1 * s + ((1-l)*(1/2*t) + l*t) by RLVECT_1:def 8
        .= (1-l)*(1/2)*s - 1 * s + ((1-l)*(1/2*t) + l*t) by RLVECT_1:def 7
        .= ((1-l)*(1/2) - 1) * s + ((1-l)*(1/2*t) + l*t) by RLVECT_1:35
        .= (-1/2 - l*(1/2)) * s + ((1-l)*(1/2)*t + l*t) by RLVECT_1:def 7
        .= (-1/2 - l*(1/2)) * s + ((1-l)*(1/2) + l) * t by RLVECT_1:def 6
        .= (-(1/2 + l*(1/2))) * s + (1/2 + l*(1/2)) * t
        .= (1/2 + l*(1/2)) * t - (1/2 + l*(1/2)) * s by RLVECT_1:79
        .= (1/2 + l*(1/2)) * (t - s) by RLVECT_1:34;
      then 1/2 + l*(1/2) = 0 or t - s = 0.TOP-REAL n by RLVECT_1:11;
      hence contradiction by A2,A17,RLVECT_1:21;
    end;
A18: s in halfline(s,t) by Th25;
    hereby
      set o = (1+l)/2;
      let m be object;
      assume m in {s,e1};
      then
A19:  m = s or m = e1 by TARSKI:def 2;
      e1 = (1-l)*(1/2*s) + (1-l)*(1/2*t) + l*t by A16,RLVECT_1:def 5
        .= (1-l)*(1/2)*s + (1-l)*(1/2*t) + l*t by RLVECT_1:def 7
        .= (1-l)*(1/2)*s + (1-l)*(1/2)*t + l*t by RLVECT_1:def 7
        .= (1-l)*(1/2)*s + ((1-l)*(1/2)*t + l*t) by RLVECT_1:def 3
        .= (1-l)*(1/2)*s + ((1-l)*(1/2) + l)*t by RLVECT_1:def 6
        .= (1-o)*s + o*t;
      then
A20:  e1 in halfline(s,t) by A17;
      e1 in Sphere(x,r) by A13,A15,XBOOLE_0:def 4;
      hence m in halfline(s,t) /\ Sphere(x,r) by A3,A18,A19,A20,XBOOLE_0:def 4;
    end;
    hereby
      let m be object;
      assume
A21:  m in halfline(s,t) /\ Sphere(x,r);
      then
A22:  m in halfline(s,t) by XBOOLE_0:def 4;
A23:  m in Sphere(x,r) by A21,XBOOLE_0:def 4;
      per cases;
      suppose
        m in halfline(X,t);
        then m in halfline(X,t) /\ Sphere(x,r) by A23,XBOOLE_0:def 4;
        then m = e1 by A13,TARSKI:def 1;
        hence m in {s,e1} by TARSKI:def 2;
      end;
      suppose
A24:    not m in halfline(X,t);
        consider M being Real such that
A25:    m = (1-M)*s + M*t and
A26:    0 <= M by A22;
A27:    now
          set o = 2*M-1;
          assume M > 1;
          then 2*M > 2*1 by XREAL_1:68;
          then
A28:      2*M-1 > 2*1-1 by XREAL_1:14;
          (1-o)*X + o*t = (1-o)*(1/2 * s) + (1-o)*(1/2 * t) + o*t by
RLVECT_1:def 5
            .= (1-o)*(1/2) * s + (1-o)*(1/2 * t) + o*t by RLVECT_1:def 7
            .= (1-o)*(1/2) * s + (1-o)*(1/2) * t + o*t by RLVECT_1:def 7
            .= (1-o)*(1/2) * s + ((1-o)*(1/2) * t + o*t) by RLVECT_1:def 3
            .= (1-o)*(1/2) * s + ((1-o)*(1/2)+o) * t by RLVECT_1:def 6
            .= m by A25;
          hence contradiction by A24,A28;
        end;
        |. t-x .| <= r & |. t-x .| <> r by A4,A8,Th6;
        then |. t-x .| < r by XXREAL_0:1;
        then t in Ball(x,r);
        then
A29:    LSeg(s,t) /\ Sphere(x,r) = {s} by A3,Th31;
        m in LSeg(s,t) by A25,A26,A27;
        then m in {s} by A23,A29,XBOOLE_0:def 4;
        then m = s by TARSKI:def 1;
        hence m in {s,e1} by TARSKI:def 2;
      end;
    end;
    thus thesis by A8,A14;
  end;
end;
