using CalculusWithJuliaSquared
plotly()18 Continuity
This section uses the following add-on package:
CalculusWithJuliaSquared re-exports Plots and Symbolics, so neither needs a using of its own, and it loads Nemo for us, which is what lets symbolic_solve handle polynomial equations. Limits are taken with symlim, which returns the value and the route it took — and in this section the route is the point: one of them is the definition of continuity, computed.

The definition Google finds for continuous is forming an unbroken whole; without interruption.
The concept in calculus, as transferred to functions, is similar. Roughly speaking, a continuous function is one whose graph could be drawn without having to lift (or interrupt) the pencil drawing it.
Consider these two graphs:
and
Though similar at some level - they agree at nearly every value of \(x\) - the first has a “jump” from \(-1\) to \(1\) instead of the transition in the second one. The first is not continuous at \(0\) - a break is needed to draw it - whereas the second is continuous.
A formal definition of continuity was a bit harder to come about. At first the concept was that for any \(y\) between any two values in the range for \(f(x)\), the function should take on the value \(y\) for some \(x\). Clearly this could distinguish the two graphs above, as one takes no values in \((-1,1)\), whereas the other - the continuous one - takes on all values in that range.
However, Cauchy defined continuity by \(f(x + \alpha) - f(x)\) being small whenever \(\alpha\) was small. This basically rules out “jumps” and proves more useful as a tool to describe continuity.
The modern definition simply pushes the details to the definition of the limit:
The definition says three things
- The limit exists at \(c\).
- The function is defined at \(c\) (\(c\) is in the domain).
- The value of the limit is the same as \(f(c)\).
The definition speaks to continuity at a point, we can extend it to continuity over an interval \((a,b)\) by saying:
Finally, as with limits, it can be convenient to speak of right continuity and left continuity at a point, where the limit in the definition is replaced by a right or left limit, as appropriate.
In particular, a function is continuous over \([a,b]\) if it is continuous on \((a,b)\), left continuous at \(b\) and right continuous at \(a\).
The limit in the definition of continuity is the basic limit and not an extended sense where infinities are accounted for.
Examples of continuity
Most familiar functions are continuous everywhere.
- For example, a monomial function \(f(x) = ax^n\) for non-negative, integer \(n\) will be continuous. This is because the limit exists everywhere, the domain of \(f\) is all \(x\) and there are no jumps.
- Similarly, the building-block trigonometric functions \(\sin(x)\), \(\cos(x)\) are continuous everywhere.
- So are the exponential functions \(f(x) = a^x, a > 0\).
- The hyperbolic sine (\((e^x - e^{-x})/2\)) and cosine (\((e^x + e^{-x})/2\)) are, as \(e^x\) is.
- The hyperbolic tangent is, as \(\cosh(x) > 0\) for all \(x\).
Some familiar functions are mostly continuous but not everywhere.
- For example, \(f(x) = \sqrt{x}\) is continuous on \((0,\infty)\) and right continuous at \(0\), but it is not defined for negative \(x\), so can’t possibly be continuous there.
- Similarly, \(f(x) = \log(x)\) is continuous on \((0,\infty)\), but it is not defined at \(x=0\), so is not right continuous at \(0\).
- The tangent function \(\tan(x) = \sin(x)/\cos(x)\) is continuous everywhere except the points \(x\) with \(\cos(x) = 0\) (\(\pi/2 + k\pi, k\) an integer).
- The hyperbolic co-tangent is not continuous at \(x=0\) – when \(\sinh\) is \(0\),
- The semicircle \(f(x) = \sqrt{1 - x^2}\) is continuous on \((-1, 1)\). It is not continuous at \(-1\) and \(1\), though it is right continuous at \(-1\) and left continuous at \(1\). (It is continuous on \([-1,1]\).)
Examples of discontinuity
There are various reasons why a function may not be continuous.
- The function \(f(x) = \sin(x)/x\) has a limit at \(0\) but is not defined at \(0\), so is not continuous at \(0\). The function can be redefined to make it continuous.
- The function \(f(x) = 1/x\) is continuous everywhere except \(x=0\) where no limit exists.
- A rational function \(f(x) = p(x)/q(x)\) will be continuous everywhere except where \(q(x)=0\). (The function \(f\) may still have a limit where \(q\) is \(0\), should factors cancel, but \(f\) won’t be defined at such values.)
- The function
\[ f(x) = \begin{cases} -1 &~ x < 0 \\ 0 &~ x = 0 \\ 1 &~ x > 0 \end{cases} \]
is implemented by Julia’s sign function. It has a value at \(0\), but no limit at \(0\), so is not continuous at \(0\). Furthermore, the left and right limits exist at \(0\) but are not equal to \(f(0)\) so the function is not left or right continuous at \(0\). It is continuous everywhere except at \(x=0\).
- Similarly, the function defined by this graph
is not continuous at \(x=0\). It has a limit of \(0\) at \(0\), a function value \(f(0) =1/2\), but the limit and the function value are not equal.
- The
floorfunction, which rounds down to the nearest integer, is also not continuous at the integers, but is right continuous at the integers, as, for example, \(\lim_{x \rightarrow 0+} f(x) = f(0)\). This graph emphasizes the right continuity by placing a filled marker for the value of the function when there is a jump and an open marker where the function is not that value.
- The function \(f(x) = 1/x^2\) is not continuous at \(x=0\): \(f(x)\) is not defined at \(x=0\) and \(f(x)\) has no limit at \(x=0\) (in the usual sense).
- On the Wikipedia page for continuity the example of Dirichlet’s function is given:
\[ f(x) = \begin{cases} 0 &~ \text{if } x \text{ is irrational,}\\ 1 &~ \text{if } x \text{ is rational.} \end{cases} \]
The limit for any \(c\) is discontinuous, as any interval about \(c\) will contain both rational and irrational numbers so the function will not take values in a small neighborhood around any potential \(L\).
18.0.1 Continuity, read off the route
Every example above was settled in prose. symlim can settle most of them, and the way it reports its answer says which kind of discontinuity it met. The :substitution route fires only when two things hold: the expression evaluates to a finite number at \(c\), and that number agrees with the numeric evidence gathered on the way in to \(c\). Compare that with the definition: the value \(f(c)\) exists, the limit exists, and they are equal. A :substitution answer is continuity at \(c\), computed (within the tolerance of the numeric cross-check, which is why the definition is stated in words and the route is evidence for it, not a proof). Every other route means substitution was tried first and declined — the limit exists, but \(f\) was not usable at \(c\).
The function \(\sin(x)/x\) has a limit at \(0\) but no value there:
@variables x
symlim(sin(x)/x, x, 0)(1//1, :series)
:series rather than :substitution: a limit, reached without ever evaluating at \(0\) — the signature of a removable singularity. The function \(1/x\) has no limit at \(0\):
symlim(1/x, x, 0)(nothing, :sides_disagree)
A refusal, with the reason. :sides_disagree says both one-sided limits exist and differ — here \(-\infty\) and \(+\infty\). That is also what sign looks like, the jump from \(-1\) to \(1\):
symlim(sign(x), x, 0)(nothing, :sides_disagree)
symlim(sign(x), x, 0; side = :right), symlim(sign(x), x, 0; side = :left)((1, :squeeze), (-1, :squeeze))
The one-sided limits are \(1\) and \(-1\); neither is \(\text{sign}(0) = 0\), so sign is neither left nor right continuous at \(0\), exactly as the bullet above says. The route for those two is :squeeze: on a box that excludes \(0\) itself, sign is constant, and interval arithmetic encloses it exactly. Compare \(1/x^2\), which is not a jump but a pole:
symlim(1/x^2, x, 0)(Inf, :divergent_numeric)
:divergent_numeric — the values grow without bound, on both sides in the same direction. The floor function is the interesting one, because it is continuous from one side only:
symlim(floor(x), x, 0; side = :right), symlim(floor(x), x, 0; side = :left)((0, :substitution), (-1, :squeeze))
From the right, :substitution: the limit is \(\lfloor 0 \rfloor = 0\), found by evaluating — right continuity, which is what the plot with the filled and open markers shows. From the left the limit is \(-1\), found by bounding, and it is not the value at \(0\): not left continuous. The route difference is the one-sidedness.
So the reader has a procedure for any function they meet, not just these: take symlim; :substitution means continuous there; :sides_disagree means a jump (ask each side to see the two values); :divergent_numeric means an infinite discontinuity; any other route that returns a value means the limit exists but the function is not defined there. Ask for side = :left or :right to test one-sided continuity.
Example
Let a function be defined by cases:
\[ f(x) = \begin{cases} 3x^2 + c &~ x \geq 0,\\ 2x-3 &~ x < 0. \end{cases} \]
What value of \(c\) will make \(f(x)\) a continuous function?
We note that for \(x < 0\) and for \(x > 0\) the function is defined by a simple polynomial, so is continuous. At \(x=0\) to be continuous we need a limit to exists and be equal to \(f(0)\), which is \(c\). A limit exists if the left and right limits are equal. This means we need to solve for \(c\) to make the left and right limits equal. We do this next with a bit of overkill in this case. The right piece is the one that carries \(c\):
@variables x c
ex1 = 3x^2 + c
ex2 = 2x - 3
symlim(ex1, x, 0; side = :right)(c, :substitution)
The answer is \(c\) itself, by :substitution: the parameter rides through the limit as a symbol, which is exactly what we want — we are about to solve for it. The left piece:
symlim(ex2, x, 0; side = :left)(-3, :substitution)
Both routes are :substitution. That is the statement that each piece is continuous up to the junction, so its one-sided limit is just its value there — which is the remark made in words below. Their difference is what has to vanish:
del = symlim(ex1, x, 0; side = :right)[1] - symlim(ex2, x, 0; side = :left)[1]We need to solve for \(c\) to make del zero. This is a polynomial equation in \(c\) — a linear one — and symbolic_solve is the tool for polynomial equations. It returns a vector of roots; a linear equation has exactly one, and only says so:
only(symbolic_solve(del ~ 0, c))-3
This gives the value of \(c\).
This is a bit fussier than need be. As the left and right pieces (say, \(f_l\) and \(f_r\)) as both are polynomials are continuous everywhere, so would have left and right limits given through evaluation. Solving for c as follows is enough:
only(symbolic_solve(substitute(ex1, x => 0) ~ substitute(ex2, x => 0), c))-3
Example
Identifying from its graph that a function is discontinuous or not can be complicated by the graphing algorithm which simply connects adjacent points with a line segment allowing the eye to fill in the dot-to-dot graphic as a curve. The default plot of the floor function shows a potential issue:
plot(floor, -5/2, 5/2; label=false)The “risers” on the steps are an artifact of the basic dot-to-dot algorithm, which assumes continuity between adjacent points (we were more careful in our earlier plot of this function).
The following simple function just plots a bunch of points, leaving the eye to fill in the line, though so many points are chosen this doesn’t require much effort for simple cases. This function also plots a point on the \(x\)- and \(y\)-axes (emphasized by the argument framestyle=:origin) for each point graphed to emphasize the range of \(y\) values for the specified \(x\) values.
function pixel_plot(f, a, b; kwargs...)
xs = range(a, b, 801) # lots of points
ys = f.(xs)
zs = zero.(xs)
p = plot(;framestyle=:origin, legend=false, kwargs...)
scatter!(p, xs, ys; marker=(:square, :black, 1)) # f(x)
scatter!(p, xs, zs; marker=(:square, :blue, 2, 0.03)) # domain, [a,b]
scatter!(p, zs, ys; marker=(:square, :red, 3, 0.25)) # range
p
end
pixel_plot(floor, -5/2, 5/2)The broken up range suggests a fundamentally discontinuous function. In the next section we will see this differently—that a continuous function will have an unbroken range when restricted to some interval \([a,b]\).
For one more example, here we see the difference between sin and sign, as functions:
p1 = pixel_plot(sin, -pi, pi; title="sin")
p2 = pixel_plot(sign, -pi, pi; title="sign")
plot(p1, p2)The continuous sin function has an unbroken range, \([-1,1]\); the discontinuous sign function has a broken range consisting of \({-1, 0, 1}\).
18.1 Rules for continuity
As we’ve seen, functions can be combined in several ways. How do these relate with continuity?
Suppose \(f(x)\) and \(g(x)\) are both continuous on \(I\). Then:
- The linear combination \(h(x) = a f(x) + b g(x)\) is continuous on \(I\) for any real numbers \(a\) and \(b\);
- The product \(h(x) = f(x) \cdot g(x)\) is continuous on \(I\); and
- The quotient \(h(x) = f(x) / g(x)\) is continuous at all points \(c\) in \(I\) where \(g(c) \neq 0\).
- The composition \(h(x) = f(g(x))\) is continuous at \(x=c\) if \(g(x)\) is continuous at \(c\) and \(f(x)\) is continuous at \(g(c)\).
So, continuity is preserved for all of the basic operations except when dividing by \(0\).
Examples
- Since a monomial \(f(x) = ax^n\) (\(n\) a non-negative integer) is continuous, by the first rule, any polynomial will be continuous.
- Since both \(f(x) = e^x\) and \(g(x)=\sin(x)\) are continuous everywhere, so will be \(h(x) = e^x \cdot \sin(x)\).
- Since \(f(x) = e^x\) is continuous everywhere and \(g(x) = -x\) is continuous everywhere, the composition \(h(x) = e^{-x}\) will be continuous everywhere.
- Since \(f(x) = x\) is continuous everywhere, the function \(h(x) = 1/x\) - a ratio of continuous functions - will be continuous everywhere except possibly at \(x=0\) (where it is not continuous).
- The function \(h(x) = e^{x\ln(x)}\) will be continuous on \((0,\infty)\), the same domain that \(g(x) = x\ln(x)\) is continuous. This function (which simplifies to \(x^x\) when \(x>0\)) has a right limit at \(0\) (of \(1\)), but is not right continuous, as \(h(0)\) is not defined. (The function
h(x) = exp(x*log(x))is not defined at0but the functionh(x) = x^xis defined at0.0to be1.0.)
That last remark is one the routes make visible. The two expressions are the same function on \((0, \infty)\) and have the same right limit at \(0\), but only one of them has a value there:
symlim(exp(x * log(x)), x, 0; side = :right)(1, :gruntz)
symlim(x^x, x, 0; side = :right)(1, :substitution)
:gruntz for the first: the limit had to be derived, because exp(0 * log(0)) is not a number. :substitution for the second: 0.0^0.0 is 1.0 in Julia, the limit agrees with it, and so — as Julia defines it — \(x^x\) is right continuous at \(0\) where \(e^{x\ln x}\) is not. Same limit, different continuity, and the route is where the difference shows.
18.2 Questions
Question
Let \(f(x) = \sin(x)\) and \(g(x) = \cos(x)\). Which of these is not continuous everywhere?
\[ f+g,~ f-g,~ f\cdot g,~ f\circ g,~ f/g \]
Question
Let \(f(x) = \sin(x)\), \(g(x) = \sqrt{x}\).
When will \(f\circ g\) be continuous?
When will \(g \circ f\) be continuous?
Question
The composition \(f\circ g\) will be continuous everywhere provided:
Question
At which values is \(f(x) = 1/\sqrt{x-2}\) not continuous?
Question
A value \(x=c\) is a removable singularity for \(f(x)\) if \(f(x)\) is not continuous at \(c\) but will be if \(f(c)\) is redefined to be \(\lim_{x \rightarrow c} f(x)\).
The function \(f(x) = (x^2 - 4)/(x-2)\) has a removable singularity at \(x=2\). What value would we redefine \(f(2)\) to be, to make \(f\) a continuous function?
Question
The highly oscillatory function
\[ f(x) = x^2 (\cos(1/x) - 1) \]
has a removable singularity at \(x=0\). What value would we redefine \(f(0)\) to be, to make \(f\) a continuous function?
Question
Let \(f(x)\) be defined by
\[ f(x) = \begin{cases} c + \sin(2x - \pi/2) &~ x > 0\\ 3x - 4 &~ x \leq 0. \end{cases} \]
What value of \(c\) will make \(f(x)\) continuous?
Question
Suppose \(f(x)\), \(g(x)\), and \(h(x)\) are continuous functions on \((a,b)\). If \(a < c < b\), are you sure that \(\lim_{x \rightarrow c} f(g(x))\) is \(f(g(c))\)?
Question
Consider the function \(f(x)\) given by the following graph
The function \(f(x)\) is continuous at \(x=1\)?
The function \(f(x)\) is continuous at \(x=2\)?
The function \(f(x)\) is right continuous at \(x=3\)?
The function \(f(x)\) is left continuous at \(x=4\)?
Question
Let \(f(x)\) and \(g(x)\) be continuous functions. Their graphs over \([0,1]\) are given by:
What is \(\lim_{x \rightarrow 0.25} f(g(x))\)?
What is \(\lim_{x \rightarrow 0.25} g(f(x))\)?
What is \(\lim_{x \rightarrow 0.5} f(g(x))\)?
Question
A parametric equation is specified by a parameterization \((f(t), g(t)), a \leq t \leq b\). The parameterization will be continuous if and only if each function is continuous.
Suppose \(k_x\) and \(k_y\) are positive integers and \(a, b\) are positive numbers, will the Lissajous curve given by \((a\cos(k_x t), b\sin(k_y t))\) be continuous?
Here is a sample graph for \(a=1, b=2, k_x=3, k_y=4\):
a,b = 1, 2
k_x, k_y = 3, 4
plot(t -> a * cos(k_x *t), t-> b * sin(k_y * t), 0, 4pi)