reserve c,c1,c2 for Cardinal, G,G1,G2 for _Graph, v for Vertex of G;

theorem Th65:
  for G being _finite _Graph, v being Denumeration of the_Vertices_of G
  holds G.size() = Sum(G.inDegreeMap()*v) & G.size() = Sum(G.outDegreeMap()*v)
proof
  let G be _finite _Graph, v be Denumeration of the_Vertices_of G;
  :: first part
  deffunc I1(object) = E1(G,v/.$1);
  set f1 = XFS2FS(G.inDegreeMap()*v), S1 = {I1(i) where i is Nat : i < len f1};
  :: we show that (obviously) card union S1 = Sum f1
  :: by using a scheme from MSAFREE5
  A1: now
    let i,j be Nat;
    assume A2: i < len f1 & j < len f1 & i <> j;
    then i < len(G.inDegreeMap()*v) & j < len(G.inDegreeMap()*v)
      by AFINSQ_1:def 9;
    then i in dom(G.inDegreeMap()*v) & j in dom(G.inDegreeMap()*v)
      by AFINSQ_1:86;
    then i in dom v & j in dom v by FUNCT_1:11;
    then v.i<>v.j & v.i=v/.i & v.j=v/.j by A2, FUNCT_1:def 4, PARTFUN1:def 6;
    hence I1(i) misses I1(j) by Lm13;
  end;
  A3: now
    let i be Nat;
    assume i < len f1;
    then i < len(G.inDegreeMap()*v) by AFINSQ_1:def 9;
    then A4: i in dom(G.inDegreeMap()*v) by AFINSQ_1:86;
    then A5: i in dom v by FUNCT_1:11;
    i+1 in dom f1 by A4, AFINSQ_1:95;
    then 1 <= i+1 & i+1 <= len f1 by FINSEQ_3:25;
    then A6: 1 <= i+1 & i+1 <= len(G.inDegreeMap()*v) by AFINSQ_1:def 9;
    thus card I1(i)
       = card [:[:{v/.i}, (v/.i).edgesIn():],{1}:] by ZFMISC_1:def 3
      .= card [:{v/.i}, (v/.i).edgesIn():] by CARD_1:69
      .= card [:(v/.i).edgesIn(), {v/.i}:] by CARD_2:4
      .= (v/.i).inDegree() by CARD_1:69
      .= G.inDegreeMap().(v/.i) by Def12
      .= G.inDegreeMap().(v.i) by A5, PARTFUN1:def 6
      .= (G.inDegreeMap()*v).i by A4, FUNCT_1:12
      .= (G.inDegreeMap()*v).(i+1-1)
      .= f1.(i+1) by A6, AFINSQ_1:def 9;
  end;
  A7: card union S1 = Sum f1 from MSAFREE5:sch 1(A1,A3);
  :: union S1 = rng F1(G) is obvious, if a bit lengthy to prove
  :: after that, basic cardinality considerations show the desired result
  now
    let y be object;
    hereby
      assume y in union S1;
      then consider Y being set such that
        A8: y in Y & Y in S1 by TARSKI:def 4;
      consider i being Nat such that
       A9: Y = I1(i) & i < len f1 by A8;
      consider x1,x2,x3 being object such that
        A10: x1 in {v/.i} & x2 in (v/.i).edgesIn() & x3 in {1} & y=[x1,x2,x3]
        by A8, A9, MCART_1:68;
      A11: x1 = v/.i by A10, TARSKI:def 1;
      reconsider x = [x2,x3] as object;
      take x;
      A12: x2 in the_Edges_of G by A10;
      then A13: x2 in dom H1(G) & x3 in dom id {1} by A10, Lm4;
      x in [: the_Edges_of G, {1} :] by A10, ZFMISC_1:def 2;
      hence x in dom F1(G) by Lm5;
      thus y = [[x1,x2],x3] by A10, XTUPLE_0:def 4
        .= [[(the_Target_of G).x2,x2],x3] by A10, A11, GLIB_000:56
        .= [[(the_Target_of G).x2,(id the_Edges_of G).x2],x3]
          by A12, FUNCT_1:18
        .= [H1(G).x2,x3] by A13, FUNCT_3:def 7
        .= [H1(G).x2,(id {1}).x3] by A10, FUNCT_1:18
        .= F1(G).(x2,x3) by A13, FUNCT_3:def 8
        .= F1(G).x by BINOP_1:def 1;
    end;
    given x being object such that
      A14: x in dom F1(G) & y = F1(G).x;
    x in [: the_Edges_of G, {1} :] by A14, Lm5;
    then consider x2,x3 being object such that
      A15: x2 in the_Edges_of G & x3 in {1} & x = [x2,x3] by ZFMISC_1:def 2;
    A16: x2 in dom H1(G) & x3 in dom id {1} by A15, Lm4;
    set x1 = (the_Target_of G).x2, i = v".x1;
    A17: y = F1(G).(x2,x3) by A14, A15, BINOP_1:def 1
      .= [H1(G).x2,(id {1}).x3] by A16, FUNCT_3:def 8
      .= [H1(G).x2,x3] by A16, FUNCT_1:18
      .= [[x1,(id the_Edges_of G).x2],x3] by A16, FUNCT_3:def 7
      .= [[x1,x2],x3] by A15, FUNCT_1:18
      .= [x1,x2,x3] by XTUPLE_0:def 4;
    x2 in dom the_Target_of G by A15, FUNCT_2:def 1;
    then x1 in rng the_Target_of G by FUNCT_1:3;
    then reconsider x1 as Vertex of G;
    x1 in the_Vertices_of G;
    then x1 in rng v by FUNCT_2:def 3;
    then A18: v.i = x1 & x1 in dom(v") by FUNCT_1:33, FUNCT_1:35;
    then i in rng(v") by FUNCT_1:3;
    then A19: i in dom v by FUNCT_1:33;
    then A20: i in G.order();
    then reconsider i as Ordinal;
    i c= G.order() by A20, ORDINAL1:def 2;
    then reconsider i as Nat;
    dom G.inDegreeMap() = the_Vertices_of G by PARTFUN1:def 2;
    then x1 in dom G.inDegreeMap();
    then i < len(G.inDegreeMap()*v) by A18, A19, FUNCT_1:11, AFINSQ_1:86;
    then i < len f1 by AFINSQ_1:def 9;
    then A21: I1(i) in S1 & v/.i = x1 by A18, A19, PARTFUN1:def 6;
    x1 in {x1} & x2 in x1.edgesIn() by A15, TARSKI:def 1, GLIB_000:56;
    then y in E1(G,x1) by A15, A17, MCART_1:69;
    hence y in union S1 by A21, TARSKI:def 4;
  end;
  then A22: union S1 = rng F1(G) by FUNCT_1:def 3;
  reconsider g = G.inDegreeMap()*v as complex-valued XFinSequence;
  thus G.size() = card [: the_Edges_of G, {1} :] by CARD_1:69
    .= card dom F1(G) by Lm5
    .= Sum f1 by A7, A22, CARD_1:70
    .= Sum(G.inDegreeMap()*v) by RVSUM_4:64;
  :: second part, analogously to first part
  deffunc I0(object) = E0(G,v/.$1);
  set f0 = XFS2FS(G.outDegreeMap()*v),S0 = {I0(i) where i is Nat : i < len f0};
  :: we show that (obviously) card union S0 = Sum f0
  :: by using a scheme from MSAFREE5
  A23: now
    let i,j be Nat;
    assume A24: i < len f0 & j < len f0 & i <> j;
    then i < len(G.outDegreeMap()*v) & j < len(G.outDegreeMap()*v)
      by AFINSQ_1:def 9;
    then i in dom(G.outDegreeMap()*v) & j in dom(G.outDegreeMap()*v)
      by AFINSQ_1:86;
    then i in dom v & j in dom v by FUNCT_1:11;
    then v.i<>v.j & v.i=v/.i & v.j=v/.j by A24, FUNCT_1:def 4, PARTFUN1:def 6;
    hence I0(i) misses I0(j) by Lm12;
  end;
  A25: now
    let i be Nat;
    assume i < len f0;
    then i < len(G.outDegreeMap()*v) by AFINSQ_1:def 9;
    then A26: i in dom(G.outDegreeMap()*v) by AFINSQ_1:86;
    then A27: i in dom v by FUNCT_1:11;
    i+1 in dom f0 by A26, AFINSQ_1:95;
    then 1 <= i+1 & i+1 <= len f0 by FINSEQ_3:25;
    then A28: 1 <= i+1 & i+1 <= len(G.outDegreeMap()*v) by AFINSQ_1:def 9;
    thus card I0(i)
       = card [:[:{v/.i}, (v/.i).edgesOut():],{0}:] by ZFMISC_1:def 3
      .= card [:{v/.i}, (v/.i).edgesOut():] by CARD_1:69
      .= card [:(v/.i).edgesOut(), {v/.i}:] by CARD_2:4
      .= (v/.i).outDegree() by CARD_1:69
      .= G.outDegreeMap().(v/.i) by Def13
      .= G.outDegreeMap().(v.i) by A27, PARTFUN1:def 6
      .= (G.outDegreeMap()*v).i by A26, FUNCT_1:12
      .= (G.outDegreeMap()*v).(i+1-1)
      .= f0.(i+1) by A28, AFINSQ_1:def 9;
  end;
  A29: card union S0 = Sum f0 from MSAFREE5:sch 1(A23,A25);
  :: union S0 = rng F0(G) is obvious, if a bit lengthy to prove
  :: after that, basic cardinality considerations show the desired result
  now
    let y be object;
    hereby
      assume y in union S0;
      then consider Y being set such that
        A30: y in Y & Y in S0 by TARSKI:def 4;
      consider i being Nat such that
        A31: Y = I0(i) & i < len f0 by A30;
      consider x1,x2,x3 being object such that
        A32: x1 in {v/.i} & x2 in (v/.i).edgesOut() & x3 in {0} & y=[x1,x2,x3]
        by A30, A31, MCART_1:68;
      A33: x1 = v/.i by A32, TARSKI:def 1;
      reconsider x = [x2,x3] as object;
      take x;
      A34: x2 in the_Edges_of G by A32;
      then A35: x2 in dom H0(G) & x3 in dom id {0} by A32, Lm4;
      x in [: the_Edges_of G, {0} :] by A32, ZFMISC_1:def 2;
      hence x in dom F0(G) by Lm5;
      thus y = [[x1,x2],x3] by A32, XTUPLE_0:def 4
        .= [[(the_Source_of G).x2,x2],x3] by A32, A33, GLIB_000:58
        .= [[(the_Source_of G).x2,(id the_Edges_of G).x2],x3]
          by A34, FUNCT_1:18
        .= [H0(G).x2,x3] by A35, FUNCT_3:def 7
        .= [H0(G).x2,(id {0}).x3] by A32, FUNCT_1:18
        .= F0(G).(x2,x3) by A35, FUNCT_3:def 8
        .= F0(G).x by BINOP_1:def 1;
    end;
    given x being object such that
      A36: x in dom F0(G) & y = F0(G).x;
    x in [: the_Edges_of G, {0} :] by A36, Lm5;
    then consider x2,x3 being object such that
      A37: x2 in the_Edges_of G & x3 in {0} & x = [x2,x3] by ZFMISC_1:def 2;
    A38: x2 in dom H0(G) & x3 in dom id {0} by A37, Lm4;
    set x1 = (the_Source_of G).x2, i = v".x1;
    A39: y = F0(G).(x2,x3) by A36, A37, BINOP_1:def 1
      .= [H0(G).x2,(id {0}).x3] by A38, FUNCT_3:def 8
      .= [H0(G).x2,x3] by A38, FUNCT_1:18
      .= [[x1,(id the_Edges_of G).x2],x3] by A38, FUNCT_3:def 7
      .= [[x1,x2],x3] by A37, FUNCT_1:18
      .= [x1,x2,x3] by XTUPLE_0:def 4;
    x2 in dom the_Source_of G by A37, FUNCT_2:def 1;
    then x1 in rng the_Source_of G by FUNCT_1:3;
    then reconsider x1 as Vertex of G;
    x1 in the_Vertices_of G;
    then x1 in rng v by FUNCT_2:def 3;
    then A40: v.i = x1 & x1 in dom(v") by FUNCT_1:33, FUNCT_1:35;
    then i in rng(v") by FUNCT_1:3;
    then A41: i in dom v by FUNCT_1:33;
    then A42: i in G.order();
    then reconsider i as Ordinal;
    i c= G.order() by A42, ORDINAL1:def 2;
    then reconsider i as Nat;
    dom G.outDegreeMap() = the_Vertices_of G by PARTFUN1:def 2;
    then x1 in dom G.outDegreeMap();
    then i < len(G.outDegreeMap()*v) by A40, A41, FUNCT_1:11, AFINSQ_1:86;
    then i < len f0 by AFINSQ_1:def 9;
    then A43: I0(i) in S0 & v/.i = x1 by A40, A41, PARTFUN1:def 6;
    x1 in {x1} & x2 in x1.edgesOut() by A37, TARSKI:def 1, GLIB_000:58;
    then y in E0(G,x1) by A37, A39, MCART_1:69;
    hence y in union S0 by A43, TARSKI:def 4;
  end;
  then A44: union S0 = rng F0(G) by FUNCT_1:def 3;
  reconsider g = G.outDegreeMap()*v as complex-valued XFinSequence;
  thus G.size() = card [: the_Edges_of G, {0} :] by CARD_1:69
    .= card dom F0(G) by Lm5
    .= Sum f0 by A29, A44, CARD_1:70
    .= Sum(G.outDegreeMap()*v) by RVSUM_4:64;
end;
