6
$\begingroup$

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?

Thank you in advance!

$\endgroup$
  • 1
    $\begingroup$ Have you seen PiecewiseExpand and LogicalExpand? Maybe they can help to preprocess your function a bit. $\endgroup$ – Roman Dec 24 '19 at 17:51
  • $\begingroup$ Hi @Roman I did, but they do not help any much, the expressions remain the same $\endgroup$ – Lu4 Dec 24 '19 at 18:27
  • 2
    $\begingroup$ 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 $\endgroup$ – Michael E2 Dec 24 '19 at 18:49
  • $\begingroup$ I can't stackoverflow rejects the question because it contains too much code... $\endgroup$ – Lu4 Dec 24 '19 at 18:54
  • $\begingroup$ @MichaelE2 I've updated the answer, I've put code into PasteBin so feel free to review... $\endgroup$ – Lu4 Dec 24 '19 at 19:01
7
$\begingroup$

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}$

| improve this answer | |
$\endgroup$
  • $\begingroup$ Wow, it really did work, thank you! $\endgroup$ – Lu4 Dec 24 '19 at 19:53

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.