
theorem Th41:
for X be set, S be with_empty_element cap-closed Subset-Family of X,
    F1,F2 be non empty disjoint_valued FinSequence of S,
    P be nonnegative zeroed Function of S,ExtREAL,
    Mx be Matrix of len F1,len F2,ExtREAL
  st
   Union F1 = Union F2 &
  ( for i,j be Nat st [i,j] in Indices Mx holds Mx*(i,j) = P.(F1.i /\ F2.j) ) &
  ( for F be disjoint_valued FinSequence of S st Union F in S
      holds P.(Union F) = Sum(P*F) )
 holds
   ( for i be Nat st i <= len (P*F2) holds (P*F2).i = (Sum(Mx@)).i )
   & Sum(P*F2) = SumAll(Mx@)
proof
   let X be set, S be with_empty_element cap-closed Subset-Family of X,
       F1,F2 be non empty disjoint_valued FinSequence of S,
       P be nonnegative zeroed Function of S,ExtREAL,
       Mx be Matrix of len F1,len F2,ExtREAL;
   assume that
A1: Union F1 = Union F2 and
A2: for i,j be Nat st [i,j] in Indices Mx holds Mx*(i,j) = P.(F1.i /\ F2.j) and
A3: for F be disjoint_valued FinSequence of S st Union F in S
      holds P.(Union F) = Sum(P*F);

   consider Kx be Matrix of len F1,len F2,S such that
KX1:for i,j be Nat st [i,j] in Indices Kx holds Kx*(i,j) = F1.i /\ F2.j
       by FStoMAT1;

A5:len (P*F2) = len F2 by FINSEQ_2:33;

C3:len Kx = len F1 & len Mx = len F1 by MATRIX_0:def 2; then
   width Kx = len F2 & width Mx = len F2 by MATRIX_0:20; then
C5:len (Kx@) = len F2 & len (Mx@) = len F2 &
   width (Kx@) = len F1 & width(Mx@) = len F1 by C3,MATRIX_0:29; then
D2:  len (P*F2) = len (Sum(Mx@)) by A5,Def5;

   thus
D6:for i be Nat st i <= len (P*F2) holds (P*F2).i = (Sum(Mx@)).i
    proof
     let i be Nat;
     assume E0: i <= len (P*F2);

     per cases;
     suppose i = 0; then
      not i in dom(P*F2) & not i in dom(Sum(Mx@)) by FINSEQ_3:24; then
      (P*F2).i = 0 & (Sum(Mx@)).i = 0 by FUNCT_1:def 2;
      hence (P*F2).i = (Sum(Mx@)).i;
     end;
     suppose i <> 0; then
E1:   1 <= i by NAT_1:14; then
      i in dom (P*F2) by E0,FINSEQ_3:25; then
E2:   i in dom F2 by FUNCT_1:11; then
      F2.i c= union rng F2 by FUNCT_1:3,ZFMISC_1:74; then
      F2.i c= Union F1 by A1,CARD_3:def 4; then
E3:   F2.i /\ Union F1 = F2.i by XBOOLE_1:28;

E4:   F2.i in rng F2 by E2,FUNCT_1:3;

E5:   i in dom(Kx@) & i in dom(Mx@) by C5,A5,E0,E1,FINSEQ_3:25;

      for p,q be object st p <> q holds ((Kx@).i).p misses ((Kx@).i).q
      proof
       let p,q be object;
       assume SA0: p <> q;
       per cases;
       suppose SA1: p in dom((Kx@).i) & q in dom((Kx@).i); then
        reconsider p1 = p, q1 = q as Nat;
E6:     [i,p1] in Indices(Kx@) & [i,q1] in Indices(Kx@)
           by SA1,E5,MATRIX_0:37; then
