Reduce
often provides a much fuller solution than Solve
. But it's always in the form of a true statement rather than functions or replacement rules, e.g.
Input:
Reduce[Sin[x^2] + Cos[a] == 0 && -π/2 <= x <= π/2, x]
Output:
(Cos[a] == -1 && (x == -Sqrt[(π/2)] || x == Sqrt[π/2])) ||
(-1 < Cos[a] <= Sin[1/4 (-4 π + π^2)] &&
(x == -Sqrt[π + ArcSin[Cos[a]]] || x == Sqrt[π + ArcSin[Cos[a]]])) ||
(Cos[a] == 0 && x == 0) ||
(-1 < Cos[a] < 0 && (x == -Sqrt[-ArcSin[Cos[a]]] || x == Sqrt[-ArcSin[Cos[a]]]))
What I need is a function that takes the variable solved for (i.e. x
here) as its input and gives corresponding value (or a list of values/separate functions for non-unique solutions) as the output. For example, the above output would be represented similarly to the following:
solution[x_] = Piecewise[{
{{-Sqrt[Pi/2], Sqrt[Pi/2]}, Cos[a] == -1},
{{-Sqrt[Pi + ArcSin[Cos[a]]], Sqrt[Pi + ArcSin[Cos[a]]]},
-1 < Cos[a] <= Sin[(1/4)*(-4*Pi + Pi^2)]},
{0, Cos[a] == 0},
{{-Sqrt[-ArcSin[Cos[a]]], Sqrt[-ArcSin[Cos[a]]]},
-1 < Cos[a] < 0}}]
What is a good way to transform the expression returned by Reduce
to such a function?
In[..]
andOut[..]
has been discussed here, and it was accepted as a consensus. You are welcome to add comments at the post there if you think that discussion should be restarted. $\endgroup$