# Boolean Polynomial Ring

Dear all, I am working polynomial ring of 100 binary variables. Sometime I get polynomial with only 4 variables. I want to study these polynomials. My following code is giving error:

from sage.crypto.boolean_function import BooleanFunction
V = BooleanPolynomialRing(100,['x%d'%(i) for i in range(100)])
V.inject_variables()
f=x1*x2+x3*x4
xx=f.variables()
l=len(xx)
P=BooleanPolynomialRing(l,map(str,xx))
f=P(f)

edit retag close merge delete

Sort by ยป oldest newest most voted

It seems that the BooleanPolynomialRing constructor doesn't accept a map object as a list of variable names, only strings and lists and tuples. It doesn't recognize map(str, xx), so it converts it to a string, which yields '<map object at 0x7f9a3205e400>', which is not alphanumeric, so it says it's not valid as a name of a variable.

Instead, you can pass list(map(str, xx)).

An easier option is just P = BooleanPolynomialRing(l, f.variables()). The constructor converts all the elements of f.variables() to strings, to be used as the names of variables in P.

By the way, instead of inject_variables you can also do x = V.gens(), and then x[0] will be x0, etc. This is useful in library code, where you don't want to inject variables. In user code, injecting variables is fine.

more