[sage-support] Re: Error message on installing Sage
On Sun, Dec 14, 2008 at 11:20 PM, mabshoff wrote: > > > > On Dec 14, 7:30 pm, "William Stein" wrote: >> On Sun, Dec 14, 2008 at 12:20 PM, Spencer wrote: > > Hi, > >> > I'm running Sage 3.2.1 on Ubuntu 8.10 (hardware: Macbook 3,1 Santa >> > Rosa with Intel Core 2 Duo). On installing Sage and starting it up for >> > the first time I get the message: >> >> > "WARNING! This Sage install was built on a machine that supports >> > instructions that are not available on this computer. Sage will >> > likely fail with ILLEGAL INSTRUCTION errors! The following processor >> > flags were on the build machine but are not on this computer: >> >> > mmxext 3dnowext 3dnow > > This indicates that the Intel CPU you use doesn't support AMD specific > extensions :). I don't think we use any 3dnow[ext] or mmxext > instructions, so feel free to delete local/lib/sage-flags.txt to get > rid of this message. There is still a small chance that you might see > an "illegal instruction - aborting" situation, but I doubt it will > happen. Just for the record, on Saturday I was anxious and I took exactly that same Opteron binary and ran it on our new Intel Xeon-based server. Things mostly worked, but I *did* get segfaults when I created matrices then pressed [tab] to do tab completion via readline. I built sage from scratch on that machine, and the version built from scratch did *not* have these problems. Thus it's entirely possible that the user will find that their sage is not working right. > >> > Emailhttp://groups.google.com/group/sage-supportfor help." >> >> > So I have followed the instructions there to come here for help. How >> > do I resolve this issue? >> >> You may want to try building Sage from source. To do so, follow >> the directions at >> >>http://sagemath.org/download-source.html >> >> Otherwise, are you using 32 or 64-bit Ubuntu? What is the output >> of cat /proc/cpuinfo on your computer? If you're using 32-bit Ubuntu, >> this is the binary you should use: >>http://sagemath.org/bin/linux/32bit/sage-3.2.1-ubuntu_32bit-xeon-i686... > > Yeah, building from source will avoid this altogether and you will get > optimum performance for your specific CPU this way. Definitely do that if you can. It's not supposed to be difficult (it just takes a lot of cputime), and you can let us know if it doesn't work, since we want to know. -- William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Error message on installing Sage
On Dec 14, 7:30 pm, "William Stein" wrote: > On Sun, Dec 14, 2008 at 12:20 PM, Spencer wrote: Hi, > > I'm running Sage 3.2.1 on Ubuntu 8.10 (hardware: Macbook 3,1 Santa > > Rosa with Intel Core 2 Duo). On installing Sage and starting it up for > > the first time I get the message: > > > "WARNING! This Sage install was built on a machine that supports > > instructions that are not available on this computer. Sage will > > likely fail with ILLEGAL INSTRUCTION errors! The following processor > > flags were on the build machine but are not on this computer: > > > mmxext 3dnowext 3dnow This indicates that the Intel CPU you use doesn't support AMD specific extensions :). I don't think we use any 3dnow[ext] or mmxext instructions, so feel free to delete local/lib/sage-flags.txt to get rid of this message. There is still a small chance that you might see an "illegal instruction - aborting" situation, but I doubt it will happen. > > Emailhttp://groups.google.com/group/sage-supportfor help." > > > So I have followed the instructions there to come here for help. How > > do I resolve this issue? > > You may want to try building Sage from source. To do so, follow > the directions at > > http://sagemath.org/download-source.html > > Otherwise, are you using 32 or 64-bit Ubuntu? What is the output > of cat /proc/cpuinfo on your computer? If you're using 32-bit Ubuntu, > this is the binary you should use: > http://sagemath.org/bin/linux/32bit/sage-3.2.1-ubuntu_32bit-xeon-i686... Yeah, building from source will avoid this altogether and you will get optimum performance for your specific CPU this way. > William Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: help solving equations
On Sun, Dec 14, 2008 at 10:53 PM, John H Palmieri wrote: > > I have some code which generates a bunch of expressions of the form > Sum (n_i a_i) where each n_i is an integer and each a_i is an unknown > in a field, and I'm most interested in the case when the field is GF > (p). Set each of these expressions equal to zero. What's the best way > in Sage to solve the resulting system of equations for the a_i's? > > For example, I can't figure out how to use 'solve', because I can't > figure out how to insist that the variables be treated as elements of > a particular field. Is the only way to convert everything to a matrix > equation? Is p big or small? Just to be clear above, are you *really* just solving a system of linear equations modulo p? William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] help solving equations
I have some code which generates a bunch of expressions of the form Sum (n_i a_i) where each n_i is an integer and each a_i is an unknown in a field, and I'm most interested in the case when the field is GF (p). Set each of these expressions equal to zero. What's the best way in Sage to solve the resulting system of equations for the a_i's? For example, I can't figure out how to use 'solve', because I can't figure out how to insist that the variables be treated as elements of a particular field. Is the only way to convert everything to a matrix equation? John --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Trying to find partitions of a pair of integers.
"Mike Hansen" writes: > Hello, > > On Sun, Dec 14, 2008 at 4:04 PM, green351 wrote: > > > > Hi, > > This is my first time emailing with a question and my first time > > trying to use Sage (I'm a complete programming dunce). I'm trying to > > do the following: > > Given the tuple (p,q) in Z x Z and integer n I need to count the > > number of integer-tuple solutions to the following > > (p,q)=(a_1,b_1)+...+(a_n,b_n) subject to the following conditions > > - (a_i,b_i) \neq (a_j,b_j) for i, j different > > - a_i, b_i >= -1 > > - a_i+b_i > 0 > > What you're trying to count is the number of multiset partitions. I > haven't written any code to do this in Sage, but I've been meaning > too. So now is a good time to start :-) > > For an interesting reference on this is Knuth's Art of Computer > Programming Volume 4, Fascicle 3 (b). Using the formula found in > http://www.emis.de/journals/HOA/IJMMS/22/1213.pdf , we get the > following bit of Sage code if you check out aldor combinat, the iso-experiment branch via svn://svn.risc.uni-linz.ac.at/hemmecke/combinat/branches you will find a literal implementation of Knuth's algorithm (with correction :-)). Please ask if you are interested in further directions. Martin --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Trying to find partitions of a pair of integers.
On Sun, 14 Dec 2008 at 05:09PM -0800, Mike Hansen wrote: > On Sun, Dec 14, 2008 at 4:04 PM, green351 wrote: > > This is my first time emailing with a question and my first time > > trying to use Sage (I'm a complete programming dunce). I'm trying to > > do the following: > > Given the tuple (p,q) in Z x Z and integer n I need to count the > > number of integer-tuple solutions to the following > > (p,q)=(a_1,b_1)+...+(a_n,b_n) subject to the following conditions > > - (a_i,b_i) \neq (a_j,b_j) for i, j different > > - a_i, b_i >= -1 > > - a_i+b_i > 0 > > What you're trying to count is the number of multiset partitions. I > haven't written any code to do this in Sage, but I've been meaning > too. So now is a good time to start :-) If you want to play with Haskell, there's an article in the Monad Reader on multiset partitions: http://www.haskell.org/sitewiki/images/d/dd/TMR-Issue8.pdf Dan -- --- Dan Drake - KAIST Department of Mathematical Sciences --- http://mathsci.kaist.ac.kr/~drake signature.asc Description: Digital signature
[sage-support] Re: Error message on installing Sage
On Sun, Dec 14, 2008 at 12:20 PM, Spencer wrote: > > I'm running Sage 3.2.1 on Ubuntu 8.10 (hardware: Macbook 3,1 Santa > Rosa with Intel Core 2 Duo). On installing Sage and starting it up for > the first time I get the message: > > "WARNING! This Sage install was built on a machine that supports > instructions that are not available on this computer. Sage will > likely fail with ILLEGAL INSTRUCTION errors! The following processor > flags were on the build machine but are not on this computer: > > mmxext 3dnowext 3dnow > > Email http://groups.google.com/group/sage-support for help." > > So I have followed the instructions there to come here for help. How > do I resolve this issue? You may want to try building Sage from source. To do so, follow the directions at http://sagemath.org/download-source.html Otherwise, are you using 32 or 64-bit Ubuntu? What is the output of cat /proc/cpuinfo on your computer? If you're using 32-bit Ubuntu, this is the binary you should use: http://sagemath.org/bin/linux/32bit/sage-3.2.1-ubuntu_32bit-xeon-i686-Linux.tar.gz William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Trying to find partitions of a pair of integers.
Hello, On Sun, Dec 14, 2008 at 4:04 PM, green351 wrote: > > Hi, > This is my first time emailing with a question and my first time > trying to use Sage (I'm a complete programming dunce). I'm trying to > do the following: > Given the tuple (p,q) in Z x Z and integer n I need to count the > number of integer-tuple solutions to the following > (p,q)=(a_1,b_1)+...+(a_n,b_n) subject to the following conditions > - (a_i,b_i) \neq (a_j,b_j) for i, j different > - a_i, b_i >= -1 > - a_i+b_i > 0 What you're trying to count is the number of multiset partitions. I haven't written any code to do this in Sage, but I've been meaning too. So now is a good time to start :-) For an interesting reference on this is Knuth's Art of Computer Programming Volume 4, Fascicle 3 (b). Using the formula found in http://www.emis.de/journals/HOA/IJMMS/22/1213.pdf , we get the following bit of Sage code @cached_function def p(*n): r = len(n) s = sum(n) if s == 0: return 1 result = 0 for k in range(1, s+1): for l in IntegerVectors(k, r, outer=n): nml = tuple(a-b for a,b in zip(n,l)) g = gcd(l) result += sigma(g)/g*sum(l)*p(*nml) return result / s You call it just like p(a,b). We can duplicate Table A-1 in the Knuth fascicle: sage: [ [p(i,j) for j in range(7)] for i in range(6)] [[1, 1, 2, 3, 5, 7, 11], [1, 2, 4, 7, 12, 19, 30], [2, 4, 9, 16, 29, 47, 77], [3, 7, 16, 31, 57, 97, 162], [5, 12, 29, 57, 109, 189, 323], [7, 19, 47, 97, 189, 339, 589]] We can also get the specific values cited in the paper with the formula: sage: p(10,5) 3804 sage: p(9,8) 13715 sage: p(10,8) 21893 sage: p(4,1,1) 38 We can also use this to count the number of distinct factorizations of an integer. For example, we can write 12 as 12*1, 6*2, 4*3, or 3*2*2. sage: p(*[exponent for prime,exponent in factor(12)]) 4 I'll try to add native support for multiset partitions here into Sage in the near future. Hope that helps, --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Trying to find partitions of a pair of integers.
Hi, This is my first time emailing with a question and my first time trying to use Sage (I'm a complete programming dunce). I'm trying to do the following: Given the tuple (p,q) in Z x Z and integer n I need to count the number of integer-tuple solutions to the following (p,q)=(a_1,b_1)+...+(a_n,b_n) subject to the following conditions - (a_i,b_i) \neq (a_j,b_j) for i, j different - a_i, b_i >= -1 - a_i+b_i > 0 I would appreciate if someone could help me out even if it doesn't take the final conditions into account. I've tried doing something like X = CartesianProduct(OrderedPartitions(5,2), OrderedPartitions(4,2)); X.count() or X = CartesianProduct(Partitions(5,length=2), Partitions(4,length=2)); X.count() but the first one counts too much and the second one too little Ok thanks in advance. sonny --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: local matrix assignment behaves as global
http://spreadsheets.google.com/ver?key=pCwvGVwSMxTzT6E2xNdo5fA&t=1229242768198000&pt=1229242748198000&diffWidget=true&s=AJVazbV8wTRdqv-uJ-exdnVEO7tqiCikJQ answer below, quote here: = The following behavior is very confusing to me. I define a program def test(a): b=a b = a^2 return b Then if I assign x = 2 and then execute test(x) 4 I get x squared and x 2 Thus x is unchanged. However suppose now that I want the same on a single element of a matrix and define def testmatrix(a): b=a b[1,1] = a[1,1]^2 return b Then I set m = identity_matrix(2)*2 Thus: m [2 0] [0 2] and testmatrix(m) [2 0] [0 4] However now also m is changed ! m [2 0] [0 4] Outside the program ! = Well, m should be [2 0] [0 2] the same after the program execution. The program is solved changing the program to def testmatrix(a): b=a.copy() b[1,1] = a[1,1]^2 return b However, it is confusing to have a function with local variable a that returns another variable b locally equal to a and changes the value of a outside the function. = hi, i've read your bug report. Well, I can only tell you that you did the right things, observations and your solution with .copy() is also correct. The thing is, that python (and other languages like java) use references as their variables. References point to objects in memory. An object is a certain instance of a class in memory. In your integer number example, you are *changing* the reference when you square a (you create a new integer instance), whereas in your matrix example, the matrix stays the *same* - only something inside is changed. This has nothing to do with local variables, since the aren't really local in both cases. Also, if you want to have the reference behavior for integers as with the matrix, create a list/vector and pass the vector, manipulate the "0"th element and return the list/vector. If you have further questions about python (this is actually only about python) you can ask on the http://groups.google.com/group/sage-support list. harald --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Error message on installing Sage
I'm running Sage 3.2.1 on Ubuntu 8.10 (hardware: Macbook 3,1 Santa Rosa with Intel Core 2 Duo). On installing Sage and starting it up for the first time I get the message: "WARNING! This Sage install was built on a machine that supports instructions that are not available on this computer. Sage will likely fail with ILLEGAL INSTRUCTION errors! The following processor flags were on the build machine but are not on this computer: mmxext 3dnowext 3dnow Email http://groups.google.com/group/sage-support for help." So I have followed the instructions there to come here for help. How do I resolve this issue? --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: show(P,xmin=0) shows area below Y=0 line
On Sun, Dec 14, 2008 at 2:44 AM, Sand Wraith wrote: > > Hi! > > I want to plot a few lines: > > Line=line([]) > for i in [-10..3]: >Line+=line([[0,0],[1.1+i/10,1.1]]) > > and show it: > > show(Line,xmin=0) > > but output contains area below X axis. :-\ You want show(Line,ymin=0,xmin=0) -- William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: The image of a matrix
On Dec 14, 2:44 am, daveloeffler wrote: > That > > On Dec 13, 6:50 pm, Jason Grout wrote: > > > That sounds the best way. We'll make kernel_left/right (along with > > left/right_kernel) the global functions, and people can do > > > kernel = left_kernel > > > in their init.sage or at the beginning of their session, if they want. > > \begin{devils-advocate} > That's inviting people to write code which will then silently and > mysteriously not work as soon as they pass it on to someone else. > \end{devils-advocate} > > David Why silently and mysteriously? If 'kernel' is not defined in Sage (as is being suggested), then if I put 'kernel = left_kernel' in my init.sage, write some code using 'kernel', and then give it to someone else, then it will fail with an appropriate error message. It's worse if we define kernel to be right_kernel and suggest that people redefine it to be left_kernel in their init.sage file. --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: The image of a matrix
I think the following is also a source of frustration: v=vector([1,2,3]) rm=matrix(v)#This will be a row matrix cm=v.transpose()#This will be a column matrix. What would the convention be for this one? This came up in another discussion: http://groups.google.com/group/sage-support/browse_thread/thread/24fa62276520b799/2ba996a4f9d18545?hl=en&lnk=gst&q=vector+to+matrix#2ba996a4f9d18545 Keep the good work. On Dec 14, 3:48 am, mabshoff wrote: > On Dec 14, 2:44 am, daveloeffler wrote: > > > > > That > > > On Dec 13, 6:50 pm, Jason Grout wrote: > > > > That sounds the best way. We'll make kernel_left/right (along with > > > left/right_kernel) the global functions, and people can do > > > > kernel = left_kernel > > > > in their init.sage or at the beginning of their session, if they want. > > > \begin{devils-advocate} > > That's inviting people to write code which will then silently and > > mysteriously not work as soon as they pass it on to someone else. > > \end{devils-advocate} > > > David > > Yes, people will do dumb things if they are given a chance, but at > least it will not be code in the Sage library that causes any more > trouble. I guess someone has to get burned a couple times to realize > that customization can be evil. If this happens a lot it won't be long > before we ask bug submitters to provide their init.sage along with the > code in question that causes trouble. > > Cheers, > > Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Lines won't show on coordinate axes
On Dec 14, 7:16 am, "David Joyner" wrote: > I'm guessing the asex are rendered last, so the lines get overwritten. > You can use > > show(a1+a2+l1+l2+p,axes=False) > > or > > a1=arrow((0,0),(3,1),rgbcolor=(0,1,1)) > a2=arrow((0,0),(-3.5,2.5),rgbcolor=(0,0,1)) > l1=line([(0,0),(-3.5,0)],rgbcolor=(1,0,0), thickness=5) > l2=line([(0,0),(0,2.5)],rgbcolor=(0,1,0), thickness=5) > p=point((3,1),rgbcolor=(0,0,1),pointsize=30) > show(a1+a2+l1+l2+p) > > > > On Sat, Dec 13, 2008 at 11:32 PM, louie wrote: > > > I'm trying to plot a couple of vectors (using arrows) and their > > projections on the x- and y- axes (using lines): > > > a1=arrow((0,0),(3,1),rgbcolor=(0,1,1)) > > a2=arrow((0,0),(-3.5,2.5),rgbcolor=(0,0,1)) > > l1=line([(0,0),(-3.5,0)],rgbcolor=(1,0,0)) > > l2=line([(0,0),(0,2.5)],rgbcolor=(0,1,0)) > > p=point((3,1),rgbcolor=(0,0,1),pointsize=30) > > show(a1+a2+l1+l2+p) > > > The arrows went fine but the lines didn't show up. Curiously: > > a) if I use arrows instead, they do show up. > > b) if I plot a line somewhere else, like line([(0,-1), > > (-3.5,0)],rgbcolor=(1,0,0)), it works > > > I'm running Sage Version 3.2, Release Date: 2008-11-20 in case it > > helps. > > > Thanks in advance for any help > > > - Louie -- Hide quoted text - > > - Show quoted text - OK, disabling the axes shows me the lines are there so, after trying thickness=3 i got a better result. I'll keep in mind the layer thing for the next time. I appreciate your help David. - Louie - --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Change to a local variable affects the variable outside the program
Hello Giovanni, most of the time it does "the right thing". If you really need call by value, whatever type the argument is, you can (must) copy the argument yourself. The copy module provides the methods copy.copy() and copy.deepcopy() for this situation. With best regards, Lars --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Lines won't show on coordinate axes
I'm guessing the asex are rendered last, so the lines get overwritten. You can use show(a1+a2+l1+l2+p,axes=False) or a1=arrow((0,0),(3,1),rgbcolor=(0,1,1)) a2=arrow((0,0),(-3.5,2.5),rgbcolor=(0,0,1)) l1=line([(0,0),(-3.5,0)],rgbcolor=(1,0,0), thickness=5) l2=line([(0,0),(0,2.5)],rgbcolor=(0,1,0), thickness=5) p=point((3,1),rgbcolor=(0,0,1),pointsize=30) show(a1+a2+l1+l2+p) On Sat, Dec 13, 2008 at 11:32 PM, louie wrote: > > I'm trying to plot a couple of vectors (using arrows) and their > projections on the x- and y- axes (using lines): > > a1=arrow((0,0),(3,1),rgbcolor=(0,1,1)) > a2=arrow((0,0),(-3.5,2.5),rgbcolor=(0,0,1)) > l1=line([(0,0),(-3.5,0)],rgbcolor=(1,0,0)) > l2=line([(0,0),(0,2.5)],rgbcolor=(0,1,0)) > p=point((3,1),rgbcolor=(0,0,1),pointsize=30) > show(a1+a2+l1+l2+p) > > The arrows went fine but the lines didn't show up. Curiously: > a) if I use arrows instead, they do show up. > b) if I plot a line somewhere else, like line([(0,-1), > (-3.5,0)],rgbcolor=(1,0,0)), it works > > I'm running Sage Version 3.2, Release Date: 2008-11-20 in case it > helps. > > Thanks in advance for any help > > - Louie - > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Change to a local variable affects the variable outside the program
Thank you Lars, I had the feeling that this behavior should be something related to Python, but I was impressed by the inconsistency, because in my first example everything worked as (I) intended. So, if this is a feature of Python I have to study it carefully ! Best regards Giovanni On Dec 14, 1:05 pm, Lars Fischer wrote: > Hello Giovanni, > > you have hit one of my favorite Python Pitfalls: Python does always > call by value, but sometimes it behaves like call by reference . > > The explanation is hidden in a footnote in the tutorial. Please see > "Defining Functions" in "More Control Flow Tools" in the Python > Tutorial:http://docs.python.org/tutorial/controlflow.html#defining-functions > > "The actual parameters (arguments) to a function call are introduced > in the local symbol table of the called function when it is called; > thus, arguments are passed using call by value (where the value is > always an object reference, not the value of the object). [1] When a > function calls another function, a new local symbol table is created > for that call." > > And the footnotes is: > [1] Actually, call by object reference would be a better description, > since if a mutable object is passed, the caller will see any changes > the callee makes to it (items inserted into a list). > > With best regards, > Lars --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Change to a local variable affects the variable outside the program
Hello Giovanni, you have hit one of my favorite Python Pitfalls: Python does always call by value, but sometimes it behaves like call by reference . The explanation is hidden in a footnote in the tutorial. Please see "Defining Functions" in "More Control Flow Tools" in the Python Tutorial: http://docs.python.org/tutorial/controlflow.html#defining-functions "The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call." And the footnotes is: [1] Actually, call by object reference would be a better description, since if a mutable object is passed, the caller will see any changes the callee makes to it (items inserted into a list). With best regards, Lars --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: The image of a matrix
On Dec 14, 2:44 am, daveloeffler wrote: > That > > On Dec 13, 6:50 pm, Jason Grout wrote: > > > That sounds the best way. We'll make kernel_left/right (along with > > left/right_kernel) the global functions, and people can do > > > kernel = left_kernel > > > in their init.sage or at the beginning of their session, if they want. > > \begin{devils-advocate} > That's inviting people to write code which will then silently and > mysteriously not work as soon as they pass it on to someone else. > \end{devils-advocate} > > David Yes, people will do dumb things if they are given a chance, but at least it will not be code in the Sage library that causes any more trouble. I guess someone has to get burned a couple times to realize that customization can be evil. If this happens a lot it won't be long before we ask bug submitters to provide their init.sage along with the code in question that causes trouble. Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] show(P,xmin=0) shows area below Y=0 line
Hi! I want to plot a few lines: Line=line([]) for i in [-10..3]: Line+=line([[0,0],[1.1+i/10,1.1]]) and show it: show(Line,xmin=0) but output contains area below X axis. :-\ --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: The image of a matrix
That On Dec 13, 6:50 pm, Jason Grout wrote: > That sounds the best way. We'll make kernel_left/right (along with > left/right_kernel) the global functions, and people can do > > kernel = left_kernel > > in their init.sage or at the beginning of their session, if they want. \begin{devils-advocate} That's inviting people to write code which will then silently and mysteriously not work as soon as they pass it on to someone else. \end{devils-advocate} David --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Change to a local variable affects the variable outside the program
The following behavior is very confusing to me. I define a program def test(a): b=a b = a^2 return b Then if I assign x = 2 and then execute test(x) 4 I get x squared and x unchanged: x 2 However suppose now that I want the same on a single element of a matrix and define def testmatrix(a): b=a b[1,1] = a[1,1]^2 return b Then I set m = identity_matrix(2)*2 Thus: m [2 0] [0 2] Now with testmatrix(m) [2 0] [0 4] I get what I wanted, but... now also m is changed ! m [2 0] [0 4] Outside the program ! I expected m to be [2 0] [0 2] the same before the program executed. The problem is solved by changing the program to def testmatrix(a): b=a.copy() b[1,1] = a[1,1]^2 return b However, it is confusing to have a function with local variable a that returns another variable b locally equal to a and changes the value of a outside the function. -- Giovanni --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---