Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Bib Ind
 Top of Book   Previous Chapter   Next Chapter 

14 simpcomp internals
 14.1 The GAP object type SCPropertyObject
  14.1-1 SCProperties

  14.1-2 SCPropertiesFlush

  14.1-3 SCPropertiesManaged

  14.1-4 SCPropertiesNames

  14.1-5 SCPropertiesTmp

  14.1-6 SCPropertiesTmpNames

  14.1-7 SCPropertyByName

  14.1-8 SCPropertyDrop

  14.1-9 SCPropertyHandlersSet

  14.1-10 SCPropertySet

  14.1-11 SCPropertySetMutable

  14.1-12 SCPropertyTmpByName

  14.1-13 SCPropertyTmpDrop

  14.1-14 SCPropertyTmpSet
 14.2 Example of a common property handler
 14.3 Writing a property handler

14 simpcomp internals

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.

14.1 The GAP object type SCPropertyObject

The 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.

14.1-1 SCProperties
> SCProperties( po )( function )

Returns: a record upon success.

Returns the record of all stored properties of the SCPropertyObject po.

14.1-2 SCPropertiesFlush
> SCPropertiesFlush( po )( function )

Returns: true upon success.

Drops all properties and temporary properties of the SCPropertyObject po.

14.1-3 SCPropertiesManaged
> 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).

14.1-4 SCPropertiesNames
> 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).

14.1-5 SCPropertiesTmp
> 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.

14.1-6 SCPropertiesTmpNames
> 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).

14.1-7 SCPropertyByName
> 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)

14.1-8 SCPropertyDrop
> 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.

14.1-9 SCPropertyHandlersSet
> 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.

14.1-10 SCPropertySet
> 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.

14.1-11 SCPropertySetMutable
> 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.

14.1-12 SCPropertyTmpByName
> 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)

14.1-13 SCPropertyTmpDrop
> 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.

14.1-14 SCPropertyTmpSet
> 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.

14.2 Example of a common property handler

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:

  1. 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.

  2. 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.

  3. If SCPropertyByName did not return fail and the cached property passes a validity check the cached property is returned.

  4. 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.

14.3 Writing a property handler

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);
 Top of Book   Previous Chapter   Next Chapter 
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Bib Ind

generated by GAPDoc2HTML