ogposets.GrSet

class rewalt.ogposets.GrSet(*elements)

Bases: object

Class 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

as_list

Returns the list of elements in increasing dimension, and, dimensionwise, in increasing position.

as_set

Returns a Python set containing the same elements.

dim

Returns the maximal dimension in which the graded set is not empty, or -1 if it is empty.

grades

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]

add(element)

Adds a single element.

Parameters

element (El) – The element to add.

remove(element)

Removes a single element.

Parameters

element (El) – The element to remove.

union(*others)

Returns the union of the graded set with other graded sets.

Parameters

*others (GrSet) – Any number of graded sets.

Returns

union – The union of the graded set with all the given others.

Return type

GrSet

intersection(*others)

Returns the intersection of the graded set with other graded sets.

Parameters

*others (GrSet) – Any number of graded sets.

Returns

intersection – The intersection of the graded set with all the given others.

Return type

GrSet

difference(other)

Returns the difference of the graded set with another graded set.

Parameters

other (GrSet) – Another graded set.

Returns

difference – The difference between the two graded sets.

Return type

GrSet

issubset(other)

Returns whether the graded set is a subset of another.

Parameters

other (GrSet) – Another graded set.

Returns

issubsetTrue if and only self is a subset of other.

Return type

bool

isdisjoint(other)

Returns whether the graded set is disjoint from another.

Parameters

other (GrSet) – Another graded set.

Returns

isdisjointTrue if and only self and other are disjoint.

Return type

bool

copy()

Returns a copy of the graded set.

Returns

copy – A copy of the graded set.

Return type

GrSet