reserve p, q for FinSequence,
  X, Y, x, y, e for set,
  D for non empty set,
  i, j, k, l, m, n, r for Nat;
reserve G for Graph;
reserve v, v1, v2, v3, v4 for Element of G;
reserve vs, vs1, vs2 for FinSequence of the carrier of G,
  c, c1, c2 for Chain of G;

theorem Th39:
  vs is_vertex_seq_of c implies (card the carrier of G = 1 or c <>
{} & not c alternates_vertices_in G iff for vs1 st vs1 is_vertex_seq_of c holds
  vs1 = vs)
proof
  assume
A1: vs is_vertex_seq_of c;
  hereby
    assume
A2: card the carrier of G = 1 or c <>{} & not c alternates_vertices_in G;
    per cases by A2;
    suppose
A3:   card the carrier of G = 1;
      then reconsider tVG = the carrier of G as finite set;
      consider X being object such that
A4:   tVG = {X} by A3,CARD_2:42;
A5:   rng vs c= {X} by A4,FINSEQ_1:def 4;
A6:   len vs = len c +1 by A1;
      let vs1;
A7:   Seg len vs = dom vs by FINSEQ_1:def 3;
      assume vs1 is_vertex_seq_of c;
      then
A8:   len vs1 = len c +1;
      assume vs1 <> vs;
      then consider j being Nat such that
A9:   j in dom vs and
A10:  vs1.j <> vs.j by A8,A6,FINSEQ_2:9;
      vs.j in rng vs by A9,FUNCT_1:def 3;
      then
A11:  vs.j = X by A5,TARSKI:def 1;
A12:  rng vs1 c= {X} by A4,FINSEQ_1:def 4;
      Seg len vs1 = dom vs1 by FINSEQ_1:def 3;
      then vs1.j in rng vs1 by A8,A6,A7,A9,FUNCT_1:def 3;
      hence contradiction by A10,A12,A11,TARSKI:def 1;
    end;
    suppose
A13:  c <>{} & not c alternates_vertices_in G;
      thus for vs1 st vs1 is_vertex_seq_of c holds vs1 = vs
      proof
        set TG = the Target of G;
        set SG = the Source of G;
        let vs1;
        defpred P[Nat] means $1 in dom vs1 & vs1.$1<>vs.$1;
        assume
A14:    vs1 is_vertex_seq_of c;
        then
A15:    len vs1 = len c +1;
A16:    len vs = len c +1 by A1;
        then
A17:    dom vs1 = dom vs by A15,FINSEQ_3:29;
        assume vs1 <> vs;
        then
A18:    ex i being Nat st P[i] by A15,A16,FINSEQ_2:9;
        consider k be Nat such that
A19:    P[k] and
A20:    for n be Nat st P[n] holds k<=n from NAT_1:sch 5 (A18);
A21:    0+1=1 & k=0 or 0+1<=k by NAT_1:13;
        per cases by A21,XXREAL_0:1;
        suppose
          k=0;
          hence contradiction by A19,FINSEQ_3:25;
        end;
        suppose
A22:      k=1;
          thus contradiction
          proof
A23:        0+1=1;
            per cases by A23,NAT_1:13;
            suppose
              len c = 0;
              hence contradiction by A13;
            end;
            suppose
A24:          1<=len c;
              defpred P[Nat] means
$1 in dom c implies vs1/.$1<>vs
/.$1 & vs1/.($1+1)<>vs/.($1+1) & (TG.(c.$1)=TG.(c.1) & SG.(c.$1)=SG.(c.1) or TG
              .(c.$1)=SG.(c.1) & SG.(c.$1)=TG.(c.1));
A25:          vs/.k=vs.k by A17,A19,PARTFUN1:def 6;
A26:          vs1/.k=vs1.k by A19,PARTFUN1:def 6;
A27:          now
                let n be Nat;
                assume
A28:            P[n];
                thus P[n+1]
                proof
                  assume
A29:              (n+1) in dom c;
                  then
