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;

theorem Th36:
  block_diagonal(F1^F2,d) = block_diagonal(F1^<*block_diagonal(F2, d)*>,d)
proof
  set F12=F1^F2;
  set D1=block_diagonal(F1,d);
  set D2=block_diagonal(F2,d);
  set D12=block_diagonal(F12,d);
  set FD=F1^<*D2*>;
  set FD2=block_diagonal(FD,d);
  set LF1=Len F1;
  set WF1=Width F1;
  set LF2=Len F2;
  set WF2=Width F2;
  set LF=Len F12;
  set WF=Width F12;
A1: LF = LF1^LF2 by Th14;
  len D12= Sum LF by Def5;
  then
A2: len D12=Sum LF1+Sum LF2 by A1,RVSUM_1:75;
A3: Sum Width <*D2*>=width D2 by Lm5;
A4: Len FD=LF1^Len <*D2*> by Th14;
  len FD2=Sum Len FD by Def5;
  then
A5: len FD2=Sum Len <*D2*>+Sum LF1 by A4,RVSUM_1:75;
A6: Sum LF1=len D1 by Def5;
A7: WF = WF1^WF2 by Th18;
A8: Width FD=WF1^Width<*D2*> by Th18;
  width FD2=Sum Width FD by Def5;
  then
A9: width FD2=Sum Width <*D2*> +Sum WF1 by A8,RVSUM_1:75;
A10: Sum WF1=width D1 by Def5;
A11: len D2=Sum LF2 by Def5;
A12: width D12 = Sum WF by Def5;
  then
A13: width D12=Sum WF1+Sum WF2 by A7,RVSUM_1:75;
A14: Sum Len <*D2*> =len D2 by Lm4;
A15: block_diagonal(<*D2*>,d)=D2 by Th34;
A16: width D2=Sum WF2 by Def5;
A17: Indices D12 = [:Seg len D12,Seg width D12:] by FINSEQ_1:def 3
    .= Indices FD2 by A2,A13,A11,A16,A5,A9,A14,A3,FINSEQ_1:def 3;
  now
A18: dom D12=Seg len D12 by FINSEQ_1:def 3;
    let i,j such that
A19: [i,j] in Indices D12;
    i in dom D12 by A19,ZFMISC_1:87;
    then
A20: 1<=i by A18,FINSEQ_1:1;
 j in Seg width D12 by A19,ZFMISC_1:87;
    then
A21: 1<=j by FINSEQ_1:1;
    now
      per cases;
      suppose
A22:    i <= Sum LF1 & j<=Sum WF1;
        then
A23:    i in dom D1 by A6,A20,FINSEQ_3:25;
        j in Seg width D1 by A10,A21,A22;
        then
A24:    [i,j] in Indices D1 by A23,ZFMISC_1:87;
        hence D12*(i,j) = D1*(i,j) by Th26
          .= FD2*(i,j) by A24,Th26;
      end;
      suppose
A25:    i> Sum LF1 & j <=Sum WF1 or i<= Sum LF1 & j >Sum WF1;
        hence D12*(i,j) = d by A19,Th29
          .= FD2*(i,j) by A17,A19,A25,Th29;
      end;
      suppose
A26:    i > Sum LF1 & j>Sum WF1;
        then reconsider ii=i-Sum LF1,jj=j-Sum WF1 as Element of NAT by NAT_1:21
;
A27:    jj<>0 by A26;
A28:    i=ii+Sum LF1;
A29:    j=jj+Sum WF1;
        ii<>0 by A26;
        then
A30:    [ii,jj] in Indices D2 by A19,A28,A29,A27,Th27;
        hence D12*(i,j) = D2*(ii,jj) by A28,A29,Th28
          .= FD2*(i,j) by A15,A28,A29,A30,Th28;
      end;
    end;
    hence D12*(i,j)=FD2*(i,j);
  end;
  hence thesis by A12,A7,A2,A11,A16,A5,A9,A14,A3,MATRIX_0:21,RVSUM_1:75;
end;
