On Thu, Nov 19, 2009 at 01:00:11PM +0100, Florent hivert wrote: > > Is there any particular reason why when one tries to iterate over > > IntegerVectors(k,n) one gets the vectors represented as lists and not > > tuples?
Nothing really but a historical choice to port things from MuPAD-Combinat as quickly as possible. Also, internally the algorithm uses lists because it needs to modify them. > > The only difference between the two that I can think of is > > that lists are mutable and tuples aren't. I cannot see why being > > mutable is an advantage. On the other hand, if the vectors weren't > > mutable one could use them as keys to a dictionary e.g.: > > > > sage: p = MixedIntegerLinearProgram() > > sage: v = p.new_variable() > > sage: p.set_objective(sum(v[i] for i in IntegerVectors(2,3))) > > > > Now I need to write > > sage: p.set_objective(sum(v[tuple(i)] for i in IntegerVectors(2,3))) > > Mutable is an advantage in the sense that if you want to modify the vector you > have to make a copy of it. (This sentence looks like a tautology !). There is > some plan to make the result type (and parent) configurable. Note that someone > could find it more natural to get the result not as a double but rather as a > true vector as we can get using > sage: v = vector([1,2,3]); v > (1, 2, 3) > sage: type(v) > <type 'sage.modules.vector_integer_dense.Vector_integer_dense'> > sage: v.parent() > Ambient free module of rank 3 over the principal ideal domain Integer Ring > I'm not sure why we (maybe = Mike Hansen) finally chose list. I don't think > one is better. We should allow both. We definitely should allow to specify any constructor for list-like objects (list, tuple, vector). Depending on the context, you may want the result to be hashable, to have further properties (like being a vector and doing linear algebra), that is mutable, ... Now what should be the default? I am not very keen on vector; we are really returning a raw combinatorial object, that will typically be used for creating exponent vectors of polynomials. And this should be done consistently with all other related things (compositions, ...). Florent: combinatorial factories are becoming more desirable every day :-) Cheers, Nicolas -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org