Search

Search papers and lessons

Test Function

Level 4 · 10 min read

A test function is a smooth function that is zero outside a bounded interval, used as a probe to measure other functions through integrals.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Sign in to see your progress

TL;DR

A test function is a probe. It is a function that is perfectly smooth, with no corners, jumps or sharp spikes, and it is zero everywhere outside some bounded interval. You multiply another function by a test function and integrate. The result is a number that depends on the other function's average behaviour near the probe's location. Test functions let mathematicians talk about rough objects using only integrals. The tool that makes this work is Integration by Parts, which moves a Derivative from the rough function onto the smooth probe.

Where you'll see it: in the definition of a Weak Solution of a differential equation, and in the theory of distributions, which generalises functions to objects like the Dirac delta (an idealised spike with total area 1 concentrated at a single point).

Intuition

A problem the probe solves

You know that the derivative of ∣x∣|x| is −1-1 for x<0x \lt 0 and +1+1 for x>0x \gt 0, but at x=0x = 0 there is a corner and no derivative. Physical problems often have such corners and jumps: a shock wave, a switch flipping, a beam with a kink. We still want to say something about their slope. The idea is to stop asking about single points and instead ask about averages, using a smooth weighting function as a probe.

The bump

Think of a smooth bump on a table. It rises from flat ground, reaches a peak, and falls back to flat ground, with no edges. Outside a small patch the table is flat, so the bump is zero there.

Now imagine you want to measure how much a rough function, say one with a jump, is doing around a point. You cannot read its slope at every point, since the slope may not exist. You can instead slide the bump along the line, multiply, and integrate. The integral reports a weighted average of the rough function, weighted by the bump. Corners and single points carry little weight, so the average is well defined. (The integral here is an ordinary definite integral: the area under the product of the two curves.)

The picture below shows one such bump. It is nonzero only inside the interval from −1-1 to 11, and it fades smoothly to zero at both ends.

−1−0.500.5100.10.20.30.4xvalue
  • bump
A standard bump. It is smooth inside (-1, 1) and it fades to zero at the ends, where all its derivatives also vanish.

The bump is the building block. Every test function is a bump in this sense: smooth, and zero outside a bounded region.

The math

Definition

A function φ\varphi on the real line is a test function if it has two properties.

  1. It is infinitely differentiable. This means its derivatives φ′\varphi', φ′′\varphi'', and so on exist at every point and are continuous. In words, the function has no corners, kinks or jumps at any order.
  2. It has compact support. This means there is a bounded interval [−R,R][-R, R] such that φ(x)=0\varphi(x) = 0 for every xx outside it. The support is the set where φ\varphi is not zero (together with its boundary points), and compact means bounded and closed.

The collection of all test functions on the real line is written Cc∞(R)C_c^\infty(\mathbb{R}). The symbol C∞C^\infty means infinitely differentiable, and the subscript cc means compact support.

The standard example is

