On Thu, May 29, 2014 at 11:22 AM, Stephen Kauffman
<[email protected]> wrote:
> That's a lot simpler than I thought it would be. Thanks. I'm converting free
> boolean algebra statements to corresponding probability statements with a
> recursive function hopefully.
>
Yep, there's a general Sage convert functionality, which is often
R(foo), where R is a parent object, and foo is anything that might
make sense. Be careful though, since it can easily lead to
mathematically meaningless results, since "R(foo)" in Sage means "make
something in R from foo by hook or crook".
Another useful command is sage_eval, which is like Python's eval, but
with the preparser:
R.<x,y> = PolynomialRing(QQ)
sage_eval('1 - x*y', globals())
-x*y + 1
Note that I expect this to work, but it doesn't:
R.<x,y> = PolynomialRing(QQ)
sage_eval('1 - x*y', {x:x, y:y})
> On 5/29/2014 2:17 PM, William Stein wrote:
>> On Thu, May 29, 2014 at 11:13 AM, Stephen Kauffman
>> <[email protected]> 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? Or does a python routine
>>> have to be written to accomplish my task? Thanks
>>
>> R.<x,y> = PolynomialRing(QQ)
>> f = R('1 - x*y')
>> f
>>
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/sage-support.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.