reserve n,m,i,j,k for Nat,
  x,y,e,X,V,U for set,
  W,f,g for Function;
reserve p,q for FinSequence;
reserve G for Graph,
  pe,qe for FinSequence of the carrier' of G;

theorem Th14:
  for p being Simple oriented Chain of G, q being FinSequence of
the carrier' of G st len p >=1 & len q=1 & (the Source of G).(q.1)=(the Target
of G).(p.(len p)) & (the Source of G).(p.1) <> (the Target of G).(p.(len p)) &
not ex k st 1<=k & k <= len p & (the Target of G).(p.k) =(the Target of G).(q.1
  ) holds p^q is Simple oriented Chain of G
proof
  let p be Simple oriented Chain of G, q be FinSequence of the carrier' of G;
  set FS=the Source of G, FT=the Target of G, v1=FS.(q.1), v2=FT.(q.1), vp=(
  the Target of G).(p.len p), E=the carrier' of G, V=the carrier of G;
  assume that
A1: len p >=1 and
A2: len q=1 and
A3: v1=vp and
A4: FS.(p.1) <> vp and
A5: not ex k st 1<=k & k <= len p & FT.(p.k) = v2;
  set lp=len p;
  1 in dom q by A2,FINSEQ_3:25;
  then reconsider v1, v2 as Element of V by FINSEQ_2:11,FUNCT_2:5;
  consider r being FinSequence of V such that
A6: r is_oriented_vertex_seq_of p and
A7: for n,m st 1<=n & n<m & m<=len r & r.n=r.m holds n=1 & m=len r by
GRAPH_4:def 7;
  set pq=p^q;
  set rv=r^<*v2*>;
A8: len r = len p + 1 by A6,GRAPH_4:def 5;
A9: for n st 1<=n & n<=len p holds p.n joins r/.n, r/.(n+1)
                      by A6,GRAPH_4:1,def 5;
A10: now
    let n;
    assume that
A11: 1 <= n and
A12: n <= len pq;
    per cases;
    suppose
A13:  n=len pq;
      set m=len p;
      take v1,v2;
      p.m orientedly_joins r/.m, r/.(m+1) by A1,A6,GRAPH_4:def 5;
      then
A14:  vp = r/.(m+1) by GRAPH_4:def 1;
A15:  n = len r by A2,A8,A13,FINSEQ_1:22;
      then n in dom r by A11,FINSEQ_3:25;
      hence v1 = r.n by A3,A8,A15,A14,PARTFUN1:def 6
        .=rv.n by A11,A15,Lm1;
      thus v2 = rv.(n+1) by A15,FINSEQ_1:42;
      q.1 joins v1, v2 by GRAPH_1:def 12;
      hence pq.n joins v1, v2 by A2,A8,A15,Lm2;
    end;
    suppose
A16:  n<>len pq;
      take x=r/.n;
      take y=r/.(n+1);
      n < len pq by A12,A16,XXREAL_0:1;
      then
A17:  n < len p +1 by A2,FINSEQ_1:22;
      then
A18:  n+1 <= len r by A8,NAT_1:13;
      n in dom r by A8,A11,A17,FINSEQ_3:25;
      hence x = r.n by PARTFUN1:def 6
        .= rv.n by A8,A11,A17,Lm1;
      1 <= n+1 by NAT_1:12;
      then n+1 in dom r by A18,FINSEQ_3:25;
      hence y = r.(n+1) by PARTFUN1:def 6
        .=rv.(n+1) by A18,Lm1,NAT_1:12;
A19:  n <= len p by A17,NAT_1:13;
      then p.n joins r/.n, r/.(n+1) by A9,A11;
      hence pq.n joins x, y by A11,A19,Lm1;
    end;
  end;
A20: now
    let n;
    assume 1 <= n & n <= len pq;
    then n in dom pq by FINSEQ_3:25;
    then pq.n in rng pq by FUNCT_1:def 3;
    then
A21: pq.n in rng p \/ rng q by FINSEQ_1:31;
    rng p c= E & rng q c= E by FINSEQ_1:def 4;
    then rng p \/ rng q c= E by XBOOLE_1:8;
    hence pq.n in E by A21;
  end;
A22: len rv = len r + 1 by FINSEQ_2:16;
  then
A23: len rv = len pq +1 by A2,A8,FINSEQ_1:22;
  p.lp orientedly_joins r/.lp, r/.(lp+1) by A1,A6,GRAPH_4:def 5;
  then
A24: vp = r/.(lp+1) by GRAPH_4:def 1;
A25: now
    let n,m;
    assume that
A26: 1<=n and
A27: n<m and
A28: m<=len rv and
A29: rv.n=rv.m;
    assume
A30: not (n=1 & m=len rv);
    per cases;
    suppose
      m < len rv;
      then
A31:  m <= len r by A22,NAT_1:13;
A32:  1 <= m by A26,A27,XXREAL_0:2;
      then
A33:  m in dom r by A31,FINSEQ_3:25;
      n < len r by A27,A31,XXREAL_0:2;
      then
A34:  r.n=rv.n by A26,Lm1
        .=r.m by A29,A31,A32,Lm1;
      then
A35:  m=len r by A7,A26,A27,A31;
A36:  n=1 by A7,A26,A27,A31,A34;
      then
