Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

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

1034945 views
1
2
18 simpcomp internals
3
4
The package simpcomp works with geometric objects for which the GAP object
5
types SCSimplicialComplex and SCNormalSurface are defined and calculates
6
properties of these objects via so called property handlers. This chapter
7
describes how to extend simpcomp by writing own property handlers.
8
9
If you extended simpcomp and want to share your extension with other users
10
please send your extension to one of the authors and we will consider
11
including it (of course with giving credit) in a future release of simpcomp.
12
13
14
18.1 The GAP object type SCPropertyObject
15
16
In the following, we present a number of functions to manage a GAP object of
17
type SCPropertyObject. Since most properties of SCPolyhedralComplex,
18
SCSimplicialComplex and SCNormalSurface are managed by the GAP4 type system
19
(cf. [BL98]), the functions described below are mainly used by the object
20
type SCLibRepository and to store temporary properties.
21
22
18.1-1 SCProperties
23
24
SCProperties( po )  method
25
Returns: a record upon success.
26
27
Returns the record of all stored properties of the SCPropertyObject po.
28
29
18.1-2 SCPropertiesFlush
30
31
SCPropertiesFlush( po )  method
32
Returns: true upon success.
33
34
Drops all properties and temporary properties of the SCPropertyObject po.
35
36
18.1-3 SCPropertiesManaged
37
38
SCPropertiesManaged( po )  method
39
Returns: a list of managed properties upon success, fail otherwise.
40
41
Returns a list of all properties that are managed for the SCPropertyObject
42
po via property handler functions. See SCPropertyHandlersSet (18.1-9).
43
44
18.1-4 SCPropertiesNames
45
46
SCPropertiesNames( po )  method
47
Returns: a list upon success.
48
49
Returns a list of all the names of the stored properties of the
50
SCPropertyObject po. These can be accessed via SCPropertySet (18.1-10) and
51
SCPropertyDrop (18.1-8).
52
53
18.1-5 SCPropertiesTmp
54
55
SCPropertiesTmp( po )  method
56
Returns: a record upon success.
57
58
Returns the record of all stored temporary properties (these are mutable in
59
contrast to regular properties and not serialized when the object is
60
serialized to XML) of the SCPropertyObject po.
61
62
18.1-6 SCPropertiesTmpNames
63
64
SCPropertiesTmpNames( po )  method
65
Returns: a list upon success.
66
67
Returns a list of all the names of the stored temporary properties of the
68
SCPropertyObject po. These can be accessed via SCPropertyTmpSet (18.1-14)
69
and SCPropertyTmpDrop (18.1-13).
70
71
18.1-7 SCPropertyByName
72
73
SCPropertyByName( po, name )  method
74
Returns: any value upon success, fail otherwise.
75
76
Returns the value of the property with name name of the SCPropertyObject po
77
if this property is known for po and fail otherwise. The names of known
78
properties can be accessed via the function SCPropertiesNames (18.1-4)
79
80
18.1-8 SCPropertyDrop
81
82
SCPropertyDrop( po, name )  method
83
Returns: true upopn success, fail otherwise
84
85
Drops the property with name name of the SCPropertyObject po. Returns true
86
if the property is successfully dropped and fail if a property with that
87
name did not exist.
88
89
18.1-9 SCPropertyHandlersSet
90
91
SCPropertyHandlersSet( po, handlers )  method
92
Returns: true
93
94
Sets the property handling functions for a SCPropertyObject po to the
95
functions described in the record handlers. The record handlers has to
96
contain entries of the following structure: [Property Name]:=[Function name
97
computing and returning the property]. For SCSimplicialComplex for example
98
simpcomp defines (among many others): F:=SCFVector. See the file
99
lib/prophandler.gd.
100
101
18.1-10 SCPropertySet
102
103
SCPropertySet( po, name, data )  method
104
Returns: true upon success.
105
106
Sets the value of the property with name name of the SCPropertyObject po to
107
data. Note that the argument becomes immutable. If this behaviour is not
108
desired, use SCPropertySetMutable (18.1-11) instead.
109
110
18.1-11 SCPropertySetMutable
111
112
SCPropertySetMutable( po, name, data )  method
113
Returns: true upon success.
114
115
Sets the value of the property with name name of the SCPropertyObject po to
116
data. Note that the argument does not become immutable. If this behaviour is
117
not desired, use SCPropertySet (18.1-10) instead.
118
119
18.1-12 SCPropertyTmpByName
120
121
SCPropertyTmpByName( po, name )  method
122
Returns: any value upon success, fail otherwise.
123
124
Returns the value of the temporary property with the name name of the
125
SCPropertyObject po if this temporary property is known for po and fail
126
otherwise. The names of known temporary properties can be accessed via the
127
function SCPropertiesTmpNames (18.1-6)
128
129
18.1-13 SCPropertyTmpDrop
130
131
SCPropertyTmpDrop( po, name )  method
132
Returns: true upon success, fail otherwise
133
134
Drops the temporary property with name name of the SCPropertyObject po.
135
Returns true if the property is successfully dropped and fail if a temporary
136
property with that name did not exist.
137
138
18.1-14 SCPropertyTmpSet
139
140
SCPropertyTmpSet( po, name, data )  method
141
Returns: true upon success.
142
143
Sets the value of the temporary property with name name of the
144
SCPropertyObject po to data. Note that the argument does not become
145
immutable. This is the standard behaviour for temporary properties.
146
147
148
18.2 Example of a common attribute
149
150
In this section we will have a look at the property handler
151
SCEulerCharacteristic (7.3-3) in order to explain the inner workings of
152
property handlers. This is the code of the property handler for calculating
153
the Euler characteristic of a complex in simpcomp:
154
155
 Example 
