Evaluate Limit only if both directions(sides) are equal? E.g. $\lim\limits_{x\to 0}\left(\frac{1}{x}\right)=\text{DNE}$

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! How can I archive this? This is what the graph looks like: 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.

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
• 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. – James Smith Nov 29 '15 at 20:07
• 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"? – James Smith Nov 29 '15 at 20:16
• @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 NotationAutoLoadNotationPalette = 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. – Chip Hurst Nov 29 '15 at 20:31
• Got it. Thanks again. You are the best. – James Smith Nov 29 '15 at 20:38