The undocumented function Internal`FromPiecewise
seems to take a Piecewise
function in the standard form returned by PiecewiseExpand
and return a list consisting of a partition of the real numbers into intervals and a list of corresponding values.
try = {3 (1 - q), 2 (1 - q) + q, 1 + 1.5 q};
Internal`FromPiecewise@ PiecewiseExpand@ Min[try]
(* {{0.4 <= q < 1/2, q >= 1/2, q < 0.4}, {2 - q, -3 (-1 + q), 1 + 1.5 q}} *)
Since each break point occurs one at an equality (i.e. <=
or >=
), we can extract them and solve. The function ineqToEq
converts an inequality like those above to an equality or to False
(which signifies no end point).
ineqToEq[ie_] := Replace[
LogicalExpand@ ie /. Less | Greater -> (True &),
{(GreaterEqual | LessEqual)[a_, b_] :> a == b, True -> False}
]
Applied to the OP's example:
Or @@ ineqToEq /@ First@ Internal`FromPiecewise@ PiecewiseExpand@ Min[try] // Solve
(* {{q -> 0.4}, {q -> 1/2}} *)
This following passes Patrick Stevens's clever D
test, but this method finds the break point:
f = Piecewise[{{q^3, q < 0}}, q^2];
Or @@ ineqToEq /@ First@ Internal`FromPiecewise@ PiecewiseExpand@ f // Solve
(* {{q -> 0}} *)
Another internal alternative
There are many functions in Mathematica that process the discontinuities of a piecewise function. You would think there would be an easy way to do it, but there doesn't seem to be one. Well, here's a different function, again internal, undocumented, and subject to change, which is used by NIntegrate
. One advantage is that it handles Min
with the user first converting it to a Piecewise
function.
Here's how it works on the OP's function:
NIntegrate`PiecewiseNIntegrateMultipleRanges[
Min[try], {{q, -Infinity, Infinity}}, {(* options *)}, {(* piecewise options *)}]
(* {{2 - q, {q, 2/5, 1/2}}, {-3 (-1 + q), {q, 1/2, ∞}}, {1/2 (2 + 3 q), {q, -∞, 2/5}}} *)
General function and example:
pwBreaks[f_, x_] :=
DeleteCases[Infinity | -Infinity]@*Union @@
NIntegrate`PiecewiseNIntegrateMultipleRanges[
f, {{x, -Infinity, Infinity}}, {}, {}][[All, 2, 2 ;; 3]]
pwBreaks[Min[try], q]
(* {2/5, 1/2} *)
Min[try] // PiecewiseExpand
(and manipulation of that result) what you're after? $\endgroup$With[{rt = Rationalize[try]}, {#, Reduce[Min[rt] == #]} & /@ rt]
might also float your boat - in either case, you'll need to massage the results to pull out the items of interest.... $\endgroup${q -> 1/2, q -> 2/5}
$\endgroup$