This file is indexed.

/usr/share/gap/lib/semipperm.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
############################################################################
##
#W  semipperm.gi           GAP library                         J. D. Mitchell
##
##
#Y  Copyright (C)  2013,  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 partial perm 
##  semigroups.

#

InstallMethod(DisplayString, "for a partial perm semigroup with generators",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup], ViewString);

# the following is used to produce the view string for every type of partial
# perm semigroup, in particular it is required so that it is used in preference
# to the method for inverse semigroups/monoids

BindGlobal("ViewStringForPartialPermSemigroups", 
function(S)
  local str, nrgens;
  
  str:="<";

  if HasIsTrivial(S) and IsTrivial(S) then 
    Append(str, "trivial ");
  else 
    if HasIsCommutative(S) and IsCommutative(S) then 
      Append(str, "commutative ");
    fi;
  fi;

  if HasIsTrivial(S) and IsTrivial(S) then 
  elif HasIsZeroSimpleSemigroup(S) and IsZeroSimpleSemigroup(S) then 
    Append(str, "0-simple ");
  elif HasIsSimpleSemigroup(S) and IsSimpleSemigroup(S) then 
    Append(str, "simple ");
  fi;

  if HasIsInverseSemigroup(S) and IsInverseSemigroup(S) then 
    Append(str, "inverse ");
  fi;

  Append(str, "partial perm ");
 
  if HasIsMonoid(S) and IsMonoid(S) then 
    Append(str, "monoid ");
    if HasIsInverseSemigroup(S) and IsInverseSemigroup(S) then 
      nrgens:=Length(GeneratorsOfInverseMonoid(S));
    else 
      nrgens:=Length(GeneratorsOfMonoid(S));
    fi;
  else 
    Append(str, "semigroup ");
    if HasIsInverseSemigroup(S) and IsInverseSemigroup(S) then 
      nrgens:=Length(GeneratorsOfInverseSemigroup(S));
    else
      nrgens:=Length(GeneratorsOfSemigroup(S));
    fi;
  fi;
 
 if HasIsTrivial(S) and not IsTrivial(S) and HasSize(S) and Size(S)<2^64 then 
    Append(str, "\<\>of size ");
    Append(str, String(Size(S)));
    Append(str, ", ");
  fi;
 
  Append(str, "\<\>on ");
  Append(str, String(RankOfPartialPermSemigroup(S)));
  Append(str, " pts\<\> with ");

  Append(str, String(nrgens));
  Append(str, " generator");

  if nrgens>1 or nrgens=0 then 
    Append(str, "s");
  fi;
  Append(str, ">");

  return str;
end);

# the following method is required so that the view string method for partial
# perm semigroup (immediately below) is used in preference to the method for
# inverse semigroups

InstallMethod(ViewString, "for a partial perm inverse semigroup",
[IsPartialPermSemigroup and IsInverseSemigroup],
ViewStringForPartialPermSemigroups);

InstallMethod(ViewString, "for a partial perm inverse semigroup",
[IsPartialPermSemigroup and IsInverseMonoid],
ViewStringForPartialPermSemigroups);

InstallMethod(ViewString, "for a partial perm semigroup with generators",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
ViewStringForPartialPermSemigroups);

InstallMethod(ViewString, "for a partial perm monoid with generators",
[IsPartialPermMonoid and HasGeneratorsOfMonoid],
ViewStringForPartialPermSemigroups);

InstallMethod(ViewString, 
"for a simple inverse partial perm semigroup with generators",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup 
and IsSimpleSemigroup and IsInverseSemigroup], 
function(s)
  local str, nrgens;
  
  str:="<";

  if HasIsTrivial(s) and IsTrivial(s) then 
    Append(str, "trivial ");
  else 
    if HasIsCommutative(s) and IsCommutative(s) then 
      Append(str, "commutative ");
    fi;
  fi;

  Append(str, "partial perm group ");

  if HasIsMonoid(s) and IsMonoid(s) then 
    nrgens:=Length(GeneratorsOfInverseMonoid(s));
  else 
    nrgens:=Length(GeneratorsOfInverseSemigroup(s));
  fi;
 
 if HasIsTrivial(s) and not IsTrivial(s) and HasSize(s) and Size(s)<2^64 then 
    Append(str, "\<\>of size ");
    Append(str, String(Size(s)));
    Append(str, ", ");
  fi;
 
  Append(str, "\<\>on ");
  Append(str, String(RankOfPartialPermSemigroup(s)));
  Append(str, " pts\<\> with ");

  Append(str, String(nrgens));
  Append(str, " generator");

  if nrgens>1 or nrgens=0 then 
    Append(str, "s");
  fi;
  Append(str, ">");

  return str;
end);

#

