On Wednesday, March 21, 2018 at 6:29:37 PM UTC, saad khalid wrote:
>
> Hey everyone:
>
> I'm currently in the process of converting some code from Mathematica to 
> Sage, my primary motivation being that Mathematica is running it too slowly 
> and I was hoping that I could somehow get some increase in speed with Sage. 
> My thought was that this would be easiest if I were able to use cython 
> along with Sage. Is this currently possible? For example, one of the 
> Mathematica functions takes a polynomial in 2 variables as input and 
> computes the value of the order in one of the variables (ie for x1^3 + 
> x1*x2^2 + x2, the order for x1 would be 3). I wrote some Sage could that 
> can do this, but then how can I use what the sage code computes with cython 
> code? When I was trying to compile some cython code in Cocalc using 
> %cython, it would not let me include any Sage code. For eg, I tried 
> including the line:
> R.<x1,x2> = RR[]
>
> but it threw errors at me. Do you think I am approaching this speed up 
> idea in a reasonable way? Or should I be trying to do it purely in Sage or 
> purely in cython? Thanks!
>

A large part of  the Sage library is written in Cython. Cython in Sage 
needs a bit more care. Did you read
http://doc.sagemath.org/html/en/developer/coding_in_cython.html ?

The following works in CoCalc ipython notebook:

%cythondef tst():    from sage.rings.real_mpfr import RR    from 
sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing    R2 = 
PolynomialRing(RR,'x1,x2')    (x1,x2) = R2.gens()    return x1**2-x2**3



Note that to get the needed import statements, you can run

import_statements('RR'), etc



----------------
Tp 
  

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to