I wrote a couple methods that relied on Partition(x).next() where 'x' is a list of Integers. Essentially I wanted to print out all the possible partitions of an Integer so I wrote the following functions:
def get_partitions(x,y=[]): """ Gets the list of the input argument and all the partitions of it that follow it lexicographically. See Partition.next(). """ if type(x) is Integer: return get_partitions([x]) y.append(x) x = Partition(x).next() if x != False: return get_partitions(x) return y def print_partitions(x): """ Prints the argument and the list of partitions that follow it lexicographically. """ part = get_partitions(x) for i in part: print i Now I would expect that when I call print_partitions(x), where 'x' is an Integer that SAGE would print all possible partitions of 'x'. The first time I call the function it works as expected. However, for each call after that, it seems to concatenate the results to the results of all the previous calls. Here's an example: sage: print_partitions(10) [10] [9, 1] [8, 2] [8, 1, 1] [7, 3] [7, 2, 1] [7, 1, 1, 1] [6, 4] [6, 3, 1] [6, 2, 2] [6, 2, 1, 1] [6, 1, 1, 1, 1] [5, 5] [5, 4, 1] [5, 3, 2] [5, 3, 1, 1] [5, 2, 2, 1] [5, 2, 1, 1, 1] [5, 1, 1, 1, 1, 1] [4, 4, 2] [4, 4, 1, 1] [4, 3, 3] [4, 3, 2, 1] [4, 3, 1, 1, 1] [4, 2, 2, 2] [4, 2, 2, 1, 1] [4, 2, 1, 1, 1, 1] [4, 1, 1, 1, 1, 1, 1] [3, 3, 3, 1] [3, 3, 2, 2] [3, 3, 2, 1, 1] [3, 3, 1, 1, 1, 1] [3, 2, 2, 2, 1] [3, 2, 2, 1, 1, 1] [3, 2, 1, 1, 1, 1, 1] [3, 1, 1, 1, 1, 1, 1, 1] [2, 2, 2, 2, 2] [2, 2, 2, 2, 1, 1] [2, 2, 2, 1, 1, 1, 1] [2, 2, 1, 1, 1, 1, 1, 1] [2, 1, 1, 1, 1, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] sage: print_partitions(5) [10] [9, 1] [8, 2] [8, 1, 1] [7, 3] [7, 2, 1] [7, 1, 1, 1] [6, 4] [6, 3, 1] [6, 2, 2] [6, 2, 1, 1] [6, 1, 1, 1, 1] [5, 5] [5, 4, 1] [5, 3, 2] [5, 3, 1, 1] [5, 2, 2, 1] [5, 2, 1, 1, 1] [5, 1, 1, 1, 1, 1] [4, 4, 2] [4, 4, 1, 1] [4, 3, 3] [4, 3, 2, 1] [4, 3, 1, 1, 1] [4, 2, 2, 2] [4, 2, 2, 1, 1] [4, 2, 1, 1, 1, 1] [4, 1, 1, 1, 1, 1, 1] [3, 3, 3, 1] [3, 3, 2, 2] [3, 3, 2, 1, 1] [3, 3, 1, 1, 1, 1] [3, 2, 2, 2, 1] [3, 2, 2, 1, 1, 1] [3, 2, 1, 1, 1, 1, 1] [3, 1, 1, 1, 1, 1, 1, 1] [2, 2, 2, 2, 2] [2, 2, 2, 2, 1, 1] [2, 2, 2, 1, 1, 1, 1] [2, 2, 1, 1, 1, 1, 1, 1] [2, 1, 1, 1, 1, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] [5] [4, 1] [3, 2] [3, 1, 1] [2, 2, 1] [2, 1, 1, 1] [1, 1, 1, 1, 1] Notice that the second function call displays the partitions of 10 before displaying the expected partitions of 5. This behavior occurs when I use just the get_partitions() function. The print_partitions() relies on that function so I think the problem is in get_partitions() or in the Partition(x).next() function. Does anyone see the problem? Thanks. -Jake (mekaj) --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~----------~----~----~----~------~----~------~--~---