CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<!-- This is an automatically generated file. -->
4
<Chapter Label="Chapter_Add_Functions">
5
<Heading>Add Functions</Heading>
6
7
<P/>
8
This section describes the overall structure of Add-functions and the functions installed by them.
9
<P/>
10
<Section Label="Chapter_Add_Functions_Section_Functions_Installed_by_Add">
11
<Heading>Functions Installed by Add</Heading>
12
13
<P/>
14
Add functions (up to some exceptions) have the following syntax
15
<P/>
16
DeclareOperation( "AddSomeFunc",
17
[ IsCapCategory, IsList, IsInt ] );
18
<P/>
19
The first argument is the category to which some function (e.g. KernelObject)
20
is added, the second is a list containing pairs of functions and additional
21
filters for the arguments, (e.g. if one argument is a morphism, an additional filter could be IsMomomorphism).
22
The third is a weight which will then be the weight for SomeFunc. This is described later.
23
If only one function is to be installed, the list can be replaced by the function.
24
Via InstallMethod, CAP installs the given function(s) as methods for the install name of SomeFunc,
25
as listed in the MethodRecord. If no install name is given, the name SomeFunc is used.
26
<P/>
27
All installed methods follow the following steps, described below:
28
<List>
29
<Item>
30
Redirect function
31
</Item>
32
<Item>
33
Prefunction
34
</Item>
35
<Item>
36
Function
37
</Item>
38
<Item>
39
Logic
40
</Item>
41
<Item>
42
Postfunction
43
</Item>
44
<Item>
45
Addfunction
46
</Item>
47
</List>
48
<P/>
49
Every other part, except from function, does only depend on the name SomeFunc. We now explain the steps in detail.
50
<P/>
51
<List>
52
<Item>
53
Redirect function: The redirect is used to redirect the computation from the given functions to some other symbol.
54
If there is for example a with given method for some universal property, and the universal object is already computed,
55
the redirect function might detect such a thing, calls the with given operation with the universal object as additional
56
argument and then returns the value. In general, the redirect can be an arbitrary function. It is called with the same
57
arguments as the operation SomeFunc itself and can return an array containing [ true, something ], which will cause
58
the installed method to simply return the object something, or [ false ]. If the output is false, the computation will
59
continue with the step Prefunction. Additionally, for every category and every name like SomeFunc, there is a boolean,
60
stored in the categorys redirects component under the name of SomeFunc, which, when it is false, will prevent the
61
redirect function from being executed.
62
</Item>
63
</List>
64
<P/>
65
<List>
66
<Item>
67
Prefunction: The prefunction should be used for error handling and soft checks of the sanity of the input to SomeFunc
68
(e.g. for KernelLift it should check wether range and source of the morphims coincide). Generally, the prefunction is defined
69
in the method record and only depend on the name SomeFunc. It is called with the same input as the function itself, and
70
should return either [ true ], which continues the computation, or [ false, "message" ], which will cause an error with
71
message "message" and some additional information.
72
</Item>
73
</List>
74
<P/>
75
<List>
76
<Item>
77
Function: This will launch the function(s) given as arguments. The result should be as specified in the type of
78
SomeFunc. The resulting object is now named the result.
79
</Item>
80
</List>
81
<P/>
82
<List>
83
<Item>
84
Logic: For every function, some logical todos can be implemented in a logic texfile for the category. If there is
85
some logic written down in a file belonging to the category, or belonging to some type of category. Please see the
86
description of logic for more details. If there is some logic and some predicate relations for the function SomeFunc,
87
it is installed in this step for the result.
88
</Item>
89
</List>
90
<P/>
91
<List>
92
<Item>
93
Postfunction: The postfunction called with the arguments of the function and the result. It can be an arbitrary function doing
94
some cosmetics. If for example SomeFunc is KernelEmbeddingedding, it will set the KernelObject of the input morphism to result.
95
The postfunction is also taken from the method record and does only depend on the name SomeFunc.
96
</Item>
97
</List>
98
<P/>
99
<List>
100
<Item>
101
Addfunction: If the result is a category cell, it is added to the category for which the function was installed.
102
</Item>
103
</List>
104
<P/>
105
</Section>
106
107
108
<Section Label="Chapter_Add_Functions_Section_Add_Method">
109
<Heading>Add Method</Heading>
110
111
<P/>
112
Except from installing a new method for the name SomeFunc, an Add method does slightly more.
113
Every Add method has the same structure. The steps in the Add method are as follows:
114
<P/>
115
<List>
116
<Item>
117
Weight check: If the current weight of the operation is lower than the given weight of the new functions,
118
then the add function returns and installs nothing.
119
</Item>
120
</List>
121
<P/>
122
<List>
123
<Item>
124
Option check: There are two possible options for every add method: SetPrimitive and IsDerivation.
125
<List>
126
<Item>
127
SetPrimitive should be a boolean, the default is true. If SetPrimitive is false, then the
128
current call of this add will not set the installed function to be primitive. This is used for derivations.
129
</Item>
130
<Item>
131
IsDerivation should be a boolean, default is false. If it is true, the add method assumes that the given
132
function is a derivation and does not try to install a corresponding pair (See below).
133
</Item>
134
</List>
135
</Item>
136
</List>
137
<P/>
138
<List>
139
<Item>
140
Standard weight: If the weight parameter is -1, the Standard weight is assumed, which is 100.
141
</Item>
142
</List>
143
<P/>
144
<List>
145
<Item>
146
Checking for pairs: If the function is not a with given operation, has a corresponding with given or is a with given,
147
and is newly installed, i.e. the current installation weight which is given to the add function
148
is less than the current weight, the add method is going to install a corresponding pair function,
149
i.e. a function for the corresponding with or without given method, which redirects to the currently
150
installed functions. It also deactivates the redirect for this function.
151
Note that the pair install is only done for primitive functions, and if the current weight is
152
higher than the given weight.
153
</Item>
154
</List>
155
<P/>
156
<List>
157
<Item>
158
Can compute: Set the corresponding can compute of the category to true
159
</Item>
160
</List>
161
<P/>
162
<List>
163
<Item>
164
Install methods: Decide on the methods used to install the function. Check wether InstallMethodWithCache, InstallMethodWithToDoForIsWellDefined,
165
both, or simply InstallMethod is used. This is decided by the ToDo and the caching flags.
166
</Item>
167
</List>
168
<P/>
169
<List>
170
<Item>
171
Installation: Next, the method to install the functions is created. It creates the correct filter list, by merging the standard filters
172
for the operation with the particular filters for the given functions, then installs the method as described above.
173
</Item>
174
</List>
175
<P/>
176
<List>
177
<Item>
178
SetPrimitive: If the set primitive flag is true, it is set as primitive in the weight list of the category.
179
</Item>
180
</List>
181
<P/>
182
<List>
183
<Item>
184
Pair install: If there is a function pair, as described above, it is installed.
185
</Item>
186
</List>
187
<P/>
188
After calling an add method, the corresponding Operation is availible in the category. Also, some derivations, which are triggered by the setting
189
of the primitive value, might be availible.
190
<P/>
191
</Section>
192
193
194
<Section Label="Chapter_Add_Functions_Section_InstallAdd_Function">
195
<Heading>InstallAdd Function</Heading>
196
197
<P/>
198
Almost all Add methods in the CAP kernel are installed by the CapInternalInstallAdd operation.
199
The definition of this function is as follows:
200
<P/>
201
DeclareOperation( "CapInternalInstallAdd",
202
[ IsRecord ] );
203
<P/>
204
The record can have the following components, used as described:
205
<P/>
206
<List>
207
<Item>
208
function_name: The name of the function. This does not have to coincide with the installation name. It is used for the derivation weight.
209
</Item>
210
</List>
211
<P/>
212
<List>
213
<Item>
214
installation_name (optional): A string which is the name of the operation for which the
215
functions given to the Add method are installed as methods.
216
</Item>
217
</List>
218
<P/>
219
<List>
220
<Item>
221
pre_function (optional): A function which is used as the prefunction of the installed methods, as described above.
222
</Item>
223
</List>
224
<P/>
225
<List>
226
<Item>
227
redirect_function (optional): A function which is used as the redirect function of the installed methods, as described above.
228
</Item>
229
</List>
230
<P/>
231
<List>
232
<Item>
233
post_function (optional): A function which is used as the postfunction of the installed methods, as described above.
234
</Item>
235
</List>
236
<P/>
237
<List>
238
<Item>
239
filter_list: A list containing the basic filters for the methods installed by the add methods. Possible are filters, or
240
the strings category, object, morphism, or twocell, which will then be replaced at the time the add method is
241
called with the corresponding filters of the category.
242
</Item>
243
</List>
244
<P/>
245
<List>
246
<Item>
247
well_defined_todo (optional): A boolean, default value is true, which states wether there should be to do list entries
248
which propagate well definedness from the input of the installed methods to their output.
249
Please note that true only makes sense if at least one argument and the output of the
250
installed method is a cell.
251
</Item>
252
</List>
253
<P/>
254
<List>
255
<Item>
256
cache_name (optional): The name of the cache which is used for the installed methods. If no cache name is given, the caching
257
for the operation is deactivated completely.
258
</Item>
259
</List>
260
<P/>
261
<List>
262
<Item>
263
argument_list (optional): A list containing integers, which defines which arguments should be used for the additional functions, (e.g redirect, pre, ...).
264
This is important for the Op method contructions. If no argument list is given, all arguments are used.
265
Please note that if you have a method selection argument for your function, you need to give the argument_list
266
to explicitly state which argument is the method selection argument.
267
</Item>
268
</List>
269
<P/>
270
<List>
271
<Item>
272
return_type (optional): The return type can be object, morphism, or twocell. If it is one of those, the correct add function (see above) is
273
used for the result of the computation. Otherwise, no add function is used after all.
274
</Item>
275
</List>
276
<P/>
277
<List>
278
<Item>
279
is_with_given: Boolean, marks wether the function which is to be installed a with given function or not.
280
</Item>
281
</List>
282
<P/>
283
<List>
284
<Item>
285
with_given_without_given_name_pair (optional): If the currently installed operation has a corresponding with given operation or
286
is the with given of another operation, the names of both should be in this list.
287
</Item>
288
</List>
289
<P/>
290
<List>
291
<Item>
292
functorial (optional): If an object has a corresponding functorial function, e.g., KernelObject and KernelObjectFunctorial,
293
the name of the functorial is stored as a string.
294
</Item>
295
</List>
296
<P/>
297
Using all those entries, the operation CapInternalInstallAdd installs add methods as described above. It first provides a
298
sanity check for all the entries described, then installs the Add method in 4 ways, with list or functions as second argument, and
299
with an optional third parameter for the weight.
300
<P/>
301
</Section>
302
303
304
<Section Label="Chapter_Add_Functions_Section_Install_All_Adds">
305
<Heading>Install All Adds</Heading>
306
307
<P/>
308
The function CAP_INTERNAL_INSTALL_ALL_ADDS does not take any arguments, it is an auxiliary function which iterates over the
309
CAP_INTERNAL_METHOD_NAME_RECORD and calls, after some cosmetics, the CapInternalInstallAdd with the corresponding method record entry.
310
The steps below are performed for every entry of the method record:
311
<P/>
312
<List>
313
<Item>
314
No install check: If the no_install component in the record is set to true, the loop continues with the next
315
entry, since this flag indicates that there should be no add function for this operation.
316
</Item>
317
</List>
318
<P/>
319
<List>
320
<Item>
321
Cache check: If there is no cache_name, set it to the name of the method record entry.
322
</Item>
323
</List>
324
<P/>
325
<List>
326
<Item>
327
Function name: Set the component function_name to the entry name.
328
</Item>
329
</List>
330
<P/>
331
<List>
332
<Item>
333
Redirect: Since the redirect function needs the category to work correctly, the given redirects in the method records are
334
packed up to discard the last argument, which is the category.
335
</Item>
336
</List>
337
<P/>
338
<List>
339
<Item>
340
arg_list: Next, an argument list for redirect and post function is created, by looking at the filter list in the record.
341
If the first one is a list, the first and the last (method selection argument) is used, otherwise only the first.
342
</Item>
343
</List>
344
<P/>
345
<List>
346
<Item>
347
WithGiven special case: If the current entry belongs to a WithGiven operation, the with_given_without_given_name_pair is set,
348
the with given flag is set to true, and the CapInternalInstallAdd is called with the record. The loop
349
then continues.
350
</Item>
351
</List>
352
<P/>
353
<List>
354
<Item>
355
Non universal object special case: If the Operation does not have a universal type, i.e. does not belong to a universal
356
construction, CapInternalInstallAdd is called with the record. The loop then continues.
357
</Item>
358
</List>
359
<P/>
360
Please note that we are now in the case where the operation belongs to a universal construction, (e.g. KernelLift) and is not
361
a WithGiven type of operation.
362
<P/>
363
<List>
364
<Item>
365
argument_list: If the method is an Op construction, i.e. has a method selection object, the argument list is set to all but the
366
last object and then used as above. Otherwise, the argument_list is set to all arguments.
367
</Item>
368
</List>
369
<P/>
370
<List>
371
<Item>
372
If the Operation constructs a universal object, the postfunction is created and then CapInternalInstallAdd is called.
373
</Item>
374
</List>
375
<P/>
376
<List>
377
<Item>
378
If the Operation constructs a universal morphism, the redirect is created and stored in the record.
379
Also, the postfunction is created. Then CapInternalInstallAdd is called.
380
</Item>
381
</List>
382
<P/>
383
After one call of this function, all add methods are installed correctly. A second call should not do anything.
384
<P/>
385
</Section>
386
387
388
</Chapter>
389
390
391