# Reduce not solving linear equation

I have a long equation in 7 variables but the equation is linear (affine) in x. But when I try to solve with Reduce, it keeps running forever. With Solve, I am able to get an answer. Usually I have the opposite problem, Solve does not work and Reduce does. Any ideas on how to make Reduce work? I am teaching a class using Mathematica and it would be nice if we did not have to keep switching to Solve and Reduce all the time. The code is given below:

 Reduce[ q*((-1 + 1/PH)*R - (1/5)*(-1 + 1/PH)*
R^2*(1 - x + x/PH))*(1 - λH) +
q*(1 - PH - (1/5)*(1 - PH)*(PH*(1 - x) + x))*λH +
(1 - q)*((-1 + 1/PL)*R - (1/5)*(-1 + 1/PL)*R^2*(1 - x + x/PL))*
(1 - λL) + (1 - q)*(1 -
PL - (1/5)*(1 - PL)*(PL*(1 - x) + x))*
λL == 0, {x},Reals]

• You might want to share these equations, or a smaller version where Reduce[] also chokes. Nov 5, 2015 at 21:26
• @J.M. Thanks for the suggestion, I added the code. Nov 7, 2015 at 19:36
• Can't write an answer yet (waiting for all the reopen votes to roll in), but here's why: What's the solution of $a x+b=0$? You might have said $x = -b/a$. But when Mathematica gives results much more innocent than that, people will often still cry bloody murder on this site because the right answer if $x = -b/a$ if $a \ne 0$. Otherwise, if $a = b = 0$ then any $x$ satisfies the equation. This is exactly the answer that Reduce gives. Reduce[a x + b == 0, x] -> (b == 0 && a == 0) || (a != 0 && x == -(b/a)). Now use CoefficientList to see what a and b are for your equation. ... Nov 7, 2015 at 20:13
• ... They're complicated enough. Trying Reduce[a==0] (with your equation's a substituted in) gives a pretty complicated solution. Reduce[a==0 && b==0] is already hard enough to handle that Reduce never finishes. The solution: either don't use such complicated coefficients (i.e. use CoefficientList to see what they are then replace them with simple symbols), or use Solve which isn't so fussy about edge cases like a==0. As I understand, this is exactly why we have both Solve and Reduce. I wouldn't want to stick to only one of them just to make things look simpler in class. Nov 7, 2015 at 20:17
• Many students already come here asking naïve questions which show that they think of Mathematica as some magical blackbox that should be able to mysteriously solve any problem you throw at it, without having a good sense of what is a reasonable request (to Mathematica) and what isn't, or how difficult a problem really is. Best not to propagate such misunderstandings. BTW here's an example of people being upset about Mathematica missing the a==0 case: mathematica.stackexchange.com/questions/65624/… and all links in the sidebar. Nov 7, 2015 at 20:18

Solve gives "generic" solutions only, which may not be valid under all conditions.

Reduce attempts to find generally valid solutions.

Your equation has the form a x + b == 0, where a and b are complicated expressions.

Solve says that the solution is x == -b/a.

In[1]:= Solve[a x + b == 0, x]
Out[1]= {{x -> -(b/a)}}


But this is not generally valid. If a == 0 and b != 0 then there are no solutions. If a == b == 0 then any x is a solution. Reduce can figure this out:

In[2]:= Reduce[a x + b == 0, x]
Out[2]= (b == 0 && a == 0) || (a != 0 && x == -(b/a))


In your case a and b are very complicated:

{a, b} = CoefficientList[
q*((-1 + 1/PH)*R - (1/5)*(-1 + 1/PH)*
R^2*(1 - x + x/PH))*(1 - \[Lambda]H) +
q*(1 - PH - (1/5)*(1 - PH)*(PH*(1 - x) + x))*\[Lambda]H + (1 -
q)*((-1 + 1/PL)*R - (1/5)*(-1 + 1/PL)*
R^2*(1 - x + x/PL))*(1 - \[Lambda]L) + (1 - q)*(1 -
PL - (1/5)*(1 - PL)*(PL*(1 - x) + x))*\[Lambda]L, x];


Just solving for a == 0 gives an even more complicated result:

