# Using solve on conditional functions

I know that the code is pretty long, but most of it is just defintion. Do you see why the Solve gives me "his system cannot be solved with the methods available to Solve" back?

p[A1] := 30
p[A2] := 30
p[B1] := 60
p[B2] := 60
p[A12] := 100
p[B12] := 70

a[l1] := 10
a[h1] := 40
b[l1] := 20
b[h1] := 50
a[l2] := 10
a[h2] := 40
b[l2] := 20
b[h2] := 50

(*all low*)
x = a[l1];
y = a[l2];
u = b[l1];
v = b[l2];

(*G[1,x_,y_] is probability of player a playing with 1 given 1 and 2 \
play with him*)
G[1, x_, y_] := 1 /; p[A12] - x - y >= p[A2] - y && p[A12] - x - y >= 0
G[1, x_, y_] := 1 /; p[A1] - x > p[A2] - y && p[A1] - x >= 0
G[1, x_, y_] := 1/2 /; p[A1] - x == p[A2] - y && p[A1] - x >= 0
G[1, x_, y_] := 0

(*A spielt mit 1 wenn nur 1*)
G[2, x_, y_] := 1 /; p[A1] - x >= 0
G[2, x_, y_] := 0

(*A spielt mit 2 wenn beide*)
G[3, x_, y_] := 1 /; p[A12] - x - y >= p[A1] - x && p[A12] - x - y >= 0
G[3, x_, y_] := 1 /; p[A2] - y > p[A1] - x && p[A2] - y >= 0
G[3, x_, y_] := 1/2 /; p[A2] - y == p[A1] - x && p[A2] - y >= 0
G[3, x_, y_] := 0

(*A spielt mit 2 wenn nur 2*)
G[4, x_, y_] := 1 /; p[A2] - y >= 0
G[4, x_, y_] := 0

(*B spielt mit 1 wenn beide*)
H[1, x_, y_] := 1 /; p[B12] - x - y >= p[B2] - y && p[B12] - x - y >= 0
H[1, x_, y_] := 1 /; p[B1] - x > p[B2] - y && p[B1] - x >= 0
H[1, x_, y_] := 1/2 /; p[B1] - x == p[B2] - y && p[B1] - x >= 0
H[1, x_, y_] := 0

(*B spielt mit 1 wenn nur 1*)
H[2, x_, y_] := 1 /; p[B1] - x >= 0
H[2, x_, y_] := 0

(*B spielt mit 2 wenn beide*)
H[3, x_, y_] := 1 /; p[B12] - x - y >= p[B1] - x && p[B12] - x - y >= 0
H[3, x_, y_] := 1 /; p[B2] - y > p[B1] - x && p[B2] - y >= 0
H[3, x_, y_] := 1/2 /; p[B2] - y == p[B1] - x && p[B2] - y >= 0
H[3, x_, y_] := 0

(*B spielt mit 2 wenn nur 2*)
H[4, x_, y_] := 1 /; p[B2] - y >= 0
H[4, x_, y_] := 0

(*Find Solution,l:=EV von 1 mit A,m:=1 mit B,n:=2 mit A,o:=2 mit B*)
(*P[q_,w,] is probability that 1 selects A given bids u,v,x,y*)
P[q_, w_] := 1 /; q > w
P[q_, w_] := 1/2 /; q == w
P[q_, w_] := 0 /; q < w
(*U[q_,w,] is probability that 1 selects B given bids u,v,x,y*)
U[q_, w_] := 1 /; w > q
U[q_, w_] := 1/2 /; w == q
U[q_, w_] := 0 /; w < q

(*S[q_,w,] is probability that 2 selects A given bids u,v,x,y*)
S[f_, g_] := 1 /; f > g
S[f_, g_] := 1/2 /; f == g
S[f_, g_] := 0 /; f < g

(*S[q_,w,] is probability that 2 selects B given bids u,v,x,y*)
T[f_, g_] := 1 /; g > f
T[f_, g_] := 1/2 /; g == f
T[f_, g_] := 0 /; g < f

