GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
<Chapter Label="chap:internals">1<Heading><Package>simpcomp</Package> internals</Heading>23The 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.45<P/>67If 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>.89<P/>1011<#Include Label="propobject" />1213<Section Label="sec:prophandlerex">14<Heading>Example of a common attribute</Heading>1516In this section we will have a look at the property handler <Ref Func="SCEulerCharacteristic"/> in order to explain the inner workings of property handlers.1718This is the code of the property handler for calculating the Euler characteristic of a complex in <Package>simpcomp</Package>:1920<Example><![CDATA[21DeclareAttribute("SCEulerCharacteristic",SCIsPolyhedralComplex);2223InstallMethod(SCEulerCharacteristic,24"for SCSimplicialComplex",25[SCIsSimplicialComplex],26function(complex)2728local f, chi, i;2930f:=SCFVector(complex);31if f=fail then32return fail;33fi;34chi:=0;3536for i in [1..Size(f)] do37chi:=chi + ((-1)^(i+1))*f[i];38od;3940return chi;41end);4243InstallMethod(SCEulerCharacteristic,44"for SCNormalSurface",45[SCIsNormalSurface],46function(sl)4748local facets, f, chi;495051f:=SCFVector(sl);52if(f=fail) then53return fail;54fi;5556if Length(f) = 1 then57return f[1];58elif Length(f) =3 then59return f[1]-f[2]+f[3];60elif Length(f) =4 then61return f[1]-f[2]+f[3]+f[4];62else63Info(InfoSimpcomp,1,"SCEulerCharacteristic: illegal f-vector found: ",f,". ");64return fail;65fi;6667end);68]]>69</Example>7071When looking at the code one already sees the structure that such a handler needs to have:7273<Enum>74<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>7576<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>7778<Item>If the property was already computed, the GAP4 type system automatically returns the cached property avoiding unnecessary double calculations.</Item>7980<Item>If the property is not already known. it is computed and returned (and automatically cached by the GAP4 type system).</Item>81</Enum>82838485</Section>868788<Section Label="sec:prophandlerskel">89<Heading>Writing a method for an attribute</Heading>9091This section provides the skeleton of a method that can be used when writing own methods:9293<Example><![CDATA[94DeclareAttribute("SCMyPropertyHandler",SCPolyhedralComplex);9596InstallMethod(SCMyPropertyHandler,97"for SCSimplicialComplex[ and further arguments]",98[SCIsSimplicialComplex[, further arguments]],99function(complex[, further arguments])100101local myprop, ...;102103# compute the property104[ do property computation here]105106return myprop;107end);]]>108</Example>109</Section>110111112</Chapter>113114115