1

The GAP-command DirectSumMat allows to take the direct sum of matrices over (only certain?) fields. Now I did the following in GAP:

F:=FunctionField(Rationals,["x1","x2","x3","x4"]);AssignGeneratorVariables(F);
N:=[[x1,x2],[x3,x4]];U:=DirectSumMat(N,N);

This gives an error so it seems that the command DirectSumMat does not work over the field F:=FunctionField(Rationals,["x1","x2","x3","x4"]); or am I using the command wrong? The command DirectSumMat seems to work fine over the rationals.

Question: Is there an easy fix for this so that one can take the direct sum of matrices over any fields in GAP?

Mare
  • 2,332
  • 1
    Hi Mare, I would recommend for future questions that you also state the version of GAP you are using, and include the full input and output of your GAP session, to make it easier to understand what's going on. In this case, your code works in GAP up to 4.11.1, and is broken in 4.12.0 onwards -- i.e., there is a bug. I'll file this in the GAP issue tracker. – Max Horn Apr 05 '23 at 10:53
  • @MaxHorn Thank you. Ill look up the version the next time I use my laptop again that I used when asking this question. Is there a way to see whehter the code for DirectSumMat and see how it was changed during those versions? Maybe I can see the code and modify it. – Mare Apr 05 '23 at 11:06
  • It is not the code for DirectSumMat that changed but the mechanism for determining a base field from the matrix entries. – ahulpke Apr 05 '23 at 12:01
  • @hulpe actually the code for DirectSumMat did change quite a lot. of course the core which does the actual work did not – Max Horn Apr 05 '23 at 13:54
  • See https://github.com/gap-system/gap/issues/5434 – Max Horn Apr 06 '23 at 10:19

1 Answers1

2

As a workaround until DirectSumMat is fixed (hopefully in GAP 4.13.0, to be released in a couple weeks if all goes well), you can use this helper. For simplicity, it takes the coefficient ring plus two matrices; if you need more you can either call it multiple times or adapt it suitably):

MyDirectSumMat:=function(R,m1,m2)
  local m, r1, r2, c1, c2;
  r1 := NrRows(m1);
  r2 := NrRows(m2);
  c1 := NrCols(m1);
  c2 := NrCols(m2);
  m := NullMat(r1+r2, c1+c2, R);
  CopySubMatrix(m1, m, [1..r1], [1..r1], [1..c1], [1..c1] );
  CopySubMatrix(m2, m, [1..r2], [r1+1..r1+r2], [1..c2], [c1+1..c1+c2] );
  return m;
end;

Example:

gap> F:=FunctionField(Rationals,["x1","x2","x3","x4"]);AssignGeneratorVariables(F);
FunctionField(...,[ x1, x2, x3, x4 ])
#I  Assigned the global variables [ x1, x2, x3, x4 ]
gap> N:=[[x1,x2],[x3,x4]];
[ [ x1, x2 ], [ x3, x4 ] ]
gap> U:=MyDirectSumMat(F, N, N);
[ [ x1, x2, 0, 0 ], [ x3, x4, 0, 0 ], [ 0, 0, x1, x2 ], [ 0, 0, x3, x4 ] ]
Max Horn
  • 1,832