reserve P,P1,P2,R for Subset of TOP-REAL 2,
  p,p1,p2,p3,p11,p22,q,q1,q2,q3,q4 for Point of TOP-REAL 2,
  f,h for FinSequence of TOP-REAL 2,
  r for Real,
  u for Point of Euclid 2,
  n,m,i,j,k for Nat,
  x,y for set;

theorem Th22:
  not f/.1 in Ball(u,r) & f/.len f in Ball(u,r) & p in Ball(u,r) &
f is being_S-Seq & not p in L~f implies ex h st L~h is_S-P_arc_joining f/.1,p &
  L~h c= L~f \/ Ball(u,r)
proof
  set p1 = f/.1;
  set Mf= {LSeg(f,k):1<=k & k+1<=len f};
  assume that
A1: not p1 in Ball(u,r) and
A2: f/.len f in Ball(u,r) and
A3: p in Ball(u,r) and
A4: f is being_S-Seq and
A5: not p in L~f;
A6: f is special by A4;
  defpred X[Nat] means 1<=$1 & $1<=len f - 1 & LSeg(f,$1) meets Ball(u,r);
A7: len f>= 2 by A4;
  then reconsider n=len f - 1 as Element of NAT by INT_1:5,XXREAL_0:2;
  2=1+1;
  then
A8: 1<=len f - 1 by A7,XREAL_1:19;
  n+1=len f;
  then f/.len f in LSeg(f,n) by A8,TOPREAL1:21;
  then LSeg(f,n) meets Ball(u,r) by A2,XBOOLE_0:3;
  then
A9: ex n be Nat st X[n] by A8;
  consider m be Nat such that
A10: X[m] and
A11: for i be Nat st X[i] holds m<=i from NAT_1:sch 5(A9);
  reconsider m as Element of NAT by ORDINAL1:def 12;
  consider q1,q2 such that
A12: f/.m = q1 and
A13: f/.(m+1) = q2;
A14: LSeg(f,m) /\ Ball(u,r) <> {} by A10,XBOOLE_0:def 7;
A15: m+1<=len f by A10,XREAL_1:19;
  then
A16: LSeg(f,m) = LSeg(q1,q2) by A10,A12,A13,TOPREAL1:def 3;
  m<=m+1 by NAT_1:11;
  then
A17: m<=len f by A15,XXREAL_0:2;
A18: Seg len f=dom f by FINSEQ_1:def 3;
A19: now
    set x = the Element of Ball(u,r) /\ L~(f|m);
    set M = {LSeg(f|m,i):1<=i & i+1<=len(f|m)};
A20: Seg len(f|m) = dom(f |m ) by FINSEQ_1:def 3;
    assume
A21: Ball(u,r) /\ L~(f|m) <> {};
    then
A22: x in Ball(u,r) by XBOOLE_0:def 4;
    x in L~(f|m) by A21,XBOOLE_0:def 4;
    then consider X be set such that
A23: x in X and
A24: X in M by TARSKI:def 4;
    consider k such that
A25: X=LSeg(f|m,k) and
A26: 1<=k and
A27: k+1<=len(f|m) by A24;
    k<=k+1 by NAT_1:11;
    then k<=len(f|m) by A27,XXREAL_0:2;
    then
A28: k in Seg len(f|m) by A26,FINSEQ_1:1;
    1<=k+1 by NAT_1:11;
    then k+1 in Seg len(f|m) by A27,FINSEQ_1:1;
    then x in LSeg(f,k) by A23,A25,A28,A20,TOPREAL3:17;
    then
A29: LSeg(f,k) meets Ball(u,r) by A22,XBOOLE_0:3;
    Seg m c= Seg len f by A17,FINSEQ_1:5;
    then
A30: Seg m = dom f /\ (Seg m) by A18,XBOOLE_1:28
      .= dom(f|(Seg m)) by RELAT_1:61
      .= Seg len(f|m) by A20,FINSEQ_1:def 16;
A31: k+1-1 <= len(f|m)-1 by A27,XREAL_1:9;
    then
