
theorem Th31:
  for P being _finite Path-like _Graph ex P0 being vertex-distinct Path of P
  st P0.vertices() = the_Vertices_of P & P0.edges() = the_Edges_of P &
    (Endvertices P = {P0.first(),P0.last()} iff P is non _trivial) &
    (P0 is trivial iff P is _trivial) & (P0 is closed iff P is _trivial) &
    P0 is minlength
proof
  defpred P[Nat] means for P being _finite Path-like _Graph
    st P.order() = $1+1 ex P0 being vertex-distinct Path of P
    st P0.vertices() = the_Vertices_of P & P0.edges() = the_Edges_of P &
    (Endvertices P = {P0.first(),P0.last()} iff P is non _trivial) &
    (P0 is closed iff P is _trivial) & P0 is minlength;
  A1: P[0]
  proof
    let P be _finite Path-like _Graph;
    assume P.order() = 0+1;
    then A2: P is _trivial by GLIB_000:26;
    then consider v being Vertex of P such that
      A3: the_Vertices_of P = {v} by GLIB_000:22;
    take P0 = P.walkOf(v);
    thus P0.vertices() = the_Vertices_of P by A3, GLIB_001:90;
    thus P0.edges() = the_Edges_of P by A2;
    thus thesis by A2;
  end;
  A4: for n being Nat st P[n] holds P[n+1]
  proof
    let n be Nat;
    assume A5: P[n];
    let P be _finite Path-like _Graph;
    assume A6: P.order() = n+1+1;
    then P.order() <> 1;
    then A7: P is non _trivial by GLIB_000:26;
    then A8: P.minDegree() = 1 by Th30;
    set v = the with_min_degree Vertex of P;
    v.degree() = 1 by A8, GLIB_013:def 15;
    then A9: v is endvertex by GLIB_000:174;
    set H = the removeVertex of P,v;
    reconsider H as _finite Path-like _Graph by A9, Th21;
    H.order() + 1 = P.order() by A7, GLIB_000:48;
    then A10: H.order() = n+1 by A6;
    then consider P9 being vertex-distinct Path of H such that
      A11: P9.vertices()=the_Vertices_of H & P9.edges()=the_Edges_of H and
      A12: Endvertices H = {P9.first(),P9.last()} iff H is non _trivial and
      A13: P9 is closed iff H is _trivial and
      A14: P9 is minlength by A5;
    reconsider P8 = P9 as Walk of P by GLIB_001:167;
    reconsider P8 as vertex-distinct Path of P by GLIB_001:176;
    consider e being object such that
      A15: v.edgesInOut() = {e} & not e Joins v,v,P by A9, GLIB_000:def 51;
    set w = v.adj(e);
    e in {e} by TARSKI:def 1;
    then A16: e Joins v,w,P by A15, GLIB_000:67;
    then A17: v <> w by A15;
    then A18: not w in {v} by TARSKI:def 1;
    A19: the_Vertices_of H = the_Vertices_of P \ {v} by A7, GLIB_000:47;
    then reconsider u = w as Vertex of H by A18, XBOOLE_0:def 5;
    v in {v} by TARSKI:def 1;
    then A20: not v in the_Vertices_of H by A19, XBOOLE_0:def 5;
    A21: not e in the_Edges_of H
    proof
      assume e in the_Edges_of H;
      then e Joins v,w,H by A16, GLIB_000:73;
      hence contradiction by A20, GLIB_000:13;
    end;
    A22: P is addAdjVertex of H,u,e,v or P is addAdjVertex of H,v,e,u
      by A7, A15, GLIB_008:38;
    then A23: the_Vertices_of P = the_Vertices_of H \/ {v} &
      the_Edges_of P = the_Edges_of H \/ {e} by A20, A21, GLIB_006:def 12;
    per cases;
    suppose A24: H is _trivial;
      then A25: the_Vertices_of H = {u} by ZFMISC_1:132;
      set P0 = P8.addEdge(e);
      P8.last() = P9.last()
        .= u by A25, TARSKI:def 1;
      then A26: e Joins P8.last(),v,P by A16, GLIB_000:14;
      not v in P9.vertices() by A20;
      then not v in P8.vertices() by GLIB_001:98;
      then reconsider P0 as vertex-distinct Walk of P by A26, GLIB_001:155;
      reconsider P0 as vertex-distinct Path of P;
      take P0;
      thus P0.vertices() = P8.vertices() \/ {v} by A26, GLIB_001:95
        .= the_Vertices_of P by A11, A23, GLIB_001:98;
      thus P0.edges() = P8.edges() \/ {e} by A26, GLIB_001:111
        .= the_Edges_of P by A11, A23, GLIB_001:110;
      A27: u = P9.first() by A25, TARSKI:def 1
        .= P8.first()
        .= P0.first() by A26, GLIB_001:63;
      A28: v = P0.last() by A26, GLIB_001:63;
      H.order() = 1 by A24, GLIB_000:26;
      then A29: Endvertices P = {u} \/ {v} by A6, A10, A23, A25, Lm6
        .= {P0.first(),P0.last()} by A27, A28, ENUMSET1:1;
      P9.first() = u & P9.last() = u by A25, TARSKI:def 1;
      then P9 is_Walk_from u,u by GLIB_001:def 23;
      then P0 is minlength by A14, A21, A22, GLIBPRE1:62, GLIBPRE1:63;
      hence thesis by A17, A27, A28, A29, GLIB_001:def 24;
    end;
    suppose A30: H is non_trivial;
      then A31: Endvertices H = {P9.first(),P9.last()} by A12;
      u is endvertex
      proof
        assume u is non endvertex;
        then u.degree() <> 1 by GLIB_000:174;
        then A33: 2 <= u.degree() by A30, GLIB_000:157, NAT_1:23;
        u.degree() <= 2 by Th17;
        then A34: u.degree() = 2 by A33, XXREAL_0:1;
        w.degree() = u.degree() +` 1 by A20, A21, A22, Th10, Th11;
        hence contradiction by A34, Th17;
      end;
      then u in Endvertices H by GLIB_006:def 8;
      then per cases by A31, TARSKI:def 2;
      suppose A35: u = P9.last(); :: partly same as trivial case
        then A36: e Joins P8.last(),v,P by A16, GLIB_000:14;
        set P0 = P8.addEdge(e);
        not v in P9.vertices() by A20;
        then not v in P8.vertices() by GLIB_001:98;
        then reconsider P0 as vertex-distinct Walk of P by A36, GLIB_001:155;
        reconsider P0 as vertex-distinct Path of P;
        take P0;
        thus A37: P0.vertices() = P8.vertices() \/ {v} by A36, GLIB_001:95
          .= the_Vertices_of P by A11, A23, GLIB_001:98;
        thus P0.edges() = P8.edges() \/ {e} by A36, GLIB_001:111
          .= the_Edges_of P by A11, A23, GLIB_001:110;
        now
          let x be object;
          thus x in Endvertices P implies x = P0.first() or x = P0.last()
          proof
            assume x in Endvertices P;
            then consider p being Vertex of P such that
              A38: x = p & p is endvertex by GLIB_006:def 8;
            thus thesis by A37, A38, GLIB_001:143;
          end;
          assume x = P0.first() or x = P0.last();
          then per cases;
          suppose x = P0.first();
            then A39: x = P8.first() by A36, GLIB_001:63
              .= P9.first();
            then reconsider u9 = x as Vertex of H;
            reconsider v9 = u9 as Vertex of P by A23, XBOOLE_0:def 3;
            A40: u9 <> v by A19, ZFMISC_1:56;
            u9 <> w by A13, A30, A35, A39, GLIB_001:def 24;
            then A41: u9.degree() = v9.degree() by A40, A22, Th9;
            u9 in Endvertices H by A31, A39, TARSKI:def 2;
            then v9.degree() = 1 by A41, GLIB_006:56, GLIB_000:174;
            hence x in Endvertices P by GLIB_006:56, GLIB_000:174;
          end;
          suppose x = P0.last();
            then A42: x = v by A36, GLIB_001:63;
            v is endvertex by A20, A21, A22, GLIB_006:141, GLIB_006:142;
            hence x in Endvertices P by A42, GLIB_006:56;
          end;
        end;
        then A43: Endvertices P = {P0.first(),P0.last()} by TARSKI:def 2;
        P0.first() = P8.first() by A36, GLIB_001:63
          .= P9.first();
        then P0.first() in the_Vertices_of H;
        then A44: P0.first() <> P0.last() by A20, A36, GLIB_001:63;
        P9 is_Walk_from P9.first(), u by A35, GLIB_001:def 23;
        then P0 is minlength by A14, A21, A22, GLIBPRE1:62, GLIBPRE1:63;
        hence thesis by A43, A44, GLIB_001:def 24;
      end;
      suppose A45: u = P9.first();
        then u = P8.first()
          .= P8.reverse().last() by GLIB_001:22;
        then A47: e Joins P8.reverse().last(),v,P by A16, GLIB_000:14;
        set P0 = P8.reverse().addEdge(e);
        not v in P9.vertices() by A20;
        then not v in P8.vertices() by GLIB_001:98;
        then not v in P8.reverse().vertices() by GLIB_001:92;
        then reconsider P0 as vertex-distinct Walk of P by A47, GLIB_001:155;
        reconsider P0 as vertex-distinct Path of P;
        take P0;
        thus A48: P0.vertices()
           = P8.reverse().vertices() \/ {v} by A47, GLIB_001:95
          .= P8.vertices() \/ {v} by GLIB_001:92
          .= the_Vertices_of P by A11, A23, GLIB_001:98;
        thus P0.edges() = P8.reverse().edges() \/ {e} by A47, GLIB_001:111
          .= P8.edges() \/ {e} by GLIB_001:107
          .= the_Edges_of P by A11, A23, GLIB_001:110;
        now
          let x be object;
          thus x in Endvertices P implies x = P0.first() or x = P0.last()
          proof
            assume x in Endvertices P;
            then consider p being Vertex of P such that
              A49: x = p & p is endvertex by GLIB_006:def 8;
            thus thesis by A48, A49, GLIB_001:143;
          end;
          assume x = P0.first() or x = P0.last();
          then per cases;
          suppose x = P0.first();
            then A50: x = P8.reverse().first() by A47, GLIB_001:63
              .= P8.last() by GLIB_001:22
              .= P9.last();
            then reconsider u9 = x as Vertex of H;
            reconsider v9 = u9 as Vertex of P by A23, XBOOLE_0:def 3;
            A51: u9 <> v by A19, ZFMISC_1:56;
            u9 <> w by A13, A30, A45, A50, GLIB_001:def 24;
            then A52: u9.degree() = v9.degree() by A51, A22, Th9;
            u9 in Endvertices H by A31, A50, TARSKI:def 2;
            then v9.degree() = 1 by A52, GLIB_006:56, GLIB_000:174;
            hence x in Endvertices P by GLIB_006:56, GLIB_000:174;
          end;
          suppose x = P0.last();
            then A53: x = v by A47, GLIB_001:63;
            v is endvertex by A20, A21, A22, GLIB_006:141, GLIB_006:142;
            hence x in Endvertices P by A53, GLIB_006:56;
          end;
        end;
        then A54: Endvertices P = {P0.first(),P0.last()} by TARSKI:def 2;
        P0.first() = P8.reverse().first() by A47, GLIB_001:63
          .= P8.last() by GLIB_001:22
          .= P9.last();
        then P0.first() in the_Vertices_of H;
        then A55: P0.first() <> P0.last() by A20, A47, GLIB_001:63;
        P9.reverse() is_Walk_from P9.last(),u
          by A45, GLIB_001:def 23, GLIB_001:23;
        then P0 is minlength by A14, A21, A22, GLIBPRE1:62, GLIBPRE1:63;
        hence thesis by A54, A55, GLIB_001:def 24;
      end;
    end;
  end;
  A58: for n being Nat holds P[n] from NAT_1:sch 2(A1,A4);
  let P be _finite Path-like _Graph;
  consider n being Nat such that
    A59: P.order() = n+1 by NAT_1:6;
  consider P0 being vertex-distinct Path of P such that
    A60: P0.vertices() = the_Vertices_of P & P0.edges() = the_Edges_of P &
      (Endvertices P = {P0.first(),P0.last()} iff P is non _trivial) and
    A61: (P0 is closed iff P is _trivial) & P0 is minlength by A58, A59;
  take P0;
  now
    thus P0 is trivial implies P is _trivial
    proof
      assume P0 is trivial;
      then consider v being Vertex of P such that
        A62: P0 = P.walkOf(v) by GLIB_001:128;
      the_Vertices_of P = {v} by A60, A62, GLIB_001:90;
      then P.order() = 1 by GLIB_000:27;
      hence thesis by GLIB_000:26;
    end;
    assume P is _trivial;
    hence P0 is trivial;
  end;
  hence thesis by A60, A61;
end;
