{ "hash": "6f158f6270a0622df9b3bbf516649f07", "result": { "markdown": "# Limits, issues, extensions of the concept\n\n\n\nThis section uses the following add-on packages:\n\n``` {.julia .cell-code}\nusing CalculusWithJulia\nusing Plots\nusing SymPy\n```\n\n\n\n\n---\n\n\nThe limit of a function at $c$ need not exist for one of many different reasons. Some of these reasons can be handled with extensions to the concept of the limit, others are just problematic in terms of limits. This section covers examples of each.\n\n\nLet's begin with a function that is just problematic. Consider\n\n\n\n$$\nf(x) = \\sin(1/x)\n$$\n\n\nAs this is a composition of nice functions it will have a limit everywhere except possibly when $x=0$, as then $1/x$ may not have a limit. So rather than talk about where it is nice, let's consider the question of whether a limit exists at $c=0$.\n\n\nA graph shows the issue:\n\n::: {.cell hold='true' execution_count=4}\n\n::: {.cell-output .cell-output-display execution_count=5}\n{}\n:::\n:::\n\n\nThe graph oscillates between $-1$ and $1$ infinitely many times on this interval - so many times, that no matter how close one zooms in, the graph on the screen will fail to capture them all. Graphically, there is no single value of $L$ that the function gets close to, as it varies between all the values in $[-1,1]$ as $x$ gets close to $0$. A simple proof that there is no limit, is to take any $\\epsilon$ less than $1$, then with any $\\delta > 0$, there are infinitely many $x$ values where $f(x)=1$ and infinitely many where $f(x) = -1$. That is, there is no $L$ with $|f(x) - L| < \\epsilon$ when $\\epsilon$ is less than $1$ for all $x$ near $0$.\n\n\nThis function basically has too many values it gets close to. Another favorite example of such a function is the function that is $0$ if $x$ is rational and $1$ if not. This function will have no limit anywhere, not just at $0$, and for basically the same reason as above.\n\n\nThe issue isn't oscillation though. Take, for example, the function $f(x) = x \\cdot \\sin(1/x)$. This function again has a limit everywhere save possibly $0$. But in this case, there is a limit at $0$ of $0$. This is because, the following is true:\n\n\n\n$$\n-|x| \\leq x \\sin(1/x) \\leq |x|.\n$$\n\n\nThe following figure illustrates:\n\n::: {.cell hold='true' execution_count=5}\n``` {.julia .cell-code}\nf(x) = x * sin(1/x)\nplot(f, -1, 1)\nplot!(abs)\nplot!(x -> -abs(x))\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n{}\n:::\n:::\n\n\nThe [squeeze](http://en.wikipedia.org/wiki/Squeeze_theorem) theorem of calculus is the formal reason $f$ has a limit at $0$, as as both the upper function, $|x|$, and the lower function, $-|x|$, have a limit of $0$ at $0$.\n\n\n## Right and left limits\n\n\nAnother example where $f(x)$ has no limit is the function $f(x) = x /|x|, x \\neq 0$. This function is $-1$ for negative $x$ and $1$ for positive $x$. Again, this function will have a limit everywhere except possibly at $x=0$, where division by $0$ is possible.\n\n\nIt's graph is\n\n::: {.cell hold='true' execution_count=6}\n``` {.julia .cell-code}\nf(x) = abs(x)/x\nplot(f, -2, 2)\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n{}\n:::\n:::\n\n\nThe sharp jump at $0$ is misleading - again, the plotting algorithm just connects the points, it doesn't handle what is a fundamental discontinuity well - the function is not defined at $0$ and jumps from $-1$ to $1$ there. Similarly to our example of $\\sin(1/x)$, near $0$ the function get's close to both $1$ and $-1$, so will have no limit. (Again, just take $\\epsilon$ smaller than $1$.)\n\n\nBut unlike the previous example, this function *would* have a limit if the definition didn't consider values of $x$ on both sides of $c$. The limit on the right side would be $1$, the limit on the left side would be $-1$. This distinction is useful, so there is an extension of the idea of a limit to *one-sided limits*.\n\n\nLet's loosen up the language in the definition of a limit to read:\n\n\n> The limit of $f(x)$ as $x$ approaches $c$ is $L$ if for every neighborhood, $V$, of $L$ there is a neighborhood, $U$, of $c$ for which $f(x)$ is in $V$ for every $x$ in $U$, except possibly $x=c$.\n\n\n\nThe $\\epsilon-\\delta$ definition has $V = (L-\\epsilon, L + \\epsilon)$ and $U=(c-\\delta, c+\\delta)$. This is a rewriting of $L-\\epsilon < f(x) < L + \\epsilon$ as $|f(x) - L| < \\epsilon$.\n\n\nNow for the defintion:\n\n\n> A function $f(x)$ has a limit on the right of $c$, written $\\lim_{x \\rightarrow c+}f(x) = L$ if for every $\\epsilon > 0$, there exists a $\\delta > 0$ such that whenever $0 < x - c < \\delta$ it holds that $|f(x) - L| < \\epsilon$. That is, $U$ is $(c, c+\\delta)$\n\n\n\nSimilarly, a limit on the left is defined where $U=(c-\\delta, c)$.\n\n\nThe `SymPy` function `limit` has a keyword argument `dir=\"+\"` or `dir=\"-\"` to request that a one-sided limit be formed. The default is `dir=\"+\"`. Passing `dir=\"+-\"` will compute both one side limits, and throw an error if the two are not equal, in agreement with no limit existing.\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\n@syms x\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n```\n(x,)\n```\n:::\n:::\n\n\n::: {.cell hold='true' execution_count=8}\n``` {.julia .cell-code}\nf(x) = abs(x)/x\nlimit(f(x), x=>0, dir=\"+\"), limit(f(x), x=>0, dir=\"-\")\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```\n(1, -1)\n```\n:::\n:::\n\n\n:::{.callout-warning}\n## Warning\nThat means the mathematical limit need not exist when `SymPy`'s `limit` returns an answer, as `SymPy` is only carrying out a one sided limit. Explicitly passing `dir=\"+-\"` or checking that both `limit(ex, x=>c)` and `limit(ex, x=>c, dir=\"-\")` are equal would be needed to confirm a limit exists mathematically.\n\n:::\n\nThe relation between the two concepts is that a function has a limit at $c$ if an only if the left and right limits exist and are equal. This function $f$ has both existing, but the two limits are not equal.\n\n\nThere are other such functions that jump. Another useful one is the floor function, which just rounds down to the nearest integer. A graph shows the basic shape:\n\n::: {.cell execution_count=9}\n``` {.julia .cell-code}\nplot(floor, -5,5)\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n{}\n:::\n:::\n\n\nAgain, the (nearly) vertical lines are an artifact of the graphing algorithm and not actual points that solve $y=f(x)$. The floor function has limits except at the integers. There the left and right limits differ.\n\n\nConsider the limit at $c=0$. If $0 < x < 1/2$, say, then $f(x) = 0$ as we round down, so the right limit will be $0$. However, if $-1/2 < x < 0$, then the $f(x) = -1$, again as we round down, so the left limit will be $-1$. Again, with this example both the left and right limits exists, but at the integer values they are not equal, as they differ by 1.\n\n\nSome functions only have one-sided limits as they are not defined in an interval around $c$. There are many examples, but we will take $f(x) = x^x$ and consider $c=0$. This function is not well defined for all $x < 0$, so it is typical to just take the domain to be $x > 0$. Still it has a right limit $\\lim_{x \\rightarrow 0+} x^x = 1$. `SymPy` can verify:\n\n::: {.cell execution_count=10}\n``` {.julia .cell-code}\nlimit(x^x, x, 0, dir=\"+\")\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n```{=html}\n \n\\[\n1\n\\]\n\n```\n:::\n:::\n\n\nThis agrees with the IEEE convention of assigning `0^0` to be `1`.\n\n\nHowever, not all such functions with indeterminate forms of $0^0$ will have a limit of $1$.\n\n\n##### Example\n\n\nConsider this funny graph:\n\n::: {.cell hold='true' execution_count=11}\n\n::: {.cell-output .cell-output-display execution_count=12}\n{}\n:::\n:::\n\n\nDescribe the limits at $-1$, $0$, and $1$.\n\n\n * At $-1$ we see a jump, there is no limit but instead a left limit of 1 and a right limit appearing to be $1/2$.\n * At $0$ we see a limit of $1$.\n * Finally, at $1$ again there is a jump, so no limit. Instead the left limit is about $-1$ and the right limit $1$.\n\n\n## Limits at infinity\n\n\nThe loose definition of a horizontal asymptote is \"a line such that the distance between the curve and the line approaches $0$ as they tend to infinity.\" This sounds like it should be defined by a limit. The issue is, that the limit would be at $\\pm\\infty$ and not some finite $c$. This requires the idea of a neighborhood of $c$, $0 < |x-c| < \\delta$ to be reworked.\n\n\nThe basic idea for a limit at $+\\infty$ is that for any $\\epsilon$, there exists an $M$ such that when $x > M$ it must be that $|f(x) - L| < \\epsilon$. For a horizontal asymptote, the line would be $y=L$. Similarly a limit at $-\\infty$ can be defined with $x < M$ being the condition.\n\n\nLet's consider some cases.\n\n\nThe function $f(x) = \\sin(x)$ will not have a limit at $+\\infty$ for exactly the same reason that $f(x) = \\sin(1/x)$ does not have a limit at $c=0$ - it just oscillates between $-1$ and $1$ so never eventually gets close to a single value.\n\n\n`SymPy` gives an odd answer here indicating the range of values:\n\n::: {.cell execution_count=12}\n``` {.julia .cell-code}\nlimit(sin(x), x => oo)\n```\n\n::: {.cell-output .cell-output-display execution_count=13}\n```{=html}\n \n\\[\n\\left\\langle -1, 1\\right\\rangle\n\\]\n\n```\n:::\n:::\n\n\n(We used `SymPy`'s `oo` for $\\infty$ and not `Inf`.)\n\n\n---\n\nHowever, a damped oscillation, such as $f(x) = e^{-x} \\sin(x)$ will have a limit:\n\n::: {.cell execution_count=13}\n``` {.julia .cell-code}\nlimit(exp(-x)*sin(x), x => oo)\n```\n\n::: {.cell-output .cell-output-display execution_count=14}\n```{=html}\n \n\\[\n0\n\\]\n\n```\n:::\n:::\n\n\n---\n\n\nWe have rational functions will have the expected limit. In this example $m = n$, so we get a horizontal asymptote that is not $y=0$:\n\n::: {.cell execution_count=14}\n``` {.julia .cell-code}\nlimit((x^2 - 2x +2)/(4x^2 + 3x - 2), x=>oo)\n```\n\n::: {.cell-output .cell-output-display execution_count=15}\n```{=html}\n \n\\[\n\\frac{1}{4}\n\\]\n\n```\n:::\n:::\n\n\n---\n\nThough rational functions can have only one (at most) horizontal asymptote, this isn't true for all functions. Consider the following $f(x) = x / \\sqrt{x^2 + 4}$. It has different limits depending if $x$ goes to $\\infty$ or negative $\\infty$:\n\n::: {.cell hold='true' execution_count=15}\n``` {.julia .cell-code}\nf(x) = x / sqrt(x^2 + 4)\nlimit(f(x), x=>oo), limit(f(x), x=>-oo)\n```\n\n::: {.cell-output .cell-output-display execution_count=16}\n```\n(1, -1)\n```\n:::\n:::\n\n\n(A simpler example showing this behavior is just the function $x/|x|$ considered earlier.)\n\n\n##### Example: Limits at infinity and right limits at $0$\n\n\nGiven a function $f$ the question of whether this exists:\n\n\n\n$$\n\\lim_{x \\rightarrow \\infty} f(x)\n$$\n\n\ncan be reduced to the question of whether this limit exists:\n\n\n\n$$\n\\lim_{x \\rightarrow 0+} f(1/x)\n$$\n\n\nSo whether $\\lim_{x \\rightarrow 0+} \\sin(1/x)$ exists is equivalent to whether $\\lim_{x\\rightarrow \\infty} \\sin(x)$ exists, which clearly does not due to the oscillatory nature of $\\sin(x)$.\n\n\nSimilarly, one can make this reduction\n\n\n\n$$\n\\lim_{x \\rightarrow c+} f(x) =\n\\lim_{x \\rightarrow 0+} f(c + x) =\n\\lim_{x \\rightarrow \\infty} f(c + \\frac{1}{x}).\n$$\n\n\nThat is, right limits can be analyzed as limits at $\\infty$ or right limits at $0$, should that prove more convenient.\n\n\n## Limits of infinity\n\n\nVertical asymptotes are nicely defined with horizontal asymptotes by the graph getting close to some line. However, the formal definition of a limit won't be the same. For a vertical asymptote, the value of $f(x)$ heads towards positive or negative infinity, not some finite $L$. As such, a neighborhood like $(L-\\epsilon, L+\\epsilon)$ will no longer make sense, rather we replace it with an expression like $(M, \\infty)$ or $(-\\infty, M)$. As in: the limit of $f(x)$ as $x$ approaches $c$ is *infinity* if for every $M > 0$ there exists a $\\delta>0$ such that if $0 < |x-c| < \\delta$ then $f(x) > M$. Approaching $-\\infty$ would conclude with $f(x) < -M$ for all $M>0$.\n\n\n##### Examples\n\n\nConsider the function $f(x) = 1/x^2$. This will have a limit at every point except possibly $0$, where division by $0$ is possible. In this case, there is a vertical asymptote, as seen in the following graph. The limit at $0$ is $\\infty$, in the extended sense above. For $M>0$, we can take any $0 < \\delta < 1/\\sqrt{M}$. The following graph shows $M=25$ where the function values are outside of the box, as $f(x) > M$ for those $x$ values with $0 < |x-0| < 1/\\sqrt{M}$.\n\n::: {.cell hold='true' execution_count=16}\n\n::: {.cell-output .cell-output-display execution_count=17}\n{}\n:::\n:::\n\n\n---\n\n\nThe function $f(x)=1/x$ requires us to talk about left and right limits of infinity, with the natural generalization. We can see that the left limit at $0$ is $-\\infty$ and the right limit $\\infty$:\n\n::: {.cell hold='true' execution_count=17}\n\n::: {.cell-output .cell-output-display execution_count=18}\n{}\n:::\n:::\n\n\n`SymPy` agrees:\n\n::: {.cell hold='true' execution_count=18}\n``` {.julia .cell-code}\nf(x) = 1/x\nlimit(f(x), x=>0, dir=\"-\"), limit(f(x), x=>0, dir=\"+\")\n```\n\n::: {.cell-output .cell-output-display execution_count=19}\n```\n(-oo, oo)\n```\n:::\n:::\n\n\n---\n\nConsider the function $g(x) = x^x(1 + \\log(x)), x > 0$. Does this have a *right* limit at $0$?\n\n\nA quick graph shows that a limit may be $-\\infty$:\n\n::: {.cell execution_count=19}\n``` {.julia .cell-code}\ng(x) = x^x * (1 + log(x))\nplot(g, 1/100, 1)\n```\n\n::: {.cell-output .cell-output-display execution_count=20}\n{}\n:::\n:::\n\n\nWe can check with `SymPy`:\n\n::: {.cell execution_count=20}\n``` {.julia .cell-code}\nlimit(g(x), x=>0, dir=\"+\")\n```\n\n::: {.cell-output .cell-output-display execution_count=21}\n```{=html}\n \n\\[\n-\\infty\n\\]\n\n```\n:::\n:::\n\n\n## Limits of sequences\n\n\nAfter all this, we still can't formalize the basic question asked in the introduction to limits: what is the area contained in a parabola. For that we developed a sequence of sums: $s_n = 1/2 \\dot((1/4)^0 + (1/4)^1 + (1/4)^2 + \\cdots + (1/4)^n)$. This isn't a function of $x$, but rather depends only on non-negative integer values of $n$. However, the same idea as a limit at infinity can be used to define a limit.\n\n\n> Let $a_0,a_1, a_2, \\dots, a_n, \\dots$ be a sequence of values indexed by $n$. We have $\\lim_{n \\rightarrow \\infty} a_n = L$ if for every $\\epsilon > 0$ there exists an $M>0$ where if $n > M$ then $|a_n - L| < \\epsilon$.\n\n\n\nCommon language is the sequence *converges* when the limit exists and otherwise *diverges*.\n\n\nThe above is essentially the same as a limit *at* infinity for a function, but in this case the function's domain is only the non-negative integers.\n\n\n`SymPy` is happy to compute limits of sequences. Defining this one involving a sum is best done with the `summation` function:\n\n::: {.cell execution_count=21}\n``` {.julia .cell-code}\n@syms i::integer n::(integer, positive)\ns(n) = 1//2 * summation((1//4)^i, (i, 0, n)) # rationals make for an exact answer\nlimit(s(n), n=>oo)\n```\n\n::: {.cell-output .cell-output-display execution_count=22}\n```{=html}\n \n\\[\n\\frac{2}{3}\n\\]\n\n```\n:::\n:::\n\n\n##### Example\n\n\nThe limit\n\n\n\n$$\n\\lim_{x \\rightarrow 0} \\frac{e^x - 1}{x} = 1,\n$$\n\n\nis an important limit. Using the definition of $e^x$ by an infinite sequence:\n\n\n\n$$\ne^x = \\lim_{n \\rightarrow \\infty} (1 + \\frac{x}{n})^n,\n$$\n\n\nwe can establish the limit using the squeeze theorem. First,\n\n\n\n$$\nA = |(1 + \\frac{x}{n})^n - 1 - x| = |\\Sigma_{k=0}^n {n \\choose k}(\\frac{x}{n})^k - 1 - x| = |\\Sigma_{k=2}^n {n \\choose k}(\\frac{x}{n})^k|,\n$$\n\n\nthe first two sums cancelling off. The above comes from the binomial expansion theorem for a polynomial. Now ${n \\choose k} \\leq n^k$so we have\n\n\n\n$$\nA \\leq \\Sigma_{k=2}^n |x|^k = |x|^2 \\frac{1 - |x|^{n+1}}{1 - |x|} \\leq\n\\frac{|x|^2}{1 - |x|}.\n$$\n\n\nusing the *geometric* sum formula with $x \\approx 0$ (and not $1$):\n\n::: {.cell hold='true' execution_count=22}\n``` {.julia .cell-code}\n@syms x n i\nsummation(x^i, (i,0,n))\n```\n\n::: {.cell-output .cell-output-display execution_count=23}\n```{=html}\n \n\\[\n\\begin{cases} n + 1 & \\text{for}\\: x = 1 \\\\\\frac{1 - x^{n + 1}}{1 - x} & \\text{otherwise} \\end{cases}\n\\]\n\n```\n:::\n:::\n\n\nAs this holds for all $n$, as $n$ goes to $\\infty$ we have:\n\n\n\n$$\n|e^x - 1 - x| \\leq \\frac{|x|^2}{1 - |x|}\n$$\n\n\nDividing both sides by $x$ and noting that as $x \\rightarrow 0$, $|x|/(1-|x|)$ goes to $0$ by continuity, the squeeze theorem gives the limit:\n\n\n\n$$\n\\lim_{x \\rightarrow 0} \\frac{e^x -1}{x} - 1 = 0.\n$$\n\n\nThat ${n \\choose k} \\leq n^k$ can be viewed as the left side counts the number of combinations of $k$ choices from $n$ distinct items, which is less than the number of permutations of $k$ choices, which is less than the number of choices of $k$ items from $n$ distinct ones without replacement – what $n^k$ counts.\n\n\n### Some limit theorems for sequences\n\n\nThe limit discussion first defined limits of scalar univariate functions at a point $c$ and then added generalizations. The pedagogical approach can be reversed by starting the discussion with limits of sequences and then generalizing from there. This approach relies on a few theorems to be gathered along the way that are mentioned here for the curious reader:\n\n\n * Convergent sequences are bounded.\n * All *bounded* monotone sequences converge.\n * Every bounded sequence has a convergent subsequence. (Bolzano-Weirstrass)\n * The limit of $f$ at $c$ exists and equals $L$ if and only if for *every* sequence $x_n$ in the domain of $f$ converging to $c$ the sequence $s_n = f(x_n)$ converges to $L$.\n\n\n## Summary\n\n\nThe following table captures the various changes to the definition of the limit to accommodate some of the possible behaviors.\n\n::: {.cell execution_count=23}\n\n::: {.cell-output .cell-output-display execution_count=24}\n```{=html}\n\n
| Type | Notation | V | U |
|---|---|---|---|
limit \n | \\(\\lim_{x\\rightarrow c}f(x) = L\\)\n | \\((L-\\epsilon, L+\\epsilon)\\)\n | \\((c - \\delta, c+\\delta)\\)\n |
right limit \n | \\(\\lim_{x\\rightarrow c+}f(x) = L\\)\n | \\((L-\\epsilon, L+\\epsilon)\\)\n | \\((c, c+\\delta)\\)\n |
left limit \n | \\(\\lim_{x\\rightarrow c-}f(x) = L\\)\n | \\((L-\\epsilon, L+\\epsilon)\\)\n | \\((c - \\delta, c)\\)\n |
limit at \\(\\infty\\) \n | \\(\\lim_{x\\rightarrow \\infty}f(x) = L\\)\n | \\((L-\\epsilon, L+\\epsilon)\\)\n | \\((M, \\infty)\\)\n |
limit at \\(-\\infty\\) \n | \\(\\lim_{x\\rightarrow -\\infty}f(x) = L\\)\n | \\((L-\\epsilon, L+\\epsilon)\\)\n | \\((-\\infty, M)\\)\n |
limit of \\(\\infty\\) \n | \\(\\lim_{x\\rightarrow c}f(x) = \\infty\\)\n | \\((M, \\infty)\\)\n | \\((c - \\delta, c+\\delta)\\)\n |
limit of \\(-\\infty\\) \n | \\(\\lim_{x\\rightarrow c}f(x) = -\\infty\\)\n | \\((-\\infty, M)\\)\n | \\((c - \\delta, c+\\delta)\\)\n |
limit of a sequence \n | \\(\\lim_{n \\rightarrow \\infty} a_n = L\\)\n | \\((L-\\epsilon, L+\\epsilon)\\)\n | \\((M, \\infty)\\)\n |