On Thu, May 29, 2014 at 11:37 AM, Simon King <simon.k...@uni-jena.de> wrote: > Hi Stephen > > On 2014-05-29, Stephen Kauffman <strangerl...@gmail.com> wrote: >> Specifically I have a polynomial such as mypoly = X*Y + 1 in >> BooleanPoynomialRing() and str(mypoly) converts it to the string 'X*Y + 1' >> then I do some stuff with re pattern matching to construct the string '1 - >> x*y' which I now want to convert to a polynomial in 'x' and 'y' in QQ. Are >> there any built in functions or methods to do that? > > Generally, if you have an algebraic structure Y (often called "parent") in > Sage, and have some element x of some other algebraic structure x, then > Y(x) tries to convert x into an element of Y. The same holds for > conversion of a string. > > Note, however, that a conversion is not necessarily making mathematical > sense, if the structures X and Y are too different (i.e., there may be > no homomorphism from X to Y). So, use conversions only if you know what > you are doing. > > What you describe would be as follows: > sage: P.<x,y> = BooleanPolynomialRing() > sage: mypoly = x*y+1 > sage: R = QQ['x','y'] > sage: R(mypoly) > x*y + 1 > sage: R('1-x*y') # replacing + by - in str(mypoly) > x*y - 1 > > Best regards, > Simon
Simon -- great answer -- like my second one but even better. This seems like the sort of thing our FAQ should have. Believe it or not, we have a Sage FAQ: http://sagemath.org/doc/faq/ I doubt it has been touched in years, and I doubt anybody even knows how to change it... > > > -- > 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 http://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/d/optout. -- William Stein Professor of Mathematics University of Washington http://wstein.org -- 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 http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.