/usr/share/gap/lib/modulrow.gi 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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | #############################################################################
##
#W modulrow.gi GAP library Thomas Breuer
##
##
#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 methods for *row modules*, that is,
## free left modules consisting of row vectors.
##
## Especially methods for *full row modules* $R^n$ are contained.
##
## (See the file `modulmat.gi' for the methods for matrix modules.)
##
#############################################################################
##
#F FullRowModule( <R>, <n> )
##
InstallGlobalFunction( FullRowModule, function( R, n )
local M; # the free module record, result
if not ( IsRing( R ) and IsInt( n ) and 0 <= n ) then
Error( "usage: FullRowModule( <R>, <n> ) for ring <R>" );
fi;
if IsDivisionRing( R ) then
M:= Objectify( NewType( CollectionsFamily( FamilyObj( R ) ),
IsFreeLeftModule
and IsGaussianSpace
and IsFullRowModule
and IsAttributeStoringRep ),
rec() );
else
M:= Objectify( NewType( CollectionsFamily( FamilyObj( R ) ),
IsFreeLeftModule
and IsFullRowModule
and IsAttributeStoringRep ),
rec() );
fi;
SetLeftActingDomain( M, R );
SetDimensionOfVectors( M, n );
return M;
end );
#############################################################################
##
#M \^( <R>, <n> ) . . . . . . . . . . . . . . . full row module over a ring
##
InstallOtherMethod( \^,
"for ring and integer (delegate to `FullRowModule')",
[ IsRing, IsInt ],
FullRowModule );
#############################################################################
##
#M IsRowModule . return `false' for objects which are not free left modules
##
InstallOtherMethod( IsRowModule,
Concatenation("return `false' for objects which are ",
"not free left modules"),
true, [ IsObject ], 0,
function ( obj )
if not IsFreeLeftModule(obj) then return false; else TryNextMethod(); fi;
end );
#############################################################################
##
#M IsRowModule( <M> )
##
InstallMethod( IsRowModule,
"for a free left module",
[ IsFreeLeftModule ],
M -> IsRowVector( Zero( M ) ) );
#############################################################################
##
#M IsFullRowModule( M )
##
InstallMethod( IsFullRowModule,
"for free left (row) module",
[ IsFreeLeftModule ],
M -> IsRowModule( M )
and Dimension( M ) = DimensionOfVectors( M )
and ForAll( GeneratorsOfLeftModule( M ),
v -> IsSubset( LeftActingDomain( M ), v ) ) );
#############################################################################
##
#M Dimension( <M> )
##
InstallMethod( Dimension,
"for full row module",
[ IsFreeLeftModule and IsFullRowModule ],
DimensionOfVectors );
#############################################################################
##
#M Random( <M> )
##1
InstallMethod( Random,
"for full row module",
[ IsFreeLeftModule and IsFullRowModule ],
function( M )
local R,v;
R:= LeftActingDomain( M );
v := List( [ 1 .. DimensionOfVectors( M ) ], x -> Random( R ) );
if IsField(R) then
ConvertToVectorRep(v,R);
fi;
return v;
end );
#############################################################################
##
#M Representative( <M> )
##
InstallMethod( Representative,
"for full row module",
[ IsFreeLeftModule and IsFullRowModule ],
M -> ListWithIdenticalEntries( DimensionOfVectors( M ),
Zero( LeftActingDomain( M ) ) ) );
#############################################################################
##
#M GeneratorsOfLeftModule( <V> )
##
InstallMethod( GeneratorsOfLeftModule,
"for full row module",
[ IsFreeLeftModule and IsFullRowModule ],
M -> IdentityMat( DimensionOfVectors( M ), LeftActingDomain( M ) ) );
#############################################################################
##
#M ViewObj( <M> )
##
InstallMethod( ViewObj,
"for full row module",
[ IsFreeLeftModule and IsFullRowModule ],
function( M )
Print( "( " );
View( LeftActingDomain( M ) );
Print( "^", DimensionOfVectors( M ), " )" );
end );
#############################################################################
##
#M ViewString( <M> ) . . . . . . . . . . . . . . . . . for full row modules
##
InstallMethod( ViewString, "for full row modules", true,
[ IsFreeLeftModule and IsFullRowModule ], 0, String );
#############################################################################
##
#M PrintObj( <M> )
##
InstallMethod( PrintObj,
"for full row module",
[ IsFreeLeftModule and IsFullRowModule ],
function( M )
Print( "( ", LeftActingDomain( M ), "^", DimensionOfVectors( M ), " )" );
end );
#############################################################################
##
#M String( <M> ) . . . . . . . . . . . . . . . . . . . for full row modules
##
InstallMethod( String, "for full row modules", true,
[ IsFreeLeftModule and IsFullRowModule ], 0,
M -> Concatenation(List(["( ",LeftActingDomain(M),"^",
DimensionOfVectors(M)," )"], String)) );
#############################################################################
##
#M \in( <v>, <V> )
##
InstallMethod( \in,
"for full row module",
IsElmsColls,
[ IsRowVector, IsFreeLeftModule and IsFullRowModule ],
function( v, M )
return Length( v ) = DimensionOfVectors( M )
and IsSubset( LeftActingDomain( M ), v );
end );
#############################################################################
##
#M BasisVectors( <B> ) . . . . . for a canonical basis of a full row module
##
InstallMethod( BasisVectors,
"for canonical basis of a full row module",
[ IsBasis and IsCanonicalBasis and IsCanonicalBasisFullRowModule ],
function( B )
B:= UnderlyingLeftModule( B );
return IdentityMat( DimensionOfVectors( B ), LeftActingDomain( B ) );
end );
#############################################################################
##
#M CanonicalBasis( <V> )
##
InstallMethod( CanonicalBasis,
"for a full row module",
[ IsFreeLeftModule and IsFullRowModule ],
function( V )
local B;
B:= Objectify( NewType( FamilyObj( V ),
IsFiniteBasisDefault
and IsCanonicalBasis
and IsCanonicalBasisFullRowModule
and IsAttributeStoringRep ),
rec() );
SetUnderlyingLeftModule( B, V );
return B;
end );
#############################################################################
##
#M Basis( <M> ) . . . . . . . . . . . . . . . . . . . . for full row module
##
InstallMethod( Basis,
"for full row module (delegate to `CanonicalBasis')",
[ IsFreeLeftModule and IsFullRowModule ], CANONICAL_BASIS_FLAGS,
CanonicalBasis );
#############################################################################
##
#M Coefficients( <B>, <v> ) . . for a canonical basis of a full row module
##
InstallMethod( Coefficients,
"for canonical basis of a full row module",
IsCollsElms,
[ IsBasis and IsCanonicalBasisFullRowModule, IsRowVector ],
function( B, v )
local V, R;
V:= UnderlyingLeftModule( B );
R:= LeftActingDomain( V );
if Length( v ) = DimensionOfVectors( V ) and IsSubset( R, v ) then
return ShallowCopy( v );
else
return fail;
fi;
end );
#############################################################################
##
#M IsCanonicalBasisFullRowModule( <B> ) . . . . . . . . . . . . for a basis
##
InstallMethod( IsCanonicalBasisFullRowModule,
"for a basis",
[ IsBasis ],
B -> IsFullRowModule( UnderlyingLeftModule( B ) )
and IsCanonicalBasis( B ) );
#############################################################################
##
#M EnumeratorByBasis( <B> ) . . . . for canonical basis of full row module
##
BindGlobal( "NumberElement_FiniteFullRowModule", function( e, v )
local len, n, i, pos;
if not IsDenseList( v ) then
return fail;
fi;
len:= Length( v );
if len <> e!.dimension then
return fail;
fi;
n:= 0;
i:= 1;
while i <= len and v[i] = e!.coeffszero do
i:= i+1;
od;
while i <= len do
pos:= Position( e!.coeffsenum, v[i], 0 );
if pos = fail then
return fail;
fi;
n:= e!.q * n + pos - 1;
i:= i+1;
od;
return n + 1;
end );
BindGlobal( "PosVecEnumFF", function( enum, v )
local i,l;
if not IsCollsElms( FamilyObj( enum ), FamilyObj( v ) )
or not IsRowVector( v )
or Length( v ) <> enum!.dimension then
return fail;
fi;
# test whether the vector is indeed compact over a finite field
if not IsDataObjectRep(v) then
# the degree of the field extension q provides
l:= LogInt( enum!.q, Characteristic(v) );
for i in v do
if not (IsFFE(i) and IsInt(l/DegreeFFE(i))) then
# cannot convert, wrong type of object
return NumberElement_FiniteFullRowModule( enum, v );
fi;
od;
if ConvertToVectorRep( v, enum!.q ) = fail then
# cannot convert, wrong type of object
return NumberElement_FiniteFullRowModule( enum, v );
fi;
fi;
# Problem with GF(4) vectors over GF(2)
if ( IsGF2VectorRep(v) and enum!.q <> 2 )
or ( Is8BitVectorRep(v) and enum!.q = 2 ) then
return NumberElement_FiniteFullRowModule( enum, v );
fi;
# compute index via number
v:= NumberFFVector( v, enum!.q );
if v <> fail then
v:= v+1;
fi;
return v;
end);
BindGlobal( "ElementNumber_FiniteFullRowModule", function( enum, n )
local v, i;
if Size( enum ) < n then
Error( "<enum>[", n, "] must have an assigned value" );
fi;
v:= ShallowCopy( enum!.zerovector );
i:= Length( v );
n:= n-1;
while 0 < n do
v[i]:= enum!.coeffsenum[ RemInt( n, enum!.q ) + 1 ];
n:= QuoInt( n, enum!.q );
i:= i-1;
od;
if IsFFE( enum!.coeffszero ) then
ConvertToVectorRep( v, enum!.q );
fi;
MakeImmutable( v );
return v;
end );
BindGlobal( "NumberElement_InfiniteFullRowModule", function( enum, vector )
local n,
i,
max,
maxpos,
pos,
len;
if not IsCollsElms( FamilyObj( enum ), FamilyObj( vector ) )
or not IsList( vector ) then
return fail;
fi;
n:= Length( vector );
if n <> enum!.dimension then
return fail;
fi;
# Replace the entries of `vector' by their positions.
vector:= List( vector, x -> Position( enum!.coeffsenum, x, 0 ) );
if fail in vector then
return fail;
fi;
vector:= vector - 1;
# Find the maximal entry in the vector, and its number.
max:= vector[1];
for i in [ 2 .. n ] do
if max < vector[i] then
max:= vector[i];
fi;
od;
if max = 0 then
return 1;
fi;
# Compute the positions of `max' in `vector',
maxpos:= [];
for i in [ 1 .. n ] do
if vector[i] = max then
Add( maxpos, i-1 );
fi;
od;
# Compute the number of those elements with same distribution
# of `max' as in `vector' that come before `vector'.
pos:= 0;
for i in [ n, n-1 .. 1 ] do
if vector[i] <> max then
pos:= pos * max + vector[i];
fi;
od;
pos:= pos + 1;
# Compute the number of those elements with smaller distribution
# of `max'.
# Consider the following example.
# 1 3 4 7
# m ? m m ? ? m ? ... ? (`vector', the `?' mean entries < `m')
# * * * * * * ? ? ... ? gives (m+1)^6 m^{n-6}
# * * * ? ? ? m ? ... ? gives (m+1)^3 m^{n-3-1}
# * * ? m ? ? m ? ... ? gives (m+1)^2 m^{n-2-2}
# ? ? m m ? ? m ? ... ? gives (m+1)^0 m^{n-0-3}
len:= Length( maxpos );
for i in [ len, len-1 .. 1 ] do
pos:= pos + ( max + 1 )^maxpos[i] * max^( n - len - maxpos[i] + i );
od;
return pos;
end );
BindGlobal( "ElementNumber_InfiniteFullRowModule", function( enum, N )
local n,
val,
max,
maxpos,
pos,
vector,
i,
quorem;
# Catch the special case.
n:= enum!.dimension;
if N = 1 then
val:= enum!.coeffsenum[1];
return List( [ 1 .. n ], x -> val );
fi;
# Compute the maximal entry of the element.
max:= 1;
while max^n < N do
max:= max + 1;
od;
# Compute the positions of the maximal entry.
maxpos:= [];
repeat
pos:= 0;
val:= (max-1)^( n - Length( maxpos ) );
while val < N do
pos:= pos + 1;
val:= val * max / ( max - 1 );
od;
if 0 < pos then
N:= N - val * ( max - 1 ) / max;
Add( maxpos, pos );
fi;
until pos = 0;
maxpos:= Reversed( maxpos );
# Compute the values of the element that are strictly smaller than `max'.
vector:= [];
N:= N - 1;
for i in [ 1 .. n ] do
if i in maxpos then
vector[i]:= max;
else
quorem:= QuotientRemainder( Integers, N, max-1 );
vector[i]:= quorem[2] + 1;
N:= quorem[1];
fi;
od;
# Translate the positions to values.
for i in [ 1 .. n ] do
vector[i]:= enum!.coeffsenum[ vector[i] ];
od;
# Return the element.
return Immutable( vector );
end );
InstallMethod( EnumeratorByBasis,
"for enumerator via canonical basis of a full row module",
[ IsBasis and IsCanonicalBasis and IsCanonicalBasisFullRowModule ],
function( B )
local V, F, enum;
V:= UnderlyingLeftModule( B );
F:= LeftActingDomain( V );
if IsFinite( F ) then
enum:= EnumeratorByFunctions( V, rec(
ElementNumber := ElementNumber_FiniteFullRowModule,
NumberElement := NumberElement_FiniteFullRowModule,
coeffsenum := Enumerator( F ),
q := Size( F ),
coeffszero := Zero( F ),
zerovector := Zero( V ),
dimension := Dimension( V ) ) );
if IsField( F ) and Size( F ) < 256 and IsInternalRep( One( F ) ) then
# Use a more efficient method for `Position'.
enum!.NumberElement:= PosVecEnumFF;
SetFilterObj( enum, IsQuickPositionList );
fi;
SetFilterObj( enum, IsSSortedList );
return enum;
elif IsFiniteDimensional( V ) then
# The ring is infinite, use the canonical ordering of $\N_0^n$
# as defined for the iterator.
return EnumeratorByFunctions( V, rec(
ElementNumber := ElementNumber_InfiniteFullRowModule,
NumberElement := NumberElement_InfiniteFullRowModule,
dimension := Dimension( V ),
coeffsenum := Enumerator( F ) ) );
else
Error( "not implemented for infinite dimensional free modules" );
fi;
end );
#############################################################################
##
#M IteratorByBasis( <B> ) . . . . . . for canon. basis of a full row module
##
BindGlobal( "NextIterator_FiniteFullRowModule", function( iter )
local pos;
# Increase the counter.
pos:= iter!.dimension;
while iter!.counter[ pos ] = iter!.q do
iter!.counter[ pos ]:= 1;
pos:= pos - 1;
od;
iter!.counter[ pos ]:= iter!.counter[ pos ] + 1;
# Return the linear combination.
return iter!.ringelements{ iter!.counter };
end );
BindGlobal( "IsDoneIterator_FiniteFullRowModule",
iter -> iter!.counter = iter!.limit );
BindGlobal( "ShallowCopy_FiniteFullRowModule",
iter -> rec( dimension := iter!.dimension,
counter := ShallowCopy( iter!.counter ),
position := iter!.position,
q := iter!.q,
limit := ShallowCopy( iter!.limit ),
ringelements := iter!.ringelements ) );
BindGlobal( "NextIterator_InfiniteFullRowModule", function( iter )
local dim, # dimension of the free module
vector, # positions of the coefficients in `iter!.coeffsenum'
# of the previous element
result, # coefficients of the previous element
max1, # one less than the maximal entry in `vector'
max, # maximal entry in `vector'
firstval, # first entry in `iter!.coeffsenum'
i; # loop variable
# (Increase the counter.)
dim := iter!.dimension;
vector := iter!.vector;
result := iter!.result;
max1 := iter!.maxentry - 1;
firstval := iter!.firstval;
# If not all entries in `vector' are `max1' or `max1 + 1' then
# increase the counter formed by the positions with entry
# different from `max1 + 1', and return the result.
for i in [ 1 .. dim ] do
if vector[i] < max1 then
vector[i]:= vector[i] + 1;
result[i]:= iter!.coeffsenum[ vector[i] ];
return ShallowCopy( result );
elif vector[i] = max1 then
vector[i]:= 1;
result[i]:= firstval;
fi;
od;
# Otherwise if all entries are `max1 + 1', increase the maximum.
max:= iter!.maxentry;
if dim < PositionNot( vector, max ) then
max:= max + 1;
iter!.maxentry:= max;
vector[1]:= max;
iter!.maxval:= iter!.coeffsenum[ max ];
result[1]:= iter!.maxval;
for i in [ 2 .. dim ] do
vector[i]:= 1;
result[i]:= firstval;
od;
return ShallowCopy( result );
fi;
# Otherwise get the next start configuration with maximum `max'.
# (The entries of `vector' are now either `1' or `max'.)
for i in [ 1 .. dim ] do
if vector[i] = max then
vector[i]:= 1;
result[i]:= firstval;
else
vector[i]:= max;
result[i]:= iter!.maxval;
return ShallowCopy( result );
fi;
od;
Assert( 2, true,
"there should be a position with value different from `max'" );
end );
BindGlobal( "ShallowCopy_InfiniteFullRowModule",
iter -> rec( dim := iter!.dimension,
vector := ShallowCopy( iter!.vector ),
result := ShallowCopy( iter!.result ),
coeffsenum := iter!.coeffsenum,
maxentry := iter!.maxentry,
firstval := iter!.firstval,
maxval := iter!.maxval ) );
InstallMethod( IteratorByBasis,
"for canonical basis of a full row module",
[ IsBasis and IsCanonicalBasisFullRowModule ],
function( B )
local V,
F,
dim,
counter,
q,
enum,
vector,
firstval,
result;
V:= UnderlyingLeftModule( B );
dim:= Dimension( V );
if dim = 0 then
return TrivialIterator( Zero( V ) );
elif IsFinite( LeftActingDomain( V ) ) then
F:= LeftActingDomain( V );
counter := List( [ 1 .. dim ], x -> 1 );
counter[ Length( counter ) ]:= 0;
q:= Size( F );
return IteratorByFunctions( rec(
IsDoneIterator := IsDoneIterator_FiniteFullRowModule,
NextIterator := NextIterator_FiniteFullRowModule,
ShallowCopy := ShallowCopy_FiniteFullRowModule,
dimension := dim,
counter := counter,
position := 1,
q := q,
limit := List( [ 1 .. dim ], x -> q ),
ringelements := EnumeratorSorted( F ) ) );
else
enum:= Enumerator( LeftActingDomain( V ) );
vector:= List( [ 1 .. dim ], x -> 0 );
# vector[1]:= -1;
firstval:= enum[1];
result:= List( [ 1 .. dim ], x -> firstval );
return IteratorByFunctions( rec(
IsDoneIterator := ReturnFalse,
NextIterator := NextIterator_InfiniteFullRowModule,
ShallowCopy := ShallowCopy_InfiniteFullRowModule,
dimension := dim,
vector := vector,
result := result,
coeffsenum := enum,
maxentry := 0,
firstval := firstval,
maxval := firstval ) );
fi;
end );
#############################################################################
##
#E
|