
theorem Th15:
for X being finite set holds
 card { {x,[y, union X]} where x, y is Element of union X
                         : {x,y} in PairsOf X } = 2 * card PairsOf X
proof
 let G be finite set; set Y = union G;
   set A = { {x,[y,Y]} where x, y is Element of union G : {x,y} in PairsOf G };
   set EG = PairsOf G; set uG = union G;
   set s = canFS(EG);
A1: len s = card EG by FINSEQ_1:93;
A2: rng s = EG by FUNCT_2:def 3;
   defpred P[object,object] means
    for a, b being set st $1 = {a, b} holds $2 = {{a,[b,Y]},{b,[a,Y]}};
A3: for x,y1,y2 being object st x in EG & P[x,y1] & P[x,y2] holds y1 = y2
   proof let x,v1,v2 be object such that
    A4: x in EG and
    A5: P[x,v1] and
    A6: P[x,v2];
       consider x1, y1 being set such that
             x1 <> y1 and x1 in union G and y1 in union G and
    A7: x = {x1, y1} by A4,Th11;
        v2 = {{x1,[y1,Y]},{y1,[x1,Y]}} by A7,A6;
     hence v1 = v2 by A7,A5;
    end;
A8: for x being object st x in EG ex y being object st P[x,y]
proof
      let x be object;
      assume x in EG;
       then consider x1, y1 being set such that
            x1 <> y1 and x1 in union G and y1 in union G and
    A9: x = {x1, y1} by Th11;
        take y = {{x1,[y1,Y]},{y1,[x1,Y]}};
        let a, b be set;
        assume x = {a, b};
          then a=x1 & b=y1 or a=y1 & b = x1 by A9,ZFMISC_1:6;
        hence y = {{a,[b,Y]},{b,[a,Y]}};
    end;
   consider f being Function such that
A10: dom f = EG and
A11: for x being object st x in EG holds P[x,f.x] from FUNCT_1:sch 2(A3,A8);
   now
    let y be set;
    assume y in rng (f*s);
     then y in rng f by FUNCT_1:14;
     then consider x being object such that
    A12: x in dom f and
    A13: y = f.x by FUNCT_1:def 3;
       consider x1, y1 being set such that
        x1 <> y1 and x1 in union G and y1 in union G and
    A14: x = {x1, y1} by A12,A10,Th11;
        y = {{x1,[y1,Y]},{y1,[x1,Y]}} by A14,A13,A12,A10,A11;
    hence y is finite;
   end;
   then reconsider S = f*s as finite-yielding FinSequence
    by A2,A10,FINSEQ_1:16,FINSET_1:def 2;
A15: dom S = dom s by A2,A10,RELAT_1:27;
   deffunc F(set) = card (S.$1);
   consider L being FinSequence of NAT such that
A16: len L = len S and
A17: for j being Nat st j in dom L holds L.j = F(j) from FINSEQ_2:sch 1;
A18: dom S = dom L by A16,FINSEQ_3:29;
A19: for i be Nat st i in dom S holds S.i is finite & L.i = card (S.i) by A18,
A17;
    now
      let x, y be object;
      assume A20: x <> y;
      per cases;
      suppose that A21: x in dom S and A22: y in dom S;
         A23: x in dom s & s.x in dom f by A21,FUNCT_1:11;
         A24: y in dom s & s.y in dom f by A22,FUNCT_1:11;
             consider x1,y1 being set such that
                x1 <> y1 and
         A25: x1 in union G & y1 in union G and
         A26: s.x = {x1, y1} by A23,A10,Th11;
             consider x2,y2 being set such that
              x2 <> y2 and
         A27: x2 in union G & y2 in union G and
         A28: s.y = {x2, y2} by A24,A10,Th11;
         A29: S.x = f.(s.x) by A21,FUNCT_1:12;
         A30: S.y = f.(s.y) by A22,FUNCT_1:12;
         A31: S.x = {{x1,[y1,Y]},{y1,[x1,Y]}} by A26,A29,A23,A10,A11;
         A32: S.y = {{x2,[y2,Y]},{y2,[x2,Y]}} by A28,A30,A24,A10,A11;
        assume S.x meets S.y;
          then consider a being object such that
        A33: a in S.x and
        A34: a in S.y by XBOOLE_0:3;
        A35: a = {x1,[y1,Y]} or a = {y1,[x1,Y]} by A33,A31,TARSKI:def 2;
        A36: a = {x2,[y2,Y]} or a = {y2,[x2,Y]} by A34,A32,TARSKI:def 2;
            x1 = x2 & y1 = y2 or x1 = y2 & y1 = x2 or y1 = x2 & x1 = y2
             by A25,A27,A35,A36,Th4;
        hence contradiction by A26,A28,A20,A23,A24,FUNCT_1:def 4;
      end;
      suppose not (x in dom S & y in dom S);
         then S.x = {} or S.y = {} by FUNCT_1:def 2;
        hence S.x misses S.y;
      end;
    end; then
