Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This may not be the best way to recover a polynomial from its string representation but it appears to work.

Say p = R.random_element(degree=2,terms=+infinity), then s = str(p) gives you its representation as a string. To recover p you can try q = R( eval(s)). Then p==q should evaluate to True.

This may not be the best way to recover a polynomial from its string representation but it appears to work.

Say p = R.random_element(degree=2,terms=+infinity), then s = str(p) gives you its representation as a string. To recover p you can try q = R( eval(s)). Then p==q should evaluate to True.

Now, if you are reading a file fr with a polynomial per line, you can try the following to recover the polynomials.

vars = ['x'+str(i) for i in range(10)]
R= BooleanPolynomialRing(names=vars)
R.inject_variables()
polys = [ R(eval(l[:-1])) for l in fr]

Update: Added iteration through file.