# Ticket #11293: trac_11293-all-relations-poset.patch

File trac_11293-all-relations-poset.patch, 2.5 KB (added by rbeezer, 10 years ago)
• ## sage/combinat/posets/posets.py

```# HG changeset patch
# User Rob Beezer <beezer@ups.edu>
# Date 1304534650 25200
# Node ID 86367af255a984dfccacce996946644b972cb65e
# Parent  52179a365cc3f43af41bd9764c8adee89f9c19dd
11293: all relations of a poset

diff -r 52179a365cc3 -r 86367af255a9 sage/combinat/posets/posets.py```
 a for u,v,l in self._hasse_diagram.edge_iterator(): yield map(self._vertex_to_element,(u,v)) def relations(self): r""" Returns a list of all relations of the poset. OUTPUT: A list of pairs (each pair is a list), where the first element of the pair is less than the second element. Pairs are produced in a rough sort of lexicographic order, where earlier elements are from lower levels of the poset. EXAMPLES:: sage: Q = Poset({0:, 1:, 2:, 3:, 4:[]}) sage: Q.relations() [[1, 2], [1, 3], [1, 4], [0, 2], [0, 3], [0, 4], [2, 3], [2, 4], [3, 4]] AUTHOR: - Rob Beezer (2011-05-04) """ return [r for r in self.relations_iterator()] def relations_iterator(self): r""" Returns an iterator for all the relations of the poset. OUTPUT: A generator that produces pairs (each pair is a list), where the first element of the pair is less than the second element. Pairs are produced in a rough sort of lexicographic order, where earlier elements are from lower levels of the poset. EXAMPLES:: sage: Q = Poset({0:, 1:, 2:, 3:, 4:[]}) sage: type(Q.relations_iterator()) sage: [z for z in Q.relations_iterator()] [[1, 2], [1, 3], [1, 4], [0, 2], [0, 3], [0, 4], [2, 3], [2, 4], [3, 4]] AUTHOR: - Rob Beezer (2011-05-04) """ # Relies on vertices 0 to n-1 in the Hasse diagram being a # linear extension of the elements of the poset n = self._hasse_diagram.order() for i in range(n): for j in range(i+1, n): if self._hasse_diagram.is_less_than(i, j): yield [self._vertex_to_element(i), self._vertex_to_element(j)] def is_lequal(self, x, y): """ Returns True if x is less than or equal to y in the poset, and