Ticket #11446: trac_11446-outline_of_partition-pod.v2.patch

File trac_11446-outline_of_partition-pod.v2.patch, 4.9 KB (added by chapoton, 9 years ago)
  • sage/combinat/partition.py

    # HG changeset patch
    # User Paul-Olivier Dehaye <paulolivier@gmail.com>
    # Date 1307696477 -7200
    # Node ID 3fb7f9134720f325d6339164012e2d764baf774c
    # Parent  65af49f242a58913af7c89daca6e485b56c4851f
    #11446: Computes the outline of a partition, the graph of its Russian diagram
    
    diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
    a b class Partition_class(CombinatorialObjec 
    26482648        """
    26492649        return self.dimension()**2/factorial(self.size())
    26502650
     2651    def outline(self, variable = sage.symbolic.ring.var("x")):
     2652        r"""
     2653        Returns the outline of the partition ``self``.
     2654
     2655        This is a piecewise linear function, normalized so that the area
     2656        under the partition [1] is 2.
     2657
     2658        INPUT:
     2659
     2660        - ``self`` -- a partition
     2661
     2662        - variable -- a variable (default: x)
     2663
     2664        EXAMPLES::
     2665
     2666            sage: [Partition([5,4]).outline()(x=i) for i in range(-10,11)]
     2667            [10, 9, 8, 7, 6, 5, 6, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     2668
     2669            sage: Partition([]).outline()
     2670            abs(x)
     2671
     2672            sage: Partition([1]).outline()
     2673            abs(x - 1) + abs(x + 1) - abs(x)
     2674
     2675            sage: y=sage.symbolic.ring.var("y")
     2676            sage: Partition([6,5,1]).outline(variable=y)
     2677            abs(y - 3) - abs(y - 2) + abs(y - 1) - abs(y + 3) + abs(y + 4) - abs(y + 5) + abs(y + 6)
     2678
     2679        TESTS::
     2680
     2681            sage: integrate(Partition([1]).outline()-abs(x),(x,-10,10))
     2682            2
     2683
     2684        """
     2685        outside_contents = [self.content(*c) for c in self.outside_corners()]
     2686        inside_contents = [self.content(*c) for c in self.corners()]
     2687        return sum(abs(variable+c) for c in outside_contents)\
     2688                       -sum(abs(variable+c) for c in inside_contents)
     2689
     2690
     2691
    26512692
    26522693##################################################
    26532694
    def RestrictedPartitions(n, S, k=None): 
    29673008    integer n into sums with k summands with the summands of the
    29683009    partition coming from the set S. If k is not given all restricted
    29693010    partitions for all k are returned.
    2970    
     3011
    29713012    Wraps GAP's RestrictedPartitions.
    2972    
     3013
    29733014    EXAMPLES::
    2974    
     3015
    29753016        sage: RestrictedPartitions(5,[3,2,1])
    29763017        doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    29773018        See http://trac.sagemath.org/5478 for details.
    2978         Partitions of 5 restricted to the values [1, 2, 3] 
     3019        Partitions of 5 restricted to the values [1, 2, 3]
    29793020        sage: RestrictedPartitions(5,[3,2,1]).list()
    29803021        [[3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]
    29813022        sage: RestrictedPartitions(5,[3,2,1],4)
    class RestrictedPartitions_nsk(Combinato 
    30333074    def __repr__(self):
    30343075        """
    30353076        EXAMPLES::
    3036        
     3077
    30373078            sage: RestrictedPartitions(5,[3,2,1]).__repr__()
    30383079            doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    30393080            See http://trac.sagemath.org/5478 for details.
    3040             'Partitions of 5 restricted to the values [1, 2, 3] '
     3081            doctest:...: DeprecationWarning: RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.
     3082            See http://trac.sagemath.org/5478 for details.
     3083            'Partitions of 5 restricted to the values [1, 2, 3]'
    30413084            sage: RestrictedPartitions(5,[3,2,1],4).__repr__()
    30423085            'Partitions of 5 restricted to the values [1, 2, 3] of length 4'
    30433086        """
    3044         string = "Partitions of %s restricted to the values %s "%(self.n, self.S)
     3087        string = "Partitions of %s restricted to the values %s"%(self.n, self.S)
    30453088        if self.k is not None:
    3046             string += "of length %s" % self.k
     3089            string += " of length %s" % self.k
    30473090        return string
    30483091
    30493092    def list(self):
    class RestrictedPartitions_nsk(Combinato 
    30523095        integer n into sums with k summands with the summands of the
    30533096        partition coming from the set `S`. If k is not given all
    30543097        restricted partitions for all k are returned.
    3055        
     3098
    30563099        Wraps GAP's RestrictedPartitions.
    3057        
     3100
    30583101        EXAMPLES::
    3059        
     3102
    30603103            sage: RestrictedPartitions(8,[1,3,5,7]).list()
    30613104            doctest:...: DeprecationWarning: RestrictedPartitions is deprecated; use Partitions with the parts_in keyword instead.
    30623105            See http://trac.sagemath.org/5478 for details.
    3063             doctest:...: DeprecationWarning: RestrictedPartitions_nsk is deprecated; use Partitions with the parts_in keyword instead.
    3064             See http://trac.sagemath.org/5478 for details.
    30653106            [[7, 1], [5, 3], [5, 1, 1, 1], [3, 3, 1, 1], [3, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]
    30663107            sage: RestrictedPartitions(8,[1,3,5,7],2).list()
    30673108            [[7, 1], [5, 3]]