A32: k<=m-1 by A30,FINSEQ_1:6;
    m = len(f|m) by A30,FINSEQ_1:6;
    then len(f|m) -1<=len f - 1 by A17,XREAL_1:9;
    then k<=len f - 1 by A31,XXREAL_0:2;
    then m<=k by A11,A26,A29;
    then m<=m-1 by A32,XXREAL_0:2;
    then 0<=m+-1-m by XREAL_1:48;
    hence contradiction;
  end;
  for i st 1<=i<=len f - 1 & LSeg(f,i) /\ Ball(u,r) <> {}
   holds m<=i by A11,XBOOLE_0:def 7;
  then
A33: not q1 in Ball(u,r) by A1,A10,A12,TOPREAL3:26;
  set A=LSeg(f,m) /\ Ball(u,r);
A34: q1=|[q1`1,q1`2]| & q2=|[q2`1,q2`2]| by EUCLID:53;
  m+1 <= n+1 by A10,XREAL_1:6;
  then LSeg(f,m) in Mf by A10;
  then
A35: LSeg(f,m) c= union Mf by ZFMISC_1:74;
  now
    per cases;
    suppose
      ex q st q in A & (p`1=q`1 or p`2=q`2);
      then consider q such that
A36:  q in A and
A37:  p`1=q`1 or p`2=q`2;
A38:  q in Ball(u,r) by A36,XBOOLE_0:def 4;
A39:  q in LSeg(q,p) by RLTOPSP1:68;
A40:  q in LSeg(f,m) by A36,XBOOLE_0:def 4;
      then consider h such that
A41:  h is being_S-Seq and
A42:  h/.1=p1 and
A43:  h/.len h=q and
A44:  L~h is_S-P_arc_joining p1,q and
A45:  L~h c= L~f and
A46:  L~h = L~(f|m) \/ LSeg(q1,q) by A1,A4,A12,A38,Th17;
      take g = h^<* p *>;
A47:  L~h \/ Ball(u,r) c= L~f \/ Ball(u,r) by A45,XBOOLE_1:9;
A48:  q in L~f by A35,A40;
A49:  now
        per cases by A37;
        suppose
          p`1=q`1;
          hence p`1=q`1 & p`2<>q`2 or p`1<>q`1 & p`2=q`2 by A5,A48,TOPREAL3:6;
        end;
        suppose
          p`2=q`2;
          hence p`1=q`1 & p`2<>q`2 or p`1<>q`1 & p`2=q`2 by A5,A48,TOPREAL3:6;
        end;
      end;
A50:  LSeg(q,p) /\ L~h c= {q}
      proof
A51:    now
          per cases by A6,A10,A15,A12,A13;
          suppose
            q1`1=q2`1;
            hence q1`1 = q`1 or q1`2=q`2 by A34,A16,A40,TOPREAL3:11;
          end;
          suppose
            q1`2=q2`2;
            hence q1`1 = q`1 or q1`2=q`2 by A34,A16,A40,TOPREAL3:12;
          end;
        end;
        LSeg(q,p) = LSeg(q,p) /\ Ball(u,r) by A3,A38,TOPREAL3:21,XBOOLE_1:28;
        then
A52:    LSeg(q,p) /\ (L~(f|m) \/ LSeg(q1,q)) = LSeg(q,p) /\ Ball(u,r) /\
        L~(f|m) \/ LSeg(q,p) /\ LSeg(q1,q) by XBOOLE_1:23
          .= LSeg(q,p) /\(Ball(u,r) /\ L~(f|m))\/ LSeg(q,p) /\ LSeg(q1,q) by
XBOOLE_1:16
          .= LSeg(q1,q) /\ LSeg(q,p) by A19;
A53:    now
          q1 in LSeg(q1,q2) by RLTOPSP1:68;
          then
A54:      LSeg(q1,q) c= LSeg(f,m) by A16,A40,TOPREAL1:6;
          assume p in LSeg(q1,q);
          hence contradiction by A5,A35,A54;
        end;
        let x be object;
        assume x in LSeg(q,p) /\ L~h;
        hence thesis by A3,A33,A38,A49,A46,A52,A53,A51,TOPREAL3:42;
      end;
      q in L~h by A44,Th3;
      then q in LSeg(q,p) /\ L~h by A39,XBOOLE_0:def 4;
      then {q} c= LSeg(q,p) /\ L~h by ZFMISC_1:31;
      then
