
theorem Lm87A:
  for X be RealHilbertSpace, M be Subspace of X,
      x,x0 be Point of X, d be Real
  st x0 in M &
  (ex Y be non empty Subset of REAL st
      Y = {||.x-y.|| where y is Point of X: y in M}
    & d = lower_bound Y >= 0) holds
   d = ||.x-x0.|| iff
     for w be Point of X st w in M holds w, x-x0 are_orthogonal
proof
  let X be RealHilbertSpace, M be Subspace of X,
      x,x0 be Point of X, d be Real;
  assume that
A2: x0 in M and
A3: ex Y be non empty Subset of REAL st
      Y = {||.x-y.|| where y is Point of X: y in M}
    & d = lower_bound Y >= 0;
  consider Y be non empty Subset of REAL such that
A4: Y = {||.x-y.|| where y is Point of X: y in M}
  & d = lower_bound Y >= 0 by A3;
  reconsider r0=0 as Real;
  for r be ExtReal st r in Y holds r0 <= r
  proof
    let r be ExtReal;
    assume r in Y; then
    ex y be Point of X st r = ||.x-y.|| & y in M by A4;
    hence r0 <= r by BHSP_1:28;
  end; then
  r0 is LowerBound of Y by XXREAL_2:def 2; then
A51: Y is bounded_below;
A6: for y0 be Point of X st y0 in M holds d <= ||.x-y0.||
  proof
    let y0 be Point of X;
    assume y0 in M; then
    ||.x-y0.|| in Y by A4;
    hence thesis by A51,A4,SEQ_4:def 2;
  end;
  hereby assume AS1: d = ||.x-x0.||;
    assume not (for w be Point of X st w in M
                 holds w, x-x0 are_orthogonal); then
    consider w be Point of X such that
B1:   w in M & w .|. (x-x0) <> 0;
    set e = w .|. (x-x0);
    set r = e/||.w.||^2;
    set s = ||.w.||^2;
    reconsider w0 = x0 + r*w as Point of X;
B21: r*w in M by B1,RUSUB_1:15;
    per cases;
    suppose C11: s = 0;
      ||.w.|| = 0 by C11,SQUARE_1:17,SQUARE_1:22,BHSP_1:28; then
      w = 0.X by BHSP_1:26;
      hence contradiction by B1,BHSP_1:14;
    end;
    suppose CS2: s <> 0;
C2:   ||.x-w0.||^2 = ||.(x-x0) - r*w.||^2 by RLVECT_1:27
       .= ||.x-x0.||^2 - 2*((x-x0) .|. (r*w)) + ||.r*w.||^2 by RUSUB_5:29;
C3:   (x-x0) .|. (r*w) = (e/s)*e by BHSP_1:3
                      .= (e*e)/s by XCMPLX_1:74
                      .= e^2/s by SQUARE_1:def 1;
C4:   ||.r*w.||^2 = (|.r.|*||.w.||)^2 by BHSP_1:27
                 .= |.r.|^2*s by SQUARE_1:9
                 .= (e/s)^2*s by COMPLEX1:75
                 .= (e*(1/s))^2*s by XCMPLX_1:99
                 .= e^2*(1/s)^2*s by SQUARE_1:9
                 .= e^2*((1/s)^2*s)
                 .= e^2*((1/s)*(1/s)*s) by SQUARE_1:def 1
                 .= e^2*((1/s)*((1/s)*s))
                 .= e^2*((1/s)*1) by CS2,XCMPLX_1:106
                 .= e^2/s by XCMPLX_1:99;
C5:   ||.x-w0.||^2 = ||.x-x0.||^2 - e^2/s by C3,C4,C2;
C6:   0 < e^2 by B1,SQUARE_1:12;
      0 <= ||.w.|| by BHSP_1:28; then
      0 <= ||.w.||*||.w.||; then
      0 < s by CS2,SQUARE_1:def 1; then
C7:   ||.x-w0.||^2 < ||.x-x0.||^2 by C5,XREAL_1:44,C6;
      0 <= ||.x-w0.||*||.x-w0.|| by XREAL_1:63; then
      0 <= ||.x-w0.||^2 by SQUARE_1:def 1; then
      sqrt ||.x-w0.||^2 < sqrt ||.x-x0.||^2 by C7,SQUARE_1:27; then
C91:  ||.x-w0.|| < sqrt ||.x-x0.||^2 by BHSP_1:28,SQUARE_1:22;
      d <= ||.x-w0.|| by A6,B21,A2,RUSUB_1:14;
      hence contradiction by C91,AS1,BHSP_1:28,SQUARE_1:22;
    end;
  end;
  assume AS2: for w be Point of X st w in M holds w, x-x0 are_orthogonal;
B1: for y be Point of X st
      y in M holds ||.x-x0.|| <= ||.x-y.||
  proof
    let y be Point of X;
    assume y in M; then
C1: x0-y,x-x0 are_orthogonal by AS2,A2,RUSUB_1:17;
    x - y = (x - y) + 0.X
         .= (x + -y) + (-x0 + x0) by RLVECT_1:5
         .= ((x + -y) + -x0) + x0 by RLVECT_1:def 3
         .= ((x + -x0) + -y) + x0 by RLVECT_1:def 3
         .= (x - x0) + (x0 - y) by RLVECT_1:def 3; then
    ||.x-y.||^2 = ||.x-x0.||^2 + ||.x0-y.||^2 by C1,RUSUB_5:30; then
C2: ||.x-y.||^2 - ||.x0-y.||^2 = ||.x-x0.||^2;
    0 <= ||.x0-y.||*||.x0-y.|| by XREAL_1:63; then
C31: 0 <= ||.x0-y.||^2 by SQUARE_1:def 1;
    0 <= ||.x-x0.||*||.x-x0.|| by XREAL_1:63; then
    0 <= ||.x-x0.||^2 by SQUARE_1:def 1; then
    sqrt ||.x-x0.||^2 <= sqrt ||.x-y.||^2
      by C31,C2,XREAL_1:43,SQUARE_1:26; then
    ||.x-x0.|| <= sqrt ||.x-y.||^2 by BHSP_1:28,SQUARE_1:22;
    hence ||.x-x0.|| <= ||.x-y.|| by BHSP_1:28,SQUARE_1:22;
  end;
  for s be Real st s in Y holds ||.x-x0.|| <= s
  proof
    let s be Real;
    assume s in Y; then
    consider y0 be Point of X such that
C1:   s = ||.x-y0.|| & y0 in M by A4;
    thus ||.x-x0.|| <= s by B1,C1;
  end; then
B2: ||.x-x0.|| <= d by A4,SEQ_4:43;
  d <= ||.x-x0.|| by A2,A6;
  hence d = ||.x-x0.|| by B2,XXREAL_0:1;
end;
