3
$\begingroup$

I want the limit of a function to only evaluate if both the left and right hand side are equal. For example $\lim _{x\to 0}\left(\frac{1}{x}\right)$ doesn't exist(two sided limit). However, the right side is $\lim _{x\to 0+}\left(\frac{1}{x}\right)=\infty $ and the left side is $\lim _{x\to 0-}\left(\frac{1}{x}\right)=-\infty $. I want to create it, so:Limit[1/x, x -> 0] gives me does not exist, instead of $\infty$ which is only the right side limit!

enter image description here

How can I archive this?

enter image description here

This is what the graph looks like:

enter image description here

PS: I am new to Mathematica and tried to find it in the documentations, however, all I found was I can specify Direction -> to 1 or -1, but there was no 0 for it checking both sides and returning a value only if both sides are equal.

$\endgroup$
6
$\begingroup$

Limit can actually approach a value from any direction in the complex plane. For instance Limit[__, Direction -> I] is valid.

To have a bidirectional limit along the real line, you'll have to implement it yourself. Something like this should work pretty well I think.

Basically just take limits in both directions and make sure they equal.

$NonNumericPattern = ComplexInfinity | _DirectedInfinity | _Interval | 
  Undefined | Indeterminate;

equalQ[l : $NonNumericPattern, r_, ___] := l == r
equalQ[l_, r : $NonNumericPattern, ___] := l == r
equalQ[l_, r_, assum_: True] := PossibleZeroQ[l - r, Assumptions -> assum]

Options[RealLimit] = FilterRules[Options[Limit], Except[Direction]];

RealLimit[expr_, x_ -> a_, ops : OptionsPattern[]] := 
  Block[{llim, rlim},

    llim = Limit[expr, x -> a, ops, Direction -> 1];
    rlim = Limit[expr, x -> a, ops, Direction -> -1];

    ConditionalExpression[rlim, equalQ[llim, rlim, OptionValue[Assumptions]]]
  ]

RealLimit[1/x, x -> 0]
Undefined

Edit

Since version 11.2, Limit is bidirectional over the reals by default:

$VersionNumber
11.2
Limit[1/x, x -> 0]
Indeterminate
$\endgroup$
  • $\begingroup$ Cool, I am new to mathematica + calculus and this is really helpful. I really appreciate taking the time to write all this code to fit my needs exactly. I am very grateful, thanks a lot!!! I still have to learn how to write my own functions like this in mathematica, but thanks for the help. $\endgroup$ – James Smith Nov 29 '15 at 20:07
  • $\begingroup$ Is there anyway to append this into a built in function within my version of mathematica or make it so when I create a new notebook that it automatically runs the code to define "RealLimit"? $\endgroup$ – James Smith Nov 29 '15 at 20:16
  • 3
    $\begingroup$ @JamesSmith Yes, though it's a bit of a hack. First in Mma, run FileNameJoin[{$BaseDirectory, "Kernel", "init.m"}]. Locate this file on your machine and open it. Next, paste Notation`AutoLoadNotationPalette = False; Needs["Notation`"]; Notation[ParsedBoxWrapper[RowBox[{"Limit", "[", "args_", "]"}]]\[DoubleLongRightArrow]ParsedBoxWrapper[RowBox[{"RealLimit", "[", "args_", "]"}]]], paste the code for RealLimit, and save the file. Now quit Mma and reopen. Now every time you type Limit[...], Mathematica will parse it as RealLimit[...]. Let me know if you have any troubles. $\endgroup$ – Chip Hurst Nov 29 '15 at 20:31
  • $\begingroup$ Got it. Thanks again. You are the best. $\endgroup$ – James Smith Nov 29 '15 at 20:38

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.