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

1 次查看(过去 30 天)
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.

请先登录,再进行评论。

回答(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 CenterFile Exchange 中查找有关 Solver 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