On Wed, 05 May 2010 at 05:38PM -0700, Eva wrote: > My question: what is the best way to enumerate vectors in Z^d (for an > arbitrary d that my function will be passed as a parameter, so I don't > know its value in advance) starting with 0, then going through all > vectors with just a single 1 and all other entries 0, then going > through all vectors with a single -1 and all other entries 0, then > going through all vectors with two 1's or -1's and all other entries > 0, etc.? Ideally I could find the next vector in my sequence of > vectors to consider one-at-a-time, so that I don't generate more > vectors than I need to, but I suspect it will be easier to generate > vectors in the sequence in batches, such as all vectors with a single > 1 entry, then all vectors with a single -1 entry, and so on.
One starting point is IntegerVectors -- try IntegerVectors? in a Sage session. You can do IntegerVectors(5,3) to get an iterator for all vectors of nonnegative integers of length 3 that sum to 5. Others may have better ideas, but my first guess is that you'll work with IntegerVectors(n,d) (for n = 1, 2, 3...) and for each vector, look at all the nonzero entries and flip the signs in all possible ways. For a integer vector v, you can find the nonzero entries with something like [i for i, val in enumerate(v) if val != 0] and then call Subsets on that list and flip signs: for indices in Subsets([i for i, val in enumerate(v) if val != 0]): w = v[:] for index in indices: w[index] *= -1 # now do your coset test stuff There are probably much better ways to do this, but the above will work, I think. You can also ask your question in the sage-combinat-devel group. Dan -- --- Dan Drake ----- http://mathsci.kaist.ac.kr/~drake -------
signature.asc
Description: Digital signature