# Solving Boolean equations

@Artes suggested this code to me to solve this system of equations:

'x[a_, b_] := Boole[a >= b]
y[a_, c_] := Boole[a >= c]
z[b_, c_] := Boole[b >= c]
Solve[ a == x[a, b] + y[a, c] && b == x[a, b] + z[b, c] &&
c == y[a, c] + z[b, c], {a, b, c}]'


What's the fastest way to get to the solution of x[a_, b_], which should be a parameter now.

A problem which arised while coding the above was, that this code

 H[1, x_, y_] := 1 /; 10 - x - y >= p[B2] - y && 10 - x - y >= 0
H[1, x_, y_] := 1 /; 6 - x > p[B2] - y && 6 - x >= 0
H[1, x_, y_] := 0.5 /; 4 - x == p[B2] - y && 4 - x >= 0
H[1, x_, y_] := 0 /; others


doesn't work for me.

P[q_, w_] := 1 /; q > w
P[q_, w_] := 0 /; others
P[q_, w_] := 0.5 /; q == w


This code on the other hand works fine. So i suppose that "others" in the case of multiple conditions doesn't work any longer. Is there a solution?

• try Boole and Reduce or FindInstance May 27, 2016 at 15:12
• Don't delete previous information of your question since it makes the answers to it unreasonable. Have you looked at the documentation pages? If so, why can't you resolve your problem? If you demonstrate your attempts it will be likely someone'll provide the answer. May 31, 2016 at 9:29

Let's define the following functions:

x[a_, b_] := Boole[a >= b]
y[a_, c_] := Boole[a >= c]
z[b_, c_] := Boole[b >= c]


In fact we need only one function but for clarity of dealing with variables we have used three definitions, then we rewrite the given system

Solve[ a == x[a, b] + y[a, c] && b == x[a, b] + z[b, c] &&
c == y[a, c] + z[b, c], {a, b, c}]

{{a -> 0, b -> 1, c -> 1}, {a -> 2, b -> 2, c -> 2}}


alternatively

Reduce[ a == x[a, b] + y[a, c] && b == x[a, b] + z[b, c] &&
c == y[a, c] + z[b, c], {a, b, c}]

(a == 0 && b == 1 && c == 1) || (a == 2 && b == 2 && c == 2)

• or FindInstance[a == x[a, b] + y[a, c] && b == x[a, b] + z[b, c] && c == y[a, c] + z[b, c], {a, b, c}, 2] May 27, 2016 at 15:58
• I wouldn't recommend FindInstance since it doesn't decide if the solution set is complete regardless of the fact that sometimes it can find all solutions. May 27, 2016 at 16:09
• How would this change if i have 3rd option in one/all of the "if" instances? Boule can't work anymore... May 27, 2016 at 21:30
• @Andreas You are welcome. In more complicated conditions instead of Boole you can use Switch or you can define functions with Condition (shorthand: /;). See the documentation pages or you can find similar problems here on this site. May 27, 2016 at 21:41

Just another way (this is answer to original question, see Artes answer):

bfun[a_, b_, c_] := Boole[{a >= b, a >= c, b >= c}]
an[x_, y_,
z_] := {#1, #3, #2} & @@ (Total /@ Partition[{x, y, z}, 2, 1, 1])
t = Tuples[{0, 1}, 3];
lhs = an @@@ (bfun @@@ (an @@@ t));
rhs = an @@@ t;
crit = MapThread[#1 == #2 &, {lhs, rhs}];
pck = Pick[t, crit];
TableForm[Join[{##}, an@##] & @@@ pck,
TableHeadings -> {None, {"x", "y", "z", "A", "B", "C"}}]