This file is indexed.

/usr/share/gap/lib/mgmadj.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  mgmadj.gi                    GAP library                  Andrew Solomon
##
##
#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 magmas with zero adjoined.
##


#############################################################################
##
#M  IsMultiplicativeZero( <M>, <elt> )
##
InstallMethod( IsMultiplicativeZero,
    "generic method for an element and a magma with multiplicative zero",
    IsCollsElms,
    [ IsMagma and HasMultiplicativeZero, IsMultiplicativeElement], 0,
function( M, z )
	return z = MultiplicativeZero(M);
end);

InstallMethod( IsMultiplicativeZero,
    "generic method for an element and a magma",
    IsCollsElms,
    [ IsMagma, IsMultiplicativeElement], 0,
function( M,z  )
	local x,i,en;

	i := 1;
	en := Enumerator(M);
	while IsBound(en[i]) do
		x := en[i];
		if x*z <> z or z*x <> z then	
			return false;
		fi;
		i := i +1;
	od;
	SetMultiplicativeZero(M,Immutable(z));
	return true;
end);

#############################################################################
##
#M  IsMultiplicativeZero( <M>, <elt> )
##
InstallMethod( IsMultiplicativeZero,
	"generic method for an element of a semigroup, given generators",
	IsCollsElms, [IsSemigroup and HasGeneratorsOfSemigroup, 
					IsMultiplicativeElement], 0,
function(S, z)
	if ForAll(GeneratorsOfSemigroup(S), x->x*z=z and z*x=z) then
		SetMultiplicativeZero(S, Immutable(z));
		return true;
	fi;
	return false;
end);

############################################################################
##
#R  IsMagmaWithMultiplicativeZeroAdjoinedElementRep(<obj>)
##
##  Representation of an element of this type is as record which 
##  has a field "IsTheZero" and another, "UnderlyingElement" which
##  has a value in case "IsTheZero" is false.
##
DeclareRepresentation("IsMagmaWithMultiplicativeZeroAdjoinedElementRep", 
	IsComponentObjectRep and IsMultiplicativeElementWithZero,
	["IsTheZero", "UnderlyingElement"]);


#############################################################################
##
#M  OneOp( <elm> )  
##
InstallMethod( OneOp,
    "for an element of a magma with zero adjoined",
    true,
    [ IsMultiplicativeElementWithOne  and 
		IsMagmaWithMultiplicativeZeroAdjoinedElementRep], 0,
function( elm )
	# has to be created "by hand" so to speak, since the family
	# won't necessarily have the homomorphism to hand when it is created.
	return Objectify(TypeObj(elm), rec( IsTheZero:= false, 
					UnderlyingElement := One(FamilyObj(elm)!.underlyingMagma)));
end );

#############################################################################
##
#M  MultiplicativeZeroOp( <elm> )
##
##  This is a shortcut - the family of elements is the same as the 
##  elements of the magma. It is really the *magma's* zero.
##
InstallMethod( MultiplicativeZeroOp,
    "for an element of a magma with zero adjoined",
    true,
    [ IsMagmaWithMultiplicativeZeroAdjoinedElementRep], 0,
function( elm )
    return FamilyObj(elm)!.zero;
end );


#############################################################################
##
#M  MultiplicativeZero( <M> )
##
InstallOtherMethod( MultiplicativeZero,
    "for a magma",
    true,
    [ IsMagma ], 0,
function( M )
		local en, i;

		en := Enumerator(M);
		i := 1;
		while (IsBound(en[i])) do
			if IsMultiplicativeZero(M, en[i]) then
				return en[i];
			fi;
			i := i +1;
		od;
		return fail;
end );