A37: S is disjoint_valued by PROB_2:def 2;
   Union S = union rng S; then
A38: card (union rng S) = Sum L by A18,A19,A37,DIST_1:17;
A39: dom ((len L) |-> 2) = Seg len L by FUNCOP_1:13
      .= dom L by FINSEQ_1:def 3;
   now let j be Nat such that
   A40: j in dom L;
   A41: S.j = f.(s.j) by A40,A18,FUNCT_1:12;
       consider x, y being set such that
   A42: x <> y and x in union G and  y in union G and
   A43: s.j = {x, y} by Th11,A40,A18,A15,A2,FUNCT_1:3;
   A44: f.(s.j) = {{x,[y,Y]},{y,[x,Y]}} by A43,A11,A40,A18,A15,A2,FUNCT_1:3;
   A45: now assume {x,[y,Y]} = {y,[x,Y]};
         then x= y or x = [x,Y] by ZFMISC_1:6;
        hence contradiction by A42,Th3;
       end;
   A46: j in Seg len L by A40,FINSEQ_1:def 3;
     thus L.j = card (S.j) by A40,A17
             .= 2 by A45,A44,A41,CARD_2:57
             .= ((len L) |-> 2).j by A46,FINSEQ_2:57;
   end;
   then
A47: L = (len L) |-> 2 by A39;
A48: len L = card EG by A16,A15,A1,FINSEQ_3:29;
   union rng S = A proof
    thus union rng S c= A proof
      let a be object;
      assume a in union rng S;
      then consider YY being set such that
    A49: a in YY and
    A50: YY in rng S by TARSKI:def 4;
        consider b being object such that
    A51: b in dom S and
    A52: YY = S.b by A50,FUNCT_1:def 3;
    A53: S.b = f.(s.b) by A51,FUNCT_1:12;
    A54: s.b in EG by A51,A15,A2,FUNCT_1:3;
        consider x, y being set such that x <> y and
    A55: x in union G and
    A56: y in union G and
    A57: s.b = {x, y} by Th11,A51,A15,A2,FUNCT_1:3;
        f.(s.b) = {{x,[y,Y]},{y,[x,Y]}} by A57,A11,A51,A15,A2,FUNCT_1:3;
        then a = {x,[y,Y]} or a = {y,[x,Y]} by A49,A52,A53,TARSKI:def 2;
      hence a in A by A57,A54,A55,A56;
    end;
    thus A c= union rng S proof
      let a be object;
      assume a in A;
      then consider x, y being Element of uG such that
    A58: a = {x,[y,Y]} and
    A59: {x,y} in EG;
        consider c being object such that c in dom s and
    A60: s.c = {x,y} by A59,A2,FUNCT_1:def 3;
        rng S = rng f by A10,A2,RELAT_1:28;
then A61: f.(s.c) in rng S by A10,A60,A59,FUNCT_1:3;
         f.(s.c) = {{x,[y,Y]},{y,[x,Y]}} by A60,A59,A11;
        then a in f.(s.c) by A58,TARSKI:def 2;
      hence a in union rng S by A61,TARSKI:def 4;
    end;
   end;
 hence card A = 2 * card EG by A38,A47,A48,RVSUM_1:80;
end;
