# Ticket #12569: trac_12569-permutohedron_intervals-sg.patch

File trac_12569-permutohedron_intervals-sg.patch, 2.9 KB (added by giraudo, 15 months ago)

Tested on Sage 4.8, combinat branch

• ## sage/combinat/permutation.py

```# HG changeset patch
# User Samuele Giraudo <Samuele.Giraudo@univ-mlv.fr>
# Date 1329993066 -3600
# Node ID 71237df16d6b8478d35f0cf8caf04a43ca787f85
# Parent  77d3e03c1260faf5914ac7fc86677f75bbba55b4
#12569: add a method to compute permutohedron intervals

diff --git a/sage/combinat/permutation.py b/sage/combinat/permutation.py```
 a class Permutation_class(CombinatorialObj return transitive_ideal(lambda x: x.permutohedron_succ(side), self) def right_permutohedron_interval_iterator(self, other) : r""" Returns an iterator on the permutations (represented as integer lists) belonging to the right permutohedron interval where `self` is the minimal element and `other`, the maximal. """ if len(self) != len(other) : raise ValueError,\ "len(%s) and len(%s) must be equal" %(self, other) if not self.permutohedron_lequal(other) : raise ValueError,\ "%s must be lower or equal than %s for the right permutohedron order"\ %(self, other) from sage.graphs.digraph import DiGraph d = DiGraph() d.add_vertices(xrange(1, len(self) + 1)) d.add_edges([(j + 1, i + 1) for (i, j) in self.inverse().inversions()]) d.add_edges([(other[i], other[j]) for i in xrange(len(other) - 1)\ for j in xrange(i, len(other)) if other[i] < other[j]]) from sage.graphs.linearextensions import LinearExtensions return LinearExtensions(d) def right_permutohedron_interval(self, other) : r""" Returns the list of the permutations belonging to the right permutohedron interval where `self` is the minimal element and `other`, the maximal. EXAMPLES:: sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) [[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]] TESTS:: sage: Permutation([]).right_permutohedron_interval(Permutation([])) [[]] sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) [[3, 1, 2]] sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) [[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]] sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) [[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]] """ return [Permutation(p) for p in self.right_permutohedron_interval_iterator(other)] ############ # Patterns # ############