# Avoiding divide by zero to simplify an expression enough to solve

I have a very complicated expression that I'm trying to set to zero and solve. I simplify by substituting in variables, but Mathematica isn't fully simplifying it -- my guess is because it thinks it might be dividing by zero. I try to avoid this, but I'm getting stuck. Would be very appreciative of help with this and with ultimately solving the equation for b.

Here is the original expression:

$\gamma +\frac{2 e^{\frac{3 b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \left(e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}\right) \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sigma ^2}} \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}}}{\sqrt{\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}}}\right)^{-\frac{\mu }{\sqrt{\mu ^2+2 \lambda \sigma ^2}}-1} \sqrt{\mu ^2+2 \lambda \sigma ^2} \left(-\mu ^2+\sqrt{\mu ^2+2 \lambda \sigma ^2} \mu -2 \lambda \sigma ^2\right)}{\left(-1+e^{\frac{2 b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}}\right)^2 \lambda \sigma ^2 \left(\sqrt{\mu ^2+2 \lambda \sigma ^2}-\mu \right)}-\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \left(e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}\right) \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sigma ^2}} \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}}}{\sqrt{\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}}}\right)^{-\frac{\mu }{\sqrt{\mu ^2+2 \lambda \sigma ^2}}-2} \left(-\frac{\mu }{\sqrt{\mu ^2+2 \lambda \sigma ^2}}-1\right) \left(-\mu ^2+\sqrt{\mu ^2+2 \lambda \sigma ^2} \mu -2 \lambda \sigma ^2\right) \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sigma ^2}} \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \sqrt{\mu ^2+2 \lambda \sigma ^2} \text{mc}}{\sigma ^2}+\frac{e^{\frac{b \mu }{\sigma ^2}} \text{me} \mu }{\sigma ^2}\right)}{2 \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}} \sqrt{\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}}}+\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sigma ^2}} \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}} \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sqrt{\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}} \sigma ^2}-\frac{e^{\frac{\left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right) b}{\sigma ^2}+\frac{\sqrt{\mu ^2+2 \lambda \sigma ^2} b}{2 \sigma ^2}} \text{me} \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}} \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{2 \left(\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}\right)^{3/2} \sigma ^2}\right)}{\left(-1+e^{\frac{2 b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}}\right) \lambda \left(\sqrt{\mu ^2+2 \lambda \sigma ^2}-\mu \right)}-\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sigma ^2}} \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}}}{\sqrt{\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}}}\right)^{-\frac{\mu }{\sqrt{\mu ^2+2 \lambda \sigma ^2}}-1} \left(-\mu ^2+\sqrt{\mu ^2+2 \lambda \sigma ^2} \mu -2 \lambda \sigma ^2\right) \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \sqrt{\mu ^2+2 \lambda \sigma ^2} \text{mc}}{\sigma ^2}+\frac{e^{\frac{b \mu }{\sigma ^2}} \text{me} \mu }{\sigma ^2}\right)}{\left(-1+e^{\frac{2 b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}}\right) \lambda \left(\sqrt{\mu ^2+2 \lambda \sigma ^2}-\mu \right)}-\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \left(e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}\right) \left(\frac{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{2 \sigma ^2}} \sqrt{e^{\frac{b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}} \text{mc}+e^{\frac{b \mu }{\sigma ^2}} \text{me}}}{\sqrt{\text{mc}+e^{\frac{b \left(\mu +\sqrt{\mu ^2+2 \lambda \sigma ^2}\right)}{\sigma ^2}} \text{me}}}\right)^{-\frac{\mu }{\sqrt{\mu ^2+2 \lambda \sigma ^2}}-1} \sqrt{\mu ^2+2 \lambda \sigma ^2} \left(-\mu ^2+\sqrt{\mu ^2+2 \lambda \sigma ^2} \mu -2 \lambda \sigma ^2\right)}{\left(-1+e^{\frac{2 b \sqrt{\mu ^2+2 \lambda \sigma ^2}}{\sigma ^2}}\right) \lambda \sigma ^2 \left(\sqrt{\mu ^2+2 \lambda \sigma ^2}-\mu \right)}$

I can then simplify with some substitution (pasting the input code here as well for reproduction):

