# Why does Simplify on an equation not remove terms that can't be zero

I have a complicated equation, with a parameter T which is positive. The parameter ends up multiplying all terms of my equation, so Mathematica factors it out the front. But for some reason Simplify (or FullSimplify) refuses to factor it out, unless the rest of the equation is simple.

Simplify[T (b +  e (-1 + c) (1 + Tanh[a])) == 0, T > 0]

(* T (b + (-1 + c) e (1 + Tanh[a])) == 0 *)


If I make the equation slightly simpler, Mathematica has no problem with removing the T:

Simplify[T (b +  e (c) (1 + Tanh[a])) == 0, T > 0]

(* b + c e + c e Tanh[a] == 0 *)


My actual equation is much longer, but I want to be able to check that T does not exist in it.

• How simple an expression is depends on how you quantify simplicity. If you provide Simplify with a different complexity function (e.g. ComplexityFunction -> (StringLength[ToString[#1]] &), you can get the T factored out, at the expense of some other reorganization of your equation. See also (92686). – MarcoB Jun 26 '17 at 14:12
• It is not clear, what do you want. Mathematica does factor it out in your first expression. You seem to mean that Mma does not automatically divide by the both equation parts by it, do you? You have written that your equation always has T as a factor. If I understood this right, there is a simple way to get rid of it: equation/.T->1. Have fun! – Alexei Boulbitch Jun 26 '17 at 14:15
• It might be helpful to try Reduce to see possible solutions. If T==0 is one of them, it suggests (but does not guarantee) that you can factor it out. Reduce[tt (b + e (c - 1) (1 + Tanh[a])) == 0, tt] =  (* b == -(-1 + c) e (1 + Tanh[a]) || tt == 0 *). – MikeY Jun 26 '17 at 14:15
• @AlexeiBoulbitch Mathematica factors $T$ out yes, but I'm telling it that $T>0$ in the assumptions, so it should be able to remove it entirely. – KraZug Jun 26 '17 at 14:56
• @MarcoB, for any complexity function, removing the T entirely would make it simpler. – KraZug Jun 26 '17 at 14:57

This is an interesting case. First, here is a more minimal example. While Simplify does not eliminate T:

Simplify[(1 + 2 a^2 (a + b)) T == 0, T != 0]
(* (1 + 2 a^2 (a + b)) T == 0 *)


FullSimplify does the job in this case:

FullSimplify[(1 + 2 a^2 (a + b)) T == 0, T != 0]
(* 1 + 2 a^2 (a + b) == 0 *)


Simplify does work for much more complicated cases such as

Simplify[(1 + 2 a^2 (a + b) + x^1/3 - Coth[Gamma[42^z] I]) T == 0, T != 0]
(* 3 + 6 a^3 + 6 a^2 b + x + 3 I Cot[Gamma[42^z]] == 0 *)


So the complexity by itself is not the issue.

Now, to a possible solution to your problem. In the MMA documentation for ComplexityFunction the "Properties & Relations" section contains the complexity function Simplify uses by default to assess the complexity of a term. You may modify this function such that any appearance of T is extremely expensive:

SimplifyCountX[p_] := Which[
p===T, 10^6,
IntegerQ[p], If[p==0,1,Floor[N[Log[2,Abs[p]]/Log[2,10]]]+If[p>0,1,2]],
NumberQ[p], 2,
]


The first case within Which[...] is the modification. Everything else is like in the documentation.

Using this complexity function things should at least improve for you:

Simplify[(1 + 2 a^2 (a + b)) T == 0, T != 0, ComplexityFunction -> SimplifyCountX]
(* 1 + 2 a^3 + 2 a^2 b == 0 *)


I also tested this with more complicated functions, and it seems to work.

To make sure if it worked, use

FreeQ[..., T]


on the simplified expression.

"I want to be able to check that T does not exist in it."

I assume you mean you want to check that you can factor T out. So, expanding on @AlexeiBoulbitch's suggestion, remove it, multiply by it, and check for equality.

expression = T (b + e (-1 + c) (1 + Tanh[a]))
Simplify[T (expression /. T -> 1) == expression]
(* True *)

• But this doesn't work if the factor is $T^2$ for example. – KraZug Jun 27 '17 at 8:26
• It'm still not entirely clear on what you want, but MatchQ[Cancel[expression/(expression /. T -> 1)], Power[T, _]] will check to see if you can factor any power of T out. – John Doty Jun 27 '17 at 14:04
• To be honest, I mostly just want to understand why Mathematica doesn't remove it in this case, when it can. – KraZug Jun 27 '17 at 14:06
• Simplify doesn't exhaustively try every available transformation. It has no reliable way to to tell it's "done". It makes decisions based on the informed guesses its developers built into it. There's no way for the user to understand why it didn't choose a particular transformation trajectory, and it would probably not be illuminating if you could. – John Doty Jun 27 '17 at 14:38
Simplify[Expand[T (b + e (-1 + c) (1 + Tanh[a]))] == 0, T > 0]
(* b + c e + c e Tanh[a] == e (1 + Tanh[a]) *)


eliminates T. Perhaps, this works because Expand makes the LeafCount of the equation larger, giving Simplify more options to try things. (Not a very satisfying explanation, I admit. Nonetheless, I have seen Expand before Simplify help in the other situations.) To gather all terms to the left side of the equation again, use

Simplify[# - Last[%]] & /@ %
(* b + (-1 + c) e + (-1 + c) e Tanh[a] == 0 *)


cf[e_] := LeafCount[e] + 100 Count[e, T, Infinity]

Note that this answer is taken almost directly from Mathematica documentation. Once again, it appears that Simplify works better when the achievable savings in ComplexityFunction is large.