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

1035252 views
1
<Chapter Label="chap:internals">
2
<Heading><Package>simpcomp</Package> internals</Heading>
3
4
The package <Package>simpcomp</Package> works with geometric objects for which the &GAP; object types <C>SCSimplicialComplex</C> and <C>SCNormalSurface</C> are defined and calculates properties of these objects via so called property handlers. This chapter describes how to extend <Package>simpcomp</Package> by writing own property handlers.
5
6
<P/>
7
8
If you extended <Package>simpcomp</Package> and want to share your extension with other users please send your extension to one of the authors and we will consider including it (of course with giving credit) in a future release of <Package>simpcomp</Package>.
9
10
<P/>
11
12
<#Include Label="propobject" />
13
14
<Section Label="sec:prophandlerex">
15
<Heading>Example of a common attribute</Heading>
16
17
In this section we will have a look at the property handler <Ref Func="SCEulerCharacteristic"/> in order to explain the inner workings of property handlers.
18
19
This is the code of the property handler for calculating the Euler characteristic of a complex in <Package>simpcomp</Package>:
20
21
<Example><![CDATA[
22
DeclareAttribute("SCEulerCharacteristic",SCIsPolyhedralComplex);
23
24
InstallMethod(SCEulerCharacteristic,
25
"for SCSimplicialComplex",
26
[SCIsSimplicialComplex],
27
function(complex)
28
29
local f, chi, i;
30
31
f:=SCFVector(complex);
32
if f=fail then
33
return fail;
34
fi;
35
chi:=0;
36
37
for i in [1..Size(f)] do
38
chi:=chi + ((-1)^(i+1))*f[i];
39
od;
40
41
return chi;
42
end);
43
44
InstallMethod(SCEulerCharacteristic,
45
"for SCNormalSurface",
46
[SCIsNormalSurface],
47
function(sl)
48
49
local facets, f, chi;
50
51
52
f:=SCFVector(sl);
53
if(f=fail) then
54
return fail;
55
fi;
56
57
if Length(f) = 1 then
58
return f[1];
59
elif Length(f) =3 then
60
return f[1]-f[2]+f[3];
61
elif Length(f) =4 then
62
return f[1]-f[2]+f[3]+f[4];
63
else
64
Info(InfoSimpcomp,1,"SCEulerCharacteristic: illegal f-vector found: ",f,". ");
65
return fail;
66
fi;
67
68
end);
69
]]>
70
</Example>
71
72
When looking at the code one already sees the structure that such a handler needs to have:
73
74
<Enum>
75
<Item>Each property handler (a GAP operation) needs to be defined. This is done by the first line of code. Once an operation is defined, multiple methods can by implemented for various types of GAP objects (here two methods are implemented for the GAP object types <C>SCSimplicialComplex</C> and <C>SCNormalSurface</C>).</Item>
76
77
<Item>First note that the validity of the arguments is checked by GAP. For example, the first method only accepts an argument of type <C>SCSimplicialComplex</C>.</Item>
78
79
<Item>If the property was already computed, the GAP4 type system automatically returns the cached property avoiding unnecessary double calculations.</Item>
80
81
<Item>If the property is not already known. it is computed and returned (and automatically cached by the GAP4 type system).</Item>
82
</Enum>
83
84
85
86
</Section>
87
88
89
<Section Label="sec:prophandlerskel">
90
<Heading>Writing a method for an attribute</Heading>
91
92
This section provides the skeleton of a method that can be used when writing own methods:
93
94
<Example><![CDATA[
95
DeclareAttribute("SCMyPropertyHandler",SCPolyhedralComplex);
96
97
InstallMethod(SCMyPropertyHandler,
98
"for SCSimplicialComplex[ and further arguments]",
99
[SCIsSimplicialComplex[, further arguments]],
100
function(complex[, further arguments])
101
102
local myprop, ...;
103
104
# compute the property
105
[ do property computation here]
106
107
return myprop;
108
end);]]>
109
</Example>
110
</Section>
111
112
113
</Chapter>
114
115