7
$\begingroup$

How can I read this Reduce output from Mathematica that I got from solving an inequality? I do not perfectly know when one case in this case analysis is over and the next starts. I can see the differentiation between $r<0$, $r=0$ and $r>0$ as well as for the different $p$-values, but then it gets tricky. Isn't there a nicer way to illustrate the result? I need a general answer since I will have to calculate many of these inequalities.

This is the result:

F \[Element] 
  Reals && ((r < 
      0 && ((p < 
          0 && ((F < 0 && (a < (p - F r)/(F r) || a > 0)) || (F == 0 &&
              a > 0) || (0 < F < p/(2 r) && 
             0 < a < (p - F r)/(F r)) || (p/(2 r) < F < p/
              r && (a < 0 || a > (p - F r)/(F r))) || (F > p/r && (
              p - F r)/(F r) < a < 0))) || (p > 
          0 && ((F < p/r && (p - F r)/(F r) < a < 0) || (p/r < F < p/(
              2 r) && (a < 0 || a > (p - F r)/(F r))) || (p/(2 r) < 
              F < 0 && 0 < a < (p - F r)/(F r)) || (F == 0 && 
             a > 0) || (F > 
              0 && (a < (p - F r)/(F r) || a > 0)))))) || (r == 
      0 && ((p < 0 && a > 0) || (p > 0 && a > 0))) || (r > 
      0 && ((p < 
          0 && ((F < p/r && (p - F r)/(F r) < a < 0) || (p/r < F < p/(
              2 r) && (a < 0 || a > (p - F r)/(F r))) || (p/(2 r) < 
              F < 0 && 0 < a < (p - F r)/(F r)) || (F == 0 && 
             a > 0) || (F > 
              0 && (a < (p - F r)/(F r) || a > 0)))) || (p > 
          0 && ((F < 0 && (a < (p - F r)/(F r) || a > 0)) || (F == 0 &&
              a > 0) || (0 < F < p/(2 r) && 
             0 < a < (p - F r)/(F r)) || (p/(2 r) < F < p/
              r && (a < 0 || a > (p - F r)/(F r))) || (F > p/r && (
              p - F r)/(F r) < a < 0))))))

I tried to make a case analysis by typing in:

Reduce[(2*a*p*r*F - a*p^2)/((2*a + 2)*r^2*F^2 + (-2*a - 4)*p*r*F + 2*p^2) < 0]

Thankful for every help.

