2

By hand, I computed $f(x,y) = x \oplus xy = (0, 0, 1, 0)$ since, in ascending (lexicographical) order,

$f(0,0) = 0 \\ f(0,1) = 0 \\f(1,0) = 1 \\ f(1,1) = 0$

However, using the following code on sagemath

R.<x,y> = BooleanPolynomialRing(2)
B = BooleanFunction( x+x*y)
B.truth_table(format='int')

The answer is (0, 1, 0, 0). I tried with other Boolean functions of two variables and I'm getting different answers from what I calculate by hand. Another example is $f(x,y) = x$. By hand, the answer is $f = (0,0,1,1)$ but using sage, it is $(0, 1, 0, 1)$. Is it that the order in which the bits are calculated is incorrect?

A few details for context

I'm specifically interested in the convention regarding Boolean functions. For example, there are tasks that ask to find the ANF of a boolean function given in the $f = (b_1,b_2, \ldots , b_n)$ where $b_i$ is either $0$ or $1$. In the textbooks I have checked, it is often assumed that these values are in ascending order. In this answer, for instance, the truth table was calculated in ascending order

E.Nole
  • 175
  • 5

1 Answers1

2

The truth table

\begin{array}{|c|c|c|} \hline x & y & xy & x \oplus xy \\ \hline 1 & 1 & 1 & 0 \\ \hline 1 & 0 & 0 & 1 \\ \hline 0 & 1 & 0 & 0 \\ \hline 0 & 0 & 0 & 0 \\ \hline \end{array}

and you can use Boolean formulas

f = propcalc.formula("x ^x&y")
f.truthtable()

outputs

x      y      value
False  False  False  
False  True   False  
True   False  True   
True   True   False  
kelalaka
  • 49,797
  • 12
  • 123
  • 211