hermann on Fri, 22 May 2026 14:07:00 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: question on collecting t_MAT


On 2026-05-22 11:22, Bill Allombert wrote:
On Fri, May 22, 2026 at 10:33:12AM +0200, hermann@stamm-wilbrandt.de wrote:
Doc says that "Matrices are internally represented as a vector of columns".
But shouldn't below return a 2-element vector of "t_MAT" entries?

? [type(A)|e<-[1,2];A<-matrix(2,2,x,y,e)]
["t_COL", "t_COL", "t_COL", "t_COL"]

This is correct, this is the same as
[type(A)|e<-[1,2];A<-[[e,e]~,[e,e]~]]

If not, how to modify to result in ["t_MAT", "t_MAT"] ?

Add brackets:

? [type(A)|e<-[1,2];A<-[matrix(2,2,x,y,e)]]
%2 = ["t_MAT","t_MAT"]

Cheers,
Bill.

Thanks, that was my fault.
For assignment workaround for "a=x" one has to use "a<-[x]".
So my "A<-matrix(2,2,x,y,e)" stripped off the outer "[]" of matrix.

I wanted to search for "minimal" unimodular matrix that has no 0 in A nor A^-1.
For "minimal" I used "sum of squares for entries of A and A^-1.

No solution with two values in S, so I used S=[1,2,3].
Minimal sum of squares is 70 (all 35+35 for A and A^-1).
A single 3 at 9 positions, and a pair of 1s in distinct rows+columns.
So 18 minimal solutions.

$ gp -q < 3x3.gp
70

[1 2 2]

[2 1 2]

[2 2 3]

...

[3 2 2]

[2 1 2]

[2 2 1]


[3 2 2]

[2 2 1]

[2 1 2]

$


The "<-[]" fix here is "A<-[[a11,a12,a13;a21,a22,a23;a31,a32,a33]]":

$ cat 3x3.gp
S=[1,2,3];
no0(A)=return(vecprod(concat(Vec(A)))!=0);
sl2(A)=norml2(A)+norml2(A^-1);
{
  Ms=[A|a11<-S;a12<-S;a13<-S;
        a21<-S;a22<-S;a23<-S;
        a31<-S;a32<-S;a33<-S;
        A<-[[a11,a12,a13;a21,a22,a23;a31,a32,a33]],
        matdet(A)^2==1 && no0(A^-1)
     ];
}
Mss=vecsort(Ms,sl2);
mi=sl2(Mss[1]);
print(mi);
foreach(Mss,A,if(sl2(A)==mi,printp(A)));
$


Regards,

Hermann.