Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 1: Math FoundationsCalculus

Integrals as accumulation

P1.C945 min●●○ IntermediateReviewed Nov 30, 2026

Why this matters for machine learning

Probability for continuous quantities lives in areas under curves. A density, the probability of an interval, an expected value, a cumulative distribution and the area under a ROC curve are all integrals, so integrals are how an ML model's uncertainty and evaluation are written down.

  • A probability density has total area 1, and the probability of an interval is the area under the density over that interval. (P1.D2: Random variables)
  • The cumulative distribution function (CDF) is an accumulation function: the area under the density up to xx. (P1.D2: Random variables)
  • The expected value of a continuous quantity is the integral ∫x p(x) dx\int x\,p(x)\,dx, and a loss averaged over a distribution is an integral that a data average approximates. (P1.D4: Expectation and variance)
  • The Gaussian density divides by 2π\sqrt{2\pi} so that its area is exactly 1: a normalising constant is an integral. (P1.D3: Common distributions)
  • AUC, a standard score for classifiers, is the area under the ROC curve, found in practice with the trapezoid rule. (P3.A9: Evaluation metrics, coming soon)

Before this: Summation, products and indices, Rates of change and the derivative, Derivative rules

After this lesson you can

  • Turn a rate into a total by adding up thin pieces, and say what units the total has
  • Write left, right, midpoint and trapezoid Riemann sums with Σ\Sigma notation, and explain why they approach one number as the strips get thinner
  • Read the definite integral ∫abf(x) dx\int_a^b f(x)\,dx symbol by symbol, treat area below the axis as negative, and say how fast each rule's error shrinks
  • State both halves of the fundamental theorem of calculus, and evaluate simple integrals with an antiderivative of xnx^n, ekx\mathrm{e}^{kx} or 1/x1/x
  • Explain why a probability density needs an integral: probability is area, the total area is 1, and expected values, CDFs and AUC are integrals

In P1.C1 you were given how far a car had travelled, and you found its speed. Now turn the question around. You are given the speedometer readings, second by second, and you want to know how far the car went. A tap pours water into a tank at a changing rate, and you want to know how much water is in the tank. A model assigns a probability density to a measurement, and you want the chance that the measurement falls between two values.

All three are the same job: add up a rate over a stretch to get a total. Doing this with thinner and thinner pieces gives the integral, the second great tool of calculus, and the one that probability is built on.

Adding up a rate

If the speed never changes, the answer is easy. At 3 m/s for 5 seconds the car goes 3×5=153\times5=15 m. On a graph with time across and speed up, this is a rectangle of height 3 and width 5, and 15 is its area. The unit fits too: (metres per second) ×\times seconds == metres.

Now let the speed change. Take the toy car of P1.C1, with distance d(t)=t2d(t)=t^2 metres. Its speed is v(t)=d′(t)=2tv(t)=d'(t)=2t m/s: 0 at the start, 2 after one second, 6 after three. How far does it go in the first 3 seconds? We pretend we do not know dd and only know the speeds.

Cut the 3 seconds into three pieces of 1 second. Inside one piece the speed is not constant, but we can pick one speed for it and treat it as constant:

  • speed at the start of each piece (0, 2, 40,\,2,\,4 m/s): 0⋅1+2⋅1+4⋅1=60\cdot1+2\cdot1+4\cdot1=6 m;
  • speed at the end of each piece (2, 4, 62,\,4,\,6 m/s): 2⋅1+4⋅1+6⋅1=122\cdot1+4\cdot1+6\cdot1=12 m;
  • speed in the middle of each piece (1, 3, 51,\,3,\,5 m/s): 1⋅1+3⋅1+5⋅1=91\cdot1+3\cdot1+5\cdot1=9 m.

The car is speeding up, so the start-of-piece speeds are too low and the end-of-piece speeds are too high. The truth is between 6 and 12. The middle guess is 9, and from P1.C1 we know the true distance is d(3)−d(0)=9d(3)-d(0)=9 m. Thinner pieces close in on it (the three right-hand columns are the total distance in metres):

pieceswidthstartendmiddle
31 s6129
60.5 s7.510.59
300.1 s8.79.39

(The middle guess is exactly 9 every time because this speed is a straight line: on each piece the too-low half cancels the too-high half. That is special to straight lines.)

The recipe has two steps. Cut the stretch into thin pieces, so the rate is nearly constant on each. Add up (rate on the piece) ×\times (width of the piece). The same recipe works for water into a tank (litres per minute ×\times minutes == litres) or for any other rate.

Area under a curve

Each term in the recipe is the area of a rectangle: its height is the rate, and its width is the width of the piece. So the sum is the area of a row of rectangles, and as the rectangles get thinner, their tops follow the curve. That gives the key picture of this lesson:

The total accumulated from a rate is the area between the graph of the rate and the horizontal axis.

Whenever you see an area under a curve in machine learning, ask: what is the height a rate of, and what is the total? For a probability density, the height is probability per unit of xx, and the total is a probability.

Riemann sums

Now say it exactly, for a function ff on an interval from aa to bb. Cut the interval into nn strips of equal width

Δx=b−an,xi=a+i Δx(i=0,1,…,n),\begin{aligned} \Delta x&=\frac{b-a}{n},\\ x_i&=a+i\,\Delta x\quad(i=0,1,\dots,n), \end{aligned}

so x0=ax_0=a and xn=bx_n=b. A Riemann sum (named after the mathematician Bernhard Riemann) adds up f(sample point)×Δxf(\text{sample point})\times\Delta x over the strips. The sample point can be:

  • the left end of each strip, x0,…,xn−1x_0,\dots,x_{n-1};
  • the right end, x1,…,xnx_1,\dots,x_n;
  • the middle, a+(i−12)Δxa+(i-\tfrac12)\Delta x for i=1,…,ni=1,\dots,n.

With the Σ\Sigma notation of P1.A3 (a sum with nn terms in each case):

Ln=∑i=0n−1f(xi) Δx,Rn=∑i=1nf(xi) Δx,Mn=∑i=1nf ⁣(a+(i−12)Δx)Δx.\begin{aligned} L_n&=\sum_{i=0}^{n-1}f(x_i)\,\Delta x,\\ R_n&=\sum_{i=1}^{n}f(x_i)\,\Delta x,\\ M_n&=\sum_{i=1}^{n}f\!\left(a+(i-\tfrac12)\Delta x\right)\Delta x . \end{aligned}