$\endgroup$
6
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Commented Apr 28, 2015 at 14:41
  • $\begingroup$ Using Simplify[Reduce[...]] can sometimes make the result 30% smaller and thus possibly a little easier to read. Positioning your cursor just after a ( and giving a single mouse click highlights the matching pair of () and can thus help you determine when one case ends and the next starts. Thus you have four alternatives in your simplified result or three compound cases in your unsimplified result. Thank you for showing the Reduce[] that you used to get that result. That was very helpful in trying to provide you with some assistance. $\endgroup$
    – Bill
    Commented Apr 28, 2015 at 16:32
  • 3
    $\begingroup$ BooleanConvert[ ]and LogicalExpand[ ] are sometimes useful to flatten the nested conditions. That doesn't mean that the expression will be "easy" to read, but at least you may focus in one condition at a time $\endgroup$ Commented Apr 28, 2015 at 16:42
  • $\begingroup$ Example LogicalExpand@ Reduce[(2*a*p*r*F - a*p^2)/((2*a + 2)*r^2*F^2 + (-2*a - 4)*p*r*F + 2*p^2) < 0, Reals] $\endgroup$ Commented Apr 28, 2015 at 16:43
  • $\begingroup$ @Bill Thanks a lot for your answer. I will try the Simplify[] . At belisarius Thanks a lot as well. Thanks for proposing BooleanConvert[] and LogicalExpand[]. $\endgroup$
    – Researcher
    Commented Apr 29, 2015 at 8:42

2 Answers 2

11
$\begingroup$

First thing to consider with such a convoluted expression is that there are many equivalent forms of it. FullSimplify, espectially with assumptions (or Assuming) can considerably reduce the size of output.

Some examples, although by any means all the flexibility, are represented below.

First, let's define a function which formats Boolean equations, rewritten into disjunctive normal form, with "simplest" forms first. Every row represents one item in Or ($a\lor b\lor c\lor\ldots$).

ClearAll[prettyDNF];

prettyDNF[eqns_] := 
 TraditionalForm@
  Column[SortBy[
    List @@ (FullSimplify /@
       BooleanMinimize[eqns, "DNF"]), 
    LeafCount],
   Dividers -> All]

A simple example:

prettyDNF[a || b && c]

$$\begin{array}{|l|} \hline a \\ \hline b\land c \\ \hline \end{array}$$

Now you can show your output in slightly more understandable form:

prettyDNF[
 FullSimplify@
  Reduce[(2*a*p*r*F - a*p^2)/((2*a + 2)*r^2*F^2 + (-2*a - 4)*p*r*F + 2*p^2) < 0]]

$$\begin{array}{|l|} \hline F\in \mathbb{R}\land p\neq 0\land r=0\land a>0 \\ \hline a>0\land F\leq 0\land p>0\land r>0 \\ \hline F\geq 0\land p<0\land a>0\land r>0 \\ \hline F\geq 0\land r<0\land a>0\land p>0 \\ \hline p<0\land r<0\land a>0\land F\leq 0 \\ \hline F>0\land p>0\land r<0\land p<(a+1) F r \\ \hline F>0\land p<0\land r>0\land (a+1) F r<p \\ \hline a<0\land r>0\land F r<p\land p<2 F r \\ \hline a<0\land r>0\land 2 F r<p\land p<F r \\ \hline a<0\land r<0\land p<F r\land 2 F r<p \\ \hline F<0\land p>0\land r>0\land p<(a+1) F r \\ \hline F<0\land p<0\land r<0\land (a+1) F r<p \\ \hline a<0\land a+1>\frac{p}{F r}\land p>0\land r>0 \\ \hline a<0\land p<0\land r<0\land a+1>\frac{p}{F r} \\ \hline a<0\land 2 F<\frac{p}{r}\land F>\frac{p}{r}\land p>0 \\ \hline F<\frac{p}{r}\land a+1>\frac{p}{F r}\land 2 F>\frac{p}{r} \\ \hline 2 F<\frac{p}{r}\land a+1>\frac{p}{F r}\land F>\frac{p}{r} \\ \hline a+1<\frac{p}{F r}\land 2 F<\frac{p}{r}\land a>0\land p>0\land r>0 \\ \hline a+1<\frac{p}{F r}\land 2 F<\frac{p}{r}\land p<0\land r<0\land a>0 \\ \hline a+1<\frac{p}{F r}\land p<0\land a>0\land 2 F>\frac{p}{r}\land r>0 \\ \hline a+1<\frac{p}{F r}\land r<0\land a>0\land 2 F>\frac{p}{r}\land p>0 \\ \hline \end{array}$$

If you can use assumptions on your variables (let's assume F > 0), it may reduce number of forms radically:

Assuming[F > 0, 
 prettyDNF[
  FullSimplify@
   Reduce[(2*a*p*r*F - a*p^2)/((2*a + 2)*r^2*F^2 + (-2*a - 4)*p*r*F + 2*p^2) < 0]]]

$$\begin{array}{|l|} \hline p<0\land a>0\land r>0 \\ \hline r<0\land a>0\land p>0 \\ \hline p\neq 0\land r=0\land a>0 \\ \hline a<0\land p<F r\land 2 F r<p \\ \hline a<0\land F r<p\land p<2 F r \\ \hline a+1<\frac{p}{F r}\land p<0\land r>0 \\ \hline a+1<\frac{p}{F r}\land r<0\land p>0 \\ \hline a<0\land a+1>\frac{p}{F r}\land p>0\land r>0 \\ \hline a<0\land p<0\land r<0\land a+1>\frac{p}{F r} \\ \hline a+1<\frac{p}{F r}\land 2 F<\frac{p}{r}\land a>0 \\ \hline F<\frac{p}{r}\land a+1>\frac{p}{F r}\land 2 F>\frac{p}{r} \\ \hline \end{array}$$

Also, there may be other rewriting methods than FullSimplify with Assuming. For instance, cylindrical algebraic decomposition (which may a have more intuitive geometric formulation) can be used on polynomials:

ClearAll[prettyDNF2];

prettyDNF2[eqns_] := 
 TraditionalForm@
  Column[SortBy[List @@
     BooleanMinimize[eqns, "DNF"], 
    LeafCount],
   Dividers -> All]

Assuming[F > 0,
 prettyDNF2[
  Refine@CylindricalDecomposition[
   (2*a*p*r*F - a*p^2)/((2*a + 2)*r^2*F^2 + (-2*a - 4)*p*r*F + 2*p^2) < 0,
   {F, r, p, a}]]]

$$\begin{array}{|l|} \hline r=0\land a>0\land p>0 \\ \hline r=0\land p<0\land a>0 \\ \hline p<0\land a>0\land r>0 \\ \hline r<0\land a>0\land p>0 \\ \hline F r<p<2 F r\land a<0\land r>0 \\ \hline 2 F r<p<F r\land a<0\land r<0 \\ \hline a<\frac{p-F r}{F r}\land p<0\land r>0 \\ \hline a<\frac{p-F r}{F r}\land r<0\land p>0 \\ \hline 0<a<\frac{p-F r}{F r}\land p>2 F r\land r>0 \\ \hline 0<a<\frac{p-F r}{F r}\land p<2 F r\land r<0 \\ \hline 0<p<F r\land \frac{p-F r}{F r}<a<0\land r>0 \\ \hline F r<p<0\land \frac{p-F r}{F r}<a<0\land r<0 \\ \hline F r<p<2 F r\land a>\frac{p-F r}{F r}\land r>0 \\ \hline 2 F r<p<F r\land r<0\land a>\frac{p-F r}{F r} \\ \hline \end{array}$$

EDIT:

Some eye candy for two-dimensional toy case, for demonstration of the fact visualization is a very good way to make inequalities intuitive in two-dimensional cases:

Module[{eqns, sols},
 eqns = x^2 + y^2 < 1 && x^2 + (y - 1/2)^2 > 1/2 && ! (0 < y - x/2 < 1/4); 
 sols = Assuming[(x | y) \[Element] Reals, 
   FullSimplify[List @@ BooleanMinimize[Reduce@eqns, "DNF"]]];
 RegionPlot[sols, {x, -1, 1}, {y, -1, 1},
  PlotPoints -> 100, PlotLegends -> "Expressions"]]

enter image description here

Same with GenericCylindricalDecomposition, which generates only fully dimensional regions:

Module[{eqns, sols},
 eqns = x^2 + y^2 < 1 && x^2 + (y - 1/2)^2 > 1/2 && ! (0 < y - x/2 < 1/4); 
 sols = List @@ 
   BooleanMinimize[
    First@GenericCylindricalDecomposition[eqns, {x, y}], "DNF"];
 RegionPlot[sols, {x, -1, 1}, {y, -1, 1},
  PlotPoints -> 100, PlotLegends -> "Expressions"]]

enter image description here

It's worth noting the order of decomposition affects formulation of regions.

$\endgroup$
2
  • $\begingroup$ Wow. What can I say. This is a pretty awesome answer. Thanks a lot for all your effort. Very helpful as well. Should solve my problem with illustration. $\endgroup$
    – Researcher
    Commented Apr 29, 2015 at 8:45
  • 1
    $\begingroup$ Related in regard of recognizing connected components in semialgebraic sets: mathematica.stackexchange.com/a/83166/3056 . If a semialgebraic set consists of multiple connected components, this may help making results more understandable in smaller pieces. $\endgroup$
    – kirma
    Commented May 12, 2015 at 4:58
5
$\begingroup$

Here is an another approach on visualizing (two-dimensional) inequalities in a hierarchial fashion. It's certainly work in progress in many ways, but what can you expect from something hacked together while waiting for a flight... :)

(Interestingly enough ":" and TraditionalForm works differently on these saved selections than on Mma. Oh well.)

EDIT: Improved showRegion thanks to rcollyer!

ClearAll[showRegion];

showRegion[eq_, vars_List, range_List] := 
 RegionPlot[ImplicitRegion[eq, vars], PlotRange -> range, 
  FrameTicks -> None]


ClearAll[visualizeEquation];

visualizeEquation[e_And | e_Or | e_Xor, vars_List, range_List] := 
  Framed@OpenerView[{Row[{showRegion[e, vars, range], Spacer[20], 
        Head@e, ":", 
        Spacer[10], (Head@e) @@ (Framed /@ (List @@ e))}], 
      Column[visualizeEquation[#, vars, range] & /@ (List @@ e)]}, 
     True];
visualizeEquation[e_, vars_List, range_List] := 
  Framed@Row[{showRegion[e, vars, range], Spacer[20], e}];


visualizeEquation[
 Xor[x^2 + (y - 1/4)^2 <= 1, x^2 + (y + 1/4)^2 <= 1],
 {x, y},
 {{-3/2, 3/2}, {-3/2, 3/2}}] // TraditionalForm

enter image description here

visualizeEquation[
 Reduce@Xor[x^2 + (y - 1/4)^2 <= 1, x^2 + (y + 1/4)^2 <= 1], {x, 
  y}, {{-3/2, 3/2}, {-3/2, 3/2}}] // TraditionalForm

enter image description here

$\endgroup$
8
  • 1
    $\begingroup$ I'd use BoundaryDiscretizeRegion instead of DiscretizeRegion as it doesn't display the mesh. But, it requires that RegionDimension equal RegionEmbeddingDimension. So, I used With[{reg = ImplicitRegion[eq, vars]}, If[RegionDimension@reg != RegionEmbeddingDimension@reg, DiscretizeRegion[reg, range], BoundaryDiscretizeRegion[reg, range] ] ] to switch back when it wasn't allowed. $\endgroup$
    – rcollyer
    Commented May 1, 2015 at 15:00
  • 1
    $\begingroup$ @rcollyer Guess what was the thing I wrestled most on my hack? Displaying regions of dimension 0, 1 and 2 all in an acceptable manner. There's room for improvement in that regard in my code, but in my opinion also on facilities Mma provides. $\endgroup$
    – kirma
    Commented May 1, 2015 at 15:02
  • 1
    $\begingroup$ Looking through it, I think RegionPlot is even better: showRegion[eq_, vars_List, range_List] := RegionPlot[ImplicitRegion[eq, vars], PlotRange -> range, FrameTicks -> None]. Also, you can display multiple regions at once with it, which in most cases clarifies how they go together. $\endgroup$
    – rcollyer
    Commented May 1, 2015 at 15:11
  • $\begingroup$ @rcollyer Huh! I tried to do this the "old way", using equation in RegionPlot. Apparently supplying region instead actually works! :) $\endgroup$
    – kirma
    Commented May 1, 2015 at 15:23
  • $\begingroup$ welcome to version 10. The mini-bar is on your right, and world domination is just a quick bit of coding away. :) $\endgroup$
    – rcollyer
    Commented May 1, 2015 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.