[sage-support] Re: When to use fast_float
On Nov 12, 2008, at 5:52 PM, kcrisman wrote: >> put those three lines in where indicated and it will be orders of >> magnitude faster for most cases, plus will handle constants, lambda >> functions, etc., automatically. >> >> fast_float is one of Sage's coolest "secrets". Thanks :) > That brings up a question I've had for a while. When is it good to > use fast_float (I've seen a lot of code over the last few months which > replaces other calls with it) and when is it not good, or for instance > when might RR be better, or just nothing? E.g. William's examples on > the interact wiki use it, but the others don't. Given the limitations > of our Sage server, something like that could really help things if it > really speeded it up. Unfortunately, as a non-CS type the > documentation just doesn't compute for me, and just seeing a couple of > examples where it is good to use it and where it isn't would be very > helpful. > > For instance, should it only be used in .py files, or is it worthwhile > in the command line or notebook? Is it worth using if something is > evaluated fewer than (say) 100 times? Can it be interspersed with ZZ > (I assume not) or RR(n), say RR(1000) (I have no idea)? Thanks for > any examples, especially from non-high-performance situations where it > still might speed things up considerably (or do something bad). The fast_float functionality is mostly for internal use, and is useful when one wants to evaluate an expression to double floating- point (i.e. 53-bits using the machine's native arithmetic) lots of times. "Lots" depends on the application, but is probably in the neighborhood of 10-100+, depending on the complexity of the equation and whether or not it has any symbolic values like pi (which slow down "normal" evaluation via maxima a huge amount). Thus it is suited to things like plotting or numerical integration. However, most such functions internally construct fast_float objects, so there usually is no need for the user to do so. That being said, there are plenty of use cases for it for end users. On the interact wiki (looking at the calculus page) it seems that fast_float is used when the function is evaluated a lot, and not when it is just passed off to something else (e.g. to contour_plot which (should) use the fast_float internally). The usage in "Coordinate Transformations" is probably redundant, as parametric_plot should be calling fast_float itself. Not sure it completely answers your question, but hopefully it helps. - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: How do you plot equations if one parameter is a list of values ?
If one does sage: Ii.subs(pars).variables() (x,) so that is fine. However, sage: RR(Ii.subs(pars)(x=-10)) Traceback (most recent call last): ... TypeError which tells you what the error is (not very helpful in this case). On a hunch sage: CC(Ii.subs(pars)(x=-10)) 2.59329101030962e-14*I so the problem here is that there is some numerical noise and you're taking the square root of a tiny, negative number (which should probably be 0?). - Robert On Nov 12, 2008, at 12:06 PM, kex wrote: > > Thank you very much Stan, this was helpfull > > I have more questions, > I get this message: > > verbose 0 (3605: plot.py, _plot) WARNING: When plotting, failed to > evaluate function at 200 points. > verbose 0 (3605: plot.py, _plot) Last error message: '' > > Why does it fail to evaluate ? > > my datasheet: > > #Definiram vrednosti parametrov > var('mi r_sonde h_sonde A T e0 V_P T_e k_b m_e n_se') > pars=dict(mi=1.67e-27,r_sonde=75e-6,h_sonde=1e-2,A=6e5,T=34782, > e0=1.6e-19,V_P=3,T_e=34782,k_b=1.38e-22,m_e=9.1e-31,n_se=1e16) > > # Temperaturno omejeno obmocje > #var('A T e0 k_b') > #pars0=dict(A=6e5,T=34782,e0=1.6e-19,k_b=1.38e-23) > jemt= ( A*T^2*exp(-e0*x/(k_b *T))) > show(jemt) > plot(jemt.subs(pars),-90,0) > > # Obmocje omejeno s prostorskim nabojem > > # PHI je normalizirana napetost > phi=e0*(x - V_P)/T_e #Te je bil pomno%u017Een z kb > # F vstavim v beta > F=exp(phi)-1 > # beta vstavim v G > beta_0= -4*phi^2 - 2*phi*(F^2 -2*F) > beta_1= 4*(-2*F-1)*phi^2 + 8*F*phi-F^2 > beta_2= 4*phi^2 - 8*phi^3 > # enacba za G > G=(-beta_1+sqrt(beta_1^2 - 4*beta_0*beta_2))*(2*beta_2)^-1 > # Definiram Ce > Ce=sqrt(8*T_e*(pi*m_e)^-1) > # Koncno definiram emisijski tok za obmocje prostorskega naboja > jems=0.5*G*(1+G)^-1 * e0*n_se*Ce*sqrt(-pi*phi) > show(jems) > plot(jems.subs(pars),-100,0) > > #--ERROR IS PRODUCED BY THE CODE THAT FOLLOWS > Cs=sqrt(T_e/mi) > S=pi*r_sonde^2*h_sonde > # V temperaturnem obmo%u010Dju Vb g=jemt * (e0*n_se*Ce*sqrt(-0.25*pi*phi)-jemt)^-1 > M=sqrt((1+g)*(1+g/(2*phi))^-1) > Ii=e0*n_se*M*Cs*S # ko smo v obmocju kjer velja Vb v Vb>Vp > show(Ii) > plot(Ii.subs(pars),-100,0) > > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] When to use fast_float
> put those three lines in where indicated and it will be orders of > magnitude faster for most cases, plus will handle constants, lambda > functions, etc., automatically. > > fast_float is one of Sage's coolest "secrets". > That brings up a question I've had for a while. When is it good to use fast_float (I've seen a lot of code over the last few months which replaces other calls with it) and when is it not good, or for instance when might RR be better, or just nothing? E.g. William's examples on the interact wiki use it, but the others don't. Given the limitations of our Sage server, something like that could really help things if it really speeded it up. Unfortunately, as a non-CS type the documentation just doesn't compute for me, and just seeing a couple of examples where it is good to use it and where it isn't would be very helpful. For instance, should it only be used in .py files, or is it worthwhile in the command line or notebook? Is it worth using if something is evaluated fewer than (say) 100 times? Can it be interspersed with ZZ (I assume not) or RR(n), say RR(1000) (I have no idea)? Thanks for any examples, especially from non-high-performance situations where it still might speed things up considerably (or do something bad). - kcrisman --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: taking functions as arguments
pong wrote: > Here is my script > > def shaded_area_plot(f,g,c,d,a,b): > step = 0.01 from sage.ext.fast_eval import fast_float f = fast_float(f) g = fast_float(g) > vf = [(x,f(x)) for x in srange(a, (b+step), step)] > vg = [(x,g(x)) for x in srange(b, (a-step), -step)] > sha = polygon(vf + vg, rgbcolor='grey') > return(plot(f, (c,d)) + plot(g, (c,d), rgbcolor='red') + sha) > > Most likely that's not well-written but I hope that's at least clear. > > for example, then shaded_area_plot(sin(x), lambda x:0, 0, pi, 1, 2) > give me the shaded area between the sine curve and the x-axis over > [0,pi] > > I hope there is a better solution to my problem. > put those three lines in where indicated and it will be orders of magnitude faster for most cases, plus will handle constants, lambda functions, etc., automatically. fast_float is one of Sage's coolest "secrets". Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: taking functions as arguments
Here is my script def shaded_area_plot(f,g,c,d,a,b): step = 0.01 vf = [(x,f(x)) for x in srange(a, (b+step), step)] vg = [(x,g(x)) for x in srange(b, (a-step), -step)] sha = polygon(vf + vg, rgbcolor='grey') return(plot(f, (c,d)) + plot(g, (c,d), rgbcolor='red') + sha) Most likely that's not well-written but I hope that's at least clear. for example, then shaded_area_plot(sin(x), lambda x:0, 0, pi, 1, 2) give me the shaded area between the sine curve and the x-axis over [0,pi] I hope there is a better solution to my problem. On Nov 12, 9:22 am, Jason Grout <[EMAIL PROTECTED]> wrote: > pong wrote: > > I defined a function which show the shaded area between the graphs of > > two functions over an interval (maybe such function already exist?). > > For example, > > > plot_shaded_area(sin(x), cos(x), 1,2) > > > show the shaded area between sine and cosine over [1,2]. Well, my > > script doesn't work if I change cos(x) to 0. The reason is 0 is an > > integer but not a function. I get around that by > > > plot_shaded_area(sin(x), lambda x:0, 1,2) > > > but I would like a more "natural" syntax as I don't want to scare my > > students off from using SAGE. > > Any help? Thanks. > > Actually, could you post your script? There might an easier way to > handle this. > > Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Drawing points on a sphere
I change the sequence of dots to size=2 and now the line looks better. world + sum([point3d(v, color='red') for v in city_coords]) + sum ([point3d(v, size=2, color='green') for v in mydots]) The parametric_plot3d command seems a better way to do this but I am not sure yet how to use it. I am working on it. Thanks On Nov 11, 11:19 pm, John H Palmieri <[EMAIL PROTECTED]> wrote: > On Nov 11, 9:01 pm, Robert Bradshaw <[EMAIL PROTECTED]> > wrote: > > > You can pass a "radius" or "size" parameter to the point command, > > which will make them smaller or larger. Also, you can look at the > > line3d command (pass it a list of points to get a curved line). > > Also the parametric_plot3d command might be useful. --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Computing a sum
On Nov 10, 7:15 pm, cesarnda <[EMAIL PROTECTED]> wrote: > that is the output I was expecting, but it is not the input I gave. > Obviously, > 1/x - 1/(x+1) = 1/(x*(x+1)) > > but, if the right hand side can be done why the left hand side can't? > This is the bug I was talking about... Thanks for pointing it out. If you can file a bug report in the Maxima bug tracker (http://sourceforge.net/projects/maxima/bugs or something like that) or post a message to the mailing list, that would be helpful. It turns out that nusum (the Gosper algorithm written by Gosper himself iirc) can solve this problem, but I guess nusum is not consulted by simplify_sum before the latter gives up. I didn't look into it carefully. best Robert Dodier --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: How do you plot equations if one parameter is a list of values ?
Thank you very much Stan, this was helpfull I have more questions, I get this message: verbose 0 (3605: plot.py, _plot) WARNING: When plotting, failed to evaluate function at 200 points. verbose 0 (3605: plot.py, _plot) Last error message: '' Why does it fail to evaluate ? my datasheet: #Definiram vrednosti parametrov var('mi r_sonde h_sonde A T e0 V_P T_e k_b m_e n_se') pars=dict(mi=1.67e-27,r_sonde=75e-6,h_sonde=1e-2,A=6e5,T=34782, e0=1.6e-19,V_P=3,T_e=34782,k_b=1.38e-22,m_e=9.1e-31,n_se=1e16) # Temperaturno omejeno obmocje #var('A T e0 k_b') #pars0=dict(A=6e5,T=34782,e0=1.6e-19,k_b=1.38e-23) jemt= ( A*T^2*exp(-e0*x/(k_b *T))) show(jemt) plot(jemt.subs(pars),-90,0) # Obmocje omejeno s prostorskim nabojem # PHI je normalizirana napetost phi=e0*(x - V_P)/T_e #Te je bil pomno%u017Een z kb # F vstavim v beta F=exp(phi)-1 # beta vstavim v G beta_0= -4*phi^2 - 2*phi*(F^2 -2*F) beta_1= 4*(-2*F-1)*phi^2 + 8*F*phi-F^2 beta_2= 4*phi^2 - 8*phi^3 # enacba za G G=(-beta_1+sqrt(beta_1^2 - 4*beta_0*beta_2))*(2*beta_2)^-1 # Definiram Ce Ce=sqrt(8*T_e*(pi*m_e)^-1) # Koncno definiram emisijski tok za obmocje prostorskega naboja jems=0.5*G*(1+G)^-1 * e0*n_se*Ce*sqrt(-pi*phi) show(jems) plot(jems.subs(pars),-100,0) #--ERROR IS PRODUCED BY THE CODE THAT FOLLOWS Cs=sqrt(T_e/mi) S=pi*r_sonde^2*h_sonde # V temperaturnem obmo%u010Dju VbVp show(Ii) plot(Ii.subs(pars),-100,0) --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Computing a sum
On Tue, Nov 11, 2008 at 3:15 AM, cesarnda <[EMAIL PROTECTED]> wrote: > > that is the output I was expecting, but it is not the input I gave. > Obviously, > 1/x - 1/(x+1) = 1/(x*(x+1)) > > but, if the right hand side can be done why the left hand side can't? > This is the bug I was talking about... It probably depends on the algorithm, in sympy, it's currently the other way round: In [2]: sum(1/x - 1/(x+1), (x, 1, oo)) Out[2]: 1 In [3]: sum(1/(x*(x+1)), (x, 1, oo)) Out[3]: Sum(1/(x*(1 + x)), (x, 1, oo)) Ondrej --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: taking functions as arguments
pong wrote: > I defined a function which show the shaded area between the graphs of > two functions over an interval (maybe such function already exist?). > For example, > > plot_shaded_area(sin(x), cos(x), 1,2) > > show the shaded area between sine and cosine over [1,2]. Well, my > script doesn't work if I change cos(x) to 0. The reason is 0 is an > integer but not a function. I get around that by > > plot_shaded_area(sin(x), lambda x:0, 1,2) > > but I would like a more "natural" syntax as I don't want to scare my > students off from using SAGE. > Any help? Thanks. Actually, could you post your script? There might an easier way to handle this. Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: taking functions as arguments
pong wrote: > I defined a function which show the shaded area between the graphs of > two functions over an interval (maybe such function already exist?). > For example, > > plot_shaded_area(sin(x), cos(x), 1,2) > > show the shaded area between sine and cosine over [1,2]. Well, my > script doesn't work if I change cos(x) to 0. The reason is 0 is an > integer but not a function. I get around that by > > plot_shaded_area(sin(x), lambda x:0, 1,2) > > but I would like a more "natural" syntax as I don't want to scare my > students off from using SAGE. > Any help? Thanks. This came up a while ago for plots as well. One fix is to wrap the argument in "SR", creating a SymbolicRing 0 instead of an Integer 0. plot_shaded_area(sin(x), SR(0)) or you can do the wrapping in the actual function. This will mean that you can't pass in lambda functions or python functions, though. You could try wrapping it in SR() and catch the error, though. try: f = SR(f) except: pass Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] taking functions as arguments
I defined a function which show the shaded area between the graphs of two functions over an interval (maybe such function already exist?). For example, plot_shaded_area(sin(x), cos(x), 1,2) show the shaded area between sine and cosine over [1,2]. Well, my script doesn't work if I change cos(x) to 0. The reason is 0 is an integer but not a function. I get around that by plot_shaded_area(sin(x), lambda x:0, 1,2) but I would like a more "natural" syntax as I don't want to scare my students off from using SAGE. Any help? Thanks. --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Wrong limit
mabshoff wrote: > comparing results from two different systems > that ideally do not share any components is a good thing :) And *that* is something that Sage lets you do that almost no one else does. It is pretty easy and free to compare answers between axiom, maxima, sympy, or if you have them, mathematica, magma, etc. Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Wrong limit
On Nov 11, 2:38 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On 11 Lis, 22:21, Robert Samal <[EMAIL PROTECTED]> wrote: Hi, > > Hi Minh, > > > > I think this issue has been fixed in sage-3.1.4. Under sage-3.1.4, the > > > command > > > > sage: lim ( x*(sqrt(x^2)-sqrt(x))/sqrt(x^2 -x), x=oo) > > > +Infinity > > > > returns what you'd expect. > > > That's great news, perhaps I should update more frequently. > > By any chance, does somebody know what was the issue? > > I have the same incorrect answer from maxima 5.13. Some bugs in limits > have been fixed in maxima recently. The new maxima has been probably > installed into sage. Yes, we usually ship the latest Maxima release. > > > > Not only am I curious, but I'd also like to know, how much should > > I rely on results I get from sage in future. > > I never trust anything computed using any CAS. :-) > I use maxima or maple or sage frequently and I have always in my mind > that the answers could be incorrect. +1 In the end all CAS have bugs just like regular software. One should never trust any CAS and comparing results from two different systems that ideally do not share any components is a good thing :) > Robert Marik Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---