eqn = {l == S[n, c]*G[1, x, y]*x + (1 - S[n, c])*G[2, x, y]*x,
m == T[n, c]*H[1, u, v]*u + (1 - T[n, c])*H[2, u, v]*u,
n == P[l, m]*G[3, x, y]*y + (1 - P[l, m])*G[4, x, y]*y,
c == U[l, m]*H[3, u, v]*v + (1 - U[l, m])*H[4, u, v]*v}

Solve[eqn, {l, m, n, c}]

• Your functions are defined procedurally. Jun 13, 2016 at 17:47
• Try and redefine your functions using Piecewise, or Boole, rather than multiple conditional definitions. That may help. I'm sure that you also realize that Solve would have to generate quite a few conditions and explore very many branches of your solution space to provide a general solution. Perhaps, if you provide further assumptions on the variables, or try Reduce, you might have more luck. Jun 13, 2016 at 18:11

There may be reasons you elected to write:

p[A1] := 30


rather than simply

pA1 = 30;


and I would think it would be legitimate. However I re-wrote your code using (what to me) seems a simpler format.

pA1 = 30; pA2 = 30;
pB1 = 60; pB2 = 60;
pA12 = 100; B12 = 70;

al1 = 10; ah1 = 40;
bl1 = 20; bh1 = 50;
al2 = 10; ah2 = 40;
bl2 = 20; bh2 = 50;

x = al1; y = al2;
u = bl1; v = bl2;

G[1, x_, y_] := 1 /; pA12 - x - y >= pA2 - y && pA12 - x - y >= 0
G[1, x_, y_] := 1 /; pA1 - x > pA2 - y && pA1 - x >= 0
G[1, x_, y_] := 1/2 /; pA1 - x == pA2 - y && pA1 - x >= 0
G[1, x_, y_] := 0

G[2, x_, y_] := 1 /; pA1 - x >= 0
G[2, x_, y_] := 0

G[3, x_, y_] := 1 /; pA12 - x - y >= pA1 - x && pA12 - x - y >= 0
G[3, x_, y_] := 1 /; pA2 - y > pA1 - x && pA2 - y >= 0
G[3, x_, y_] := 1/2 /; pA2 - y == pA1 - x && pA2 - y >= 0
G[3, x_, y_] := 0

G[4, x_, y_] := 1 /; pA2 - y >= 0
G[4, x_, y_] := 0

H[1, x_, y_] := 1 /; pB12 - x - y >= pB2 - y && pB12 - x - y >= 0
H[1, x_, y_] := 1 /; pB1 - x > pB2 - y && pB1 - x >= 0
H[1, x_, y_] := 1/2 /; pB1 - x == pB2 - y && pB1 - x >= 0
H[1, x_, y_] := 0

H[2, x_, y_] := 1 /; pB1 - x >= 0
H[2, x_, y_] := 0

H[3, x_, y_] := 1 /; pB12 - x - y >= pB1 - x && pB12 - x - y >= 0
H[3, x_, y_] := 1 /; pB2 - y > pB1 - x && pB2 - y >= 0
H[3, x_, y_] := 1/2 /; pB2 - y == pB1 - x && pB2 - y >= 0
H[3, x_, y_] := 0

H[4, x_, y_] := 1 /; pB2 - y >= 0
H[4, x_, y_] := 0


Note that the way it was written the P, U, S and T functions are identical (again, you may have something different in mind). So I only wrote one. In order to help Solve I stipulated that the input arguments should be numeric.

P[q_?NumberQ, w_?NumberQ] := 1 /; q > w
P[q_?NumberQ, w_?NumberQ] := 1/2 /; q == w
P[q_?NumberQ, w_?NumberQ] := 0 /; q < w


The equation is unchanged except that only P was used

eqn = {
l == P[n, c]*G[1, x, y]*x + (1 - P[n, c])*G[2, x, y]*x,
m == P[n, c]*H[1, x, v]*u + (1 - P[n, c])*H[2, u, v]*u,
n == P[l, m]*G[3, x, y]*y + (1 - P[l, m])*G[4, x, y]*y,
c == P[l, m]*H[3, u, v]*v + (1 - P[l, m])*H[4, u, v]*v
}


Now Solve yields a result

Solve[eqn, {l, m, n, c}]

{{l -> 10, m -> 20, n -> 10, c -> 20}}


I don't know whether it is the _?NumberQ or the removal of the nested SetDelayed (i.e, :=) that caused it to work. Perhaps you can track that down.

