reserve P for Subset of TOP-REAL 2,
  f,f1,f2,g for FinSequence of TOP-REAL 2,
  p,p1,p2,q,q1,q2 for Point of TOP-REAL 2,
  r1,r2,r19,r29 for Real,
  i,j,k,n for Nat;

theorem Th31:
  f is unfolded & g is unfolded & k+1 = len f & LSeg(f,k) /\ LSeg(
f/.len f,g/.1) = {f/.len f} & LSeg(f/.len f,g/.1) /\ LSeg(g,1) = {g/.1} implies
  f^g is unfolded
proof
  assume that
A1: f is unfolded and
A2: g is unfolded and
A3: k+1 = len f and
A4: LSeg(f,k) /\ LSeg(f/.len f,g/.1) = {f/.len f} and
A5: LSeg(f/.len f,g/.1) /\ LSeg(g,1) = {g/.1};
  let i be Nat such that
A6: 1 <= i and
A7: i + 2 <= len(f^g);
A8: len(f^g) = len f + len g by FINSEQ_1:22;
  per cases;
  suppose
A9: i+2 <= len f;
    then
A10: i+1 in dom f by A6,SEQ_4:135;
A11: i+(1+1) = i+1+1;
    i+1 <= i+1+1 by NAT_1:11;
    hence LSeg(f^g,i) /\ LSeg(f^g,i+1) = LSeg(f,i) /\ LSeg(f^g,i+1) by A9,Th6,
XXREAL_0:2
      .= LSeg(f,i) /\ LSeg(f,i+1) by A9,A11,Th6
      .= {f/.(i+1)} by A1,A6,A9
      .= {(f^g)/.(i+1)} by A10,FINSEQ_4:68;
  end;
  suppose
A12: i + 2 > len f;
A13: i+(1+1) = i+1+1;
    now
      per cases;
      suppose
A14:    i <= len f;
        len g <> 0 by A7,A8,A12;
        then 1 <= len g by NAT_1:14;
        then
A15:    1 in dom g by FINSEQ_3:25;
A16:    f is non empty by A6,A14;
        now
          per cases;
          suppose
A17:        i = len f;
            then
A18:        LSeg(f^g,i+1) = LSeg(g,1) by Th7;
            LSeg(f^g,i) = LSeg(f/.len f,g/.1) by A16,A15,A17,Th8,RELAT_1:38;
            hence thesis by A5,A15,A17,A18,FINSEQ_4:69;
          end;
          suppose
            i <> len f;
            then i < len f by A14,XXREAL_0:1;
            then
A19:        i+1 <= len f by NAT_1:13;
            len f <= i+1 by A12,A13,NAT_1:13;
            then
A20:        i+1 = len f by A19,XXREAL_0:1;
            then
A21:        LSeg(f^g,i) = LSeg(f,k) by A3,Th6;
A22:        len f in dom f by A16,FINSEQ_5:6;
            LSeg(f^g,i+1) = LSeg(f/.len f,g/.1) by A16,A15,A20,Th8,RELAT_1:38;
            hence thesis by A4,A20,A21,A22,FINSEQ_4:68;
          end;
        end;
        hence thesis;
      end;
      suppose
A23:    i > len f;
        then reconsider j = i - len f as Element of NAT by INT_1:5;
        len f + 1 <= i by A23,NAT_1:13;
        then
A24:    1 <= j by XREAL_1:19;
A25:    i+2-len f <= len g by A7,A8,XREAL_1:20;
        then
A26:    j+(1+1) <= len g;
        j+1 <= j+1+1 by NAT_1:11;
        then j+1 <= len g by A25,XXREAL_0:2;
        then
A27:    j+1 in dom g by A24,SEQ_4:134;
A28:    len f + (j+1) = i+1;
        len f + j = i;
        hence LSeg(f^g,i) /\ LSeg(f^g,i+1) = LSeg(g,j) /\ LSeg(f^g,i+1) by A24
,Th7
          .= LSeg(g,j) /\ LSeg(g,j+1) by A28,Th7,NAT_1:11
          .= {g/.(j+1)} by A2,A24,A26
          .= {(f^g)/.(i+1)} by A28,A27,FINSEQ_4:69;
      end;
    end;
    hence thesis;
  end;
end;
