This file is indexed.

/usr/share/gap/lib/module.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
#############################################################################
##
#W  module.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 generic methods for modules.
##


#############################################################################
##
#M  LeftModuleByGenerators( <R>, <gens> )
#M  LeftModuleByGenerators( <R>, <gens>, <zero> )
##
##  Create the <R>-left module generated by <gens>,
##  with zero element <zero>.
##
InstallMethod( LeftModuleByGenerators,
    "for ring and collection",
    [ IsRing, IsCollection ],
    function( R, gens )
    local V;
    V:= Objectify( NewType( FamilyObj( gens ),
                            IsLeftModule and IsAttributeStoringRep ),
                   rec() );
    SetLeftActingDomain( V, R );
    SetGeneratorsOfLeftModule( V, AsList( gens ) );

    CheckForHandlingByNiceBasis( R, gens, V, false );
    return V;
    end );

InstallMethod( LeftModuleByGenerators,
    "for ring, homogeneous list, and vector",
    [ IsRing, IsHomogeneousList, IsObject ],
    function( R, gens, zero )
    local V;

    V:= Objectify( NewType( CollectionsFamily( FamilyObj( zero ) ),
                            IsLeftModule and IsAttributeStoringRep ),
                   rec() );
    SetLeftActingDomain( V, R );
    SetGeneratorsOfLeftModule( V, AsList( gens ) );
    SetZero( V, zero );
    if IsEmpty( gens ) then
      SetIsTrivial( V, true );
    fi;

    CheckForHandlingByNiceBasis( R, gens, V, zero );
    return V;
    end );


#############################################################################
##
#M  AsLeftModule( <R>, <D> )  . . . . . domain <D>, viewed as left <R>-module
##
InstallMethod( AsLeftModule,
    "generic method for a ring and a collection",
    [ IsRing, IsCollection ],
    function ( R, D )
    local   S,  L;

    D := AsSSortedList( D );
    L := ShallowCopy( D );
    S := TrivialSubmodule( LeftModuleByGenerators( R, D ) );
    SubtractSet( L, AsSSortedList( S ) );
    while not IsEmpty(L)  do
        S := ClosureLeftModule( S, L[1] );
        SubtractSet( L, AsSSortedList( S ) );
    od;
    if Length( AsSSortedList( S ) ) <> Length( D )  then
        return fail;
    fi;
    S := LeftModuleByGenerators( R, GeneratorsOfLeftModule( S ) );
    SetAsSSortedList( S, D );
    SetIsFinite( S, true );
    SetSize( S, Length( D ) );

    # return the left module
    return S;
    end );


#############################################################################
##
#M  AsLeftModule( <R>, <M> )  . . . . . . . . . . .  for ring and left module
##
##  View the left module <M> as a left module over the ring <R>.
##
InstallMethod( AsLeftModule,
    " for a ring and a left module",
    [ IsRing, IsLeftModule ],
    function( R, M )
    local W,        # the space, result
          base,     # basis vectors of field extension
          gen,      # loop over generators of `V'
          b,        # loop over `base'
          gens,     # generators of `V'
          newgens;  # extended list of generators

    if R = LeftActingDomain( M ) then

      # No change of the left acting domain is necessary.
      return M;

    elif IsSubset( R, LeftActingDomain( M ) ) then

      # Check whether `M' is really a module over the bigger field,
      # that is, whether the set of elements does not change.
      base:= BasisVectors( Basis( AsField( LeftActingDomain( M ), R ) ) );
#T generalize `AsField', at least to `AsAlgebra'!
      for gen in GeneratorsOfLeftModule( M ) do
        for b in base do
          if not b * gen in M then

            # The extension would change the set of elements.
            return fail;

          fi;
        od;
      od;

      # Construct the left module.
      W:= LeftModuleByGenerators( R, GeneratorsOfLeftModule(M), Zero(M) );

    elif IsSubset( LeftActingDomain( M ), R ) then

      # View `M' as a module over a smaller ring.
      # For that, the list of generators must be extended.
      gens:= GeneratorsOfLeftModule( M );
      if IsEmpty( gens ) then
        W:= LeftModuleByGenerators( R, [], Zero( M ) );
      else

        base:= BasisVectors( Basis( AsField( R, LeftActingDomain( M ) ) ) );
#T generalize `AsField', at least to `AsAlgebra'!
        newgens:= [];
        for b in base do
          for gen in gens do
            Add( newgens, b * gen );
          od;
        od;
        W:= LeftModuleByGenerators( R, newgens );

      fi;

    else

      # View `M' first as module over the intersection of rings,
      # and then over the desired ring.
      return AsLeftModule( R,
                 AsLeftModule( Intersection2( R, LeftActingDomain( M ) ),
                               M ) );

    fi;

    UseIsomorphismRelation( M, W );
    UseSubsetRelation( M, W );
    return W;
    end );


