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 b class Permutation_class(CombinatorialObj 
    24222422        return transitive_ideal(lambda x: x.permutohedron_succ(side), self) 
    24232423 
    24242424 
     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 
    24252471    ############ 
    24262472    # Patterns # 
    24272473    ############