A55:  LSeg(q,p) /\ L~h = {q} by A50;
      then L~g c=L~h \/ Ball(u,r) by A3,A38,A49,A41,A43,Th19;
      hence L~g is_S-P_arc_joining p1,p & L~g c=L~f \/ Ball(u,r) by A3,A38,A49
,A41,A42,A43,A55,A47,Th19;
    end;
    suppose
A56:  for q st q in A holds p`1<>q`1 & p`2<>q`2;
      set x = the Element of A;
A57:  x in LSeg(f,m) by A14,XBOOLE_0:def 4;
      then reconsider q=x as Point of TOP-REAL 2;
A58:  q`1<>p`1 & q`2<>p`2 by A14,A56;
      q <> p1 by A1,A14,XBOOLE_0:def 4;
      then consider h such that
A59:  h is being_S-Seq and
A60:  h/.1=p1 and
A61:  h/.len h=q and
A62:  L~h is_S-P_arc_joining p1,q and
A63:  L~h c= L~f and
A64:  L~h = L~(f|m) \/ LSeg(q1,q) by A4,A12,A57,Th17;
A65:  q in Ball(u,r) by A14,XBOOLE_0:def 4;
A66:  q=|[q`1,q`2]| & p=|[p`1,p`2]| by EUCLID:53;
      now
        per cases by A3,A65,A66,TOPREAL3:25;
        suppose
A67:      |[q`1,p`2]| in Ball(u,r);
          set v = |[q`1,p`2]|;
A68:      (LSeg(q,v) \/ LSeg(v,p)) /\ L~h c= {q}
          proof
            let x be object;
            set L = LSeg(q,v) \/ LSeg(v,p);
            assume
A69:        x in L /\ L~h;
            LSeg(q,v) c=Ball(u,r) & LSeg(v,p) c=Ball(u,r) by A3,A65,A67,
TOPREAL3:21;
            then L = L /\ Ball(u,r) by XBOOLE_1:8,28;
            then
A70:        L /\ (L~(f|m) \/ LSeg(q1,q)) = L /\ Ball(u,r) /\ L~(f|m) \/
            L /\ LSeg( q1,q) by XBOOLE_1:23
              .= L /\ (Ball(u,r) /\ L~(f|m)) \/ L /\ LSeg(q1,q) by XBOOLE_1:16
              .= {} \/ L /\ LSeg(q1,q) by A19;
A71:        now
              per cases by A6,A10,A15,A12,A13;
              suppose
                q1`1=q2`1;
                hence q1`1 = q`1 or q1`2=q`2 by A34,A16,A57,TOPREAL3:11;
              end;
              suppose
                q1`2=q2`2;
                hence q1`1 = q`1 or q1`2=q`2 by A34,A16,A57,TOPREAL3:12;
              end;
            end;
            now
              per cases by A71;
              suppose
A72:            q1`1 = q`1;
                now
                  q1 in LSeg(q1,q2) by RLTOPSP1:68;
                  then
A73:              LSeg(q1,q) c= LSeg(f,m) by A16,A57,TOPREAL1:6;
A74:              v`2=p`2 by EUCLID:52;
                  assume v in LSeg(q1,q);
                  then v in LSeg(f,m) /\ Ball(u,r) by A67,A73,XBOOLE_0:def 4;
                  hence contradiction by A56,A74;
                end;
                hence thesis by A33,A65,A58,A64,A67,A70,A69,A72,TOPREAL3:43;
              end;
              suppose
                q1`2 = q`2;
                hence thesis by A14,A56,A64,A70,A69,TOPREAL3:27;
              end;
            end;
            hence thesis;
          end;
          take g = h^<* |[q`1,p`2]|,p *>;
          q in LSeg(q,v) by RLTOPSP1:68;
          then
A75:      q in (LSeg(q,v) \/ LSeg(v,p)) by XBOOLE_0:def 3;
A76:      L~h \/ Ball(u,r) c= L~f \/ Ball(u,r) by A63,XBOOLE_1:9;
          q in L~h by A62,Th3;
          then q in (LSeg(q,v) \/ LSeg(v,p)) /\ L~h by A75,XBOOLE_0:def 4;
          then {q} c= (LSeg(q,v) \/ LSeg(v,p)) /\ L~h by ZFMISC_1:31;
          then
