This file is indexed.

/usr/share/gap/lib/tuples.gi is in gap-libs 4r8p8-3.

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
#############################################################################
##
#W  tuples.gi                   GAP library                      Steve Linton
##
##
#Y  Copyright (C)  1996,  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 declares the operations for direct product elements.
##


#############################################################################
##
#V  DIRECT_PRODUCT_ELEMENT_FAMILIES . . . list of all direct product elements
#V                                                                   families
##
EmptyDirectProductElementsFamily!.defaultTupleType:= NewType(
    EmptyDirectProductElementsFamily, IsDefaultDirectProductElementRep );

SetComponentsOfDirectProductElementsFamily( EmptyDirectProductElementsFamily,
    [] );

InstallValue( DIRECT_PRODUCT_ELEMENT_FAMILIES,
    [ [ EmptyDirectProductElementsFamily ] ] );


#############################################################################
##
#M  DirectProductElementsFamily( <famlist> )  . . .  family of direct product
#M                                                                   elements
##
InstallMethod( DirectProductElementsFamily,
    "for a collection (of families)",
    fam -> fam = CollectionsFamily(FamilyOfFamilies),
    [ IsCollection ],
    function( famlist )
    local n, tupfams, freepos, len, i, fam, tuplespos,
          tuplesfam,filter,filter2;

    n := Length(famlist);
    if not IsBound(DIRECT_PRODUCT_ELEMENT_FAMILIES[n+1]) then
      tupfams:= WeakPointerObj( [] );
      DIRECT_PRODUCT_ELEMENT_FAMILIES[n+1]:= tupfams;
      freepos:= 1;
    else
      tupfams:= DIRECT_PRODUCT_ELEMENT_FAMILIES[n+1];
      len:= LengthWPObj( tupfams );
      for i in [ 1 .. len+1 ]  do
        fam:= ElmWPObj( tupfams, i );
        if fam = fail then
          if not IsBound( freepos ) then
            freepos:= i;
          fi;
        elif ComponentsOfDirectProductElementsFamily( fam ) = famlist then
          tuplespos:= i;
          break;
        fi;
      od;
    fi;

    if IsBound( tuplespos ) then
      Info( InfoDirectProductElements, 2,
            "Reused direct product elements family, length ", n );
      tuplesfam:= tupfams[ tuplespos ];
    else
      Info( InfoDirectProductElements, 1,
            "Created new direct product elements family, length ", n );
      filter:=IsDirectProductElement;
      filter2:=IsDirectProductElementFamily;
      # inherit positive element comparison from the families but do not
      # trigger the computation.
      if ForAll(famlist,i->HasCanEasilySortElements(i) and
       CanEasilySortElements(i)) then
        filter:=filter and CanEasilySortElements;
        filter2:=filter2 and CanEasilySortElements;
      elif ForAll(famlist,i->HasCanEasilyCompareElements(i) and
        CanEasilyCompareElements(i)) then
        filter:=filter and CanEasilyCompareElements;
        filter2:=filter2 and CanEasilyCompareElements;
      fi;
      tuplesfam:= NewFamily( "DirectProductElementsFamily( <<famlist>> )",
                             IsDirectProductElement, filter, filter2 );
      SetComponentsOfDirectProductElementsFamily( tuplesfam,
          Immutable( famlist ) );
      SetElmWPObj( tupfams, freepos, tuplesfam );
      tuplesfam!.defaultTupleType:= NewType( tuplesfam,
                                        IsDefaultDirectProductElementRep );
    fi;

    return tuplesfam;
    end );


#############################################################################
##
#M  DirectProductElementsFamily( [] ) . . . .  family of empty direct product
#M                                                                 element(s)
##
InstallOtherMethod( DirectProductElementsFamily,
    "for an empty list",
    [ IsList and IsEmpty ],
    function( empty )
    Info( InfoDirectProductElements, 2,
          "Reused direct product elements family, length 0 ");
    return DIRECT_PRODUCT_ELEMENT_FAMILIES[1][1];
    end );


#############################################################################
##
#M  DirectProductElement( <objlist> ) . . . . . make a direct product element
##
InstallMethod( DirectProductElement,
    "for a list",
    [ IsList ],
    function( objlist )
    local fam;
    fam := DirectProductElementsFamily( List(objlist, FamilyObj) );
    return DirectProductElementNC( fam, objlist );
    end );


#############################################################################
##
#M  DirectProductElement( <fam>, <objlist> )  . make a direct product element
##
InstallOtherMethod( DirectProductElement,
    "for a direct product elements family, and a list",
    [ IsDirectProductElementFamily, IsList ],
    function( fam, objlist )
    while ComponentsOfDirectProductElementsFamily( fam )
          <> List( objlist, FamilyObj ) do
      objlist:=
          Error( "objects not of proper families for direct product ",
                 "elements family supplied, you may supply replacements" );
    od;
    return DirectProductElementNC( fam, objlist );
    end );