The common factor Δx\Delta x can be pulled out of the sum (the first rule of P1.A3). The trapezoid rule joins the two ends of each strip by a slanted line, so each strip is a trapezoid, and its area is the width times the average of the two end heights. Adding them up gives exactly the average of the left and right sums: Tn=12(Ln+Rn)T_n=\tfrac12(L_n+R_n).

A first example, by hand

Let f(x)=x2f(x)=x^2 on [0,1][0,1] with n=4n=4. Then Δx=0.25\Delta x=0.25 and the strip ends are 0, 0.25, 0.5, 0.75, 10,\ 0.25,\ 0.5,\ 0.75,\ 1, where ff equals 0, 0.0625, 0.25, 0.5625, 10,\ 0.0625,\ 0.25,\ 0.5625,\ 1.

L4=0.25 (0+0.0625+0.25+0.5625)=0.21875,R4=0.25 (0.0625+0.25+0.5625+1)=0.46875.\begin{aligned} L_4&=0.25\,(0+0.0625\\&\qquad+0.25+0.5625)=0.21875,\\ R_4&=0.25\,(0.0625+0.25\\&\qquad+0.5625+1)=0.46875. \end{aligned}

For the midpoint rule the heights are read at 0.125, 0.375, 0.625, 0.8750.125,\ 0.375,\ 0.625,\ 0.875, where ff equals 0.0156250.015625, 0.1406250.140625, 0.3906250.390625 and 0.7656250.765625, so M4=0.25×1.3125=0.328125M_4=0.25\times1.3125=0.328125.

Since x2x^2 is increasing, each left height is the smallest on its strip and each right height is the largest. So the true area lies between L4L_4 and R4R_4 (we will see it is 13=0.3333…\tfrac13=0.3333\ldots), and the midpoint sum is already close. More strips make this sharper:

nnleft LnL_nright RnR_nmidpoint MnM_n
40.218750.468750.328125
100.2850.3850.3325
1000.328350.338350.333325
10000.332830.333830.33333

(The last row is rounded to 5 decimals.) All three columns head to 0.3333…=130.3333\ldots=\tfrac13.

The limit: the definite integral

For a continuous ff, the left, right, midpoint and trapezoid sums all approach the same number as n→∞n\to\infty (this is a theorem; this lesson checks it with numbers, not a proof). That number is the definite integral:

∫abf(x) dx=lim⁡n→∞∑i=1nf(xi) Δx.\int_a^b f(x)\,dx=\lim_{n\to\infty}\sum_{i=1}^{n}f(x_i)\,\Delta x .

Here is what each symbol means:

  • ∫\int is a stretched letter S, for “sum”.
  • aa and bb are the limits: where the interval starts and ends (the “limits of integration”, not the limit n→∞n\to\infty).
  • f(x)f(x) is the height of the curve at xx.
  • dxdx stands for the width of a very thin strip, the Δx\Delta x of the sum after the limit. It also names the variable that runs from aa to bb. So “f(x) dxf(x)\,dx” reminds you of “height times strip width”.

As with dydx\frac{dy}{dx} in P1.C1, treat ∫abf(x) dx\int_a^b f(x)\,dx as one piece of notation for the limit of the sums. The dxdx is notation that reminds you of Δx\Delta x, the strip width in the sums. It is not a number that you can set to 0.01, divide by or cancel. The letter xx is a dummy variable, like the index of a sum in P1.A3: ∫abf(t) dt\int_a^b f(t)\,dt means exactly the same number. And the integral is a number, not a function of xx.

Checking x2x^2 exactly

For x2x^2 on [0,1][0,1] the sums can be done exactly. The strip ends are xi=i/nx_i=i/n and Δx=1/n\Delta x=1/n. The left sum is

Ln=∑i=0n−1(in)21n=1n3∑i=1n−1i2=(n−1) n (2n−1)6 n3=13−12n+16n2,\begin{aligned} L_n&=\sum_{i=0}^{n-1}\left(\tfrac in\right)^2\tfrac1n\\ &=\frac1{n^3}\sum_{i=1}^{n-1}i^2\\ &=\frac{(n-1)\,n\,(2n-1)}{6\,n^3}\\ &=\frac13-\frac1{2n}+\frac1{6n^2}, \end{aligned}

using ∑i=1mi2=m(m+1)(2m+1)6\sum_{i=1}^{m}i^2=\frac{m(m+1)(2m+1)}{6} from P1.A3 with m=n−1m=n-1. In the same way Rn=13+12n+16n2R_n=\frac13+\frac1{2n}+\frac1{6n^2}, so Tn=13+16n2T_n=\frac13+\frac1{6n^2}, and the midpoint sum is Mn=13−112n2M_n=\frac13-\frac1{12n^2}. Every one of them tends to 13\tfrac13. (Check n=10n=10: L10=0.3333−0.05+0.0017=0.285L_{10}=0.3333-0.05+0.0017=0.285, as in the table.) So

∫01x2 dx=13.\int_0^1x^2\,dx=\frac13 .

Rectangles getting thinner: a Riemann sum against the exact integral

f(x) = x²

0.20.40.60.810.20.40.60.81x

■ strip above the axis (adds) · ▨ strip below the axis (subtracts) · dots: where each height is read

strip width Δx = (b − a) / n = (1 − 0) / 4 = 0.25
left sum = 0.21875
exact integral F(b) − F(a) = 0.33333333
error = sum − exact = −1.15×10⁻¹, about −34.4% of the exact value
error × n = −4.58×10⁻¹; error × n² = −1.83×10⁰

The left sum with n = 4 strips is 0.115 below the exact integral.

On [0, 1] the exact area is 1/3. The exact value comes from an antiderivative F (the second half of the fundamental theorem of calculus, below). Sums and errors are computed in ordinary 64-bit floating point. Try doubling n and watch which of the two last numbers settles down.

Rectangles getting thinner. Pick a function, a rule, the interval [a, b] and the number of strips n. Blue strips are above the axis, red hatched strips below it. The readouts compare the sum with the exact integral.

