
theorem Th98:
  for G1 being _Graph, G2 being simple _Graph
  holds G2 is GraphComplement of G1 iff
    the_Vertices_of G2 = the_Vertices_of G1 &
    the_Edges_of G2 misses the_Edges_of G1 &
    for v,w being Vertex of G1 st v <> w holds
      (ex e1 being object st e1 Joins v,w,G1) iff
      (not ex e2 being object st e2 Joins v,w,G2)
proof
  let G1 be _Graph, G2 be simple _Graph;
  :: the first direction is straight forward
  hereby
    assume G2 is GraphComplement of G1;
    then consider G9 being LGraphComplement of G1 such that
      A1: G2 is removeLoops of G9 by Def9;
    thus the_Vertices_of G2 = the_Vertices_of G9 by A1, GLIB_000:def 33
      .= the_Vertices_of G1 by Def7;
    A2: the_Edges_of G2 c= the_Edges_of G9 by A1, GLIB_000:def 32;
    the_Edges_of G9 misses the_Edges_of G1 by Def7;
    hence the_Edges_of G2 misses the_Edges_of G1 by A2, XBOOLE_1:63;
    let v,w be Vertex of G1;
    assume A3: v <> w;
    hereby
      given e1 being object such that
        A4: e1 Joins v,w,G1;
      given e2 being object such that
        A5: e2 Joins v,w,G2;
      e2 Joins v,w,G9 by A1, A5, GLIB_000:72;
      hence contradiction by A4, Th64;
    end;
    assume A6: not ex e2 being object st e2 Joins v,w,G2;
    not ex e9 being object st e9 Joins v,w,G9
    proof
      given e9 being object such that
        A7: e9 Joins v,w,G9;
      A8: e9 in the_Edges_of G9 by A7, GLIB_000:def 13;
      not e9 in G9.loops() by A3, A7, GLIB_009:46;
      then e9 in the_Edges_of G9 \ G9.loops() by A8, XBOOLE_0:def 5;
      then A9: e9 in the_Edges_of G2 by A1, GLIB_000:53;
      e9 Joins v,w,G2 by A1, A7, A9, GLIB_000:73;
      hence contradiction by A6;
    end;
    hence ex e1 being object st e1 Joins v,w,G1 by Def7;
  end;
  :: for the second direction we need to add loops to G2 to get a G9
  :: but the loops must be distinct from both the edges of G1 and of G2,
  :: so some construction is needed (except if G1 is already loopfull)
  assume that A10: the_Vertices_of G2 = the_Vertices_of G1 &
      the_Edges_of G2 misses the_Edges_of G1 and
    A11: for v,w being Vertex of G1 st v <> w holds
      (ex e1 being object st e1 Joins v,w,G1) iff
      (not ex e2 being object st e2 Joins v,w,G2);
  per cases;
  suppose A12: G1 is non loopfull;
    defpred P[object] means not ex e being object st e Joins $1,$1,G1;
    consider V being Subset of the_Vertices_of G2 such that
      A13: for x being set holds x in V iff x in the_Vertices_of G2 & P[x]
      from SUBSET_1:sch 1;
    A14: V is non empty by A10, A12, A13;
    set E = the set of all [{the_Edges_of G1,the_Edges_of G2},v]
      where v is Element of V;
    deffunc F(object) = $1`2;
    consider f being Function such that
      A15: dom f = E & for x being object st x in E holds f.x = F(x)
      from FUNCT_1:sch 3;
    now
      let x1,x2 be object;
      assume A16: x1 in dom f & x2 in dom f & f.x1 = f.x2;
      then consider v1 being Element of V such that
        A17: x1 = [{the_Edges_of G1,the_Edges_of G2},v1] by A15;
      consider v2 being Element of V such that
        A18: x2 = [{the_Edges_of G1,the_Edges_of G2},v2] by A15, A16;
      v1 = [{the_Edges_of G1,the_Edges_of G2},v1]`2
        .= f.x1 by A15, A16, A17
        .= [{the_Edges_of G1,the_Edges_of G2},v2]`2 by A15, A16, A18
        .= v2;
      hence x1 = x2 by A17, A18;
    end;
    then reconsider f as one-to-one Function by FUNCT_1:def 4;
    now
      let y be object;
      hereby
        assume y in rng f;
        then consider x being object such that
          A19: x in dom f & f.x = y by FUNCT_1:def 3;
        consider v being Element of V such that
          A20: x = [{the_Edges_of G1,the_Edges_of G2},v] by A15, A19;
        y = [{the_Edges_of G1,the_Edges_of G2},v]`2 by A15, A19, A20
          .= v;
        hence y in V by A14;
      end;
      set x = [{the_Edges_of G1,the_Edges_of G2},y];
      assume y in V;
      then A21: x in E;
      then f.x = [{the_Edges_of G1,the_Edges_of G2},y]`2 by A15
        .= y;
      hence y in rng f by A15, A21, FUNCT_1:3;
    end;
    then A22: rng f = V by TARSKI:2;
    A23: E misses the_Edges_of G1
    proof
      assume E meets the_Edges_of G1;
      then consider e being object such that
        A24: e in E & e in the_Edges_of G1 by XBOOLE_0:3;
      reconsider e as set by TARSKI:1;
      consider v being Element of V such that
        A25: e = [{the_Edges_of G1,the_Edges_of G2},v] by A24;
      A26: e = {{{the_Edges_of G1,the_Edges_of G2}, v},
        {{the_Edges_of G1,the_Edges_of G2}}} by A25, TARSKI:def 5;
      A27: the_Edges_of G1 in
        {the_Edges_of G1, the_Edges_of G2} by TARSKI:def 2;
      A28: {the_Edges_of G1, the_Edges_of G2} in
        {{the_Edges_of G1, the_Edges_of G2}} by TARSKI:def 1;
      {{the_Edges_of G1, the_Edges_of G2}} in e by A26, TARSKI:def 2;
      hence contradiction by A24, A27, A28, XREGULAR:8;
    end;
    A29: E misses the_Edges_of G2
    proof
      assume E meets the_Edges_of G2;
      then consider e being object such that
        A30: e in E & e in the_Edges_of G2 by XBOOLE_0:3;
      reconsider e as set by TARSKI:1;
      consider v being Element of V such that
        A31: e = [{the_Edges_of G1,the_Edges_of G2},v] by A30;
      A32: e = {{{the_Edges_of G1,the_Edges_of G2}, v},
        {{the_Edges_of G1,the_Edges_of G2}}} by A31, TARSKI:def 5;
      A33: the_Edges_of G2 in
        {the_Edges_of G1, the_Edges_of G2} by TARSKI:def 2;
      A34: {the_Edges_of G1, the_Edges_of G2} in
        {{the_Edges_of G1, the_Edges_of G2}} by TARSKI:def 1;
      {{the_Edges_of G1, the_Edges_of G2}} in e by A32, TARSKI:def 2;
      hence contradiction by A30, A33, A34,  XREGULAR:8;
    end;
    set s = the_Source_of G2 +* f;
    now
      thus dom s = dom the_Source_of G2 \/ dom f by FUNCT_4:def 1
        .= the_Edges_of G2 \/ E by A15, FUNCT_2:def 1;
      A35: rng s c= rng the_Source_of G2 \/ rng f by FUNCT_4:17;
      rng the_Source_of G2 \/ rng f c= the_Vertices_of G2 by A22, XBOOLE_1:8;
      hence rng s c= the_Vertices_of G2 by A35, XBOOLE_1:1;
    end;
    then reconsider s as Function of the_Edges_of G2 \/ E, the_Vertices_of G2
      by FUNCT_2:2;
    set t = the_Target_of G2 +* f;
    now
      thus dom t = dom the_Target_of G2 \/ dom f by FUNCT_4:def 1
        .= the_Edges_of G2 \/ E by A15, FUNCT_2:def 1;
      A36: rng t c= rng the_Target_of G2 \/ rng f by FUNCT_4:17;
      rng the_Target_of G2 \/ rng f c= the_Vertices_of G2 by A22, XBOOLE_1:8;
      hence rng t c= the_Vertices_of G2 by A36, XBOOLE_1:1;
    end;
    then reconsider t as Function of the_Edges_of G2 \/ E, the_Vertices_of G2
      by FUNCT_2:2;
    set G9 = createGraph(the_Vertices_of G2,the_Edges_of G2 \/ E,s,t);
    :: show that G9 is addLoops
    now
      :: for that first show that G9 is Supergraph
      now
        thus the_Vertices_of G2 c= the_Vertices_of G9;
        thus the_Edges_of G2 c= the_Edges_of G9 by XBOOLE_1:7;
        let e be set;
        assume A37: e in the_Edges_of G2;
        then e in the_Edges_of G2 \/ E by XBOOLE_0:def 3;
        then A38: not e in dom f by A15, A29, A37, XBOOLE_0:5;
        hence (the_Source_of G2).e = (the_Source_of G2 +* f).e by FUNCT_4:11
          .= (the_Source_of G9).e;
        thus (the_Target_of G2).e = (the_Target_of G2 +* f).e
            by A38, FUNCT_4:11
          .= (the_Target_of G9).e;
      end;
      hence G9 is Supergraph of G2 by GLIB_006:def 9;
      thus the_Vertices_of G9 = the_Vertices_of G2;
      reconsider E as set;
      reconsider f as one-to-one Function;
      take E, f;
      thus E misses the_Edges_of G2 by A29;
      thus the_Edges_of G9 = the_Edges_of G2 \/ E;
      thus dom f = E by A15;
      thus rng f = V by A22;
      thus the_Source_of G9 = the_Source_of G2 +* f;
      thus the_Target_of G9 = the_Target_of G2 +* f;
    end;
    then A39: G9 is addLoops of G2, V by Def5;
    then G2 == the removeLoops of G9 by Th26;
    then A40: G2 is removeLoops of G9 by GLIB_009:59;
    A41: G9 is non-multi by A39;
    :: show that G9 is LGraphComplement
    now
      thus the_Vertices_of G9 = the_Vertices_of G1 by A10;
      thus the_Edges_of G9 misses the_Edges_of G1 by A10, A23, XBOOLE_1:70;
      let v,w be Vertex of G1;
      hereby
        given e1 being object such that
          A43: e1 Joins v,w,G1;
        given e2 being object such that
          A44: e2 Joins v,w,G9;
        per cases by A39, A44, GLIB_006:72;
        suppose A45: e2 Joins v,w,G2;
          then v <> w by GLIB_000:18;
          hence contradiction by A11, A43, A45;
        end;
        suppose A46: not e2 in the_Edges_of G2;
          e2 in the_Edges_of G9 by A44, GLIB_000:def 13;
          then A47: e2 in E by A46, XBOOLE_0:def 3;
          then consider u being Element of V such that
            A48: e2 = [{the_Edges_of G1,the_Edges_of G2},u];
          A49: not ex e being object st e Joins u,u,G1 by A13, A14;
          A50: (the_Source_of G9).e2 = s.e2
             .= f.e2 by A15, A47, FUNCT_4:13
             .= [{the_Edges_of G1,the_Edges_of G2},u]`2 by A15, A47, A48
             .= u;
          (the_Target_of G9).e2 = t.e2
             .= f.e2 by A15, A47, FUNCT_4:13
             .= [{the_Edges_of G1,the_Edges_of G2},u]`2 by A15, A47, A48
             .= u;
          then v = u & w = u by A44, A50, GLIB_000:def 13;
          hence contradiction by A43, A49;
        end;
      end;
      assume A51: not ex e2 being object st e2 Joins v,w,G9;
      assume A52: not ex e1 being object st e1 Joins v,w,G1;
      per cases;
      suppose A53: v <> w;
        not ex e2 being object st e2 Joins v,w,G2 by A39, A51, GLIB_006:70;
        hence contradiction by A11, A52, A53;
      end;
      suppose A54: v = w;
        set e = [{the_Edges_of G1,the_Edges_of G2},v];
        A55: not ex e1 being object st e1 Joins v,v,G1 by A52, A54;
        v in V by A10, A13, A55;
        then A56: e in E;
        then A57: e in the_Edges_of G9 by XBOOLE_0:def 3;
        A58: (the_Source_of G9).e = s.e
          .= f.e by A15, A56, FUNCT_4:13
          .= e`2 by A15, A56
          .= v;
        (the_Target_of G9).e = t.e
          .= f.e by A15, A56, FUNCT_4:13
          .= e`2 by A15, A56
          .= v;
        then e Joins v,w,G9 by A54, A57, A58, GLIB_000:def 13;
        hence contradiction by A51;
      end;
    end;
    then G9 is LGraphComplement of G1 by A41, Def7;
    hence thesis by A40, Def9;
  end;
  suppose A59: G1 is loopfull;
    now
      let v,w be Vertex of G1;
      hereby
        given e1 being object such that
          A60: e1 Joins v,w,G1;
        per cases;
        suppose v <> w;
          hence not ex e2 being object st e2 Joins v,w,G2 by A11, A60;
        end;
        suppose v = w;
          hence not ex e2 being object st e2 Joins v,w,G2 by GLIB_000:18;
        end;
      end;
      assume A61: not ex e2 being object st e2 Joins v,w,G2;
      per cases;
      suppose v <> w;
        hence ex e1 being object st e1 Joins v,w,G1 by A11, A61;
      end;
      suppose v = w;
        hence ex e1 being object st e1 Joins v,w,G1 by A59;
      end;
    end;
    then A62: G2 is LGraphComplement of G1 by A10, Def7;
    G2 is removeLoops of G2 by GLIB_009:58;
    hence thesis by A62, Def9;
  end;
end;