#############################################################################
##
#M  PrintObj( <dpelm> )  . . . . . . . . . . . print a direct product element
##
InstallMethod( PrintObj,
    "for a direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    local i;
    Print( "DirectProductElement( [ " );
    for i in [ 1 .. Length( dpelm )-1 ] do
      Print( dpelm[i], ", " );
    od;
    if Length( dpelm ) <> 0 then
      Print( dpelm[ Length( dpelm ) ] );
    fi;
    Print(" ] )");
    end );

#############################################################################
##
#M  ViewObj( <dpelm> ) . . . . . . . . . . . .  view a direct product element
##
InstallMethod( ViewObj,
    "for a direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    local i;
    Print( "DirectProductElement( " );
    Print( ViewString( AsList( (dpelm) ) ) );
    Print(" )");
    end );


#############################################################################
##
#M  <dpelm1> <  <dpelm2> . . . . . . . . . . . . . . . . . . . . . comparison
##
InstallMethod( \<,
    "for two direct product elements",
    IsIdenticalObj,
    [ IsDirectProductElement, IsDirectProductElement ],
    function( dpelm1, dpelm2 )
    local i;
    for i in [1..Length(dpelm1)] do
      if dpelm1[i] < dpelm2[i] then
        return true;
      elif dpelm1[i] > dpelm2[i] then
        return false;
      fi;
    od;
    return false;
    end );


#############################################################################
##
#M  <dpelm1> = <dpelm2>  . . . . . . . . . . . . . . . . . . . . . comparison
##
InstallMethod( \=,
    "for two direct product elements",
    IsIdenticalObj,
    [ IsDirectProductElement, IsDirectProductElement ],
    function( dpelm1, dpelm2 )
    local i;
    for i in [1..Length(dpelm1)] do
      if dpelm1[i] <> dpelm2[i] then
        return false;
      fi;
    od;
    return true;
    end );


#############################################################################
##
#M  CanEasilyCompareElements( <dpelm> )
##
InstallMethod( CanEasilyCompareElements,
    "for direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    local i;
    for i in dpelm do
      if not CanEasilyCompareElements( i ) then
        return false;
      fi;
    od;
    return true;
    end );


#############################################################################
##
#M  DirectProductElementNC( <dpelmfam>, <objlist> )   . make a direct product
#M                                                                    element
##
##  Note that we really have to copy the list passed, even if it is immutable
##  as we are going to call `Objectify'.
##
InstallMethod( DirectProductElementNC,
    "for a direct product elements family, and a list",
    [ IsDirectProductElementFamily, IsList ],
    function( fam, objlist )
    local t;
    Assert( 2, ComponentsOfDirectProductElementsFamily( fam )
                   = List( objlist, FamilyObj ) );
    t:= Objectify( fam!.defaultTupleType,
            PlainListCopy( List( objlist, Immutable ) ) );
    Info( InfoDirectProductElements, 3,
          "Created a new DirectProductElement ", t );
    return t;
    end );


#############################################################################
##
#M  <dpelm>[ <index> ] . . . . . . . . . . . . . . . . . . . component access
##
InstallMethod( \[\],
    "for a direct product element in default repres., and a pos. integer",
    [ IsDefaultDirectProductElementRep, IsPosInt ],
    function( dpelm, index )
    while index > Length( dpelm ) do
      index:= Error( "<index> too large for <dpelm>, ",
                     "you may return another index" );
    od;
    return dpelm![index];
    end );


#############################################################################
##
#M  Length( <dpelm> )  . . . . . . . . . . . . . . . . . number of components
##
InstallMethod( Length,
    "for a direct product element in default representation",
    [ IsDefaultDirectProductElementRep ],
    function( dpelm )
    return Length( ComponentsOfDirectProductElementsFamily(
                       FamilyObj( dpelm ) ) );
    end );


#############################################################################
##
#M  InverseOp( <dpelm> )
##
InstallMethod( InverseOp,
    "for a direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    return DirectProductElement( List( dpelm, Inverse ) );
    end );


#############################################################################
##
#M  OneOp( <dpelm> )
##
InstallMethod( OneOp,
    "for a direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    return DirectProductElement( List( dpelm, One ) );
    end );


#############################################################################
##
#M  \*( <dpelm>, <dpelm> )
##
InstallMethod( \*,
    "for two direct product elements",
    [ IsDirectProductElement, IsDirectProductElement ],
    function( elm1, elm2 )
    local n;
    n := Length( elm1 );
    return DirectProductElement( List( [1..n], x -> elm1[x]*elm2[x] ) );
    end );


