SCPropertyObject
The package simpcomp works with simplicial complexes for which a GAP object type SCSimplicialComplex is defined and calculates properties of these objects via so called property handlers. This chapter describes how to extend simpcomp by writing own property handlers.
If you extended simpcomp 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 simpcomp.
SCPropertyObjectThe following functions compute basic properties of simplicial complexes of type SCSimplicialComplex. None of these functions alter the complex. All properties are returned as immutable objects (this ensures data consistency of the cached properties of a simplicial complex). Use ShallowCopy or the internal simpcomp function SCIntFunc.DeepCopy to get a mutable copy.
Note: every simplicial complex is internally stored with the standard vertex labeling from 1 to n and a maptable to restore the original vertex labeling. Thus, we have to relabel some of the complex properties (facets, face lattice, generators, etc...) whenever we want to return them to the user. As a consequence, some of the functions exist twice, one of them with the appendix "Ex". These functions return the standard labeling whereas the other ones relabel the result to the original labeling.
> SCProperties( po ) | ( function ) |
Returns: a record upon success.
Returns the record of all stored properties of the SCPropertyObject po.
> SCPropertiesFlush( po ) | ( function ) |
Returns: true upon success.
Drops all properties and temporary properties of the SCPropertyObject po.
> SCPropertiesManaged( po ) | ( function ) |
Returns: a list of managed properties upon success, fail otherwise.
Returns a list of all properties that are managed for the SCPropertyObject po via property handler functions. See SCPropertyHandlersSet (14.1-9).
> SCPropertiesNames( po ) | ( function ) |
Returns: a list upon success.
Returns a list of all the names of the stored properties of the SCPropertyObject po. These can be accessed via SCPropertySet (14.1-10) and SCPropertyDrop (14.1-8).
> SCPropertiesTmp( po ) | ( function ) |
Returns: a record upon success.
Returns the record of all stored temporary properties (these are mutable in contrast to regular properties and not serialized when the object is serialized to XML) of the SCPropertyObject po.
> SCPropertiesTmpNames( po ) | ( function ) |
Returns: a list upon success.
Returns a list of all the names of the stored temporary properties of the SCPropertyObject po. These can be accessed via SCPropertyTmpSet (14.1-14) and SCPropertyTmpDrop (14.1-13).
> SCPropertyByName( po, name ) | ( function ) |
Returns: any value upon success, fail otherwise.
Returns the value of the property with name name of the SCPropertyObject po if this property is known for po and fail otherwise. The names of known properties can be accessed via the function SCPropertiesNames (14.1-4)
> SCPropertyDrop( po, name ) | ( function ) |
Returns: true upopn success, fail otherwise
Drops the property with name name of the SCPropertyObject po. Returns true if the property is successfully dropped and fail if a property with that name did not exist.
> SCPropertyHandlersSet( po, handlers ) | ( function ) |
Returns: true
Sets the property handling functions for a SCPropertyObject po to the functions described in the record handlers. The record handlers has to contain entries of the following structure: [Property Name]:=[Function name computing and returning the property]. For SCSimplicialComplex for example simpcomp defines (among many others): F:=SCFVector. See the file lib/prophandler.gd.
> SCPropertySet( po, name, data ) | ( function ) |
Returns: true upon success.
Sets the value of the property with name name of the SCPropertyObject po to data. Note that the argument becomes immutable. If this behaviour is not desired, use SCPropertySetMutable (14.1-11) instead.
> SCPropertySetMutable( po, name, data ) | ( function ) |
Returns: true upon success.
Sets the value of the property with name name of the SCPropertyObject po to data. Note that the argument does not become. If this behaviour is not desired, use SCPropertySet (14.1-10) instead.
> SCPropertyTmpByName( po, name ) | ( function ) |
Returns: any value upon success, fail otherwise.
Returns the value of the temporary property with the name name of the SCPropertyObject po if this temporary property is known for po and fail otherwise. The names of known temporary properties can be accessed via the function SCPropertiesTmpNames (14.1-6)
> SCPropertyTmpDrop( po, name ) | ( function ) |
Returns: true upon success, fail otherwise
Drops the temporary property with name name of the SCPropertyObject po. Returns true if the property is successfully dropped and fail if a temporary property with that name did not exist.
> SCPropertyTmpSet( po, name, data ) | ( function ) |
Returns: true upon success.
Sets the value of the temporary property with name name of the SCPropertyObject po to data. Note that the argument does not become immutable. This is the standard behaviour for temporary properties.
In this section we will have a look at the property handler SCEulerCharacteristic (4.7-9) in order to explain the inner workings of property handlers. This is the code of the property handler for calculating the Euler characteristic of a complex in simpcomp:
InstallGlobalFunction(SCEulerCharacteristic, function(complex) local f, chi, i; if(not SCIsSimplicialComplex(complex)) then Info(InfoSimpcomp,1,"SCEulerCharacteristic: first argument must be of type SCSimplicialComplex."); return fail; fi; chi:=SCPropertyByName(complex,"Chi"); if chi<>fail and IsInt(chi) then return chi; else SCPropertyDrop(complex,"Chi"); f:=SCFVector(complex); if f=fail then return fail; fi; chi:=0; for i in [1..Size(f)] do chi:=chi + ((-1)^(i+1))*f[i]; od; SCPropertySet(complex,"Chi",chi); return chi; fi; end); |
When looking at the code one already see the structure that such a handler needs to have:
The arguments are checked for validity -- in case of invalid arguments an error is signaled with Info(InfoSimpcomp,1,"Error message."); and the function returns fail.
It is checked whether the property was computed already with the function SCPropertyByName -- it takes a complex (as SCPropertyObject) and a property name (as String) as arguments and returns the property or fail if that property does not exist.
If SCPropertyByName did not return fail and the cached property passes a validity check the cached property is returned.
Otherwise the property is first dropped via the function SCPropertyDrop -- it takes a complex (as SCPropertyObject) and a property name (as String) as arguments -- then recomputed and finally written back to the complex via the function SCPropertySet (that takes a complex, a property name and a property as arguments) and returned.
This section provides the skeleton of a property handler that can be used when writing own property handlers:
InstallGlobalFunction(SCMyPropertyHandler, function(complex[, further arguments]) local myprop, ...; # test arguments if(not SCIsSimplicialComplex(complex)) then Info(InfoSimpcomp,1,"SCMyPropertyHandler: first argument must be of type SCSimplicialComplex."); return fail; fi; # check if the property that you want to compute is cached myprop:=SCPropertyByName(complex,"MyProperty"); if myprop<>fail and [check of validity of myprop here] then return myprop; else # first drop the property SCPropertyDrop(complex,"MyProperty"); # now (re)compute the property [ do property computation here] # set the newly created property and return it SCPropertySet(complex,"MyProperty",myprop); return myprop; fi; end); |
generated by GAPDoc2HTML