1
$\begingroup$

Suppose I have an expression of x. Now I want to somehow evaluate its "limit" at x->Infinity, but in such a way that the terms that infinite were left unevaluated rather than replaced with infinity sign? Is this possible?

For instance,

$2-\frac{e^{x }+1}{x +1}\to 2-\frac{e^{x }}{x +1}$

$\endgroup$
8
  • $\begingroup$ Mathematically this is ambiguous. Symbolically at least for this simple example you can try limitHold[direction_][expr_]:=Module[{lim=Limit[expr,direction]},If[lim==Infinity,Unevaluated@expr,lim]], then limitHold[x->Infinity]/@Expand[(Exp@x+1)/(x+1)+2] gives the desired result. $\endgroup$
    – Lacia
    Aug 12, 2022 at 0:45
  • $\begingroup$ @lilyric hmmm, tried this on Log[x + 1]/Log[x] and got zero (expected one) $\endgroup$
    – Anixx
    Aug 12, 2022 at 0:50
  • $\begingroup$ This is because Log[x + 1]/Log[x] has only one term, and you need replace /@ by @. The original example contains three terms, so I use Map /@ so that limitHold acts on each single term and then they get added together. $\endgroup$
    – Lacia
    Aug 12, 2022 at 0:54
  • 1
    $\begingroup$ This ad hoc method depends on which function is symbolically "simpler" than others. You may treat $e^x$ as simpler than $e^x+1$, but mathematically they are equally analytic functions. $\endgroup$
    – Lacia
    Aug 12, 2022 at 0:56
  • $\begingroup$ @lilyric here are some more examples of what I want: mathoverflow.net/questions/427516/… $\endgroup$
    – Anixx
    Aug 12, 2022 at 0:58

2 Answers 2

1
$\begingroup$
expression = 2 - (1 + E^x)/(1 + x);

TL;DR : Try automatically mapping Asymptotic to sub expressions until one of the results fits your criteria.

Code

(code explanation after discussion below)

Note : …=\[Ellipsis]

sub…expressions = 
  DeleteDuplicates@Cases[expression, _, All];

(sub…expressions
     // Map[(expression /. # -> Asymptotic[#, x -> Infinity]) &]
    // DeleteDuplicates
   // DeleteCases[expression]
  // Select[Limit[# - expression, x -> Infinity] == 0 &]
 )

$$ \left\{2-\frac{e^x}{x+1}\right\} $$

EDIT : The following code might be faster and might handle better expressions that depend on multiple variables. This modification is not included in the explanation section below.

sub…expressions =
 DeleteDuplicates@
  DeleteCases[x]@Cases[expression, _?(Not@*FreeQ[x]), {1, Infinity}]

asymptotic[expression_, sub…expression_, var_, limit_] :=
 expression /. 
  sub…expression :> 
   Asymptotic[sub…expression, x -> limit]

j=1;

While[approximation=
        asymptotic[expression
                ,
                sub…expressions[[j]]
                ,
                x
                ,
                Infinity
                ]
    ;
    j++
    ;
    approximation===expression ∨
    Not[Limit[approximation-expression,x->Infinity]===0]
]
approximation

Discussion

(code section below)

It seems that Asymptotic replaces every part of the expression with it's approximation which is similar to the behavior of ReplaceAll. The problem is then controlling how the replacements occur. Such a problem may occur with ReplaceAll as well.

There are different techniques to gain control on how replacements occur and they may be applied to this problem. For example, using ReplaceAt or MapAt and Asymptotic to control where the transformations occur depending on their position or using pattern matching on sub expressions.

If the expression is not too large we can just try everything and select the ones that give the result we want. An alternative would require some sort of smart algorithm that is aware of the expression as a whole and that applies Asymptotic at the right parts based on a criteria from the user. That seems rather complicated (albeit an artificial neural network might find a pattern) so for now it might be significantly easier to just try everything and select the results that satisfy the criteria. A simplified version of that is what the code below does.

Code explanation

Find sub expressions:

Note : …=\[Ellipsis]

sub…expressions = 
  DeleteDuplicates@Cases[2 - (1 + E^x)/(1 + x), _, All];

$$\left\{2,-1,1,e,x,e^x,e^x+1,x+1,\frac{1}{x+1},-\frac{e^x+1}{x+1},2-\frac{e^x+1}{x+1}\right\}$$

To visualize what will follow, consider applying a function h with no definition:

formal…list = (expression /. # -> h[#]) & /@ 
  sub…expressions

$$ \left\{h(2)-\frac{e^x+1}{x+1},h(-1) \left(e^x+1\right) (x+1)^{h(-1)}+2,2-\frac{h(1)+e^x}{h(1)+x},2-\frac{h(e)^x+1}{x+1},2-\frac{e^{h(x)}+1}{h(x)+1},2-\frac{h\left(e^x\right)+1}{x+1},2-\frac{h\left(e^x+1\right)}{x+1},2-\frac{e^x+1}{h(x+1)},2-\left(e^x+1\right) h\left(\frac{1}{x+1}\right),h\left(-\frac{e^x+1}{x+1}\right)+2\right\} $$

Note that not all combinations of applications of h are present. For every element in sub…expressions, every occurrence of that element in the original expression is replaced by h[element] at the same time via the replacement rule. This makes the computation a bit faster than trying all possible combinations but it might discard combinations that were the right combinations to consider. In the following, the above subset will be sufficient however if more combinations are needed we could use:

ReplaceAt[expression, b_ :> h[b], #] & /@ 
 Position[expression, _, Heads -> False] 

Below h is replaced with Asymptotic using the desired limit :

asymptotic…list = 
 formal…list /. h -> (Asymptotic[#, x -> Infinity] &) // 
   DeleteDuplicates // DeleteCases[expression]

$$\left\{2-\frac{e^x}{x+1},2-\frac{e^x+1}{x},2-\frac{e^x}{x}\right\}$$

Now choose the approximation such that expression-approximation goes to zero in the desired limit:

Select[asymptotic…list, 
 Limit[# - expression, x -> Infinity] == 0 &]

$$ \left\{2-\frac{e^x}{x+1}\right\} $$

Note: I used Limit but in my experience Limit is rather slow.Series[# - expression,{x,Infinity,0}]//Normal does not seem to be sufficient with the exponential term.

$\endgroup$
0
$\begingroup$
$Version

(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)

Clear["Global`*"]

f[x_] := 2 - (E^x + 1)/(x + 1)

asym[x_] = Asymptotic[f[x], x -> Infinity]

(* -(E^x/x) *)

LogLogPlot[{-f[x], -asym[x]}, {x, 1, 30},
 PlotStyle -> {Automatic, Dashed},
 PlotLegends -> Placed["Expressions", {.4, .7}]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Well, for $2-\frac{e^{x }+1}{x +1}$ it gives asymptotic $-\frac{e^{x }}{x }$ and the difference between the original function and the asymptotic grows (and grows exponentially). So I need something similar to asymptotic but with difference going to zero. $\endgroup$
    – Anixx
    Jul 12, 2022 at 21:04
  • $\begingroup$ Presumably what you want is for the relative error to go to zero, i.e., Limit[(f[x] - asym[x])/f[x], x -> Infinity] (which it does). $\endgroup$
    – Bob Hanlon
    Jul 12, 2022 at 21:31
  • $\begingroup$ No I want absolute error going to zero. $\endgroup$
    – Anixx
    Jul 12, 2022 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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