1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
|
#############################################################################
##
#W object.gd GAP library Martin Schoenert
##
#H @(#)$Id: object.gd,v 4.50.2.2 2007/09/05 15:06:47 gap Exp $
##
#Y Copyright (C) 1997, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany
#Y (C) 1998 School Math and Comp. Sci., University of St. Andrews, Scotland
#Y Copyright (C) 2002 The GAP Group
##
## This file declares the operations for all objects.
##
Revision.object_gd :=
"@(#)$Id: object.gd,v 4.50.2.2 2007/09/05 15:06:47 gap Exp $";
#T Shall we add a check that no object ever lies in both
#T `IsComponentObjectRep' and `IsPositionalObjectRep'?
#T (A typical pitfall is that one decides to use `IsAttributeStoringRep'
#T for storing attribute values, *and* `IsPositionalObjectRep' for
#T convenience.)
#T Could we use `IsImpossible' and an immediate method that signals an error?
#############################################################################
##
#C IsObject( <obj> ) . . . . . . . . . . . . test if an object is an object
##
## `IsObject' returns `true' if the object <obj> is an object. Obviously it
## can never return `false'.
##
## It can be used as a filter in `InstallMethod'
## (see~"prg:Method Installation" in ``Programming in GAP'')
## when one of the arguments can be anything.
##
DeclareCategoryKernel( "IsObject", IS_OBJECT, IS_OBJECT );
#############################################################################
##
#F IsIdenticalObj( <obj1>, <obj2> ) . . . . . . . are two objects identical
##
## `IsIdenticalObj( <obj1>, <obj2> )' tests whether the objects
## <obj1> and <obj2> are identical (that is they are either
## equal immediate objects or are both stored at the same location in
## memory.
##
BIND_GLOBAL( "IsIdenticalObj", IS_IDENTICAL_OBJ );
#############################################################################
##
#F IsNotIdenticalObj( <obj1>, <obj2> ) . . . . are two objects not identical
##
## tests whether the objects <obj1> and <objs2> are not identical.
##
BIND_GLOBAL( "IsNotIdenticalObj", function ( obj1, obj2 )
return not IsIdenticalObj( obj1, obj2 );
end );
#############################################################################
##
#o <obj1> = <obj2> . . . . . . . . . . . . . . . . . . are two objects equal
##
DeclareOperationKernel( "=", [ IsObject, IsObject ], EQ );
#############################################################################
##
#o <obj1> < <obj2> . . . . . . . . . . . is one object smaller than another
##
DeclareOperationKernel( "<", [ IsObject, IsObject ], LT );
#############################################################################
##
#o <obj1> in <obj2> . . . . . . . . . . . is one object a member of another
##
DeclareOperationKernel( "in", [ IsObject, IsObject ], IN );
#############################################################################
##
#C IsCopyable( <obj> ) . . . . . . . . . . . . test if an object is copyable
##
## If a mutable form of an object <obj> can be made in {\GAP},
## the object is called *copyable*. Examples of copyable objects are of
## course lists and records. A new mutable version of the object can
## always be obtained by the operation `ShallowCopy' (see "Duplication of
## Objects").
##
DeclareCategoryKernel( "IsCopyable", IsObject, IS_COPYABLE_OBJ );
#############################################################################
##
#C IsMutable( <obj> ) . . . . . . . . . . . . test if an object is mutable
##
## tests whether <obj> is mutable.
##
## If an object is mutable then it is also copyable (see~"IsCopyable"),
## and a `ShallowCopy' (see~"ShallowCopy") method should be supplied for it.
## Note that `IsMutable' must not be implied by another filter,
## since otherwise `Immutable' would be able to create paradoxical objects
## in the sense that `IsMutable' for such an object is `false' but the
## filter that implies `IsMutable' is `true'.
##
DeclareCategoryKernel( "IsMutable", IsObject, IS_MUTABLE_OBJ );
InstallTrueMethod( IsCopyable, IsMutable);
#############################################################################
##
#O Immutable( <obj> )
##
## returns an immutable structural copy (see~"StructuralCopy") of <obj>
## in which the subobjects are immutable *copies* of the subobjects of
## <obj>.
## If <obj> is immutable then `Immutable' returns <obj> itself.
##
## {\GAP} will complain with an error if one tries to change an
## immutable object.
##
BIND_GLOBAL( "Immutable", IMMUTABLE_COPY_OBJ );
#############################################################################
##
#O ShallowCopy( <obj> ) . . . . . . . . . . . . . shallow copy of an object
##
## If {\GAP} supports a mutable form of the object <obj>
## (see~"Mutability and Copyability") then this is obtained by
## `ShallowCopy'.
## Otherwise `ShallowCopy' returns <obj> itself.
##
## The subobjects of `ShallowCopy( <obj> )' are *identical* to the
## subobjects of <obj>.
## Note that if the object returned by `ShallowCopy' is mutable then it is
## always a *new* object.
## In particular, if the return value is mutable, then it is not *identical*
## with the argument <obj>, no matter whether <obj> is mutable or immutable.
## But of course the object returned by `ShallowCopy' is *equal* to <obj>
## w.r.t.~the equality operator `='.
##
## Since `ShallowCopy' is an operation, the concrete meaning of
## ``subobject'' depends on the type of <obj>.
## But for any copyable object <obj>, the definition should reflect the
## idea of ``first level copying''.
##
## The definition of `ShallowCopy' for lists (in particular for matrices)
## can be found in~"Duplication of Lists".
##
DeclareOperationKernel( "ShallowCopy", [ IsObject ], SHALLOW_COPY_OBJ );
#############################################################################
##
#F StructuralCopy( <obj> ) . . . . . . . . . . structural copy of an object
##
## In a few situations,
## one wants to make a *structural copy* <scp> of an object <obj>.
## This is defined as follows.
## <scp> and <obj> are identical if <obj> is immutable.
## Otherwise, <scp> is a mutable copy of <obj> such that
## each subobject of <scp> is a structural copy of the corresponding
## subobject of <obj>.
## Furthermore, if two subobjects of <obj> are identical then
## also the corresponding subobjects of <scp> are identical.
##
BIND_GLOBAL( "StructuralCopy", DEEP_COPY_OBJ );
#############################################################################
##
#A Name( <obj> ) . . . . . . . . . . . . . . . . . . . . . name of an object
##
## returns the name, a string, previously assigned to <obj> via a call to
## `SetName' (see~"SetName").
## The name of an object is used *only* for viewing the object via this
## name.
##
## There are no methods installed for computing names of objects,
## but the name may be set for suitable objects, using `SetName'.
##
DeclareAttribute( "Name", IsObject );
#############################################################################
##
#A String( <obj> ) . . . . . . . . . . . string representation of an object
#O String( <obj>, <length> ) . formatted string representation of an object
##
## `String' returns a representation of <obj>,
## which may be an object of arbitrary type, as a string.
## This string should approximate as closely as possible the character
## sequence you see if you print <obj>.
##
## If <length> is given it must be an integer.
## The absolute value gives the minimal length of the result.
## If the string representation of <obj> takes less than that many
## characters it is filled with blanks.
## If <length> is positive it is filled on the left,
## if <length> is negative it is filled on the right.
##
## In the two argument case, the string returned is a new mutable
## string (in particular not a part of any other object);
## it can be modified safely,
## and `MakeImmutable' may be safely applied to it.
##
DeclareAttribute( "String", IsObject );
DeclareOperation( "String", [ IsObject, IS_INT ] );
#############################################################################
##
#O FormattedString( <obj>, <nr> ) . . formatted string repres. of an object
##
#T is now obsolete
##
BIND_GLOBAL( "FormattedString", String );
#############################################################################
##
#O PrintObj( <obj> ) . . . . . . . . . . . . . . . . . . . . print an object
##
## `PrintObj' prints information about the object <obj>.
## This information is in general more detailed as that obtained from
## `ViewObj',
## but still it need not be sufficient to construct <obj> from it,
## and in general it is not {\GAP} readable.
##
## If <obj> has a name (see~"Name") then it will be printed via this name,
## and a domain without name is in many cases printed via its generators.
#T write that many domains (without name) are in fact GAP readable?
##
## {\GAP} readable data can be produced with `SaveObj'.
##
DeclareOperationKernel( "PrintObj", [ IsObject ], PRINT_OBJ );
# for technical reasons, this cannot be in `function.g' but must be after
# the declaration.
InstallMethod( PrintObj, "for an operation", true, [IsOperation], 0,
function ( op )
Print("<Operation \"",NAME_FUNC(op),"\">");
end);
#############################################################################
##
#O Display( <obj> ) . . . . . . . . . . . . . . . . . . . display an object
##
## Displays the object <obj> in a nice, formatted way which is easy to read
## (but might be difficult for machines to understand). The actual format
## used for this depends on the type of <obj>. Each method should print a
## newline character as last character.
##
DeclareOperation( "Display", [ IsObject ] );
#############################################################################
##
#O DisplayString( <obj> ) . . . . . . . . . . . . . . . . display an object
##
##
## Returns a string which could be used to
## display the object <obj> in a nice, formatted way which is easy to read
## (but might be difficult for machines to understand). The actual format
## used for this depends on the type of <obj>. Each method should include a
## newline character as last character.
##
DeclareOperation( "DisplayString", [ IsObject ] );
#############################################################################
##
#O IsInternallyConsistent( <obj> )
##
## For debugging purposes, it may be useful to check the consistency of
## an object <obj> that is composed from other (composed) objects.
##
## There is a default method of `IsInternallyConsistent', with rank zero,
## that returns `true'.
## So it is possible (and recommended) to check the consistency of
## subobjects of <obj> recursively by `IsInternallyConsistent'.
##
## (Note that `IsInternallyConsistent' is not an attribute.)
##
DeclareOperation( "IsInternallyConsistent", [ IsObject ] );
#############################################################################
##
#A IsImpossible( <obj> )
##
## For debugging purposes, it may be useful to install immediate methods
## that raise an error if an object lies in a filter which is impossible.
## For example, if a matrix is in the two fiters `IsOrdinaryMatrix' and
## `IsLieMatrix' then apparently something went wrong.
## Since we can install these immediate methods only for attributes
## (and not for the operation `IsInternallyConsistent'),
## we need such an attribute.
##
DeclareAttribute( "IsImpossible", IsObject );
#############################################################################
##
#O ExtRepOfObj( <obj> ) . . . . . . . external representation of an object
##
## returns the external representation of the object <obj>.
##
DeclareOperation( "ExtRepOfObj", [ IsObject ] );
#############################################################################
##
#O ObjByExtRep( <F>, <descr> ) . object in family <F> and ext. repr. <descr>
##
## creates an object in the family <F> which has the external
## representation <descr>.
##
DeclareOperation( "ObjByExtRep", [ IsFamily, IsObject ] );
#############################################################################
##
#O KnownAttributesOfObject( <object> ) . . . . . list of names of attributes
##
## returns a list of the names of the attributes whose values are known for
## <object>.
##
DeclareOperation( "KnownAttributesOfObject", [ IsObject ] );
#############################################################################
##
#O KnownPropertiesOfObject( <object> ) . . . . . list of names of properties
##
## returns a list of the names of the properties whose values are known for
## <object>.
##
DeclareOperation( "KnownPropertiesOfObject", [ IsObject ] );
#############################################################################
##
#O KnownTruePropertiesOfObject( <object> ) list of names of true properties
##
## returns a list of the names of the properties known to be `true' for
## <object>.
##
DeclareOperation( "KnownTruePropertiesOfObject", [ IsObject ] );
#############################################################################
##
#O CategoriesOfObject( <object> ) . . . . . . . list of names of categories
##
## returns a list of the names of the categories in which <object> lies.
##
DeclareOperation( "CategoriesOfObject", [ IsObject ] );
#############################################################################
##
#O RepresentationsOfObject( <object> ) . . list of names of representations
##
## returns a list of the names of the representations <object> has.
##
DeclareOperation( "RepresentationsOfObject", [ IsObject ] );
#############################################################################
##
#R IsPackedElementDefaultRep( <obj> )
##
## An object <obj> in this representation stores a related object as
## `<obj>![1]'.
## This representation is used for example for elements in f.p.~groups
## or f.p.~algebras, where the stored object is an element of a
## corresponding free group or algebra, respectively;
## it is also used for Lie objects created from objects with an associative
## multiplication.
##
DeclareRepresentation( "IsPackedElementDefaultRep", IsPositionalObjectRep,
[ 1 ] );
#############################################################################
##
#O PostMakeImmutable( <obj> ) clean-up after MakeImmutable
##
## This operation is called by the kernel immediately after making
## any COM_OBJ or POS_OBJ immutable using MakeImmutable
## It is intended that objects should have methods for this operation
## which make any appropriate subobjects immutable (eg list entries)
## other subobjects (eg MutableAttributes) need not be made immutable.
##
## A default method does nothing.
DeclareOperation( "PostMakeImmutable", [IsObject]);
#############################################################################
##
#O MemoryUsage( <obj> )
##
## <#GAPDoc Label="MemoryUsage">
## <ManSection>
## <Oper Name="MemoryUsage" Arg='obj'/>
##
## <Description>
## Returns the amount of memory in bytes used by the object <A>obj</A>
## and its subobjects. Note that in general, objects can reference
## each other in very difficult ways such that determining the memory
## usage is a recursive procedure. In particular, computing the memory
## usage of a complicated structure itself uses some additional memory,
## which is however no longer used after completion of this operation.
## This procedure descents into lists and records, positional and
## component objects, however it does not take into account the type
## and family objects! For functions, it only takes the memory usage of
## the function body, not of the local context the function wascreated
## in, although the function keeps a reference to that as well!
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MemoryUsage", [IsObject] );
DeclareGlobalFunction( "MU_ClearCache" );
DeclareGlobalFunction( "MU_AddToCache" );
DeclareGlobalFunction( "MU_Finalize" );
BIND_GLOBAL( "MEMUSAGECACHE", rec( ids := [], depth := 0 ) );
BIND_GLOBAL( "MU_MemPointer", GAPInfo.BytesPerVariable );
BIND_GLOBAL( "MU_MemBagHeader", 2 * GAPInfo.BytesPerVariable );
#############################################################################
##
#E
##
|