## <#GAPDoc Label="IsStructureObjectOrFinitelyPresentedObjectRep"> ## <ManSection> ## <Filt Type="Representation" Arg="M" Name="IsStructureObjectOrFinitelyPresentedObjectRep"/> ## <Returns><C>true</C> or <C>false</C></Returns> ## <Description> ## The &GAP; representation of finitley generated &homalg; objects. <P/> ## It is a representation of the &GAP; category <Ref Filt="IsHomalgObject"/>. ## </Description> ## </ManSection> ## <#/GAPDoc> ##
DeclareRepresentation( "IsStructureObjectOrFinitelyPresentedObjectRep",
IsStructureObjectOrObject,
[ ] );
# a new representation for the GAP-category IsHomalgObject # which is a subrepresentation of the representation IsStructureObjectOrFinitelyPresentedObjectRep and IsHomalgRingOrModule:
DeclareRepresentation( "IsHomalgRingOrFinitelyPresentedModuleRep",
IsStructureObjectOrFinitelyPresentedObjectRep and
IsHomalgRingOrModule,
[ ] );
# a new representation for the GAP-category IsContainerForWeakPointers:
DeclareRepresentation( "IsContainerForWeakPointersRep",
IsContainerForWeakPointers,
[ "weak_pointers", "active", "deleted", "counter", "cache_hits" ] );
# a new subrepresentation of IsContainerForWeakPointersRep:
DeclareRepresentation( "IsContainerForWeakPointersOnObjectsRep",
IsContainerForWeakPointersRep,
[ "weak_pointers", "active", "deleted", "counter", "accessed", "cache_misses", "cache_hits" ] );
# a new subrepresentation of IsContainerForWeakPointersOnObjectsRep:
DeclareRepresentation( "IsContainerForWeakPointersOnComputedValuesRep",
IsContainerForWeakPointersOnObjectsRep,
[ "weak_pointers", "weak_pointers_on_values", "active", "deleted", "counter", "accessed", "cache_misses", "cache_hits" ] );
# a new subrepresentation of IsContainerForWeakPointersOnObjectsRep:
DeclareRepresentation( "IsContainerForWeakPointersOnContainersRep",
IsContainerForWeakPointersOnObjectsRep,
[ "weak_pointers", "active", "deleted", "counter" ] );
#################################### # # representations for pointer object # ####################################
# a new representation for the GAP-category IsContainerForPointers:
DeclareRepresentation( "IsContainerForPointersRep",
IsContainerForPointers,
[ "pointers", "counter", "cache_hits", "cache_misses" ] );
# a new subrepresentation of IsContainerForPointersRep:
DeclareRepresentation( "IsContainerForPointersOnObjectsRep",
IsContainerForPointersRep,
[ "pointers", "counter", "accessed" ] );
# a new subrepresentation of IsContainerForPointersOnObjectsRep:
DeclareRepresentation( "IsContainerForPointersOnComputedValuesRep",
IsContainerForPointersOnObjectsRep,
[ "pointers", "pointers_on_values", "counter", "accessed" ] );
# a new subrepresentation of IsContainerForPointersOnObjectsRep:
DeclareRepresentation( "IsContainerForPointersOnContainersRep",
IsContainerForPointersOnObjectsRep,
[ "pointers", "counter" ] );
#################################### # # families and types: # ####################################
# a new family:
BindGlobal( "TheFamilyOfContainersForWeakPointers",
NewFamily( "TheFamilyOfContainersForWeakPointers" ) );
# a new type:
BindGlobal( "TheTypeContainerForWeakPointers",
NewType( TheFamilyOfContainersForWeakPointers,
IsContainerForWeakPointersRep ) );
# a new type:
BindGlobal( "TheTypeContainerForWeakPointersOnObjects",
NewType( TheFamilyOfContainersForWeakPointers,
IsContainerForWeakPointersOnObjectsRep ) );
# a new type:
BindGlobal( "TheTypeContainerForWeakPointersOnComputedValues",
NewType( TheFamilyOfContainersForWeakPointers,
IsContainerForWeakPointersOnComputedValuesRep ) );
# a new type:
BindGlobal( "TheTypeContainerForWeakPointersOnContainers",
NewType( TheFamilyOfContainersForWeakPointers,
IsContainerForWeakPointersOnContainersRep ) );
#################################### # # global variables: # ####################################
if depth = 0then
return o; elif IsAttributeStoringRep( o ) then
attr := KnownAttributesOfObject( o );
cmpn := Filtered( NamesOfComponents( o ), a -> not( a in attr ) );
cats := CategoriesOfObject( o );
reps := RepresentationsOfObject( o );
prop := KnownPropertiesOfObject( o );
all := rec( attributes := attr,
components := cmpn,
categories := cats,
representations := reps,
properties := prop ); elif IsComponentObjectRep( o ) then
cats := CategoriesOfObject( o );
reps := RepresentationsOfObject( o );
all := rec( components := NamesOfComponents( o ),
categories := cats,
representations := reps ); else
return o; fi;
## below o is an AttributeStoringRep or at least a ComponentObjectRep:
for i in NamesOfComponents( all ) do if i in [ "attributes" ] then
r := rec( ); for a in all.(i) do
r.(a) := InfoOfObject( ValueGlobal( a )( o ), depth-1 );
od; all.(i) := r; elif i in [ "components" ] then
r := rec( ); for a in all.(i) do
r.(a) := InfoOfObject( o!.(a), depth-1 );
od; all.(i) := r; elif i = "properties"then
r := rec( ); for a in all.(i) do
r.(a) := ValueGlobal( a )( o );
od; all.(i) := r; fi;
od;
##
InstallGlobalFunction( homalgTotalRuntimes, function( arg )
local r, t;
r := Runtimes( );
HOMALG_TOOLS.TotalRuntimes := r.user_time;
if IsBound( r.system_time ) and r.system_time <> fail then
HOMALG_TOOLS.TotalRuntimes := HOMALG_TOOLS.TotalRuntimes + r.system_time; fi;
if IsBound( r.user_time_children ) and r.user_time_children <> fail then
HOMALG_TOOLS.TotalRuntimes := HOMALG_TOOLS.TotalRuntimes + r.user_time_children; fi;
if IsBound( r.system_time_children ) and r.system_time_children <> fail then
HOMALG_TOOLS.TotalRuntimes := HOMALG_TOOLS.TotalRuntimes + r.system_time_children; fi;
if Length( arg ) = 0then
return HOMALG_TOOLS.TotalRuntimes; fi;
t := HOMALG_TOOLS.TotalRuntimes - arg[1];
if Length( arg ) > 1then
return Concatenation( StringTime( t ), " h" ); fi;
[ property, "implies by definition", left_property ],
[ property, "implies by definition", right_property ],
];
fi;
Append( list, add );
od;
end );
## a global function for logical implications:
InstallGlobalFunction( LogicalImplicationsForOneHomalgObject, function( statement, filter )
local len, propA, propB, propC, prop;
len := Length( statement );
if len = 3then
propA := statement[1];
prop := statement[3];
InstallTrueMethod( prop, filter and propA );
InstallImmediateMethod( propA,
filter and Tester( prop ), 0,
function( o ) if not prop( o ) then
return false; fi;
## a global function for left/right attributes:
InstallGlobalFunction( LeftRightAttributesForHomalg, function( attr, filter )
local attribute, left_attribute, right_attribute;
##
InstallGlobalFunction( MatchPropertiesAndAttributes, function( arg )
local S, T, properties, attributes, propertiesS, propertiesT,
attributesS, attributesT, p, a, components, c, attributes_do_not_check_their_equality;
S := arg[1];
T := arg[2];
properties := arg[3];
attributes := arg[4];
propertiesS := Intersection2( KnownPropertiesOfObject( S ), properties );
propertiesT := Intersection2( KnownPropertiesOfObject( T ), properties );
attributesS := Intersection2( KnownAttributesOfObject( S ), attributes );
attributesT := Intersection2( KnownAttributesOfObject( T ), attributes );
## for properties: for p in propertiesS do## also check if properties already set for both objects coincide
Setter( ValueGlobal( p ) )( T, ValueGlobal( p )( S ) );
od;
## now backwards for p in Difference( propertiesT, propertiesS ) do
Setter( ValueGlobal( p ) )( S, ValueGlobal( p )( T ) );
od;
## for attributes: for a in Difference( attributesS, attributesT ) do
Setter( ValueGlobal( a ) )( T, ValueGlobal( a )( S ) );
od;
## now backwards for a in Difference( attributesT, attributesS ) do
Setter( ValueGlobal( a ) )( S, ValueGlobal( a )( T ) );
od;
## also check if properties already set for both objects coincide
## by now, more attributes than the union might be konwn
attributesS := Intersection2( KnownAttributesOfObject( S ), attributes );
attributesT := Intersection2( KnownAttributesOfObject( T ), attributes );
for a in Intersection2( attributesS, attributesT ) do if ValueGlobal( a )( S ) <> ValueGlobal( a )( T ) then
Error( "the attribute ", a, " has different values for source and target object\n" ); fi;
od;
if Length( arg ) > 4then
components := arg[5];
for c in components do if IsBound( S!.(c) ) and not IsBound( T!.(c) ) then
T!.(c) := S!.(c); elif IsBound( T!.(c) ) and not IsBound( S!.(c) ) then
S!.(c) := T!.(c); fi;
od;
fi;
if Length( arg ) > 5then ## checking their equality might again trigger MatchPropertiesAndAttributes ## and cause infinite loops
attributes_do_not_check_their_equality := arg[6];
attributesS := Intersection2( KnownAttributesOfObject( S ), attributes_do_not_check_their_equality );
attributesT := Intersection2( KnownAttributesOfObject( T ), attributes_do_not_check_their_equality );
## for attributes: for a in Difference( attributesS, attributesT ) do
Setter( ValueGlobal( a ) )( T, ValueGlobal( a )( S ) );
od;
## now backwards for a in Difference( attributesT, attributesS ) do
Setter( ValueGlobal( a ) )( S, ValueGlobal( a )( T ) );
od;
# This function declares an attribute, but does not install the standard getter. # instead, a getter given as third argument is installed. # the primary use of this method is for morphism aids: we are able to set lazy # morphism aids and compute them by the getter. ##
InstallGlobalFunction( DeclareAttributeWithCustomGetter, function ( arg )
local attr, name, custom_getter, nname, gvar, pos, filter, new_attribute_args;
name := arg[1];
custom_getter := arg[3];
new_attribute_args := ShallowCopy( arg );
Remove( new_attribute_args, 3 ); if IsBoundGlobal( name ) then
Error( "expected a name not bound" ); else
attr := CallFuncList( NewAttribute, new_attribute_args );
BindGlobal( name, custom_getter );
nname := "Set";
Append( nname, name );
BindGlobal( nname, SETTER_FILTER( attr ) );
nname := "Has";
Append( nname, name );
BindGlobal( nname, TESTER_FILTER( attr ) ); fi;
return; end );
##
InstallGlobalFunction( AppendToAhomalgTable, function( RP, RP_addon )
local component;
for component in NamesOfComponents( RP_addon ) do
RP!.(component) := RP_addon.(component);
od;
return Filtered(
List( NamesOfComponents( arg[1] ), function( a )
local l;
l := SplitString( a, ",", "[ ]" ); if Length( l ) = 1then if Length( l[1] ) <= 24then
return Int( l[1] ); else
return fail; fi; else
return List( l, Int ); fi; end
),
b -> b <> fail ); end );
##
InstallGlobalFunction( IncreaseExistingCounterInObject, function( o, component )
o!.(component) := o!.(component) + 1;
end );
InstallGlobalFunction( IncreaseExistingCounterInObjectWithTiming, function( o, component, t )
o!.(component) := o!.(component) + [ 1, t ];
end );
##
InstallGlobalFunction( IncreaseCounterInObject, function( o, component )
if IsBound( o!.(component) ) then
o!.(component) := o!.(component) + 1; else
o!.(component) := 1; fi;
end );
##
InstallGlobalFunction( MemoryToString, function( memory )
local m;
m := memory;
if m < 1024then
return Concatenation( String( m ), " Bytes" ); fi;
m := Float( m / 1024 );
if m < 1024then
return Concatenation( String( m ), " KB" ); fi;
m := Float( m / 1024 );
if m < 1024then
return Concatenation( String( m ), " MB" ); fi;
m := Float( m / 1024 );
if m < 1024then
return Concatenation( String( m ), " GB" ); fi;
m := Float( m / 1024 );
return Concatenation( String( m ), " TB" );
end );
##
InstallGlobalFunction( PrimePowerExponent, function( n, p )
local a;
if not IsPrime( p ) then
Error( "the second argument is not a prime\n" ); fi;
a := -1;
repeat
a := a + 1;
n := n / p;
until not IsInt( n );
return a;
end );
##
InstallMethod( ViewList,
[ "IsList" ],
function( L )
local l, i;
l := Length( L );
if l = 0then
ViewObj( [ ] );
return; fi;
Print( "[ " );
ViewObj( L[1] );
for i in [ 2 .. l ] do
Print( ",\n " );
ViewObj( L[i] );
od;
Print( " ]\n" );
end );
##
InstallMethod( IdenticalPosition, "for a list and an object",
[ IsList, IsObject ],
function( L, o )
return PositionProperty( L, x -> IsIdenticalObj( x, o ) );
end );
##
InstallMethod( AppendNew, "for two lists",
[ IsList, IsList ],
function( L, N )
local n, p;
for n in N do
p := IdenticalPosition( L, n ); if p = fail then
Add( L, n ); fi;
od;
end );
##
InstallMethod( PositionsOfMaximalObjects, "for a list and a function",
[ IsList, IsFunction ],
function( L, f )
local l, r, i, p;
l := [ 1 .. Length( L ) ];
r := [ ];
for i in l do
if i in r then
continue; fi;
p := PositionProperty( l, j -> not j = i and not j in r and f( L[i], L[j] ) );
if not p = fail then
Add( r, i ); fi;
od;
return Difference( l, r );
end );
##
InstallMethod( MaximalObjects, "for a list and a function",
[ IsList, IsFunction ],
function( L, f )
return L{PositionsOfMaximalObjects( L, f )};
end );
##
InstallGlobalFunction( ExecForHomalg, function( arg )
local str, output, cmd, i, shell, cs, dir;
# simply concatenate the arguments
cmd := ShallowCopy( arg[1] ); if not IsString(cmd) then
Error("the command ",cmd," is not a name.\n", "possibly a binary is missing or has not been compiled."); fi; for i in [ 2 .. Length(arg) ] do
Append( cmd, " " );
Append( cmd, arg[i] );
od;
# select the shell, bourne shell is the default: sh -c cmd if ARCH_IS_WINDOWS() then # on Windows, we use the native shell such that behaviour does # not depend on whether cygwin is installed or not. # cmd.exe is preferrable to old-style `command.com'
shell := Filename( DirectoriesSystemPrograms(), "cmd.exe" );
cs := "/C"; else
shell := Filename( DirectoriesSystemPrograms(), "sh" );
cs := "-c"; fi;
# execute in the current directory
dir := DirectoryCurrent();
if comparing_func = fail or not IsFunction( comparing_func ) then
comparing_func := \=; fi;
if IsEmpty( list ) then
return [ ]; fi;
o := list[ 1 ];
n := PositionProperty( list, x -> not comparing_func( o, x ) );
if n = fail then
return [ [ o, Length( list ) ] ]; else
return Concatenation( [ [ o, n - 1 ] ], CollectEntries( list{ [ n .. Length( list ) ] } ) ); fi;
function( container )
local weak_pointers, l, active, l_active, i;
weak_pointers := container!.weak_pointers;
l := LengthWPObj( weak_pointers );
active := Filtered( container!.active, i -> i <= l );
l_active := Length( active );
i := 1;
while i <= l_active do if ElmWPObj( weak_pointers, active[i] ) <> fail then
i := i + 1; else## active[i] is no longer active
Remove( active, i );
l_active := l_active - 1; fi;
od;
## UpdateContainerOfWeakPointers is only called ## from view and display methods, which we do not want ## to count as accesses: # container!.accessed := container!.accessed + 1;
container!.active := active;
container!.deleted := Difference( [ 1 .. l ], active );
l := Minimum( LengthWPObj( weak_pointers ), LengthWPObj( weak_pointers_on_values ) );
active := Filtered( container!.active, i -> i <= l );
l_active := Length( active );
i := 1;
while i <= l_active do if ElmWPObj( weak_pointers, active[i] ) <> fail and
ElmWPObj( weak_pointers_on_values, active[i] ) <> fail then
i := i + 1; else## active[i] is no longer active
Remove( active, i );
l_active := l_active - 1; fi;
od;
## UpdateContainerOfWeakPointers is only called ## from view and display methods, which we do not want ## to count as accesses: # container!.accessed := container!.accessed + 1;
container!.active := active;
container!.deleted := Difference( [ 1 .. l ], active );
## here we increase container!.counter instead of container!.accessed;
container!.counter := container!.counter + 1;
end );
##
InstallMethod( _ElmWPObj_ForHomalg, "for a container of weak pointer lists and two objects (a reference and a return fail value)",
[ IsContainerForWeakPointersOnComputedValuesRep, IsObject, IsObject ], 0,
function( container, obj, FAIL )
local weak_pointers, weak_pointers_on_values, l, active, cache_hit, l_active, i, ref, value;
l := Minimum( LengthWPObj( weak_pointers ), LengthWPObj( weak_pointers_on_values ) );
active := Filtered( container!.active, i -> i <= l );
cache_hit := false;
l_active := Length( active );
i := 1;
while i <= l_active do
value := ElmWPObj( weak_pointers_on_values, active[i] ); if value <> fail then
ref := ElmWPObj( weak_pointers, active[i] ); if ref <> fail then if IsIdenticalObj( ref, obj ) then
cache_hit := true;
break; fi;
i := i + 1; else## active[i] is no longer active
Remove( active, i );
l_active := l_active - 1; fi; else## active[i] is no longer active
Remove( active, i );
l_active := l_active - 1; fi;
od;
container!.active := active;
container!.deleted := Difference( [ 1 .. l ], active );
for a in o!.active do
obj := ElmWPObj( weak_pointers, a ); if obj <> fail and
( not IsBound( obj!.counter ) or obj!.counter <> 0 ) then
Print( a, ":\t" );
ViewObj( obj );
Print( "\n" ); fi;
od;
## here we increase container!.counter instead of container!.accessed;
container!.counter := container!.counter + 1;
end );
##
InstallGlobalFunction( _AddTwoElmPObj_ForHomalg, function( container, ref, value )
Add( container!.pointers, ref );
Add( container!.pointers_on_values, value );
## here we increase container!.counter instead of container!.accessed;
container!.counter := container!.counter + 1;
end );
##
InstallMethod( _ElmPObj_ForHomalg, "for a container of weak pointer lists and two objects (a reference and a return fail value)",
[ IsContainerForPointersOnComputedValuesRep, IsObject, IsObject ], 0,
Print( "Timer ", name, " (", state, "):", " started ",
execs, " times with a total runtime of ",
elapsed_time, " ms ( = ",
Int( elapsed_time / execs * 1000 ), " μs per run)\n"
);
end );
## copied from gap/lib/methwhy.g
InstallGlobalFunction( ListImpliedFilters, function(filter)
local flags, implied, f, extra_implications, implication, name, diff_reqs,
diff_impls, reduced, list;
flags:=FLAGS_FILTER(filter);
implied := WITH_IMPS_FLAGS(flags);
atomic readonly IMPLICATIONS_SIMPLE do # select all implications which involved <filter> in the requirements
f:=Filtered(IMPLICATIONS_SIMPLE, x->IS_SUBSET_FLAGS(x[2],flags));
Append(f, Filtered(IMPLICATIONS_COMPOSED, x->IS_SUBSET_FLAGS(x[2],flags)));
od; # end atomic
# remove "obvious" implications if IS_ELEMENTARY_FILTER(filter) then
implied := SUB_FLAGS(implied, flags); fi;
reduced:= function( trues )
atomic readonly FILTER_REGION do
return Filtered( trues,
i -> not ( INFO_FILTERS[i] in FNUM_TPRS
and FLAG1_FILTER( FILTERS[i] ) in trues ) );
od; end;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.