2008/10/28 Robert Bradshaw <[EMAIL PROTECTED]>:
>
> On Oct 27, 2008, at 2:15 PM, cesarnda wrote:
>
>> is there a way to do that in a fancy way in pure cython?
>
> No, the cartesian_product_iterator will still work in the context of
> Sage though, as will Georg's solution.
>
> If I needed to do this loop super fast for an arbitrary number of k,
> I might either implement it as a map ZZ -> {-2,...,2}^n and iterate
> over ZZ, or implement a manual "add and carry."

Here's a similar alternative:

sage: A = AbelianGroup([2]*3); A
Multiplicative Abelian Group isomorphic to C2 x C2 x C2
sage: for a in A:
    print [[5,6][i] for i in a.list()]
....:
[5, 5, 5]
[5, 5, 6]
[5, 6, 5]
[5, 6, 6]
[6, 5, 5]
[6, 5, 6]
[6, 6, 5]
[6, 6, 6]

John

>
>>
>> On Oct 26, 4:02 pm, Georg <[EMAIL PROTECTED]> wrote:
>>> Hi Roland,
>>>
>>>> 2.      Is there a more elegant way for:
>>>> for k1 in range(-2,3):
>>>>  for k2 in range(-2,3):
>>>>   for k3 in range(-2,3):
>>>>    for k4 in range(-2,3):
>>>>     for k5 in range(-2,3):
>>>>      for k6 in range(-2,3):
>>>>       for k7 in range(-2,3): ?
>>>
>>>> Roland
>>>
>>> if you want to stay in pure python do this:
>>>
>>> Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
>>> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more
>>> information.>>> for x in [(k1,k2) for k1 in range(-2,3) for k2 in
>>> range(-2,3)]:
>>>
>>> ...     print x
>>>
>>> Georg
>> >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to