ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 27 May 2021 12:05:08 +0200Evaluation of Boolean function at a point.https://ask.sagemath.org/question/57285/evaluation-of-boolean-function-at-a-point/Hello! I am struggling with the following code. I have a random Boolean function, f, in n variables (n varies) and also a set of n tuples which is generated from some other code. Now I want to evaluate the function f at one of the points, i.e., I want to determine f(a). But a, being of the form say a = [random.randit(0,1) for i in range(n)], is not being taken as an input for f. Moreover changing a to tuple(a) or list(a) neither works. I am writing down the problem in the following code:
`n = 4`
`R = BooleanPolynomialRing(n,['x%d'%i for i in range(n)])`
`f = R.random_element()`
`print(f)`
`import random`
`a = [random.randint(0,1) for i in range(n)]`
`print(f(a))`
Upon running this shows the error:
`"Number of arguments is different from the number of variables of parent ring."`Thu, 27 May 2021 00:37:22 +0200https://ask.sagemath.org/question/57285/evaluation-of-boolean-function-at-a-point/Answer by rburing for <p>Hello! I am struggling with the following code. I have a random Boolean function, f, in n variables (n varies) and also a set of n tuples which is generated from some other code. Now I want to evaluate the function f at one of the points, i.e., I want to determine f(a). But a, being of the form say a = [random.randit(0,1) for i in range(n)], is not being taken as an input for f. Moreover changing a to tuple(a) or list(a) neither works. I am writing down the problem in the following code:</p>
<p><code>n = 4</code></p>
<p><code>R = BooleanPolynomialRing(n,['x%d'%i for i in range(n)])</code></p>
<p><code>f = R.random_element()</code></p>
<p><code>print(f)</code></p>
<p><code>import random</code></p>
<p><code>a = [random.randint(0,1) for i in range(n)]</code></p>
<p><code>print(f(a))</code></p>
<p>Upon running this shows the error:</p>
<p><code>"Number of arguments is different from the number of variables of parent ring."</code></p>
https://ask.sagemath.org/question/57285/evaluation-of-boolean-function-at-a-point/?answer=57294#post-id-57294A single argument consisting of a list or a tuple is not accepted as input. Only keyword arguments or `n` positional arguments (but not both) are accepted. To pass `n` positional arguments, you can do `f(*a)`.Thu, 27 May 2021 12:05:08 +0200https://ask.sagemath.org/question/57285/evaluation-of-boolean-function-at-a-point/?answer=57294#post-id-57294