This file is indexed.

/usr/share/gap/lib/smgideal.gi is in gap-libs 4r7p5-2.

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
#############################################################################
##
#W  smgideal.gi              GAP library                     Robert Arthur
##
##
#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 contains generic methods for semigroup ideals.
##


#############################################################################
##
##  Immediate methods for
##
##  IsLeftSemigroupIdeal
##  IsRightSemigroupIdeal
##  IsSemigroupIdeal
##
#############################################################################
InstallImmediateMethod( IsLeftSemigroupIdeal,
    IsLeftMagmaIdeal and HasLeftActingDomain and IsAttributeStoringRep, 0,
    I -> HasIsSemigroup(LeftActingDomain(I)) and
         IsSemigroup(LeftActingDomain(I)) );

InstallImmediateMethod( IsRightSemigroupIdeal,
    IsRightMagmaIdeal and HasRightActingDomain and IsAttributeStoringRep, 0,
    I -> HasIsSemigroup(RightActingDomain(I)) and
         IsSemigroup(RightActingDomain(I)) );

InstallImmediateMethod(IsSemigroupIdeal,
    IsMagmaIdeal and HasActingDomain and IsAttributeStoringRep, 0,
    I -> HasIsSemigroup(ActingDomain(I)) and IsSemigroup(ActingDomain(I)) );


#############################################################################
#############################################################################
##                                                                         ##
##                   ENUMERATORS                                           ##
##                                                                         ##
#############################################################################
#############################################################################

#############################################################################
##
#F  RightSemigroupIdealEnumeratorDataGetElement( <enum>, <n> )
##
##  Returns a pair [T/F, elm], such that if <n> is less than or equal to
##  the size of the right ideal the first of the pair will be
##  true, and elm will be the element at the <n>th place.   Otherwise, the
##  first of the pair will be false.
##
BindGlobal( "RightSemigroupIdealEnumeratorDataGetElement",
    function( enum, n )
    local i, ideal, new;

    ideal:= UnderlyingCollection(enum);

    if n <= Length(enum!.currentlist) then
      return [true, enum!.currentlist[n]];
    fi;

    # Starting at the first non-expanded element of the list, multiply
    # every element of the list by generators, until it is large enough
    # to give the nth element.
    while IsBound(enum!.currentlist[enum!.nextelm]) do
      for i in enum!.gens do
        new:= enum!.currentlist[enum!.nextelm] * i;
        if not new in enum!.orderedlist then
          Add(enum!.currentlist, new);
          AddSet(enum!.orderedlist, new);
        fi;
      od;
      enum!.nextelm:= enum!.nextelm+1;

      # If we have now evaluated the element in the nth place
      if n <= Length(enum!.currentlist) then
        return [true, enum!.currentlist[n]];
      fi;
    od;

    # By now we have closed the list, and found it not to contain n
    # elements.
    if not HasAsSSortedList(ideal) then
      SetAsSSortedList(ideal, enum!.orderedlist);
    fi;
    return [false, 0];
    end );


#############################################################################
##
#F  LeftSemigroupIdealEnumeratorDataGetElement( <Enum>, <n> )
##
##  Returns a pair [T/F, elm], such that if <n> is less than or equal to
##  the size of the underlying left ideal the first of the pair will be
##  true, and elm will be the element at the <n>th place.   Otherwise, the
##  first of the pair will be false.
##
BindGlobal("LeftSemigroupIdealEnumeratorDataGetElement",
function (enum, n)

local i, ideal, new;

ideal:= UnderlyingCollection(enum);

if n <= Length(enum!.currentlist) then
return [true, enum!.currentlist[n]];
fi;

# Starting at the first non-expanded element of the list, multiply
# every element of the list by generators, until it is large enough
# to give the nth element.
while IsBound(enum!.currentlist[enum!.nextelm]) do
for i in enum!.gens do
new:= i * enum!.currentlist[enum!.nextelm];
if not new in enum!.orderedlist then
Add(enum!.currentlist, new);
AddSet(enum!.orderedlist, new);
fi;
od;
enum!.nextelm:= enum!.nextelm+1;

# If we have now evaluated the element in the nth place
if n <= Length(enum!.currentlist) then
return [true, enum!.currentlist[n]];
fi;
od;

# By now we have closed the list, and found it not to contain n
# elements.
if not HasAsSSortedList(ideal) then
SetAsSSortedList(ideal, enum!.orderedlist);
fi;
return [false, 0];
end);

