0
$\begingroup$

enter image description here

@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?

$\endgroup$
2
  • 2
    $\begingroup$ try Boole and Reduce or FindInstance $\endgroup$
    – george2079
    May 27, 2016 at 15:12
  • 2
    $\begingroup$ 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. $\endgroup$
    – Artes
    May 31, 2016 at 9:29

2 Answers 2

8
$\begingroup$

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)
$\endgroup$
4
  • $\begingroup$ 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] $\endgroup$
    – bill s
    May 27, 2016 at 15:58
  • 3
    $\begingroup$ 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. $\endgroup$
    – Artes
    May 27, 2016 at 16:09
  • $\begingroup$ How would this change if i have 3rd option in one/all of the "if" instances? Boule can't work anymore... $\endgroup$
    – user34047
    May 27, 2016 at 21:30
  • $\begingroup$ @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. $\endgroup$
    – Artes
    May 27, 2016 at 21:41
0
$\begingroup$

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"}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.