# 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 """ return [x for x in self.lower_covers_iterator(y)] def elements_of_the_rank_iterator(self,k): r""" Rertuns an iterator of the elements of rank k. INPUT: ``k``: an integer OUTPUT: an iterator of the elements of rank k. Examples:: sage: type(Poset(([0,1,2],[(0,1),(0,2)])).elements_of_the_rank_iterator(1)) sage: list(Poset(([0,1,2,3,4],[(0,1),(1,4),(0,2),(2,3),(3,4)])).elements_of_the_rank_iterator(1)) Traceback (most recent call last): ... ValueError: Poset is not ranked """ p = self r = p.rank_function() if p.is_ranked(): for a in p: if r(a) == k: yield a else: raise ValueError, "Poset is not ranked" def elements_of_the_rank(self,k): r""" Rertuns the list of the elements of rank k. INPUT: ``k``: an integer OUTPUT: a list of the elements of rank k. Examples:: sage: Poset(([0,1,2],[(0,1),(0,2)])).elements_of_the_rank(1) [1, 2] sage: Poset(([0,1,2,3,4],[(0,1),(1,4),(0,2),(2,3),(3,4)])).elements_of_the_rank(1) Traceback (most recent call last): ... ValueError: Poset is not ranked """ return [ a for a in self.elements_of_the_rank_iterator(k) ] def cardinality(self): """ Returns the number of elements in the poset.