Class 12 Maths, Worked in Full Past papersGet updates
Chapter 5 · Continuity and Differentiability

Miscellaneous · Q20: Yes: f(x)=∣x∣+∣x−1∣f(x)=|x|+|x-1| is continuous everywhere, not differentiable only at 0 and 1

Miscellaneous ExerciseContinuity and differentiability · Miscellaneous Exercise
The question

Does there exist a function which is continuous everywhere but not differentiable at exactly two points? Justify your answer.

Exam answer

Yes. Consider f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1|⁠, i.e.

f(x)={1−2x,x<01,0≤x≤12x−1,x>1f(x) = \begin{cases} 1 - 2x, & x \lt 0 \\ 1, & 0 \le x \le 1 \\ 2x - 1, & x \gt 1 \end{cases}

ff is continuous everywhere, being the sum of the continuous functions ∣x∣|x| and ∣x−1∣|x - 1|⁠.

At x=0x = 0⁠, f(0)=1f(0) = 1⁠:

LHD=lim⁡h→0−(1−2h)−1h=−2RHD=lim⁡h→0+1−1h=0\begin{aligned} \text{LHD} &= \lim_{h\to0^-}\frac{(1 - 2h) - 1}{h} = -2 \\ \text{RHD} &= \lim_{h\to0^+}\frac{1 - 1}{h} = 0 \end{aligned}

LHD ≠\ne RHD, so ff is not differentiable at x=0x = 0⁠.

At x=1x = 1⁠, f(1)=1f(1) = 1⁠:

LHD=lim⁡h→0−1−1h=0RHD=lim⁡h→0+(1+2h)−1h=2\begin{aligned} \text{LHD} &= \lim_{h\to0^-}\frac{1 - 1}{h} = 0 \\ \text{RHD} &= \lim_{h\to0^+}\frac{(1 + 2h) - 1}{h} = 2 \end{aligned}

LHD ≠\ne RHD, so ff is not differentiable at x=1x = 1⁠.

On x<0x \lt 0⁠, 0<x<10 \lt x \lt 1 and x>1x \gt 1⁠, ff is a polynomial, so it is differentiable there.

Hence f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1| is continuous everywhere but not differentiable at exactly two points, x=0x = 0 and x=1x = 1⁠. So such a function exists.

Want the reason behind every step, the basics and the checks?

The one idea this problem is built on

∣x∣|x| is continuous everywhere and has exactly one corner, at 0 (shown in the book after Theorem 3). Shifting it gives ∣x−1∣|x - 1|⁠, with its corner at 1. Adding the two keeps continuity and keeps both corners, because near each corner the other term is an ordinary straight line. To justify "yes" we must name a function and prove all three facts: continuous everywhere, not differentiable at the two points, differentiable everywhere else.

Given, to show, and the plan
Question
Is there f:R→Rf : \R \to \R⁠, continuous at every real number, that fails to be differentiable at exactly two points?
Answer to justify
Yes, for example f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1|⁠.
Plan
(1) Write ff piecewise. (2) Prove ff is continuous everywhere, checking the junctions 0 and 1 directly. (3) Show ff is differentiable at every x≠0,1x \ne 0, 1⁠. (4) One-sided derivatives at 0. (5) One-sided derivatives at 1. (6) Conclude.

Basics you need

1Continuity at a point

ff is continuous at cc if the left-hand limit, the right-hand limit and f(c)f(c) all exist and are equal (Definition 1, Section 5.2). Lesson: continuity at a point

2Algebra of continuous functions

Sums of continuous functions are continuous (Theorem 1); compositions of continuous functions are continuous (Theorem 2). ∣x∣|x| is continuous (Example 7). Lesson: algebra of continuous functions

3Differentiability at a point

ff is differentiable at cc exactly when the left-hand and right-hand limits of f(c+h)−f(c)h\frac{f(c+h) - f(c)}{h} are finite and equal (Section 5.3). Lesson: differentiability

4Piecewise functions

Remove each absolute value by splitting the line where its inside changes sign. Basics: piecewise functions

Solution

  1. Choose the function and write it piecewise

    Let f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1| for all real xx⁠. The insides xx and x−1x - 1 change sign at 0 and 1, so:

    f(x)={−x+(1−x)=1−2x,x<0,x+(1−x)=1,0≤x≤1,x+(x−1)=2x−1,x>1.f(x) = \begin{cases} -x + (1 - x) = 1 - 2x, & x < 0, \\ x + (1 - x) = 1, & 0 \le x \le 1, \\ x + (x - 1) = 2x - 1, & x > 1. \end{cases}
    On each piece both absolute values have a fixed sign, so they can be replaced by ordinary expressions. At the junctions both neighbouring formulas give the same value (f(0)=1f(0) = 1 and f(1)=1f(1) = 1⁠), which already hints at continuity.
    ∣u∣=u|u| = u for u≥0u \ge 0 and −u-u for u<0u < 0 (Basic 4). Basics: piecewise functions
  2. ff is continuous at every real number

    By the theorems. ∣x∣|x| is continuous (Example 7). ∣x−1∣|x - 1| is the composite of the continuous functions x↦x−1x \mapsto x - 1 and u↦∣u∣u \mapsto |u|⁠, so it is continuous (Theorem 2). Their sum ff is continuous (Theorem 1).

    Directly at the junctions. At x=0x = 0⁠:

    lim⁡x→0−f(x)=lim⁡x→0−(1−2x)=1,lim⁡x→0+f(x)=lim⁡x→0+1=1,f(0)=∣0∣+∣−1∣=1.\begin{aligned} \lim_{x\to0^-} f(x) &= \lim_{x\to0^-}(1 - 2x) = 1, \\ \lim_{x\to0^+} f(x) &= \lim_{x\to0^+} 1 = 1, \\ f(0) &= |0| + |-1| = 1. \end{aligned}

    At x=1x = 1⁠:

    lim⁡x→1−f(x)=lim⁡x→1−1=1,lim⁡x→1+f(x)=lim⁡x→1+(2x−1)=1,f(1)=∣1∣+∣0∣=1.\begin{aligned} \lim_{x\to1^-} f(x) &= \lim_{x\to1^-} 1 = 1, \\ \lim_{x\to1^+} f(x) &= \lim_{x\to1^+}(2x - 1) = 1, \\ f(1) &= |1| + |0| = 1. \end{aligned}

    All three numbers agree at each junction, and inside each piece ff is a polynomial, which is continuous (Example 14). So ff is continuous everywhere.

    The theorem argument is already a complete proof; the direct check shows the same thing through the definition, at the only two places where something could go wrong.
    Definition 1, Section 5.2; Theorems 1 and 2, Section 5.2.1; Examples 7 and 14 (Basics 1, 2). Lesson: continuity at a point
  3. ff is differentiable at every xx other than 0 and 1

    Take c<0c < 0⁠. For ∣h∣<∣c∣|h| < |c|⁠, both cc and c+hc + h are negative, so

    f(c+h)−f(c)h=(1−2c−2h)−(1−2c)h=−2.\frac{f(c+h) - f(c)}{h} = \frac{(1 - 2c - 2h) - (1 - 2c)}{h} = -2.

    Hence f′(c)=−2f'(c) = -2⁠.

    In the same way f′(c)=0f'(c) = 0 for 0<c<10 < c < 1 (where ff is the constant 1) and f′(c)=2f'(c) = 2 for c>1c > 1 (where f(x)=2x−1f(x) = 2x - 1⁠).

    Around any point that is not a junction there is a small open interval on which ff is one straight line, so the difference quotient is that line's slope for all small hh⁠. Only at 0 and 1 do the two sides of a point use different formulas.
    Derivative as the limit of the difference quotient (Basic 3). Basics: slope at a point
  4. Not differentiable at x=0x = 0

    Here f(0)=1f(0) = 1⁠. For small h<0h < 0⁠, f(h)=1−2hf(h) = 1 - 2h⁠; for small h>0h > 0 (h<1h < 1⁠), f(h)=1f(h) = 1⁠.

    LHD=lim⁡h→0−(1−2h)−1h=−2,RHD=lim⁡h→0+1−1h=0.\begin{aligned} \text{LHD} &= \lim_{h\to0^-}\frac{(1 - 2h) - 1}{h} = -2, \\ \text{RHD} &= \lim_{h\to0^+}\frac{1 - 1}{h} = 0. \end{aligned}

    −2≠0-2 \ne 0⁠, so ff is not differentiable at 0.

    The graph arrives at (0,1)(0, 1) with slope −2-2 and leaves with slope 0: a corner. Note that the term ∣x−1∣|x - 1| is the straight line 1−x1 - x near 0, so it adds the same slope −1-1 on both sides and cannot cancel the corner of ∣x∣|x|⁠.
    Left-hand and right-hand derivatives, Section 5.3 (Basic 3). Lesson: differentiability
  5. Not differentiable at x=1x = 1

    Here f(1)=1f(1) = 1⁠. For small h<0h < 0 (h>−1h > -1⁠), f(1+h)=1f(1 + h) = 1⁠; for small h>0h > 0⁠, f(1+h)=2(1+h)−1=1+2hf(1 + h) = 2(1 + h) - 1 = 1 + 2h⁠.

    LHD=lim⁡h→0−1−1h=0,RHD=lim⁡h→0+(1+2h)−1h=2.\begin{aligned} \text{LHD} &= \lim_{h\to0^-}\frac{1 - 1}{h} = 0, \\ \text{RHD} &= \lim_{h\to0^+}\frac{(1 + 2h) - 1}{h} = 2. \end{aligned}

    0≠20 \ne 2⁠, so ff is not differentiable at 1.

    −1 1 2 1 2 3 4 x y corner at x = 0 slopes −2 | 0 corner at x = 1 slopes 0 | 2 y = |x| + |x − 1| slope −2 slope 2 slope 0
    f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1| for −1.5≤x≤2.5-1.5 \le x \le 2.5⁠, equal scales. Three straight pieces with slopes −2-2⁠, 00 and 22⁠; the graph is unbroken (continuous) but has corners at (0,1)(0, 1) and (1,1)(1, 1)⁠, and nowhere else.
    Same picture as at 0: slope 0 on the left, slope 2 on the right. Near 1 the term ∣x∣|x| is just xx⁠, a line, so the corner of ∣x−1∣|x - 1| survives.
    Compare Exercise 5.2, Q9: ∣x−1∣|x - 1| is not differentiable at 1. Exercise 5.2 Q9
  6. Conclude

    f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1| is continuous at every real number (Step 2), differentiable at every real number except 0 and 1 (Step 3), and not differentiable at 0 or at 1 (Steps 4, 5). So it is continuous everywhere and fails to be differentiable at exactly two points. The answer to the question is yes.

    "Exactly two" needs both halves: at least these two points fail (Steps 4, 5) and no other point fails (Step 3). Many other examples work the same way, for instance ∣x−p∣+∣x−q∣|x - p| + |x - q| for any two different numbers pp⁠, qq⁠.
    Theorem 3 and its remark: continuity does not imply differentiability. Lesson: differentiability
Result

Yes. For example f(x)=∣x∣+∣x−1∣f(x) = |x| + |x - 1| is continuous at every real number, is differentiable at every xx other than 0 and 1, and is not differentiable at x=0x = 0 (one-sided derivatives −2-2 and 00⁠) or at x=1x = 1 (one-sided derivatives 00 and 22⁠).

Check it with numbers

With h=±0.001h = \pm 0.001⁠: at 0, f(−0.001)−f(0)−0.001=1.002−1−0.001=−2\frac{f(-0.001) - f(0)}{-0.001} = \frac{1.002 - 1}{-0.001} = -2 and f(0.001)−f(0)0.001=1−10.001=0\frac{f(0.001) - f(0)}{0.001} = \frac{1 - 1}{0.001} = 0⁠. At 1, f(0.999)−1−0.001=0\frac{f(0.999) - 1}{-0.001} = 0 and f(1.001)−10.001=1.002−10.001=2\frac{f(1.001) - 1}{0.001} = \frac{1.002 - 1}{0.001} = 2⁠. ✓ Values: f(−1.5)=4f(-1.5) = 4⁠, f(0.5)=1f(0.5) = 1⁠, f(2.5)=4f(2.5) = 4⁠.

Common mistakes
  1. Answering "yes" without an example and a proof. "Justify" means: exhibit a function and prove all three properties.
  2. Assuming corners always survive addition. They can cancel: ∣x∣+(1−∣x∣)=1|x| + (1 - |x|) = 1 has no corner at all. That is why Steps 4 and 5 compute the one-sided derivatives of the sum itself.
  3. Forgetting to show differentiability elsewhere. Without Step 3, the example could fail at more than two points.
What to take away
  1. Continuity does not imply differentiability; corners of ∣x−p∣|x - p| are the standard examples.
  2. Sums of shifted absolute values give continuous functions with corners exactly where you choose.
  3. To prove "exactly nn points", show failure at those points and success everywhere else.

Every fact used, and where it comes from

FactUsed inSource
Continuity at a pointStep 2Definition 1, Section 5.2 (Lesson: continuity at a point)
∣x∣|x| is continuous; polynomials are continuousStep 2Examples 7 and 14, Section 5.2
Sums and composites of continuous functions are continuousStep 2Theorems 1 and 2, Section 5.2.1 (Lesson: algebra of continuous functions)
Differentiable at cc⁠: one-sided derivatives finite and equalSteps 3–5Section 5.3 (Lesson: differentiability)
Continuity does not imply differentiability (∣x∣|x| at 0)Steps 4–6Theorem 3 and the remark after Corollary 1, Section 5.3
Numerical values, figure coordinatesCheck, figureRecomputed in the site's verification script
Found an error, or want more?

Tell us if something on this page is wrong or unclear, or if you would like a fuller explanation, another method or a new feature. Send feedback on this problem →