#############################################################################
##
#F  SemigroupIdealEnumeratorDataGetElement( <Enum>, <n> )
##
##  Returns a pair [T/F, elm], such that if <n> is less than or equal to
##  the size of the underlying  ideal the first of the pair will be
##  true, and elm will be the element at the <n>th place.   Otherwise, the
##  first of the pair will be false.
##
BindGlobal("SemigroupIdealEnumeratorDataGetElement",
function (enum, n)

local i, j, new, onleft, ideal;

ideal:= UnderlyingCollection(enum);

if n <= Length(enum!.currentlist) then
return [true, enum!.currentlist[n]];
fi;

# Starting at the first non-expanded element of the list, multiply
# every element of the list by generators, until it is large enough
# to give the nth element.
onleft:= false;
while IsBound(enum!.currentlist[enum!.nextelm]) do
for i in enum!.gens do
for j in [1,2] do
if onleft then
new:= i * enum!.currentlist[enum!.nextelm];
else
new:= enum!.currentlist[enum!.nextelm] * i;
fi;
if not new in enum!.orderedlist then
Add(enum!.currentlist, new);
AddSet(enum!.orderedlist, new);
fi;
onleft:= not onleft;
od;
od;
enum!.nextelm:= enum!.nextelm+1;

# If we have now evaluated the element in the nth place
if n <= Length(enum!.currentlist) then
return [true, enum!.currentlist[n]];
fi;
od;

# By now we have closed the list, and found it not to contain n
# elements.
if not HasAsSSortedList(ideal) then
SetAsSSortedList(ideal, enum!.orderedlist);
fi;
return [false, 0];
end);


#############################################################################
##
#M  \[\]( <E>, <n> )
##
##  Returns the <n>th element of a right semigroup ideal enumerator.   Sets
##  AsSSorted list for the underlying ideal when all elements have been
##  found.
##
BindGlobal( "ElementNumber_SemigroupIdealEnumerator", function( enum, n )
    if IsBound( enum[n] ) then
      return( enum!.currentlist[n] );  # we know it to be bound, so
                                       # must have computed it!
    else
      Error("Position out of range");
    fi;
    end );


#############################################################################
##
#M  Position( <E>, <elm>, 0 )
##
##  There was no special `Position' method for these enumerators,
##  so we install a simpleminded approach.
##
BindGlobal( "NumberElement_SemigroupIdealEnumerator", function( enum, elm )
    local pos;

    if not IsCollsElms( FamilyObj( enum ), FamilyObj( elm ) ) then
      return fail;
    fi;

    pos:= 1;
    while IsBound( enum[ pos ] ) do
      if enum[ pos ] = elm then
        return pos;
      fi;
      pos:= pos + 1;
    od;
    return fail;
    end );


#############################################################################
##
#M  IsBound\[\]( <E>, <n> )
##
##  Returns true if the enumerator has size at least <n>.   This is the meat
##  of the enumerators calculation, with \[\] relying on it to set the
##  required data.
##
InstallGlobalFunction( IsBound_RightSemigroupIdealEnumerator,
    function( enum, n )
    return RightSemigroupIdealEnumeratorDataGetElement( enum, n )[1];
    end );

InstallGlobalFunction( IsBound_LeftSemigroupIdealEnumerator,
    function( enum, n )
    return LeftSemigroupIdealEnumeratorDataGetElement( enum, n )[1];
    end );

BindGlobal( "IsBound_SemigroupIdealEnumerator", function( enum, n )
    return SemigroupIdealEnumeratorDataGetElement( enum, n )[1];
    end );


#############################################################################
##
##  The following Length and \in methods are needed because of an
##  infinite recursion which is caused by the method
##  Size  "for a collection" calling
##  Length "for domain enumerator with underlying collection"
##  which in turn calls Size "for a collection" for the underlying collection.
##  This sets up the recursion.
##
##  The methods below insure we never get into this infinite recursion
##  with Semigroup enumerators.
##
##  Example:
##
##  f:=FreeSemigroup("a","b","c");
##  x:=GeneratorsOfSemigroup(f);
##  a:=x[1];;b:=x[2];;c:=x[3];;
##  r:= [ [a*b,b*a],[a*c,c*a],[b*c,c*b],[a*a,a],[b*b,b],[c*c,c] ];
##  s := f/r;
##  Size(s);
##
##  recursion depth trap (5000)
##  at
##  return Size( UnderlyingCollection( enum ) );
##  Length( Enumerator( C ) ) called from
##  Size( UnderlyingCollection( enum ) ) called from
##  Length( Enumerator( C ) ) called from
##  Size( UnderlyingCollection( enum ) ) called from
##  Length( Enumerator( C ) ) called from
##

#############################################################################
##
#M  Length(<semigroupenum>)
##
##  Find the length of the enumerator of a semigroup ideal enumerator.
##
BindGlobal( "Length_SemigroupIdealEnumerator", function( e )
    local n;

    n:=1;
    while IsBound(e[n]) do
      n := n+1;
    od;
    return n-1;
    end );