#############################################################################
##
#M  SetGeneratorsOfLeftModule( <M>, <gens> )
##
##  If <M> is a free left module and <gens> is a finite list then <M> is
##  finite dimensional.
##
InstallMethod( SetGeneratorsOfLeftModule,
    "method that checks for `IsFiniteDimensional'",
    IsIdenticalObj,
    [ IsFreeLeftModule and IsAttributeStoringRep, IsList ],
  function( M, gens )
    SetIsFiniteDimensional( M, IsFinite( gens ) );
    TryNextMethod();
  end );


#############################################################################
##
#M  Characteristic( <M> ) . . . . . . . . . . characteristic of a left module
##
##  Do we have and/or need a replacement method?


#############################################################################
##
#M  Representative( <D> ) .  representative of a left operator additive group
##
InstallMethod( Representative,
    "for left operator additive group with known generators",
    [ IsLeftOperatorAdditiveGroup
      and HasGeneratorsOfLeftOperatorAdditiveGroup ],
    RepresentativeFromGenerators( GeneratorsOfLeftOperatorAdditiveGroup ) );


#############################################################################
##
#M  Representative( <D> ) . representative of a right operator additive group
##
InstallMethod( Representative,
    "for right operator additive group with known generators",
    [ IsRightOperatorAdditiveGroup
      and HasGeneratorsOfRightOperatorAdditiveGroup ],
    RepresentativeFromGenerators( GeneratorsOfRightOperatorAdditiveGroup ) );


#############################################################################
##
#M  ClosureLeftModule( <V>, <a> ) . . . . . . . . .  closure of a left module
##
InstallMethod( ClosureLeftModule,
    "for left module and vector",
    IsCollsElms,
    [ IsLeftModule, IsVector ],
    function( V, w )

    # if possible test if the element lies in the module already
    if w in GeneratorsOfLeftModule( V ) or
       ( HasAsList( V ) and w in AsList( V ) ) then
      return V;
    fi;

    # Otherwise make a new module.
    return LeftModuleByGenerators( LeftActingDomain( V ),
                           Concatenation( GeneratorsOfLeftModule( V ),
                                          [ w ] ) );
    end );


#############################################################################
##
#M  ClosureLeftModule( <V>, <W> ) . . . . . . . . .  closure of a left module
##
InstallOtherMethod( ClosureLeftModule,
    "for two left modules",
    IsIdenticalObj,
    [ IsLeftModule, IsLeftModule ],
    function( V, W )
    local C, v;
    if LeftActingDomain( V ) = LeftActingDomain( W ) then
      C:= V;
      for v in GeneratorsOfLeftModule( W ) do
        C:= ClosureLeftModule( C, v );
      od;
      return C;
    else
      return ClosureLeftModule( V, AsLeftModule( LeftActingDomain(V), W ) );
    fi;
    end );


#############################################################################
##
#M  \+( <U1>, <U2> )  . . . . . . . . . . . . . . . . sum of two left modules
##
InstallOtherMethod( \+,
    "for two left modules",
    IsIdenticalObj,
    [ IsLeftModule, IsLeftModule ],
    function( V, W )

    local S;          # sum of <V> and <W>, result

    if LeftActingDomain( V ) <> LeftActingDomain( W ) then
      S:= Intersection2( LeftActingDomain( V ), LeftActingDomain( W ) );
      S:= \+( AsLeftModule( S, V ), AsLeftModule( S, W ) );
    elif IsEmpty( GeneratorsOfLeftModule( V ) ) then
      S:= W;
    else
      S:= LeftModuleByGenerators( LeftActingDomain( V ),
                           Concatenation( GeneratorsOfLeftModule( V ),
                                          GeneratorsOfLeftModule( W ) ) );
    fi;

    return S;
    end );


