ogposets.GrSet
- class rewalt.ogposets.GrSet(*elements)
Bases:
objectClass for sets of elements of an oriented graded poset, graded by their dimension.
Objects of the class behave as sets; several methods of the set class are supported. However the data is stored in a way that allows fast access to elements of a given dimension.
- Parameters
elements (
El) – Any number of elements.
Examples
We create an instance by listing elements; repetitions do not count.
>>> test = GrSet(El(0, 2), El(0, 2), El(0, 3), El(2, 0), El(3, 1)) >>> test GrSet(El(0, 2), El(0, 3), El(2, 0), El(3, 1)) >>> len(test) 4
We can access the subsets of elements of given dimensions with indexer operators. These support slice syntax.
>>> test[0] GrSet(El(0, 2), El(0, 3)) >>> test[0:3] GrSet(El(0, 2), El(0, 3), El(2, 0))
The iterator for graded sets goes through the elements in increasing dimension and, for each dimension, in increasing position.
>>> for x in test: ... print(x) ... El(0, 2) El(0, 3) El(2, 0) El(3, 1)
We can add and remove elements.
>>> test.remove(El(0, 3)) >>> test GrSet(El(0, 2), El(2, 0), El(3, 1)) >>> test.add(El(1, 1)) >>> test GrSet(El(0, 2), El(1, 1), El(2, 0), El(3, 1))
Set methods such as union, difference, and intersection are available with the same syntax.
Methods
add(element)Adds a single element.
copy()Returns a copy of the graded set.
difference(other)Returns the difference of the graded set with another graded set.
intersection(*others)Returns the intersection of the graded set with other graded sets.
isdisjoint(other)Returns whether the graded set is disjoint from another.
issubset(other)Returns whether the graded set is a subset of another.
remove(element)Removes a single element.
union(*others)Returns the union of the graded set with other graded sets.
Attributes
Returns the list of elements in increasing dimension, and, dimensionwise, in increasing position.
Returns a Python set containing the same elements.
Returns the maximal dimension in which the graded set is not empty, or -1 if it is empty.
Returns the list of dimensions in which the graded set is not empty.
- property grades
Returns the list of dimensions in which the graded set is not empty.
- Returns
grades – The list of dimensions in which the graded set is not empty.
- Return type
list[int]
- property dim
Returns the maximal dimension in which the graded set is not empty, or -1 if it is empty.
- Returns
dim – The maximal dimension in which the graded set is not empty.
- Return type
int
- property as_set
Returns a Python set containing the same elements.
- Returns
as_set – A Python set containing the same elements.
- Return type
set[El]
- property as_list
Returns the list of elements in increasing dimension, and, dimensionwise, in increasing position.
- Returns
as_list – A list containing the same elements.
- Return type
list[El]
- union(*others)
Returns the union of the graded set with other graded sets.
- intersection(*others)
Returns the intersection of the graded set with other graded sets.
- difference(other)
Returns the difference of the graded set with another graded set.
- issubset(other)
Returns whether the graded set is a subset of another.
- Parameters
other (
GrSet) – Another graded set.- Returns
issubset –
Trueif and only self is a subset of other.- Return type
bool