GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
1[1X18 [33X[0;0Y[5Xsimpcomp[105X[101X[1X internals[133X[101X23[33X[0;0YThe package [5Xsimpcomp[105X works with geometric objects for which the [5XGAP[105X object4types [10XSCSimplicialComplex[110X and [10XSCNormalSurface[110X are defined and calculates5properties of these objects via so called property handlers. This chapter6describes how to extend [5Xsimpcomp[105X by writing own property handlers.[133X78[33X[0;0YIf you extended [5Xsimpcomp[105X and want to share your extension with other users9please send your extension to one of the authors and we will consider10including it (of course with giving credit) in a future release of [5Xsimpcomp[105X.[133X111213[1X18.1 [33X[0;0YThe [5XGAP[105X[101X[1X object type [10XSCPropertyObject[110X[101X[1X[133X[101X1415[33X[0;0YIn the following, we present a number of functions to manage a [5XGAP[105X object of16type [10XSCPropertyObject[110X. Since most properties of [10XSCPolyhedralComplex[110X,17[10XSCSimplicialComplex[110X and [10XSCNormalSurface[110X are managed by the GAP4 type system18(cf. [BL98]), the functions described below are mainly used by the object19type [10XSCLibRepository[110X and to store temporary properties.[133X2021[1X18.1-1 SCProperties[101X2223[29X[2XSCProperties[102X( [3Xpo[103X ) [32X method24[6XReturns:[106X [33X[0;10Ya record upon success.[133X2526[33X[0;0YReturns the record of all stored properties of the [10XSCPropertyObject[110X [3Xpo[103X.[133X2728[1X18.1-2 SCPropertiesFlush[101X2930[29X[2XSCPropertiesFlush[102X( [3Xpo[103X ) [32X method31[6XReturns:[106X [33X[0;10Y[9Xtrue[109X upon success.[133X3233[33X[0;0YDrops all properties and temporary properties of the [10XSCPropertyObject[110X [3Xpo[103X.[133X3435[1X18.1-3 SCPropertiesManaged[101X3637[29X[2XSCPropertiesManaged[102X( [3Xpo[103X ) [32X method38[6XReturns:[106X [33X[0;10Ya list of managed properties upon success, [9Xfail[109X otherwise.[133X3940[33X[0;0YReturns a list of all properties that are managed for the [10XSCPropertyObject[110X41[3Xpo[103X via property handler functions. See [2XSCPropertyHandlersSet[102X ([14X18.1-9[114X).[133X4243[1X18.1-4 SCPropertiesNames[101X4445[29X[2XSCPropertiesNames[102X( [3Xpo[103X ) [32X method46[6XReturns:[106X [33X[0;10Ya list upon success.[133X4748[33X[0;0YReturns a list of all the names of the stored properties of the49[10XSCPropertyObject[110X [3Xpo[103X. These can be accessed via [2XSCPropertySet[102X ([14X18.1-10[114X) and50[2XSCPropertyDrop[102X ([14X18.1-8[114X).[133X5152[1X18.1-5 SCPropertiesTmp[101X5354[29X[2XSCPropertiesTmp[102X( [3Xpo[103X ) [32X method55[6XReturns:[106X [33X[0;10Ya record upon success.[133X5657[33X[0;0YReturns the record of all stored temporary properties (these are mutable in58contrast to regular properties and not serialized when the object is59serialized to XML) of the [10XSCPropertyObject[110X [3Xpo[103X.[133X6061[1X18.1-6 SCPropertiesTmpNames[101X6263[29X[2XSCPropertiesTmpNames[102X( [3Xpo[103X ) [32X method64[6XReturns:[106X [33X[0;10Ya list upon success.[133X6566[33X[0;0YReturns a list of all the names of the stored temporary properties of the67[10XSCPropertyObject[110X [3Xpo[103X. These can be accessed via [2XSCPropertyTmpSet[102X ([14X18.1-14[114X)68and [2XSCPropertyTmpDrop[102X ([14X18.1-13[114X).[133X6970[1X18.1-7 SCPropertyByName[101X7172[29X[2XSCPropertyByName[102X( [3Xpo[103X, [3Xname[103X ) [32X method73[6XReturns:[106X [33X[0;10Yany value upon success, [9Xfail[109X otherwise.[133X7475[33X[0;0YReturns the value of the property with name [3Xname[103X of the [10XSCPropertyObject[110X [3Xpo[103X76if this property is known for [3Xpo[103X and [9Xfail[109X otherwise. The names of known77properties can be accessed via the function [2XSCPropertiesNames[102X ([14X18.1-4[114X)[133X7879[1X18.1-8 SCPropertyDrop[101X8081[29X[2XSCPropertyDrop[102X( [3Xpo[103X, [3Xname[103X ) [32X method82[6XReturns:[106X [33X[0;10Y[9Xtrue[109X upopn success, [9Xfail[109X otherwise[133X8384[33X[0;0YDrops the property with name [3Xname[103X of the [10XSCPropertyObject[110X [3Xpo[103X. Returns [9Xtrue[109X85if the property is successfully dropped and [9Xfail[109X if a property with that86name did not exist.[133X8788[1X18.1-9 SCPropertyHandlersSet[101X8990[29X[2XSCPropertyHandlersSet[102X( [3Xpo[103X, [3Xhandlers[103X ) [32X method91[6XReturns:[106X [33X[0;10Y[9Xtrue[109X[133X9293[33X[0;0YSets the property handling functions for a SCPropertyObject [3Xpo[103X to the94functions described in the record [3Xhandlers[103X. The record [3Xhandlers[103X has to95contain entries of the following structure: [10X[Property Name]:=[Function name96computing and returning the property][110X. For [10XSCSimplicialComplex[110X for example97[5Xsimpcomp[105X defines (among many others): [10XF:=SCFVector[110X. See the file98[10Xlib/prophandler.gd[110X.[133X99100[1X18.1-10 SCPropertySet[101X101102[29X[2XSCPropertySet[102X( [3Xpo[103X, [3Xname[103X, [3Xdata[103X ) [32X method103[6XReturns:[106X [33X[0;10Y[9Xtrue[109X upon success.[133X104105[33X[0;0YSets the value of the property with name [3Xname[103X of the [10XSCPropertyObject[110X [3Xpo[103X to106[3Xdata[103X. Note that the argument becomes immutable. If this behaviour is not107desired, use [2XSCPropertySetMutable[102X ([14X18.1-11[114X) instead.[133X108109[1X18.1-11 SCPropertySetMutable[101X110111[29X[2XSCPropertySetMutable[102X( [3Xpo[103X, [3Xname[103X, [3Xdata[103X ) [32X method112[6XReturns:[106X [33X[0;10Y[9Xtrue[109X upon success.[133X113114[33X[0;0YSets the value of the property with name [3Xname[103X of the [10XSCPropertyObject[110X [3Xpo[103X to115[3Xdata[103X. Note that the argument does not become immutable. If this behaviour is116not desired, use [2XSCPropertySet[102X ([14X18.1-10[114X) instead.[133X117118[1X18.1-12 SCPropertyTmpByName[101X119120[29X[2XSCPropertyTmpByName[102X( [3Xpo[103X, [3Xname[103X ) [32X method121[6XReturns:[106X [33X[0;10Yany value upon success, [9Xfail[109X otherwise.[133X122123[33X[0;0YReturns the value of the temporary property with the name [3Xname[103X of the124[10XSCPropertyObject[110X [3Xpo[103X if this temporary property is known for [3Xpo[103X and [9Xfail[109X125otherwise. The names of known temporary properties can be accessed via the126function [2XSCPropertiesTmpNames[102X ([14X18.1-6[114X)[133X127128[1X18.1-13 SCPropertyTmpDrop[101X129130[29X[2XSCPropertyTmpDrop[102X( [3Xpo[103X, [3Xname[103X ) [32X method131[6XReturns:[106X [33X[0;10Y[9Xtrue[109X upon success, [9Xfail[109X otherwise[133X132133[33X[0;0YDrops the temporary property with name [3Xname[103X of the [10XSCPropertyObject[110X [3Xpo[103X.134Returns [9Xtrue[109X if the property is successfully dropped and [9Xfail[109X if a temporary135property with that name did not exist.[133X136137[1X18.1-14 SCPropertyTmpSet[101X138139[29X[2XSCPropertyTmpSet[102X( [3Xpo[103X, [3Xname[103X, [3Xdata[103X ) [32X method140[6XReturns:[106X [33X[0;10Y[9Xtrue[109X upon success.[133X141142[33X[0;0YSets the value of the temporary property with name [3Xname[103X of the143[10XSCPropertyObject[110X [3Xpo[103X to [3Xdata[103X. Note that the argument does not become144immutable. This is the standard behaviour for temporary properties.[133X145146147[1X18.2 [33X[0;0YExample of a common attribute[133X[101X148149[33X[0;0YIn this section we will have a look at the property handler150[2XSCEulerCharacteristic[102X ([14X7.3-3[114X) in order to explain the inner workings of151property handlers. This is the code of the property handler for calculating152the Euler characteristic of a complex in [5Xsimpcomp[105X:[133X153154[4X[32X Example [32X[104X155[4X[28XDeclareAttribute("SCEulerCharacteristic",SCIsPolyhedralComplex);[128X[104X156[4X[28X[128X[104X157[4X[28XInstallMethod(SCEulerCharacteristic,[128X[104X158[4X[28X"for SCSimplicialComplex",[128X[104X159[4X[28X[SCIsSimplicialComplex],[128X[104X160[4X[28Xfunction(complex)[128X[104X161[4X[28X[128X[104X162[4X[28X local f, chi, i;[128X[104X163[4X[28X[128X[104X164[4X[28X f:=SCFVector(complex);[128X[104X165[4X[28X if f=fail then[128X[104X166[4X[28X return fail;[128X[104X167[4X[28X fi;[128X[104X168[4X[28X chi:=0;[128X[104X169[4X[28X[128X[104X170[4X[28X for i in [1..Size(f)] do[128X[104X171[4X[28X chi:=chi + ((-1)^(i+1))*f[i];[128X[104X172[4X[28X od;[128X[104X173[4X[28X[128X[104X174[4X[28X return chi;[128X[104X175[4X[28Xend);[128X[104X176[4X[28X[128X[104X177[4X[28XInstallMethod(SCEulerCharacteristic,[128X[104X178[4X[28X"for SCNormalSurface",[128X[104X179[4X[28X[SCIsNormalSurface],[128X[104X180[4X[28Xfunction(sl)[128X[104X181[4X[28X[128X[104X182[4X[28X local facets, f, chi;[128X[104X183[4X[28X[128X[104X184[4X[28X [128X[104X185[4X[28X f:=SCFVector(sl);[128X[104X186[4X[28X if(f=fail) then[128X[104X187[4X[28X return fail;[128X[104X188[4X[28X fi;[128X[104X189[4X[28X [128X[104X190[4X[28X if Length(f) = 1 then[128X[104X191[4X[28X return f[1];[128X[104X192[4X[28X elif Length(f) =3 then[128X[104X193[4X[28X return f[1]-f[2]+f[3];[128X[104X194[4X[28X elif Length(f) =4 then[128X[104X195[4X[28X return f[1]-f[2]+f[3]+f[4];[128X[104X196[4X[28X else[128X[104X197[4X[28X Info(InfoSimpcomp,1,"SCEulerCharacteristic: illegal f-vector found: ",f,". ");[128X[104X198[4X[28X return fail;[128X[104X199[4X[28X fi;[128X[104X200[4X[28X[128X[104X201[4X[28Xend);[128X[104X202[4X[28X[128X[104X203[4X[32X[104X204205[33X[0;0YWhen looking at the code one already sees the structure that such a handler206needs to have:[133X207208[31X1[131X [33X[0;6YEach property handler (a GAP operation) needs to be defined. This is209done by the first line of code. Once an operation is defined, multiple210methods can by implemented for various types of GAP objects (here two211methods are implemented for the GAP object types [10XSCSimplicialComplex[110X212and [10XSCNormalSurface[110X).[133X213214[31X2[131X [33X[0;6YFirst note that the validity of the arguments is checked by GAP. For215example, the first method only accepts an argument of type216[10XSCSimplicialComplex[110X.[133X217218[31X3[131X [33X[0;6YIf the property was already computed, the GAP4 type system219automatically returns the cached property avoiding unnecessary double220calculations.[133X221222[31X4[131X [33X[0;6YIf the property is not already known. it is computed and returned (and223automatically cached by the GAP4 type system).[133X224225226[1X18.3 [33X[0;0YWriting a method for an attribute[133X[101X227228[33X[0;0YThis section provides the skeleton of a method that can be used when writing229own methods:[133X230231[4X[32X Example [32X[104X232[4X[28XDeclareAttribute("SCMyPropertyHandler",SCPolyhedralComplex);[128X[104X233[4X[28X[128X[104X234[4X[28XInstallMethod(SCMyPropertyHandler,[128X[104X235[4X[28X"for SCSimplicialComplex[ and further arguments]",[128X[104X236[4X[28X[SCIsSimplicialComplex[, further arguments]],[128X[104X237[4X[28Xfunction(complex[, further arguments])[128X[104X238[4X[28X[128X[104X239[4X[28X local myprop, ...;[128X[104X240[4X[28X[128X[104X241[4X[28X # compute the property[128X[104X242[4X[28X [ do property computation here][128X[104X243[4X[28X[128X[104X244[4X[28X return myprop;[128X[104X245[4X[28Xend);[128X[104X246[4X[32X[104X247248249250