[sage-support] Re: OT: Sage notebook as a interface for python
[cc-ing to sage-support, please answer on sage-support rather than sage-devel] You can also use one of the following tricks. - you can make a cell python by typing %python in the first line of the cell. - towards the top of every notebook worksheet, there are four drop-down menus: [File...][Action...][Data...][sage] You can use the last of these menus and change 'sage' to 'python'. The same works to change your worksheet to 'gap', 'maxima', or many other choices. Samuel Volker Braun wrote: > > Next time try sage-support for support questions. > > sage: preparser(False) > sage: 3/2 > 1 > > > > > On Thursday, October 23, 2014 2:10:00 PM UTC+1, Jori Mantysalo wrote: >> >> Off-topic. Sorry. >> >> Has anyone used Sage notebook as a GUI for python only? I was asked to >> make some easy way for 15-25 students to use python, some python >> libraries >> and some example materials. >> >> Sage kind of is not logical answer for this. But if ipython can't handle >> this, what else to do? Can Sage be configured to not preparse input, i.e. >> answer to "1/2" just like plain python would? >> >> -- >> Jori Mäntysalo >> > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Arbitrary precision linear programming
Mike wrote: > > I'd like to be able to do linear programming to arbitrary precision. The > documentation that I've found claims that both the glpk and PPL solvers > should do this, but I haven't been able to get either to work. > > As an example, the following code prints c to high precision, but the > solutions only to 12 digits. Where should I look for guidance? > Note: this seeks to maximize x+y given that 3x<=1 and 3y<=1, so the > solution is (1/3, 1/3) > > Mike M > > R=RealField(100) > c=Matrix(R, 2, 1, [-1, -1]) > G=Matrix(R, 2, 2, [3, 0, 0, 3]) > h=Matrix(R, 2, 1, [1, 1]) > print c # To check the precision being used by "print" > print > > sol=linear_program(c,G,h) > print sol['x'] > sol=linear_program(c,G,h, solver='glpk') > print sol['x'] > sol=linear_program(c,G,h, solver='PPL') > print sol['x'] > > This reminds me of a recent discussion about precision and number of correct digits through a calculation: https://groups.google.com/d/topic/sage-devel/ypcOxPlv__s/discussion -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: How to create and use lists of variables?
You can define a function which takes a list or tuple as an argument, and then you can iterate through its elements, with tests if you like. sage: def sum_elements_whose_square_is_one(x): : return sum(a for a in x if a^2 == 1) Then for example: sage: sum_elements_whose_square_is_one([1,2,3,4,-1,]) 0 If that does not answer your question, please give a concrete example of a function you want to define. Or even wrong code that shows what you want. smoha...@gmail.com wrote: I am a primitive sage user and I want to produce a function of n variables (x[1],x[2],...,x[n]), in nested 'for' loops. I've searched in sage's documentation, but I have still 2 problems: 1. How to define a list of variables, such that I can use its items, as independent variables, in loops. The loops are needed because the function is made up of sums of multiplications of clauses of these variables? 2. How to simplify the result of loops according to some extra conditions, such as x[i]^2==1 ? > > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: OT: Sage notebook as a interface for python
> > > - towards the top of every notebook worksheet, > there are four drop-down menus: > > [File...][Action...][Data...][sage] > > You can use the last of these menus and > change 'sage' to 'python'. > >> >>> And you can make it so that the default for the worksheet is this system in general somewhere, I think. This is a very sensible way to teach Python (as long as you don't need certain things like turtle graphics) and have recommended many people do it this way. I essentially taught a class in Python programming this summer using Sage as well, though we did use the Sage-specific things since it was a class for professional mathematicians. Good luck! -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Strange error
I am running the following Python example from the book "Learning Python", from Mark Lutz and David Ascher, but Sage is returning a TypeError after presenting the correct response. Can anyone explain me why? I've found this very strange. sage: class Commuter: : def __init__(self, val): : self.val = val : def __add__(self, other): : print "add", self.val, other : def __radd__(self, other): : print "radd", self.val, other : sage: x = Commuter(88) sage: y = Commuter(99) sage: x + 1 add 88 1 sage: 1 + y radd 99 1 --- TypeError Traceback (most recent call last) in () > 1 Integer(1) + y /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__add__ (build/cythonized/sage/structure/element.c:14696)() /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:8323)() TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and '' -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Strange error
The short answer is that mathematical objects in Sage don't define addition by implementing __add__ and __radd__ by hand. If you want to learn about them make sure to not add Sage objects (like Sage integers). E.g. int(1) + y would work. On Thursday, October 23, 2014 7:46:02 PM UTC+1, João Alberto Ferreira wrote: > > I am running the following Python example from the book "Learning > Python", from Mark Lutz and David Ascher, but Sage is returning a > TypeError after presenting the correct response. Can anyone explain me > why? I've found this very strange. > > sage: class Commuter: > : def __init__(self, val): > : self.val = val > : def __add__(self, other): > : print "add", self.val, other > : def __radd__(self, other): > : print "radd", self.val, other > : > sage: x = Commuter(88) > sage: y = Commuter(99) > sage: x + 1 > add 88 1 > sage: 1 + y > radd 99 1 > --- > > TypeError Traceback (most recent call > last) > in () > > 1 Integer(1) + y > > /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/element.so > > > in sage.structure.element.RingElement.__add__ > (build/cythonized/sage/structure/element.c:14696)() > > /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/coerce.so > > > in sage.structure.coerce.CoercionModel_cache_maps.bin_op > (build/cythonized/sage/structure/coerce.c:8323)() > > TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and > '' > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
Re: [sage-support] Re: Strange error
Or type Integer = int to make Sage integers the usual Python integers in that session. On Thu, Oct 23, 2014 at 11:54 AM, Volker Braun wrote: > The short answer is that mathematical objects in Sage don't define addition > by implementing __add__ and __radd__ by hand. If you want to learn about > them make sure to not add Sage objects (like Sage integers). E.g. int(1) + y > would work. > > > > On Thursday, October 23, 2014 7:46:02 PM UTC+1, João Alberto Ferreira wrote: >> >> I am running the following Python example from the book "Learning >> Python", from Mark Lutz and David Ascher, but Sage is returning a >> TypeError after presenting the correct response. Can anyone explain me >> why? I've found this very strange. >> >> sage: class Commuter: >> : def __init__(self, val): >> : self.val = val >> : def __add__(self, other): >> : print "add", self.val, other >> : def __radd__(self, other): >> : print "radd", self.val, other >> : >> sage: x = Commuter(88) >> sage: y = Commuter(99) >> sage: x + 1 >> add 88 1 >> sage: 1 + y >> radd 99 1 >> >> --- >> TypeError Traceback (most recent call >> last) >> in () >> > 1 Integer(1) + y >> >> >> /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/element.so >> in sage.structure.element.RingElement.__add__ >> (build/cythonized/sage/structure/element.c:14696)() >> >> >> /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/coerce.so >> in sage.structure.coerce.CoercionModel_cache_maps.bin_op >> (build/cythonized/sage/structure/coerce.c:8323)() >> >> TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and >> '' > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/d/optout. -- William Stein Professor of Mathematics University of Washington http://wstein.org -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
Re: [sage-support] Re: Strange error
Or, in the notebook/cell server/cloud, choose "python" from the drop-down menu for system and just do this example in Python! Lots of options. > Or type > > Integer = int > > to make Sage integers the usual Python integers in that session. > > On Thu, Oct 23, 2014 at 11:54 AM, Volker Braun > wrote: > > The short answer is that mathematical objects in Sage don't define > addition > > by implementing __add__ and __radd__ by hand. If you want to learn about > > them make sure to not add Sage objects (like Sage integers). E.g. int(1) > + y > > would work. > > > > > > > > On Thursday, October 23, 2014 7:46:02 PM UTC+1, João Alberto Ferreira > wrote: > >> > >> I am running the following Python example from the book "Learning > >> Python", from Mark Lutz and David Ascher, but Sage is returning a > >> TypeError after presenting the correct response. Can anyone explain me > >> why? I've found this very strange. > >> > >> sage: class Commuter: > >> : def __init__(self, val): > >> : self.val = val > >> : def __add__(self, other): > >> : print "add", self.val, other > >> : def __radd__(self, other): > >> : print "radd", self.val, other > >> : > >> sage: x = Commuter(88) > >> sage: y = Commuter(99) > >> sage: x + 1 > >> add 88 1 > >> sage: 1 + y > >> radd 99 1 > >> > >> > --- > >> TypeError Traceback (most recent call > >> last) > >> in () > >> > 1 Integer(1) + y > >> > >> > >> > /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/element.so > > > >> in sage.structure.element.RingElement.__add__ > >> (build/cythonized/sage/structure/element.c:14696)() > >> > >> > >> > /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/coerce.so > > > >> in sage.structure.coerce.CoercionModel_cache_maps.bin_op > >> (build/cythonized/sage/structure/coerce.c:8323)() > >> > >> TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and > >> '' > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "sage-support" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to sage-support+unsubscr...@googlegroups.com. > > To post to this group, send email to sage-support@googlegroups.com. > > Visit this group at http://groups.google.com/group/sage-support. > > For more options, visit https://groups.google.com/d/optout. > > > > -- > William Stein > Professor of Mathematics > University of Washington > http://wstein.org > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
Re: [sage-support] Re: Strange error
Ok, thank you all! I was curious just because, due to the error, I did not expect a result. On Thursday, October 23, 2014 5:28:46 PM UTC-2, kcrisman wrote: > > Or, in the notebook/cell server/cloud, choose "python" from the drop-down > menu for system and just do this example in Python! Lots of options. > > >> Or type >> >> Integer = int >> >> to make Sage integers the usual Python integers in that session. >> >> On Thu, Oct 23, 2014 at 11:54 AM, Volker Braun > > wrote: >> > The short answer is that mathematical objects in Sage don't define >> addition >> > by implementing __add__ and __radd__ by hand. If you want to learn >> about >> > them make sure to not add Sage objects (like Sage integers). E.g. >> int(1) + y >> > would work. >> > >> > >> > >> > On Thursday, October 23, 2014 7:46:02 PM UTC+1, João Alberto Ferreira >> wrote: >> >> >> >> I am running the following Python example from the book "Learning >> >> Python", from Mark Lutz and David Ascher, but Sage is returning a >> >> TypeError after presenting the correct response. Can anyone explain me >> >> why? I've found this very strange. >> >> >> >> sage: class Commuter: >> >> : def __init__(self, val): >> >> : self.val = val >> >> : def __add__(self, other): >> >> : print "add", self.val, other >> >> : def __radd__(self, other): >> >> : print "radd", self.val, other >> >> : >> >> sage: x = Commuter(88) >> >> sage: y = Commuter(99) >> >> sage: x + 1 >> >> add 88 1 >> >> sage: 1 + y >> >> radd 99 1 >> >> >> >> >> --- >> >> TypeError Traceback (most recent call >> >> last) >> >> in () >> >> > 1 Integer(1) + y >> >> >> >> >> >> >> /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/element.so >> >> >> >> in sage.structure.element.RingElement.__add__ >> >> (build/cythonized/sage/structure/element.c:14696)() >> >> >> >> >> >> >> /usr/local/Sagemath/sage-6.3/local/lib/python2.7/site-packages/sage/structure/coerce.so >> >> >> >> in sage.structure.coerce.CoercionModel_cache_maps.bin_op >> >> (build/cythonized/sage/structure/coerce.c:8323)() >> >> >> >> TypeError: unsupported operand parent(s) for '+': 'Integer Ring' and >> >> '' >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "sage-support" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an >> > email to sage-support...@googlegroups.com . >> > To post to this group, send email to sage-s...@googlegroups.com >> . >> > Visit this group at http://groups.google.com/group/sage-support. >> > For more options, visit https://groups.google.com/d/optout. >> >> >> >> -- >> William Stein >> Professor of Mathematics >> University of Washington >> http://wstein.org >> > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Arbitrary precision linear programming
On Wednesday, 22 October 2014 21:38:39 UTC-6, Mike wrote: > > I'd like to be able to do linear programming to arbitrary precision. The > documentation that I've found claims that both the glpk and PPL solvers > should do this, but I haven't been able to get either to work. > > As an example, the following code prints c to high precision, but the > solutions only to 12 digits. Where should I look for guidance? > Note: this seeks to maximize x+y given that 3x<=1 and 3y<=1, so the > solution is (1/3, 1/3) > > Mike M > > R=RealField(100) > c=Matrix(R, 2, 1, [-1, -1]) > G=Matrix(R, 2, 2, [3, 0, 0, 3]) > h=Matrix(R, 2, 1, [1, 1]) > print c # To check the precision being used by "print" > print > > sol=linear_program(c,G,h) > print sol['x'] > sol=linear_program(c,G,h, solver='glpk') > print sol['x'] > sol=linear_program(c,G,h, solver='PPL') > print sol['x'] > > My "straightforward" simplex method for teaching can handle this one correctly: http://sagecell.sagemath.org/?z=eJxljUGLwjAQhe-F_oeHe0kgLa2ee60XhVL3JoukSdwOGxNJIui_31hkYRHeDLx58_HGbjTS9mSsZm3T8LJQ3V6mQHc2CqwFWoFjlVfVfuVw-z_MOm4EmkWb58P8TudZ2Gsgl6CAD3x6qNmoH6TZ4BqMokjeYTLkvnGLRmN6YLUAqxdYFmUxoMNuGIKfrLkcknRaBt37cGFbgbm2FBPjAqxS_GX-aof6TE7akyaVcpUMD8brSUZSp-jt7Xlj_BfTdE8X&lang=sage It can get pretty bad on degenerate problems, however, since it assumes all computations are exact even when they are not. Andrey -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Arbitrary precision linear programming
If your problem is over QQ then just use that (PPL supports exact rationals). On Thursday, October 23, 2014 4:38:39 AM UTC+1, Mike wrote: > > I'd like to be able to do linear programming to arbitrary precision. The > documentation that I've found claims that both the glpk and PPL solvers > should do this, but I haven't been able to get either to work. > > As an example, the following code prints c to high precision, but the > solutions only to 12 digits. Where should I look for guidance? > Note: this seeks to maximize x+y given that 3x<=1 and 3y<=1, so the > solution is (1/3, 1/3) > > Mike M > > R=RealField(100) > c=Matrix(R, 2, 1, [-1, -1]) > G=Matrix(R, 2, 2, [3, 0, 0, 3]) > h=Matrix(R, 2, 1, [1, 1]) > print c # To check the precision being used by "print" > print > > sol=linear_program(c,G,h) > print sol['x'] > sol=linear_program(c,G,h, solver='glpk') > print sol['x'] > sol=linear_program(c,G,h, solver='PPL') > print sol['x'] > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.