A30:              1<=n+1 by FINSEQ_3:25;
A31:              n+1<=len c by A29,FINSEQ_3:25;
                  thus vs1/.(n+1)<>vs/.(n+1) & vs1/.(n+1+1)<>vs/.(n+1+1) & (TG
.(c.(n+1))=TG.(c.1) & SG.(c.(n+1))=SG.(c.1) or TG.(c.(n+1))=SG.(c.1) & SG.(c.(n
                  +1))=TG.(c.1))
                  proof
                    per cases;
                    suppose
A32:                  n=0;
                      hence vs1/.(n+1)<>vs/.(n+1) by A17,A19,A22,A26,
PARTFUN1:def 6;
A33:                  1<=len c by A30,A31,XXREAL_0:2;
                      then c.1 joins vs/.1,vs/.(1+1) by A1;
                      then
A34:                  SG.(c.1)=vs/.1 & TG.(c.1)=vs/.(1+1) or SG.(c.1)=vs
                      /.(1+1) & TG.(c.1)= vs/.1;
                      c.1 joins vs1/.1,vs1/.(1+1) by A14,A33;
                      hence vs1/.(n+1+1)<>vs/.(n+1+1) by A17,A19,A22,A26,A32
,A34,PARTFUN1:def 6;
                      thus thesis by A32;
                    end;
                    suppose
A35:                  0<n;
A36:                  n<=len c by A31,NAT_1:13;
A37:                  0+1<=n by A35,NAT_1:13;
                      hence vs1/.(n+1)<> vs/.(n+1) by A28,A36,FINSEQ_3:25;
                      c.n joins vs1/.n, vs1/.(n+1) by A14,A37,A36;
                      then
A38:                  SG.(c.n)=vs1/.n & TG.(c.n)= vs1/.(n+1) or SG.(c.n)=
                      vs1/.(n+1) & TG.(c. n)=vs1/.n;
                      c.(n+1) joins vs/.(n+1), vs/.(n+1+1) by A1,A30,A31;
                      then
A39:                  SG.(c.(n+1))=vs/.(n+1) & TG.(c.(n+1))=vs/.(n+1+1)
or SG.(c.(n+1))=vs/. (n+1+1) & TG.(c.(n+1))=vs/.(n+1);
A40:                  c.(n+1) joins vs1/.(n+1), vs1/.(n+1+1) by A14,A30,A31;
                      hence vs1/.(n+1+1)<>vs/.(n+1+1) by A28,A37,A36,A39,
FINSEQ_3:25;
                      c.n joins vs/.n, vs/.(n+1) by A1,A37,A36;
                      hence thesis by A28,A37,A36,A38,A40,A39,FINSEQ_3:25;
                    end;
                  end;
                end;
              end;
A41:          P[0] by FINSEQ_3:25;
A42:          for n being Nat holds P[n] from NAT_1:sch 2(A41,A27);
              now
                let x be object;
                hereby
                  assume x in G-VSet rng c;
                  then consider v such that
A43:              x=v and
A44:              ex e being Element of the carrier' of G st e in rng
                  c & (v = (the Source of G).e or v = (the Target of G).e);
                  consider e such that
A45:              e in rng c and
A46:              v = SG.e or v = TG.e by A44;
                  consider d being object such that
A47:              d in dom c and
A48:              e=c.d by A45,FUNCT_1:def 3;
                  reconsider d as Element of NAT by A47;
                  TG.(c.d)=TG.(c.1) & SG.(c.d)=SG.(c.1) or TG.(c.d)=SG.(c
                  .1) & SG.(c.d)=TG.(c.1) by A42,A47;
                  hence x in {SG.(c.1), TG.(c.1)} by A43,A46,A48,TARSKI:def 2;
                end;
                0+1<=len c by A13,NAT_1:13;
                then
A49:            1 in dom c by FINSEQ_3:25;
                then
A50:            c.1 in rng c by FUNCT_1:def 3;
A51:            rng c c= the carrier' of G by FINSEQ_1:def 4;
                then reconsider e=c.1 as Element of the carrier' of G by A50;
                reconsider t = TG.e as Element of G by A50,A51,FUNCT_2:5;
                reconsider s = SG.e as Element of G by A50,A51,FUNCT_2:5;
                assume x in {SG.(c.1), TG.(c.1)};
                then
