# Reduce, Piecewise function gives result that does not make any sense given condition constraint

Here is my code:

N1 = 1;
N2 = 1;
X1 = N2/(1 - \[Sigma]);

c = 1
surpluspayoff10011010 = (N1 + x + y)/((N1 + x + y) + N2)* X1 -
c y - (((N1 + x)/((N1 + x) + N2))*X1);
yargmax10011010 = Simplify[y /. NSolve[\!$$\*SubscriptBox[\(\[PartialD]$$, $$y$$]$$(surpluspayoff10011010)$$\) ==
0, y]][[2]];
yargmax10011010 =
Simplify[Piecewise[{{0,
Simplify@
Reduce[{Rationalize@yargmax10011010 < 0  && 0 <= \[Sigma] < 1 &&
ymax > 1}, x]}, {yargmax10011010,
Simplify@
Reduce[{Rationalize@yargmax10011010 <= ymax &&
0 <= \[Sigma] < 1 && ymax > 1}, x]}, {ymax,
Simplify@
Reduce[{Rationalize@yargmax10011010 > ymax &&
0 <= \[Sigma] < 1 && ymax > 1}, x]  }}]];
surpluspayoff10011010 =
Simplify[(N1 + yargmax10011010 +
x)/((N2) + (N1 + x + yargmax10011010))* X1 -
yargmax10011010 - (((N1 + x)/((N1 + x) + N2))*X1) ];
yargmax10011010 =
Simplify[Piecewise[{{0,
Simplify@
Reduce[{Rationalize@surpluspayoff10011010 < 0 &&
0 <= \[Sigma] < 1  && ymax > 1}, x]}, {yargmax10011010,
Simplify@
Reduce[{Rationalize@surpluspayoff10011010 >= 0 &&
0 <= \[Sigma] < 1 && ymax > 1}, x]}}]];


I cannot put the result here, since it will look very ugly here. But the thing is I already gave the condition for 0<\sigma<1 , 1< ymax, but the result for yargmax10011010 is something that violated these conditions. Basicly,look at the result of yargmax10011010 when y=0, we have conditions such as ymax =<1, and such

• Your code is complex and somewhat messy. Perhaps you could reduce it to a simpler example. Nevertheless, I suspect that your problem ultimately is that you did not explicitly give appropriate assumptions when using Simplify. If you want to set global assumptions, so you don't have to specify them every time you run Simplify, look into \$Assumptions. You may also be interested in this tutorial: Using assumptions. – MarcoB Sep 8 '19 at 22:24
• Thank you, I will try that – user66418 Sep 8 '19 at 22:36
• It did not work, the result still does not make sense (basicly we have for yargmax 2 values that overlap) – user66418 Sep 8 '19 at 22:46
• It doesn't appear that any of your 9 Simplify or 5 Rationalize are accomplishing anything for you. With or without those I get the result Piecewise[{{0, ymax<=1 || 2+x+Sqrt[1/(1-σ)]!=0 || σ>=1 || σ<0}, {(2+x+Sqrt[1-σ]-2*σ-x*σ)/(σ-1), 2+x+Sqrt[1/(1-σ)]>=0 && 2+x+ymax+Sqrt[1/(1-σ)]>=0 && 0<=σ<1] && ymax>1}}, ymax] – Bill Sep 8 '19 at 23:14
• Hi Bill, please look at my comment in Jack post – user66418 Sep 8 '19 at 23:41

I used simpler variable names (e.g., y1 in place of yargmax10011010) and rather than redefining them created new ones (this last because when you are tracking down a problem it often is better not to redefine variables).

I believe that MarcoB is correct, adding assumptions to Simplify removes the offending inequalities.

N1 = 1;
N2 = 1;
X1 = N2/(1 - σ);
c = 1;

s1 = (N1 + x + y)/((N1 + x + y) + N2)*X1 -
c y - (((N1 + x)/((N1 + x) + N2))*X1)
(* -y - (1 + x)/((2 + x) (1 - σ)) +
(1 + x + y)/((2 + x + y) (1 - σ)) *)


The first pass

y1 = Simplify[y /. NSolve[D[s1, y] == 0, y]][[2]]
(* (2. + x + Sqrt[1. - 1. σ] - 2. σ -
1. x σ)/(-1. + σ) *)


The second pass

y2 = Simplify[
Piecewise[{
{0, Simplify@
Reduce[{Rationalize@y1 < 0 && 0 <= σ < 1 && ymax > 1},
x]}, {y1,
Simplify@
Reduce[{Rationalize@y1 <= ymax && 0 <= σ < 1 &&
ymax > 1}, x]}, {ymax,
Simplify@
Reduce[{Rationalize@y1 > ymax && 0 <= σ < 1 && ymax > 1},
x]}}
],
ymax > 1
]


I will have to use a snapshot for the result

Use y2 for new version of s1

s2 = Simplify[(N1 + y2 + x)/((N2) + (N1 + x + y2))*X1 -
y2 - (((N1 + x)/((N1 + x) + N2))*X1), ymax > 1]


and finally

y3 = Simplify[
Piecewise[{
{0, Simplify@
Reduce[{Rationalize@s2 < 0 && 0 <= \[Sigma] < 1 && ymax > 1},
x]}, {y2,
Simplify@
Reduce[{Rationalize@s2 >= 0 && 0 <= \[Sigma] < 1 && ymax > 1},
x]}
}],
ymax > 1
]


• As you can see, the result makes no sense, just look at it, in the first line 2+x+square root of blah blah is always greater than 0 , and in the second line 2+x+ square root is always larger than 0 as well, so y can be both 0 and the second thing at the same time. So if 0<sigma<1, we have 2 values of y , at the same time – user66418 Sep 8 '19 at 23:39
• Your question as I understood it was about violating constraints. In this example the constraints are not violated but are redundant (with ymax > 1 the second statement is not required). Did you want the redundant constraint removed? – Jack LaVigne Sep 8 '19 at 23:45
• The result is wrong, just plug in sigma equal 0.95, ymax equal 2 for example, and you see y is equal to 0. And just think about it, the function is not maximized at y=0. I used Nsolve to find max because the function is concave. But thanks anyways for your help, I think maybe I should solve this on paper, perhaps? – user66418 Sep 8 '19 at 23:46
• I am not familiar with the problem and am unable to tell whether zero is wrong. Setting sigma =0.95 and ymax = 2, when I plot y1 I get a line. When I plot y2 I get a constant of 2 below -8.47214, a constant of zero above . -6.47214 and a line connecting the two between.those bounds. For 'y3' I get zero everywhere. – Jack LaVigne Sep 9 '19 at 1:06
• The first condition is true everywhere except x==6.47214 and produces zero. The second condition is true at x==6.47214 and the expression computes to be zero. – Jack LaVigne Sep 9 '19 at 1:15