[GAP Forum] Boolean matrix

Gordon Royle gordon.royle at uwa.edu.au
Wed Mar 2 07:24:40 GMT 2016


Each iteration of Add(A,B) simply adds (to A) another reference to the same copy of B, so all four rows of A refer to a single copy of B.

If you change that one copy (using *any* of the references) then every reference to that copy will reflect the change.

You need to actually create four genuine “deep copies" of B if you want them to be independent.

(I am also not sure whether GAP treats arrays of booleans as bit patterns which is what you would need in order to really save memory)



On 2 Mar 2016, at 2:03 pm, Sara Yaftian <sara.yaftian at gmail.com<mailto:sara.yaftian at gmail.com>> wrote:

Dear GAP Forum

I need a m by n Boolean matrix for saving memory in my works. I know
A:=NullMat(m,n);
is a Null matrix but I need boolean version. I wrote the following code

B:=[];
for i in [1..3] do
Add(B,false);
od;
A:=[B];
for j in [1..3] do
Add(A,B);
od;

this is the output:
gap> A;
[ [ false, false, false ], [ false, false, false ], [ false, false, false
], [ false, false, false ] ]

and I obtained a null Boolean matrix but if I use the following command

A[2][3] := true;

I have the following problem

gap> A;
[ [ false, false, true ], [ false, false, true ], [ false, false, true ], [
false, false, true ] ]

I need just A[2][3] := true not A[i][3].

Would you please help me?

Best regards
Sara
_______________________________________________
Forum mailing list
Forum at mail.gap-system.org<mailto:Forum at mail.gap-system.org>
http://mail.gap-system.org/mailman/listinfo/forum

Professor Gordon Royle
School of Mathematics and Statistics
University of Western Australia
Gordon.Royle at uwa.edu.au<mailto:Gordon.Royle at uwa.edu.au>















More information about the Forum mailing list