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)#
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: 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)) Graphics object consisting of 6 graphics primitives 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)]