# How to Reduce conditions of Piecewise function

Edit

I had problems with pasting an example to stackoverflow itself so here is the link to PasteBin containing sample code: https://pastebin.com/yi6AyrHy

I have fairly big piecewise function which I'm willing to gradually simplify. The main issue is piecewise function conditions, which are presented in unreadable form. A call to Reduce[...] simplifies the form, for example:

Reduce[w == 1/2 + x && w + x == 0, {x, y}]


Which gives:

w == 1/4 && x == -(1/4)


But the question is how to apply Reduce to every condition of piecewise function?

• Have you seen PiecewiseExpand and LogicalExpand? Maybe they can help to preprocess your function a bit. – Roman Dec 24 '19 at 17:51
• Hi @Roman I did, but they do not help any much, the expressions remain the same – Lu4 Dec 24 '19 at 18:27
• Please post what you tried, because problems with code often require the code for the problem to be diagnosed. Here's what I got: i.stack.imgur.com/9t71q.png – Michael E2 Dec 24 '19 at 18:49
• I can't stackoverflow rejects the question because it contains too much code... – Lu4 Dec 24 '19 at 18:54
• @MichaelE2 I've updated the answer, I've put code into PasteBin so feel free to review... – Lu4 Dec 24 '19 at 19:01

Perhaps you can try PiecewiseExpand with the Method suboption "ConditionSimplifier" set to Reduce as shown in the first example in PiecewiseExpand >> Options >> Method:

pw = Min[x^2 + 2 x - 2, Max[2 x^2 - 3 x + 4, x^2 - 3]]


Min[-2 + 2 x + x^2, Max[-3 + x^2, 4 - 3 x + 2 x^2]]

 PiecewiseExpand[pw]

% // TeXForm


$$\begin{cases} x^2-3 & x>-\frac{1}{2}\land x^2-3 x\leq -7 \\ x^2+2 x-2 & \left(x^2-3 x>-7\land x^2-5 x\geq -6\right)\lor \left(x^2-3 x\leq -7\land x\leq -\frac{1}{2}\right) \\ 2 x^2-3 x+4 & \text{True} \end{cases}$$

PiecewiseExpand[pw, Method -> {"ConditionSimplifier" -> Reduce}]

% // TeXForm


$$\begin{cases} x^2+2 x-2 & x\leq 2\lor x\geq 3 \\ 2 x^2-3 x+4 & \text{True} \end{cases}$$

• Wow, it really did work, thank you! – Lu4 Dec 24 '19 at 19:53