I'm sure someone else can give a better answer, but hopefully the below examples help a little.
On Sun, Oct 26, 2008 at 7:56 AM, Rolandb <[EMAIL PROTECTED]> wrote: > > Hi, > To learn SAGE takes a while, and good exercises are scarce. > It was mentioned before, but the site http://projecteuler.net/ is > interesting. The idea is to solve relatively simple mathematical > problems and the level is going up slowly. For instance group > operations, read/write to a file, speed are topics you will > encounter. > > Until now I solved 38 problems. Two questions arise: > 1. Suppose you have two functions: SLOW and FAST which return the > boolean True or False. > Is there a difference in speed between: > a. If SLOW and FAST: …. > b. If FAST and SLOW: …. > The second option seems faster because only SLOW is executed if > FAST==True. Or does the compiler checks this? sage: a = 1; b = 2 sage: if a == 1 and b == 2: print a ....: 1 sage: if a == 0 and c == 2: print a ....: sage: If it evaluated both it would give a "c is undefined" error. On the other hand, if you replace c by lambda then you will get an error, so the second expression is not ignored entirely. > > 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): ? One idea is you could try L = range(-2,3) M = Tuples(L,7) for m in M: k1 = m[0]; ...; k7 = m[6] ... There might be faster ways though. > > Roland > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---