I would like to find x in the equation A*f(x)=0 for A>0. Since A is a very large expression, I would save time by solving f(x)=0 instead. Is there a way to let Mathematica "cancel out A" (even if it is an expression that not explicitly specified)?

Note that FullSimplify does not do this job correctly (and certainly not fast enough)


Solve[(Q (-1 + A + Sqrt[x]))/B == 0]

I would like to obtain the expression (without manual inspection):

A + Sqrt[x] == 1
  • $\begingroup$ you can use Replace to eliminate A, like Replace[A[y] f[x], A[y] f[x] -> f[x]] $\endgroup$ – Sumit Aug 24 '16 at 13:06
  • $\begingroup$ Thanks, but the issue is that A is big, unknown expression. The replacement rule would therefore not work... $\endgroup$ – Breugem Aug 24 '16 at 13:15
  • 1
    $\begingroup$ A few example expressions will be helpful. $\endgroup$ – Szabolcs Aug 24 '16 at 13:17
  • 1
    $\begingroup$ What about a + b + b x == 0? Do you expect this to be transformed to a/b + 1 + x == 0? My point is that it is not clear when a factor should be divided out. In your example Q and B disappear completely, so it is a very specific case. What are your criteria for deciding what to divide out? I'm just trying to make the question more objective and concrete. $\endgroup$ – Szabolcs Aug 24 '16 at 14:16
  • $\begingroup$ Thanks for your comment. Key importance to me is to generate an equation that can simply be executed as fast as possible. $\endgroup$ – Breugem Aug 24 '16 at 14:35

Here is one method:

Select[((Q (-1 + A + Sqrt[x]))/B == 0)[[1]], Not[FreeQ[#, x]] &] == 0

(* -1 + A + Sqrt[x] == 0 *)

Then you could put the output into Solve.

Or, more generally:

SetAttributes[extractfx, HoldAll];
extractfx[eq_, sym_Symbol] := Select[eq[[1]], Not[FreeQ[#, sym]] &] == 0;

which yields:

extractfx[(Q (-1 + A + Sqrt[x]))/B == 0, x]

(* -1 + A + Sqrt[x] == 0 *)

Note that the above code works only when the LHS has some multiplication at the outmost level and contains your variable, and the RHS is 0.


You can use the optional parameter of Simplify or FullSimplify to specify assumptions. $A f(x)=0$ only simplifies to $f(x)=0$ when $A\ne0$, so we can just use that assumption:


And of course you can specify a list of assumptions as well:

Simplify[(Q (-1 + A + Sqrt[x]))/B == 0, {Q!=0, B!=0}]

See the full documentation for Simplify.

  • $\begingroup$ That does not prevent the evaluation of A. $\endgroup$ – JungHwan Min Aug 24 '16 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.