Permutation of Boolean function in Matlab

1 回表示 (過去 30 日間)
H R
H R 2015 年 3 月 14 日
回答済み: ag 2024 年 12 月 27 日
I have the Boolean function f = x0x1 + x1x2 (Between x0 and x1 is And operator and between (x0x1) and (x1x2) is XoR operator) and x0,x1,x2 are logical for example x0=[1 0 1 0] ,...
What I am looking for is the permutations (1, 0, 2) and (0, 2, 1) in the Boolean function above.
It means that I have to get different Boolean functions made up with the permutation. For example finding f=x1x0+x0x2 and f=x0x2+x2x1 from f=x0x1+x1x2 by permutation (1,0,2) and (0,2,1) respectively.
Can anybody help me to write the Matlab code for the permutation of the Boolean function? Thanks in advance.

回答 (1 件)

ag
ag 2024 年 12 月 27 日
Hi HR,
I understand that you want to evaluate the expression "((x0 & x1) ^ (x1 & x2))" by permuting the values of (x0), (x1), and (x2).
To achieve this, you can concatenate the values of (x0), (x1), and (x2) into a two-dimensional array. Subsequently, you can pass the required arrays according to the specified permutation.
Below is a code snippet that demonstrates this process:
% Assuming x0, x1, and x2 are arrays of logical values
x = [x0; x1; x2];
% Define the permutations
permutations = {[1, 0, 2], [0, 2, 1]}; %since MATLAB requires indices to start from 1, add 1 before accessing the index
% Iterate over each permutation
for i = 1:length(permutations)
perm = permutations{i};
% Assuming calcExpression is a function that takes three arrays as input, namely x0, x1, and x2
result = calcExpression(x(perm(1)+1, :), x(perm(2)+1, :), x(perm(3)+1, :));
disp(result);
end
Hope this helps!

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by