A52:            x=s or x =t by TARSKI:def 2;
                e in rng c by A49,FUNCT_1:def 3;
                hence x in G-VSet rng c by A52;
              end;
              then
A53:          G-VSet rng c = {SG.(c.1), TG.(c.1)} by TARSKI:2;
              c.k joins vs1/.k, vs1/.(k+1) by A14,A22,A24;
              then
A54:          SG.(c.1)=vs1/.1 & TG.(c.1)=vs1/.(k+1) or SG.(c.1)=vs1/.(k+1
              ) & TG.(c.1 )=vs1/.1 by A22;
A55:          c.k joins vs/.k, vs/.(k+1) by A1,A22,A24;
A56:          now
                let n;
                n in dom c implies TG.(c.n)=TG.(c.1) & SG.(c.n)=SG.(c.1)
                or TG.(c.n)=SG.(c.1) & SG.(c.n)=TG.(c.1) by A42;
                hence n in dom c implies SG.(c.n) <> TG.(c.n) by A19,A22,A26
,A25,A55,A54;
              end;
              SG.(c.1)=vs/.1 & TG.(c.1)=vs/.(k+1) or SG.(c.1)=vs/.(k+1) &
              TG.(c.1)= vs/.1 by A22,A55;
              then card (G-VSet rng c) = 2 by A19,A22,A26,A25,A54,A53,CARD_2:57
;
              hence contradiction by A13,A24,A56;
            end;
          end;
        end;
        suppose
          1<k;
          then 1+1<=k by NAT_1:13;
          then consider k1 being Nat such that
A57:      1<=k1 and
A58:      k1<k and
A59:      k=k1+1 by FINSEQ_6:127;
A60:      k<=len vs1 by A19,FINSEQ_3:25;
          then
A61:      k1<=len vs1 by A58,XXREAL_0:2;
          then
A62:      k1 in dom vs1 by A57,FINSEQ_3:25;
A63:      k1<=len c by A15,A59,A60,XREAL_1:6;
          then c.k1 joins vs1/.k1, vs1/.(k1+1) by A14,A57;
          then
A64:      SG.(c.k1)=vs1/.k1 & TG.(c.k1)=vs1/.k or SG.(c.k1)=vs1/.k & TG.(
          c.k1)= vs1/.k1 by A59;
A65:      vs1/.k1=vs1.k1 by A57,A61,FINSEQ_4:15;
A66:      vs1/.k=vs1.k by A19,PARTFUN1:def 6;
          c.k1 joins vs/.k1, vs/.(k1+1) by A1,A57,A63;
          then
A67:      SG.(c.k1)=vs/.k1 & TG.(c.k1)=vs/.k or SG.(c.k1)=vs/.k & TG.(c.
          k1)=vs/. k1 by A59;
A68:      vs/.k=vs.k by A17,A19,PARTFUN1:def 6;
          vs/.k1=vs.k1 by A15,A16,A57,A61,FINSEQ_4:15;
          hence contradiction by A19,A20,A58,A62,A65,A66,A68,A64,A67;
        end;
      end;
    end;
  end;
  assume
A69: for vs1 st vs1 is_vertex_seq_of c holds vs1 = vs;
  assume card the carrier of G <> 1;
  then consider x, y such that
A70: x in the carrier of G and
A71: y in the carrier of G and
A72: x<>y by Lm7;
  reconsider y as Element of G by A71;
  reconsider x as Element of G by A70;
  assume
A73: c ={} or c alternates_vertices_in G;
  thus contradiction
  proof
    per cases by A73;
    suppose
A74:  c ={};
      then <*x*> = vs by A69,Th32;
      then
A75:  vs.1 = x;
      <*y*> = vs by A69,A74,Th32;
      hence contradiction by A72,A75;
    end;
    suppose
      c alternates_vertices_in G;
      then consider vs1,vs2 such that
A76:  vs1<>vs2 and
A77:  vs1 is_vertex_seq_of c and
A78:  vs2 is_vertex_seq_of c and
      for vs st vs is_vertex_seq_of c holds vs=vs1 or vs=vs2 by Th38;
      vs1 = vs by A69,A77;
      hence contradiction by A69,A76,A78;
    end;
  end;
end;
