I often run into the problem that Mathematica refuses to simplify divergent subexpressions as part of a full expression that is manifestly finite. This only happens when a symbolic power is involved.
A minimal example is:
expr = x^(d - 4) (a x^2 + b (x + x^3 + c x^d));
Let's say this is an expression that I want to use for all d>=3
.
Then d=3
comes closest to diverging:
Series[expr/.d->3,{x,0,0}]
gives b
, ofcourse.
But I want to be able to do this:
expr /. d->3 /.x->0
which in its current form will run into a division by zero.
Note that if we simplify the expression after setting d->3
it does work, but that is not what I'm after.
I have at various times made some ad hoc solution with a replacement rule for example, but I've run into this problem so often now that I'm looking for a definite general solution.
You may assume that the expression is rational in x
, that the expression when properly expanded is finite and nonzero at x=x0
(in the example above x0=0
), and that there is some definite lower bound for the symbolic power (d
above).
I'm ideally looking for a simple and reasonably fast solution that works for any expression satisfying the above criteria.
EDIT:
Something like Expand[expr]
would work, but I want something more sensible, keeping the expression as much as possible in simplified form.
Limit[expr, d -> 3 ] /. x->0
? $\endgroup$Replace[expr, t_Times :> Distribute@t, All] /. d -> 3 /. x -> 0
? $\endgroup$/. d->3 /. x->0
, that is the point, it shouldn't be necessary. $\endgroup$Expand
should work too), but I want to keep the expression as close as possible to the simplified form, ideally just changing the already present powers of x appropriately to make it manifestly finite. $\endgroup$