| | 2425 | def right_permutohedron_interval_iterator(self, other) : |
| | 2426 | r""" |
| | 2427 | Returns an iterator on the permutations (represented as integer |
| | 2428 | lists) belonging to the right permutohedron interval where `self` |
| | 2429 | is the minimal element and `other`, the maximal. |
| | 2430 | """ |
| | 2431 | if len(self) != len(other) : |
| | 2432 | raise ValueError,\ |
| | 2433 | "len(%s) and len(%s) must be equal" %(self, other) |
| | 2434 | if not self.permutohedron_lequal(other) : |
| | 2435 | raise ValueError,\ |
| | 2436 | "%s must be lower or equal than %s for the right permutohedron order"\ |
| | 2437 | %(self, other) |
| | 2438 | from sage.graphs.digraph import DiGraph |
| | 2439 | d = DiGraph() |
| | 2440 | d.add_vertices(xrange(1, len(self) + 1)) |
| | 2441 | d.add_edges([(j + 1, i + 1) for (i, j) in self.inverse().inversions()]) |
| | 2442 | d.add_edges([(other[i], other[j]) for i in xrange(len(other) - 1)\ |
| | 2443 | for j in xrange(i, len(other)) if other[i] < other[j]]) |
| | 2444 | from sage.graphs.linearextensions import LinearExtensions |
| | 2445 | return LinearExtensions(d) |
| | 2446 | |
| | 2447 | def right_permutohedron_interval(self, other) : |
| | 2448 | r""" |
| | 2449 | Returns the list of the permutations belonging to the right |
| | 2450 | permutohedron interval where `self` is the minimal element and |
| | 2451 | `other`, the maximal. |
| | 2452 | |
| | 2453 | EXAMPLES:: |
| | 2454 | |
| | 2455 | sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) |
| | 2456 | [[2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 4, 1, 5, 3], [2, 4, 5, 1, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] |
| | 2457 | |
| | 2458 | TESTS:: |
| | 2459 | |
| | 2460 | sage: Permutation([]).right_permutohedron_interval(Permutation([])) |
| | 2461 | [[]] |
| | 2462 | sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) |
| | 2463 | [[3, 1, 2]] |
| | 2464 | sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) |
| | 2465 | [[1, 3, 2, 4], [1, 3, 4, 2], [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1]] |
| | 2466 | sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) |
| | 2467 | [[2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 4, 1, 5, 3], [2, 4, 5, 1, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] |
| | 2468 | """ |
| | 2469 | return [Permutation(p) for p in self.right_permutohedron_interval_iterator(other)] |
| | 2470 | |