Ask Your Question
0

Boolean Polynomial Ring

asked 3 years ago

Sanu gravatar image

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)
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 3 years ago

rburing gravatar image

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.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 3 years ago

Seen: 718 times

Last updated: Jul 14 '21