Things to try with the rectangles widget:

  1. Start with x2x^2 on [0,1][0,1], the left rule and n=4n=4: the sum is 0.218750.21875 and the error is negative (the sum is too small). Switch to the right rule: too big. Midpoint: close. Slide nn up to 300 and watch all three sums meet the exact value 0.33330.3333.
  2. Choose speed 2t (on [0,3][0,3]). The midpoint and trapezoid rules give exactly 9 for every nn, as the table above said. The left and right sums are 9 minus and plus the same amount.
  3. Choose sin x on [0,π][0,\pi] (exact area 2), then slide bb up to 2π2\pi: strips below the axis turn red and hatched, and the sum falls to about 0. (Over a whole period the heights cancel by symmetry, so this particular case gives 0 for every nn and rule: a special case, not a sign that nn is large enough.) Signed area is the next section.
  4. Choose e⁻ˣ and slide bb up. The exact area from 0 to bb is 1−e−b1-\mathrm{e}^{-b}, which gets closer to 1 but never reaches it. That is the area of a probability density, which later sections use.
  5. Choose x² − 1 and watch the last readout line. Which number settles down as nn grows, “error × n\times\,n” or “error × n2\times\,n^2”, for the left rule? For the midpoint rule? (Left: error × n\times\,n, near −4-4. Midpoint: error × n2\times\,n^2, near −0.67-0.67.)

Signed area: below the axis counts negative

If f(x)f(x) is negative, the rectangle “height” is negative, and its term f(xi) Δxf(x_i)\,\Delta x is negative too. So the integral is a signed area:

∫abf(x) dx=(area above)−(area below).\begin{aligned} \int_a^b f(x)\,dx&=(\text{area above})\\ &\quad-(\text{area below}). \end{aligned}

Example: f(x)=x2−1f(x)=x^2-1 on [0,2][0,2]. It is below the axis for 0<x<10<x<1, where the area is 23\tfrac23, and above it for 1<x<21<x<2, where the area is 43\tfrac43. So the integral is 43−23=23\tfrac43-\tfrac23=\tfrac23, which the widget shows. Another: ∫02πsin⁡x dx=0\int_0^{2\pi}\sin x\,dx=0, since the hump above the axis and the hump below it are equal, while the total shaded region has area 2+2=42+2=4.

This is the right behaviour for rates: if the car’s velocity is negative, it is going backwards, and the integral of velocity is displacement (net change of position), not total distance travelled. To get the total area between a curve and the axis, integrate ∣f∣|f| instead.

Rules that follow from the sums (the same rules as for Σ\Sigma in P1.A3), for ff and gg continuous:

  • ∫aaf(x) dx=0\int_a^a f(x)\,dx=0 (no width, no area);
  • ∫baf(x) dx=−∫abf(x) dx\int_b^a f(x)\,dx=-\int_a^b f(x)\,dx (walking the interval backwards makes every Δx\Delta x negative);
  • ∫abf(x) dx=∫acf(x) dx+∫cbf(x) dx\int_a^b f(x)\,dx=\int_a^c f(x)\,dx+\int_c^b f(x)\,dx (cut the interval at any cc between aa and bb);
  • ∫ab(f(x)+g(x))dx=∫abf(x) dx+∫abg(x) dx\int_a^b\bigl(f(x)+g(x)\bigr)dx=\int_a^b f(x)\,dx+\int_a^b g(x)\,dx, and ∫abc f(x) dx=c∫abf(x) dx\int_a^b c\,f(x)\,dx=c\int_a^b f(x)\,dx for a constant cc.

How fast do the sums converge?

The sums approach the integral, but at different speeds. For x2x^2 on [0,1][0,1] we know the errors exactly from the formulas above. Here are the errors (sum minus exact) as nn doubles:

nnleftmidpointtrapezoid
10−0.0483-0.0483−0.00083-0.000830.001670.00167
20−0.0246-0.0246−0.00021-0.000210.000420.00042
40−0.0124-0.0124−0.000052-0.0000520.000100.00010
80−0.00622-0.00622−0.000013-0.0000130.0000260.000026

Doubling nn cuts the left error by about 2 and the midpoint and trapezoid errors by about 4. (The trapezoid errors are positive. The right error is nearly the left error with the sign flipped: ±12n\pm\frac1{2n}.) In words: for a smooth function, the left and right rules have error of order 1n\frac1n, and the midpoint and trapezoid rules of order 1n2\frac1{n^2}. To gain one more correct digit, the left rule needs ten times as many strips; the midpoint rule about 3.23.2 times as many (10\sqrt{10}).

Two cautions. First, “smooth” matters: these rates assume a function with continuous derivatives, not a corner or a jump inside the interval. Second, the rates are about the typical case, not a law for every function and interval: for sin⁡x\sin x on [0,π][0,\pi] the left, right and trapezoid sums are all the same number (both end heights are 0), and their error is of order 1/n21/n^2, not 1/n1/n (the code cell below shows it). The Go-deeper box gives the rule that explains both.

Go deeper Where the error sizes come from

For a smooth ff and large nn, the errors are close to the following (sum minus exact; this is the leading term of the Euler–Maclaurin formula, stated here and checked with numbers, not proved):

Ln−∫≈−f(b)−f(a)2 Δx,Rn−∫≈+f(b)−f(a)2 Δx,Mn−∫≈−f′(b)−f′(a)24 Δx2,Tn−∫≈+f′(b)−f′(a)12 Δx2.\begin{aligned} L_n-\int&\approx-\frac{f(b)-f(a)}{2}\,\Delta x,\\ R_n-\int&\approx+\frac{f(b)-f(a)}{2}\,\Delta x,\\ M_n-\int&\approx-\frac{f'(b)-f'(a)}{24}\,\Delta x^2,\\ T_n-\int&\approx+\frac{f'(b)-f'(a)}{12}\,\Delta x^2 . \end{aligned}

For x2x^2 on [0,1][0,1]: f(b)−f(a)=1f(b)-f(a)=1 and f′(b)−f′(a)=2f'(b)-f'(a)=2, so at n=10n=10 (Δx=0.1\Delta x=0.1) the left error is about −0.05-0.05 (true −0.0483-0.0483), the midpoint −224(0.01)=−0.00083-\frac{2}{24}(0.01)=-0.00083, and the trapezoid 0.001670.00167, matching the table. The left and right errors depend on the change of ff across the interval: if f(a)=f(b)f(a)=f(b) (like sin⁡x\sin x on [0,π][0,\pi]) that term vanishes and the next one, of order Δx2\Delta x^2, remains. The midpoint error is about half the trapezoid error and has the opposite sign, which is why combining them (Simpson’s rule) works so well; that rule is not taught here.

The fundamental theorem of calculus

Computing an integral as a limit of sums is slow. The shortcut connects this lesson to P1.C1, and it is one of the most important results in calculus.

Part 1: the area so far has slope ff

Fix a starting point aa and let the right-hand end move. The area collected from aa up to xx is a function of xx, the accumulation function:

