Ticket #13236: trac_13236-iterator_of_homogeneous_component_of_ranked_poset-nu.patch

File trac_13236-iterator_of_homogeneous_component_of_ranked_poset-nu.patch, 2.0 KB (added by numata, 10 years ago)
  • sage/combinat/posets/posets.py

    # HG changeset patch
    # User Yasuhide NUMATA <numata-y@wakhok.ac.jp>
    # Date 1342066638 -32400
    # Node ID 63d68b9993ac48232e5454e8418e793787ffdac3
    # Parent  e45c6e9f665ecb23ddc77d8af4876b9b925f972a
    #13236: add methods of homogeneous part of a ranked poset
    
    diff --git a/sage/combinat/posets/posets.py b/sage/combinat/posets/posets.py
    a b  
    19191919        """
    19201920        return [x for x in self.lower_covers_iterator(y)]
    19211921
     1922    def elements_of_the_rank_iterator(self,k):
     1923        r"""
     1924        Rertuns an iterator of the elements of rank k.
     1925       
     1926        INPUT: ``k``: an integer
     1927   
     1928        OUTPUT: an iterator of the elements of rank k.
     1929
     1930        Examples::
     1931
     1932            sage: type(Poset(([0,1,2],[(0,1),(0,2)])).elements_of_the_rank_iterator(1))
     1933            <type 'generator'>
     1934       
     1935            sage: list(Poset(([0,1,2,3,4],[(0,1),(1,4),(0,2),(2,3),(3,4)])).elements_of_the_rank_iterator(1))
     1936            Traceback (most recent call last):
     1937            ...
     1938            ValueError: Poset is not ranked
     1939
     1940        """
     1941        p = self
     1942        r = p.rank_function()
     1943        if p.is_ranked():
     1944            for a in p:
     1945                if r(a) == k:
     1946                    yield a
     1947        else:
     1948            raise ValueError, "Poset is not ranked"
     1949
     1950    def elements_of_the_rank(self,k):
     1951        r"""
     1952        Rertuns the list of the elements of rank k.
     1953       
     1954        INPUT: ``k``: an integer
     1955   
     1956        OUTPUT: a list of the elements of rank k.
     1957
     1958        Examples::
     1959
     1960            sage: Poset(([0,1,2],[(0,1),(0,2)])).elements_of_the_rank(1)
     1961            [1, 2]
     1962       
     1963            sage: Poset(([0,1,2,3,4],[(0,1),(1,4),(0,2),(2,3),(3,4)])).elements_of_the_rank(1)
     1964            Traceback (most recent call last):
     1965            ...
     1966            ValueError: Poset is not ranked
     1967
     1968        """
     1969        return [ a for a in self.elements_of_the_rank_iterator(k) ]
     1970
    19221971    def cardinality(self):
    19231972        """
    19241973        Returns the number of elements in the poset.