#############################################################################
##
#M  \in (obj, semigroupenum)
##
##  Needed only for infinite semigroups which do not have their own \in
##  method e.g. finitely presented semigroups.
##  For example a semigroup of matrices over a infinite domain.
##
##  m := [[2,3],[4,5]];
##  s := Semigroup(m);
##  [[2,3],[4,5]] in s;
##
##  Without the \in method below we would use the default case which
##  implicitly requires the Length of the semigroup to be computed never
##  terminating.
##
BindGlobal( "Membership_SemigroupIdealEnumerator", function( obj, enum )
    local i;

    i := 1;
    while IsBound( enum[i] ) do
      if obj = enum[i] then
        return true;
      fi;
      i := i +1;
    od;
    return false;
    end );


#############################################################################
##
#M  Enumerator( <I> ) . . . . . . . . . . . . . . for a right semigroup ideal
#M  Enumerator( <I> ) . . . . . . . . . . . . . .  for a left semigroup ideal
#M  Enumerator( <I> ) . . . . . . . . . . . for a (two sided) semigroup ideal
##
InstallGlobalFunction( EnumeratorOfSemigroupIdeal,
    function( I, actdom, isbound, gens )

    if not HasGeneratorsOfSemigroup( actdom ) then
      TryNextMethod();
    fi;

    return EnumeratorByFunctions( I, rec(
        ElementNumber := ElementNumber_SemigroupIdealEnumerator,
        NumberElement := NumberElement_SemigroupIdealEnumerator,
        IsBound\[\]   := isbound,
        Length        := Length_SemigroupIdealEnumerator,
        Membership    := Membership_SemigroupIdealEnumerator,

        currentlist   := ShallowCopy( AsSet( gens ) ),
        gens          := AsSet( GeneratorsOfSemigroup( actdom ) ),
        nextelm       := 1,
        orderedlist   := ShallowCopy( AsSet( gens ) ) ) );
    end );

InstallMethod( Enumerator,
    "for a right semigroup ideal",
    [ IsRightSemigroupIdeal and HasGeneratorsOfRightMagmaIdeal ],
    I -> EnumeratorOfSemigroupIdeal( I, RightActingDomain( I ),
             IsBound_RightSemigroupIdealEnumerator,
             GeneratorsOfRightMagmaIdeal( I ) ) );

InstallMethod( Enumerator,
    "for a left semigroup ideal",
    [ IsLeftSemigroupIdeal and HasGeneratorsOfLeftMagmaIdeal ],
    I -> EnumeratorOfSemigroupIdeal( I, LeftActingDomain( I ),
             IsBound_LeftSemigroupIdealEnumerator,
             GeneratorsOfLeftMagmaIdeal( I ) ) );

InstallMethod( Enumerator,
    "for a semigroup ideal",
    [ IsSemigroupIdeal and HasGeneratorsOfMagmaIdeal ],
    I -> EnumeratorOfSemigroupIdeal( I, ActingDomain( I ),
             IsBound_SemigroupIdealEnumerator,
             GeneratorsOfMagmaIdeal( I ) ) );


#############################################################################
##
#M  ReesCongruenceOfSemigroupIdeal( <I> )
##
##  A two sided ideal <I> of a semigroup <S>  defines a congruence on
##  <S> given by $\Delta \cup I \times I$.
##
InstallMethod(ReesCongruenceOfSemigroupIdeal,
    "for a two sided semigroup congruence",
    [ IsMagmaIdeal and IsSemigroupIdeal ],
    function(i)
    local mc;

    mc := LR2MagmaCongruenceByPartitionNCCAT(Parent(i),
              [Enumerator(i)], IsMagmaCongruence);
    SetIsSemigroupCongruence(mc, true);

    return mc;
    end );


#############################################################################
##
#M  PrintObj( <S> ) . . . . . . . . . . . . . . . . . .  for a SemigroupIdeal
##
InstallMethod( PrintObj,
    "for a semigroup ideal",
    [ IsMagmaIdeal and IsSemigroupIdeal ],
    function( S )
    Print( "SemigroupIdeal( ... )" );
    end );

InstallMethod( PrintObj,
    "for a semigroup ideal with known generators",
    [ IsMagmaIdeal and IsSemigroupIdeal and HasGeneratorsOfMagmaIdeal ],
    function( S )
    Print( "SemigroupIdeal( ", GeneratorsOfMagmaIdeal( S ), " )" );
    end );


#############################################################################
##
#M  ViewObj( <S> )  . . . . . . . . . . . . . . . . . .  for a SemigroupIdeal
##
InstallMethod( ViewObj,
    "for a semigroup ideal",
    [ IsMagmaIdeal and IsSemigroupIdeal ],
    function( S )
    Print( "<SemigroupIdeal>" );
    end );

InstallMethod( ViewObj,
    "for a semigroup ideal with known generators",
    [ IsMagmaIdeal and IsSemigroupIdeal and HasGeneratorsOfMagmaIdeal ],
    function( S )
    Print( "<semigroup ideal with ", Length(GeneratorsOfMagmaIdeal( S )),
           " generators>" );
    end );


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