/usr/share/gap/lib/vecmat.gd is in gap-libs 4r7p9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | #############################################################################
##
#W vecmat.gd GAP Library Frank Celler
##
##
#Y Copyright (C) 1997, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
#Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
#Y Copyright (C) 2002 The GAP Group
##
## This file contains the basic operations for creating and doing arithmetic
## with vectors.
##
#############################################################################
##
#v GF2One . . . . . . . . . . . . . . . . . . . . . . . . . . one of GF(2)
##
BIND_GLOBAL( "GF2One", Z(2) );
#############################################################################
##
#v GF2Zero . . . . . . . . . . . . . . . . . . . . . . . . . . zero of GF(2)
##
BIND_GLOBAL( "GF2Zero", 0*Z(2) );
#############################################################################
##
#R IsGF2VectorRep( <obj> ) . . . . . . . . . . . . . . . . . vector over GF2
##
## <ManSection>
## <Filt Name="IsGF2VectorRep" Arg='obj' Type='Representation'/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareRepresentation(
"IsGF2VectorRep",
IsDataObjectRep and IsRowVectorObj, [],
IsRowVector );
#############################################################################
##
#V TYPE_LIST_GF2VEC . . . . . . . . . . . . . . type of mutable GF2 vectors
##
## <ManSection>
## <Var Name="TYPE_LIST_GF2VEC"/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareGlobalVariable(
"TYPE_LIST_GF2VEC",
"type of a packed GF2 vector" );
#############################################################################
##
#V TYPE_LIST_GF2VEC_IMM . . . . . . . . . . . type of immutable GF2 vectors
##
## <ManSection>
## <Var Name="TYPE_LIST_GF2VEC_IMM"/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareGlobalVariable(
"TYPE_LIST_GF2VEC_IMM",
"type of a packed, immutable GF2 vector" );
#############################################################################
##
#V TYPE_LIST_GF2VEC_IMM_LOCKED . . . . . . . . type of immutable GF2 vectors
##
## <ManSection>
## <Var Name="TYPE_LIST_GF2VEC_IMM_LOCKED"/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareGlobalVariable(
"TYPE_LIST_GF2VEC_IMM_LOCKED",
"type of a packed, immutable GF2 vector with representation lock" );
#############################################################################
##
#V TYPE_LIST_GF2VEC_LOCKED . . . . . . . . type of mutable GF2 vectors
##
## <ManSection>
## <Var Name="TYPE_LIST_GF2VEC_LOCKED"/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareGlobalVariable(
"TYPE_LIST_GF2VEC_LOCKED",
"type of a packed, mutable GF2 vector with representation lock" );
#############################################################################
##
#F ConvertToGF2VectorRep( <vector> ) . . . . . . . . convert representation
##
## <ManSection>
## <Func Name="ConvertToGF2VectorRep" Arg='vector'/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareSynonym( "ConvertToGF2VectorRep", CONV_GF2VEC );
#############################################################################
##
#F ConvertToVectorRep( <list>[, <field>] )
#F ConvertToVectorRep( <list>[, <fieldsize>] )
#F ConvertToVectorRepNC( <list>[, <field>] )
#F ConvertToVectorRepNC( <list>[, <fieldsize>] )
##
## <#GAPDoc Label="ConvertToVectorRep">
## <ManSection>
## <Heading>ConvertToVectorRep</Heading>
## <Func Name="ConvertToVectorRep" Arg='list[, field]'
## Label="for a list (and a field)"/>
## <Func Name="ConvertToVectorRep" Arg='list[, fieldsize]'
## Label="for a list (and a prime power)"/>
## <Func Name="ConvertToVectorRepNC" Arg='list[, field]'
## Label="for a list (and a field)"/>
## <Func Name="ConvertToVectorRepNC" Arg='list[, fieldsize]'
## Label="for a list (and a prime power)"/>
##
## <Description>
## Called with one argument <A>list</A>,
## <Ref Func="ConvertToVectorRep" Label="for a list (and a field)"/>
## converts <A>list</A> to an internal row vector representation
## if possible.
## <P/>
## Called with a list <A>list</A> and a finite field <A>field</A>,
## <Ref Func="ConvertToVectorRep" Label="for a list (and a field)"/>
## converts <A>list</A> to an internal row vector representation appropriate
## for a row vector over <A>field</A>.
## <P/>
## Instead of a <A>field</A> also its size <A>fieldsize</A> may be given.
## <P/>
## It is forbidden to call this function unless <A>list</A> is a plain
## list or a row vector, <A>field</A> is a field, and all elements
## of <A>list</A> lie in <A>field</A>.
## Violation of this condition can lead to unpredictable behaviour or a
## system crash.
## (Setting the assertion level to at least 2 might catch some violations
## before a crash, see <Ref Func="SetAssertionLevel"/>.)
## <P/>
## <A>list</A> may already be a compressed vector. In this case, if no
## <A>field</A> or <A>fieldsize</A> is given, then nothing happens. If one is
## given then the vector is rewritten as a compressed vector over the
## given <A>field</A> unless it has the filter
## <C>IsLockedRepresentationVector</C>, in which case it is not changed.
## <P/>
## The return value is the size of the field over which the vector
## ends up written, if it is written in a compressed representation.
## <P/>
## In this example, we first create a row vector and then ask &GAP; to
## rewrite it, first over <C>GF(2)</C> and then over <C>GF(4)</C>.
## <P/>
## <Example><![CDATA[
## gap> v := [Z(2)^0,Z(2),Z(2),0*Z(2)];
## [ Z(2)^0, Z(2)^0, Z(2)^0, 0*Z(2) ]
## gap> RepresentationsOfObject(v);
## [ "IsPlistRep", "IsInternalRep" ]
## gap> ConvertToVectorRep(v);
## 2
## gap> v;
## <a GF2 vector of length 4>
## gap> ConvertToVectorRep(v,4);
## 4
## gap> v;
## [ Z(2)^0, Z(2)^0, Z(2)^0, 0*Z(2) ]
## gap> RepresentationsOfObject(v);
## [ "IsDataObjectRep", "Is8BitVectorRep" ]
## ]]></Example>
## <P/>
## A vector in the special representation over <C>GF(2)</C> is always viewed
## as <C><a GF2 vector of length ...></C>.
## Over fields of orders 3 to 256, a vector of length 10 or less is viewed
## as the list of its coefficients, but a longer one is abbreviated.
## <P/>
## Arithmetic operations (see <Ref Sect="Arithmetic for Lists"/> and
## the following sections) preserve the compression status of row vectors in
## the sense that if all arguments are compressed row vectors written over
## the same field and the result is a row vector then also the result is a
## compressed row vector written over this field.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalFunction( "ConvertToVectorRepNC");
DeclareSynonym( "ConvertToVectorRep",ConvertToVectorRepNC);
#############################################################################
##
#F ConvertToMatrixRep( <list>[, <field>] )
#F ConvertToMatrixRep( <list>[, <fieldsize>] )
#F ConvertToMatrixRepNC( <list>[, <field>] )
#F ConvertToMatrixRepNC( <list>[, <fieldsize>] )
##
## <#GAPDoc Label="ConvertToMatrixRep">
## <ManSection>
## <Func Name="ConvertToMatrixRep" Arg='list[, field]'
## Label="for a list (and a field)"/>
## <Func Name="ConvertToMatrixRep" Arg='list[, fieldsize]'
## Label="for a list (and a prime power)"/>
## <Func Name="ConvertToMatrixRepNC" Arg='list[, field]'
## Label="for a list (and a field)"/>
## <Func Name="ConvertToMatrixRepNC" Arg='list[, fieldsize]'
## Label="for a list (and a prime power)"/>
##
## <Description>
##
## This function is more technical version of <Ref Func="ImmutableMatrix"/>,
## which will never copy a matrix (or any rows of it) but may fail if it
## encounters rows locked in the wrong representation, or various other
## more technical problems. Most users should use <Ref Func="ImmutableMatrix"/>
## instead. The NC versions of the function do less checking of the
## argument and may cause unpredictable results or crashes if given
## unsuitable arguments.
##
## Called with one argument <A>list</A>,
## <Ref Func="ConvertToMatrixRep" Label="for a list (and a field)"/>
## converts <A>list</A> to an internal matrix representation
## if possible.
## <P/>
## Called with a list <A>list</A> and a finite field <A>field</A>,
## <Ref Func="ConvertToMatrixRep" Label="for a list (and a field)"/>
## converts <A>list</A> to an internal matrix representation appropriate
## for a matrix over <A>field</A>.
## <P/>
## Instead of a <A>field</A> also its size <A>fieldsize</A> may be given.
## <P/>
## It is forbidden to call this function unless all elements of <A>list</A>
## are row vectors with entries in the field <A>field</A>.
## Violation of this condition can lead to unpredictable behaviour or a
## system crash.
## (Setting the assertion level to at least 2 might catch some violations
## before a crash, see <Ref Func="SetAssertionLevel"/>.)
## <P/>
## <A>list</A> may already be a compressed matrix. In this case, if no
## <A>field</A> or <A>fieldsize</A> is given, then nothing happens.
## <P/>
## The return value is the size of the field over which the matrix
## ends up written, if it is written in a compressed representation.
## <P/>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalFunction( "ConvertToMatrixRepNC");
DeclareGlobalFunction("ConvertToMatrixRep",ConvertToMatrixRepNC);
#############################################################################
##
#F ImmutableGF2VectorRep( <vector> ) . . . . . . . . convert representation
##
## <ManSection>
## <Func Name="ImmutableGF2VectorRep" Arg='vector'/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "ImmutableGF2VectorRep", function( vector )
if ForAny( vector, x -> x <> GF2Zero and x <> GF2One ) then
return fail;
fi;
vector := ShallowCopy(vector);
CONV_GF2VEC(vector);
SET_TYPE_DATOBJ( vector, TYPE_LIST_GF2VEC_IMM );
return vector;
end );
#############################################################################
##
#R IsGF2MatrixRep( <obj> ) . . . . . . . . . . . . . . . . . matrix over GF2
##
DeclareRepresentation(
"IsGF2MatrixRep",
IsPositionalObjectRep and IsRowListMatrix, [],
IsMatrix );
#############################################################################
##
#M IsOrdinaryMatrix( <obj> )
#M IsConstantTimeAccessList( <obj> )
#M IsSmallList( <obj> )
##
## Lists in `IsGF2VectorRep' and `IsGF2MatrixRep' are (at least) as good
## as lists in `IsInternalRep' w.r.t.~the above filters.
##
InstallTrueMethod( IsConstantTimeAccessList, IsList and IsGF2VectorRep );
InstallTrueMethod( IsSmallList, IsList and IsGF2VectorRep );
InstallTrueMethod( IsOrdinaryMatrix, IsMatrix and IsGF2MatrixRep );
InstallTrueMethod( IsConstantTimeAccessList, IsList and IsGF2MatrixRep );
InstallTrueMethod( IsSmallList, IsList and IsGF2MatrixRep );
#############################################################################
##
#V TYPE_LIST_GF2MAT . . . . . . . . . . . . . type of mutable GF2 matrices
##
## <ManSection>
## <Var Name="TYPE_LIST_GF2MAT"/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareGlobalVariable(
"TYPE_LIST_GF2MAT",
"type of a packed GF2 matrix" );
#############################################################################
##
#V TYPE_LIST_GF2MAT_IMM . . . . . . . . . . type of immutable GF2 matrices
##
## <ManSection>
## <Var Name="TYPE_LIST_GF2MAT_IMM"/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareGlobalVariable(
"TYPE_LIST_GF2MAT_IMM",
"type of a packed, immutable GF2 matrix" );
#############################################################################
##
#F ConvertToGF2MatrixRep( <matrix> ) . . . . . . . . convert representation
##
## <ManSection>
## <Func Name="ConvertToGF2MatrixRep" Arg='matrix'/>
##
## <Description>
## </Description>
## </ManSection>
##
DeclareSynonym( "ConvertToGF2MatrixRep", CONV_GF2MAT);
#############################################################################
##
#F ImmutableGF2MatrixRep( <matrix> ) . . . . . . . . convert representation
##
## <ManSection>
## <Func Name="ImmutableGF2MatrixRep" Arg='matrix'/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "ImmutableGF2MatrixRep", function(matrix)
local new, i, row;
# put length at position 1
new := [ Length(matrix) ];
for i in matrix do
row := ImmutableGF2VectorRep(i);
if row = fail then
return fail;
fi;
Add( new, row );
od;
# convert
Objectify( TYPE_LIST_GF2MAT_IMM, new );
# and return new matrix
return new;
end );
#############################################################################
##
#F ImmutableMatrix( <field>, <matrix>[, <change>] ) . convert into "best" representation
##
## <#GAPDoc Label="ImmutableMatrix">
## <ManSection>
## <Func Name="ImmutableMatrix" Arg='field, matrix[, change]'/>
##
## <Description>
## returns an immutable matrix equal to <A>matrix</A> which is in the optimal
## (concerning space and runtime) representation for matrices defined over
## <A>field</A>. This means that matrices obtained by several calls of
## <Ref Oper="ImmutableMatrix"/> for the same <A>field</A> are compatible
## for fast arithmetic without need for field conversion.
## <P/>
## The input matrix <A>matrix</A> or its rows might change the
## representation,
## however the result of <Ref Oper="ImmutableMatrix"/> is not necessarily
## <E>identical</E> to <A>matrix</A> if a conversion is not possible.
## <P/>
## If <A>change</A> is <K>true</K>, the rows of <A>matrix</A>
## (or <A>matrix</A> itself) may be changed to become immutable;
## otherwise they are copied first).
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ImmutableMatrix",[IsObject,IsMatrix]);
#############################################################################
##
#O NumberFFVector( <vec>, <sz> )
##
## <#GAPDoc Label="NumberFFVector">
## <ManSection>
## <Oper Name="NumberFFVector" Arg='vec, sz'/>
##
## <Description>
## returns an integer that gives the position of the finite field row vector
## <A>vec</A> in the sorted list of all row vectors over the field with
## <A>sz</A> elements in the same dimension as <A>vec</A>.
## <Ref Func="NumberFFVector"/> returns <K>fail</K> if the vector cannot be
## represented over the field with <A>sz</A> elements.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation("NumberFFVector", [IsRowVector,IsPosInt]);
#############################################################################
##
#E
|