Elements with labels.#
This module implements a simple wrapper class for pairs consisting of
an “element” and a “label”.
For representation purposes (repr
, str
, latex
), this pair
behaves like its label, while the element is “silent”.
However, these pairs compare like usual pairs (i.e., both element and
label have to be equal for two such pairs to be equal).
This is used for visual representations of graphs and posets
with vertex labels.
- class sage.misc.element_with_label.ElementWithLabel(element, label)[source]#
Bases:
object
Auxiliary class for showing/viewing
Poset`s with non-injective labelings. For hashing and equality testing the resulting object behaves like a tuple ``(element, label)`
. For any presentation purposes it appears just aslabel
would.EXAMPLES:
sage: # needs sage.combinat sage.graphs sage: P = Poset({1: [2,3]}) sage: labs = {i: P.rank(i) for i in range(1, 4)} sage: print(labs) {1: 0, 2: 1, 3: 1} sage: print(P.plot(element_labels=labs)) # needs sage.plot Graphics object consisting of 6 graphics primitives sage: # needs sage.combinat sage.graphs sage.modules sage: from sage.misc.element_with_label import ElementWithLabel sage: W = WeylGroup("A1") sage: P = W.bruhat_poset(facade=True) sage: D = W.domain() sage: v = D.rho() - D.fundamental_weight(1) sage: nP = P.relabel(lambda w: ElementWithLabel(w, w.action(v))) sage: list(nP) [(0, 0), (0, 0)]
>>> from sage.all import * >>> # needs sage.combinat sage.graphs >>> P = Poset({Integer(1): [Integer(2),Integer(3)]}) >>> labs = {i: P.rank(i) for i in range(Integer(1), Integer(4))} >>> print(labs) {1: 0, 2: 1, 3: 1} >>> print(P.plot(element_labels=labs)) # needs sage.plot Graphics object consisting of 6 graphics primitives >>> # needs sage.combinat sage.graphs sage.modules >>> from sage.misc.element_with_label import ElementWithLabel >>> W = WeylGroup("A1") >>> P = W.bruhat_poset(facade=True) >>> D = W.domain() >>> v = D.rho() - D.fundamental_weight(Integer(1)) >>> nP = P.relabel(lambda w: ElementWithLabel(w, w.action(v))) >>> list(nP) [(0, 0), (0, 0)]