Re: [sage-support] Re: Evaluating Symbolic Expressions
On Wed, Nov 2, 2011 at 12:08 PM, Laurent moky.m...@gmail.com wrote: In order to anticipate the next question, if you are wotking in a script instead of the terminal. The code f(x,y)=x*y print f(5,4) raises SyntaxError: can't assign to function call The code x,y=var('x,y') f=x*y print f(4,3) raises DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) I know two correct ways to do that : x,y=var('x,y') f=x*y print f(x=4,y=3) or x,y=var('x,y') f=symbolic_expression(x*y).function(x,y) print f(x,y) Remark that f=symbolic_expression(x*cos(y)).function(x,y) print f(0,1) # 0 g=symbolic_expression(x*cos(y)).function(y,x) print g(0,1) # 1!! Hope it helps in any way Laurent -- 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 Hi, I think its a issue of parsing. If your file is called hello.py it gives the errors you mentioned. However if you call your file hello.sage it works. If you call your file hello.sage and run sage hello.sage it generates a hello.py which I append below - # This file was *autogenerated* from the file temp.sage. from sage.all_cmdline import * # import sage library _sage_const_5 = Integer(5); _sage_const_4 = Integer(4) var('x,y') __tmp__=var(x,y); f = symbolic_expression(x*y).function(x,y) print f(_sage_const_5 ,_sage_const_4 ) I think you can now figure out how it is working. Hope it helps. Rajeev -- 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
Re: [sage-support] gsl in sage outside of notebook
On Thu, Sep 15, 2011 at 3:24 PM, Rajeev Singh rajs2...@gmail.com wrote: On Thu, Sep 15, 2011 at 12:07 PM, Robert Bradshaw rober...@math.washington.edu wrote: On Wed, Sep 14, 2011 at 2:31 AM, Rajeev Singh rajs2...@gmail.com wrote: Hi, The following examples compiles from the notebook %cython cimport sage.gsl.ode import sage.gsl.ode include 'gsl.pxi' cdef class van_der_pol(sage.gsl.ode.ode_system): cdef double beta def __cinit__(self, double beta=1.0): self.beta = beta cdef int c_f(self,double t, double *y,double *dydt): dydt[0]=y[1] dydt[1]=-y[0]-self.beta*y[1]*(y[0]*y[0]-1) return GSL_SUCCESS cdef int c_j(self, double t,double *y,double *dfdy,double *dfdt): dfdy[0]=0 dfdy[1]=1.0 dfdy[2]=-2.0*10*y[0]*y[1]-1.0 dfdy[3]=-10*(y[0]*y[0]-1.0) dfdt[0]=0 dfdt[1]=0 return GSL_SUCCESS However if I put it in a file vander.pyx (say) and use the following setup.py - from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext = Extension(vander, [vander.pyx], include_dirs = ['/home/rajeev/bin/sage/devel/sage-main/sage/gsl/']) setup(ext_modules=[ext], cmdclass = {'build_ext': build_ext}) I get the following error - cdef class van_der_pol(sage.gsl.ode.ode_system): ^ vander.pyx:10:5: 'ode_system' is not declared I guess the problem is with the setup.py. Can someone tell me how to do this? IIRC, the notebook %cython creates a setup.py--you could just look at that. Chances are your Extension object is missing include dirs and libraries. -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 Hi, The present script takes a pyx file as input and outputs a c, o and so file in the same directory. The so can now be imported in a sage program. I have already checked it and its seems to be working fine. I did look at the commands generated by setup.py file to write this script. Rajeev Hi, There is a better (safer I guess) way of doing the task using something called cython_create_local_so. The following command will do the job - sage -c from sage.all import cython_create_local_so; cython_create_local_so('_laplace.pyx') Rajeev -- 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
Re: [sage-support] How to write Sage code to cython code
On Sat, Sep 17, 2011 at 5:46 PM, Santanu Sarkar sarkar.santanu@gmail.com wrote: Hi all, I want to use cython. The following code does not work %cython cdef P P = next_prime(ZZ.random_element(2^(100-1),2^100)) -- 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 Try this - %cython from sage.all import * cdef P P = next_prime(ZZ.random_element(2^(100-1),2^100)) print P Rajeev -- 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
Re: [sage-support] gsl in sage outside of notebook
On Thu, Sep 15, 2011 at 12:07 PM, Robert Bradshaw rober...@math.washington.edu wrote: On Wed, Sep 14, 2011 at 2:31 AM, Rajeev Singh rajs2...@gmail.com wrote: Hi, The following examples compiles from the notebook %cython cimport sage.gsl.ode import sage.gsl.ode include 'gsl.pxi' cdef class van_der_pol(sage.gsl.ode.ode_system): cdef double beta def __cinit__(self, double beta=1.0): self.beta = beta cdef int c_f(self,double t, double *y,double *dydt): dydt[0]=y[1] dydt[1]=-y[0]-self.beta*y[1]*(y[0]*y[0]-1) return GSL_SUCCESS cdef int c_j(self, double t,double *y,double *dfdy,double *dfdt): dfdy[0]=0 dfdy[1]=1.0 dfdy[2]=-2.0*10*y[0]*y[1]-1.0 dfdy[3]=-10*(y[0]*y[0]-1.0) dfdt[0]=0 dfdt[1]=0 return GSL_SUCCESS However if I put it in a file vander.pyx (say) and use the following setup.py - from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext = Extension(vander, [vander.pyx], include_dirs = ['/home/rajeev/bin/sage/devel/sage-main/sage/gsl/']) setup(ext_modules=[ext], cmdclass = {'build_ext': build_ext}) I get the following error - cdef class van_der_pol(sage.gsl.ode.ode_system): ^ vander.pyx:10:5: 'ode_system' is not declared I guess the problem is with the setup.py. Can someone tell me how to do this? IIRC, the notebook %cython creates a setup.py--you could just look at that. Chances are your Extension object is missing include dirs and libraries. -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 Hi, The present script takes a pyx file as input and outputs a c, o and so file in the same directory. The so can now be imported in a sage program. I have already checked it and its seems to be working fine. I did look at the commands generated by setup.py file to write this script. Rajeev -- 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
Re: [sage-support] Re: plot3d with adaptive=True fails
On Thu, Sep 15, 2011 at 7:10 PM, kcrisman kcris...@gmail.com wrote: On Sep 15, 9:08 am, Dan Drake dr...@kaist.edu wrote: This is strange: x, y =var('x y') plot3d(sqrt(x^2+y^2)*sin(1/sqrt(x^2+y^2)), (x,-1/2, 1/2), (y, -1/2, 1/2), adaptive=True) fails with ValueError: cannot convert float NaN to integer. Something goes wrong when it partitions up the domain, probably when it looks at the origin. Is there a way to avoid this? Is this a bug? Or rather, very very close to the origin. I don't have time right now, but can you confirm that there is not a depth of recursion keyword like there is in 2d plotting? I would call this a bug. -- 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 For the time being there is a hack - x, y, x1, y1 =var('x y x1 y1') plot3d(lambda x,y: limit( limit(sqrt(x1^2+y1^2)*sin(1/sqrt(x1^2+y1^2)), x1=x), y1=y), (x,-1/2, 1/2), (y, -1/2, 1/2), adaptive=True) #slow or plot3d(lambda x,y: limit( limit(sqrt(x1^2+y1^2)*sin(1/sqrt(x1^2+y1^2)), x1=x), y1=y) if x^2+y^21e-4 else sqrt(x^2+y^2)*sin(1/sqrt(x^2+y^2)), (x,-1/2, 1/2), (y, -1/2, 1/2), adaptive=True) # dirty but fast -- 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] gsl in sage outside of notebook
Hi, The following examples compiles from the notebook %cython cimport sage.gsl.ode import sage.gsl.ode include 'gsl.pxi' cdef class van_der_pol(sage.gsl.ode.ode_system): cdef double beta def __cinit__(self, double beta=1.0): self.beta = beta cdef int c_f(self,double t, double *y,double *dydt): dydt[0]=y[1] dydt[1]=-y[0]-self.beta*y[1]*(y[0]*y[0]-1) return GSL_SUCCESS cdef int c_j(self, double t,double *y,double *dfdy,double *dfdt): dfdy[0]=0 dfdy[1]=1.0 dfdy[2]=-2.0*10*y[0]*y[1]-1.0 dfdy[3]=-10*(y[0]*y[0]-1.0) dfdt[0]=0 dfdt[1]=0 return GSL_SUCCESS However if I put it in a file vander.pyx (say) and use the following setup.py - from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext = Extension(vander, [vander.pyx], include_dirs = ['/home/rajeev/bin/sage/devel/sage-main/sage/gsl/']) setup(ext_modules=[ext], cmdclass = {'build_ext': build_ext}) I get the following error - cdef class van_der_pol(sage.gsl.ode.ode_system): ^ vander.pyx:10:5: 'ode_system' is not declared I guess the problem is with the setup.py. Can someone tell me how to do this? Thanks in advance. Rajeev -- 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
Re: [sage-support] noob q: solve in loop doesn't iterate each time
On Wed, Sep 7, 2011 at 7:31 PM, Chipslinger cbol...@boltoneng.com wrote: I've been messing around with using Sage for solving node equations. I have the right syntax and structure for creating and symbolically solving equations, but am struggling with: * Using solve in a loop -- it doesn't evaluate using new parameters each time through * Printing in decimal format -- I've tried using N(x, digits=4), but can't get it to work with the result from solve; I get lots of errors Here's a simple program I tried last night (using sagenb.org version 4.7): # Schmitt Trigger Threshold Calculation var('rtop, rbot, rfd, rout_pullup, vnode, vcc, vin, vthresh') rtop = 1 rbot = 1 rout_pullup = 1 rfd = 1e6 vin = 5 #vcc = 5 eq1 = (vin-vnode)/rtop + (vcc-vnode)/(rout_pullup+rfd) == vnode/rbot out_states = [0, 5] for i in range(2): vcc = out_states[i] vthresh = solve([eq1], vnode) print '%4s: %4s'%(vcc, vthresh) Any help or pointers towards relevant docs would be greatly appreciated. Thank you in advance. -- 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 How about this - # Schmitt Trigger Threshold Calculation var('rtop, rbot, rfd, rout_pullup, vnode, vcc, vin, vthresh') rtop = 1 rbot = 1 rout_pullup = 1 rfd = 1e6 vin = 5 #vcc = 5 eq1 = (vin-vnode)/rtop + (vcc-vnode)/(rout_pullup+rfd) == vnode/rbot out_states = [0, 5] vthresh = solve([eq1], vnode)[0].rhs() for i in range(2): vcc = out_states[i] print '%4s: %.4f'%(vcc, vthresh.substitute(vcc=vcc).n()) output is - 0: 2.4877 5: 2.5123 I have done very small changes in your code. Hope it helps. Rajeev -- 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] Fwd: Speeding up Python Again
On Wed, Aug 10, 2011 at 6:48 PM, Rajeev Singh rajs2...@gmail.com wrote: Hi, I was trying out the codes discussed at http://technicaldiscovery.blogspot.com/2011/07/speeding-up-python-again.html Here is a summary of my results - Computer: Desktopimsc9aravali annapurna NumPy: 7.651419 4.219105 5.576453 4.858640 Cython: 4.259419 3.477259 3.204909 2.357819 Weave: 4.302778 * 3.298551 2.40 Looped Fortran: 4.199148 3.414484 3.202963 2.315644 Vectorized Fortran: 3.118410 2.131966 1.512303 1.460251 pure fortran update1: 1.205727 1.964857 2.034688 1.336086 pure fortran update2: 0.600848 0.604649 0.573593 0.721339 imsc9, aravali and annapurna are HPC machines at my institute * for some reason Weave didn't compile on imsc9 Indeed there is about a factor of 7 to 12 difference between pure fortran with update2 (vectorized) and the numpy version. I should mention that I changed N to 150 in laplace_for.f90 Rajeev Hi, Continuing the comparison of various ways of implementing solving laplace equation, following result might interest you - Desktop imsc9 aravali annapurna Octave (0): 20.7866 *21.6179 * Vectorized Fortran (pure) (1): 0.7487 0.6501 0.7507 1.1619 Vectorized Fortran (f2py) (2): 0.7190 0.6089 0.6243 1.0312 NumPy (3): 4.1343 2.5844 2.6565 3.7445 Cython (4): 1.7273 1.9927 2.0471 1.3525 Cython with C (5): 1.7248 1.9665 2.0354 1.3367 Weave (6): 1.9818 * 2.1326 1.4003 Looped Fortran (f2py) (7): 1.6996 1.9657 2.0429 1.3354 Looped Fortran (pure) (8): 1.7189 2.0145 2.0917 1.5086 C (pure) (9): 1.2820 1.9948 2.0527 1.4259 imsc9, aravali and annapurna are HPC machines at my institute * for some reason Weave didn't compile on imsc9 * octave isn't installed on imsc9 and annapurna The difference between numpy and fortran performance seems significant. However f2py does as well as pure fortran now. The difference from earlier case is that earlier there was a division inside the loop which I have replaced by multiplication by reciprocal. This does not affect the result but makes the execution faster in all cases except pure fortran (I guess fortran compiler was already doing it). I would be happy to give all the codes if someone is interested. Should we update the performance python page at scipy with these codes? This might be of interest to people doing numerical computation using Sage. Should we put all these examples in Numerical Sage along with the above table? Rajeev -- 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] fortran example in numerical sage document not working
Hi, If I put the following in notebook, I don't get what is expected, i.e. a function called linearequations - fortran.libraries = ['lapack', 'blas'] code = '''!f90 Subroutine LinearEquations(A,b,n) Integer n Real*8 A(n,n), b(n) Integer i, j, pivot(n), ok call DGESV(n, 1, A, n, pivot, b, n, ok) end ''' fortran(code) Although apart from showing some warning it does generate a .so file. I am using Sage 4.6.2 compiled from source on Debian squeeze. Can someone suggest how to get it working? Rajeev -- 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] ode_solver in cython
Hi, I am not able to understand why the following should not work (in notebook) - cell 1 ## %cython from sage.all import ode_solver, random cdef class A: cdef double mu def __init__(self, double mu=1.): self.mu = mu def func(self, x): return self.mu*x[0], self.mu*x[1] def func1(): a = A() trajectory = ode_solver() trajectory.algorithm = rkf45 trajectory.function = lambda t, y: a.func(y) trajectory.ode_solve(y_0=[random(), random()], t_span=[0,10], num_points=100) u1 = trajectory.interpolate_solution(0) return u1 ## end of cell 1 ### This compiles without any problem, but when I do - cell 2 ## u1 = func1() plot(u1, (0,10)) ## end of cell 2 ### I get the following error - TypeError: arg is not a Python function If I define func1 outside the cython cell then everything works fine. This is just a toy problem but captures the behavior I encountered. I hope someone can explain. Rajeev -- 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: f2py error within sage
On Sat, Jul 30, 2011 at 1:42 PM, Rajeev Singh rajs2...@gmail.com wrote: Hi, I have a script (say a.py) which uses a function written in fortran 90. Within the script I give the command to compile using - os.system('f2py -c PD_evolve.f90 -m PD_evolve') It works fine on my computer if I run the script using - python a.py However it doesn't work if I use - sage -python a.py and gives an error while compiling. The last lines of error message are - /usr/bin/gfortran -Wall /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/PD_evolvemodule.o /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/fortranobject.o /tmp/tmpBTbBKB/PD_evolve.o -L/home/rajeev/bin/sage/local/lib -lpython2.6 -lgfortran -o ./PD_evolve.so /usr/lib/gcc/i486-linux-gnu/4.4.5/libgfortranbegin.a(fmain.o): In function `main': (.text+0x27): undefined reference to `MAIN__' collect2: ld returned 1 exit status /usr/lib/gcc/i486-linux-gnu/4.4.5/libgfortranbegin.a(fmain.o): In function `main': (.text+0x27): undefined reference to `MAIN__' collect2: ld returned 1 exit status error: Command /usr/bin/gfortran -Wall /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/PD_evolvemodule.o /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/fortranobject.o /tmp/tmpBTbBKB/PD_evolve.o -L/home/rajeev/bin/sage/local/lib -lpython2.6 -lgfortran -o ./PD_evolve.so failed with exit status 1 I have compiled sage4.6.2 from source on Debian squeeze. I hope it makes sense to ask this question here as the trouble is within sage. Rajeev Hi, Going through the source code of numpy.f2py.compile and fortran in sage, I managed to get things working. The following code works just fine - path = os.environ['SAGE_LOCAL']+'/bin/sage-g77_shared' extra_args = '--f77exec=%s --f90exec=%s' %(path, path) args = ' -c -m %s %s %s'%('PD_evolve', 'PD_evolve.f90', extra_args) cmd = '%s -c import numpy.f2py as f2py2e;f2py2e.main() %s' %(sys.executable,args) os.system(cmd) The other thing that worked was InlineFortran from sage.misc.inline_fortran however it would compile the source every time I run the program, whereas the above set of instructions create a .so file which can be imported directly in future runs. This is just for future reference. Rajeev -- 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] f2py error within sage
Hi, I have a script (say a.py) which uses a function written in fortran 90. Within the script I give the command to compile using - os.system('f2py -c PD_evolve.f90 -m PD_evolve') It works fine on my computer if I run the script using - python a.py However it doesn't work if I use - sage -python a.py and gives an error while compiling. The last lines of error message are - /usr/bin/gfortran -Wall /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/PD_evolvemodule.o /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/fortranobject.o /tmp/tmpBTbBKB/PD_evolve.o -L/home/rajeev/bin/sage/local/lib -lpython2.6 -lgfortran -o ./PD_evolve.so /usr/lib/gcc/i486-linux-gnu/4.4.5/libgfortranbegin.a(fmain.o): In function `main': (.text+0x27): undefined reference to `MAIN__' collect2: ld returned 1 exit status /usr/lib/gcc/i486-linux-gnu/4.4.5/libgfortranbegin.a(fmain.o): In function `main': (.text+0x27): undefined reference to `MAIN__' collect2: ld returned 1 exit status error: Command /usr/bin/gfortran -Wall /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/PD_evolvemodule.o /tmp/tmpBTbBKB/tmp/tmpBTbBKB/src.linux-i686-2.6/fortranobject.o /tmp/tmpBTbBKB/PD_evolve.o -L/home/rajeev/bin/sage/local/lib -lpython2.6 -lgfortran -o ./PD_evolve.so failed with exit status 1 I have compiled sage4.6.2 from source on Debian squeeze. I hope it makes sense to ask this question here as the trouble is within sage. Rajeev -- 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
Re: [sage-support] dirac delta function
On Mon, Jul 11, 2011 at 9:43 AM, robin hankin hankin.ro...@gmail.comwrote: Hi. When I type integrate(dirac_delta(x),x,-1,1) I expected to get 1, as the documentation clearly implies. But instead I get a symbolic answer. How do I make sage return 1? cheers Robin -- Robin Hankin Uncertainty Analyst hankin.ro...@gmail.com -- 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 You can use sympy as - import sympy sympy.integrate(sympy.DiracDelta(x), (x,-1,1)) 1 Rajeev -- 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
Re: [sage-support] Log log plots in sage.
Hi, One way using pylab is following - sage: import pylab as plt sage: x = plt.array([2^ii for ii in range(10)]) sage: y = x^2 sage: plt.loglog(x, y, '.') [matplotlib.lines.Line2D object at 0x5265d50] sage: plt.savefig('/home/rajeev/a.png') Hope it helps. Rajeev -- 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
Re: [sage-support] Import Ellipse module?
On Thu, May 26, 2011 at 10:26 PM, Mel chemmyg...@gmail.com wrote: Do I need to download/load something before I can import the ellipse module? When I type from sage.plot.ellipse import Ellipse I get ImportError: No module named ellipse Thanks! -- 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 I don't get any error when I execute the above line with sage-4.6.2 on debian. -- 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
Re: [sage-support] Re: imposing commutation relation
On Wed, May 25, 2011 at 11:55 AM, Simon King simon.k...@uni-jena.de wrote: Hi Rajeev, On 25 Mai, 06:14, Rajeev Singh rajs2...@gmail.com wrote: sage: R.a,b = FreeAlgebra(QQ, 2) sage: p = a*(a+2*b) sage: list(p) [(2, a*b), (1, a^2)] is there a simple way to reverse this last step? I thought that for many parents R holds that R(list(p))==p, but apparently I was mistaken. However, for example, in the case of polynomials, one has sage: P.x,y = QQ[] sage: p = P.random_element() sage: p x*y + 5*y^2 - x + 1 sage: p.dict() {(1, 0): -1, (0, 0): 1, (1, 1): 1, (0, 2): 5} sage: P(p.dict()) == p True But apparently that does not hold for free algebras. Here is a work- around using the 'add' function: sage: R.a,b = FreeAlgebra(QQ, 2) sage: p = a*(a+2*b) sage: L = list(p) sage: add([c*R(m) for c,m in L], R(0)) a^2 + 2*a*b Cheers, Simon -- 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 Thanks Simon, One small querry - sage: R.a,b = FreeAlgebra(QQ, 2) sage: p = a*(a+2*b) sage: p a^2 + 2*a*b sage: list(p) [(2, a*b), (1, a^2)] Why is the order of terms in the list not the same that in string of p (a^2 in string appears before a*b and the opposite happens for the list) ? What can I do to make them in same order? Rajeev -- 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
Re: [sage-support] Re: imposing commutation relation
Thanks Simon, i think list of lists and tuples are good enough for me. sage: R.a,b = FreeAlgebra(QQ, 2) sage: p = a*(a+2*b) sage: list(p) [(2, a*b), (1, a^2)] is there a simple way to reverse this last step? just for information - i asked this same question at the sympy mailing list and i give below parts of the answer which would be important for people using sage - The parts below are from the replies of Aaron S. Meurer (asmeu...@gmail.com) - Just a heads up, starting in the next release, symbols('xy') will create one symbol named xy, not two symbols x and y. To get around this, you should do symbols('x y') or symbols('x, y') (this works in the older release too, so you can start to change your code now). In [9]: x, y = symbols('x y', commutative=False) In [10]: a = expand((x + y)**3) In [11]: a Out[11]: 22 3 22 3 x⋅y⋅x + x⋅y + x ⋅y + x + y⋅x⋅y + y⋅x + y ⋅x + y In [12]: a.subs(x*y, y*x + 1) Out[12]: 3 2 2 3 x⋅(1 + y⋅x) + x + y⋅x + y⋅(1 + y⋅x) + y ⋅x + y + (1 + y⋅x)⋅x + (1 + y⋅x)⋅y Actually, it looks like if you are using SymPy 0.6.7, there is a bug that makes this return a wrong result: For people using sympy in sage, this last point seems important. I actually checked and we use SymPy 0.6.4 Rajeev -- 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
Re: [sage-support] Re: imposing commutation relation
Hi, I think my other question got buried in the first one, so here it is again. If I have - sage: R.a,b = FreeAlgebra(QQ, 2) sage: a*(a+b) a^2 + a*b Is there a simple way to get a*a instead of a^2 ? Rajeev -- 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
Re: [sage-support] Re: using existing functions with vectors / lists / arrays
On Sun, May 22, 2011 at 4:45 PM, Berkin Malkoc malk...@gmail.com wrote: I have something like: y = x^2 I can evaluate it at one point: y(2) # 4 I'd like to evaluate it at a group of points: y( x ) # 2, 4, 9, 16, ... Can this just work like in IDL or MATLAB? How would one define x? What is the quickest syntax if it can't just be a variable? Perhaps: For purely numerical work a la Matlab, you may want to use numpy arrays (you will be using Python and not any Sage functionality): sage: import numpy sage: x = numpy.array([1, 2, 3, 4]) sage: def y(x): : return x*x : sage: y(x) array([ 1, 4, 9, 16]) -- 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 if the function of the single variable is somewhat more complicated then one can use vectorize from numpy - sage: import numpy as np sage: x = np.array([1,2,3,4]) sage: x array([1, 2, 3, 4]) sage: def y(x): : if x 3: : return 2*x : else: : return x*x : sage: y_vec = np.vectorize(y) this fails - sage: y(x) --- ValueErrorTraceback (most recent call last) while this works - sage: y_vec(x) array([ 2, 4, 9, 16]) hope it helps. Rajeev -- 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
Re: [sage-support] interact question
here is the answer to the first thing. use auto_update=False - sage: @interact ... def _(A=matrix(QQ,3,3,range(9)), v=matrix(QQ,3,1,range(3)), auto_update=False): ... try: ... x = A\v ... html('$$%s %s = %s$$'%(latex(A), latex(x), latex(v))) ... except: ... html('There is no solution to $$%s x=%s$$'%(latex(A), latex(v))) Rajeev On Tue, May 18, 2010 at 1:50 PM, ma...@mendelu.cz ma...@mendelu.cz wrote: Dear support, this code is from interact help: sage: @interact ... def _(A=matrix(QQ,3,3,range(9)), v=matrix(QQ,3,1,range(3))): ... try: ... x = A\v ... html('$$%s %s = %s$$'%(latex(A), latex(x), latex(v))) ... except: ... html('There is no solution to $$%s x=%s$$'%(latex(A), latex(v))) If I want to change five numbers in the matrix A, I get a solution whenever I change each field. Is it possible to change all my five fields first and the let interact to compute the answer? In other words, interact should not do anything, unless asked explicitly. I was thinking about adding a checkbox and perform the computation only if the checkbox is on, but this gives another problem: how to uncheck the checkbox from Sage interact after computation is done. I am thinking about an interact which allows some comfortable manipulations with matrix rows and can be used for row pivoting, evaluating inverse functions, solving systems of linear equations and evaluating rank and determinants. For example, can be used on recitations. If something like this has been done, let me know, please. Many thanks Robert Marik -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.comsage-support%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org -- 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: create a subdiagonal matrix quickly
I should mention that these methods are all nice for this problem, but they also end up copying an awful lot of zeros. I think it would be way more efficient in general to make a zero matrix, then set the right diagonal by hand using a for loop. Don't you think using a sparse matrix would be a better thing to do in such situations? Rajeev --~--~-~--~~~---~--~~ 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] unable to get SAGE working on my debian lenny machine ...
Hi, I have recently started using SAGE on sagenb.org and I am very impressed by it. I have downloaded the full system and was following the instruction given, but it didn't work for me. Precisely, the following problems come - 1. it is unable to execute the binary file 10:38:07 $ ./sage -- | Sage Version 3.4.1, Release Date: 2009-04-21 | | Type notebook() for the GUI, and license() for information.| -- /home/rajeev/sage/local/bin/sage.bin: /home/rajeev/sage/local/bin/sage.bin: cannot execute binary file 2. on giving make, the first few lines are- 10:38:11 $ make cd spkg ./install all 21 | tee -a ../install.log /bin/ls: cannot access bzip2-*-install: No such file or directory /bin/ls: cannot access dir-*-install: No such file or directory /bin/ls: cannot access prereq-*-install: No such file or directory ... Though I have been using linux for sometime, I am good enough to understand what's going on here. Best, Rajeev --~--~-~--~~~---~--~~ 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: unable to get SAGE working on my debian lenny machine ...
Thanks a lot William. This was the problem. He downloaded the wrong binary for his computer/OS. Maybe he downloaded a 64-bit binary for a 32-bit operating system or something. I downloaded the correct binary and its working fine. Sorry for a question, which should not have been there in first place! Thanks again, Rajeev --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---