How to substitute a random sample of variables in Boolean Function
I want to make a function which generates randomly a Boolean function with n variables and then substitutes k of them with zero. I tried to get the list of terms of the function and then do the substitution which is certainly wrong.
def Pol_sub(n,k):
if k>n:
print("substitution can't be done")
else:
B=BooleanPolynomialRing(n,'x')
list=sorted((sample(xrange(0,n),k)))
f=B.random_element()
ls=f.terms()
print(f)
zero_vec=[0 for x in xrange(0,k)]
return(ls.subs({ls[list[i]]:zero_vec[i] for i in xrange(0,k)}))