How to solve the equation of binary logic operation, where all unknowns are 0 or 1

1 回表示 (過去 30 日間)
dcydhb dcydhb
dcydhb dcydhb 2020 年 8 月 8 日
編集済み: dcydhb dcydhb 2020 年 8 月 8 日
For example, I have the following equations, linear equations and nonlinear equations, in which the unknowns can only take 0 or 1, and it is based on this operation rule,
for Addition operation:
1+1=0,1+0=1,0+1=1,0+0=0,
For multiplication operation:
0*0=0,0*1=0,1*0=0,1*1=1
so how to solve the values of all unknowns?
x1+x2+x3+(x4+1)*(x5+x6+1)=x1*x2,
x2+x3+x4+(x5+1)*(x6+x1+1)=x2*x3,
x3+x4+x5+(x6+1)*(x1+x2+1)=x3*x4,
x4+x5+x6+(x1+1)*(x2+x3+1)=x4*x5,
x5+x6+x1+(x2+1)*(x3+x4+1)=x5*x6,
x6+x1+x2+(x3+1)*(x4+x5+1)=x6*x1,
and in fact, the original question consists of 416 equations and 416 variables including form
c0...c31 and x1...x384 which should be only 0 or 1
as i have attached in the
equations.txt
  6 件のコメント
dcydhb dcydhb
dcydhb dcydhb 2020 年 8 月 8 日
i want to say that the equation i have posted is just an example equation and my original equation consists of 300 unknowns so
i need other way rahher than brute force search.
Walter Roberson
Walter Roberson 2020 年 8 月 8 日
gf(x,1) appears to implement the required mathematics.

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2020 年 8 月 8 日
編集済み: Bruno Luong 2020 年 8 月 8 日
[x1,x2,x3,x4,x5,x6]=ndgrid(0:1);
x1 = x1(:);
x2 = x2(:);
x3 = x3(:);
x4 = x4(:);
x5 = x5(:);
x6 = x6(:);
b = [x1+x2+x3+(x4+1).*(x5+x6+1)-x1.*x2, ...
x2+x3+x4+(x5+1).*(x6+x1+1)-x2.*x3, ...
x3+x4+x5+(x6+1).*(x1+x2+1)-x3.*x4, ...
x4+x5+x6+(x1+1).*(x2+x3+1)-x4.*x5, ...
x5+x6+x1+(x2+1).*(x3+x4+1)-x5.*x6, ...
x6+x1+x2+(x3+1).*(x4+x5+1)-x6.*x1 ];
b=mod(b,2);
idx = find(all(b==0,2));
for i=1:length(idx)
k=idx(i);
fprintf('x1=%d,x2=%d,x3=%d,x4=%d,x5=%d,x6=%d\n', x1(k), x2(k), x3(k), x4(k), x5(k), x6(k));
end
Result
x1=1,x2=0,x3=0,x4=0,x5=0,x6=0
x1=0,x2=1,x3=0,x4=0,x5=0,x6=0
x1=0,x2=0,x3=1,x4=0,x5=0,x6=0
x1=0,x2=0,x3=0,x4=1,x5=0,x6=0
x1=0,x2=0,x3=0,x4=0,x5=1,x6=0
x1=0,x2=0,x3=0,x4=0,x5=0,x6=1
x1=1,x2=1,x3=1,x4=1,x5=1,x6=1
  5 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 8 日
mathematically, your systems are non-linear, since they have functions of variables being multiplied by functions of variables. In what you posted, the maximum degree is 2, which makes the system "quadratic", and there are techniques for dealing with quadratic functions. Does this extend in general to your equations, that you never "and" more than two variables together ?
dcydhb dcydhb
dcydhb dcydhb 2020 年 8 月 8 日
i am sorry what does your 'and' mean, i have just attached the original equations and i think may you can just explore the original equations and thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by