A(x)=∫axf(t) dt.A(x)=\int_a^x f(t)\,dt .

(The variable inside is called tt because xx is already the upper limit.) Slide xx to the right and A(x)A(x) grows by a thin new strip. How fast?

A new strip of width hh starts at xx. If hh is small, ff hardly changes across it, so the strip is nearly a rectangle of height f(x)f(x) and width hh:

A(x+h)−A(x)≈f(x) h,A(x+h)-A(x)\approx f(x)\,h,

so

A(x+h)−A(x)h≈f(x).\frac{A(x+h)-A(x)}{h}\approx f(x).

The left side is the difference quotient of P1.C1. As h→0h\to0 it tends to A′(x)A'(x), and the right side is f(x)f(x). For continuous ff this gives part 1 of the theorem:

A′(x)=f(x).A'(x)=f(x).

Numbers, for f(t)=t2f(t)=t^2 and a=0a=0, where A(x)=x33A(x)=\frac{x^3}3: at x=1x=1, with h=0.01h=0.01, A(1.01)−A(1)=0.0101003A(1.01)-A(1)=0.0101003 and the quotient is 1.01001.0100, near f(1)=1f(1)=1. With h=0.001h=0.001 it is 1.00101.0010. (Here A(x)=x33A(x)=\frac{x^3}{3} comes from part 2, below; the sums confirm it.)

In words: the rate at which the area grows equals the height of the curve. Taller curve, faster growth. Where ff is negative, AA falls. Where ff crosses zero, AA is flat for an instant.

Accumulation function: area so far, and its slope

0.511.522.5246t

Top: f(t), the rate. Shaded: the area from 0 to x.

0.511.522.5−1123x

Bottom: A(x), the area so far (solid up to x). Orange: its tangent, with slope f(x).

x = 1.5
height f(x) = 1.25
A(x) = x³/3 − x = −0.375
A(x) from 2000 thin strips = −0.375
slope of A at x, from (A(x + h) − A(x − h)) / 2h with h = 0.0001: 1.25 (compare f(x) = 1.25)

f(x) = 1.25 is above the axis, so the area A(x) is growing as x moves right, at the rate f(x) = 1.25 per unit of x.

The area counts from 0. Where f is below the axis the hatched area is negative, so A goes down. A flat spot of A is where f is zero. The two plots use different scales, so read the slope from the numbers, not from the angle on screen.

Accumulation function. Top: f(t) with the area from 0 to x shaded (blue above the axis, red hatched below). Bottom: A(x), the area so far, with its orange tangent. The slope of the tangent is the height f(x) of the top plot.

Things to try with the accumulation widget:

  1. With t2−1t^2-1, drag xx from 0 to 2.5. While ff is negative (up to x=1x=1), the area is negative and AA falls; at x=1x=1, where ff crosses zero, the tangent of AA is flat; afterwards AA rises. The readout “slope of AA” matches f(x)f(x) at every position.
  2. Choose cos t and drag xx across π/2≈1.57\pi/2\approx1.57: ff crosses zero, and A=sin⁡xA=\sin x has its peak there.
  3. Choose e⁻ᵗ: ff stays positive, so AA always rises, but more and more slowly, and levels off near 1.
  4. Compare “A(x)A(x)” with “A(x)A(x) from 2000 thin strips”: the formula and the thin-strip sum agree.

Part 2: integrals from antiderivatives

A function FF is an antiderivative of ff if F′=fF'=f. Part 1 says AA is one antiderivative of ff. Suppose FF is another. Two functions with the same derivative on an interval differ only by a constant (a fact we use without proof here), so F(x)=A(x)+CF(x)=A(x)+C. Then F(b)−F(a)=A(b)−A(a)=A(b)−0=∫abfF(b)-F(a)=A(b)-A(a)=A(b)-0=\int_a^b f. This is part 2:

∫abf(x) dx=F(b)−F(a),\int_a^b f(x)\,dx=F(b)-F(a),

where F′=fF'=f. It is usually written [F(x)]ab=F(b)−F(a)\bigl[F(x)\bigr]_a^b=F(b)-F(a). The condition is that ff is continuous on [a,b][a,b] and F′=fF'=f at every point of [a,b][a,b].

Check: F(x)=x33F(x)=\frac{x^3}3 has F′(x)=x2F'(x)=x^2 (the power rule of P1.C2), so ∫01x2 dx=13−0=13\int_0^1x^2\,dx=\frac13-0=\frac13, which the sums gave with a lot more work. For the toy car, F(t)=t2F(t)=t^2 has F′=2tF'=2t, so ∫032t dt=32−02=9\int_0^32t\,dt=3^2-0^2=9 m.

Read part 2 as: the integral of a rate is the total change. The car’s speed is the derivative of its distance, so adding up the speeds gives the change in distance, d(3)−d(0)d(3)-d(0). This is the accumulation idea, and the shortcut at once. Differentiation and integration undo each other: part 1 says differentiating an integral returns the function, and part 2 says integrating a derivative returns the change.

Part 1 is useful even when you cannot find a formula. For A(x)=∫0xe−t2dtA(x)=\int_0^x\mathrm{e}^{-t^2}dt there is no simple AA, yet part 1 tells you at once that A′(x)=e−x2A'(x)=\mathrm{e}^{-x^2}.

Antiderivatives: the rules backwards