Good luck!

• La Ligne: Zhank you very much for your time and effort! Jun 14, 2016 at 8:13
Clear[p, a, b, G, H, P, U, S, T]

p[A1] = 30; p[A2] = 30;
p[B1] = 60; p[B2] = 60;
p[A12] = 100; p[B12] = 70;

a[l1] = 10; a[h1] = 40;
b[l1] = 20; b[h1] = 50;
a[l2] = 10; a[h2] = 40;
b[l2] = 20; b[h2] = 50;

(*all low*)
x = a[l1]; y = a[l2];
u = b[l1]; v = b[l2];


Rather than adding conditions to mutiple definitions, use Piecewise

(*G[1,x_,y_] is probability of player a playing with 1 given 1 and 2 play \
with him*)
G[1, x_, y_] = Piecewise[{
{1, p[A12] - x - y >= p[A2] - y && p[A12] - x - y >= 0 ||
p[A1] - x > p[A2] - y && p[A1] - x >= 0},
{1/2, p[A1] - x == p[A2] - y && p[A1] - x >= 0}}];

(*A spielt mit 1 wenn nur 1*)
G[2, x_, y_] = Piecewise[{{1, p[A1] - x >= 0}}];

(*A spielt mit 2 wenn beide*)
G[3, x_, y_] = Piecewise[{
{1, p[A12] - x - y >= p[A1] - x && p[A12] - x - y >= 0 ||
p[A2] - y > p[A1] - x && p[A2] - y >= 0},
{1/2, p[A2] - y == p[A1] - x && p[A2] - y >= 0}}];

(*A spielt mit 2 wenn nur 2*)
G[4, x_, y_] = Piecewise[{{1, p[A2] - y >= 0}}];

(*B spielt mit 1 wenn beide*)
H[1, x_, y_] = Piecewise[{
{1, p[B12] - x - y >= p[B2] - y && p[B12] - x - y >= 0 ||

p[B1] - x > p[B2] - y && p[B1] - x >= 0},
{1/2, p[B1] - x == p[B2] - y && p[B1] - x >= 0}}];

(*B spielt mit 1 wenn nur 1*)
H[2, x_, y_] = Piecewise[{{1, p[B1] - x >= 0}}];

(*B spielt mit 2 wenn beide*)
H[3, x_, y_] = Piecewise[{
{1, p[B12] - x - y >= p[B1] - x && p[B12] - x - y >= 0 ||

p[B2] - y > p[B1] - x && p[B2] - y >= 0},
{1/2, p[B2] - y == p[B1] - x && p[B2] - y >= 0}}];

(*B spielt mit 2 wenn nur 2*)
H[4, x_, y_] = Piecewise[{{1, p[B2] - y >= 0}}];

(*Find Solution,l:=EV von 1 mit A,m:=1 mit B,n:=2 mit A,o:=2 mit B*)

(*P[q_,w,] is probability that 1 selects A given bids u,v,x,y*)

P[q_, w_] = Piecewise[{{1, q > w}, {1/2, q == w}}];

(*U[q_,w,] is probability that 1 selects B given bids u,v,x,y*)

U[q_, w_] = Piecewise[{{1, w > q}, {1/2, w == q}}];

(*S[q_,w,] is probability that 2 selects A given bids u,v,x,y*)

S[f_, g_] = Piecewise[{{1, f > g}, {1/2, g == f}}];

(*T[q_,w,] is probability that 2 selects B given bids u,v,x,y*)

T[f_, g_] = Piecewise[{{1, g > f}, {1/2, f == g}}];

eqn = {
l == S[n, c]*G[1, x, y]*x + (1 - S[n, c])*G[2, x, y]*x,
m == T[n, c]*H[1, u, v]*u + (1 - T[n, c])*H[2, u, v]*u,
n == P[l, m]*G[3, x, y]*y + (1 - P[l, m])*G[4, x, y]*y,
c == U[l, m]*H[3, u, v]*v + (1 - U[l, m])*H[4, u, v]*v} // PiecewiseExpand

(*  {l == 10, m == 20, n == 10, c == 20}  *)


Solve[eqn, {l, m, n, c}] == {Rule @@@ eqn}