
theorem Th45:
  for G1 being _Graph, v being Vertex of G1, G2 being removeVertex of G1, v
  st v is endvertex holds G1.numComponents() = G2.numComponents()
proof
  let G1 be _Graph, v be Vertex of G1, G2 be removeVertex of G1, v;
  assume A1: v is endvertex;
  then A2: G1 is non _trivial by GLIB_000:122;
  ex f being Function st f is one-to-one &
    dom f = G1.componentSet() & rng f = G2.componentSet()
  proof
    reconsider C = G1.componentSet() as a_partition of the_Vertices_of G1
      by Th23;
    set V = EqClass(v,C);
    set f = id C +* (V, V\{v});
    take f;
    for x1,x2 being object st x1 in dom f & x2 in dom f & f.x1 = f.x2
      holds x1 = x2
    proof
      let x1,x2 be object;
      assume A3: x1 in dom f & x2 in dom f & f.x1 = f.x2;
      then A4: x1 in dom id C & x2 in dom id C by FUNCT_7:30;
      A5: not V\{v} in C
      proof
        assume A6: V\{v} in C;
        set w = the Element of V\{v};
        w in V by A6, XBOOLE_1:36, TARSKI:def 3;
        then w in V /\ (V\{v}) by A6, XBOOLE_0:def 4;
        then A8: not V misses V\{v} by XBOOLE_0:def 7;
        v in {v} by TARSKI:def 1;
        then not v in V\{v} by XBOOLE_0:def 5;
        then A9: V <> V \{v} by EQREL_1:def 6;
        V in C by EQREL_1:def 6;
        hence contradiction by A6, A8, A9, EQREL_1:def 4;
      end;
      per cases;
      suppose x1 <> V & x2 <> V;
        then f.x1 = (id C).x1 & f.x2 = (id C).x2 by FUNCT_7:32;
        then f.x1 = x1 & f.x2 = x2 by A4, FUNCT_1:18;
        hence thesis by A3;
      end;
      suppose x1 = V & x2 <> V;
        then f.x1 = V\{v} & f.x2 = (id C).x2 by A4, FUNCT_7:31, FUNCT_7:32;
        hence thesis by A5, A3, A4, FUNCT_1:18; :: by contradiction
      end;
      suppose x1 <> V & x2 = V;
        then f.x2 = V\{v} & f.x1 = (id C).x1 by A4, FUNCT_7:31, FUNCT_7:32;
        hence thesis by A5, A3, A4, FUNCT_1:18; :: by contradiction
      end;
      suppose x1 = V & x2 = V;
        hence thesis;
      end;
    end;
    hence f is one-to-one by FUNCT_1:def 4;
    thus A10: dom f = dom id C by FUNCT_7:30
      .= G1.componentSet();
    for y being object holds y in rng f iff y in G2.componentSet()
    proof
      let y be object;
      hereby
        assume y in rng f;
        then consider x being object such that
          A11: x in dom f & y = f.x by FUNCT_1:def 3;
        reconsider x as set by TARSKI:1;
        per cases;
        suppose A12: x = V;
          V in dom id C by EQREL_1:def 6;
          then A13: y = V\{v} by A11, A12, FUNCT_7:31;
          ex w being Vertex of G2 st V\{v} = G2.reachableFrom(w)
          proof
            consider e being object such that
              A14: v.edgesInOut() = {e} & not e Joins v,v,G1
              by A1, GLIB_000:def 51;
            set w = v.adj(e);
            A15: e in v.edgesInOut() by A14, TARSKI:def 1;
            then A16: v <> w by A14, GLIB_000:67;
            A17: the_Vertices_of G2 = the_Vertices_of G1 \ {v}
              by A2, GLIB_000:47;
            v in G1.reachableFrom(v) & e Joins v,w,G1
              by A15, GLIB_000:67, GLIB_002:9;
            then A18: w in G1.reachableFrom(v) by GLIB_002:10;
            not w in {v} by A16, TARSKI:def 1;
            then reconsider w0 = w as Vertex of G2 by A17, XBOOLE_0:def 5;
            take w0;
            thus V\{v} = G1.reachableFrom(v)\{v} by Th24
              .= G1.reachableFrom(w)\{v} by A18, GLIB_002:12
              .= G2.reachableFrom(w0) by A1, A18, Th25;
          end;
          hence y in G2.componentSet() by A13, GLIB_002:def 8;
        end;
        suppose A19: x <> V;
          consider w being Vertex of G1 such that
            A20: x = G1.reachableFrom(w) by A10, A11, GLIB_002:def 8;
          A21: x in C & V in C by A10, A11, EQREL_1:def 6;
          x misses V by A19, A21, EQREL_1:def 4;
          then A22: x misses G1.reachableFrom(v) by Th24;
          G1.reachableFrom(w) <> G1.reachableFrom(v) by A20, A22, XBOOLE_1:66;
          then A23: not w in G1.reachableFrom(v) by GLIB_002:12;
          then A24: v <> w by GLIB_002:9;
          A25: the_Vertices_of G2 = the_Vertices_of G1 \ {v}
            by A2, GLIB_000:47;
          not w in {v} by A24, TARSKI:def 1;
          then reconsider w0 = w as Vertex of G2 by A25, XBOOLE_0:def 5;
          G1.reachableFrom(w) = G2.reachableFrom(w0) by A2, A23, Th26;
          then A26: x in G2.componentSet() by A20, GLIB_002:def 8;
          x = (id C).x by A10, A11, FUNCT_1:18
            .= y by A11, A19, FUNCT_7:32;
          hence y in G2.componentSet() by A26;
        end;
      end;
      assume y in G2.componentSet();
      then consider w0 being Vertex of G2 such that
        A27: y = G2.reachableFrom(w0) by GLIB_002:def 8;
      the_Vertices_of G2 c= the_Vertices_of G1;
      then reconsider w = w0 as Vertex of G1 by TARSKI:def 3;
      ex x being object st x in dom f & y = f.x
      proof
        per cases;
        suppose A28: w in G1.reachableFrom(v);
          then G2.reachableFrom(w0) = G1.reachableFrom(w) \ {v} by A1, Th25;
          then y = G1.reachableFrom(v) \ {v} by A27, A28, GLIB_002:12;
          then A29: y = V\{v} by Th24;
          take V;
          V = G1.reachableFrom(v) by Th24;
          then A30: V in C by GLIB_002:def 8;
          hence V in dom f by A10;
          V in dom id C by A30;
          hence y = f.V by A29, FUNCT_7:31;
        end;
        suppose A31: not w in G1.reachableFrom(v);
          then A32: G2.reachableFrom(w0) = G1.reachableFrom(w) by A2, Th26;
          set x = G1.reachableFrom(w);
          take x;
          A33: x in G1.componentSet() by GLIB_002:def 8;
          hence x in dom f by A10;
          x <> V
          proof
            assume x = V;
            then x = G1.reachableFrom(v) by Th24;
            hence contradiction by A31, GLIB_002:9;
          end;
          then f.x = (id C).x by FUNCT_7:32
            .= x by A33, FUNCT_1:18;
          hence y = f.x by A27, A32;
        end;
      end;
      hence thesis by FUNCT_1:def 3;
    end;
    hence rng f = G2.componentSet() by TARSKI:2;
  end;
  then card G1.componentSet() = card G2.componentSet()
    by WELLORD2:def 4, CARD_1:5;
  then G1.numComponents() = card G2.componentSet() by GLIB_002:def 9;
  hence thesis by GLIB_002:def 9;
end;