#############################################################################
##
#F  Submodule( <M>, <gens> )  . . . . .  submodule of <M> generated by <gens>
#F  SubmoduleNC( <M>, <gens> )
#F  Submodule( <M>, <gens>, "basis" )
#F  SubmoduleNC( <M>, <gens>, "basis" )
##
InstallGlobalFunction( Submodule, function( arg )
    local M, gens, S;

    # Check the arguments.
    if Length( arg ) < 2
       or not IsLeftModule( arg[1] )
       or not (IsEmpty(arg[2]) or IsCollection( arg[2] )) then
      Error( "first argument must be a left module, second a collection\n" );
    fi;

    # Get the arguments.
    M    := arg[1];
    gens := AsList( arg[2] );

    if IsEmpty( gens ) then
      return SubmoduleNC( M, gens );
    elif     IsIdenticalObj( FamilyObj( M ), FamilyObj( gens ) )
         and IsSubset( M, gens ) then
      S:= LeftModuleByGenerators( LeftActingDomain( M ), gens );
      SetParent( S, M );
      if Length( arg ) = 3 and arg[3] = "basis" then
        UseBasis( S, gens );
      fi;
      UseSubsetRelation( M, S );
      
      #
      # These cannot be handled by UseSubsetRelation, because they
      # depend on M and S having the same LeftActingDomain
      #
      if IsRowModule(M) then
          SetIsRowModule(S, true);
          SetDimensionOfVectors(S,DimensionOfVectors(M));
      elif IsMatrixModule( M ) then
        SetIsMatrixModule( S, true );
        SetDimensionOfVectors( S, DimensionOfVectors( M ) );
      fi;
      if IsGaussianSpace(M) then
          SetFilterObj(S, IsGaussianSpace);
      fi;
      return S;
    fi;

    Error( "usage: Submodule( <M>, <gens> [, \"basis\"] )" );
end );

InstallGlobalFunction( SubmoduleNC, function( arg )
    local S;
    if IsEmpty( arg[2] ) then
      S:= Objectify( NewType( FamilyObj( arg[1] ),
                                  IsFreeLeftModule
                              and IsTrivial
                              and IsAttributeStoringRep ),
                     rec() );
      SetLeftActingDomain( S, LeftActingDomain( arg[1] ) );
      SetGeneratorsOfLeftModule( S, AsList( arg[2] ) );
    else
      S:= LeftModuleByGenerators( LeftActingDomain( arg[1] ), arg[2] );
    fi;
    if Length( arg ) = 3 and arg[3] = "basis" then
      UseBasis( S, arg[2] );
    fi;
    SetParent( S, arg[1] );
    UseSubsetRelation( arg[1], S );
      
    #
    # These cannot be handled by UseSubsetRelation, because they
    # depend on M and S having the same LeftActingDomain
    #
    if IsRowModule(arg[1]) then
        SetIsRowModule(S, true);
        SetDimensionOfVectors(S, DimensionOfVectors(arg[1]));
    elif IsMatrixModule( arg[1] ) then
      SetIsMatrixModule( S, true );
      SetDimensionOfVectors( S, DimensionOfVectors( arg[1] ) );
    fi;
    if IsGaussianSpace(arg[1]) then
        SetFilterObj(S, IsGaussianSpace);
    fi;
    return S;
end );


#############################################################################
##
#M  TrivialSubadditiveMagmaWithZero( <M> )  . . . . . . . . for a left module
##
InstallMethod( TrivialSubadditiveMagmaWithZero,
    "generic method for left modules",
    [ IsLeftModule ],
    M -> SubmoduleNC( M, [] ) );


#############################################################################
##
#M  DimensionOfVectors( <M> ) . . . . . . . . . . . . . . . for a left module
##
InstallMethod( DimensionOfVectors,
    "generic method for left modules",
    [ IsFreeLeftModule ],
    function( M )

    M:= Representative( M );
    if IsMatrix( M ) then
      return DimensionsMat( M );
    elif IsRowVector( M ) then
      return Length( M );
    else
      TryNextMethod();
    fi;
    end );


#############################################################################
##
#E