InstallMethod(One, "for a partial perm semigroup with generators", 
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
function(s)
  local x;
  
  x:=One(GeneratorsOfSemigroup(s));
  if x in s then 
    return x;
  fi;
  return fail;
end);

#

InstallMethod(One, "for a partial perm monoid with generators", 
[IsPartialPermMonoid and HasGeneratorsOfSemigroup],
function(s)
  return One(GeneratorsOfSemigroup(s));
end);

#

InstallTrueMethod(IsFinite, IsPartialPermSemigroup);

#

InstallMethod(DegreeOfPartialPermSemigroup,
"for a partial perm semigroup",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
s-> DegreeOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(DegreeOfPartialPermCollection,
"for a partial perm semigroup",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
s-> DegreeOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(CodegreeOfPartialPermSemigroup,
"for a partial perm semigroup with generators",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
s-> CodegreeOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(CodegreeOfPartialPermCollection,
"for a partial perm semigroup with generators",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
s-> CodegreeOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(CodegreeOfPartialPermSemigroup,
"for an inverse partial perm semigroup",
[IsPartialPermSemigroup and IsInverseSemigroup and HasGeneratorsOfSemigroup],
s-> DegreeOfPartialPermSemigroup(s));

InstallMethod(RankOfPartialPermSemigroup,
"for a partial perm semigroup",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
s-> RankOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(RankOfPartialPermCollection,
"for a partial perm semigroup",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
s-> RankOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(DomainOfPartialPermCollection,
"for a partal perm semigroup",
[IsPartialPermSemigroup],
s-> DomainOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(ImageOfPartialPermCollection,
"for a partal perm semigroup",
[IsPartialPermSemigroup],
s-> ImageOfPartialPermCollection(GeneratorsOfSemigroup(s)));

InstallMethod(FixedPointsOfPartialPerm, "for a partial perm semigroup",
[IsPartialPermSemigroup],
s-> MovedPoints(GeneratorsOfSemigroup(s)));

InstallMethod(MovedPoints, "for a partial perm semigroup",
[IsPartialPermSemigroup],
s-> MovedPoints(GeneratorsOfSemigroup(s)));

InstallMethod(NrFixedPoints, "for a partial perm semigroup",
[IsPartialPermSemigroup],
s-> NrFixedPoints(GeneratorsOfSemigroup(s)));

InstallMethod(NrMovedPoints, "for a partial perm semigroup",
[IsPartialPermSemigroup],
s-> NrMovedPoints(GeneratorsOfSemigroup(s)));

InstallMethod(LargestMovedPoint, "for a partial perm semigroup",
[IsPartialPermSemigroup], s-> LargestMovedPoint(GeneratorsOfSemigroup(s)));

InstallMethod(LargestImageOfMovedPoint, "for a partial perm semigroup",
[IsPartialPermSemigroup], 
s-> LargestImageOfMovedPoint(GeneratorsOfSemigroup(s)));

InstallMethod(SmallestMovedPoint, "for a partial perm semigroup",
[IsPartialPermSemigroup], s-> SmallestMovedPoint(GeneratorsOfSemigroup(s)));

InstallMethod(SmallestImageOfMovedPoint, "for a partial perm semigroup",
[IsPartialPermSemigroup], 
s-> SmallestImageOfMovedPoint(GeneratorsOfSemigroup(s)));

#

InstallOtherMethod(OneMutable, "for a partial perm semigroup",
[IsPartialPermSemigroup],
function(s)
  local  one;
  one := One(GeneratorsOfSemigroup(s));
  if one in s then
    return one;
  fi;
  return fail;
end);

#

InstallOtherMethod(ZeroMutable, "for a partial perm semigroup",
[IsPartialPermSemigroup],
function(s)
  local  zero;
  zero := Zero(GeneratorsOfSemigroup(s));
  if zero in s then
    return zero;
  fi;
  return fail;
end);

#

InstallMethod(GeneratorsOfInverseSemigroup,
"for an inverse partial perm semigroup with generators",
[IsPartialPermSemigroup and IsInverseSemigroup and HasGeneratorsOfSemigroup],
function(s)
  local gens, pos, f;

  gens:=ShallowCopy(GeneratorsOfSemigroup(s));
  for f in gens do
    pos:=Position(gens, f^-1);
    if pos<>fail and f<>f^-1 then 
      Remove(gens, pos);
    fi;
  od;
  MakeImmutable(gens);
  return gens;
end);

#

InstallMethod(GeneratorsOfInverseMonoid,
"for an inverse partial perm monoid with generators",
[IsPartialPermSemigroup and IsInverseMonoid and HasGeneratorsOfMonoid],
function(s)
  local gens, one, pos, f;

  gens:=ShallowCopy(GeneratorsOfMonoid(s));
  one:=One(s);
  for f in gens do
    pos:=Position(gens, f^-1);
    if pos<>fail and (f<>f^-1 or f=one) then 
      Remove(gens, pos);
    fi;
  od;
  MakeImmutable(gens);
  return gens;
end);

#

InstallImmediateMethod(GeneratorsOfSemigroup,
IsPartialPermSemigroup and HasGeneratorsOfInverseSemigroup, 0, 
function(s)
  local gens, f;

  gens:=ShallowCopy(GeneratorsOfInverseSemigroup(s));
  for f in gens do
    if DomainOfPartialPerm(f)<>ImageSetOfPartialPerm(f) and not f^-1 in gens
     then
      Add(gens, f^-1);
    fi;
  od;
  MakeImmutable(gens);
  return gens;
end);

#

InstallImmediateMethod(GeneratorsOfMonoid,
IsPartialPermMonoid and HasGeneratorsOfInverseMonoid, 0, 
function(s)
  local gens, pos, f;

  gens:=ShallowCopy(GeneratorsOfInverseMonoid(s));
  for f in gens do
    if DomainOfPartialPerm(f)<>ImageSetOfPartialPerm(f) 
     and not f^-1 in gens then
      Add(gens, f^-1);
    fi;
  od;
  MakeImmutable(gens);
  return gens;
end);

# isomorphisms

#

InstallMethod(IsomorphismPartialPermSemigroup, 
"for a semigroup with generators",
[IsSemigroup and HasGeneratorsOfSemigroup],
function(S)
  local elts, iso, gens;

  if not IsInverseSemigroup(S) then 
    return fail;
  fi;
  
  elts:=Elements(S);

  iso:=function(x)
    local dom, y;
    y:=InversesOfSemigroupElement(S, x)[1];
    dom:=Set(elts*y);
    return PartialPermNC(List(dom, y-> Position(elts, y)),
     List(List(dom, y-> y*x), y-> Position(elts, y)));
  end;

  gens:=ShallowCopy(GeneratorsOfSemigroup(S));
  Apply(gens, iso);
  return MagmaHomomorphismByFunctionNC(S, InverseSemigroup(gens), iso);
end);

#

InstallMethod(IsomorphismPartialPermMonoid, 
"for a monoid with generators",
[IsMonoid and HasGeneratorsOfMonoid],
function(S)
  local elts, iso, gens;

  if not IsInverseSemigroup(S) then 
    return fail;
  fi;
  
  elts:=Elements(S);

  iso:=function(x)
    local dom, y;
    y:=InversesOfSemigroupElement(S, x)[1];
    dom:=Set(elts*y);
    return PartialPermNC(List(dom, y-> Position(elts, y)),
     List(List(dom, y-> y*x), y-> Position(elts, y)));
  end;

  gens:=ShallowCopy(GeneratorsOfMonoid(S));
  Apply(gens, iso);
  return MagmaHomomorphismByFunctionNC(S, InverseMonoid(gens), iso);
end);

#JDM improve this

InstallMethod(IsomorphismPartialPermMonoid,
"for a transformation semigroup",
[IsTransformationSemigroup and HasGeneratorsOfSemigroup],
function(s)
  local iso;

  if not IsInverseMonoid(s) and MultiplicativeNeutralElement(s)=fail then
    Error("usage: the argument should be an inverse semigroup with ",  
     "a mult. neutral element,");
    return;
  fi;

  iso:=function(f)
  local dom, img;
    dom:=ImageSetOfTransformation(InversesOfSemigroupElement(s, f)[1], 
      DegreeOfTransformationSemigroup(s));
    img:=List(dom, i-> i^f);
    return PartialPermNC(dom, img);
  end;

  return MagmaHomomorphismByFunctionNC(s,
   InverseMonoid(List(GeneratorsOfSemigroup(s), iso)), iso);
end);

#JDM improve this

InstallMethod(IsomorphismPartialPermSemigroup,
"for a transformation semigroup",
[IsTransformationSemigroup and HasGeneratorsOfSemigroup],
function(s)
  local iso;

  if not IsInverseSemigroup(s) then
    Error("usage: the argument should be an inverse semigroup,");
    return;
  fi;

  iso:=function(f)
    local dom, img;
    dom:=ImageSetOfTransformation(InversesOfSemigroupElement(s, f)[1], 
      DegreeOfTransformationSemigroup(s));
    img:=List(dom, i-> i^f);
    return PartialPermNC(dom, img);
  end;

  return MagmaHomomorphismByFunctionNC(s,
   InverseSemigroup(List(GeneratorsOfSemigroup(s), iso)), iso);
end);

#

InstallMethod(IsomorphismPartialPermMonoid, "for a perm group",
[IsPermGroup],
function(g)
  local dom;
  dom:=MovedPoints(g);
  return MagmaIsomorphismByFunctionsNC(g,
   InverseMonoid(List(GeneratorsOfGroup(g), p-> AsPartialPerm(p, dom))), 
   p-> AsPartialPerm(p, dom), f-> AsPermutation(f));
end);

#

InstallMethod(IsomorphismPartialPermSemigroup, "for a perm group",
[IsPermGroup],
function(g)
  local dom;
  dom:=MovedPoints(g);
  return MagmaIsomorphismByFunctionsNC(g,
   InverseSemigroup(List(GeneratorsOfGroup(g), p-> AsPartialPerm(p, dom))), 
   p-> AsPartialPerm(p, dom), f-> AsPermutation(f));
end);

#

InstallMethod(IsomorphismPartialPermSemigroup, "for a partial perm semigroup",
[IsPartialPermSemigroup],
function(S)
  return MagmaIsomorphismByFunctionsNC(S, S, IdFunc, IdFunc);
end);

#

InstallMethod(IsomorphismPartialPermMonoid, "for a partial perm monoid", 
[IsPartialPermMonoid], 
function(s)
  return MagmaIsomorphismByFunctionsNC(s, s, IdFunc, IdFunc);
end);

#

InstallMethod(IsomorphismPartialPermMonoid, 
"for a partial perm semigroup",
[IsPartialPermSemigroup],
function(s)
  local t;

  if IsInverseSemigroup(s) then 
    t:=AsInverseMonoid(s);
  else 
    t:=AsMonoid(s);
  fi;
  if t=fail then 
    return fail;
  fi;
  return MagmaIsomorphismByFunctionsNC(s, t, IdFunc, IdFunc); 
end);

#

InstallMethod(SymmetricInverseSemigroup, "for a integer",
[IsInt],
function(n)
  local s;

  if n<0 then
    Error("usage: the argument should be a non-negative integer,");
    return;
  elif n=0 then
    s:=InverseMonoid(PartialPermNC([]));
  elif n=1 then
    s:=InverseMonoid(PartialPermNC([1]), PartialPermNC([]));
  elif n=2 then
    s:=InverseMonoid(PartialPermNC([2,1]), PartialPermNC([1]));;
  else
    s:=InverseMonoid(List(GeneratorsOfGroup(SymmetricGroup(n)), x->
     PartialPermNC(ListPerm(x, n))), PartialPermNC([0..n-1]*1));
  fi;

  SetIsSymmetricInverseSemigroup(s, true);
  return s;
end);

#

InstallMethod(ViewString, "for a symmetric inverse semigroup",
[IsSymmetricInverseSemigroup and IsPartialPermSemigroup], 
function(s)
  return STRINGIFY("<symmetric inverse semigroup on ",
   DegreeOfPartialPermSemigroup(s), " pts>");
end);

#InstallMethod(IsSymmetricInverseSemigroup, 
#"for a semigroup", [IsSemigroup], ReturnFalse);

#

InstallMethod(IsSymmetricInverseSemigroup,
"for a partial perm semigroup with generators",
[IsPartialPermSemigroup and HasGeneratorsOfSemigroup],
function(s)
  return ForAll(GeneratorsOfSemigroup(
   SymmetricInverseSemigroup(DegreeOfPartialPermSemigroup(s))),
    x-> x in s);
end);

#

InstallMethod(NaturalPartialOrder, 
"for an inverse partial perm semigroup",
[IsPartialPermSemigroup and IsInverseSemigroup],
function(s)
  local elts, p, n, out, i, j;

  elts:=ShallowCopy(Elements(s));  
  p:=Sortex(elts, ShortLexLeqPartialPerm)^-1; 
  n:=Length(elts);
  out:=List([1..n], x-> []);
  for i in [n, n-1..2] do
    for j in [i-1,i-2 ..1] do
      if NaturalLeqPartialPerm(elts[j], elts[i]) then
        AddSet(out[i], j);
      fi;
    od;
  od;
  Perform(out, ShrinkAllocationPlist);
  Apply(out, x-> OnSets(x, p));
  return Permuted(out, p);
end);

#

InstallMethod(ReverseNaturalPartialOrder, 
"for an inverse partial perm semigroup",
[IsPartialPermSemigroup and IsInverseSemigroup],
function(s)
  local elts, p, n, out, i, j;

  elts:=ShallowCopy(Elements(s));  
  p:=Sortex(elts, ShortLexLeqPartialPerm)^-1; 
  n:=Length(elts);
  out:=List([1..n], x-> []);
  for i in [1..n-1] do
    for j in [i+1..n] do
      if NaturalLeqPartialPerm(elts[i], elts[j]) then
        AddSet(out[i], j);
      fi;
    od;
  od;
  Perform(out, ShrinkAllocationPlist);
  Apply(out, x-> OnSets(x, p));
  return Permuted(out, p);
end);