# Extract desired solutions from Reduce

I have the function

a = 1 - 3 Sin[theta]^2 Cos[phi]^2;


which I solve for 'phi' when $a=0$

sol = Reduce[a == 0, phi]


which gives me the result How do I turn this output into a nice list of results for desired values of C, much like Solve[ ] would give me, so that I can use Plot[ ] and visualise the functions?

• I fear I may get a 'duplicate' wrist slap as a similar question was answered by m_goldberg on one of my previous posts, and to certain degrees on other posts, but I don't understand well enough to translate to this particular problem :) Hopefully this simple example will help. As always thanks very much for any help.
– Tom
Jun 30, 2014 at 13:06
• Do you mean that you are looking for an entirely automated solution that would work for any Reduce output with no manual intervention? That sounds difficult. Otherwise is {ToRules[sol /. C -> 0]} acceptable here? The manual step was choosing a particular (integer) value for C. Jun 30, 2014 at 13:32
• That's great @Szabolcs. Neat simple solution I was hoping for. What If I wanted a list of all the solutions for values of C say from 1 to 50?
– Tom
Jun 30, 2014 at 13:42
• Not sure what's simplest in that case ... use a Table? Can't really think of anything simpler than that. Jun 30, 2014 at 13:44

ToRules is useful here.

If we manually set a value to the parameter C, we can convert the remaining expression to a list of rules similar to what Solve would return:

In:= rules = {ToRules[sol /. C -> 0]}

Out= {{phi -> -ArcCos[-(Csc[theta]/Sqrt)]}, {phi -> ArcCos[-(Csc[theta]/Sqrt)]},
{phi -> -ArcCos[Csc[theta]/Sqrt]}, {phi -> ArcCos[Csc[theta]/Sqrt]}}


Notice that ToRules removed the Sin[theta] != 0 condition, but it would remove the C ∈ Integers condition if we don't make it go away manually. I do not know (and did not check) when precisely it will remove any conditions. So in more general applications this is something to pay attention to.

Plot[phi /. rules, {theta, -5, 5}]


An alternative approach here is to use Solve, which returns the same solution (in recent versions!) as Reduce, but in a different form:

Solve[a == 0, phi]
(* {{phi ->
ConditionalExpression[-ArcCos[-(Csc[theta]/Sqrt)] +
2 π C, C ∈ Integers]}, {phi ->
ConditionalExpression[ArcCos[-(Csc[theta]/Sqrt)] + 2 π C,
C ∈ Integers]}, {phi ->
ConditionalExpression[-ArcCos[Csc[theta]/Sqrt] + 2 π C,
C ∈ Integers]}, {phi ->
ConditionalExpression[ArcCos[Csc[theta]/Sqrt] + 2 π C,
C ∈ Integers]}} *)


If Solve does not generate full conditions by default, as Reduce would, we can use the option Solve[..., Method -> Reduce] to force it to do so.

To make all these ConditionalExpressions go away, we can use Normal:

sol2 = Normal@Solve[a == 0, phi]
(* {{phi -> -ArcCos[-(Csc[theta]/Sqrt)] +
2 π C}, {phi ->
ArcCos[-(Csc[theta]/Sqrt)] +
2 π C}, {phi -> -ArcCos[Csc[theta]/Sqrt] +
2 π C}, {phi -> ArcCos[Csc[theta]/Sqrt] + 2 π C}} *)


Notice that this retained C, but dropped the condition. Now we can do

Block[{C}, Join @@ Table[phi /. sol2, {C, -5, 5}]]


to have a table of solutions corresponding to $C_1 \in \{-5, -4, \ldots, 4, 5\}$. Block was needed to temporarily lift the protection from C.

Using Solve doesn't give anything new here, it's just a different way of achieving the same results. It may be more or less convenient than Reduce.

Respecting generated conditions is important. In this particular equation (which could be solved by hand and the conditions are clear from the equation. You can access the solutions in a number of ways (e.g. using rules from Solve). Here is just one way:

a = 1 - 3 Sin[theta]^2 Cos[phi]^2;
sol = Reduce[a == 0, phi]
solc = sol /. Equal[x_, y_] :> Rule[x, y];
funs = Cases[solc, Rule[phi, x_] :> x, Infinity] /. C -> 0
Plot[funs, {theta, 0, 2 Pi}, PlotStyle -> {Red, Green, Blue, Orange}] 