reserve i,j,m,n,k for Nat,
  x,y for set,
  K for Field,
  a,a1,a2 for Element of K,
  D for non empty set,
  d,d1,d2 for Element of D,
  M,M1,M2 for (Matrix of D),
  A,A1,A2,B1,B2 for (Matrix of K),
  f,g for FinSequence of NAT;
reserve F,F1,F2 for FinSequence_of_Matrix of D,
  G,G9,G1,G2 for FinSequence_of_Matrix of K;
reserve S,S1,S2 for FinSequence_of_Square-Matrix of D,
  R,R1,R2 for FinSequence_of_Square-Matrix of K;
reserve N for (Matrix of n,K),
  N1 for (Matrix of m,K);
reserve p,p1 for FinSequence of K;

theorem Th78:
  width A1 = len B1 & width A2 = len B2 implies block_diagonal(<*
A1,A2*>,0.K)*block_diagonal(<*B1,B2*>,0.K) = block_diagonal(<*A1,A2*>(#)(<*B1,
  B2*>),0.K)
proof
  assume that
A1: width A1=len B1 and
A2: width A2=len B2;
A3: width (A1*B1)=width B1 by A1,MATRIX_3:def 4;
  set b12=<*B1,B2*>;
  set a12=<*A1,A2*>;
  set b2=<*B2*>;
  set b1=<*B1*>;
  set a2=<*A2*>;
  set a1=<*A1*>;
  set ab=a12(#)b12;
A4: Len b12=(Len b1)^Len b2 by Th14;
  set bB=block_diagonal(b12,0.K);
  set bA=block_diagonal(a12,0.K);
A5: Sum Width a12=width bA by Def5;
A6: Sum Len b12=len bB by Def5;
A7: Width a1= <*width A1*> by Th19;
  set bAbB=bA*bB;
  set bAB=block_diagonal(ab,0.K);
A8: Sum Len ab=len bAB by Def5;
A9: Sum Width ab=width bAB by Def5;
A10: Sum Len a12=len A1+len A2 by Th16;
A11: Sum Width b12= width B1+width B2 by Th20;
A12: len (A2*B2)=len A2 by A2,MATRIX_3:def 4;
A13: ab = <*A1*B1,A2*B2*> by Th77;
A14: Width a2=<*width A2*> by Th19;
A15: Len b2= <*len B2*> by Th15;
A16: Len b1=<*len B1*> by Th15;
A17: Width a12=(Width a1)^Width a2 by Th18;
  then
A18: Len ab=Len a12 by A1,A2,A4,A7,A14,A16,A15,Th73;
A19: Width ab=Width b12 by A1,A2,A17,A4,A7,A14,A16,A15,Th73;
  Sum Len a12=len bA by Def5;
  then
A20: len (bA*bB)=Sum Len a12 by A1,A2,A17,A4,A7,A14,A16,A15,A5,A6,
MATRIX_3:def 4;
A21: len (A1*B1)=len A1 by A1,MATRIX_3:def 4;
  Sum Width b12=width bB by Def5;
  then
A22: width (bA*bB)=Sum Width b12 by A1,A2,A17,A4,A7,A14,A16,A15,A5,A6,
MATRIX_3:def 4;
A23: width (A2*B2)=width B2 by A2,MATRIX_3:def 4;
A24: Indices (A1*B1) = [:Seg len (A1*B1),Seg width (A1*B1):] by FINSEQ_1:def 3
    .= [:dom A1,Seg width B1:] by A3,A21,FINSEQ_1:def 3;
  now
A25: dom bAB=Seg len bAB by FINSEQ_1:def 3;
    let i,j such that
A26: [i,j] in Indices bAB;
A27: j in Seg width bAB by A26,ZFMISC_1:87;
A28: i in dom bAB by A26,ZFMISC_1:87;
    then
A29: 1<=i by A25,FINSEQ_1:1;
    Indices bAB = [:Seg len bAB,Seg width bAB:] by FINSEQ_1:def 3
      .= Indices bAbB by A8,A9,A20,A22,A18,A19,FINSEQ_1:def 3;
    then
A30: bAbB*(i,j) = Line(bA,i) "*" Col(bB,j) by A1,A2,A17,A4,A7,A14,A16,A15,A5,A6
,A26,MATRIX_3:def 4
      .= Sum(mlt(Line(bA,i),Col(bB,j)));
A31: 1<=j by A27,FINSEQ_1:1;
    now
      per cases;
      suppose
A32:    i<=len A1;
        then
A33:    i in dom (A1*B1) by A21,A29,FINSEQ_3:25;
A34:    i in dom A1 by A29,A32,FINSEQ_3:25;
        then
A35:    Line(bA,i)=Line(A1,i)^(width A2 |-> 0.K) by Th23;
        now
          per cases;
          suppose
            j<=width B1;
            then
A36:        j in Seg width B1 by A31;
            then
A37:        [i,j] in Indices (A1*B1) by A24,A34,ZFMISC_1:87;
A38:        dom Line(A1*B1,i)=Seg width B1 by A3,FINSEQ_2:124;
            Col(bB,j)=Col(B1,j)^(len B2|->0.K) by A36,Th24;
            hence
            bAbB*(i,j) = Sum(mlt(Line(A1,i),Col(B1,j)))+ Sum(mlt(width A2
            |->0.K,len B2|->0.K)) by A1,A2,A30,A35,Lm9
              .= Sum(mlt(Line(A1,i),Col(B1,j)))+ Sum(0.K*(width A2|->0.K))
            by A2,FVSUM_1:66
              .= Sum(mlt(Line(A1,i),Col(B1,j)))+ 0.K*Sum(width A2|->0.K) by
FVSUM_1:73
              .= Sum(mlt(Line(A1,i),Col(B1,j)))+0.K
              .= Line(A1,i)"*"Col(B1,j) by RLVECT_1:def 4
              .= (A1*B1)*(i,j) by A1,A37,MATRIX_3:def 4
              .= Line(A1*B1,i).j by A3,A36,MATRIX_0:def 7
              .= (Line(A1*B1,i)^(width (A2*B2) |-> 0.K)).j by A36,A38,
FINSEQ_1:def 7
              .= Line(bAB,i).j by A13,A33,Th23
              .= bAB*(i,j) by A27,MATRIX_0:def 7;
          end;
          suppose
A39:        j>width B1;
            then reconsider J=j-width B1 as Element of NAT by NAT_1:21;
A40:        j=J+width B1;
A41:        len Line(A1*B1,i)=width B1 by A3,CARD_1:def 7;
A42:        dom (width (A2*B2) |-> 0.K)= Seg width B2 by A23,FINSEQ_2:124;
            J<>0 by A39;
            then
A43:        J in Seg width B2 by A9,A19,A11,A27,A40,FINSEQ_1:61;
            then Col(bB,J+width B1)=(len B1 |-> 0.K)^Col(B2,J) by Th24;
            hence bAbB*(i,j) = Sum(mlt(Line(A1,i),len B1 |-> 0.K))+ Sum(mlt(
            width A2|->0.K,Col(B2,J))) by A1,A2,A30,A35,Lm9
              .= Sum(mlt(Line(A1,i),len B1 |-> 0.K))+ Sum(0.K*Col(B2,J)) by A2,
FVSUM_1:66
              .= Sum(0.K*Line(A1,i))+Sum(0.K*Col(B2,J)) by A1,FVSUM_1:66
              .= Sum(0.K*Line(A1,i))+0.K*Sum Col(B2,J) by FVSUM_1:73
              .= 0.K*Sum Line(A1,i)+0.K*Sum Col(B2,J) by FVSUM_1:73
              .= 0.K*Sum Line(A1,i)+0.K
              .= 0.K+0.K
              .= 0.K by RLVECT_1:def 4
              .= (width (A2*B2) |-> 0.K).J by A23,A43,FINSEQ_2:57
              .= (Line(A1*B1,i)^(width (A2*B2) |->0.K)). (J+width (A1*B1)) by
A3,A43,A41,A42,FINSEQ_1:def 7
              .= Line(bAB,i).j by A13,A3,A33,Th23
              .= bAB*(i,j) by A27,MATRIX_0:def 7;
          end;
        end;
        hence bAbB*(i,j)=bAB*(i,j);
      end;
      suppose
A44:    i>len A1;
        then reconsider I=i-len A1 as Element of NAT by NAT_1:21;
A45:    i=I+len A1;
A46:    dom A2=dom (A2*B2) by A12,FINSEQ_3:29;
        I<>0 by A44;
        then I in Seg len A2 by A8,A18,A10,A28,A25,A45,FINSEQ_1:61;
        then
A47:    I in dom A2 by FINSEQ_1:def 3;
        then
A48:    Line(bA,I+len A1)=(width A1 |-> 0.K)^Line(A2,I) by Th23;
        now
          per cases;
          suppose
A49:        j<=width B1;
A50:        dom (width (A1*B1) |->0.K)=Seg width B1 by A3,FINSEQ_2:124;
A51:        j in Seg width B1 by A31,A49;
            then Col(bB,j)=Col(B1,j)^(len B2 |-> 0.K) by Th24;
            hence bAbB*(i,j) = Sum(mlt(width A1 |-> 0.K,Col(B1,j))) + Sum(mlt(
            Line(A2,I),len B2|->0.K)) by A1,A2,A30,A48,Lm9
              .= Sum(mlt(width A1 |-> 0.K,Col(B1,j))) + Sum(0.K*Line(A2,I))
            by A2,FVSUM_1:66
              .= Sum(0.K*Col(B1,j))+Sum(0.K*Line(A2,I)) by A1,FVSUM_1:66
              .= Sum(0.K*Col(B1,j))+0.K*Sum Line(A2,I) by FVSUM_1:73
              .= 0.K*Sum Col(B1,j)+0.K*Sum Line(A2,I) by FVSUM_1:73
              .= 0.K*Sum Col(B1,j)+0.K
              .= 0.K+0.K
              .= 0.K by RLVECT_1:def 4
              .= (width (A1*B1) |-> 0.K).j by A3,A51,FINSEQ_2:57
              .= ((width (A1*B1) |-> 0.K)^Line(A2*B2,I)).j by A51,A50,
FINSEQ_1:def 7
              .= Line(bAB,I+len A1).j by A13,A21,A47,A46,Th23
              .= bAB*(i,j) by A27,MATRIX_0:def 7;
          end;
          suppose
A52:        j>width B1;
            then reconsider J=j-width B1 as Element of NAT by NAT_1:21;
A53:        j=J+width B1;
            J<>0 by A52;
            then
A54:        J in Seg width B2 by A9,A19,A11,A27,A53,FINSEQ_1:61;
            then
A55:        [I,J] in Indices (A2*B2) by A23,A47,A46,ZFMISC_1:87;
A56:        len (width (A1*B1) |->0.K)=width B1 by A3,CARD_1:def 7;
A57:        dom Line(A2*B2,I)=Seg width B2 by A23,FINSEQ_2:124;
            Col(bB,J+width B1)=(len B1 |-> 0.K)^Col(B2,J) by A54,Th24;
            hence bAbB*(i,j) = Sum(mlt(width A1 |-> 0.K,len B1|->0.K)) + Sum(
            mlt(Line(A2,I),Col(B2,J))) by A1,A2,A30,A48,Lm9
              .= Sum(0.K*(width A1 |-> 0.K)) + Sum(mlt(Line(A2,I),Col(B2,J))
            ) by A1,FVSUM_1:66
              .= 0.K*Sum(width A1|->0.K) + Sum(mlt(Line(A2,I),Col(B2,J)))by
FVSUM_1:73
              .= 0.K+Sum(mlt(Line(A2,I),Col(B2,J)))
              .= Line(A2,I)"*"Col(B2,J) by RLVECT_1:def 4
              .= (A2*B2)*(I,J) by A2,A55,MATRIX_3:def 4
              .= Line(A2*B2,I).J by A23,A54,MATRIX_0:def 7
              .= ((width (A1*B1) |->0.K)^Line(A2*B2,I)). (J+width B1) by A54
,A57,A56,FINSEQ_1:def 7
              .= Line(bAB,I+len A1).j by A13,A21,A47,A46,Th23
              .= bAB*(i,j) by A27,MATRIX_0:def 7;
          end;
        end;
        hence bAbB*(i,j)=bAB*(i,j);
      end;
    end;
    hence bAB*(i,j)=bAbB*(i,j);
  end;
  hence thesis by A8,A9,A20,A22,A18,A19,MATRIX_0:21;
end;
