I am writing a piece of Matlab 16 code which utilizes the following definition to compute Boolean functions of a specified arity which fulfill the linearity condition. This property is found in this paper (page 4) and is stated here again as follows:
A function $f(x_1,...,x_n)$ is said to be linear if its canonic expression has the form \begin{equation} f(x_1,...,x_n) = a_0 \oplus a_1x_1 \oplus a_2x_2 \oplus...\oplus a_nx_n\end{equation} where $a_i (0\le i\le n)$ is 0 or 1 and $\oplus$ denotes the 2-input exclusive OR operation.
Although the paper does not specify an order of operation (AND vs. XOR) I did write the code for both scenarios. For either scenario I am not getting the correct subset of operations.
The way I understand this equation is that each $a_i$ take on 0 or 1. so there are a total of 8 combinations. Since we are dealing with arity $n$, we4 have $n$ $x$ values which also may take on values of either 0 or 1. The resulting values of the various permutations are then merged and that bnary string is the truth function of some operation. That operation is then linear.
The code is as follows:
clear all;
clc;
AtomNum = 2;
% This creates the a values from M.'s paper
for j=0:2^(AtomNum+1)-1
a{j+1} = dec2bin(j);
for n = length(a{j+1}):AtomNum
a{j+1} = strcat('0',a{j+1});
end
end
% Create the x combinations but that are one binary digit
% shorter
for j=0:2^(AtomNum)-1
x{j+1} = dec2bin(j);
for n = length(x{j+1}):AtomNum-1
x{j+1} = strcat('0',x{j+1});
end
end
% Now evaluate expression
for j=0:2^(AtomNum+1)-1
A = a{j+1};
Q = '';
V = A(1);
for k=0:2^(AtomNum)-1
X = x{k+1};
for m=1:AtomNum
V = xor(V,and(str2num(A(m+1)),str2num(X(m))));
end
Q = strcat(Q,num2str(V));
end
Q
end
The truth functions/operations that meet the linear criteria with this code are: $\top, \leftrightarrow, \leftarrow, \rightarrow$.
If you assume that I have the order of operation incorrect then the code becomes:
clear all;
clc;
AtomNum = 2;
% This creates the a values from M.'s paper
for j=0:2^(AtomNum+1)-1
a{j+1} = dec2bin(j);
for n = length(a{j+1}):AtomNum
a{j+1} = strcat('0',a{j+1});
end
end
% Create the x combinations but that are one binary digit
% shorter
for j=0:2^(AtomNum)-1
x{j+1} = dec2bin(j);
for n = length(x{j+1}):AtomNum-1
x{j+1} = strcat('0',x{j+1});
end
end
% Now evaluate expression
for j = 0:2^(AtomNum+1)-1
A = a{j+1};
Q = '';
V = A(1);
for k = 0:2^(AtomNum)-1
X = x{k+1};
for m = 1:AtomNum
V = xor(V,str2num(A(m+1)));
V = and(V, str2num(X(m)));
end
Q = strcat(Q,num2str(V));
end
Q
end
with output: $\bot, q, \land, \nrightarrow$
The solutions I should get are: $\top, \bot, p, q, \lnot p, \lnot q, \oplus, \leftrightarrow$
I would greatly appreciate any help understanding where my understanding is incorrect or where my code fails to produce the correct solutions.