φ(x)={exp⁡ ⁣(−11−x2)if ∣x∣<1,0if ∣x∣≥1.\varphi(x) = \begin{cases} \exp\!\left(\dfrac{-1}{1 - x^2}\right) & \text{if } |x| \lt 1, \\ 0 & \text{if } |x| \ge 1. \end{cases}

Here exp⁡\exp is the exponential function, and ∣x∣|x| is the absolute value. Inside the interval the exponent is finite. As xx approaches ±1\pm 1 the exponent tends to −∞-\infty, so φ\varphi tends to 00 (a limit). At the edges φ\varphi vanishes, and so do all its derivatives. The exponential decays to zero faster than any power of the distance from the edge, which is why the bump is smooth across the boundary.

Why the probe is useful

Let uu be a locally integrable function, meaning its integral over any bounded interval is finite. Its action on a test function is the number

⟨u,φ⟩=∫−∞∞u(x) φ(x) dx.\langle u, \varphi \rangle = \int_{-\infty}^{\infty} u(x)\,\varphi(x)\,dx.

This integral is finite because φ\varphi vanishes outside a bounded interval, so only a bounded part of uu is ever seen. The integral can be computed even when uu has jumps, since jumps do not affect an integral.

Two facts make the probe useful. First, if uu is smooth, integration by parts from Integration by Parts lets the Derivative of uu move onto φ\varphi, with the boundary terms vanishing because φ\varphi has compact support:

∫u′(x) φ(x) dx=−∫u(x) φ′(x) dx.\int u'(x)\,\varphi(x)\,dx = -\int u(x)\,\varphi'(x)\,dx.

Second, the right-hand side needs no derivative of uu at all. That is the key to defining weak derivatives.

Shifting and scaling

If φ\varphi is a test function and aa is any number, then φ(x−a)\varphi(x - a) is also a test function. It is the same bump, moved so that it is centred at aa. Scaling φ(x/ε)\varphi(x/\varepsilon) for a small positive number ε\varepsilon gives a narrower bump. Both operations keep smoothness and compact support, so they keep you inside Cc∞(R)C_c^\infty(\mathbb{R}).

Worked examples

Example
Evaluating the standard bump

Use φ(x)=exp⁡ ⁣(−1/(1−x2))\varphi(x) = \exp\!\big(-1/(1-x^2)\big) for ∣x∣<1|x| \lt 1.

  1. At x=0x = 0: 1−02=11 - 0^2 = 1, so the exponent is −1-1 and φ(0)=e−1≈0.3679\varphi(0) = e^{-1} \approx 0.3679.
  2. At x=0.5x = 0.5: 1−0.25=0.751 - 0.25 = 0.75, so the exponent is −1/0.75≈−1.3333-1/0.75 \approx -1.3333 and φ(0.5)≈0.2636\varphi(0.5) \approx 0.2636.
  3. At x=0.9x = 0.9: 1−0.81=0.191 - 0.81 = 0.19, so the exponent is −1/0.19≈−5.263-1/0.19 \approx -5.263 and φ(0.9)≈0.0052\varphi(0.9) \approx 0.0052.
  4. At x=1.5x = 1.5, outside the interval: φ(1.5)=0\varphi(1.5) = 0 by definition.
  5. Interpretation: the values fall from about 0.37 at the centre to nearly zero close to the edge, and they reach zero exactly at ∣x∣=1|x| = 1. The fall is gradual, which is why the bump is smooth.
Example
Integrating a derivative against the probe

Take the standard bump φ\varphi and any smooth function uu. Show that ∫u′ φ dx\int u'\,\varphi\,dx and −∫u φ′ dx-\int u\,\varphi'\,dx are equal, and that ∫φ′ dx=0\int \varphi'\,dx = 0.

  1. Integrate ∫φ′ dx\int \varphi'\,dx directly. By the fundamental theorem of calculus, it equals φ(∞)−φ(−∞)\varphi(\infty) - \varphi(-\infty).
  2. Since φ\varphi is zero outside [−1,1][-1, 1], both endpoint values are 00. So ∫φ′ dx=0\int \varphi'\,dx = 0.
  3. Now let u(x)=xu(x) = x, so u′=1u' = 1. Then ∫u′ φ dx=∫φ dx\int u'\,\varphi\,dx = \int \varphi\,dx.
  4. Integrate by parts: ∫u′φ dx=[uφ]−∫uφ′ dx\int u'\varphi\,dx = [u\varphi] - \int u\varphi'\,dx. The bracket is zero because φ\varphi vanishes at both ends.
  5. So ∫φ dx=−∫x φ′(x) dx\int \varphi\,dx = -\int x\,\varphi'(x)\,dx. This is an identity you can check numerically, and it holds for every test function.

The example shows the general rule: moving a derivative from the function onto the probe changes the sign and costs nothing else.

Example
Smoothing a jump with a bump

This is the example that connects test functions to real problems. Take the step function H(x)=0H(x) = 0 for x<0x \lt 0 and H(x)=1H(x) = 1 for x≥0x \ge 0. It has a jump at 00 and no derivative there. Average it against a bump of width ε\varepsilon.

  1. Let ρ\rho be a bump, normalised so its total area is 11. Define ρε(y)=ρ(y/ε)/ε\rho_\varepsilon(y) = \rho(y/\varepsilon)/\varepsilon. This is a narrower, taller bump with area still 11.
  2. The smoothed step is Sε(x)=∫H(x−y) ρε(y) dyS_\varepsilon(x) = \int H(x - y)\,\rho_\varepsilon(y)\,dy. Only the part with x−y≥0x - y \ge 0 contributes, so Sε(x)=∫−∞xρε(y) dyS_\varepsilon(x) = \int_{-\infty}^{x} \rho_\varepsilon(y)\,dy.
  3. This is the cumulative area under the bump up to xx. It rises from 00 to 11 as xx passes through the bump.
  4. Because the bump is symmetric about 00, half its area lies to the left of 00. So Sε(0)=1/2S_\varepsilon(0) = 1/2.
  5. Interpretation: the sharp jump becomes a smooth ramp of width about ε\varepsilon, and the ramp is infinitely differentiable. As ε\varepsilon shrinks, the ramp approaches the jump. This averaging with test functions is exactly the procedure that makes weak derivatives well defined.

Recap: a test function is a smooth bump that is exactly zero outside a bounded interval. Pairing it with another function through an integral gives a number, the pairing lets derivatives be moved onto the bump, and so rough functions get a meaning for their derivatives. The next idea built on it is the Weak Solution.

Tradeoffs and failure modes

SituationProblemBetter choice
The function is already smooth and you need its pointwise valuesAveraging loses detail at single pointsEvaluate the function directly
The function is rough and you still need a meaning for its derivativeThe pointwise derivative does not existUse the weak derivative defined with test functions
You need to probe fine detail at one locationA single bump averages over its whole widthUse a narrower bump, scaling by a small ε\varepsilon
You need a probe that is not zero far awayCompact support is required for the boundary terms to vanishMultiply by a cutoff function, or work on a bounded domain

A common failure is forgetting compact support. If a probe does not vanish far away, the boundary terms in integration by parts no longer disappear, and the weak derivative definition gives wrong results. Another pitfall is thinking a test function must be sharp. It is the opposite: the smoothness is what lets derivatives move onto it.

History

The idea of testing a function against smooth weights is older than the name. Sergei Sobolev used test functions in the 1930s to define the weak derivatives that now carry his name. Laurent Schwartz gave the full theory in the 1940s and early 1950s, calling the generalised objects distributions. In that theory the test functions form the space Cc∞(R)C_c^\infty(\mathbb{R}), and the distributions are the continuous linear functionals on it. The theory made it possible to treat the Dirac delta as a rigorous object. Later, weak solutions of differential equations, which accept solutions with jumps and kinks, were defined with exactly this machinery.

Check yourself

QuestionWhy must a test function be zero outside some bounded interval?Show answer

If the probe did not vanish far away, the integral of uφu\varphi could be infinite, and the boundary terms in integration by parts would not disappear. Compact support keeps every integral finite and lets the boundary terms vanish, so the weak derivative definition works.

QuestionCompute φ(0.5)\varphi(0.5) for φ(x)=exp⁡(−1/(1−x2))\varphi(x) = \exp(-1/(1-x^2)) when ∣x∣<1|x| \lt 1.Show answer

The denominator is 1−0.25=0.751 - 0.25 = 0.75, so the exponent is −1/0.75=−4/3-1/0.75 = -4/3. Then φ(0.5)=e−4/3≈0.2636\varphi(0.5) = e^{-4/3} \approx 0.2636.

QuestionA bump φ\varphi is shifted to φ(x−3)\varphi(x - 3). Is the shifted function still a test function? Why?Show answer

Yes. Shifting moves the bump but does not change its smoothness, because the derivatives of φ(x−3)\varphi(x - 3) are the shifted derivatives of φ\varphi. It is still zero outside a bounded interval, now centred at 33. So it still has compact support.

QuestionWhy does averaging a jump against a bump produce a smooth function, even though the jump itself is not smooth?Show answer

The averaged value at each point is an integral over a neighbourhood. Integrals smooth out sudden changes, because a single point has no weight. The smoothing bump is itself infinitely differentiable, and the average inherits smoothness from it, so the result is a smooth ramp rather than a jump.

Sources

Test Function — explained simply | ungoon.me