[sage-support] Re: Superimpose various region_plot's
On Jul 13, 8:35 pm, David Sanders dpsand...@gmail.com wrote: On Jul 13, 4:47 pm, Jason Grout jason-s...@creativetrax.com wrote: On 7/13/10 4:46 AM, David Sanders wrote: Hi, I need to superimpose several region_plot's. These have regions colored in different colors which may or may not overlap. However, if I do something like var('p q') plot1 = region_plot([p+q1, p+q-1], (p,-2,2), (q,-2,2), incol='red') plot2 = region_plot([p-q1, p-q-1], (p,-2,2), (q,-2,2), incol='blue') show(plot1+plot2) then I see at most the outline of the first plot. It seems that the second plot covers up the first plot, since the default value of outcol is 'white'. Is there any way to make these plots transparent (i.e. with an alpha value less than 1), or at least not opaque? I tried putting the option outcol=None but this is not accepted. This would seem to me to be the first way of solving the issue. I had a look at the code for region_plot, which I at least understand the idea of. It uses matplotlib for the graphics, so perhaps the question of transparency is a matplotlib question. Nonetheless, I believe that matplotlib does have this capability, so this should be possible...! It seems that adding transparency is a natural way to do this. I've posted a rough patch to do this up athttp://trac.sagemath.org/sage_trac/ticket/9491 I've also attached a figure resulting from: var('p q') plot1 = region_plot([p+q1, p+q-1], (p,-2,2), (q,-2,2), incol='red', opacity=0.5) plot2 = region_plot([p-q1, p-q-1], (p,-2,2), (q,-2,2), incol='blue', opacity=0.5) show(plot1+plot2) Exactly what I had in mind, thanks! David. Sorry I don't have right now to finish the patch and ask for review; I'm rushing out the door. I have been playing with this a bit, and have found some problems. Firstly, with this code it seems not to be possible to make a region_plot *without* specifying opacity -- it looks like a default argument is missing somewhere. But the main problem is the same one as I started with. Currently, each region_plot paints the part which is not inside the region in white (by default), as opposed to leaving it blank. This means that when opacity != 0.5, the second plot drawn still partially hides the first. My preferred behaviour would be simply to not draw anything if, for example, outcol == None. Perhaps this is not the right place for this discussion (is that the sage-devel list?), but I tried to modify the code to do this, by checking for outcol as follows: if outcol: g.add_primitive(ContourPlot(xy_data_array, xrange,yrange, dict(contours=[-1e307, 0, 1e307], cmap=cmap, fill=True, **options))) else: g.add_primitive(ContourPlot(xy_data_array, xrange,yrange, dict(contours=[-1e307, 0], cmap=cmap, fill=True, **options))) (I also checked for it where it is converted to an rgbcolor.) So if outcol==None, then it should only fill the negative region, which corresponds to where the arguments are true. However, I never got this to work, apparently because I don't understand properly what the cmap object does and how it works. Directly in matplotlib I did manage to do what I wanted, but not specifying a cmap. Here I can't seem to get it quite right, but it seems to me like this is the right direction to go in. Can somebody enlighten me on cmap? Thanks, David. Thanks, Jason regionplot.png 27KViewDownload -- 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 URL: http://www.sagemath.org
[sage-support] Superimpose various region_plot's
Hi, I need to superimpose several region_plot's. These have regions colored in different colors which may or may not overlap. However, if I do something like var('p q') plot1 = region_plot([p+q1, p+q-1], (p,-2,2), (q,-2,2), incol='red') plot2 = region_plot([p-q1, p-q-1], (p,-2,2), (q,-2,2), incol='blue') show(plot1+plot2) then I see at most the outline of the first plot. It seems that the second plot covers up the first plot, since the default value of outcol is 'white'. Is there any way to make these plots transparent (i.e. with an alpha value less than 1), or at least not opaque? I tried putting the option outcol=None but this is not accepted. This would seem to me to be the first way of solving the issue. I had a look at the code for region_plot, which I at least understand the idea of. It uses matplotlib for the graphics, so perhaps the question of transparency is a matplotlib question. Nonetheless, I believe that matplotlib does have this capability, so this should be possible...! Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Re: Superimpose various region_plot's
On Jul 13, 4:47 pm, Jason Grout jason-s...@creativetrax.com wrote: On 7/13/10 4:46 AM, David Sanders wrote: Hi, I need to superimpose several region_plot's. These have regions colored in different colors which may or may not overlap. However, if I do something like var('p q') plot1 = region_plot([p+q1, p+q-1], (p,-2,2), (q,-2,2), incol='red') plot2 = region_plot([p-q1, p-q-1], (p,-2,2), (q,-2,2), incol='blue') show(plot1+plot2) then I see at most the outline of the first plot. It seems that the second plot covers up the first plot, since the default value of outcol is 'white'. Is there any way to make these plots transparent (i.e. with an alpha value less than 1), or at least not opaque? I tried putting the option outcol=None but this is not accepted. This would seem to me to be the first way of solving the issue. I had a look at the code for region_plot, which I at least understand the idea of. It uses matplotlib for the graphics, so perhaps the question of transparency is a matplotlib question. Nonetheless, I believe that matplotlib does have this capability, so this should be possible...! It seems that adding transparency is a natural way to do this. I've posted a rough patch to do this up athttp://trac.sagemath.org/sage_trac/ticket/9491 I've also attached a figure resulting from: var('p q') plot1 = region_plot([p+q1, p+q-1], (p,-2,2), (q,-2,2), incol='red', opacity=0.5) plot2 = region_plot([p-q1, p-q-1], (p,-2,2), (q,-2,2), incol='blue', opacity=0.5) show(plot1+plot2) Exactly what I had in mind, thanks! David. Sorry I don't have right now to finish the patch and ask for review; I'm rushing out the door. Thanks, Jason regionplot.png 27KViewDownload -- 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 URL: http://www.sagemath.org
[sage-support] Re: Pattern matching of a symbolic function acting on a symbolic variable
On Jul 11, 12:22 pm, William Stein wst...@gmail.com wrote: On Sat, Jul 10, 2010 at 10:04 PM, David Sanders dpsand...@gmail.com wrote: On Jul 10, 10:01 pm, David Sanders dpsand...@gmail.com wrote: Hi, Following up from a couple of my previous posts, I am now wondering how to do symbolic pattern matching for an expression of the following form: Apologies for replying to my own post, but I was wondering if there's any documentation I should be reading about this stuff, rather than posting every naive question here? (Although maybe it's actually useful to post naive questions here!) Maybe http://sagemath.org/doc/reference/calculus.html I'm curious if you had any trouble finding this. It's very easy -- just click Documentation, then Reference from the sage homepage. Thanks, I had seen this, I think via a Google search, but I did not explore it enough. I guess I was confused by the title 'calculus' instead of 'symbolic manipulation' -- I assumed it was just about differentiation etc. By the way, a minor but important point: the typographical conventions on this page (and many others) are not consistent: some of the titles have every word with an initial capital, whereas some have only the first word and proper names capitalized (my preference). Some have full stops (points) at the end, and others don't (my preference). Personally I have never liked monolithic pages with all possible information, such as http://sagemath.org/doc/reference/sage/symbolic/expression.html It is very difficult to navigate and find what you are looking for. Perhaps the examples could somehow be hidden until you hit a relevant link, at which point they reveal themselves. I suppose the page is probably automatically generated, but it would be more helpful to split it up into bitesize pieces. For example, there is a lot of noise generated by obvious functions like sin, cos etc. Finding the relevant bit about how to do pattern matching is not easy, for example. (Especially if you don't know that what you need is pattern matching!) In general, I find that the documentation is difficult to navigate for a Sage beginner. It is not clear what level each document is at. Even the order of the documents in the Sage standard documentation hides A tour of Sage, for example, amid more advanced documents. Of course, I realise that writing documentation is difficult! Perhaps it would be useful to have a kind of beginner's page, which lists a suggested order in which to read the different types of documentation. David. 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 URL: http://www.sagemath.org
[sage-support] Re: Pattern matching of a symbolic function acting on a symbolic variable
On Jul 11, 8:13 pm, ma...@mendelu.cz ma...@mendelu.cz wrote: On 11 čnc, 12:22, William Stein wst...@gmail.com wrote: On Sat, Jul 10, 2010 at 10:04 PM, David Sanders dpsand...@gmail.com wrote: Maybe http://sagemath.org/doc/reference/calculus.html Perhaps alsohttp://www.ginac.de/tutorial/Pattern-matching-and-advanced-substituti... OK, that is also useful, thanks. In particular, I notice that there is the concept of indexed objects in GiNaC. Is this accessible from Sage? Or pass to Maxima and use pattern matching from Maxima, which is well documented in documantation to Maxima. I am now confused about which system is used for the symbolics in Sage? Is it GiNaC, or Maxima, or a mixture? How can I find out which system is being used for which operation? I would very much prefer not to have to learn Maxima if I can help it, since the whole point is that Sage is supposed to provide the nice, coherent interface which makes this unnecessary! I also note that after reading the documentation, I am still left without an answer to my original question, which is how to do pattern matching in Sage (or if it's even possible) for something of the form f(i) ! David. Robert -- 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 URL: http://www.sagemath.org
[sage-support] How to plot regions defined by inequalities in 3D?
Hi, I have been playing around with the implicit_plot3d command, and it's very nice. Is there something similar to plot regions defined by inequalities in 3D, along the lines of the Mathematica RegionPlot3D command? I see that there is an old discussion from 2 years ago about this. It seems to me (in my ignorance) that the kind of algorithm required to do this should not be too different from that for implicit_plot3d with the region option. (Though implicit_plot3d draws surfaces, whereas region_plot3d would draw volumes. But apparently the marching cubes algorithm is used for both?) Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Re: Pattern matching of a symbolic function acting on a symbolic variable
On Jul 12, 12:19 pm, Burcin Erocal bur...@erocal.org wrote: Hi David, On Mon, 12 Jul 2010 02:24:41 -0700 (PDT) David Sanders dpsand...@gmail.com wrote: On Jul 11, 8:13 pm, ma...@mendelu.cz ma...@mendelu.cz wrote: On 11 čnc, 12:22, William Stein wst...@gmail.com wrote: On Sat, Jul 10, 2010 at 10:04 PM, David Sanders dpsand...@gmail.com wrote: Maybe http://sagemath.org/doc/reference/calculus.html Perhaps alsohttp://www.ginac.de/tutorial/Pattern-matching-and-advanced-substituti... OK, that is also useful, thanks. In particular, I notice that there is the concept of indexed objects in GiNaC. Is this accessible from Sage? There is an experimental patch. I'm really busy these days, but this is close to the top of my list. :) OK great, thanks! http://groups.google.com/group/sage-devel/t/69ab50fe11672111 Or pass to Maxima and use pattern matching from Maxima, which is well documented in documantation to Maxima. I am now confused about which system is used for the symbolics in Sage? Is it GiNaC, or Maxima, or a mixture? How can I find out which system is being used for which operation? It's a mixture, though we are trying to move as much as possible to GiNaC and native Sage. AFAIK, the only way to tell what is being used is to read the code. As a general rule, basic arithmetic and pattern matching is done with GiNaC, more advanced functionality, limits, simplification, factorization, etc. calls maxima. I see, thanks for the clarification. The structure is gradly becoming clearer to me. I have been looking at GiNaC a bit, and it seems to be very clean. I would very much prefer not to have to learn Maxima if I can help it, since the whole point is that Sage is supposed to provide the nice, coherent interface which makes this unnecessary! I can totally understand that. We definitely need to improve the interface to cover this functionality. Thanks for pointing it out. I also note that after reading the documentation, I am still left without an answer to my original question, which is how to do pattern matching in Sage (or if it's even possible) for something of the form f(i) ! I don't think this is supported by GiNaC expressions at the moment. If using wildcards for functions is available in GiNaC, we can wrap it easily. Implementing it would take more time though. Can you ask the GiNaC list if this is possible purely using GiNaC (from C++)? Actually, from browsing the documentation, I can't even find symbolic functions in GiNaC like f = function('f') in Sage. Does this exist in GiNaC? Does the above Sage statement reference something in GiNaC? If so, what? (I tried to answer this question myself using function? function?? in Sage, but this just said that it was a built-in function, and gave me neither the name of a file, nor the source code. Is there another way of getting information about this?) Thanks, David. Cheers, Burcin -- 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 URL: http://www.sagemath.org
[sage-support] Re: How to plot regions defined by inequalities in 3D?
On Jul 12, 7:29 pm, Carl Witty carl.wi...@gmail.com wrote: On Jul 12, 2:28 am, David Sanders dpsand...@gmail.com wrote: Hi, I have been playing around with the implicit_plot3d command, and it's very nice. Is there something similar to plot regions defined by inequalities in 3D, along the lines of the Mathematica RegionPlot3D command? I see that there is an old discussion from 2 years ago about this. It seems to me (in my ignorance) that the kind of algorithm required to do this should not be too different from that for implicit_plot3d with the region option. (Though implicit_plot3d draws surfaces, whereas region_plot3d would draw volumes. But apparently the marching cubes algorithm is used for both?) I haven't looked at this stuff in more than a year, but I think this is all accurate: Our plotting framework doesn't really understand volumes, only surfaces. So it would be a major overhaul to produce a plot that showed (via some sort of volumetric shading, say) the difference between the inside and the outside of your region. Yes, I agree, although that overhaul could well be worth it! However, if you want to produce a plot of the surface of your region, that's pretty easy. If your region is defined by a single inequality F(x,y,z)0, then you can just implicit_plot3d F(x,y,z). If your region is defined as a boolean combination of inequalities, then arrange all the inequalities to be of the form F(x,y,z) 0, then drop all the 0, replace and with max_symbolic, replace or with min_symbolic, and replace not F(x,y,z) with -F(x,y,z). Also, when you plot, because ofhttp://trac.sagemath.org/sage_trac/ticket/9483 you need to add smooth=False. Here's a complete example. This forms the intersection between a cube and the union of two cylinders. sage: var('x,y,z') (x, y, z) sage: implicit_plot3d(max_symbolic(min_symbolic(x*x+y*y-1, x*x+z*z-2), x-1.8, y-1.8, z-1.8, -x-1.8, -y-1.8, -z-1.8), (x, -2, 2), (y, -2, 2), (z, -2, 2), smooth=False) It would be great to put all of this into a region_plot3d command, but as far as I know, Sage does not yet support symbolic conjunctions and disjunctions (ands and ors); so it would be difficult to tell region_plot3d about any region more complicated than a single inequality. OK, thanks, I had come to a similar conclusion, though the trick with max_ and min_symbolic is neat. For the moment I think this will do most of the things that I need, but the fact that there are no symbolic and's and or's makes it quite (=very) messy if there are multiple intersecting volumes which restrict each other. Thanks, David. Carl -- 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 URL: http://www.sagemath.org
[sage-support] Pattern matching of a symbolic function acting on a symbolic variable
Hi, Following up from a couple of my previous posts, I am now wondering how to do symbolic pattern matching for an expression of the following form: f, g = function('f g') i = var('i') expr = f(i+1) g(i) I need to extract the indices i+1 and i from this expression. If I simplify to expr = f(i) then I still can't work out how to pattern match this. I tried patterns w0 = SR.wild(0) w1 = SR.wild(1) expr.match( w0(w1) ) expr.match( w0[w1] ) but both give errors If I use expr.operator() I get the response f But I cannot even test the type of this, since the type of f and the type of g are different. Presumably I am missing a key concept here. Any suggestions? Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Re: Pattern matching of a symbolic function acting on a symbolic variable
On Jul 10, 10:01 pm, David Sanders dpsand...@gmail.com wrote: Hi, Following up from a couple of my previous posts, I am now wondering how to do symbolic pattern matching for an expression of the following form: Apologies for replying to my own post, but I was wondering if there's any documentation I should be reading about this stuff, rather than posting every naive question here? (Although maybe it's actually useful to post naive questions here!) Thanks, David. f, g = function('f g') i = var('i') expr = f(i+1) g(i) I need to extract the indices i+1 and i from this expression. If I simplify to expr = f(i) then I still can't work out how to pattern match this. I tried patterns w0 = SR.wild(0) w1 = SR.wild(1) expr.match( w0(w1) ) expr.match( w0[w1] ) but both give errors If I use expr.operator() I get the response f But I cannot even test the type of this, since the type of f and the type of g are different. Presumably I am missing a key concept here. Any suggestions? Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Re: Notebook appearance: change font and syntax highlighting?
On Jul 9, 6:21 am, Jason Grout jason-s...@creativetrax.com wrote: On 7/7/10 2:34 PM, David Sanders wrote: Hi, [Using 'Sage Version 4.4.4, Release Date: 2010-06-23' on Kubuntu 10.04] I have just started using Sage, mainly using the notebook interface, which on the whole is excellent and impressive! I started out by trying the new interface Cantor, which is very nice, but I found it to be too unstable, for example it randomly crashed several times when I pressed Tab in the wrong place. But I liked its font, and especially its syntax highlighting. So the question is: is it possible to change the font and to use syntax highlighting in the standard (web browser) notebook interface? I found a few discussions on sage-devel, but they are apparently old (?). It seems to me that this is an important missing feature at the moment (assuming I am not just not finding the correct check box!) In the notebook, you can edit a file and get syntax highlighting. For example, open a new worksheet, go to the Data menu, click Upload or create file, and type a name in the third box (for naming a new file). An editor will then open up that has python syntax highlighting. I followed these instructions, but I do not seem to get an editable file. I get the message You may download test or create a linked copy to the worksheet or delete test. Access test in this worksheet by typing DATA+'test'. Here DATA is a special variable that gives the exact path to all data files uploaded to this worksheet. But I can't edit anything on that page. hope is that eventually, we might use something like this for code cells. However, as Mike says, speed is a primary concern. Another primary concern is that the syntax highlighting uses a different kind of input box that is typically way more buggy in browsers than the plain text box we currently use. There are huge amounts of bug workarounds for various browsers in the syntax highlighting program used above, for example. However, if the application (CodeMirror) that we use for syntax highlighting above proves to be okay for cells, there are *lots* more cool things that we can do beyond just changing fonts and syntax highlighting. On Jul 9, 10:14 am, Jason Grout jason-s...@creativetrax.com wrote: On 7/8/10 9:45 PM, Alex Leone wrote: I just recently got a patch into codemirror (the syntax highlighting that data files use) so that it resizes just like sage input cell textarea's. We should be able to replace input cells with codemirror soon. Yea! Seehttp://github.com/jasongrout/CodeMirrorfor my github mirror of CodeMirror, where I've explored some ideas about having javascript widgets embedded in Codemirror cells. The code is just exploratory at this point, but I think there's a real possibility for some fantastic interfaces (for example, a graph editor right in the code cell that lets you draw that graph, like: G=box with an editable graph inside it This sounds excellent, can't wait to see what it all looks like! Thanks to everybody for the replies. David. By the way, it's straightforward to change the fonts in the input boxes. I'm not sure of the exact code, but you just have to find out what CSS variable controls the font inside text area boxes and change that. It should be something like one line that you can execute inside a Sage cell to change the font. Thanks, Jason -- 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 URL: http://www.sagemath.org
[sage-support] Re: Extracting parts of a symbolic expression
On Jul 9, 5:16 am, kcrisman kcris...@gmail.com wrote: On Jul 8, 2:38 pm, David Sanders dpsand...@gmail.com wrote: Hi, I am trying to extract part of a symbolic expression. The expression -- an eigenvalue of a matrix -- has the form A + B*sqrt(C) where A, B and C are themselves complicated symbolic expressions. I wish to extract the subexpression C from this to test where the eigenvalues change type (where C==0). By using introspection and the help (both excellent features!), I stumbled across one possible solution, using iterator. But it's very fussy: I have to do something like: var('A B C') eigval = A + B*sqrt(C) terms = list( eigval.iterator() ) first = terms[0] terms2 = list(first.iterator()) desired = list(terms2[1].iterator())[0] to extract the part I want into the variable desired I don't know if this would be better, but... sage: eigval B*sqrt(C) + A sage: eigval.operands()[0].operands()[1].operands()[0] C At least it is using the things specific to symbolic expressions. Thanks, this is certainly better than the previous option! It still feels a bit clumsy to me though. To me it would seem more intuitive to use indexing directly on the expression, to be able to do something like eigval[0][1][0] which is similar to what is available in Mathematica, for example, but this doesn't work, since apparently indexing is not defined for symbolic expressions. (Couldn't it be defined to have exactly this functionality?) This seems intriguing, but I have no idea if it's possible. Me neither, but it would seem to me (with no deep understanding of either Python or Sage...) that it's a question of defining the __getitem__ method to return the corresponding element by iterating. Perhaps this is just hopelessly naive though, I'm afraid I have no understanding of the undoubted complexity of the symbolic objects. David. - kcrisman -- 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 URL: http://www.sagemath.org
[sage-support] Re: Extracting parts of a symbolic expression
On Jul 9, 6:14 am, Jason Grout jason-s...@creativetrax.com wrote: On 7/8/10 11:38 AM, David Sanders wrote: Hi, I am trying to extract part of a symbolic expression. The expression -- an eigenvalue of a matrix -- has the form A + B*sqrt(C) where A, B and C are themselves complicated symbolic expressions. I wish to extract the subexpression C from this to test where the eigenvalues change type (where C==0). By using introspection and the help (both excellent features!), I stumbled across one possible solution, using iterator. But it's very fussy: I have to do something like: var('A B C') eigval = A + B*sqrt(C) terms = list( eigval.iterator() ) first = terms[0] terms2 = list(first.iterator()) desired = list(terms2[1].iterator())[0] to extract the part I want into the variable desired To me it would seem more intuitive to use indexing directly on the expression, to be able to do something like eigval[0][1][0] which is similar to what is available in Mathematica, for example, but this doesn't work, since apparently indexing is not defined for symbolic expressions. (Couldn't it be defined to have exactly this functionality?) So the question finally is: am I reinventing the wheel here? Is there a simple way to do this? You could use pattern matching: sage: w0=SR.wild(0) sage: w1=SR.wild(1) sage: w2=SR.wild(2) sage: var('a,b,c') (a, b, c) sage: m=(a+b*sqrt(c)).match(sqrt(w0)*w1+w2) sage: m[w0] c sage: m=(a+b*sqrt(sqrt(17)*c^2+a)).match(sqrt(w0)*w1+w2) sage: m[w0] sqrt(17)*c^2 + a This seems to be closest to what I was looking for, thanks -- it looks like a very powerful method! David. Thanks, Jason -- 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 URL: http://www.sagemath.org
[sage-support] Re: Expressions with arbitrary indices
On Jul 9, 3:54 am, Jason Grout jason-s...@creativetrax.com wrote: On 7/8/10 12:26 PM, David Sanders wrote: Hi, How can I manipulate objects with indices? I need to do things like a_i + b_i * c_{j+1} using a TeX style notation (so that in the last term, the index is j +1) where i and j are symbolic. In Mathematica this would be something like a[i] + b[i] * c[j+1] but something like that presumably cannot work in Sage, since [] are reserved for other things! Here's one way to get such expressions: sage: a=function('a') sage: b=function('b') sage: c=function('c') sage: var('j') j sage: a(j)*b(j)*c(j+1) a(j)*b(j)*c(j + 1) Perfect, that's exactly what I was looking for, thanks! I then need to be able to manipulate such expressions to act on them with functions according to the values of different indices in each term: if there is a product a_i b_i with two equal indices then I need to apply a different rule than if the indices are different( a_i b_j with j not equal to i ). Could somebody please tell me what syntax I need (if indeed this is possible...)? How would you manipulate such expressions in Mathematica according to the rules you give above? It is code I wrote a while ago, but the basic idea is, in light of your response to another question I asked, to do some kind of pattern matching. In fact, the operation is an expectation, so the Mathematica code has things like ExpectationExpression[b_ + c_] := ExpectationExpression[b] + ExpectationExpression[c] to express that the expectation is linear. Of course, Mathematica manages to do the pattern matching in a rather intuitive way. Then ExpectationExpression[a_ b_] /; FreeQ[a, e[i_]] FreeQ[a, sp[i_]] FreeQ[a, sm[i_]] FreeQ[a, lp[i_]] FreeQ[a, lm[i_]] FreeQ[a, m[i]] := a*ExpectationExpression[b] to say that it's multiplicative as long as none of the random variables of interest (e_i etc.) occur in the expression. I guess the key part of the code is this kind of thing, a whole series of pattern matching for different possibilities of multiplicative terms: Ex[sp[i_]^alpha_ sm[i_] ^beta_] := ExpectationOfS[i, alpha, beta] Ex[sp[i_] sm[i_] ^beta_] := ExpectationOfS[i, 1, beta] and finally ExpectationOfS[i_, alpha_, beta_] := e[i]^(alpha + beta) FullSimplify[ Gamma[m[i]] / Gamma[m[i] + alpha + beta]] Expand[ FullSimplify[ Gamma[lp[i] + alpha] Gamma[ lm[i] + beta] / (Gamma[lp[i]] Gamma[lm[i]])]] which is the end of the road where the values are finally calculated. I am happy to make the full code available if that is of interest. (I doubt it!) As I say, however, I think it is now clear to me that this is basically a pattern matching exercise, so with your kind assistance I believe that I now know at least the direction that I need to take to do this kind of calculation. Many thanks! David. Here, Ex is another operator that applies once the expression has been reduced further, Thanks, Jason -- 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 URL: http://www.sagemath.org
[sage-support] Re: Shortcut key for deleting a word in notebook interface
On Jul 7, 11:52 pm, David Sanders dpsand...@gmail.com wrote: On Jul 7, 11:43 pm, ma...@mendelu.cz ma...@mendelu.cz wrote: On 7 čnc, 22:55, David Sanders dpsand...@gmail.com wrote: Hi, [I am using 'Sage Version 4.4.4, Release Date: 2010-06-23', downloaded a couple of days ago as the Ubuntu 10.04 binary package, used in Kubuntu 10.04.] I am just starting out with Sage, and I am very impressed over all. But after using it pretty intensively for 2 days, I find that I have a couple of niggles with the notebook interface. Is there a key combination for deleting the previous word? I see that someone once asked about the Ctrl+Backspace behaviour, which I have to admit I also use a lot (in Kubuntu), so I often find myself accidentally putting together cells I didn't want to. So: (1) Is there a built-in key combination for deleting a word? Deleting by hand (without the mouse) is tedious without this. I remark that in bash, the combination for this is Alt-Backspace, which seems to me could be a good option either for word deletion, or for cell joining. Hi, I use shift+arrow and then delete keys. Ah, that's a good idea. I guess you mean shift+ctrl+arrow (to highlight the whole word at once) and then backspace. It's still twice as complicated as, and less natural (for me) than, ctrl+backspace or alt+backspace, though. I also found by accident that ctrl+shift+backspace deletes the current line (at least in Firefox on Kubuntu). It still would be nice to have a proper delete previous word key combination, and indeed to have that being configurable by the user. I don't know how difficult that would be. David. Thanks, David. Robert -- 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 URL: http://www.sagemath.org
[sage-support] Re: How to export notebook worksheet to text file
On Jul 8, 5:45 am, TianWei ltwis...@gmail.com wrote: I built a worksheet with several cells in the notebook, and then wanted to try to run it on a remote computer using the command line interface. But I could not find a convincing way to export the worksheet to a simple text file that I could import directly to sage, i.e. a something.sage file. In the end, I had to copy and paste each cell separately into a text file on the remote machine, which I then imported with load something.sage But this is clearly not a reasonable solution for a long worksheet. I tried the Text option in the worksheet, but that produced output which I could not just copy straight into the sage command line, or import with load. If Sage has an easy, automatic way of doing this, I'm not aware of it. However, there's a couple ways to accomplish what you want to do without doing a bunch of repetitive actions (for example, manually copying out each the text cell). Unfortunately, both of my suggestions require a bit of work: (1) Open the worksheet through the notebook interface, then click on the Text tab. Copy the text there, then write a little script to strip out every line that doesn't begin with sage: . The lines that have sage: prepended are lines in the input cells (assuming you didn't type sage: somewhere in the worksheet itself). Strip out the sage: text. OK, this is the idea that I came up with. It is also necessary to strip out the ... that come at the start of indented lines, the html lines corresponding to the pretty-printed output, etc. I guess I just assumed that this must already have been done and be easily accessible, since it seems like a reasonably obvious thing to want to do -- use the nice notebook interface to create a document, and then convert it to plain Python and/or Sage to use for whatever. (2) You could tinker around with Notebook, Worksheet, and Cell objects in Sage (using a script, command-line, or notebook interface). In summary, you could create a Notebook object; get the desired Worksheet object using one of the methods of the Notebook object; get a list of Cell objects from the Worksheet; then pull out the input text from each Cell object. The documentation for these objects are: http://www.sagemath.org/doc/reference/sagenb/notebook/notebook.htmlhttp://www.sagemath.org/doc/reference/sagenb/notebook/worksheet.htmlhttp://www.sagemath.org/doc/reference/sagenb/notebook/cell.html Again, I'm (obviously) not aware of a cleaner way to just pull out the input text from a worksheet, and these two suggestions are just the work-arounds I could think of. Thanks to all for the suggestions. David. As a side-note, the inverse process (converting from plain-text commands to a sage worksheet) is easy; just upload it through the notebook interface. -- Tianwei -- 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 URL: http://www.sagemath.org
[sage-support] Extracting parts of a symbolic expression
Hi, I am trying to extract part of a symbolic expression. The expression -- an eigenvalue of a matrix -- has the form A + B*sqrt(C) where A, B and C are themselves complicated symbolic expressions. I wish to extract the subexpression C from this to test where the eigenvalues change type (where C==0). By using introspection and the help (both excellent features!), I stumbled across one possible solution, using iterator. But it's very fussy: I have to do something like: var('A B C') eigval = A + B*sqrt(C) terms = list( eigval.iterator() ) first = terms[0] terms2 = list(first.iterator()) desired = list(terms2[1].iterator())[0] to extract the part I want into the variable desired To me it would seem more intuitive to use indexing directly on the expression, to be able to do something like eigval[0][1][0] which is similar to what is available in Mathematica, for example, but this doesn't work, since apparently indexing is not defined for symbolic expressions. (Couldn't it be defined to have exactly this functionality?) So the question finally is: am I reinventing the wheel here? Is there a simple way to do this? Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Expressions with arbitrary indices
Hi, How can I manipulate objects with indices? I need to do things like a_i + b_i * c_{j+1} using a TeX style notation (so that in the last term, the index is j +1) where i and j are symbolic. In Mathematica this would be something like a[i] + b[i] * c[j+1] but something like that presumably cannot work in Sage, since [] are reserved for other things! I then need to be able to manipulate such expressions to act on them with functions according to the values of different indices in each term: if there is a product a_i b_i with two equal indices then I need to apply a different rule than if the indices are different( a_i b_j with j not equal to i ). Could somebody please tell me what syntax I need (if indeed this is possible...)? Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Strange (non-)substitution of variables whose name is not equal to their representation
Hi, I have finally managed to try out Sage seriously after a long time wanting to (and with intermediate-level Python experience). In general it's really rather amazing, thanks to all involved! I have come across what -- to me -- seems at least incongruous, when substituting variables. I am using 'Sage Version 4.4.4, Release Date: 2010-06-23', downloaded a couple of days ago as the Ubuntu 10.04 binary package. I want to have a variable called eps, but which appears as an epsilon in the notebook interface, so I do eps = var(epsilon) Now suppose I have a = 3 * eps I now want to substitute eps=1, so I do a.subs(eps = 1) but the response is still 3*epsilon ! If I do a.subs(epsilon = 1) then I get 3. But also, if I do a.subs({eps:1}) with a dictionary instead, then I get what I expect, namely 3. This seems to me strange, and possibly a bug, but maybe I'm just misunderstanding. Of course, I have found the solution -- just use a dictionary -- but I would like to understand what's going on. I see that the examples in the documentation seem always to use variables defined simply as var('x') etc., whose names are equal to their representations, so this problem seems not to arise. Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Shortcut key for deleting a word in notebook interface
Hi, [I am using 'Sage Version 4.4.4, Release Date: 2010-06-23', downloaded a couple of days ago as the Ubuntu 10.04 binary package, used in Kubuntu 10.04.] I am just starting out with Sage, and I am very impressed over all. But after using it pretty intensively for 2 days, I find that I have a couple of niggles with the notebook interface. Is there a key combination for deleting the previous word? I see that someone once asked about the Ctrl+Backspace behaviour, which I have to admit I also use a lot (in Kubuntu), so I often find myself accidentally putting together cells I didn't want to. So: (1) Is there a built-in key combination for deleting a word? Deleting by hand (without the mouse) is tedious without this. I remark that in bash, the combination for this is Alt-Backspace, which seems to me could be a good option either for word deletion, or for cell joining. (2) Is there a (simple) way of changing the default key bindings? Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] How to export notebook worksheet to text file
Hi, [Using 'Sage Version 4.4.4, Release Date: 2010-06-23' on Kubuntu 10.04.] The following seems like it must come up a lot, but I have not been able to find an answer (apologies if I missed it somewhere). I built a worksheet with several cells in the notebook, and then wanted to try to run it on a remote computer using the command line interface. But I could not find a convincing way to export the worksheet to a simple text file that I could import directly to sage, i.e. a something.sage file. In the end, I had to copy and paste each cell separately into a text file on the remote machine, which I then imported with load something.sage But this is clearly not a reasonable solution for a long worksheet. I tried the Text option in the worksheet, but that produced output which I could not just copy straight into the sage command line, or import with load. So what is the obvious solution that I am missing? Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Notebook appearance: change font and syntax highlighting?
Hi, [Using 'Sage Version 4.4.4, Release Date: 2010-06-23' on Kubuntu 10.04] I have just started using Sage, mainly using the notebook interface, which on the whole is excellent and impressive! I started out by trying the new interface Cantor, which is very nice, but I found it to be too unstable, for example it randomly crashed several times when I pressed Tab in the wrong place. But I liked its font, and especially its syntax highlighting. So the question is: is it possible to change the font and to use syntax highlighting in the standard (web browser) notebook interface? I found a few discussions on sage-devel, but they are apparently old (?). It seems to me that this is an important missing feature at the moment (assuming I am not just not finding the correct check box!) Thanks and best wishes, 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 URL: http://www.sagemath.org
[sage-support] Re: How to export notebook worksheet to text file
[Using 'Sage Version 4.4.4, Release Date: 2010-06-23' on Kubuntu 10.04.] The following seems like it must come up a lot, but I have not been able to find an answer (apologies if I missed it somewhere). I built a worksheet with several cells in the notebook, and then wanted to try to run it on a remote computer using the command line interface. But I could not find a convincing way to export the worksheet to a simple text file that I could import directly to sage, i.e. a something.sage file. Hi and thanks for your reply. There's more to a worksheet than the sage commands. OK, that's true, I should have been more specific. You want to create a worksheet file (foo.sws), using File-save worksheet to a file... (the 'File' menu on the worksheet). From there you can File-load worksheet from file. That doesn't work for me, since I want to import from the command line interface. So, as far as I can tell, I can't import the binary .sws worksheet file -- I need a plain Python script, or a something.sage file. So my more precise question is: How can I extract the sage commands from a worksheet into a plaintext script which I can run from the command-line interface to sage (e.g. on a remote machine)? HTH Justin -- Justin C. Walker Thanks, 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 URL: http://www.sagemath.org
[sage-support] Re: Shortcut key for deleting a word in notebook interface
On Jul 7, 11:43 pm, ma...@mendelu.cz ma...@mendelu.cz wrote: On 7 čnc, 22:55, David Sanders dpsand...@gmail.com wrote: Hi, [I am using 'Sage Version 4.4.4, Release Date: 2010-06-23', downloaded a couple of days ago as the Ubuntu 10.04 binary package, used in Kubuntu 10.04.] I am just starting out with Sage, and I am very impressed over all. But after using it pretty intensively for 2 days, I find that I have a couple of niggles with the notebook interface. Is there a key combination for deleting the previous word? I see that someone once asked about the Ctrl+Backspace behaviour, which I have to admit I also use a lot (in Kubuntu), so I often find myself accidentally putting together cells I didn't want to. So: (1) Is there a built-in key combination for deleting a word? Deleting by hand (without the mouse) is tedious without this. I remark that in bash, the combination for this is Alt-Backspace, which seems to me could be a good option either for word deletion, or for cell joining. Hi, I use shift+arrow and then delete keys. Ah, that's a good idea. I guess you mean shift+ctrl+arrow (to highlight the whole word at once) and then backspace. It's still twice as complicated as, and less natural (for me) than, ctrl+backspace or alt+backspace, though. Thanks, David. Robert -- 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 URL: http://www.sagemath.org