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_Managing_Derived_Methods">
5
<Heading>Managing Derived Methods</Heading>
6
7
<P/>
8
<Section Label="Chapter_Managing_Derived_Methods_Section_Info_Class">
9
<Heading>Info Class</Heading>
10
11
<ManSection>
12
<InfoClass Name="DerivationInfo" />
13
<Description>
14
Info class for derivations.
15
</Description>
16
</ManSection>
17
18
19
<P/>
20
<ManSection>
21
<Func Arg="arg" Name="ActivateDerivationInfo" />
22
<Description>
23
<P/>
24
</Description>
25
</ManSection>
26
27
28
<P/>
29
<ManSection>
30
<Func Arg="arg" Name="DeactivateDerivationInfo" />
31
<Description>
32
<P/>
33
</Description>
34
</ManSection>
35
36
37
</Section>
38
39
40
<Section Label="Chapter_Managing_Derived_Methods_Section_Derivation_Objects">
41
<Heading>Derivation Objects</Heading>
42
43
<ManSection>
44
<Filt Arg="arg" Name="IsDerivedMethod" Label="for IsObject"/>
45
<Returns><C>true</C> or <C>false</C>
46
</Returns>
47
<Description>
48
A derivation object describes a derived method.
49
It contains information about which operation the derived method
50
implements, and which other operations it relies on.
51
</Description>
52
</ManSection>
53
54
55
<ManSection>
56
<Oper Arg="name, target_op, used_ops_with_multiples, weight, implementations_with_extra_filters, category_filter" Name="MakeDerivation" Label="for IsString, IsFunction, IsDenseList,IsPosInt, IsDenseList, IsFunction"/>
57
<Description>
58
Creates a new derivation object.
59
The argument <A>name</A> is an arbitrary name used to
60
identify this derivation, and is useful only for debugging
61
purposes.
62
The argument <A>target_op</A> is the operation which
63
the derived method implements.
64
The argument <A>used_ops_with_multiples</A> contains each
65
operation used by the derived method, together with a positive
66
integer specifying how many times that operation is used.
67
This is given as a list of lists, where each sublist has as
68
first entry an operation and as second entry an integer.
69
The argument <A>weight</A> is an additional number to add
70
when calculating the resulting weight of the target operation
71
using this derivation. Unless there is any particular reason
72
to regard the derivation as exceedingly expensive, this number
73
should be <C>1</C>.
74
The argument <A>implementations_with_extra_filters</A> contains
75
one or more functions with the actual implementation of the
76
derived method, together with lists of extra argument filters
77
for each function. The argument is a list with entries of the
78
form <C>[fun, filters]</C>, where <C>fun</C> is a function and
79
<C>filters</C> is a (not necessarily dense) list of argument
80
filters. If only one function is given, then <C>filters</C>
81
should be the empty list; in this case the argument's value
82
would be [[fun,[]]], where <C>fun</C> is the function.
83
The argument <A>category_filter</A> is a filter describing
84
which categories the derivation is valid for. If it is valid
85
for all categories, then this argument should have the value
86
<C>IsCapCategory</C>.
87
</Description>
88
</ManSection>
89
90
91
<ManSection>
92
<Attr Arg="d" Name="DerivationName" Label="for IsDerivedMethod"/>
93
<Description>
94
The name of the derivation. This is a name identifying this
95
particular derivation, and normally not the same as the name
96
of the operation implemented by the derivation.
97
</Description>
98
</ManSection>
99
100
101
<ManSection>
102
<Attr Arg="d" Name="DerivationWeight" Label="for IsDerivedMethod"/>
103
<Description>
104
Extra weight for the derivation.
105
</Description>
106
</ManSection>
107
108
109
<ManSection>
110
<Attr Arg="d" Name="DerivationFunctionsWithExtraFilters" Label="for IsDerivedMethod"/>
111
<Description>
112
The implementation(s) of the derivation, together with lists
113
of extra filters for each implementation.
114
</Description>
115
</ManSection>
116
117
118
<ManSection>
119
<Attr Arg="d" Name="CategoryFilter" Label="for IsDerivedMethod"/>
120
<Description>
121
Filter describing which categories the derivation is valid for.
122
</Description>
123
</ManSection>
124
125
126
<ManSection>
127
<Oper Arg="d, C" Name="IsApplicableToCategory" Label="for IsDerivedMethod, IsCapCategory"/>
128
<Returns><C>true</C> if the category <A>C</A> is known to satisfy the category filter of the derivation <A>d</A>.
129
</Returns>
130
<Description>
131
Checks if the derivation is known to be valid for a given category.
132
</Description>
133
</ManSection>
134
135
136
<ManSection>
137
<Attr Arg="d" Name="TargetOperation" Label="for IsDerivedMethod"/>
138
<Returns>The name (as a string) of the operation implemented by the derivation <A>d</A>
139
</Returns>
140
<Description>
141
<P/>
142
</Description>
143
</ManSection>
144
145
146
<ManSection>
147
<Attr Arg="d" Name="UsedOperations" Label="for IsDerivedMethod"/>
148
<Returns>The names (as strings) of the operations used by the derivation <A>d</A>
149
</Returns>
150
<Description>
151
<P/>
152
</Description>
153
</ManSection>
154
155
156
<ManSection>
157
<Attr Arg="d" Name="UsedOperationMultiples" Label="for IsDerivedMethod"/>
158
<Returns>Multiplicities of each operation used by the derivation <A>d</A>, in order corresponding to the operation names returned by <C>UsedOperations(d)</C>.
159
</Returns>
160
<Description>
161
<P/>
162
</Description>
163
</ManSection>
164
165
166
<ManSection>
167
<Attr Arg="d" Name="UsedOperationsWithMultiples" Label="for IsDerivedMethod"/>
168
<Returns>The names of the operations used by the derivation <A>d</A>, together with their multiplicities. The result is a list consisting of lists of the form <C>[op_name, mult]</C>, where <C>op_name</C> is a string and <C>mult</C> a positive integer.
169
</Returns>
170
<Description>
171
<P/>
172
</Description>
173
</ManSection>
174
175
176
<ManSection>
177
<Oper Arg="d, weight, C" Name="InstallDerivationForCategory" Label="for IsDerivedMethod, IsPosInt, IsCapCategory"/>
178
<Description>
179
Install the derived method <A>d</A> for the category <A>C</A>.
180
The integer <A>weight</A> is the computed weight of the operation
181
implemented by this derivation.
182
</Description>
183
</ManSection>
184
185
186
<ManSection>
187
<Oper Arg="d, op_weights" Name="DerivationResultWeight" Label="for IsDerivedMethod, IsDenseList"/>
188
<Description>
189
Computes the resulting weight of the target operation of this
190
derivation given a list of weights for the operations it uses.
191
The argument <A>op_weights</A> should be a list of integers
192
specifying weights for the operations given by
193
<C>UsedOperations( d )</C>, in the same order.
194
</Description>
195
</ManSection>
196
197
198
</Section>
199
200
201
<Section Label="Chapter_Managing_Derived_Methods_Section_Derivation_Graphs">
202
<Heading>Derivation Graphs</Heading>
203
204
<ManSection>
205
<Filt Arg="arg" Name="IsDerivedMethodGraph" Label="for IsObject"/>
206
<Returns><C>true</C> or <C>false</C>
207
</Returns>
208
<Description>
209
A derivation graph consists of a set of operations and a set of derivations
210
specifying how some operations can be implemented in terms of other operations.
211
</Description>
212
</ManSection>
213
214
215
<ManSection>
216
<Oper Arg="operations" Name="MakeDerivationGraph" Label="for IsDenseList"/>
217
<Description>
218
Make a derivation graph containing the given set of operations and no derivations.
219
The argument <A>operations</A> should be a list of strings, the names of the
220
operations. The set of operations is fixed once the graph is created.
221
Derivations can be added to the graph by calling <C>AddDerivation</C>.
222
</Description>
223
</ManSection>
224
225
226
<ManSection>
227
<Oper Arg="graph, operations" Name="AddOperationsToDerivationGraph" Label="for IsDerivedMethodGraph, IsDenseList"/>
228
<Description>
229
Adds a list of operation names <A>operations</A> to a given derivation graph <A>graph</A>.
230
This is used in extensions of CAP which want to have their own primitive operations,
231
but do not want to pollute the CAP kernel any more. Please use it with caution. If
232
a weight list/category was created before it will not be aware of the operations.
233
</Description>
234
</ManSection>
235
236
237
<ManSection>
238
<Oper Arg="G, d" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsDerivedMethod"/>
239
<Description>
240
Add a derivation to a derivation graph.
241
</Description>
242
</ManSection>
243
244
245
<P/>
246
<ManSection>
247
<Oper Arg="arg1,arg2,arg3,arg4" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsFunction, IsDenseList, IsObject"/>
248
<Description>
249
<P/>
250
</Description>
251
</ManSection>
252
253
254
<P/>
255
<ManSection>
256
<Oper Arg="arg1,arg2,arg3" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsFunction, IsDenseList"/>
257
<Description>
258
<P/>
259
</Description>
260
</ManSection>
261
262
263
<P/>
264
<ManSection>
265
<Oper Arg="arg1,arg2,arg3" Name="AddDerivation" Label="for IsDerivedMethodGraph, IsFunction, IsFunction"/>
266
<Description>
267
<P/>
268
</Description>
269
</ManSection>
270
271
272
<P/>
273
<ManSection>
274
<Oper Arg="arg1,arg2,arg3,arg4,arg5,arg6" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsDenseList, IsDenseList, IsDenseList"/>
275
<Description>
276
<P/>
277
</Description>
278
</ManSection>
279
280
281
<ManSection>
282
<Oper Arg="arg1,arg2,arg3,arg4,arg5" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsDenseList, IsDenseList"/>
283
<Description>
284
<P/>
285
</Description>
286
</ManSection>
287
288
289
<ManSection>
290
<Oper Arg="arg1,arg2,arg3,arg4,arg5,arg6" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsDenseList, IsFunction, IsFunction"/>
291
<Description>
292
<P/>
293
</Description>
294
</ManSection>
295
296
297
<ManSection>
298
<Oper Arg="arg1,arg2,arg3,arg4,arg5" Name="AddDerivationPair" Label="for IsDerivedMethodGraph, IsFunction, IsFunction, IsFunction, IsFunction"/>
299
<Description>
300
<P/>
301
</Description>
302
</ManSection>
303
304
305
<P/>
306
<ManSection>
307
<Func Arg="arg" Name="AddDerivationToCAP" />
308
<Description>
309
<P/>
310
</Description>
311
</ManSection>
312
313
314
<P/>
315
<ManSection>
316
<Func Arg="arg" Name="AddDerivationPairToCAP" />
317
<Description>
318
<P/>
319
</Description>
320
</ManSection>
321
322
323
<P/>
324
<ManSection>
325
<Func Arg="arg" Name="AddWithGivenDerivationPairToCAP" />
326
<Description>
327
<P/>
328
</Description>
329
</ManSection>
330
331
332
<ManSection>
333
<Attr Arg="G" Name="Operations" Label="for IsDerivedMethodGraph"/>
334
<Description>
335
Gives the operations in the graph <A>G</A>, as a list of strings.
336
</Description>
337
</ManSection>
338
339
340
<ManSection>
341
<Oper Arg="G, op_name" Name="DerivationsUsingOperation" Label="for IsDerivedMethodGraph, IsString"/>
342
<Description>
343
Finds all the derivations in the graph <A>G</A> that use the operation named
344
<A>op_name</A>, and returns them as a list.
345
</Description>
346
</ManSection>
347
348
349
<ManSection>
350
<Oper Arg="G, op_name" Name="DerivationsOfOperation" Label="for IsDerivedMethodGraph, IsString"/>
351
<Description>
352
Finds all the derivations in the graph <A>G</A> targeting the operation named
353
<A>op_name</A> (that is, the derivations that provide implementations of this
354
operation), and returns them as a list.
355
</Description>
356
</ManSection>
357
358
359
</Section>
360
361
362
<Section Label="Chapter_Managing_Derived_Methods_Section_Managing_Derivations_in_a_Category">
363
<Heading>Managing Derivations in a Category</Heading>
364
365
<ManSection>
366
<Filt Arg="arg" Name="IsOperationWeightList" Label="for IsObject"/>
367
<Returns><C>true</C> or <C>false</C>
368
</Returns>
369
<Description>
370
An operation weight list manages the use of derivations in a single category <Math>C</Math>.
371
For every operation, it keeps a weight value which indicates how costly it is
372
to perform that operation in the category <Math>C</Math>. Whenever a new operation is
373
implemented in <Math>C</Math>, the operation weight list should be notified about this and
374
given a weight to assign to this operation. It will then automatically install
375
all possible derived methods for <Math>C</Math> in such a way that every operation has the
376
smallest possible weight (the weight of a derived method is computed by using
377
the weights of the operations it uses; see <C>DerivationResultWeight</C>).
378
</Description>
379
</ManSection>
380
381
382
<ManSection>
383
<Oper Arg="C, G" Name="MakeOperationWeightList" Label="for IsCapCategory, IsDerivedMethodGraph"/>
384
<Description>
385
Create the operation weight list for a category.
386
This should only be done once for every category, and the category should
387
afterwards remember the returned object.
388
The argument <A>C</A> is the CAP category this operation weight list is associated to,
389
and the argument <A>G</A> is a derivation graph containing operation names and derivations.
390
</Description>
391
</ManSection>
392
393
394
<ManSection>
395
<Attr Arg="owl" Name="DerivationGraph" Label="for IsOperationWeightList"/>
396
<Description>
397
Returns the derivation graph used by the operation weight list <A>owl</A>.
398
</Description>
399
</ManSection>
400
401
402
<ManSection>
403
<Attr Arg="owl" Name="CategoryOfOperationWeightList" Label="for IsOperationWeightList"/>
404
<Description>
405
Returns the CAP category associated to the operation weight list <A>owl</A>.
406
</Description>
407
</ManSection>
408
409
410
<ManSection>
411
<Oper Arg="owl, op_name" Name="CurrentOperationWeight" Label="for IsOperationWeightList, IsString"/>
412
<Description>
413
Returns the current weight of the operation named <A>op_name</A>.
414
</Description>
415
</ManSection>
416
417
418
<ManSection>
419
<Oper Arg="owl, d" Name="OperationWeightUsingDerivation" Label="for IsOperationWeightList, IsDerivedMethod"/>
420
<Description>
421
Finds out what the weight of the operation implemented by the derivation <A>d</A>
422
would be if we had used that derivation.
423
</Description>
424
</ManSection>
425
426
427
<ManSection>
428
<Oper Arg="owl, op_name" Name="DerivationOfOperation" Label="for IsOperationWeightList, IsString"/>
429
<Description>
430
Returns the derivation which is currently used to implement the operation
431
named <A>op_name</A>.
432
If the operation is not implemented by a derivation (that is, either implemented
433
directly or not implemented at all), then <C>fail</C> is returned.
434
</Description>
435
</ManSection>
436
437
438
<ManSection>
439
<Oper Arg="owl, op_name" Name="InstallDerivationsUsingOperation" Label="for IsOperationWeightList, IsString"/>
440
<Description>
441
Performs a search from the operation <A>op_name</A>, and installs all derivations
442
that give improvements over the current state.
443
This is used internally by <C>AddPrimitiveOperation</C> and <C>Reevaluate</C>.
444
It should normally not be necessary to call this function directly.
445
</Description>
446
</ManSection>
447
448
449
<ManSection>
450
<Oper Arg="owl" Name="Reevaluate" Label="for IsOperationWeightList"/>
451
<Description>
452
Reevaluate the installed derivations, installing better derivations if possible.
453
This should be called if new derivations become available for the category,
454
either because the category has acquired more knowledge about itself
455
(e.g. it is told that it is abelian)
456
or because new derivations have been added to the graph.
457
</Description>
458
</ManSection>
459
460
461
<ManSection>
462
<Oper Arg="owl, op_name, weight" Name="AddPrimitiveOperation" Label="for IsOperationWeightList, IsString, IsInt"/>
463
<Description>
464
Add the operation named <A>op_name</A> to the operation weight list <A>owl</A>
465
with weight <A>weight</A>.
466
This causes all operations that can be derived, directly or indirectly,
467
from the newly added operation to be installed as well
468
(unless they are already installed with the same or lower weight).
469
</Description>
470
</ManSection>
471
472
473
<ManSection>
474
<Oper Arg="owl, op_name" Name="PrintDerivationTree" Label="for IsOperationWeightList, IsString"/>
475
<Description>
476
Print a tree representation of the way the operation named <A>op_name</A>
477
is implemented in the category of the operation weight list <A>owl</A>.
478
</Description>
479
</ManSection>
480
481
482
<ManSection>
483
<Oper Arg="arg1,arg2,arg3" Name="PrintTree" Label="for IsObject, IsFunction, IsFunction"/>
484
<Description>
485
Prints a tree structure.
486
</Description>
487
</ManSection>
488
489
490
<ManSection>
491
<Oper Arg="arg1,arg2,arg3,arg4" Name="PrintTreeRec" Label="for IsObject, IsFunction, IsFunction, IsInt"/>
492
<Description>
493
<P/>
494
</Description>
495
</ManSection>
496
497
498
</Section>
499
500
501
<Section Label="Chapter_Managing_Derived_Methods_Section_Min_Heaps_for_Strings">
502
<Heading>Min Heaps for Strings</Heading>
503
504
This section describes an implementation of min heaps for storing strings with
505
associated integer keys, used internally by operation weight lists.
506
<ManSection>
507
<Filt Arg="arg" Name="IsStringMinHeap" Label="for IsObject"/>
508
<Returns><C>true</C> or <C>false</C>
509
</Returns>
510
<Description>
511
A string min heap is a min heap where every node contains a string label and an
512
integer key.
513
</Description>
514
</ManSection>
515
516
517
<ManSection>
518
<Func Arg="arg" Name="StringMinHeap" />
519
<Description>
520
Create an empty string min heap.
521
</Description>
522
</ManSection>
523
524
525
<ManSection>
526
<Oper Arg="H, string, key" Name="Add" Label="for IsStringMinHeap, IsString, IsInt"/>
527
<Description>
528
Add a new node containing the label <A>string</A> and the key <A>key</A>
529
to the heap <A>H</A>.
530
</Description>
531
</ManSection>
532
533
534
<ManSection>
535
<Oper Arg="H" Name="ExtractMin" Label="for IsStringMinHeap"/>
536
<Description>
537
Remove a node with minimal key value from the heap <A>H</A>, and return it.
538
The return value is a list <C>[ label, key ]</C>, where <C>label</C>
539
is the extracted node's label (a string) and <C>key</C> is the
540
node's key (an integer).
541
</Description>
542
</ManSection>
543
544
545
<ManSection>
546
<Oper Arg="H, string, key" Name="DecreaseKey" Label="for IsStringMinHeap, IsString, IsInt"/>
547
<Description>
548
Decrease the key value for the node with label <A>string</A> in the
549
heap <A>H</A>. The new key value is given by <A>key</A> and must be
550
smaller than the node's current value.
551
</Description>
552
</ManSection>
553
554
555
<ManSection>
556
<Oper Arg="H" Name="IsEmptyHeap" Label="for IsStringMinHeap"/>
557
<Description>
558
Returns <C>true</C> if the heap <A>H</A> is empty, <C>false</C> otherwise.
559
</Description>
560
</ManSection>
561
562
563
<ManSection>
564
<Oper Arg="H" Name="HeapSize" Label="for IsStringMinHeap"/>
565
<Description>
566
Returns the number of nodes in the heap <A>H</A>.
567
</Description>
568
</ManSection>
569
570
571
<ManSection>
572
<Oper Arg="H, string" Name="Contains" Label="for IsStringMinHeap, IsString"/>
573
<Description>
574
Returns <C>true</C> if the heap <A>H</A> contains a node with
575
label <A>string</A>, and <C>false</C> otherwise.
576
</Description>
577
</ManSection>
578
579
580
<ManSection>
581
<Oper Arg="H, i, j" Name="Swap" Label="for IsStringMinHeap, IsPosInt, IsPosInt"/>
582
<Description>
583
Swaps two elements in the list used to implement the heap,
584
and updates the heap's internal mapping of labels to list indices.
585
This is an internal function which should only be called from the
586
functions that implement the heap functionality.
587
</Description>
588
</ManSection>
589
590
591
<ManSection>
592
<Oper Arg="H, i" Name="Heapify" Label="for IsStringMinHeap, IsPosInt"/>
593
<Description>
594
Heapify the heap <A>H</A>, starting from index <A>i</A>.
595
This is an internal function.
596
</Description>
597
</ManSection>
598
599
600
</Section>
601
602
603
<P/>
604
</Chapter>
605
606
607