This file is indexed.

/usr/share/gap/lib/semitran.gi is in gap-libs 4r6p5-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
############################################################################
##
#W  semitran.gi           GAP library         Isabel Araújo and Robert Arthur
##
##
#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 implementation of some basics for transformation
##  semigroups
##

#############################################################################
##
#M  IsTransformationMonoid( <M> )
##
##  If an object has IsMonoid, then it necessarily contains the identity
##  transformation, and so is a submonoid of the full transformation
##  monoid.
##
InstallTrueMethod(IsTransformationMonoid, IsMonoid and
    IsTransformationCollection);

#############################################################################
##
#M  IsTransformationMonoid( <S> )
##
##  A transformation semigroup is a transformation monoid iff at least
##  one of the generators is of rank n, where n is the degree of the
##  semigroup.
##
InstallMethod(IsTransformationMonoid, "for a transformation semigroup",
    true, [IsTransformationSemigroup and HasGeneratorsOfSemigroup], 0,
function( S )
    if ForAny(GeneratorsOfSemigroup(S),
           x->RankOfTransformation(x)=DegreeOfTransformationSemigroup(S)) then

        SetGeneratorsOfMonoid(S, GeneratorsOfSemigroup(S));
        return true;
    else
        return false;
    fi;
end);

#############################################################################
##
#M  AsMonoid( <S> )
##
##  Given a Transformation semigroup with known generators
##  for which IsTransformationMonoid is true, return it as a monoid.
##
InstallMethod(AsMonoid, "for transformation semigroup", true,
    [IsTransformationSemigroup and HasGeneratorsOfSemigroup], 0,
function(S)
    if IsTransformationMonoid(S) then
        return Monoid(GeneratorsOfSemigroup(S));
    else
        return fail;
    fi;
end);

##############################################################################
##
#M  IsFinite( <M> )
##
##  Transformation semigroups (considered in gap) are finite
##
InstallTrueMethod(IsFinite, IsTransformationSemigroup);

#############################################################################
##
#M  DegreeOfTransformationSemigroup( <S> )
##
##  Since we insist all elements must have the same degree, we may simply
##  give the degree of one generator.
##
InstallMethod(DegreeOfTransformationSemigroup, "degree of a trans semigroup",
true, [IsTransformationSemigroup],0,
function(s)
    return DegreeOfTransformation(AsList(GeneratorsOfSemigroup(s))[1]);
end);

###############################################################################
##
#M  IsomorphismPermGroup( <H> )
##
##  for a greens H class of a semigroup
##  returns an isomorphism from the H class to an isomorphic Perm group
##
InstallOtherMethod( IsomorphismPermGroup,
    "for a Green's group H class of a semigroup", true,
    [ IsGreensHClass and IsEquivalenceClass], 0,
function( h )

    local enum,      # enumerator of h
          isgroup,   # is h a group
          gens,      # the generators of the perm group
          permgroup, # the perm group
          perm,      # a permutation
          i,j,       # loop variables
          mapfun;    # the function that computes the mapping

    if not(IsFinite(h)) then
       TryNextMethod();
    fi;


     if not( IsGroupHClass(h) ) then
        Error("can only create isomorphism of group H classes");
    fi;

#    i := 1;
#    isgroup := false;
#    while IsBound( enum[ i ] ) and not( isgroup ) do
#        if enum[ i ]*enum[ i ] = enum[ i ] then
#            isgroup := true;
#        fi;
#        i := i+1;
#    od;


    # now we build the Perm group

    # For each element of h we build the permutation induced in h by itself
    # These permutations are going to be the generators of the perm group
    gens:=[]; enum := Enumerator( h );

    i := 1;
    while IsBound( enum[ i ] ) do
        perm := [];
        j := 1;
        while IsBound( enum[ j ] ) do
            Add( perm, Position( enum, enum[i] * enum[ j ] ) );
            j := j+1;
        od;
        Add( gens, PermList(perm) );
        i := i+1;
    od;
    # notice that gens now is a list of permutations, entry i of which
    # is the permutation induced in H by the element enum[i]

    # now we build the group
    permgroup := Group( gens );

    mapfun := a -> gens[ Position( enum, a )];

    return MappingByFunction( h, permgroup, mapfun );

end);

###############################################################################
##
#M  IsomorphismTransformationSemigroup( <S> )
##
##  For a generic semigroup <S>  with MultiplicativeNeutralElement.
##  Returns an isomorphism from <S> to a transformation semigroup
##  It is the right regular representation of $S$.
##
##  This function could be much more space efficient if we knew how
##  to factor elements of a semigroup into words in the generators!
##
InstallMethod( IsomorphismTransformationSemigroup,
    "for a generic semigroup with multiplicative neutral element",
    true,
    [ IsSemigroup and HasMultiplicativeNeutralElement], 0,
function( s )
    local
        en,     #enumerator of the semigroup - this becomes part of the isomorphism
        gens,   # the generators of the transformation semigroup
        mapfun; # the function which describes the mapping

    if not(IsFinite(s)) then
       Error("error, semigroup is infinite. Transformation semigroups in GAP are finite");
    fi;
    en := EnumeratorSorted(s);

    mapfun := a -> Transformation( List([1..Length(en)], i->Position(en, en[i]*a)));

    gens := List(GeneratorsOfSemigroup(s),x->mapfun(x));

    return MagmaHomomorphismByFunctionNC( s, Semigroup(gens), mapfun );

end);