#############################################################################
##
#M  IsGeneratorsOfMagmaWithInverses( <list> )
##
InstallMethod( IsGeneratorsOfMagmaWithInverses,
    "for list of direct product elements",
    [ IsDirectProductElementCollection ],
    function( l )
        local n;
        if IsEmpty (l) then
            return true;
        fi;
        n := Length (l[1]);
        if ForAny (l, x -> Length (x) <> n) then
            return false;
        fi;
        return ForAll( [ 1 .. n ],
            i -> IsGeneratorsOfMagmaWithInverses (l{[1..Length(l)]}[i]));
    end );

#############################################################################
##
#M  \^( <dpelm>, <integer> )
##
InstallMethod( \^,
    "for direct product element, and integer",
    [ IsDirectProductElement, IsInt ],
    function( dpelm, x )
    return DirectProductElement( List( dpelm, y -> y^x ) );
    end );


#############################################################################
##
#M  AdditiveInverseOp( <dpelm> )
##
InstallMethod( AdditiveInverseOp,
    "for a direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    return DirectProductElement( List( dpelm, AdditiveInverse ) );
    end );


#############################################################################
##
#M  ZeroOp( <dpelm> )
##
InstallMethod( ZeroOp,
    "for a direct product element",
    [ IsDirectProductElement ],
    function( dpelm )
    return DirectProductElement( List( dpelm, Zero ) );
    end );


#############################################################################
##
#M  \+( <dpelm1>, <dpelm2> )
##
InstallMethod( \+,
    "for two direct product elements",
    [ IsDirectProductElement, IsDirectProductElement ],
    function( dpelm1, dpelm2 )
    local n;
    n := Length( dpelm1 );
    return DirectProductElement( List( [1..n], x -> dpelm1[x]+dpelm2[x] ) );
    end );


#############################################################################
##
#M  \+( <dpelm>, <defaultlist> )
#M  \+( <defaultlist>, <dpelm> )
#M  \*( <dpelm>, <defaultlist> )
#M  \*( <defaultlist>, <dpelm> )
#M  \+( <dpelm>, <nonlist> )
#M  \+( <nonlist>, <dpelm> )
#M  \*( <dpelm>, <nonlist> )
#M  \*( <nonlist>, <dpelm> )
##
##  Direct product elements do *not* lie in `IsGeneralizedRowVector',
##  since they shall behave as scalars;
##  for example we want the sum of a direct product element and a list of
##  diect product elements to be the list of sums.
##  (It would also be possible to make them generalized row vectors with
##  additive and multiplicative nesting depth zero, but then the nesting
##  depths would have to be calculated whenever they are needed.
##  In fact I think this approach would be equivalent.)
##
##  Because direct product elements are lists, there are no default methods
##  for adding or multiplying a direct product element and a default list.
##  So we install such methods where direct product elements act as scalars.
##  Analogously,
##  we define the sum and the product of a direct product element
##  with a non-list as the direct product element of componentwise sums and
##  products, respectively.
##
#T As soon as IsListDefault implies IsAdditiveElement and
#T IsMultiplicativeElement, the InstallOtherMethod in the first four
#T of the following methods can be replaced by InstallMethod!
InstallOtherMethod( \+,
    "for a direct product element, and a default list",
    [ IsDirectProductElement, IsListDefault ],
    SUM_SCL_LIST_DEFAULT );

InstallOtherMethod( \+,
    "for a default list, and a direct product element",
    [ IsListDefault, IsDirectProductElement ],
    SUM_LIST_SCL_DEFAULT );

InstallOtherMethod( \*,
    "for a direct product element, and a default list",
    [ IsDirectProductElement, IsListDefault ],
    PROD_SCL_LIST_DEFAULT );

InstallOtherMethod( \*,
    "for a default list, and a direct product element",
    [ IsListDefault, IsDirectProductElement ],
    PROD_LIST_SCL_DEFAULT );

InstallOtherMethod( \+,
    "for a direct product element, and a non-list",
    [ IsDirectProductElement, IsObject ],
    function( dpelm, nonlist )
    if IsList( nonlist ) then
      TryNextMethod();
    fi;
    return DirectProductElement( List( dpelm, entry -> entry + nonlist ) );
    end );

InstallOtherMethod( \+,
    "for a non-list, and a direct product element",
    [ IsObject, IsDirectProductElement ],
    function( nonlist, dpelm )
    if IsList( nonlist ) then
      TryNextMethod();
    fi;
    return DirectProductElement( List( dpelm, entry -> nonlist + entry ) );
    end );

InstallOtherMethod( \*,
    "for a direct product element, and a non-list",
    [ IsDirectProductElement, IsObject ],
    function( dpelm, nonlist )
    if IsList( nonlist ) then
      TryNextMethod();
    fi;
    return DirectProductElement( List( dpelm, entry -> entry * nonlist ) );
    end );

InstallOtherMethod( \*,
    "for a non-list, and a direct product element",
    [ IsObject, IsDirectProductElement ],
    function( nonlist, dpelm )
    if IsList( nonlist ) then
      TryNextMethod();
    fi;
    return DirectProductElement( List( dpelm, entry -> nonlist * entry ) );
    end );


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