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

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


[sage-support] How to write Sage code to cython code

2011-09-17 Thread Santanu Sarkar
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


Re: [sage-support] How to write Sage code to cython code

2011-09-17 Thread Rajeev Singh
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] How to write Sage code to cython code

2011-09-17 Thread Santanu Sarkar
It always returns 101, not a random prime of 100 bit integer.

On 17 September 2011 18:04, Rajeev Singh rajs2...@gmail.com wrote:

 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


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

2011-09-17 Thread D. S. McNeil
 It always returns 101, not a random prime of 100 bit integer.

That's because in Python/Cython, the carat ^ isn't exponentiation,
it's bitwise xor.  The most general solution is to use **:

Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type help, copyright, credits or license for more information.
 2^(100-1)
97
 2^(100)
102
 2**(100-1)
633825300114114700748351602688L
 2**(100)
1267650600228229401496703205376L


Doug

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

2011-09-17 Thread Santanu Sarkar
Thank you.
Is there any function in Python for inverse modulo of an integer?
Corresponding Sage function is  A=15.inverse_mod(17).
Also is there any function like
''.join(str(i) for i in A)  in Python for an array A?



On 17 September 2011 19:36, D. S. McNeil dsm...@gmail.com wrote:

  It always returns 101, not a random prime of 100 bit integer.

 That's because in Python/Cython, the carat ^ isn't exponentiation,
 it's bitwise xor.  The most general solution is to use **:

 Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
 Type help, copyright, credits or license for more information.
  2^(100-1)
 97
  2^(100)
 102
  2**(100-1)
 633825300114114700748351602688L
  2**(100)
 1267650600228229401496703205376L


 Doug

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


-- 
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] which system is called ?

2011-09-17 Thread Thierry Dumont
For a small introduction to Sage, I want to show what is really called, 
for a set of problems, depending on, say, the field we use:


Example:
from sage.misc.citation import get_systems
A=Matrix(RDF,[[1,3,2],[1,4,2],[0,5,2]])
B=vector(RDF,[1,2,3])
get_systems ('A.solve_left(B)')
['numpy', 'scipy']
okay!
but:
get_systems ('A\B')
[]

Why ? we do not use the LU factorization of numpy in the second case?


Other example:

A=Matrix(QQ,[[1,3,2],[1,4,2],[0,5,2]])
B=vector(QQ,[1,2,3])
get_systems ('A.solve_left(B)')
[]
It seems that linbox would be the good tool.


Is it because get_systems do not give the good answer? In that case, how 
to make a trace of what is really called?


Yours
t.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
attachment: tdumont.vcf

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

2011-09-17 Thread Amir
  Hi

  Thanks for your response.  Here is the issue I am facing right now.
I am running this particular piece of code on sage which basically
runs the command
 t=gp.thueinit(f(x),1);
 m=gp.thue(t,1)

for a number of cubic polynomials f(x). It turns out this works fine
for most polynomials. I would like to know which ones are the ones for
which
the code above fails.

I tried running my program on an older version of pari, even though
there were bugs reported in that too, the number of bugs was
definitely less. So this is
definitely an issue with pari/gp too.
But any pointers on how to figure out what polynomials this fails for
are welcome. And is it possible to run sage 4.7.1 with an older
version of Pari/gp?

To answer your question, I am using VMWare on Windows to run sage.

Thanks
Amir


On Sep 16, 1:06 am, luisfe lftab...@yahoo.es wrote:
 On Sep 15, 12:43 pm, Amir amirg...@gmail.com wrote:

   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

 An exception is not the way to dela with this error. We need gp to
 work without problems.

 Do you use the VirtualBox image to deal get this problem? I will try
 to reproduce it.

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