EE6:    [p1,i] in Indices(Kx) & [q1,i] in Indices(Kx) by MATRIX_0:def 6;
        (Kx@)*(i,p1) = ((Kx@).i).p & (Kx@)*(i,q1) = ((Kx@).i).q
           by E6,MATRPROB:14; then
        ((Kx@).i).p = Kx*(p1,i) & ((Kx@).i).q = Kx*(q1,i)
           by EE6,MATRIX_0:def 6; then
        ((Kx@).i).p = F2.i /\ F1.p1 & ((Kx@).i).q = F2.i /\ F1.q1 by EE6,KX1;
        hence ((Kx@).i).p misses ((Kx@).i).q by SA0,PROB_2:def 2,XBOOLE_1:76;
       end;
       suppose not p in dom((Kx@).i); then
        ((Kx@).i).p = {} by FUNCT_1:def 2;
        hence ((Kx@).i).p misses ((Kx@).i).q by XBOOLE_1:65;
       end;
       suppose not q in dom((Kx@).i); then
        ((Kx@).i).q = {} by FUNCT_1:def 2;
        hence ((Kx@).i).p misses ((Kx@).i).q by XBOOLE_1:65;
       end;
      end; then
E8:   (Kx@).i is disjoint_valued FinSequence of S by PROB_2:def 2;

      now let x be object;
       assume x in Union((Kx@).i); then
       x in union rng ((Kx@).i) by CARD_3:def 4; then
       consider A be set such that
E9:     x in A & A in rng((Kx@).i) by TARSKI:def 4;
       consider m be object such that
E10:    m in dom((Kx@).i) & A = ((Kx@).i).m by E9,FUNCT_1:def 3;
       reconsider m as Nat by E10;
E11:   [i,m] in Indices (Kx@) by E10,E5,MATRIX_0:37; then
EE11:  [m,i] in Indices(Kx) by MATRIX_0:def 6;
       ((Kx@).i).m = (Kx@)*(i,m) by E11,MATRPROB:14; then
       ((Kx@).i).m = (Kx)*(m,i) by EE11,MATRIX_0:def 6; then
       ((Kx@).i).m = F2.i /\ F1.m by EE11,KX1; then
E12:   x in F2.i & x in F1.m by E9,E10,XBOOLE_0:def 4;

       1 <= m & m <= len F1 by EE11,MATRIX_0:33; then
       m in dom F1 by FINSEQ_3:25; then
       F1.m in rng F1 by FUNCT_1:3; then
       x in union rng F1 by E12,TARSKI:def 4; then
       x in Union F1 by CARD_3:def 4;
       hence x in (F2.i /\ Union F1) by E12,XBOOLE_0:def 4;
      end; then
E13:  Union((Kx@).i) c= (F2.i /\ Union F1) by TARSKI:def 3;

      now let x be object;
       assume x in F2.i /\ Union F1; then
E14:   x in F2.i & x in Union F1 by XBOOLE_0:def 4; then
       x in union rng F1 by CARD_3:def 4; then
       consider A be set such that
E15:    x in A & A in rng F1 by TARSKI:def 4;
       consider m be object such that
E16:    m in dom F1 & A = F1.m by E15,FUNCT_1:def 3;
       reconsider m as Nat by E16;
       1 <= i & i <= len F2 & 1 <= m & m <= len F1
          by E2,E16,FINSEQ_3:25; then
EE17:  [m,i] in Indices Kx by MATRIX_0:31; then
E17:   [i,m] in Indices (Kx@) by MATRIX_0:def 6;
       ((Kx@).i).m = (Kx@)*(i,m) by E17,MATRPROB:14; then
       ((Kx@).i).m = Kx*(m,i) by EE17,MATRIX_0:def 6; then
       ((Kx@).i).m = F2.i /\ F1.m by EE17,KX1; then
E18:   x in ((Kx@).i).m by E14,E15,E16,XBOOLE_0:def 4;
       m in dom((Kx@).i) by E17,MATRIX_0:38; then
       ((Kx@).i).m in rng((Kx@).i) by FUNCT_1:3; then
       x in union rng((Kx@).i) by E18,TARSKI:def 4;
       hence x in Union((Kx@).i) by CARD_3:def 4;
      end; then
      F2.i /\ Union F1 c= Union((Kx@).i) by TARSKI:def 3; then
      F2.i /\ Union F1 = Union((Kx@).i) by E13,XBOOLE_0:def 10; then
E19:  P.(F2.i /\ Union F1) = Sum(P*((Kx@).i)) by E3,E4,E8,A3;

E20:  i in Seg len (Mx@) by C5,A5,E0,E1;

