[sage-support] Re: how does one do this in Cython?
Thanks, William. I don't know why I didn't try cimport on that other example; that certainly works with Rational. But I shouldn't have simplified the example to that level. What I *really* want to cdef is MPolynomial_libsingular. Something like this: from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular cpdef MPolynomial_libsingular add(MPolynomial_libsingular a, MPolynomial_libsingular b): return a+b But I get all kinds of errors. First a bunch like this: - In file included from _Users_user_test_import_pyx_1.c:206: /Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/ local/include/factory.h:29:20: error: iostream: No such file or directory In file included from /Applications/Sage-4.6.2-OSX-64bit-10.6.app/ Contents/Resources/sage/local/include/factory.h:51, from _Users_user_test_import_pyx_1.c:206: /Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/ local/include/templates/ftmpl_array.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘’ token /Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/ local/include/templates/ftmpl_array.h:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘’ token - then more of other types. john On Jul 24, 10:34 pm, William Stein wst...@gmail.com wrote: On Sunday, July 24, 2011, john_perry_usm john.pe...@usm.edu wrote: What about not-the-notebook? :-) For example, I have the following file, called test_rational.pyx: from sage.rings.rational import Rational import --- cimport ?! cpdef Rational add(a, b): return a + b When I try to attach it to sage, I get: [lots of output removed] _home_perry_test_rational_pyx_1.pyx:8:6: 'Rational' is not a type identifier I get the same error with from sage.rings.rational import Rational cpdef Rational add(a, b): cdef Rational c c = a + b return c john On Jul 24, 7:53 pm, William Stein wst...@gmail.com wrote: On Sun, Jul 24, 2011 at 5:47 PM, john_perry_usm john.pe...@usm.edu wrote: I want to declare c to be of the type defined by the class Rational. I'm sure this is easy, but what I want to do is this: from sage.rings.rational import Rational cdef Rational c but that doesn't work. Neither does cimport (which I found in a file somewhere, albeit commented out, and now I know why). Actually, from sage.rings.rational cimport Rational *does* work, but you have to put it in the right place. As an illustration, try this in the notebook: %cython from sage.rings.rational cimport Rational def f(Rational c, s): cdef Rational dummy = Rational('2/3') # just for illustrative purposes print dummy mpq_set_str(c.value, s, 10) Then in the next cell put this: c = 8/7 f(c, '5/3') print c -- William regards john perry -- 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 -- William Stein Professor of Mathematics University of Washingtonhttp://wstein.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 -- William Stein Professor of Mathematics University of Washingtonhttp://wstein.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] Re: how does one do this in Cython?
On Monday 25 July 2011, john_perry_usm wrote: Thanks, William. I don't know why I didn't try cimport on that other example; that certainly works with Rational. But I shouldn't have simplified the example to that level. What I *really* want to cdef is MPolynomial_libsingular. Something like this: from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular cpdef MPolynomial_libsingular add(MPolynomial_libsingular a, MPolynomial_libsingular b): return a+b But I get all kinds of errors. First a bunch like this: - In file included from _Users_user_test_import_pyx_1.c:206: /Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/ local/include/factory.h:29:20: error: iostream: No such file or directory In file included from /Applications/Sage-4.6.2-OSX-64bit-10.6.app/ Contents/Resources/sage/local/include/factory.h:51, from _Users_user_test_import_pyx_1.c:206: /Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/ local/include/templates/ftmpl_array.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘’ token /Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/ local/include/templates/ftmpl_array.h:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘’ token - then more of other types. You'll need to compile your extension module (i.e. your pyx file) with C++ instead of C. See http://sagemath.org/doc/developer/coding_in_cython.html#special-pragmas Cheers, Martin -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x8EF0DC99 _otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF _www: http://martinralbrecht.wordpress.com/ _jab: martinralbre...@jabber.ccc.de -- 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: how does one do this in Cython?
On Jul 25, 6:46 am, Martin Albrecht martinralbre...@googlemail.com wrote: You'll need to compile your extension module (i.e. your pyx file) with C++ instead of C. See http://sagemath.org/doc/developer/coding_in_cython.html#special-pragmas From that link, I understood that I need to prepend # clang: C++ to the file. I get the same errors. john -- 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: Plots and Ticks
On 7/24/11 5:36 PM, Dox wrote: Hi people, I have a little doubt about ticks in plots. I'd like to know whether the following tasks are possible: * eliminate all ticks of a plot. * eliminate the dependent variable ticks. * changing the number by letter, either 1 by \eta and 2 by 2\eta or 1 by \eta and 1.2 by \xi. Please search for ticks in the graphics documentation: http://www.sagemath.org/doc/reference/sage/plot/plot.html There are several examples there that help answer your questions. Thanks, Jason -- 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: how does one do this in Cython?
Hi John, see attachment. You'll have to change the cinclude path for it to work on your machine. On Monday 25 July 2011, john_perry_usm wrote: On Jul 25, 6:46 am, Martin Albrecht martinralbre...@googlemail.com wrote: You'll need to compile your extension module (i.e. your pyx file) with C++ instead of C. See http://sagemath.org/doc/developer/coding_in_cython.html#special-pragmas From that link, I understood that I need to prepend # clang: C++ to the file. I get the same errors. john Cheers, Martin -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x8EF0DC99 _otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF _www: http://martinralbrecht.wordpress.com/ _jab: martinralbre...@jabber.ccc.de -- 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 #clang c++ #cinclude /home/malb/Sage/current/local/include/singular #clib m readline singular givaro gmpxx gmp from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular cpdef MPolynomial_libsingular add(MPolynomial_libsingular a, MPolynomial_libsingular b): return a+b
[sage-support] Re: extending the Expression class
Is the syntax for this class t = new_exp(SR, symbolic_expression)? So that sage: t returns symbolic_expression? Second, I'm not entirely sure I understand how this patch was made, let alone how to install it. I skimmed over http://www.sagemath.org/doc/developer/patching_spkgs.html and http://www.sagemath.org/doc/developer/producing_spkgs.html#chapter-spkg but found the whole thing to be a bit over my head (I'm a newbie, sorry). Is there a series of instructions you could provide me for the installation of your patch? I'm sure you're very busy, so I really do appreciate the effort. Thanks, Steven On Jul 21, 6:37 am, Burcin Erocal bur...@erocal.org wrote: Hi, On Wed, 20 Jul 2011 17:02:49 -0700 (PDT) Steven Pollack stevenlawrencepoll...@gmail.com wrote: I noticed that a thread was developed for this sort of thing (http:// groups.google.com/group/sage-support/browse_thread/thread/ d50dc3bc2bdbeab0/34798c0585fc034f?lnk=gstq=nicolasfwc=1#), but I'm a newbie, and a lot of it went over my head. Is there a simple to create a subclass of sage.symbolic.expression.Expression? The main problem with subclassing Expression is that the result returned from arithmetic is hardcoded to be an Expression again. I quickly did a search and replace in the sage/symbolics directory to pass the new class as an argument to the fast expression constructor new_Expression_from_GEx. Here is the patch: http://sage.math.washington.edu/home/burcin/subclass_expression.patch After applying the patch the following works: sage: class new_exp(Expression): : pass : sage: t = new_exp(SR, x) sage: t x sage: type(t) class '__main__.new_exp' sage: u = t*t sage: type(u) class '__main__.new_exp' sage: u x^2 Hope this helps. Burcin -- 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: Plots and Ticks
Hi again. I've seen the documentation for plot. However, the last of the points I highlight seems to be not possible. I'd like to change the numerical ticks (1,2,3,4) by alphabetical ones (eta, xi, lambda, rho). Thank you -- 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] method .polynomial() gives unexpected answer
Apparently, this is caused by a problem in degree() which is used in polynomial(). In your example: sage: pol2.degree(q) 0 sage: pol2.degree(p) 3 You get the expected behavior if you bring q into pol2.parent() explicitly: sage: q=pol2.parent()(q) sage: pol2.degree(q),pol2.polynomial(q) (3, 4*q^3 + 3*q + 2) So, this seems like an error to me. In the implementation of degree() the line reading return singular_polynomial_deg(p, (MPolynomial_libsingularx)._poly, r) should probably be changed (x is the generator passed to the method). But maybe somebody who knows more about the singular/sage connection can say more about this. cheers, julian * rafaeldleon rafaeldl...@gmail.com [2011-07-25 12:31:29 -0700]: Hello all, I don´t know if the following is an error in the implementation of the method polynomial or if I am using it in a way that is not intended, but it seems that the use of the method polynomial changes when I am in a polynomial ring with 2 or with 3 variables. pol and pol2 are the same polynomial in rings with 3 or 2 variables resp. and the method pol.polynomial(q) and pol2.polynomial(q) return different answers. sage: R.p,q,t=ZZ[] sage: pol=2+3*q+4*q^3;pol 4*q^3 + 3*q + 2 sage: parent(pol) Multivariate Polynomial Ring in p, q, t over Integer Ring sage: pol2=pol.polynomial(t).coefficients()[0];pol2 4*q^3 + 3*q + 2 sage: parent(pol2) Multivariate Polynomial Ring in p, q over Integer Ring sage: pol2.polynomial(q) 2 sage: pol.polynomial(q) 4*q^3 + 3*q + 2 Can anyone give me some insight about why I am getting these different answers? Thanks! Rafael -- 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] Re: Plots and Ticks
On 7/25/11 12:29 PM, Dox wrote: Hi again. I've seen the documentation for plot. However, the last of the points I highlight seems to be not possible. It is, but you have to follow the pointers in the documentation to the further documentation in matplotlib. In the Sage documentation for tick_formatters, it says: - ``tick_formatter`` - A matplotlib formatter for the major ticks. There are several options. For more information about formatters, type ``from matplotlib import ticker`` and then ``ticker?``. Doing that shows a number of formatters that you can use to format labels for the ticks. One of those is an IndexFormatter, where you give it a list of strings. Here is an example: plot(x^2,(x,.9,5), ticks=[[1,2,3,4],[]],tick_formatter=ticker.IndexFormatter([0,'eta','rho','my','new'])) See the matplotlib ticker documentation for more possibilities: http://matplotlib.sourceforge.net/api/ticker_api.html#tick-formatting Thanks, Jason -- 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] Running Macaulay2 inside a sage script
Hello, I'm familiar with running just Macaulay2 from the sage notebook. However, I now have a task that requires me to execute a bunch of sage code to calculate an ideal, call some Macaulay2 functions on that ideal, and then return to the sage script to do some more calculations. Is it possible to switch back and forth this way? I have found very little in the sage documentation that even addresses Macaulay2. Thanks! Mel Dunn -- 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: Running Macaulay2 inside a sage script
Perhaps I should clarify a couple more things: I have figured out how to do simple Macaulay 2 commands inside a sage script as follows: macaulay2(S = ZZ/101[t_1 .. t_9, u_1 .. u_9]) However, many of my commands are not working. The code in Macaulay2 which I would like to execute from sage looks like this: mult = I - ( minPrimes := minimalPrimes I; monomialFreeMinPrimes := select(minPrimes, P - saturate(P, product gens S) =!= ideal (1_(ring(I; sum apply(monomialFreeMinPrimes, P - degree(I : saturate(I,P))) ) S = QQ[x,y,z] I = ideal(y-x^2, y^2-x*z) mult(I) When I try to define the mult function using the macaulay2() command, I get a syntax error because of the arrow (-). macaulay2( mult = I - ( minPrimes := minimalPrimes I; monomialFreeMinPrimes := select(minPrimes, P - saturate(P, product gens S) =!= ideal (1_(ring(I; sum apply(monomialFreeMinPrimes, P - degree(I : saturate(I,P))) ) Also, when I type I=macaulay2(ideal(x^2+y)) I get error: syntax error at 'of' Anyway, I know this is a lot of things to ask about, but any help would be appreciated. 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