Lesson
The theory — Piecewise Modeling Lab
A piecewise function is not one rule with an exception; it is two complete rules plus a statement of which one applies where. Here one linear rule governs everything below a breakpoint c and a second governs everything from c upwards. The interesting question is never what each piece does — they are just straight lines — but what happens at the seam.
What each symbol means
c- the breakpoint: the input at which the rule changes.
f(c⁻)- where the left piece is heading as
xapproachescfrom below. It is a limit, not a value: atcthe left rule no longer applies. f(c⁺)- the value the right piece actually takes at
c, which is also the value of the function there. jumpf(c⁺) − f(c⁻). Zero exactly when the two pieces meet.
Where the formula comes from
- Write the definition out with its condition attached:
f(x) = m₁x + b₁forx < c, andf(x) = m₂x + b₂forx ≥ c. Note which piece owns the breakpoint itself — here the right one, which is why the graph shows a hollow circle on the left branch and a filled one on the right. - At
cthe function has a value from the right rule,m₂c + b₂. The left rule has no value there, but it does have a destination: asxclimbs towardsc,m₁x + b₁approachesm₁c + b₁. That is the left-hand limit. - Continuity at a point means the limit from each side and the value all agree. The right-hand limit and the value are the same thing here, so two of the three are automatic and the whole condition collapses to one equation:
m₁c + b₁ = m₂c + b₂. - One equation, and any single coefficient can be moved to satisfy it:
b₂ = (m₁ − m₂)c + b₁. So continuity is always available and never free — you have to spend a parameter on it. When you do not, the leftover is exactly what the readout calls the jump:(m₂c + b₂) − (m₁c + b₁).
How to read what you see
The blue segment is the left rule and the orange one the right, and they are drawn as far as their own condition allows. At the breakpoint the blue branch ends in a hollow circle — a destination it never occupies — and the orange one starts with a filled dot, which is the actual value of f(c). When the two coincide the circles sit on top of each other and the jump row reads 0. The teal dot is f(x₀) for whatever you put in the evaluate box, and the last three rows turn the picture into numbers: whether the pieces meet, how much the slope changes as you cross, and whether the step down creates a stretch of inputs that cost more than the breakpoint does.
- Assumes
- Both pieces are straight lines, there is exactly one breakpoint, and it sits at a known place. The half-open convention matters and is a choice: the right rule owns
x = c, sof(c)ism₂c + b₂. Flip that convention and the value at the single pointcchanges while the jump does not. - Breaks when
- The real trouble comes when
cis not known but fitted. A breakpoint estimated from the same data used to fit the lines is a parameter chosen to minimise the error, so the ordinary regression standard errors are too small and the fit looks better than it is — this is what segmented-regression methods exist to handle. And a two-piece model says nothing at all about a third regime: extrapolating either line beyond the range you observed assumes a rule you never tested.
Problem solved in full
-
A tariff breakpoint at 5 and the range where buying more costs less 6 steps
A tariff charges 2x + 3 below a breakpoint at 5 and 0.8x + 8 above it. Find the value at 7 — then find the range where buying more costs less.
-
Two straight lines and a rule for which applies. The only care needed is the boundary: at exactly x = 5 the second branch is the one in force.
-
Approach the breakpoint from both sides. The left limit and the actual value disagree, and the size of the disagreement is the jump.
-
The slopes disagree too, and independently. A function can be continuous with a kink, or jump with no kink; this one does both.
-
Now the interesting question. Ask where the first branch has already climbed above the value the second branch starts at.
-
That inequality holds from 4.5 up to the breakpoint, and on that whole interval the cheaper purchase is the larger one.
-
The condition that would remove the window is worth writing down, because it is what a well-designed schedule satisfies.
Answer
13.6, and between 4.5 and 5 you should always buy 5. The second branch starts at 12 while the first branch is still climbing past it, so anyone in that window pays more for less. The window is not a rounding artefact — it is 10% of the whole first bracket, and it is exactly what a discontinuous tariff buys you. Real schedules avoid it by making the pieces meet: continuity requires b₂ − b₁ = (m₁ − m₂)c, which here would need 5 to equal 6. Marginal tax brackets are built that way on purpose, which is why the folk belief that a raise can lower your take-home pay is false for income tax and true for almost every bulk discount ever printed.
-
References (2)
- The theory section ends on what happens when the breakpoint is estimated rather than known. This is the method that handles it: V. M. R. Muggeo, "Estimating regression models with unknown break-points." Statistics in Medicine 22(19), 3055–3071, 2003.
- Insight block 3 — the piecewise-linear kink at the centre of modern networks: X. Glorot, A. Bordes and Y. Bengio, "Deep Sparse Rectifier Neural Networks." Proceedings of the 14th International Conference on Artificial Intelligence and Statistics (AISTATS), PMLR 15, 315–323, 2011.