reserve n for Element of NAT,
  a, r for Real,
  x for Point of TOP-REAL n;
reserve n for Element of NAT,
  r for non negative Real,
  s, t, x for Point of TOP-REAL n;
reserve n for non zero Element of NAT,
  s, t, o for Point of TOP-REAL n;

theorem
  for S, T, O being Element of REAL n st S = s & T = t & O = o holds s
is Point of Tdisk(o,r) & t is Point of Tdisk(o,r) & s <> t & a = (-|(t-s,s-o)|
  + sqrt(|(t-s,s-o)|^2-(Sum sqr (T-S))*(Sum sqr (S-O)-r^2))) / Sum sqr (T-S)
  implies HC(s,t,o,r) = (1-a)*s+a*t
proof
  let S, T, O be Element of REAL n such that
A1: S = s and
A2: T = t and
A3: O = o and
A4: s is Point of Tdisk(o,r) and
A5: t is Point of Tdisk(o,r) and
A6: s <> t;
A7: |. T-S .| = sqrt Sum sqr (T-S) & Sum sqr (T-S) >= 0 by EUCLID:def 5
,RVSUM_1:86;
  set H = HC(s,t,o,r);
A8: H in halfline(s,t) /\ Sphere(o,r) by A4,A5,A6,Def3;
  then H in halfline(s,t) by XBOOLE_0:def 4;
  then consider l being Real such that
A9: H = (1-l)*s + l*t and
A10: 0 <= l by TOPREAL9:26;
  H in Sphere(o,r) by A8,XBOOLE_0:def 4;
  then r = |. (1-l)*s+l*t - o .| by A9,TOPREAL9:9
    .= |. 1 * s - l*s + l*t - o .| by RLVECT_1:35
    .= |. s - l*s + l*t - o .| by RLVECT_1:def 8
    .= |. s - (l*s - l*t) - o .| by RLVECT_1:29
    .= |. s +- (l*s - l*t) +- o .|
    .= |. s+-o +- (l*s - l*t) .| by RLVECT_1:def 3
    .= |. s-o - (l*s - l*t) .|
    .= |. s-o +- l*(s-t) .| by RLVECT_1:34
    .= |. s-o + l*(-(s-t)) .| by RLVECT_1:25
    .= |. s-o + l*(t-s) .| by RLVECT_1:33;
  then
A11: r^2 = |. s-o .|^2 + 2*|(l*(t-s),s-o)| + |. l*(t-s) .|^2 by EUCLID_2:45
    .= |. s-o .|^2 + 2*(l*|(t-s,s-o)|) + |. l*(t-s) .|^2 by EUCLID_2:19;
  set A = Sum sqr (T-S);
A12: |. T-S .| <> 0 by A1,A2,A6,EUCLID:16;
A13: now
    assume A <= 0;
    then A = 0 by RVSUM_1:86;
    hence contradiction by A12,EUCLID:def 5,SQUARE_1:17;
  end;
  set C = Sum sqr (S-O) - r^2;
  set M = |(t-s,s-o)|;
  set B = 2*M;
  set l1 = (- B - sqrt delta(A,B,C)) / (2 * A);
  set l2 = (- B + sqrt delta(A,B,C)) / (2 * A);
A14: |. S-O .| = sqrt Sum sqr (S-O) by EUCLID:def 5;
  Sum sqr (S-O) >= 0 by RVSUM_1:86;
  then
A15: |. S-O .|^2 = Sum sqr (S-O) by A14,SQUARE_1:def 2;
A16: delta(A,B,C) = B^2 - 4*A*C by QUIN_1:def 1;
  the carrier of Tdisk(o,r) = cl_Ball(o,r) by Th3;
  then |. s-o .| <= r by A4,TOPREAL9:8;
  then
A17: (sqrt Sum sqr (S-O))^2 <= r^2 by A1,A3,A14,SQUARE_1:15;
  then
A18: C <= 0 by A14,A15,XREAL_1:47;
  now
    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 A13,A18,A16,QUIN_1:16
      .= A*((x-l1)*(x-l2))
      .= Quard(A,l1,l2,x) by POLYEQ_1:def 3;
  end;
  then
A19: C/A = l1*l2 by A13,POLYEQ_1:11;
A20: now
    set D = sqrt delta(A,B,C);
    assume l1 > l2;
    then -D - B > D - B by A13,XREAL_1:72;
    hence contradiction by A13,A18,A16,XREAL_1:9;
  end;
  assume
A21: a = (-M+sqrt(M^2-A*C)) / A;
  delta(A,B,C) = B^2 - 4*A*C by QUIN_1:def 1
    .= 4*(M^2-A*C);
  then
A22: l2 = (-B+sqrt(4)*sqrt(M^2-A*C)) / (2*A) by A13,A18,SQUARE_1:29
    .= (2*(-(M-sqrt(M^2-A*C)))) / (2*A) by SQUARE_1:20
    .= a by A21,XCMPLX_1:91;
A23: H = 1 * s -l*s + l*t by A9,RLVECT_1:35
    .= s -l*s + l*t by RLVECT_1:def 8
    .= s+l*t-l*s by RLVECT_1:def 3
    .= s+(l*t-l*s) by RLVECT_1:def 3
    .= s+l*(t-s) by RLVECT_1:34;
A24: |. 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;
  A*l^2+B*l+C = A*l^2+2*|(t-s,s-o)|*l+(Sum sqr (S-O) - r^2)
    .= |. T-S .|^2*l^2+2*|(t-s,s-o)|*l+(|. S-O .|^2 - r^2) by A7,A15,
SQUARE_1:def 2
    .= |. t-s .|^2*l^2+2*|(t-s,s-o)|*l+(|. s-o .|^2 - r^2) by A1,A2,A3
    .= 0 by A24,A11;
  then Polynom(A,B,C,l) = 0 by POLYEQ_1:def 2;
  then
A25: l = l1 or l = l2 by A13,A18,A16,POLYEQ_1:5;
  per cases by A14,A15,A17,XREAL_1:47;
  suppose
    C < 0;
    hence thesis by A9,A10,A13,A22,A25,A19,A20,XREAL_1:141;
  end;
  suppose
    l1 = l2;
    hence thesis by A9,A22,A25;
  end;
  suppose
A26: C = 0;
    now
A27:  now
        assume l = 0;
        then H = s+0.TOP-REAL n by A23,RLVECT_1:10
          .= s by RLVECT_1:4;
        hence contradiction by A4,A5,A6,Def3;
      end;
      assume
A28:  l = l1;
      per cases;
      suppose
A29:    0 < B;
        then l1 = (-B-B) / (2*A) by A16,A26,SQUARE_1:22;
        hence contradiction by A10,A13,A28,A29,XREAL_1:129,141;
      end;
      suppose
        B <= 0;
        then l1 = (-B--B) / (2*A) by A16,A26,SQUARE_1:23
          .= 0;
        hence contradiction by A28,A27;
      end;
    end;
    hence thesis by A9,A22,A25;
  end;
end;
