Skip to content
AI360Xpert
Beta

Function Transformations: Shifts

Add to x and the graph slides, add to the output and it lifts, multiply and it stretches. Augmentation, normalisation and positional encodings are all transformations worn as tools.

The bowl x squared slides right 3 and lifts 2 to become (x minus 3) squared plus 2, carrying its vertex from the origin to (3, 2)
The bowl x squared slides right 3 and lifts 2 to become (x minus 3) squared plus 2, carrying its vertex from the origin to (3, 2)

Why Does This Exist?

Graphs rarely arrive in position. A parabola centres at the origin; the data sits three units right and two up. A signal spans millivolts; the model wants unit range. Transformations move, stretch and flip graphs into place without recomputing their essence: shifting, scaling and reflecting are cheaper than refitting.

They are also the vocabulary of preprocessing. Standardisation is a shift plus a stretch. Cropping translates coordinates. Augmentation shifts and flips deliberately. The slopes these moves preserve or rescale are derivatives and partial derivatives; following transformed landscapes downhill is gradients.

The one idea you need first. A graph plots (x,f(x))(x, f(x)). Changing what goes into ff moves points sideways; changing what comes out moves them vertically. Inside versus outside is the whole compass.

Think of It Like This

Sliding a stencil on graph paper

Cut a parabola from a stencil and lay it on graph paper: vertex at the origin. Slide it 3 right and 2 up without rotating: same cutout, new position, vertex now at (3,2)(3, 2). Stretch it taller: same centre, steeper sides. Flip it over: a hill instead of a bowl.

Every transformation is stencil handling, never redrawing. And the stencil explains the backwards-feeling horizontal shift: to keep the same cutout point over a new xx, the formula must subtract, feeding the old input to the unchanged shape.

Where it stops: stencils slide rigidly, while scaling stretches the cutout itself. The analogy shows position; stretch needs the multiplier below.

How It Actually Works

Four moves. Vertical shift: f(x)+kf(x) + k lifts every point by kk; (x−3)2+2(x - 3)^2 + 2 sits 2 above (x−3)2(x-3)^2. Horizontal shift: f(x−h)f(x - h) slides right by hh, backwards-feeling but strict, because x−hx - h feeds the old input hh units late. Vertical stretch: a⋅f(x)a \cdot f(x) multiplies heights. Horizontal stretch: f(bx)f(bx) divides widths by bb. Reflection: −f(x)-f(x) flips over the xx-axis.

Combine with care: order matters. Shift-then-scale differs from scale-then-shift, since scaling moves already-shifted positions.

Worked example: carry the vertex to (3, 2)

Start f(x)=x2f(x) = x^2, vertex (0,0)(0, 0). Slide right 3: replace xx with x−3x - 3, giving (x−3)2(x - 3)^2, vertex (3,0)(3, 0). Lift 2: add outside, g(x)=(x−3)2+2g(x) = (x - 3)^2 + 2, vertex (3,2)(3, 2).

Verify. g(3)=0+2=2g(3) = 0 + 2 = 2. At the old centre: g(0)=9+2=11g(0) = 9 + 2 = 11, the original 00 lifted by 22 and pushed right off the axis. The diagram above shows the original bowl in place and the carried bowl arriving at (3,2)(3, 2).

Code

def f(x: float) -> float:    return x**2

def g(x: float) -> float:    # Right 3 (inside, backwards), up 2 (outside, as written).    return f(x - 3.0) + 2.0

print(g(3.0))  # -> 2.0print(g(0.0))  # -> 11.0print(f(0.0), f(3.0))  # -> 0.0 9.0

The last line proves the shift is not a value change: ff still returns 9.09.0 at 33, while gg returns 2.02.0 there. Same shape, different position, and the code says so in one line each.

Watch Out For

Shifting left with (x minus 3)

(x−3)2(x - 3)^2 moves the bowl RIGHT by 3, and most beginners slide it left. The test is instant: the vertex solves x−3=0x - 3 = 0, giving x=3x = 3, on the right. Inside-the-brackets moves run opposite to intuition because the formula compensates to reuse old outputs.

Find the new zero of the inside expression to locate the shift. If a shifted activation behaves mirrored, this sign is the cause.

Stacking scale and shift in the wrong order

"Stretch by 2, then shift right 3" is 2f(x−3)2f(x - 3)... applied as 2(x−3)22(x-3)^2 shifts first in reading order but the stretch scales the shifted shape. Meanwhile 2x2x shifted gives (2x−3)2=4(x−1.5)2(2x - 3)^2 = 4(x - 1.5)^2: the shift halved. Same words, different order, vertex at 3 versus 1.5.

Parenthesise each stage and verify with the vertex. If a preprocessing chain lands off-centre, unpeel the stages one at a time.

The Quick Version

  • Outside changes move vertically: f(x)+2f(x) + 2 lifts by 2, as written.
  • Inside changes move horizontally and backwards: f(x−3)f(x - 3) slides right 3.
  • Multipliers stretch: aa outside scales heights, bb inside divides widths.
  • (x−3)2+2(x-3)^2 + 2 carries (0,0)(0,0) to (3,2)(3,2); g(3)=2g(3) = 2, g(0)=11g(0) = 11.
  • Locate shifts by zeroing the inside; parenthesise stacked stages.