E21:  (Mx@).i = Line((Mx@),i) & (Kx@).i = Line((Kx@),i) by E5,MATRIX_0:60;

      rng((Kx@).i) c= S; then
      rng((Kx@).i) c= dom P by FUNCT_2:def 1; then
E22:  dom(P*((Kx@).i)) = dom ((Kx@).i) by RELAT_1:27; then
      len(P*((Kx@).i)) = len ((Kx@).i) by FINSEQ_3:29; then
F23:  len(P*((Kx@).i)) = width (Kx@) by E21,MATRIX_0:def 7; then
E23:  len(P*((Kx@).i)) = len ((Mx@).i) by C5,E21,MATRIX_0:def 7;

      for k be Nat st 1 <= k & k <= len (P*((Kx@).i)) holds
         (P*((Kx@).i)).k = ((Mx@).i).k
      proof
       let k be Nat;
       assume E24: 1 <= k & k <= len (P*((Kx@).i)); then
       k in dom((Kx@).i) & k in dom((Mx@).i) by E23,E22,FINSEQ_3:25; then
E25:   [i,k] in Indices(Kx@) & [i,k] in Indices(Mx@) by E5,MATRPROB:13; then
EE25:  [k,i] in Indices Kx & [k,i] in Indices Mx by MATRIX_0:def 6;

       k in dom(P*((Kx@).i)) by E24,FINSEQ_3:25; then
       (P*((Kx@).i)).k = P.(((Kx@).i).k) by FUNCT_1:12; then
       (P*((Kx@).i)).k = P.((Kx@)*(i,k)) by E25,MATRPROB:14; then
       (P*((Kx@).i)).k = P.(Kx*(k,i)) by EE25,MATRIX_0:def 6; then
       (P*((Kx@).i)).k = P.(F2.i /\ F1.k) by EE25,KX1; then
       (P*((Kx@).i)).k = Mx*(k,i) by EE25,A2; then
       (P*((Kx@).i)).k = (Mx@)*(i,k) by EE25,MATRIX_0:def 6;
       hence (P*((Kx@).i)).k = ((Mx@).i).k by E25,MATRPROB:14;
      end; then
E27:  P*((Kx@).i) = (Mx@).i by F23,C5,E21,MATRIX_0:def 7;

      F2.i c= union rng F2 by E2,FUNCT_1:3,ZFMISC_1:74; then
      F2.i c= Union F2 by CARD_3:def 4; then
      F2.i /\ Union F1 = F2.i by A1,XBOOLE_1:28; then
      (P*F2).i = Sum(P*((Kx@).i)) by E2,E19,FUNCT_1:13;
      hence (P*F2).i = (Sum(Mx@)).i by E20,E27,E21,Th16;
     end;
    end;

    consider SMF2 be Function of NAT,ExtREAL such that
A3:  Sum(P*F2) = SMF2.(len(P*F2)) &
     SMF2.0 = 0 &
     for i be Nat st i < len (P*F2) holds
      SMF2.(i+1) = SMF2.i + (P*F2).(i+1) by EXTREAL1:def 2;

    consider LL be Function of NAT,ExtREAL such that
D7:  SumAll(Mx@) = LL.(len (Sum(Mx@))) &
     LL.0 = 0. &
     for i be Nat st i < len (Sum(Mx@)) holds
       LL.(i+1) = LL.i + (Sum(Mx@)).(i+1) by EXTREAL1:def 2;

    defpred PK2[Nat] means $1 <= len(P*F2) implies SMF2.$1 = LL.$1;

D8: PK2[0] by A3,D7;
D9: for i be Nat st PK2[i] holds PK2[i+1]
    proof
     let i be Nat;
     assume V1: PK2[i];
     assume V3: i+1 <= len (P*F2); then
     SMF2.(i+1) = SMF2.i + (P*F2).(i+1) by A3,NAT_1:13; then
     SMF2.(i+1) = LL.i + (Sum(Mx@)).(i+1) by D6,V1,V3,NAT_1:13;
     hence SMF2.(i+1) = LL.(i+1) by D7,V3,D2,NAT_1:13;
    end;
    for i be Nat holds PK2[i] from NAT_1:sch 2(D8,D9);
    hence Sum(P*F2) = SumAll(Mx@) by A3,D2,D7;
end;