DGq=γ+(2 E^((3 b Sqrt[μ^2+2 λ σ^2])/σ^2) (E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me) ((E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)) Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me])/Sqrt[mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me])^(-1-μ/Sqrt[μ^2+2 λ σ^2]) Sqrt[μ^2+2 λ σ^2] (-μ^2-2 λ σ^2+μ Sqrt[μ^2+2 λ σ^2]))/((-1+E^((2 b Sqrt[μ^2+2 λ σ^2])/σ^2))^2 λ σ^2 (-μ+Sqrt[μ^2+2 λ σ^2]))-(E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) (E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me) ((E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)) Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me])/Sqrt[mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me])^(-1-μ/Sqrt[μ^2+2 λ σ^2]) Sqrt[μ^2+2 λ σ^2] (-μ^2-2 λ σ^2+μ Sqrt[μ^2+2 λ σ^2]))/((-1+E^((2 b Sqrt[μ^2+2 λ σ^2])/σ^2)) λ σ^2 (-μ+Sqrt[μ^2+2 λ σ^2]))-(E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) ((E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)) Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me])/Sqrt[mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me])^(-1-μ/Sqrt[μ^2+2 λ σ^2]) (-μ^2-2 λ σ^2+μ Sqrt[μ^2+2 λ σ^2]) ((E^((b μ)/σ^2) me μ)/σ^2+(E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc Sqrt[μ^2+2 λ σ^2])/σ^2))/((-1+E^((2 b Sqrt[μ^2+2 λ σ^2])/σ^2)) λ (-μ+Sqrt[μ^2+2 λ σ^2]))-(E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) (E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me) ((E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)) Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me])/Sqrt[mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me])^(-2-μ/Sqrt[μ^2+2 λ σ^2]) (-1-μ/Sqrt[μ^2+2 λ σ^2]) (-μ^2-2 λ σ^2+μ Sqrt[μ^2+2 λ σ^2]) ((E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)) Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me] Sqrt[μ^2+2 λ σ^2])/(2 Sqrt[mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me] σ^2)-(E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)+(b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me] (μ+Sqrt[μ^2+2 λ σ^2]))/(2 (mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me)^(3/2) σ^2)+(E^((b Sqrt[μ^2+2 λ σ^2])/(2 σ^2)) ((E^((b μ)/σ^2) me μ)/σ^2+(E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc Sqrt[μ^2+2 λ σ^2])/σ^2))/(2 Sqrt[E^((b Sqrt[μ^2+2 λ σ^2])/σ^2) mc+E^((b μ)/σ^2) me] Sqrt[mc+E^((b (μ+Sqrt[μ^2+2 λ σ^2]))/σ^2) me])))/((-1+E^((2 b Sqrt[μ^2+2 λ σ^2])/σ^2)) λ (-μ+Sqrt[μ^2+2 λ σ^2]))

DGq=Simplify[DGq//.{Sqrt[2 λ σ^2+μ^2]->A,1/(Sqrt[2 λ σ^2+μ^2])->1/A,μ/σ^2 -> B,σ^2 -> S,1/σ^2 -> 1/S}]


Which looks a bit nicer:

$\frac{\text{mc} (A+\mu ) (\mu (A-\mu )-2 \lambda S) \left(A \left(2 \text{mc} e^{\frac{A b}{S}}+\text{me} e^{\frac{b (2 A+\mu )}{S}}+\text{me} e^{b B}\right)-\mu \text{me} e^{b B} \left(e^{\frac{2 A b}{S}}-1\right)\right) \left(\frac{e^{\frac{A b}{2 S}} \sqrt{\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}}}{\sqrt{\text{me} e^{\frac{b (A+\mu )}{S}}+\text{mc}}}\right)^{1-\frac{\mu }{A}}}{2 A \lambda S (A-\mu ) \left(e^{\frac{2 A b}{S}}-1\right) \left(\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}\right)}+\frac{2 A e^{\frac{3 A b}{S}} (\mu (A-\mu )-2 \lambda S) \left(\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}\right) \left(\frac{e^{\frac{A b}{2 S}} \sqrt{\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}}}{\sqrt{\text{me} e^{\frac{b (A+\mu )}{S}}+\text{mc}}}\right)^{-\frac{A+\mu }{A}}}{\lambda S (A-\mu ) \left(e^{\frac{2 A b}{S}}-1\right)^2}-\frac{A e^{\frac{A b}{S}} (\mu (A-\mu )-2 \lambda S) \left(\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}\right) \left(\frac{e^{\frac{A b}{2 S}} \sqrt{\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}}}{\sqrt{\text{me} e^{\frac{b (A+\mu )}{S}}+\text{mc}}}\right)^{-\frac{A+\mu }{A}}}{\lambda S (A-\mu ) \left(e^{\frac{2 A b}{S}}-1\right)}-\frac{e^{\frac{A b}{S}} (\mu (A-\mu )-2 \lambda S) \left(A \text{mc} e^{\frac{A b}{S}}+\mu \text{me} e^{b B}\right) \left(\frac{e^{\frac{A b}{2 S}} \sqrt{\text{mc} e^{\frac{A b}{S}}+\text{me} e^{b B}}}{\sqrt{\text{me} e^{\frac{b (A+\mu )}{S}}+\text{mc}}}\right)^{-\frac{A+\mu }{A}}}{\lambda S (A-\mu ) \left(e^{\frac{2 A b}{S}}-1\right)}+\gamma$

I know this can be further simplified by canceling out the (A-μ) term from the numerator and the denominators, but this isn't happening. Is there a way I can tell Mathematica that A != μ ? Also, there are some additional conditions (in addition to everything being real) on the variables that hopefully make it easier for Mathematica to solve:

A > 0 && B > 0 && S > 0 && b > 0 && λ > 0 && σ > 0 && me > 0 && mc > 0 && γ > 0 && A != μ, Reals


In the end, I'm hoping to set DGq (which is a function of A,B,S,b,λ,μ,me,mc) to zero and solve for b. Solve[DGq==0,b] just hangs. Any help would be VERY appreciated.

• Thanks for the code. Please make sure that all assumptions and further insights are specified in your question. For instance, is mu real? Larger than zero? – Lukas Jun 10 '16 at 17:08
• Thanks for the suggestions -- I've put the actual code for the expression above the simplification code, and I also specified that all the variables are real. mu can be negative, zero, or positive. – Karthik Jun 10 '16 at 17:11
• @Karthik Perhaps my math is slipping here, but I can't see the simplification of $A-\mu$ you mentioned. That expression is not present as a factor in the numerators of your expression. Am I missing something? – MarcoB Jun 10 '16 at 22:41