A77:      (LSeg(q,|[q`1,p`2]|) \/ LSeg(|[q`1,p`2]|,p)) /\ L~h={q} by A68;
          then L~g c= L~h \/ Ball(u,r) by A3,A65,A58,A59,A61,A67,Th21;
          hence
          L~g is_S-P_arc_joining p1,p & L~g c=L~f \/ Ball(u,r) by A3,A65,A58
,A59,A60,A61,A67,A77,A76,Th21;
        end;
        suppose
A78:      |[p`1,q`2]| in Ball(u,r);
          set v = |[p`1,q`2]|;
A79:      (LSeg(q,v) \/ LSeg(v,p)) /\ L~h c= {q}
          proof
            let x be object;
            set L = LSeg(q,v) \/ LSeg(v,p);
            assume
A80:        x in L /\ L~h;
            LSeg(q,v) c=Ball(u,r) & LSeg(v,p) c= Ball(u,r) by A3,A65,A78,
TOPREAL3:21;
            then L = L /\ Ball(u,r) by XBOOLE_1:8,28;
            then
A81:        L /\ (L~(f|m) \/ LSeg(q1,q)) = L /\ Ball(u,r) /\ L~(f|m) \/
            L /\ LSeg(q1,q) by XBOOLE_1:23
              .= L /\ (Ball(u,r) /\ L~(f|m)) \/ L /\ LSeg(q1,q) by XBOOLE_1:16
              .= {} \/ L /\ LSeg(q1,q) by A19;
A82:        now
              per cases by A6,A10,A15,A12,A13;
              suppose
                q1`1=q2`1;
                hence q1`1 = q`1 or q1`2=q`2 by A34,A16,A57,TOPREAL3:11;
              end;
              suppose
                q1`2=q2`2;
                hence q1`1 = q`1 or q1`2=q`2 by A34,A16,A57,TOPREAL3:12;
              end;
            end;
            now
              per cases by A82;
              suppose
                q1`1 = q`1;
                hence thesis by A14,A56,A64,A81,A80,TOPREAL3:28;
              end;
              suppose
A83:            q1`2 = q`2;
                now
                  q1 in LSeg(q1,q2) by RLTOPSP1:68;
                  then
A84:              LSeg(q1,q) c= LSeg(f,m) by A16,A57,TOPREAL1:6;
A85:              v`1=p`1 by EUCLID:52;
                  assume v in LSeg(q1,q);
                  then v in LSeg(f,m) /\ Ball(u,r) by A78,A84,XBOOLE_0:def 4;
                  hence contradiction by A56,A85;
                end;
                hence thesis by A33,A65,A58,A64,A78,A81,A80,A83,TOPREAL3:44;
              end;
            end;
            hence thesis;
          end;
          take g = h^<* |[p`1,q`2]|,p *>;
          q in LSeg(q,v) by RLTOPSP1:68;
          then
A86:      q in (LSeg(q,v) \/ LSeg(v,p)) by XBOOLE_0:def 3;
A87:      L~h \/ Ball(u,r) c= L~f \/ Ball(u,r) by A63,XBOOLE_1:9;
          q in L~h by A62,Th3;
          then q in (LSeg(q,v) \/ LSeg(v,p)) /\ L~h by A86,XBOOLE_0:def 4;
          then {q} c= (LSeg(q,v) \/ LSeg(v,p)) /\ L~h by ZFMISC_1:31;
          then
A88:      (LSeg(q,|[p`1,q`2]|) \/ LSeg(|[p`1,q`2]|,p)) /\ L~h={q} by A79;
          then L~g c= L~h \/ Ball(u,r) by A3,A65,A58,A59,A61,A78,Th20;
          hence
          L~g is_S-P_arc_joining p1,p & L~g c=L~f \/ Ball(u,r) by A3,A65,A58
,A59,A60,A61,A78,A88,A87,Th20;
        end;
      end;
      hence thesis;
    end;
  end;
  hence thesis;
end;