Every derivative rule of P1.C2 gives an integral rule when read backwards. Always check an answer by differentiating it.

  • Powers. For n≠−1n\ne-1: ∫xn dx=xn+1n+1+C\displaystyle\int x^n\,dx=\frac{x^{n+1}}{n+1}+C. The derivative of the right side is (n+1)xnn+1=xn\frac{(n+1)x^n}{n+1}=x^n. Examples: ∫1 dx=x\int1\,dx=x, ∫x dx=x22\int x\,dx=\frac{x^2}2, ∫x−2dx=−1x\int x^{-2}dx=-\frac1x (on either side of 0), ∫x dx=23x3/2\int\sqrt x\,dx=\frac23x^{3/2} (for x≥0x\ge0).
  • The exception, n=−1n=-1. The formula would divide by 00. A different function does the job: (ln⁡x)′=1x(\ln x)'=\frac1x for x>0x>0 (P1.C2), and for x<0x<0 the derivative of ln⁡∣x∣\ln|x| is also 1x\frac1x (a central difference at x=−2x=-2 gives −0.5=1−2-0.5=\frac1{-2}; the chain rule of P1.C3 shows why). So ∫1x dx=ln⁡∣x∣+C\int\frac1x\,dx=\ln|x|+C on each side of 0 separately. The integral ∫ab1x dx=ln⁡b−ln⁡a\int_a^b\frac1x\,dx=\ln b-\ln a is valid when 0<a<b0<a<b (or a<b<0a<b<0 with ∣⋅∣|{\cdot}|), and not when 00 lies between aa and bb: there 1x\frac1x is not defined at 0 and its area is infinite on each side.
  • Exponentials. ∫exdx=ex+C\int\mathrm{e}^{x}dx=\mathrm{e}^{x}+C, and for a constant k≠0k\ne0, ∫ekxdx=ekxk+C\int\mathrm{e}^{kx}dx=\frac{\mathrm{e}^{kx}}k+C. Check by the limit of P1.C1: ek(x+h)−ekxh=ekxekh−1h→k ekx\frac{\mathrm{e}^{k(x+h)}-\mathrm{e}^{kx}}{h}=\mathrm{e}^{kx}\frac{\mathrm{e}^{kh}-1}{h}\to k\,\mathrm{e}^{kx}, because eu−1u→1\frac{\mathrm{e}^{u}-1}{u}\to1 with u=khu=kh. For example ∫0be−xdx=[−e−x]0b=1−e−b\int_0^b\mathrm{e}^{-x}dx=\bigl[-\mathrm{e}^{-x}\bigr]_0^b=1-\mathrm{e}^{-b}, the curve of the widget.
  • Sine. ∫sin⁡x dx=−cos⁡x+C\int\sin x\,dx=-\cos x+C. This uses (cos⁡x)′=−sin⁡x(\cos x)'=-\sin x, a fact from a table of derivatives that is not derived in this course; the widget’s sums for ∫0πsin⁡x dx=2\int_0^\pi\sin x\,dx=2 agree with −cos⁡π+cos⁡0=2-\cos\pi+\cos0=2.
  • Sums and multiples. ∫(f+g)=∫f+∫g\int\bigl(f+g\bigr)=\int f+\int g and ∫c f=c∫f\int c\,f=c\int f. For example ∫02(3x2−2x+1) dx=[x3−x2+x]02=8−4+2=6\int_0^2(3x^2-2x+1)\,dx=\bigl[x^3-x^2+x\bigr]_0^2=8-4+2=6.

The constant CC. Adding any constant to an antiderivative gives another antiderivative, since constants have derivative 0. ∫f(x) dx=F(x)+C\int f(x)\,dx=F(x)+C writes “all of them” at once, and is called the indefinite integral (a family of functions). In a definite integral CC cancels: (F(b)+C)−(F(a)+C)=F(b)−F(a)(F(b)+C)-(F(a)+C)=F(b)-F(a). So you may take C=0C=0 there.

Not every function has a closed-form antiderivative. The integral of e−x2\mathrm{e}^{-x^2} cannot be written with powers, exponentials, logarithms and the other functions of this course (this has been proved, not just failed to be found). Its definite integrals still exist as numbers and can be computed by sums. Techniques for finding harder antiderivatives, such as substitution (the chain rule of P1.C3 read backwards) and integration by parts, are not part of this lesson; a computer does them, and ML rarely needs them by hand.

When there is no formula: numerical integration

Most integrals in ML have no antiderivative you can write down, or involve data. Then we use Riemann sums directly. The sum is simply a loop, and the rules differ in cost and accuracy:

  • Midpoint and trapezoid rules are better than left and right for smooth functions (error of order 1n2\frac1{n^2}), at about the same cost (the trapezoid rule uses n+1n+1 function values, since neighbouring strips share an end).
  • With measured points only (for example a list of yy values at given xx values) the trapezoid rule is the natural choice: NumPy’s numpy.trapezoid(y, x) computes it. Newer NumPy versions have the name trapezoid and deprecate the older name numpy.trapz; NumPy 2.2.1, used to check this lesson, still has both and warns when trapz is used, and a deprecated name may be removed in a later version. The code cells here use plain Python so they run in your browser without NumPy.
  • Libraries also have adaptive routines (SciPy’s scipy.integrate.quad is one) that choose the strips for you.
  • A grid of nn points per axis costs ndn^d evaluations in dd dimensions, which is hopeless for large dd. Averaging over random points instead (Monte Carlo, P1.D9) is how high-dimensional integrals are estimated in ML.

Going to infinity: improper integrals

A density for a waiting time runs from 0 to ∞\infty. An integral over an unbounded range is defined as a limit:

∫a∞f(x) dx=lim⁡b→∞∫abf(x) dx,\int_a^\infty f(x)\,dx=\lim_{b\to\infty}\int_a^b f(x)\,dx,

when this limit is a finite number (we say the integral converges). For f(x)=e−xf(x)=\mathrm{e}^{-x}: ∫0be−xdx=1−e−b\int_0^b\mathrm{e}^{-x}dx=1-\mathrm{e}^{-b}, which is 0.632, 0.865, 0.993, 0.999950.632,\ 0.865,\ 0.993,\ 0.99995 for b=1, 2, 5, 10b=1,\ 2,\ 5,\ 10. It tends to 1, so

∫0∞e−x dx=1.\int_0^\infty\mathrm{e}^{-x}\,dx=1 .

The tail does shrink fast: beyond x=5x=5 the area is e−5=0.0067\mathrm{e}^{-5}=0.0067. An integral over the whole line is split at any point, ∫−∞∞=∫−∞0+∫0∞\int_{-\infty}^{\infty}=\int_{-\infty}^{0}+\int_{0}^{\infty}, and both halves must converge.

A height that tends to 0 is not enough. Compare 1x2\frac1{x^2} and 1x\frac1x on [1,b][1,b]. The first has area 1−1b1-\frac1b, which tends to 1. The second has area ln⁡b\ln b, which keeps growing: 2.302.30 at b=10b=10, 4.614.61 at b=100b=100, 13.813.8 at b=106b=10^6. So ∫1∞x−2dx=1\int_1^\infty x^{-2}dx=1, but ∫1∞1x dx\int_1^\infty\frac1x\,dx does not converge, though 1x→0\frac1x\to0 too.

Why probability needs integrals

A continuous quantity, such as a waiting time or a pixel intensity, can take any value in a range, so the probability of one exact value is 0 (there are too many values to share the total). Instead we describe it with a probability density p(x)p(x) and give the probability of an interval as an area:

