필터 지우기
필터 지우기

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

조회 수: 4 (최근 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