how to solve a system of boolean equations

5 views (last 30 days)
Andrei
Andrei on 5 Jan 2014
Edited: Matt J on 6 Jan 2014
Hi, i would like to know how to solve a system of boolean equations in mathlab. I found examples on how to reduce equations, but i don't know how to solve them
example:
!ab + a!b = 0
!a!bc + c = 1
a!c + a = 0
for this, the solution is a=0, b=0, c=1.
EDIT:
This is just an example, the real problem i will want to solve will be a system of 100 equations with 64 variables
note:
ab means a and b
a+b means a or b
!a means not a
I tried this, but it doesn't show the solution:
solve({(not a and b) or (a and (not b)) = false, not a and not b and c or c = true, a and not c or a or b = false}, logic)
result is:
piecewise([((a and not b) = false or not a and b) and (c = true or not a and not b and c) and (a or b = false or a and not c), C_], [(a and not b) <> false and (a or not b) or c <> true and (a or b or not c) or not a and b <> false and (not a or c), {}])
  4 Comments
Matt J
Matt J on 6 Jan 2014
Edited: Matt J on 6 Jan 2014
Note that equations with zeros on the RHS can be broken up into additional, simpler equations. E.g.,
!ab + a!b = 0
leads to
!ab=0
a!b=0
or equivalently, using DeMorgan's Law
a + !b=1
!a + b=1
So, really, you should never have a 0 on the rhs of your equations.

Sign in to comment.

Answers (2)

Alan Weiss
Alan Weiss on 6 Jan 2014
I am not sure, but perhaps you can reformulate your problem as a binary integer programming problem, and then use the Optimization Toolbox function bintprog to solve the problem.
For suggestions on turning boolean equations into binary integer programming constraints, see this link (there may be better links, it is just the first one I found).
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Matt J
Matt J on 5 Jan 2014
Edited: Matt J on 5 Jan 2014
A brute force approach would be to enumerate all possible combinations.
combs=dec2bin(0:7,3)-'0'; %All combinations
a=combs(:,1); b=combs(:,2); c=combs(:,3);
idx = ((~a.*b +~b.*a) == 0 ) & ((~a.*~b)==1) & ((a.*~b.*c +c)==1);
result = combs(idx,:)
  4 Comments
Matt J
Matt J on 6 Jan 2014
Edited: Matt J on 6 Jan 2014
If you can perform reductions on the individual equations, you might be able to pre-solve for enough variables to the point where brute force enumeration becomes possible again.
In your example, for instance, the second equation alone readily reduces to c=1,
!a!bc + c=1
(!a!b + 1)c=1
c=1
and similarly the 3rd equation readily reduces to a=0.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!