P(a≤X≤b)=∫abp(x) dx,p(x)≥0,∫−∞∞p(x) dx=1.\begin{aligned} P(a\le X\le b)&=\int_a^b p(x)\,dx,\\ p(x)&\ge0,\\ \int_{-\infty}^{\infty}p(x)\,dx&=1 . \end{aligned}

(P1.D2 is the lesson about random variables and densities; this lesson gives the integral part.) The height p(x)p(x) is probability per unit of xx, not a probability. It can be above 1: a density that is 2 on an interval of width 0.50.5 has area 2×0.5=12\times0.5=1.

Uniform density. All values in [0,2][0,2] are equally likely: p(x)=12p(x)=\tfrac12 there and 0 elsewhere. The total area is 12×2=1\tfrac12\times2=1. The probability of [0.5,1.5][0.5,1.5] is 12×1=12\tfrac12\times1=\tfrac12.

Exponential density. For a waiting time, p(x)=e−xp(x)=\mathrm{e}^{-x} for x≥0x\ge0 (and 0 for x<0x<0). The total area is 1 (the improper integral above). Probabilities are areas: P(X≤1)=1−e−1=0.632P(X\le1)=1-\mathrm{e}^{-1}=0.632, P(1≤X≤2)=e−1−e−2=0.2325P(1\le X\le2)=\mathrm{e}^{-1}-\mathrm{e}^{-2}=0.2325 and P(X≥2)=e−2=0.1353P(X\ge2)=\mathrm{e}^{-2}=0.1353; the three add to 1, as three areas that tile the whole should.

The CDF is an accumulation function. The cumulative distribution function FX(x)=P(X≤x)=∫−∞xp(t) dtF_X(x)=P(X\le x)=\int_{-\infty}^{x}p(t)\,dt (written FXF_X so it is not confused with an antiderivative FF) is the area so far, so by part 1 of the fundamental theorem FX′(x)=p(x)F_X'(x)=p(x). For the exponential density, FX(x)=1−e−xF_X(x)=1-\mathrm{e}^{-x} (for x≥0x\ge0) and FX′(x)=e−x=p(x)F_X'(x)=\mathrm{e}^{-x}=p(x). The sigmoid of P1.A5 is also a CDF: σ\sigma is the CDF of the standard logistic distribution. Its slope σ′(x)=σ(x)(1−σ(x))\sigma'(x)=\sigma(x)\bigl(1-\sigma(x)\bigr) (P1.C1, P1.C2) is the bell-shaped logistic density, with total area σ(∞)−σ(−∞)=1−0=1\sigma(\infty)-\sigma(-\infty)=1-0=1 by part 2, and P(X≤2)=σ(2)=0.881P(X\le2)=\sigma(2)=0.881. (P1.D2 develops CDFs.)

Expected value. The mean of discrete values is a weighted sum ∑xi pi\sum x_i\,p_i. For a density the sum becomes an integral, E[X]=∫x p(x) dx\mathbb{E}[X]=\int x\,p(x)\,dx: each value xx is weighted by the probability p(x) dxp(x)\,dx of landing in a thin strip around it. For the uniform density on [0,2][0,2]: ∫02x⋅12 dx=[x24]02=1\int_0^2x\cdot\tfrac12\,dx=\bigl[\tfrac{x^2}4\bigr]_0^2=1, the middle of the range. For e−x\mathrm{e}^{-x} it is 1 as well (finding it needs integration by parts, not taught here; a fine numerical sum agrees with 1 to eight decimal places, which is a check, not a proof). P1.D4 covers expectation properly.

Normalising constants. The Gaussian bell e−x2/2\mathrm{e}^{-x^2/2} has total area ∫−∞∞e−x2/2 dx=2π=2.5066…\int_{-\infty}^{\infty}\mathrm{e}^{-x^2/2}\,dx=\sqrt{2\pi}=2.5066\ldots The function e−x2/2\mathrm{e}^{-x^2/2} has no antiderivative made from elementary functions; the value is a known result whose proof (not given here) uses two dimensions, and the sums below agree. To make the total area exactly 1, the standard normal density divides by it: p(x)=12πe−x2/2p(x)=\frac1{\sqrt{2\pi}}\mathrm{e}^{-x^2/2}, whose peak height is 0.39890.3989 (P1.D3). Any “unnormalised” density becomes a real one when you divide it by its total area, which is an integral.

Area under the ROC curve (AUC). A classifier’s ROC curve plots the true-positive rate against the false-positive rate as the decision threshold moves; AUC is the area under it, 1 for a perfect classifier and 12\tfrac12 for the diagonal, which is random guessing (P3.A9). A ROC curve is a list of points, so its area is found with the trapezoid rule (scikit-learn’s auc function is documented as using it). For the points (0,0), (0.25,0.5), (0.5,0.75), (1,1)(0,0),\ (0.25,0.5),\ (0.5,0.75),\ (1,1) the three trapezoids have areas 0.0625, 0.15625, 0.43750.0625,\ 0.15625,\ 0.4375, and the AUC is 0.656250.65625.

The average value of a function

The average value of ff on [a,b][a,b] is

fˉ=1b−a∫abf(x) dx.\bar f=\frac1{b-a}\int_a^b f(x)\,dx .

It is the height of the rectangle on [a,b][a,b] with the same area as the region under the curve. Why this deserves the name: divide a Riemann sum by b−ab-a. Since Δx=b−an\Delta x=\frac{b-a}n,

1b−a∑i=1nf(xi) Δx=1n∑i=1nf(xi),\frac1{b-a}\sum_{i=1}^{n}f(x_i)\,\Delta x=\frac1n\sum_{i=1}^{n}f(x_i),

the ordinary mean of nn evenly spaced heights. The average value is what those means approach as n→∞n\to\infty. For f(x)=x2f(x)=x^2 on [0,3][0,3]: ∫03x2dx=9\int_0^3x^2dx=9, so fˉ=93=3\bar f=\frac93=3. The mean of the three heights at 0.5, 1.5, 2.50.5,\ 1.5,\ 2.5 is 0.25+2.25+6.253=2.917\frac{0.25+2.25+6.25}3=2.917, and with 100 midpoints it is 2.99992.9999.

For the toy car, vˉ=93=3\bar v=\frac{9}{3}=3 m/s is the average speed: d(3)−d(0)3−0\frac{d(3)-d(0)}{3-0}, the average rate of change of P1.C1. In general the average value of a derivative F′F' is F(b)−F(a)b−a\frac{F(b)-F(a)}{b-a}.

