
theorem Th31:
  for G being _Graph, W being closed Walk of G, n being odd Element of NAT
  st n < len W holds
    W.cut(n+2,len W).append(W.cut(1,n)) is_Walk_from W.(n+2),W.n &
    (W is Trail-like implies
      W.cut(n+2,len W).edges() misses W.cut(1,n).edges() &
      W.cut(n+2,len W).append(W.cut(1,n)).edges() = W.edges() \ {W.(n+1)}) &
    (W is Path-like implies
      W.cut(n+2,len W).vertices() /\ W.cut(1,n).vertices() = {W.first()} &
      (not W.(n+1) in G.loops()
        implies W.cut(n+2,len W).append(W.cut(1,n)) is open) &
      W.cut(n+2,len W).append(W.cut(1,n)) is Path-like)
proof
  let G be _Graph, W be closed Walk of G, n be odd Element of NAT;
  assume A1: n < len W;
  set W7 = W.cut(n+2,len W), W8 = W.cut(1,n), W9 = W7.append(W8), e = W.(n+1);
  A2: 0+1 <= n+1 & n+2 <= len W by A1, CHORD:4, XREAL_1:6;
  then A3: W7 is_Walk_from W.(n+2), W.len W by GLIB_001:37;
  A4: n <= len W by A1;
  A5: 1 <= n & 1 is odd by CHORD:2, POLYFORM:4;
  then A6: W8 is_Walk_from W.1, W.n by A4, GLIB_001:37;
  A7: W.len W = W.last()
    .= W.first() by GLIB_001:def 24
    .= W.1;
  hence W9 is_Walk_from W.(n+2),W.n by A3, A6, GLIB_001:31;
  A8: W7.last() = W.len W & W8.first() = W.1 by A3, A6, GLIB_001:def 23;
  then A9: len W9 + 1 = len W7 + len W8 by A7, GLIB_001:28;
  A10: len W8 = n by A4, GLIB_001:45;
  A11: len W7 + (n+2) = len W + 1 by A2, GLIB_001:36;
  thus W is Trail-like implies
    W7.edges() misses W8.edges() & W9.edges() = W.edges() \ {W.(n+1)}
  proof
    assume A12: W is Trail-like;
    W7.edges() /\ W8.edges() = {}
    proof
      assume W7.edges() /\ W8.edges() <> {};
      then consider x being object such that
        A13: x in W7.edges() /\ W8.edges() by XBOOLE_0:def 1;
      A14: x in W7.edges() & x in W8.edges() by A13, XBOOLE_0:def 4;
      then consider n1 being odd Element of NAT such that
        A15: n1 < len W7 & W7.(n1+1) = x by GLIB_001:100;
      consider n2 being odd Element of NAT such that
        A16: n2 < len W8 & W8.(n2+1) = x by A14, GLIB_001:100;
      A17: W.(1+n2) = x by A4, A5, A16, GLIB_001:36
        .= W.(n+2+n1) by A2, A15, GLIB_001:36;
      1+0 <= 2+n1 by XREAL_1:7;
      then A18: 1+n2 < 2+n1+n by A10, A16, XREAL_1:8;
      n+2+n1 < n+2+len W7 by A15, XREAL_1:6;
      then n+2+n1 < len W + 1 by A11;
      then A19: n+2+n1 <= len W by NAT_1:13;
      1+0 <= 1+n2 by XREAL_1:6;
      hence contradiction by A12, A17, A18, A19, GLIB_001:138;
    end;
    hence W7.edges() misses W8.edges() by XBOOLE_0:def 7;
    :: show that W satisfies the edges property (very technical)
    now
      let x be object;
      :: first inclusion
      hereby
        assume x in W9.edges();
        then consider m being odd Element of NAT such that
          A20: m < len W9 & W9.(m+1) = x by GLIB_001:100;
        m+1 in dom W9 by A20, GLIB_001:12;
        then per cases by GLIB_001:34;
        suppose A21: m+1 in dom W7;
          then A22: x = W7.(m+1) by A20, GLIB_001:32
            .= W.(n+2+(m+1)-1) by A2, A21, GLIB_001:47
            .= W.(n+2+m);
          n+2+(m+1)-1 in dom W by A2, A21, GLIB_001:47;
          then A23: n+2+m <= len W by FINSEQ_3:25;
          1+0 < 2+m by XREAL_1:8;
          then n+1 < n+(2+m) by XREAL_1:8;
          then A24: W.(n+1) <> W.(n+2+m) by A12, A2, A23, GLIB_001:138;
          n+1+m+1 < len W + 1 by A23, NAT_1:13;
          then x in W.edges() by A22, XREAL_1:6, GLIB_001:100;
          hence x in W.edges()\{e} by A22, A24, ZFMISC_1:56;
        end;
        suppose ex k being Element of NAT st k < len W8 & m+1 = len W7 + k;
          then consider k being Element of NAT such that
            A25: k < len W8 & m+1 = len W7 + k;
          A26: x = W8.(k+1) by A7, A8, A20, A25, GLIB_001:33
            .= W.(1+k) by A4, A5, A25, GLIB_001:36;
          A27: 1+0 <= k+1 by XREAL_1:6;
          A28: k is odd by A25;
          A29: k+1 < n+1 by A10, A25, XREAL_1:8;
          n+1 <= len W by A1, NAT_1:13;
          then W.(k+1) <> W.(n+1) by A12, A27, A28, A29, GLIB_001:138;
          then A30: x <> e by A26;
          k < len W by A1, A10, A25, XXREAL_0:2;
          then x in W.edges() by A26, A28, GLIB_001:100;
          hence x in W.edges()\{e} by A30, ZFMISC_1:56;
        end;
      end;
      :: second inclusion
      assume x in W.edges()\{e};
      then A31: x in W.edges() & x <> e by ZFMISC_1:56;
      then consider m being odd Element of NAT such that
        A32: m < len W & W.(m+1) = x by GLIB_001:100;
      per cases by A31, A32, XXREAL_0:1;
      suppose A33: m < n;
        A34: x = W8.(m+1) by A4, A5, A10, A32, A33, GLIB_001:36
          .= W9.(len W7 + m) by A7, A8, A10, A33, GLIB_001:33;
        1 <= m & 0 <= len W7 by CHORD:2;
        then A35: 1+0 <= m + len W7 by XREAL_1:7;
        len W7 + m < len W7 + len W8 by A10, A33, XREAL_1:8;
        then len W7 + m <= len W9 by A9, NAT_1:13;
        hence x in W9.edges() by A34, A35, GLIB_001:99;
      end;
      suppose n < m;
        then len W8 + 1 <= m by A10, NAT_1:13;
        then consider k being Nat such that
          A36: m = len W8 + 1 + k by NAT_1:10;
        reconsider k as odd Element of NAT by A36, ORDINAL1:def 12;
        A37: k < len W7
        proof
          assume len W7 <= k;
          then len W7 + (len W8 + 1) <= k + (len W8 + 1) by XREAL_1:6;
          hence contradiction by A10, A11, A32, A36;
        end;
        then A38: k+1 in dom W7 by GLIB_001:12;
        A39: x = W.(n+2 + k) by A10, A32, A36
          .= W7.(k+1) by A2, A37, GLIB_001:36
          .= W9.(k+1) by A38, GLIB_001:32;
        len W7 <= len W9 by A7, A8, GLIB_001:29;
        then k < len W9 by A37, XXREAL_0:2;
        hence x in W9.edges() by A39, GLIB_001:100;
      end;
    end;
    hence W9.edges() = W.edges()\{e} by TARSKI:2;
  end;
  assume A40: W is Path-like;
  now
    let x be object;
    hereby
      assume x in W7.vertices() /\ W8.vertices();
      then A41: x in W7.vertices() & x in W8.vertices() by XBOOLE_0:def 4;
      then consider n1 being odd Element of NAT such that
        A42: n1 <= len W7 & W7.n1 = x by GLIB_001:87;
      consider n2 being odd Element of NAT such that
        A43: n2 <= len W8 & W8.n2 = x by A41, GLIB_001:87;
      reconsider n3=n1-1, n4=n2-1 as Nat by CHORD:2;
      reconsider n3, n4 as even Element of NAT by ORDINAL1:def 12;
      n3+1 < len W7 + 1 & n4+1 < len W8 + 1 by A42, A43, NAT_1:13;
      then A44: n3 < len W7 & n4 < len W8 by XREAL_1:6;
      then A45: W.(n+2+n3) = W7.(n3+1) by A2, GLIB_001:36
        .= x by A42;
      A46: x = W.(1+n4) by A4, A5, A43, A44, GLIB_001:36;
      A47: n2+0 < n+(2+n3) by A10, A43, XREAL_1:8;
      n+2+n3 = n+1+n1;
      then n+2+n3 <= n+1+len W7 by A42, XREAL_1:6;
      then 1+n4 = 1 by A11, A40, A45, A46, A47, GLIB_001:def 28;
      hence x = W.first() by A46;
    end;
    assume x = W.first();
    then x = W.1;
    then x in W7.vertices() & x in W8.vertices() by A7, A8, GLIB_001:88;
    hence x in W7.vertices() /\ W8.vertices() by XBOOLE_0:def 4;
  end;
  hence A48: W7.vertices() /\ W8.vertices() = {W.first()} by TARSKI:def 1;
  thus not W.(n+1) in G.loops() implies W9 is open
  proof
    assume A49: not W.(n+1) in G.loops() & W9 is closed;
    A50: W.(n+2) = W7.first() by A3, GLIB_001:def 23
      .= W9.first() by A7, A8, GLIB_001:30
      .= W9.last() by A49, GLIB_001:def 24
      .= W8.last() by A7, A8, GLIB_001:30
      .= W.n by A6, GLIB_001:def 23;
    n+0 < n+2 by XREAL_1:8;
    then A51: n = 1 & n+2 = len W by A2, A40, A50, GLIB_001:def 28;
    W.(n+1) Joins W.n,W.(n+2),G by A1, GLIB_001:def 3;
    hence contradiction by A7, A49, A51, GLIB_009:def 2;
  end;
  per cases;
  suppose n = 1;
    then W8 is trivial by A4, GLIB_001:131;
    hence thesis by A40,  GLIB_001:130;
  end;
  suppose n+2 = len W;
    then W7 is trivial by GLIB_001:131;
    hence thesis by A7, A8, A40, HELLY:16;
  end;
  suppose A52: n <> 1 & n+2 <> len W;
    then 1 < n & n <> len W by A1, A5, XXREAL_0:1;
    then A53: W8 is open by A4, A40, Th30, POLYFORM:4;
    n+2 < len W & n+2 <> 1 by A2, A52, XXREAL_0:1;
    then W7 is open by A40, Th30;
    hence thesis by A7, A8, A40, A48, A53, HELLY:19;
  end;
end;
