[GAP Forum] Implementing automatic inheritance of features
Sebastian Gutsche
sebastian.gutsche at rwth-aachen.de
Fri Oct 11 14:45:34 BST 2013
Dear Johannes,
a while ago, I implemented so-called todo-lists in the ToolsForHomalg
package, which can propagate knowledge (in form of attributes and
properties) between mathematically related objects (being a subobject is
a special case). The basic idea is to attach certain tasks to an object,
which are triggered once a property or an attribute get set (and acquire
certain values). So they behave like immediate methods, but are much
more flexible (dynamic inheritance). These todo-lists might be a
solution for you. Please see the attachment for a commented example.
Just copy both files to a directory and follow the file example.gi line
by line for a demo.
Also, there is the possibility to follow how a propagated property was
set, i.e., building a proof. But this is still very beta, since the
proof-tree usually grows too large.
An example of a package that uses todo-lists outside of the homalg
project is Martin Leuner's alcove: https://github.com/martin-leuner/alcove
If you need any help please feel free to contact us.
Best wishes,
Sebastian
-------------- next part --------------
## Reads some definitions. Please look at that file first.
Read( "example_definitions.gi" );
## We first create a group and a subgroup.
G := CreateOrderedGroup( );
H := CreateOrderedSubgroup( );
## Now we create a todo-list entry, which looks up
## if G has an ordering, and then sets the ordering
## of H to the same object.
entry := ToDoListEntry( [ [ G, "Ordering" ] ], H, "Ordering", [ Ordering, G ] );
## Please read this as follows:
## First argument is a list of preconditions.
## Here the two element list means that the todo-list
## looks up if the attribute Ordering is set.
## If this is the case, it sets the Ordering ( 3th argument ) of
## H (2nd argument) to the ordering of G. This is provided by the last
## argument, which is a list. The first entry is a function, at this time
## applied to the rest of the list. We then get the ordering, which is already known,
## and set the ordering of H to it.
## The next step "activates" the entry.
AddToToDoList( entry );
## This should be false
HasOrdering( H );
SetOrdering( G, "lex" );
## Now the background magic happens, and the ordering of H is set to the same thing.
Ordering( H );
## The todo-lists are capable of even more things, for example launching a function.
G2 := CreateOrderedGroup( );
entry := ToDoListEntry( [ [ G2, "Ordering" ] ], function( ) Print( "Hello world!\n" ); end );
AddToToDoList( entry );
SetOrdering( G2, "lex" );
## The passed function is now launched once the attribute is set.
## We also provide the functionality to create todo-list entries by so
## called blueprints. These install todo-list entries for every created object
## in a category.
ToDoListEntryBlueprint( IsOrderedGroup, [ [ ToDoList_this_object, "Ordering", "lex" ] ], [ function() Print( "Yay, I have an order!\n" ); end ] );
## Now every new object should have a todo-list entry.
G3 := CreateOrderedGroup( );
SetOrdering( G3, "lex" );
-------------- next part --------------
LoadPackage( "ToolsForHomalg" );
## Define types etc. for ordered groups
DeclareCategory( "IsOrderedGroup",
IsObject );
DeclareCategory( "IsOrderedSubgroup",
IsOrderedGroup );
DeclareRepresentation( "IsOrderedGroupRep",
IsOrderedGroup and IsAttributeStoringRep,
[ ] );
DeclareRepresentation( "IsOrderedSubgroupRep",
IsOrderedSubgroup and IsAttributeStoringRep,
[ ] );
BindGlobal( "TheFamilyOfOrderedGroups",
NewFamily( "TheFamilyOfOrderedGroups" ) );
BindGlobal( "TheTypeOfOrderedGroups",
NewType( TheFamilyOfOrderedGroups,
IsOrderedGroupRep ) );
BindGlobal( "TheTypeOfOrderedSubgroups",
NewType( TheFamilyOfOrderedGroups,
IsOrderedSubgroupRep ) );
## Please note that this is not meant to work in any case.
## Its just a demo. We might need constructors for objects.
DeclareOperation( "CreateOrderedGroup",
[ ] );
InstallMethod( CreateOrderedGroup,
[ ],
function( )
local group;
group := rec();
Objectify( TheTypeOfOrderedGroups, group );
return group;
end );
## Creating a subgroup.
## Please note that there is currently no connection
## to the containing group. We will do this later by using todo-lists.
## One might solve this in a different manner.
DeclareOperation( "CreateOrderedSubgroup",
[ ] );
InstallMethod( CreateOrderedSubgroup,
[ ],
function( )
local group;
group := rec();
Objectify( TheTypeOfOrderedSubgroups, group );
return group;
end );
## The attribute we want to share between group and subgroup,
## or better propagate from group to subgroup
DeclareAttribute( "Ordering",
IsOrderedGroup );
More information about the Forum
mailing list