In[4]:= a
Out[4]= (-1 + 1/PH) q R (1 - \[Lambda]H) +
1/5 (1 - 1/PH) q R^2 (1 - \[Lambda]H) + q \[Lambda]H -
PH q \[Lambda]H +
1/5 (-1 + PH) PH q \[Lambda]H + (-1 + 1/PL) (1 -
q) R (1 - \[Lambda]L) +
1/5 (1 - 1/PL) (1 - q) R^2 (1 - \[Lambda]L) + (1 - q) \[Lambda]L -
PL (1 - q) \[Lambda]L + 1/5 (-1 + PL) PL (1 - q) \[Lambda]L

In[5]:= Reduce[a == 0]
Out[5]= (PL q \[Lambda]H !=
0 && (PH ==
Root[5 PL q R - PL q R^2 - 5 PL q R \[Lambda]H +
PL q R^2 \[Lambda]H + (5 R - 5 PL R - 5 q R - R^2 + PL R^2 +
q R^2 + 5 PL q \[Lambda]H + 5 PL q R \[Lambda]H -
PL q R^2 \[Lambda]H + 5 PL \[Lambda]L -
6 PL^2 \[Lambda]L + PL^3 \[Lambda]L - 5 PL q \[Lambda]L +
6 PL^2 q \[Lambda]L - PL^3 q \[Lambda]L -
5 R \[Lambda]L + 5 PL R \[Lambda]L + 5 q R \[Lambda]L -
5 PL q R \[Lambda]L + R^2 \[Lambda]L - PL R^2 \[Lambda]L -
q R^2 \[Lambda]L + PL q R^2 \[Lambda]L) #1 -
6 PL q \[Lambda]H #1^2 + PL q \[Lambda]H #1^3 &, 1] ||
PH == Root[
5 PL q R - PL q R^2 - 5 PL q R \[Lambda]H +
PL q R^2 \[Lambda]H + (5 R - 5 PL R - 5 q R - R^2 + PL R^2 +
q R^2 + 5 PL q \[Lambda]H + 5 PL q R \[Lambda]H -
PL q R^2 \[Lambda]H + 5 PL \[Lambda]L -
6 PL^2 \[Lambda]L + PL^3 \[Lambda]L - 5 PL q \[Lambda]L +
6 PL^2 q \[Lambda]L - PL^3 q \[Lambda]L -
5 R \[Lambda]L + 5 PL R \[Lambda]L + 5 q R \[Lambda]L -
5 PL q R \[Lambda]L + R^2 \[Lambda]L - PL R^2 \[Lambda]L -
q R^2 \[Lambda]L + PL q R^2 \[Lambda]L) #1 -
6 PL q \[Lambda]H #1^2 + PL q \[Lambda]H #1^3 &, 2] ||
PH == Root[
5 PL q R - PL q R^2 - 5 PL q R \[Lambda]H +
PL q R^2 \[Lambda]H + (5 R - 5 PL R - 5 q R - R^2 + PL R^2 +
q R^2 + 5 PL q \[Lambda]H + 5 PL q R \[Lambda]H -
PL q R^2 \[Lambda]H + 5 PL \[Lambda]L -
6 PL^2 \[Lambda]L + PL^3 \[Lambda]L - 5 PL q \[Lambda]L +
6 PL^2 q \[Lambda]L - PL^3 q \[Lambda]L -
5 R \[Lambda]L + 5 PL R \[Lambda]L + 5 q R \[Lambda]L -
5 PL q R \[Lambda]L + R^2 \[Lambda]L - PL R^2 \[Lambda]L -
q R^2 \[Lambda]L + PL q R^2 \[Lambda]L) #1 -
6 PL q \[Lambda]H #1^2 + PL q \[Lambda]H #1^3 &, 3]) &&
PH != 0) || (q == 0 && \[Lambda]L !=
0 && (PL == 1 ||
PL == -((-5 \[Lambda]L +
Sqrt[\[Lambda]L] Sqrt[
20 R - 4 R^2 + 25 \[Lambda]L - 20 R \[Lambda]L +
4 R^2 \[Lambda]L])/(2 \[Lambda]L)) ||
PL == (5 \[Lambda]L +
Sqrt[\[Lambda]L] Sqrt[
20 R - 4 R^2 + 25 \[Lambda]L - 20 R \[Lambda]L +
4 R^2 \[Lambda]L])/(2 \[Lambda]L)) &&
PH PL \[Lambda]H != 0) || (\[Lambda]H == 0 &&
5 R - 5 PL R - 5 q R - R^2 + PL R^2 + q R^2 + 5 PL \[Lambda]L -
6 PL^2 \[Lambda]L + PL^3 \[Lambda]L - 5 PL q \[Lambda]L +
6 PL^2 q \[Lambda]L - PL^3 q \[Lambda]L - 5 R \[Lambda]L +
5 PL R \[Lambda]L + 5 q R \[Lambda]L - 5 PL q R \[Lambda]L +
R^2 \[Lambda]L - PL R^2 \[Lambda]L - q R^2 \[Lambda]L +
PL q R^2 \[Lambda]L != 0 &&
PH == (5 PL q R - PL q R^2)/(-5 R + 5 PL R + 5 q R + R^2 - PL R^2 -
q R^2 - 5 PL \[Lambda]L + 6 PL^2 \[Lambda]L -
PL^3 \[Lambda]L + 5 PL q \[Lambda]L - 6 PL^2 q \[Lambda]L +
PL^3 q \[Lambda]L + 5 R \[Lambda]L - 5 PL R \[Lambda]L -
5 q R \[Lambda]L + 5 PL q R \[Lambda]L - R^2 \[Lambda]L +
PL R^2 \[Lambda]L + q R^2 \[Lambda]L -
PL q R^2 \[Lambda]L) && -5 PL q R + PL q R^2 !=
0) || (\[Lambda]L == 0 && \[Lambda]H == 0 && (R == 0 || R == 5) &&
PH PL != 0) || (\[Lambda]L == 0 && (R == 0 || R == 5) && q == 0 &&
PH PL \[Lambda]H != 0) || (\[Lambda]H == 0 &&
q == 0 && \[Lambda]L !=
0 && (PL == 1 ||
PL == -((-5 \[Lambda]L +
Sqrt[\[Lambda]L] Sqrt[
20 R - 4 R^2 + 25 \[Lambda]L - 20 R \[Lambda]L +
4 R^2 \[Lambda]L])/(2 \[Lambda]L)) ||
PL == (5 \[Lambda]L +
Sqrt[\[Lambda]L] Sqrt[
20 R - 4 R^2 + 25 \[Lambda]L - 20 R \[Lambda]L +
4 R^2 \[Lambda]L])/(2 \[Lambda]L)) && -5 PH PL R +
PH PL R^2 != 0) || (\[Lambda]H ==
0 && (R == 0 || R == 5) && \[Lambda]L != 0 && q == 1 &&
PH PL != 0) || (\[Lambda]H ==
0 && (R == 0 || R == 5) && (-1 + q) \[Lambda]L !=
0 && (PL == 1 || PL == 5) && PH != 0) || (\[Lambda]L == 0 &&
q == 0 && (-5 + R) R != 0 && PL == 1 &&
PH \[Lambda]H != 0) || (\[Lambda]L == 0 && \[Lambda]H == 0 &&
q == 0 && PL == 1 && -5 PH R + PH R^2 != 0)


Seeing this it is not surprising that

Reduce[a == 0 && b == 0]


would take a very long time (in practice: hang).

This is the reason why Reduce never finishes.

While Mathematica can solve many problems automatically, this example illustrates well why we must not treat it as a magical black box that spits out solutions. It is still important to be aware of which problems are easy to compute and which are difficult, and then guide the system accordingly. I am saying this because I noticed that many students come to this site asking "why won't Mathematica solve this" without thinking of the difficulties of the problem, or considering how they would solve it by hand. They treat Mathematica as a magical solve-it-all system that we can't possibly understand. I think it is important not to encourage such an attitude in class. Instead, encourage them to treat Mathematica as a tool that takes care of the boring details of calculations, but understand that they must still be in charge.

This is why I think that it is not necessarily a good thing to just use a single command to solve any equation and always avoid dealing with the differences between Solve and Reduce.