A37:  1 in dom r by A27,A35,FINSEQ_3:25;
      p.1 orientedly_joins r/.1, r/.(1+1) by A1,A6,GRAPH_4:def 5;
      then FS.(p.1) = r/.1 by GRAPH_4:def 1
        .=r.m by A34,A36,A37,PARTFUN1:def 6
        .=vp by A8,A24,A35,A33,PARTFUN1:def 6;
      hence contradiction by A4;
    end;
    suppose
A38:  m >= len rv;
      then m=len rv by A28,XXREAL_0:1;
      then
A39:  v2 = rv.m by A22,FINSEQ_1:42;
      consider k being Nat such that
A40:  n=k+1 by A26,NAT_1:6;
      reconsider k as Element of NAT by ORDINAL1:def 12;
      1 < n by A26,A28,A30,A38,XXREAL_0:1;
      then
A41:  1 <= k by A40,NAT_1:13;
      k+1 < len r+1 by A22,A27,A28,A40,XXREAL_0:2;
      then
A42:  k+1 <= len r by NAT_1:13;
      then
A43:  k+1 in dom r by A26,A40,FINSEQ_3:25;
A44:  k <= len p by A8,A42,XREAL_1:6;
      then p.k orientedly_joins r/.k, r/.(k+1) by A6,A41,GRAPH_4:def 5;
      then FT.(p.k) = r/.(k+1) by GRAPH_4:def 1
        .=r.(k+1) by A43,PARTFUN1:def 6
        .=v2 by A26,A29,A39,A40,A42,Lm1;
      hence contradiction by A5,A41,A44;
    end;
  end;
A45: now
    let n;
    assume that
A46: 1 <= n and
A47: n < len pq;
    per cases;
    suppose
A48:  n < len p;
      then
A49:  n+1 <= len p by NAT_1:13;
      FS.(p.(n+1)) = FT.(p.n) & p.n = pq.n by A46,A48,Lm1,GRAPH_1:def 15;
      hence FS.(pq.(n+1)) = FT.(pq.n) by A49,Lm1,NAT_1:12;
    end;
    suppose
A50:  n >= len p;
      n < len p + 1 by A2,A47,FINSEQ_1:22;
      then n <= len p by NAT_1:13;
      then
A51:  n = len p by A50,XXREAL_0:1;
      then pq.n=p.(len p) by A1,Lm1;
      hence FS.(pq.(n+1)) = FT.(pq.n) by A2,A3,A51,Lm2;
    end;
  end;
A52: now
    let n;
    assume that
A53: 1 <= n and
A54: n <= len rv;
    per cases;
    suppose
      n=len rv;
      then rv.n=v2 by A22,FINSEQ_1:42;
      hence rv.n in V;
    end;
    suppose
      n<>len rv;
      then n < len rv by A54,XXREAL_0:1;
      then
A55:  n <= len r by A22,NAT_1:13;
      then n in dom r by A53,FINSEQ_3:25;
      then r.n in V by FINSEQ_2:11;
      hence rv.n in V by A53,A55,Lm1;
    end;
  end;
  now
A56: dom r c= dom rv by FINSEQ_1:26;
    let n;
    assume that
A57: 1<=n and
A58: n<=len pq;
    per cases;
    suppose
A59:  n <= len p;
      then
A60:  n+1 <= len r by A8,XREAL_1:7;
      1 <= n+1 by NAT_1:12;
      then
A61:  n+1 in dom r by A60,FINSEQ_3:25;
      then
A62:  r/.(n+1)= r.(n+1) by PARTFUN1:def 6
        .=rv.(n+1) by A60,Lm1,NAT_1:12
        .=rv/.(n+1) by A56,A61,PARTFUN1:def 6;
A63:  p.n orientedly_joins r/.n, r/.(n+1) by A6,A57,A59,GRAPH_4:def 5;
A64:  n <= len r by A8,A59,NAT_1:12;
      then
A65:  n in dom r by A57,FINSEQ_3:25;
      then r/.n= r.n by PARTFUN1:def 6
        .=rv.n by A57,A64,Lm1
        .=rv/.n by A56,A65,PARTFUN1:def 6;
      hence pq.n orientedly_joins rv/.n, rv/.(n+1) by A57,A59,A63,A62,Lm1;
    end;
    suppose
A66:  n > len p;
A67:  len p+1 >= n by A2,A58,FINSEQ_1:22;
      len p +1 <= n by A66,NAT_1:13;
      then
A68:  n = len r by A8,A67,XXREAL_0:1;
      1 <= n+1 by NAT_1:12;
      then
A69:  n+1 in dom rv by A22,A68,FINSEQ_3:25;
A70:  v2 = rv.(n+1) by A68,FINSEQ_1:42
        .=rv/.(n+1) by A69,PARTFUN1:def 6;
A71:  q.1 orientedly_joins v1, v2 by GRAPH_4:def 1;
A72:  n in dom r by A8,A57,A67,FINSEQ_3:25;
      then v1 = r.n by A3,A8,A24,A68,PARTFUN1:def 6
        .=rv.n by A8,A57,A67,Lm1
        .=rv/.n by A56,A72,PARTFUN1:def 6;
      hence pq.n orientedly_joins rv/.n, rv/.(n+1) by A2,A8,A68,A70,A71,Lm2;
    end;
  end;
  then rv is_oriented_vertex_seq_of pq by A23,GRAPH_4:def 5;
  hence thesis by A20,A23,A52,A10,A45,A25,GRAPH_1:def 14,def 15,GRAPH_4:def 7;
end;
