# Problem with PiecewiseExpand??

GROUPS:
 In the following code, it seems that f2 evaluates incorrectly, but f1 & f3 evaluate correctly - even though f3 is generated from f2. It might not be handling the strings correctly (e.g., "Yes")?Maybe there is something subtle here I'm missing. I know how to work around this problem, but it doesn't seem I should need a workaround and it makes me wary of PiecewiseExpand.f1=Piecewise[{{Piecewise[{{a1, x == "Yes"}, {a2, x == "No"}}, 0], y == "Yes"}, {b, y == "No"}}]f2=f1//PiecewiseExpandf3=f2//FullSimplifyTable[{f1,f2,f3},{x,{"Yes","No"}},{y,{"Yes","No"}}]//TableFormThanks for any comments.
5 years ago
5 Replies
 Bruce Miller 1 Vote To save 100 people having to fire up their Mathematicas, in f2, the conditions are re-ordered to look like it is doing arithmetic with character strings. In[2]:= f2=f1//PiecewiseExpandOut[2]= Piecewise[{      {a1, Yes - y == 0 && Yes - x == 0},      {a2, Yes - y == 0 && No - x == 0},       {0, No - y != 0 || Yes - y == 0}}, b]FullSimplify or Simplify changes them back to looking like tests,  "{a1, Yes == y && Yes == x}" .  Worthy of a suggestion tomorrow.
5 years ago
 Thanks for the comments Bruce. Yes, the expansion does appear to try to do arithmetic with a string & that might be a problem with PiecewiseExpand. My real concern is that the results for f2 are actually wrong (execute the "Table" line of code,) - on my computer anyway. Maybe it is because the logic is expanded incorrectly (assumes only Reals maybe??). Curiously, once simplification is applied, these errors seem to be corrected.Makes me hesitant to use PiecewiseExpand.