  
  [1X6 [33X[0;0YMatrices[133X[101X
  
  
  [1X6.1 [33X[0;0YSome operations for matrices[133X[101X
  
  [1X6.1-1 DirectSumDecompositionMatrices[101X
  
  [33X[1;0Y[29X[2XDirectSumDecompositionMatrices[102X( [3XM[103X ) [32X operation[133X
  
  [33X[0;0YIn  June  2023  Hongyi  Zhao  asked in the Forum for a function to implement
  matrix decomposition into blocks. Such a function was then provided by Pedro
  García-Sánchez.  Hongyi  Zhao  then  requested that the function be added to
  [5XUtils[105X.  What is provided here is a revised version of the original solution,
  returning a list of decompositions.[133X
  
  [33X[0;0YThis  function  is  a  partial inverse to the undocumented library operation
  [10XDirectSumMat[110X.  So  if [22XL[122X is the list of diagonal decompositions of a matrix [22XM[122X
  then  each  entry  in [22XL[122X is a list of matrices, and the direct sum of each of
  these lists is equal to the original [22XM[122X.[133X
  
  [33X[0;0YIn  the  following examples, [22XM_6[122X is an obvious direct sum with [22X3[122X blocks. [22XM_4[122X
  is  an  example  with  three  decompositions,  while  [22XM_8 = M_4 ⊕ M_4[122X has [22X16[122X
  decompositions (not listed).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XM6 := [ [1,2,0,0,0,0], [3,4,0,0,0,0], [5,6,0,0,0,0],                       [127X[104X
    [4X[25X>[125X [27X           [0,0,9,0,0,0], [0,0,0,1,2,3], [0,0,0,4,5,6] ];;[127X[104X
    [4X[25Xgap>[125X [27XDisplay( M6 );[127X[104X
    [4X[28X[ [  1,  2,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  3,  4,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  5,  6,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  9,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  1,  2,  3 ],[128X[104X
    [4X[28X  [  0,  0,  0,  4,  5,  6 ] ][128X[104X
    [4X[25Xgap>[125X [27XL6 := DirectSumDecompositionMatrices( M6 );[127X[104X
    [4X[28X[ [ [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], [ [ 9 ] ], [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] [128X[104X
    [4X[28X     ] ][128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XM4 := [ [0,3,0,0], [0,0,0,0], [0,0,0,0], [0,0,4,0] ];;[127X[104X
    [4X[25Xgap>[125X [27XDisplay( M4 );[127X[104X
    [4X[28X[ [  0,  3,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  4,  0 ] ][128X[104X
    [4X[25Xgap>[125X [27XL4 := DirectSumDecompositionMatrices( M4 );[127X[104X
    [4X[28X[ [ [ [ 0, 3 ] ], [ [ 0, 0 ], [ 0, 0 ], [ 4, 0 ] ] ], [128X[104X
    [4X[28X  [ [ [ 0, 3 ], [ 0, 0 ] ], [ [ 0, 0 ], [ 4, 0 ] ] ], [128X[104X
    [4X[28X  [ [ [ 0, 3 ], [ 0, 0 ], [ 0, 0 ] ], [ [ 4, 0 ] ] ] ][128X[104X
    [4X[25Xgap>[125X [27Xfor L in L4 do [127X[104X
    [4X[25X>[125X [27X       A := DirectSumMat( L );; [127X[104X
    [4X[25X>[125X [27X       if ( A = M4 ) then Print( "yes, A = M4\n" ); fi; [127X[104X
    [4X[25X>[125X [27X   od;[127X[104X
    [4X[28Xyes, A = M4[128X[104X
    [4X[28Xyes, A = M4[128X[104X
    [4X[28Xyes, A = M4[128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XM8 := DirectSumMat( M4, M4 );; [127X[104X
    [4X[25Xgap>[125X [27XDisplay( M8 );[127X[104X
    [4X[28X[ [  0,  3,  0,  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  4,  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0,  3,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0,  0,  4,  0 ] ][128X[104X
    [4X[25Xgap>[125X [27XL8 := DirectSumDecompositionMatrices( M8 );;[127X[104X
    [4X[25Xgap>[125X [27XLength( L8 ); [127X[104X
    [4X[28X16[128X[104X
    [4X[28X[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  current method does not, however, catch all possible decompositions. In
  the  following  example  the  matrix  [22XM_5[122X has its third row and third column
  extirely  zero, and the only decomposition found has a [22X[0][122X factor. There are
  clearly  two  [22X2[122X-factor decompositions with a [22X2[122X-by-[22X3[122X and a [22X3[122X-by-[22X2[122X factor, but
  these are not found at present.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XM5 := [ [1,2,0,0,0], [3,4,0,0,0], [0,0,0,0,0],[127X[104X
    [4X[25X>[125X [27X           [0,0,0,6,7], [0,0,0,8,9] ];;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(M5);[127X[104X
    [4X[28X[ [  1,  2,  0,  0,  0 ],[128X[104X
    [4X[28X  [  3,  4,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  0,  0 ],[128X[104X
    [4X[28X  [  0,  0,  0,  6,  7 ],[128X[104X
    [4X[28X  [  0,  0,  0,  8,  9 ] ][128X[104X
    [4X[25Xgap>[125X [27XL5 := DirectSumDecompositionMatrices( M5 ); [127X[104X
    [4X[28X[ [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 0 ] ], [ [ 6, 7 ], [ 8, 9 ] ] ] ][128X[104X
    [4X[28X[128X[104X
  [4X[32X[104X
  
