3
$\begingroup$

This question already has an answer here:

I would like to imply Series to a list of experssions in such a way so that it expands each element of the list to the lowest non-trivial order

Example

ld={1/r, (r^2 + 4 y^2)/(4 - 2 M r + r^2)^2, 0, 4 - 4 y^2}

and what I want to do in an easy way is

Normal@{Series[ld[[1]], {r, Infinity, 1}], 
  Series[ld[[2]], {r, Infinity, 2}], 
  Series[ld[[3]], {r, Infinity, 0}], 
  Series[ld[[4]], {r, Infinity, 0}]}

which produces

{1/r, 1/r^2, 0, 4 - 4 y^2}
$\endgroup$

marked as duplicate by Carl Woll, m_goldberg, MarcoB, LCarvalho, Michael Seifert Aug 9 '17 at 16:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ See also the elegant method (posted by an incredibly modest user) in Series with a specified number of terms. $\endgroup$ – Michael Seifert Aug 9 '17 at 15:52
  • $\begingroup$ Hahah, I like that answer too. The titles of the questions made me believe they are not related, even though I saw them $\endgroup$ – ThunderBiggi Aug 10 '17 at 12:13
3
$\begingroup$

Often times it's most straightforward in Mathematica to start by automating exactly what you would do by hand, then see what type of adverse use-cases pop up.

In this case, you could try the lowest order and work up. Series expand to the $n$-th order with $n=0$. See if it worked and, if not, increasing n++ until you get somewhere.

Something like this:

    firstNTSeries[expr_, {var_, var0_}] := Module[{n = 0, res}, 
            res =expr;
            While[expr =!= 0 && 
               Normal[res = Series[expr, {var, var0, n}]] === 0,
            n++]; 
            res // Normal]

Usage:

    firstNTSeries[#, {r, \[Infinity]}] & /@ ld

If you're getting bogged down by speed, (consider above applied to $(r^{10^{13}}+r^{10^{14}})^{-1}$), you can optimize at the cost of trusting Series' ability to guess the first nontrivial step. I.e. use the output of Series to change how fast you should be advancing $n$. Something like:

    firstNTSeriesV2[expr_, {var_, var0_}] := 
          Module[{n = 0, res}, 
            res = expr;
            While[expr =!= 0 && 
                Normal[res = Series[expr, {var, var0, n}]] === 0,
                n = res[[5]]; 
            ]; 
            res // Normal
          ]
$\endgroup$
  • $\begingroup$ Thank you very much, I was thinking of doing something like that, but with If checks and it looked too cumbersome $\endgroup$ – ThunderBiggi Aug 9 '17 at 10:53
1
$\begingroup$

How about

ld = {1/r, (r^2 + 4 y^2)/(4 - 2 M r + r^2)^2, 0, 4 - 4 y^2};
MapThread[Normal[Series[#1, {r, ∞, #2}]] &, {ld, {1, 2, 0, 0}}]

{1/r, 1/r^2, 0, 4 - 4 y^2}

$\endgroup$
  • $\begingroup$ Maybe I haven't expressed myself clearly, but the example I gave is random, in reality I want something that will not require me to type by hand the orders (which I wouldn't know anyway). $\endgroup$ – ThunderBiggi Aug 10 '17 at 12:12
1
$\begingroup$
powerlist = Map[Exponent[RootReduce[#], r] &, ld] /.{ -\[Infinity] -> 0,, _?Negative -> 1}
MapThread[Normal[Series[#1, {r, Infinity, #2}]] &, {ld, powerlist}]
$\endgroup$

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