# Fast way of finding diverging terms in a huge expressions

I have a huge expression called exp1 which is a function of rr. There are some terms in the huge expression which diverge when I put rr equal to zero. I want to find these terms. Does any one know an efficient way to do that?

exp1 is here

For example, if

exp1=0.5/rr^2+ b/rr+c rr^3 + f rr^2;

I want to find 0.5/rr^2+b/rr;

I know some ways to find these terms, but exp1 is very huge and I can not use simple ways like Series[exp1,{rr,0,0}].

Finding nondivergencing terms also helps me (f rr^2 + c rr^3+... )

• As is, the question is much to vague. Do you have a concrete example? – Henrik Schumacher Jul 21 '18 at 13:20
• Yes. I ve just added it. @HenrikSchumacher – Holger Mate Jul 21 '18 at 13:27

Perhaps this will give you some idea how to approach this problem.

A number of the assignments in your large file are not used. I hope this doesn't mean that the moment you get an answer that you will say you actually wanted something different.

You said that exp1 is the focus of your problem. exp1 is a simple numerator/denominator. I extract each of those and reorganize their form. This

Collect[Numerator[exp1], rr]/Collect[Denominator[exp1], rr]

very quickly returns a result where I then manually replace large expressions with corresponding simple variable names n6, n8, n9, n11, n12, n14, d6 and d12 just to be able to show and explain the structure of your problem in a compact form.

(-rr^6 n6-rr^8 n8-rr^9 n9-rr^11 n11-rr^12 n12-rr^14 n14)/(rr^6 d6+rr^12 d12)

Note that denominator is the only place in exp1 where rr appears in any denominator.

For each of the terms in the numerator that have rr to a greater power than 6, and assuming there isn't catastrophic cancellation, the numerator will go to zero faster than the denominator. That only leaves the rr^6 to consider.

To look at this behaves as rr tends to zero I'll take a Limit using my substituted variable names instead of the original large expressions.

Limit[(-rr^6 n6-rr^8 n8-rr^9 n9-rr^11 n11-rr^12 n12-rr^14 n14)/(rr^6 d6+rr^12 d12),rr->0]

which very quickly returns

-n6/d6

If it helps, an alternate way of writing that fraction is

(-n6 - rr^2 n8 - rr^3 n9 - rr^5 n11 - rr^6 n12 - rr^8 n14)/(d6 + rr^6 d12)

You can automate putting exp1 into this form using

newexp1 = Collect[Numerator[exp1], rr]/Collect[Denominator[exp1], rr] /. rr^n_ :> rr^(n-6)

I believe this result might imply that if your large expression were suitably arranged that terms in your your fraction do not blow up as rr goes to zero, but instead go to zero because the powers of rr in the numerator are greater than the powers in the denominator thus leaving that relatively simple fraction.

You haven't said what it is that you want to do after you were able to extract the terms which blow up when you replace rr with zero, but perhaps this can give you some idea that you might be able to use.

Hopefully at least this might let you see that your problem might be considerably simpler than it originally seemed to be.

Please check all this very carefully for correctness before you depend on it.

• Nice answer! TNX – Holger Mate Jul 23 '18 at 14:29

This attempts to compute a truncated Laurent expansion of the expression at rr == 0:

Series[0.5/rr^2 + b/rr + c rr^3 + f rr^2, {rr, 0, -1}]

$\frac{0.5}{\text{rr}^2}+\frac{b}{\text{rr}}+O\left(\text{rr}^0\right)$

-1 stands for the highest order of rr in the expansion, i.e. $\frac{1}{rr}$.

• The problem is that, exp1 is very huge and I can not use this code. Please look at the exp1 in the link and my explanations – Holger Mate Jul 21 '18 at 13:32
• Can you explain a bit what a negative order means and why it works here? – rhermans Jul 21 '18 at 13:44

If you mean "terms" as in addends or summands, and making a simple example, given that you didn't share any examples of your own...

expr = FullSimplify@Sum[c[k] x^(k - 4), {k, 7}]

Select[ List @@ ExpandAll[expr], (Abs[# /. x -> 0] == Infinity) &]

Now that you did share an expresion

exp1=0.5/rr^2+ b/rr+c rr^3 + f rr^2;

Select[
List @@ ExpandAll[exp1], (Abs[# /. rr -> 0] == Infinity) &]

• I did share the exp1. – Holger Mate Jul 21 '18 at 13:30
• This method take lots of time, as exp1 is very huge – Holger Mate Jul 21 '18 at 13:33
• Performance goals nor examples of the expressions were part of the original question. It's very annoying when people move the goalpost. Anyhow, everything will take a long time in a huge expression. – rhermans Jul 21 '18 at 13:36
• Please note that it was mentioned in the original question that, exp1 is very huge. – Holger Mate Jul 21 '18 at 13:37
• I've just tried to make the question more clear. I didn't changed it – Holger Mate Jul 21 '18 at 13:38

Your exp1 is built up in steps, e.g.:

a = rhs1;
b = rhs2;
c = rhs3;

exp1 = f[a, b, c];

I suggest using Series for each definition:

a = Series[rhs1, {t, 0, 5}];
b = Series[rhs2, {t, 0, 5}];
c = Series[rhs3, {t, 0, 5}];

exp1 = Series[f[a, b, c], {t, 0, 5}]

For example, doing this for AA1, AA2, AA3, AA5, AA6, AA7 yielded the series expression for AA4 in a reasonable amount of time, and I expect it might work for your full exp1 expression.