##
##  As above, but add an extra point for faithfulness
##
InstallMethod( IsomorphismTransformationSemigroup,
    "for a generic semigroup",
    true, [IsSemigroup], 0,

function( s )
    local
        en,     #enumerator of the semigroup - this becomes part of the isomorphism
        gens,   # the generators of the transformation semigroup
        mapfun; # the function which describes the mapping


    if not(IsFinite(s)) then
        Error("error, semigroup is infinite. Transformation semigroups in GAP are finite");
    fi;

    en := EnumeratorSorted(s);

    mapfun := a -> Transformation(
    Concatenation(List([1..Length(en)], i->Position(en, en[i]*a)),[Position(en,a)]));

    gens := List(GeneratorsOfSemigroup(s),x->mapfun(x));

    return MagmaHomomorphismByFunctionNC( s, Semigroup(gens), mapfun );

end);


#############################################################################
##
##  For semigroups of SingleValued GeneralMappings with a generating set.
##  For the moment we resist the temptation to install it for a semigroup
##  of general mappings without a generating set - this would be a
##  highly suspicious object.
##
InstallMethod( IsomorphismTransformationSemigroup,
    "for a semigroup of general mappings",
    true,
    [IsSemigroup and IsGeneralMappingCollection and HasGeneratorsOfSemigroup],
    0,

function( s )
    local  gens,   # the generators of the transformation semigroup
           egens,  # the generators of the endomorphism semigroup
           mapfun; # the function which describes the mapping

    egens := GeneratorsOfSemigroup(s);
    if not ForAll(egens, g->IsMapping(g)) then
        TryNextMethod();
    fi;
    gens := List(egens, g->TransformationRepresentation(g)!.transformation);

    mapfun := a -> TransformationRepresentation(a)!.transformation;

    return MagmaHomomorphismByFunctionNC( s, Semigroup(gens), mapfun );

end);

#############################################################################
##
#F  FullTransformationSemigroup(<degree>)
##
##
InstallGlobalFunction(FullTransformationSemigroup,
    function(d)
        local s;  ## semigroup

        if not IsPosInt(d) then
            Error("<d> must be a positive integer");
        fi;

        if d =1 then
            return Monoid(Transformation([1]));
        elif d=2 then
            return Monoid(Transformation([2,1]),
                             Transformation([1,1]),
                             Transformation([2,2]) );
        fi;

        s := Monoid(Transformation(Concatenation([2..d],[1])),
                       Transformation(Concatenation([2,1],[3..d])),
                       Transformation(Concatenation([1..d-1],[1])) );

        SetSize(s,d^d);
        SetIsTransformationMonoid(s,true);
        SetIsFullTransformationSemigroup(s,true);
        return s;
    end);

#############################################################################
##
#A  IsFullTransformationSemigroup
##
##  implements simple checks to determine when a transformation semigroup is
##  the full transformation semigroup
##
InstallMethod(IsFullTransformationSemigroup, "for semigroups", true,
        [IsSemigroup],0,
    function(s)

        local gens,      ## Generators of the semigroup
              d,         ## degree of the semigroup
              a, b, c;   ## 3 generators known to generate the full
                         ## transformation semigroup

        ## Semigroup must be a transformation semigroup
        ##
        if not IsTransformationSemigroup(s) then
            return false;
        fi;

        ## Check size (if there is one)
        ##
        if HasSize(s) then
             return Size(s)=DegreeOfTransformationSemigroup(s)^
                 DegreeOfTransformationSemigroup(s);
        fi;

        ## Check small cases
        ##
        if DegreeOfTransformationSemigroup(s) < 5 then
             return Size(s)=DegreeOfTransformationSemigroup(s)^
                 DegreeOfTransformationSemigroup(s);
        fi;

        ## Lastly check to see if a set of generators known to generatate
        ##     the whole semigroup is in the semigroup
        ##     (This is a very crude test at the moment but a start)
        ##

        d := DegreeOfTransformationSemigroup(s);

        a := Transformation(Concatenation([2..d],[1]));
        b := Transformation(Concatenation([2,1],[3..d]));
        c := Transformation(Concatenation([1..d-1],[1]));

        return a in s and b in s and c in s;

    end);

#############################################################################
##
#M  \in   for full transformation semigroup
##
##  If the transformation and group have the same degree then return true
##
InstallMethod(\in, "for full transformation semigroups", true,
        [IsObject,IsFullTransformationSemigroup],0,
    function(e,tn)
        return DegreeOfTransformation(e)=DegreeOfTransformationSemigroup(tn);
    end);

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