The link to machine learning. A model’s expected loss over a distribution of inputs, with density pp, is an integral E[L]=∫L(x) p(x) dx\mathbb{E}[L]=\int L(x)\,p(x)\,dx, a weighted average of the loss. The loss L\mathcal{L} averaged over NN training examples is 1N∑L(xi)\frac1N\sum L(x_i): the same shape of formula, with the data points playing the part of the sample points. This works when the examples are independent draws from pp: the weighting by pp then happens by itself, because points land where pp is large. The data average estimates the expected loss, and on average gets closer as NN grows (the law of large numbers, P1.D8; sampling and Monte Carlo, P1.D9). That is why minimising the training loss is a sensible stand-in for minimising the loss on the whole distribution.

Integrals in three depths

Intuition

Cut a stretch into thin pieces, find how much accumulates on each piece (rate times width), and add. Thinner pieces give a better answer, and in the limit the answer is exact: the area under the rate curve. The slope of “the area so far” is the height of the curve, so finding a total is the reverse of finding a rate. In probability, the area under a density over an interval is the chance of that interval.

Math

∫abf(x) dx=lim⁡n→∞∑i=1nf(xi) Δx,Δx=b−an.\begin{gathered} \int_a^b f(x)\,dx=\lim_{n\to\infty}\sum_{i=1}^{n}f(x_i)\,\Delta x, \\ \Delta x=\tfrac{b-a}n . \end{gathered}

Signed area; linearity; additivity over intervals. Fundamental theorem: A(x)=∫axf(t) dt⇒A′=fA(x)=\int_a^xf(t)\,dt\Rightarrow A'=f; and ∫abf=F(b)−F(a)\int_a^bf=F(b)-F(a) when F′=fF'=f. Antiderivatives: ∫xn=xn+1n+1\int x^n=\frac{x^{n+1}}{n+1} (n≠−1n\ne-1), ∫1x=ln⁡∣x∣\int\frac1x=\ln|x|, ∫ekx=ekxk\int\mathrm{e}^{kx}=\frac{\mathrm{e}^{kx}}k (k≠0k\ne0). Error orders: left and right O(1n)O(\frac1n), midpoint and trapezoid O(1n2)O(\frac1{n^2}) for smooth ff. Density: P(a≤X≤b)=∫abpP(a\le X\le b)=\int_a^bp, ∫p=1\int p=1, F′=pF'=p, E[X]=∫xp\mathbb{E}[X]=\int xp. Average value 1b−a∫abf\frac1{b-a}\int_a^bf.

Code

def riemann(f, a, b, n, rule="midpoint"):
    dx = (b - a) / n
    xs = [a + (i + {"left": 0, "right": 1, "midpoint": 0.5}[rule]) * dx for i in range(n)]
    return sum(f(x) for x in xs) * dx

riemann(lambda x: x * x, 0, 1, 1000)    # about 0.33333

With NumPy, for measured points, the trapezoid rule is one call:

import numpy as np
x = np.linspace(0, np.pi, 101)
np.trapezoid(np.sin(x), x)   # about 2 (newer NumPy versions; older ones call it np.trapz)

Try it: errors of Riemann sums, and probabilities as areas

The first cell builds the four rules and prints their errors as nn doubles. Predict the pattern before you run it: which columns drop by a factor of 2, and which by 4? The second cell computes the areas of the lesson’s densities and the AUC example.

Try it: four Riemann sums and their errors

Runs real Python in your browser. First run downloads about 6 MB (once; your browser keeps it).

Challenge: change f to math.exp and the interval to [0,1][0,1] (exact value e−1\mathrm{e}-1). Which rule is closest at n=10n=10, and is the sum above or below the exact value for the left rule?

Try it: probabilities as areas

Runs real Python in your browser. First run downloads about 6 MB (once; your browser keeps it).

Challenge: the uniform density on [0,2][0,2] is 12\tfrac12. Use midpoint to compute E[X]=∫02x⋅12 dx\mathbb{E}[X]=\int_0^2 x\cdot\tfrac12\,dx and compare it with 1.

Common mistakes

Check your understanding

  1. Estimate ∫01x2 dx\int_0^1x^2\,dx with the left rule and 4 strips. You get 0.218750.21875, below the true value 13\frac13. Why is the left sum too small here?

  2. What is ∫02πsin⁡x dx\int_0^{2\pi}\sin x\,dx?

  3. Use an antiderivative to find ∫13x2 dx\int_1^3x^2\,dx.

  4. A random quantity has the density p(x)=2p(x)=2 for 0≤x≤0.50\le x\le0.5 and p(x)=0p(x)=0 elsewhere. Which statement is right?

  5. Why can the rule ∫xn dx=xn+1n+1+C\int x^n\,dx=\frac{x^{n+1}}{n+1}+C not be used for ∫1x dx\int\frac1x\,dx?

