[sage-support] rational exponents in SAGE
Can someone please add support for evaluating say 2^(3/4) or 7^(5/3). --~--~-~--~~~---~--~~ 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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: [sage-devel] Re: [sage-support] Re: sage and sudoku
- Original Message - From: Timothy Clemans [EMAIL PROTECTED] def magicsquare_normal_odd(n): r Generates nth odd normal magic square for n greater than 1 using de la Loubere's method. EXAMPLES: sage: magicsquare_normal_odd(1) [8 1 6] [3 5 7] [4 9 2] sage: magicsquare_normal_odd(2) [17 24 1 8 15] [23 5 7 14 16] [ 4 6 13 20 22] [10 12 19 21 3] [11 18 25 2 9] --skip-- That can be done in Python in one line, def Siamese_magic_square(n): return [[(i+j+(n+1)/2)%n*n+(i+2*j+1)%n+1 for j in range(n)] for i in range(n)] For example, Siamese_magic_square(3) [[8, 1, 6], [3, 5, 7], [4, 9, 2]] Siamese_magic_square(5) [[17, 24, 1, 8, 15], [23, 5, 7, 14, 16], [4, 6, 13, 20, 22], [10, 12, 19, 21, 3], [11, 18, 25, 2, 9]] Alec Mihailovs http://mihailovs.com/Alec/ --~--~-~--~~~---~--~~ 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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: [sage-devel] Re: [sage-support] Re: sage and sudoku
Wow! Now thats cool. I'm going to time test them. Thanks On 2/3/07, Alec Mihailovs [EMAIL PROTECTED] wrote: - Original Message - From: Timothy Clemans [EMAIL PROTECTED] def magicsquare_normal_odd(n): r Generates nth odd normal magic square for n greater than 1 using de la Loubere's method. EXAMPLES: sage: magicsquare_normal_odd(1) [8 1 6] [3 5 7] [4 9 2] sage: magicsquare_normal_odd(2) [17 24 1 8 15] [23 5 7 14 16] [ 4 6 13 20 22] [10 12 19 21 3] [11 18 25 2 9] --skip-- That can be done in Python in one line, def Siamese_magic_square(n): return [[(i+j+(n+1)/2)%n*n+(i+2*j+1)%n+1 for j in range(n)] for i in range(n)] For example, Siamese_magic_square(3) [[8, 1, 6], [3, 5, 7], [4, 9, 2]] Siamese_magic_square(5) [[17, 24, 1, 8, 15], [23, 5, 7, 14, 16], [4, 6, 13, 20, 22], [10, 12, 19, 21, 3], [11, 18, 25, 2, 9]] Alec Mihailovs http://mihailovs.com/Alec/ --~--~-~--~~~---~--~~ 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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: [sage-devel] Re: [sage-support] Re: sage and sudoku
From: Timothy Clemans [EMAIL PROTECTED] Wow! Now thats cool. I'm going to time test them. Thanks I had some trouble with copying and pasting your procedure in SAGE (because I use it in Windows through cygwin and rxvt with Unix line endings and my email has Windows line endings and convert it to Unix by creating a text file and then using dos2unix on it seemed to be too much trouble). So I modified your procedure to plain Python by changing ^ to ** in 2 places and changing the end line in it to return square. After that I did timing in IDLE using the print_timing decorator from http://www.daniweb.com/code/snippet368.html . It appears that Siamese_magic_square is about 4-5 times faster than magicsquare_normal_odd. Actually, if the time is important, it can be made even faster by changing the j range (that reduces the number of operations). In SAGE form that looks like def Siamese_magic_square(n): return matrix([[j%n*n+(j+j-i)%n+1 for j in range(i+(1-n)/2,i+(n+1)/2)] for i in range(n)]) That makes it about 6-7 times faster than magicsquare_normal_odd (in IDLE, without matrix - I didn't test that in SAGE and I don't know how the matrix construction works there - in particular, whether adding the size of the matrix would make it faster.) Alec Mihailovs http://mihailovs.com/Alec/ --~--~-~--~~~---~--~~ 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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---