In Boolean function truth tables in n variables, the table is arranged x_{n-1}, x_{n-2},...,x_1,x_0. How can I change so the order is x_0, x_1,... instead?

asked 2018-10-02 20:55:12 +0200

twc gravatar image

In Boolean function truth tables in n variables, the table is arranged x_{n-1}, x_{n-2},...,x_1,x_0. How can I change so the order is x_0, x_1,... instead?

edit retag flag offensive close merge delete

Comments

1

Could you please provide some code showing the situation ?

tmonteil gravatar imagetmonteil ( 2018-10-02 21:10:05 +0200 )edit
1

I enter "from sage . crypto . boolean_function import BooleanFunction" in Sage. Suppose we have the list L={(0,0,0), (0,0,1),...,(1,1,1)} of the 8 binary 3-tuples in lex order and we label them by (x2,x1,x0), which is what Sage does. Then inputs "B=BooleanFunction([1,1,0,0,1,0,1,1])" and "P=B.algebraic_normal_form()" give output " P = x0x1x2 + x0x2 + x1x2 + x1 + 1". But if we label the entries in L with (x0,x1,x2) (which I want to do and which Mathematica does) then the algebraic normal form for truth table B is "P1 = x0x1x2 + x0x1 + x0x2 + x1 + 1" (that is, we are reversing the order in which x2,x1,x0 are read). My question is how can I get Sage to label tables like L in this way?

twc gravatar imagetwc ( 2018-10-08 16:15:41 +0200 )edit

This is not my forte but it seems this labeling is a convention of Sage. Changing it would entail changing the implementation of BooleanFunction. Do you really want to change B and/or P? It is much easier to e.g. define P1 = P.subs(dict(zip(P.parent().gens(), reversed(P.parent().gens())))).

rburing gravatar imagerburing ( 2018-10-08 17:32:30 +0200 )edit
1

Thank you, that is a very nice and simpler solution to the problem.

twc gravatar imagetwc ( 2018-10-10 20:33:32 +0200 )edit