Exercises

  1. Let f(x)=x2f(x)=x^2 on [0,2][0,2] with n=4n=4 strips. Find the left, right and midpoint sums, and compare them with the exact value.
    Show answerΔx=0.5\Delta x=0.5. Left: 0.5 (0+0.25+1+2.25)=1.750.5\,(0+0.25+1+2.25)=1.75. Right: 0.5 (0.25+1+2.25+4)=3.750.5\,(0.25+1+2.25+4)=3.75. Midpoint, with heights at 0.25, 0.75, 1.25, 1.750.25,\ 0.75,\ 1.25,\ 1.75: 0.5 (0.0625+0.5625+1.5625+3.0625)=2.6250.5\,(0.0625+0.5625+1.5625+3.0625)=2.625. The exact value is 233=83=2.6667\frac{2^3}3=\frac83=2.6667, between the left and right sums, with the midpoint closest.
  2. Evaluate ∫14x dx\int_1^4\sqrt x\,dx and ∫02(3x2−2x+1) dx\int_0^2(3x^2-2x+1)\,dx.
    Show answer∫x dx=23x3/2\int\sqrt x\,dx=\frac23x^{3/2}, so the first is 23(8−1)=143≈4.667\frac23(8-1)=\frac{14}3\approx4.667. For the second, F(x)=x3−x2+xF(x)=x^3-x^2+x, so F(2)−F(0)=8−4+2=6F(2)-F(0)=8-4+2=6.
  3. Evaluate ∫03(x−1) dx\int_0^3(x-1)\,dx. What is the area above the axis, the area below, and the total area between the line and the axis?
    Show answerF(x)=x22−xF(x)=\frac{x^2}2-x. The integral is F(3)−F(0)=1.5F(3)-F(0)=1.5. The line is below the axis on [0,1][0,1], with area 12\frac12 (integral −12-\frac12), and above it on [1,3][1,3], with area 22. So the integral is 2−12=1.52-\frac12=1.5, and the total area between line and axis is 2.52.5.
  4. Find ∫1e1x dx\int_1^{\mathrm{e}}\frac1x\,dx, and explain why the same method does not work for ∫−111x dx\int_{-1}^{1}\frac1x\,dx.
    Show answer[ln⁡x]1e=1−0=1[\ln x]_1^{\mathrm{e}}=1-0=1. For ∫−11\int_{-1}^{1}, the interval contains 0, where 1x\frac1x is not defined and its height is unbounded. Writing ln⁡∣1∣−ln⁡∣−1∣=0\ln|1|-\ln|-1|=0 would be wrong: the area on each side of 0 is infinite, so the integral is not a finite number.
  5. Find ddx∫0xe−t2 dt\frac{d}{dx}\int_0^x\mathrm{e}^{-t^2}\,dt without finding the integral.
    Show answerBy part 1 of the fundamental theorem, it is e−x2\mathrm{e}^{-x^2}.
  6. The function p(x)=3x2p(x)=3x^2 on [0,1][0,1] (and 0 elsewhere) is a density. Check that its total area is 1, find P(X≤0.5)P(X\le0.5) and E[X]\mathbb{E}[X].
    Show answer∫013x2dx=[x3]01=1\int_0^13x^2dx=[x^3]_0^1=1. P(X≤0.5)=0.53=0.125P(X\le0.5)=0.5^3=0.125. E[X]=∫01x⋅3x2 dx=[3x44]01=34\mathbb{E}[X]=\int_0^1x\cdot3x^2\,dx=\bigl[\frac{3x^4}4\bigr]_0^1=\frac34.
  7. Find the average value of sin⁡x\sin x on [0,π][0,\pi].
    Show answer1π∫0πsin⁡x dx=2π≈0.637\frac1\pi\int_0^\pi\sin x\,dx=\frac2\pi\approx0.637.
  8. A tap runs at r(t)=2tr(t)=2t litres per minute for the first 3 minutes. How much water has flowed? Which part of the lesson does this match?
    Show answer∫032t dt=32=9\int_0^32t\,dt=3^2=9 litres: the toy car’s speed again, with litres per minute ×\times minutes == litres. The total is the area under the rate curve.
  9. A ROC curve passes through (0,0), (0.5,0.8), (1,1)(0,0),\ (0.5,0.8),\ (1,1). Find the AUC with the trapezoid rule.
    Show answer0.5⋅0+0.82+0.5⋅0.8+12=0.2+0.45=0.650.5\cdot\frac{0+0.8}2+0.5\cdot\frac{0.8+1}2=0.2+0.45=0.65.
  10. Does ∫1∞1x3 dx\int_1^\infty\frac1{x^{3}}\,dx converge? If so, to what?
    Show answer∫1bx−3dx=[−12x2]1b=12−12b2→12\int_1^b x^{-3}dx=\bigl[-\frac1{2x^2}\bigr]_1^b=\frac12-\frac1{2b^2}\to\frac12. It converges to 12\frac12.

Next: P1.C10 shows how a computer finds the derivatives of whole programs exactly. Integrals return in Module 1D, where densities and the areas of this lesson give probability its continuous half.

Key takeaways

  • A total from a rate: if something changes at rate f(x)f(x), then over a short stretch of width Δx\Delta x it gains about f(x) Δxf(x)\,\Delta x. Add up the pieces. This is the area of a thin rectangle of height f(x)f(x) and width Δx\Delta x, so the total is the area under the curve. Its unit is (rate unit) ×\times (input unit), for example (metres per second) ×\times seconds == metres.
  • A Riemann sum with nn strips of width Δx=b−an\Delta x=\frac{b-a}{n} is ∑f(xi) Δx\sum f(x_i)\,\Delta x, with the height read at the left end, the right end or the middle of each strip (or 12\tfrac12 of the sum of both ends, the trapezoid rule). As n→∞n\to\infty all of them head to the same number, the definite integral ∫abf(x) dx\int_a^b f(x)\,dx.
  • Area below the axis counts as negative: ∫02πsin⁡x dx=0\int_0^{2\pi}\sin x\,dx=0 although the shaded region is not empty. For a smooth ff the left and right errors shrink like 1/n1/n and the midpoint and trapezoid errors like 1/n21/n^2 (halving the strip width cuts them by about 2 and by about 4).
  • Fundamental theorem of calculus. Part 1: the accumulation function A(x)=∫axf(t) dtA(x)=\int_a^x f(t)\,dt has A′(x)=f(x)A'(x)=f(x), because a thin new strip has area about f(x) hf(x)\,h. Part 2: if F′=fF'=f then ∫abf(x) dx=F(b)−F(a)\int_a^b f(x)\,dx=F(b)-F(a). Integrating undoes differentiating, and the integral of a rate is the total change.
  • Antiderivatives run the rules of P1.C2 backwards: ∫xn dx=xn+1n+1+C\int x^n\,dx=\frac{x^{n+1}}{n+1}+C for n≠−1n\ne-1, ∫1x dx=ln⁡∣x∣+C\int\frac1x\,dx=\ln|x|+C on each side of 0, ∫ex dx=ex+C\int\mathrm{e}^{x}\,dx=\mathrm{e}^{x}+C. The constant CC cancels in F(b)−F(a)F(b)-F(a). Many functions (such as e−x2\mathrm{e}^{-x^2}) have no antiderivative made from elementary functions (powers, exponentials, logarithms, sines and the like), so numerical sums such as the trapezoid rule are used.
  • Probability. A density p(x)≥0p(x)\ge0 gives P(a≤X≤b)=∫abp(x) dxP(a\le X\le b)=\int_a^b p(x)\,dx, and the total area is 1. A density is probability per unit of xx, so it can exceed 1. The CDF is an accumulation function, the expected value is ∫x p(x) dx\int x\,p(x)\,dx, and the Gaussian's constant 2π\sqrt{2\pi} is the area under e−x2/2\mathrm{e}^{-x^2/2}.
  • The average value of ff on [a,b][a,b] is 1b−a∫abf(x) dx\frac1{b-a}\int_a^b f(x)\,dx: the limit of the ordinary mean of nn evenly spaced heights. An average over a data set is the same shape of formula, and it estimates an expected value.
Found a mistake? Tell us