Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
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 Kommentare
dcydhb dcydhb
dcydhb dcydhb am 8 Aug. 2020
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Bruno Luong
Bruno Luong am 8 Aug. 2020
Bearbeitet: Bruno Luong am 8 Aug. 2020
[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 Kommentare
Walter Roberson
Walter Roberson am 8 Aug. 2020
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 am 8 Aug. 2020
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!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by