156
DeclareAttribute("SCEulerCharacteristic",SCIsPolyhedralComplex);
157

158
InstallMethod(SCEulerCharacteristic,
159
"for SCSimplicialComplex",
160
[SCIsSimplicialComplex],
161
function(complex)
162

163
 local f, chi, i;
164

165
 f:=SCFVector(complex);
166
 if f=fail then
167
 return fail;
168
 fi;
169
 chi:=0;
170

171
 for i in [1..Size(f)] do
172
 chi:=chi + ((-1)^(i+1))*f[i];
173
 od;
174

175
 return chi;
176
end);
177

178
InstallMethod(SCEulerCharacteristic,
179
"for SCNormalSurface",
180
[SCIsNormalSurface],
181
function(sl)
182

183
 local facets, f, chi;
184

185
 
186
 f:=SCFVector(sl);
187
 if(f=fail) then
188
 return fail;
189
 fi;
190
 
191
 if Length(f) = 1 then
192
 return f[1];
193
 elif Length(f) =3 then
194
 return f[1]-f[2]+f[3];
195
 elif Length(f) =4 then
196
 return f[1]-f[2]+f[3]+f[4];
197
 else
198
 Info(InfoSimpcomp,1,"SCEulerCharacteristic: illegal f-vector found: ",f,". ");
199
 return fail;
200
 fi;
201

202
end);
203

204

205
206
When looking at the code one already sees the structure that such a handler
207
needs to have:
208
209
1 Each property handler (a GAP operation) needs to be defined. This is
210
done by the first line of code. Once an operation is defined, multiple
211
methods can by implemented for various types of GAP objects (here two
212
methods are implemented for the GAP object types SCSimplicialComplex
213
and SCNormalSurface).
214
215
2 First note that the validity of the arguments is checked by GAP. For
216
example, the first method only accepts an argument of type
217
SCSimplicialComplex.
218
219
3 If the property was already computed, the GAP4 type system
220
automatically returns the cached property avoiding unnecessary double
221
calculations.
222
223
4 If the property is not already known. it is computed and returned (and
224
automatically cached by the GAP4 type system).
225
226
227
18.3 Writing a method for an attribute
228
229
This section provides the skeleton of a method that can be used when writing
230
own methods:
231
232
 Example 
233
DeclareAttribute("SCMyPropertyHandler",SCPolyhedralComplex);
234

235
InstallMethod(SCMyPropertyHandler,
236
"for SCSimplicialComplex[ and further arguments]",
237
[SCIsSimplicialComplex[, further arguments]],
238
function(complex[, further arguments])
239

240
 local myprop, ...;
241

242
 # compute the property
243
 [ do property computation here]
244

245
 return myprop;
246
end);
247

248
249
250