Problem in Magma regarding truth table and ANF

2018-10-06 17:40:16

So, I am trying to solve a problem in Magma, that is implement a program which gives me the ANF of a Boolean function if the input is given with the truth table. There is a really nice algorithm to do that but I cannot implement it in Magma in its completeness because I am still learning how to work in it. This is my code:

list1:=[0,0,0,0,0,1];

for k:=2 to 7 do

if k lt 4 then

s:=Reverse(Append(Intseq(k,2),0));

print k,"---->",s;

list1:=Insert(list1,3*k+1,3*k+3,s);

else

s:=Reverse(Intseq(k,2));

print k,"---->",s;

list1:=Insert(list1,3*k+1,3*k+3,s);

end if;

end for;

m:=Matrix(3,list1); // matrix of binary representations of numbers 0 to 7

print m;

f:=[0,0,1,0,1,1,0,1]; // my Boolean function

function g(x1,x2,x3)

return f[1]; // initial value for the function g which will be the AFN

end function;

for k:=1 to 7 do

if g(m[k,1],m[k,2],m[k,3]) ne f[k] then

g(x1,x2,x3):=g(x1,x2,x3)+x1^(m[k,1])*x2^(m[k,2])*^x3^(m[k,3]);

//updating the function