Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
dcydhb dcydhb
dcydhb dcydhb le 8 Août 2020
Modifié(e) : dcydhb dcydhb le 8 Août 2020
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 commentaires
dcydhb dcydhb
dcydhb dcydhb le 8 Août 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.

Connectez-vous pour commenter.

Réponses (1)

Bruno Luong
Bruno Luong le 8 Août 2020
Modifié(e) : Bruno Luong le 8 Août 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 commentaires
Walter Roberson
Walter Roberson le 8 Août 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 le 8 Août 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!

Connectez-vous pour commenter.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by