Re: [sage-support] gsl in sage outside of notebook

2011-09-15 Thread Robert Bradshaw
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


Re: [sage-support] complex parts

2011-09-15 Thread Anton Sherwood

On 2011-9-14 23:35, Robert Bradshaw wrote:

... Otherwise, z.real, z.imag is probably going to
be as fast as you can get, and there's no need to define a function,
you could just write

sage: a = complex(3,4)
sage: x, y = a.real, a.imag


For trivial cases, yeah, but consider

parametric_plot((f(t-0.5j).real, f(t-0.5j).imag), (t,tmin,tmax))

parametric_plot(ReIm(f(t-0.5j)), (t,tmin,tmax))

--
Anton Sherwood *\\* www.bendwavy.org *\\* www.zazzle.com/tamfang

--
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: complex parts

2011-09-15 Thread achrzesz

 For trivial cases, yeah, but consider

         parametric_plot((f(t-0.5j).real, f(t-0.5j).imag), (t,tmin,tmax))

         parametric_plot(ReIm(f(t-0.5j)), (t,tmin,tmax))

 --
For example:

sage: f(z)=[z.real(),z.imag()]
sage: t=var('t')
sage: parametric_plot(f(exp(I*(t-5*I))),(t,0,2*pi))

Andrzej Chrzeszczyk

-- 
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: Asking whether a number is in QQ or not

2011-09-15 Thread Volker Braun
b in QQ is (or should be) equivalent to QQ(b) not throwing an error. But if 
that fails, it only means that Sage can't convert it to a rational directly, 
it is perfectly possible that after a series of (computationally expensive) 
steps one could transform b into a rational. But if we would always try 
every possible simplification then Sage would run very slow. Also, if in 
were mathematical equivalence, what should Sage return for zeta(5) in QQ?  

-- 
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: for loop in 3d image

2011-09-15 Thread achrzesz
A colon is missing after range(20).
The following version works for me:
(but the indentation  in this post may be broken)
x,y,z,t = var('x,y,z,t')
P = implicit_plot3d(x^2 +y^2 -z^2 ==1, (x,-3.2,3.2),(y,-3.2,3.2),
(z,-3,3),opacity=.2,color='blue')
for k in range(20):
P += parametric_plot3d([cos((2*pi*k)/(20))+sin((2*pi*k)/
(20))*t,sin((2*pi*k)/(20))-cos((2*pi*k)/(20))*t,t],
(t,-3,3),color='red',thickness=2)
P.show()

Andrzej Chrzeszczyk

-- 
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

2011-09-15 Thread Rajeev Singh
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


[sage-support] Re: Bug in pari/gp or sage? Any fixes?

2011-09-15 Thread Amir
 Hi

 I have the same problem. I am using sage 4.6 installed on windows
vista. This is part of code I have written in sage. Is there anyway I
can catch this error and make an exception?

 Thanks



On Sep 13, 9:49 am, vasu tewari.v...@gmail.com wrote:
 Hi
 Thanks for the reply.
 I am also using Sage 4.7.1 installed on Ubuntu 10.04. I installed it
 using the binary file available at the site.
 It is weird indeed that you don't end up getting an error! Or am I
 missing something?

 On Sep 13, 12:47 am, luisfe lftab...@yahoo.es wrote:







  On Sep 13, 9:11 am, vasu tewari.v...@gmail.com wrote:

   Hi all
   I am trying to run a particular piece of code and it gives an error
   saying there is a bug in Pari/gp. It turns out that the bug is not
   present in previous versions of Pari like 2.3.4 (on Windows at least).
   And if I understand correctly that Sage ships with the newest install
   of Pari. Is there any way to use the latest Sage version with an old
   version of Pari?? Any input is appreciated.

   For those interested, what follows is the code along with the error
   message.

   t=gp.thueinit(x^3+21*x^2-2*x-25,1);
   m=gp.thue(t,1)

  Hi Vasu,

  Which version of Sage are you running? Which plattform? How have you
  installed it?

  I cannot reproduce your error in Sage 4.7.1

  sage: t=gp.thueinit(x^3+21*x^2-2*x-25,1);
  sage: m=gp.thue(t,1)
  sage: m
  [[1, 0]]

-- 
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] loading a series of files inside a loop

2011-09-15 Thread Andrew Francis
Hi all,

I'm new to this group; thanks for having me.

I have generated a large number of text files (several lots of 81
files) with the intention of reading them back into another sage
program (via the command line).  The text filenames were generated by
the line

outputfilename=Dropbox/simdata_g1%sk%sc%seps%s.sage%
(g1int,kint,gridc,grideps)

so that the file names have a number of variables, and a typical file
is of form simdata_g18k1c2eps3.sage.  No problem this far.

