File: function.xml

package info (click to toggle)
gap 4r8p6-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 33,476 kB
  • ctags: 7,663
  • sloc: ansic: 108,841; xml: 47,807; sh: 3,628; perl: 2,342; makefile: 796; asm: 62; awk: 6
file content (191 lines) | stat: -rw-r--r-- 7,115 bytes parent folder | download | duplicates (2)
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
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %W  function.msk           GAP documentation                Alexander Hulpke -->
<!-- %% -->
<!-- %H  @(#)<M>Id: function.msk,v 1.8 2005/04/27 13:48:10 gap Exp </M> -->
<!-- %% -->
<!-- %Y  Copyright 1999 -->
<!-- %% -->
<!-- %%  This file describes functions for functions. -->
<!-- %% -->
<Chapter Label="Functions">
<Heading>Functions</Heading>

<Index Subkey="as in programming language">functions</Index>
The section&nbsp;<Ref Sect="Function"/> describes how to define a function.
In this chapter we describe functions that give information about functions,
and various utility functions used either when defining functions or calling
functions.


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Information about a function">
<Heading>Information about a function</Heading>

<#Include Label="NameFunction">
<#Include Label="NumberArgumentsFunction">
<#Include Label="NamesLocalVariablesFunction">
<#Include Label="FilenameFunc">
<#Include Label="StartlineFunc">
<#Include Label="PageSource">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Calling a function with a list argument that is interpreted as
several arguments">
<Heading>Calling a function with a list argument that is interpreted as
several arguments</Heading>

<#Include Label="CallFuncList">

</Section>

<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Calling a function with a time limit">
<Heading>Calling a function with a time limit</Heading>


<#Include Label="CallWithTimeout">
<#Include Label="GAPInfo.TimeoutsSupported">
</Section>




<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Functions that do nothing">
<Heading>Functions that do nothing</Heading>

The following functions return fixed results (or just their own argument).
They can be useful in places when the syntax requires a function, but
actually no functionality is required.
So <Ref Func="ReturnTrue"/> is often used as family predicate in
<Ref Func="InstallMethod"/>.

<#Include Label="ReturnTrue">
<#Include Label="ReturnFalse">
<#Include Label="ReturnFail">
<#Include Label="ReturnNothing">
<#Include Label="ReturnFirst">
<#Include Label="IdFunc">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Function Types">
<Heading>Function Types</Heading>

Functions are &GAP; objects and thus have categories and a family.

<#Include Label="IsFunction">
<#Include Label="IsOperation">
<#Include Label="FunctionsFamily">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Naming Conventions">
<Heading>Naming Conventions</Heading>

The way functions are named in &GAP; 
might help to memorize or even guess names of library functions.
<P/>

If a variable name consists of several words then the first
letter of each word is capitalized.
<P/>

If the first part of the name of a function is a verb then the function
may modify its argument(s) but does not return anything, for example 
<Ref Oper="Append"/> appends the list given as second argument to the
list given as first argument.
Otherwise the function returns an object without changing the arguments,
for example <Ref Func="Concatenation" Label="for several lists"/> 
returns the concatenation of the lists given as arguments.
<P/>

If the name of a function contains the word <Q><C>Of</C></Q> then the return 
value is thought of as information deduced from the arguments.
Usually such functions are attributes (see&nbsp;<Ref Sect="Attributes"/>).
Examples are <Ref Oper="GeneratorsOfGroup"/>, which returns a list of 
generators for the group entered as argument, or <Ref Func="DiagonalOfMat"/>.
<P/>

For the setter and tester functions of an attribute <C>Attr</C>
the names <C>SetAttr</C> resp.&nbsp;<C>HasAttr</C> are available
(see&nbsp;<Ref Sect="Attributes"/>).
<P/>

If the name of a function contains the word <Q><C>By</C></Q> then the 
return value is thought of as built in a certain way from the parts 
given as arguments. For example, creating a group as a factor group 
of a given group by a normal subgroup can be done by taking the image 
of <Ref Func="NaturalHomomorphismByNormalSubgroup"/>. Other examples of 
<Q><C>By</C></Q> functions are <Ref Func="GroupHomomorphismByImages"/> and
<Ref Oper="LaurentPolynomialByCoefficients"/>.
<P/>

Often such functions construct an algebraic structure given by its generators 
(for example, <Ref Oper="RingByGenerators"/>). In some cases, <Q><C>By</C></Q> 
may be replaced by <Q><C>With</C></Q> (like e.g. <Ref Oper="GroupWithGenerators"/>)
or even both versions of the name may be used. The difference between 
<C>StructByGenerators</C> and <C>StructWithGenerators</C> is that the latter 
guarantees that the <C>GeneratorsOfStruct</C> value of the result is equal to 
the given set of generators (see <Ref Label="Constructing Domains"/>).
<P/>

If the name of a function has the form <Q><C>AsSomething</C></Q> then the return 
value is an object (usually a collection which has the same family of elements),
which may, for example:
<List>
<Item>
know more about its own structure (and so support more operations) than its 
input (e.g. if the elements of the collection form a group, 
then this group can be constructed using <Ref Oper="AsGroup"/>);
</Item>
<Item>
discard its additional structure (e.g. <Ref Oper="AsList"/> applied to a 
group will return a list of its elements); 
</Item>
<Item>
contain all elements of the original object without duplicates
(like e.g. <Ref Oper="AsSet"/> does if its argument is a list of elements
from the same family);
</Item>
<Item>
remain unchanged (like e.g. <Ref Oper="AsSemigroup"/> does if 
its argument is a group). 
</Item>
</List>
If <C>Something</C> and the argument of <C>AsSomething</C> are domains,
some further rules apply as explained in 
<Ref Label="Changing the Structure" BookName="tut"/>.
<P/>

If the name of a function <C>fun1</C> ends with <Q><C>NC</C></Q> then there 
is another function <C>fun2</C> with the same name except that the <C>NC</C> 
is missing. <C>NC</C> stands for <Q>no check</Q>. When <C>fun2</C> is called 
then it checks whether its arguments are valid, and if so then it calls 
<C>fun1</C>. The functions <Ref Func="SubgroupNC"/> and 
<Ref Func="Subgroup"/> are a typical example.
<P/>

The idea is that the possibly time consuming check of the arguments
can be omitted if one is sure that they are unnecessary.
For example, if an algorithm produces generators of the derived subgroup
of a group then it is guaranteed that they lie in the original group;
<Ref Func="Subgroup"/> would check this, and <Ref Func="SubgroupNC"/> 
omits the check.
<P/>

Needless to say, all these rules are not followed slavishly, for example 
there is one operation <Ref Oper="Zero"/> instead of two operations
<C>ZeroOfElement</C> and <C>ZeroOfAdditiveGroup</C>.

</Section>

</Chapter>