Bill Allombert on Sun, 12 Feb 2012 20:13:14 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: matconcat |
On Sun, Feb 12, 2012 at 05:09:13PM +0100, Karim Belabas wrote: > Hi pari-dev, > > I implemented a convenience GP function matconcat(v), which builds > a (block) matrix from the components of v (see the examples below in P.S). > > For instance matconcat([A, B; C, D]) builds the matrix : > [A | B] > [-----] > [C | D] > > The building blocks may be t_MAT, t_VEC [ row matrix ], t_COL [ column matrix ] > and even scalars [ 1x1 matrix ] > > All this is straightforward when all dimensions match up, but I have a > problem when they don't. What to do in this case ? I see at least 3 > possibilities: > > 1) reject and raise an exception. > > 2) consider a scalar 'x' as x * matid(proper dimension), > e.g. > matconcat([3, matid(2); matid(2), 4]) > %1 = > [3 0 1 0] > > [0 3 0 1] > > [1 0 4 0] > > [0 1 0 4] > > 3) extend the blocks as needed, by rows and columns of 0 > e.g. > matconcat([3, matid(2); matid(2), 4]) > %1 = > [3 0 1 0] > > [0 0 0 1] > > [1 0 4 0] > > [0 1 0 0] > > > 1) is simplest conceptually but somewhat contrary to the general PARI > philosophy [ = try to make sense of all inputs, provided the specification > can be documented in an elegant way ] > > 2) is already useful, but doesn't allow e.g. > > matconcat(matdiagonal([[1,2;3,4], [1,2,3;4,5,6;7,8,9]])) > > [ = diagonal block matrix ] > > One can always add special cases, e.g. allow a "0" scalar, to represent an > arbitrary rectangular block of zeroes, but it quickly becomes awkward. There are two other alternatives that can be considered: Allow non square indentity matrix: e.g. [1, 0; and [1, 0, 0; 0, 1; 0, 1, 0] 0, 0] or fill the block with the value: [1,1; and [2,2,2; 1,1; 2,2,2] 1,1] This would solve the problem for 0 and remove ambiguity. The question is whether that makes mathematical sense. Cheers, Bill.