Ticket #14730: trac_14730-canonical_label_posets-ts.patch

File trac_14730-canonical_label_posets-ts.patch, 2.3 KB (added by tscrim, 6 years ago)
  • sage/combinat/posets/posets.py

    # HG changeset patch
    # User Travis Scrimshaw <tscrim@ucdavis.edu>
    # Date 1371044516 25200
    # Node ID 479e4d2d7bd919bc08c1e397b0e53196f2e569ac
    # Parent 5c9af38764f55723ca1c4ef7c8db71826576a755
    #14730: added canonical_label() method.
    
    diff --git a/sage/combinat/posets/posets.py b/sage/combinat/posets/posets.py
    a b class FinitePoset(UniqueRepresentation,  
    26092609                           category=self.category(),
    26102610                           facade=self._is_facade)
    26112611
     2612    def canonical_label(self):
     2613        """
     2614        Return the unique poset on the labels `\{0, \ldots, n-1\}` (where `n`
     2615        is the number of elements in ``self``) that is isomorphic to ``self``
     2616        and invariant in the isomorphism class.
     2617
     2618        .. SEEALSO::
     2619
     2620            - :meth:`~sage.graphs.generic_graph.GenericGraph.canonical_label()`
     2621
     2622        EXAMPLES::
     2623
     2624            sage: P = Poset((divisors(12), attrcall("divides")), linear_extension=True, facade = False)
     2625            sage: P.list()
     2626            [1, 2, 3, 4, 6, 12]
     2627            sage: P.cover_relations()
     2628            [[1, 2], [1, 3], [2, 4], [2, 6], [3, 6], [4, 12], [6, 12]]
     2629            sage: Q = P.canonical_label()
     2630            sage: Q.list()
     2631            [0, 1, 2, 3, 4, 5]
     2632            sage: Q.cover_relations()
     2633            [[0, 2], [0, 3], [1, 5], [2, 4], [3, 1], [3, 4], [4, 5]]
     2634
     2635        As a facade::
     2636
     2637            sage: P = Poset((divisors(12), attrcall("divides")), facade = True, linear_extension=True)
     2638            sage: P.list()
     2639            [1, 2, 3, 4, 6, 12]
     2640            sage: P.cover_relations()
     2641            [[1, 2], [1, 3], [2, 4], [2, 6], [3, 6], [4, 12], [6, 12]]
     2642            sage: Q = P.canonical_label()
     2643            sage: Q.list()
     2644            [0, 1, 2, 3, 4, 5]
     2645            sage: Q.cover_relations()
     2646            [[0, 2], [0, 3], [1, 5], [2, 4], [3, 1], [3, 4], [4, 5]]
     2647        """
     2648        return FinitePoset(DiGraph(self._hasse_diagram).canonical_label(),
     2649                           elements=range(len(self._elements)),
     2650                           category=self.category(),
     2651                           facade=self._is_facade)
     2652
    26122653    def with_linear_extension(self, linear_extension):
    26132654        """
    26142655        Returns a copy of ``self`` with a different default linear extension