#############################################################################
##
#A  InjectionZeroMagma( <M> )
##  
##  The canonical homomorphism from the 
##  <M> into the magma formed from <M> with a single new element
##  which is a multiplicative zero for the resulting magma.
##  
##  In order to be able to define multiplication, the elements of the
##  new magma must be in  a new family.
##
InstallMethod(InjectionZeroMagma, 
    "method for a magma",
    true,
    [IsMagma], 0,
function(M)

	local
				Fam, Typ, 	# the new family and type
				z, 					# the new zero
				ZM,					# the new magma
				ZMgens,			# generators of the new magma
				filters,		# the new elements family's filters
				coerce;			# coerce an element of the base magma into the zero magma


  # Putting IsMultiplicativeElement in the NewFamily means that when you make,
  # say [a] it picks up the Category from the Family object and makes
  # sure that [a] has CollectionsCategory(IsMultiplicativeElement)

	# Preserve all sensible properties
	filters := IsMultiplicativeElementWithZero;

	if IsMultiplicativeElementWithOne(Representative(M)) then
		filters := filters and IsMultiplicativeElementWithOne;
	fi;

	if IsAssociativeElement(Representative(M)) then
		filters := filters and IsAssociativeElement;
	fi;

  Fam := NewFamily( "TypeOfElementOfMagmaWithZeroAdjoined", filters);
	Fam!.underlyingMagma := Immutable(M);

	# put n in the type data so that we can find the position in the database
	# without a search
	Typ := NewType(Fam, filters and 
			IsMagmaWithMultiplicativeZeroAdjoinedElementRep);

	
	coerce :=  g->Objectify(Typ, 
		rec( IsTheZero:= false, UnderlyingElement := g));

	# Now create the new magma and its zero element
	z := Objectify(Typ, rec( IsTheZero:= true ) );

	if Length(GeneratorsOfMagma(M))=0 then
		# ZM := Magma(CollectionsFamily(Fam),[]);
		Error("Can't adjoin a zero to a Magma without generators");
	fi;

	# make the list of generators into generators of ZM

	ZMgens := List(GeneratorsOfMagma(M), g->coerce(g));

	if IsSemigroup(M) then
		if IsMonoid(M) then
			# need to supply the identity as second argument
			ZM :=  MonoidByGenerators(Concatenation(ZMgens, [z]));
		else
			ZM :=  Semigroup(Concatenation(ZMgens, [z]));
		fi;
	else
		ZM :=  Magma(Concatenation(ZMgens, [z]));
	fi;

	if IsGroup(M) then
		SetIsZeroGroup(ZM,true);
	fi;

	SetMultiplicativeZero(ZM,z);

	Fam!.injection := Immutable(MagmaHomomorphismByFunctionNC(M, ZM, coerce));
	Fam!.zero := Immutable(z);
	return Fam!.injection;
end);

#############################################################################
##
#M  Size( <S> ) 
##
InstallMethod( Size,
    "method for a magma with a zero adjoined",
    true,
    [ IsMagma and HasMultiplicativeZero ], 0,
    function(s)
      local sizeofs,m,fam,z;

			# if the magma has a zero, but it is not a magma with
			# a zero adjoined then this method does not apply
			z := MultiplicativeZero( s );
			if not( IsMagmaWithMultiplicativeZeroAdjoinedElementRep( z ) ) then
				TryNextMethod();
			fi; 

			# get the magma underlying s		
			fam := ElementsFamily( FamilyObj (s ) );
			m := fam!.underlyingMagma;
	
      sizeofs:=Size(m) + 1;

      return sizeofs;
    end);

#############################################################################
##
#M  <elm> * <elm>
##
##  returns the product of two elements of a magma with a zero adjoined
InstallMethod( \*,
    "for two elements of a magma with zero adjoined",
    IsIdenticalObj,
    [ IsMagmaWithMultiplicativeZeroAdjoinedElementRep, 
			IsMagmaWithMultiplicativeZeroAdjoinedElementRep ], 0,
function ( elm1, elm2 )

	if elm1!.IsTheZero or elm2!.IsTheZero then	
		return MultiplicativeZeroOp(elm1);
	else
		# compute the product in the underlying magma and then
		# inject back into the zeromagma
		return (elm1!.UnderlyingElement * elm2!.UnderlyingElement)^ 
				(FamilyObj(elm1)!.injection);
	fi;
		
end );



#############################################################################
##
#M  <elm> = <elm>
##
##  decides equality of two elements of a magma with zero adjoined
##
InstallMethod( \=,
    "for two elements of a magma with zero adjoined",
    IsIdenticalObj,
    [ IsMagmaWithMultiplicativeZeroAdjoinedElementRep, 
			IsMagmaWithMultiplicativeZeroAdjoinedElementRep ], 0,
function ( elm1, elm2 )

	if elm1!.IsTheZero and elm2!.IsTheZero then	
		return true;
	elif elm1!.IsTheZero or elm2!.IsTheZero  then 
		# only one is zero
		return false;
	else
		# compute in the underlying magma 
		return (elm1!.UnderlyingElement = elm2!.UnderlyingElement);
	fi;
		
end );

############################################################################
##
#M  <eltz> < <eltz> .. for magma with a zero adjoined
##
##  Ordering of the underlying magma with zero less than everything else
## 

InstallMethod(\<, 
"for elements of magmas with 0 adjoined", 
IsIdenticalObj,
[ IsMagmaWithMultiplicativeZeroAdjoinedElementRep, 
IsMagmaWithMultiplicativeZeroAdjoinedElementRep ], 0,
function ( elm1, elm2 )

	if elm1!.IsTheZero and elm2!.IsTheZero then						# 0 0 
		return false;
	elif elm2!.IsTheZero then 														# 1 0
		return false;
	elif elm1!.IsTheZero and not(elm2!.IsTheZero)  then 	# 0 1
		return true;
	else
		# compute in the underlying magma 
		return (elm1!.UnderlyingElement < elm2!.UnderlyingElement);
	fi;
		
end );

############################################################################
##
#A  Print(<elz>)
##
##  Print the element 
##

InstallMethod(PrintObj, "for elements of magmas with 0 adjoined", true,
[IsMagmaWithMultiplicativeZeroAdjoinedElementRep], 0, 
function(x) 
				if x!.IsTheZero then
					Print("0");
				else
					Print(x!.UnderlyingElement);
				fi;
end);


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