The files are of a form that should be sage-readable, for instance one
line is
Lpeak = 0.00101546953017314

I now want to use these files to generate some further output, reading
them into a loop as follows:

def grid_plot(grid,gamma,kappa):
for gridc in [0..8]:
for grideps in [0..8]:
load 'Dropbox/SAGE-outputs-5genes/gamma5kappa3/
simdata_g15k3c%seps%s.sage'%(cstr,epsstr)
blah blah

I am hoping to extract and use values such as that of Lpeak above.

However while I am able to load a file for particular values of the
parameters *outside* the def statement (using exactly the same load
statement), I have been unable to make sage run through my files and
extract the values inside them.  The error I get is:

ValueError: argument (='Dropbox/SAGE-outputs-5genes/gamma5kappa3/
simdata_g15k3c%seps%s.sage'%(cstr,epsstr)) to load or attach must
have extension py, pyx, sage, spyx, or m

Clearly the file does have a correct extension (.sage), as the same
command works fine outside the def statement.  So is there a problem
loading files generically inside a function definition?  Is there some
other way around this?

Thanks,
Andrew

-- 
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: Asking whether a number is in QQ or not

2011-09-15 Thread Simon King
Hi Volker,

On 15 Sep., 11:45, Volker Braun vbraun.n...@gmail.com wrote:
 b in QQ is (or should be) equivalent to QQ(b) not throwing an error.

No, that's incorrect. It should be (and is) equivalent to QQ(b)==b
returning True.

QQ(b) is just a conversion. You can convert any element of a finite
prime field into QQ:

   sage: b = GF(5)(2)
   sage: QQ(b)
   2

However, the test QQ(b)==b is not only testing whether conversion
works, but also whether there is a coercion from the ring containing b
to QQ. In my example, there is no coercion, thus, no equality:

   sage: cm.explain(QQ, b.parent())
   Will try _r_action and _l_action
   Unknown result parent.
   sage: QQ(b) == b
   False

Hence, we have
   sage: b in QQ
   False

Best regards,
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


[sage-support] Re: plot3d with adaptive=True fails

2011-09-15 Thread kcrisman


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


Re: [sage-support] Re: plot3d with adaptive=True fails

2011-09-15 Thread Rajeev Singh
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] Re: plot3d with adaptive=True fails

2011-09-15 Thread achrzesz
Also:

sage:  T = Cylindrical('height', ['radius', 'azimuth'])
sage: r, theta, z = var('r theta z')
sage: plot3d(r*sin(1/r), (r, 0.0, 0.2), (theta, 0, 2*pi),
transformation=T,adaptive=True)

Andrzej Chrzeszczyk

-- 
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] [ANN} OpenOpt, FuncDesigner, DerApproximator, SpaceFuncs release 0.36

2011-09-15 Thread dmitrey
Hi all,
new release of our free soft (OpenOpt, FuncDesigner, DerApproximator,
SpaceFuncs) v. 0.36 is out:

OpenOpt:

Now solver interalg can handle all types of constraints and
integration problems
Some minor improvements and code cleanup

FuncDesigner:

Interval analysis now can involve min, max and 1-d monotone
splines R - R of 1st and 3rd order
Some bugfixes and improvements

SpaceFuncs:

Some minor changes

DerApproximator:

Some improvements for obtaining derivatives in points from R^n
where left or right derivative for a variable is absent, especially
for stencil  1

See http://openopt.org for more details.

Regards, D.

-- 
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: Asking whether a number is in QQ or not

2011-09-15 Thread Simon King
PS:

sage: cm.explain(QQ, b.parent())

I forgot to copy-and-paste the definition of cm. It was:

  sage: from sage.structure.element import get_coercion_model
  sage: cm = get_coercion_model()

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


Re: [sage-support] Re: plot3d with adaptive=True fails

2011-09-15 Thread Dan Drake
On Thu, 15 Sep 2011 at 06:40AM -0700, kcrisman 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.

The docstring for plot3d has an (undocumented!) use of initial_depth,
but that didn't solve my problem. I just set plot_points=200 and that
gave me something good enough; switching to cylindrical coordinates also
worked, although I didn't like the look as much.



Dan

--
---  Dan Drake
-  http://mathsci.kaist.ac.kr/~drake
---


signature.asc
Description: Digital signature


[sage-support] Re: Asking whether a number is in QQ or not

2011-09-15 Thread Alex Lara
Thank you to all of you!

On Sep 15, 12:59 pm, Simon King simon.k...@uni-jena.de wrote:
 PS:

     sage: cm.explain(QQ, b.parent())

 I forgot to copy-and-paste the definition of cm. It was:

   sage: from sage.structure.element import get_coercion_model
   sage: cm = get_coercion_model()

 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