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 Th35:
  for S, T, X being Element of REAL n st S = y & T = z & X = x
holds y <> z & y in Ball(x,r) & a = (-(2*|(z-y,y-x)|) +
  sqrt delta (Sum sqr (T- S), 2 * |(z-y,y-x)|, Sum sqr (S-X) - r^2))
    / (2 * Sum sqr (T-S)) implies ex e
being Point of TOP-REAL n st {e} = halfline(y,z) /\ Sphere(x,r) & e = (1-a)*y +
  a*z
proof
  let S, T, X be Element of REAL n such that
A1: S = y and
A2: T = z and
A3: X = x;
  set s = y, t = z;
A4: Sum sqr (T-S) >= 0 by RVSUM_1:86;
  then
A5: |. T-S .|^2 = Sum sqr (T-S) by SQUARE_1:def 2;
  set A = Sum sqr (T-S);
  assume that
A6: s <> t and
A7: s in Ball(x,r) and
A8: a = (-(2*|(z-y,y-x)|) + sqrt delta (Sum sqr (T-S), 2 * |(z-y,y-x)|,
  Sum sqr (S-X) - r^2)) / (2 * Sum sqr (T-S));
A9: |. T-S .| <> 0 by A1,A2,A6,EUCLID:16;
A10: now
    assume A <= 0;
    then A = 0 by RVSUM_1:86;
    hence contradiction by A9;
  end;
  set C = Sum sqr (S-X) - r^2;
  set B = 2 * |(t-s,s-x)|;
A11: r = 0 or r <> 0;
  Sum sqr (S-X) >= 0 by RVSUM_1:86;
  then
A12: |. S-X .|^2 = Sum sqr (S-X) by SQUARE_1:def 2;
  |. s-x .| < r by A7,Th5;
  then (sqrt Sum sqr (S-X))^2 < r^2 by A1,A3,SQUARE_1:16;
  then
A13: C < 0 by A12,XREAL_1:49;
  then
A14: C/A < 0 by A10,XREAL_1:141;
  set l2 = (- B + sqrt delta(A,B,C)) / (2 * A);
  set l1 = (- B - sqrt delta(A,B,C)) / (2 * A);
  take e1 = (1-l2)*s+l2*t;
A15: 0 <= --r by A7;
A16: delta(A,B,C) = B^2 - 4*A*C & B^2 >= 0 by QUIN_1:def 1,XREAL_1:63;
A17: for x being Real holds Polynom(A,B,C,x) = Quard(A,l1,l2,x)
  proof
    let x be Real;
    thus Polynom(A,B,C,x) = A*x^2+B*x+C by POLYEQ_1:def 2
      .= A*(x-l1)*(x-l2) by A10,A13,A16,QUIN_1:16
      .= A*((x-l1)*(x-l2))
      .= Quard(A,l1,l2,x) by POLYEQ_1:def 3;
  end;
  then C/A = l1*l2 by A10,POLYEQ_1:11;
  then
A18: l1 < 0 & l2 > 0 or l1 > 0 & l2 < 0 by A14,XREAL_1:133;
A19: A*l2^2+B*l2--C = Polynom(A,B,C,l2) by POLYEQ_1:def 2
    .= Quard(A,l1,l2,l2) by A17
    .= A*((l2-l1)*(l2-l2)) by POLYEQ_1:def 3
    .= 0;
  |. e1 - x .|^2 = |. 1 * s - l2*s + l2*t - x .|^2 by RLVECT_1:35
    .= |. s - l2*s + l2*t - x .|^2 by RLVECT_1:def 8
    .= |. s + l2*t - l2*s - x .|^2 by RLVECT_1:def 3
    .= |. s + (l2*t - l2*s) - x .|^2 by RLVECT_1:def 3
    .= |. s - x + (l2*t - l2*s) .|^2 by RLVECT_1:def 3
    .= |. s-x + l2*(t-s) .|^2 by RLVECT_1:34
    .= |. s-x .|^2 + 2*|(l2*(t-s),s-x)| + |. l2*(t-s) .|^2 by EUCLID_2:45
    .= Sum sqr (S-X) + 2*(l2*|(t-s,s-x)|) + |. l2*(t-s) .|^2
         by A12,A1,A3,EUCLID_2:19
    .= Sum sqr (S-X) + 2*l2*|(t-s,s-x)| + (|.l2.|*|. t-s .|)^2 by TOPRNS_1:7
    .= Sum sqr (S-X) + 2*l2*|(t-s,s-x)| + (|.l2.|)^2*|. t-s .|^2
    .= Sum sqr (S-X) + l2*(2 * |(t-s,s-x)|) + l2^2*(|. T-S .|^2)
            by A1,A2,COMPLEX1:75
    .= Sum sqr (S-X) + l2*B + l2^2*A by A4,SQUARE_1:def 2
    .= r^2 by A19;
  then |. e1 - x .| = r or |. e1 - x .| = -r by SQUARE_1:40;
  then
A20: e1 in Sphere(x,r) by A15,A11;
A21: 4*A*C < 0 by A10,A13,XREAL_1:129,132;
  then
A22: e1 in halfline(s,t) by A10,A16,A18,QUIN_1:25;
  hereby
    let d be object;
    assume d in {e1};
    then d = e1 by TARSKI:def 1;
    hence d in halfline(s,t) /\ Sphere(x,r) by A22,A20,XBOOLE_0:def 4;
  end;
  hereby
    let d be object;
    assume
A23: d in halfline(s,t) /\ Sphere(x,r);
    then d in halfline(s,t) by XBOOLE_0:def 4;
    then consider l being Real such that
A24: d = (1-l)*s+l*t and
A25: 0 <= l;
A26: |. l*(t-s) .|^2 = (|.l.|*|. t-s .|)^2 by TOPRNS_1:7
      .= |.l.|^2 * |. t-s .|^2
      .= l^2 * |. t-s .|^2 by COMPLEX1:75;
    d in Sphere(x,r) by A23,XBOOLE_0:def 4;
    then r = |. (1-l)*s+l*t - x .| by A24,Th7
      .= |. 1 * s - l*s + l*t - x .| by RLVECT_1:35
      .= |. s - l*s + l*t - x .| by RLVECT_1:def 8
      .= |. s - (l*s - l*t) - x .| by RLVECT_1:29
      .= |. s +- (l*s - l*t) +- x .|
      .= |. s +-x +- (l*s - l*t) .| by RLVECT_1:def 3
      .= |. s-x - (l*s - l*t) .|
      .= |. s +-x  +-(l*s - l*t) .|
      .= |. s-x +- l*(s-t) .| by RLVECT_1:34
      .= |. s-x + l*(-(s-t)) .| by RLVECT_1:25
      .= |. s-x + l*(t-s) .| by RLVECT_1:33;
    then r^2 = |. s-x .|^2 + 2*|(l*(t-s),s-x)| + |. l*(t-s) .|^2 by EUCLID_2:45
      .= |. s-x .|^2 + 2*(l*|(t-s,s-x)|) + |. l*(t-s) .|^2 by EUCLID_2:19;
    then A*l^2+B*l+C = 0 by A5,A12,A1,A3,A2,A26;
    then Polynom(A,B,C,l) = 0 by POLYEQ_1:def 2;
    then l = l1 or l = l2 by A10,A13,A16,POLYEQ_1:5;
    hence d in {e1} by A10,A21,A16,A18,A24,A25,QUIN_1:25,TARSKI:def 1;
  end;
  thus thesis by A8;
end;
