Welcome to Horizontal Shifts: Sliding Left and Right! This is the first of three lessons in this course, so we are right at the starting line.
In the previous course, we moved graphs up and down by adding a constant to the whole function. Today we take on the sideways version of that story, and it comes with a twist that surprises almost everyone the first time: the sign that looks like "plus" sends the graph left, and the sign that looks like "minus" sends it right. Our goal is not to memorize that fact, but to be able to rebuild it from scratch any time we need it.
A Function as a Machine
A helpful way to picture a function is as a small machine. We feed a number in, the machine does its work, and a number comes out. For f(x)=x2, feeding in 3 produces 9.
Every transformation we study comes down to one question: did we tamper with the number going in, or with the number coming out? Adding 4 to the result after the machine finishes is a completely different action from handing the machine a different number in the first place. Vertical shifts, as you may recall, tampered with the output; horizontal shifts tamper with the input.
Reading an Expression: Inside or Outside
The written form tells us immediately which one is happening. All we need to check is where the constant sits relative to the parentheses of f.
Expression
Constant sits
Acts on
Effect
f(x)+4
outside f
output
vertical
f(x)−4
outside f
output
vertical
f(x+4)
inside f
input
horizontal
f(x−4)
inside f
input
horizontal
A quick evaluation check keeps this honest. If g(x)=f(x)+4, then g(3)=f(3)+4: we evaluate f at 3, exactly as before, and only then add 4. Writing g(3)=f(3+4) would be a misreading, because nothing in g ever changed the number handed to f.
Once we are confident about what the constant acts on, we can ask the more interesting question: what does an input change actually do to the picture?
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal
Let us take an input change seriously. Suppose g(x)=f(x−3), and suppose we already know one fact about f, say f(2)=5.
Where does the value 5 show up on the graph of g? It appears at whatever x makes the inside expression equal 2, since 2 is the only input for which f returns 5. So we solve:
x−3=2⟹x=5
Therefore g(5)=f(2)=5. The point (2,5) on f has become the point (5,5) on g. The graph moved right by 3, even though the formula shows a minus sign.
The reason is that subtracting inside the parentheses puts the input at a deficit. The expression x−3 always lags three behind x, so we must supply a larger x to bring it back up to a value that f recognizes, and larger x means further right.
The same logic runs the other way for f(x+3). To reproduce f(2) we solve x+3=2, giving x=−1, so the point lands three units to the left. Here is the pattern in one line, for h>0:
f(x−h): the inside value lags, so we need bigger inputs, and the graph slides right by h.
f(x+h): the inside value runs ahead, so we need smaller inputs, and the graph slides left by h.
Notice that this reasoning never mentioned a specific f. Whatever shape the graph has, every single one of its points has to make the same adjustment, so the whole curve travels together.
Real-world timing makes this comfortable. Suppose f(t) is the temperature of an oven t minutes after we switch it on, and one morning we start the oven three minutes late. At clock time t, the oven has only been running for t−3 minutes, so the new temperature is f(t−3).
A delay pushes the whole curve later, which is to the right on a time axis, and the formula that produces it carries a minus sign. In the same spirit, f(t+3) describes a head start: at clock time t the oven has already been running for t+3 minutes, so every stage of the heating happens sooner and the curve slides left.
It helps to always read a horizontal shift in the standard form f(x−h), where the signed number h is the shift: positive h moves right, negative h moves left. For example, f(x+6) can be rewritten as f(x−(−6)), so h=−6 and the graph moves six units left.
Two traps are worth naming before we practice.
Sign traps. Treating the visible symbol as the direction. The visible minus in f(x−3) means right, not left.
Location traps. Mistaking 2f(x) or f(x)+3 for input changes. If the constant never reaches the inside of the parentheses, the graph does not move sideways at all.
We now have a rule with a reason behind it. A constant outside f acts on outputs and moves the graph vertically, a constant inside f acts on inputs and moves it horizontally, and the horizontal direction reverses because the new x has to undo whatever the inside expression does to it. Whenever doubt creeps in, we can rebuild the answer in seconds: pick one known point, set the inside expression equal to its original input, and solve.
The exercises ahead will have us sorting expressions by what they act on, matching formulas to directions, sliding a graph on screen to see the reversal happen, and defending the backwards rule in our own words. Let's put this reasoning to work so that no sign error ever catches us off guard again.