[sage-combinat-devel] Re: [sage-devel] sage.combinat.combinat.combinations and sage.combinat.combination.Combinations
Dear Tim, On Tue, Jan 12, 2010 at 10:58:23PM +0800, Tim Joseph Dumol wrote: I've been wondering why sage.combinat.combinat.combinations still exists, when sage.combinat.combination.Combinations is much faster, being native Sage code, and thus not requiring GAP interfacing (also more reliable, I suppose). The huge speed differnce can be seen here: {{{ sage: timeit('[Combinations(range(i), j).list() for (i, j) in CartesianProduct(range(15), range(15))]') 5 loops, best of 3: 449 ms per loop sage: timeit('[combinations(range(i), j) for (i, j) in CartesianProduct(range(15), range(15))]') 5 loops, best of 3: 4.17 s per loop }}} `combinations` is 10x slower than `Combinations`. If compatibility needs to be maintained, `combinations(mset,k)` can be defiend as an alias to `Combinations(mset,k).list`. Thanks for the report! Could you please open a track ticket and send us a patch, with an alias as you suggest, and possibly a deprecation warning? Note: the following (dubious) feature advertised in 'combinations?' might be vaguely tricky to emulate: sage: mset = [d,a,v,i,d] sage: combinations(mset,3) ['add', 'adi', 'adv', 'aiv', 'ddi', 'ddv', 'div'] Thanks in advance! Best, Nicolas -- Nicolas M. Thiéry Isil nthi...@users.sf.net http://Nicolas.Thiery.name/ -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To post to this group, send email to sage-combinat-de...@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.
Re: [sage-combinat-devel] Re: Category Questions
Hi Jason! On Tue, Jan 12, 2010 at 12:19:36PM -0500, Jason Bandlow wrote: While working on this, I added a ``TestSuite(phi)`` test where ``phi`` is a TriangularModuleMorphism, mimicking what was done for DiagonalModuleMorphism. Good idea! Unfortunately, pickling fails. I don't really know where to start tracking this down... can you give me a pointer? phi is constructed from f, which itself can't be pickled: sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename(X) sage: Y = CombinatorialFreeModule(QQ, [1, 2, 3]); y = Y.basis() sage: f = lambda i: sum( y[j] for j in range(i,4) ) sage: loads(dumps(f)) Traceback (most recent call last): PicklingError: Can't pickle type 'function': attribute lookup __builtin__.function failed That's because functions are pickled by name; but the name of f is __main__.f. Pickles detects that there is no such function in the __main__module, and rightfully deduces that f could not be unpickled in a latter Sage session. Luckily, one can cheat-around this, faking f being picklable, by forcefully inserting it into __main__, as in: sage: import __main__; __main__.f = f Oh, and f should be defined with def, not lambda. sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename(X) sage: Y = CombinatorialFreeModule(QQ, [1, 2, 3]); y = Y.basis() sage: def f(i): sum( y[j] for j in range(i,4) ) sage: import __main__; __main__.f = f sage: loads(dumps(f)) function f at 0xbfbc9cc sage: phi = X.module_morphism(f, triangular=True, codomain = Y) sage: TestSuite(phi).run() See the first example of TriangularModuleMorphism. Altogether, whenever possible, I try to use standard sage functions (like factorial) for such building blocks in tests. Here is a handy trick, which involves a bit of magic in sum_of_terms (it's a morphism, and therefore * is function composition): sage: f = Y.sum_of_terms * range sage: f(5) B[0] + B[1] + B[2] + B[3] + B[4] sage: loads(dumps(f)) A map to X Cheers, Nicolas -- Nicolas M. Thiéry Isil nthi...@users.sf.net http://Nicolas.Thiery.name/ -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To post to this group, send email to sage-combinat-de...@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.
Re: [sage-combinat-devel] Re: [sage-devel] sage.combinat.combinat.combinations and sage.combinat.combination.Combinations
Dear Tim, dear sage-combinat, The huge speed differnce can be seen here: {{{ sage: timeit('[Combinations(range(i), j).list() for (i, j) in CartesianProduct(range(15), range(15))]') 5 loops, best of 3: 449 ms per loop sage: timeit('[combinations(range(i), j) for (i, j) in CartesianProduct(range(15), range(15))]') 5 loops, best of 3: 4.17 s per loop }}} I've got the same {{{ sage: timeit('[Combinations(range(i),j).list() for (i,j) in CartesianProduct(range(15),range(15))]') 5 loops, best of 3: 539 ms per loop sage: timeit('[combinations(range(i),j) for (i,j) in CartesianProduct(range(15),range(15))]') 5 loops, best of 3: 3.32 s per loop }}} But it seems that combinations wrapped from GAP is quicker on special cases (especially when mset contains repetitions) {{{ sage: l = [1,1,2,3,4,4,5,6,7,8,8,8,8] sage: timeit('combinations(l,5)') 25 loops, best of 3: 10.3 ms per loop sage: timeit('Combinations(l,5).list()') 5 loops, best of 3: 83.7 ms per loop }}} Even in mean {{{ sage: l = [1,1,2,3,4,4,5,6,7,8,8,8,8] sage: timeit('[combinations(l,i) for i in range(13)]') 5 loops, best of 3: 106 ms per loop sage: timeit('[Combinations(l,i).list() for i in range(13)]') 5 loops, best of 3: 475 ms per loop }}} Vincent -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To post to this group, send email to sage-combinat-de...@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.
[sage-combinat-devel] Re: Partitions bug with max_slope?
On Jan 9, 3:58 am, Nicolas M. Thiery nicolas.thi...@u-psud.fr wrote: On Sat, Jan 09, 2010 at 10:53:30AM +0100, Vincent Delecroix wrote: I get the following with sage-4.3, is it normal to have [2, 1] and [1, 2] as partitions ? {{{ sage: for p in Partitions(3, max_slope=1): : print p : [3] [2, 1] [1, 2] [1, 1, 1] }}} Well, that's consistent with max_slope=1. Did you mean max_slope=-1? Of course, it would have been nicer to get an error (since the highest meaningful max_slope for a partition is 0). Hopefully we will be able to do that when the IntegerListsLex kernel will be rewritten (volunteers for that welcome!). While we're on this topic, here's a bug which I don't know if anyone has worked on recently: compare sage: Partitions(4, max_slope=-1).list() [[4], [3, 1]] to sage: Partitions(4, max_slope=-1, length=3).list() # doesn't work [[2, 1, 1]] See http://trac.sagemath.org/sage_trac/ticket/6538. -- John -- You received this message because you are subscribed to the Google Groups sage-combinat-devel group. To post to this group, send email to sage-combinat-de...@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.