Integrals: area under a curve: study notes

 

1.27 Integrals: area under a curve: study notes

Learn AI by Story

1. The idea in one sentence

An integral adds up an enormous number of tiny pieces to give a total, and the simplest picture of it is the area trapped between a curve and the horizontal axis.

2. The story from the video

Kiran's car odometer is broken, but the speedometer still works, and he has a chart of speed against time. At a steady 4 m/s for 3 seconds, the distance is a plain rectangle: 4 x 3 = 12 m. Then the speed grows smoothly from 0 to 6 m/s over 3 seconds (v = 2t), and the chart becomes a triangle with area 1/2 x 3 x 6 = 9 m. The lesson: the area under a speed chart is the distance travelled. When the top edge is curved, Kiran slices the area into thin boxes, adds them up, and gets closer to the truth as the boxes get thinner. That limit of box-sums is the integral.

3. Key definitions (glossary)

  • Function: a rule that turns an input x into an output f(x). Plain English: a machine with one input and one output. Here, f(x) is the height of the curve at position x.
  • Area under a curve: the region between the graph of f, the x-axis, and two vertical lines at x = a and x = b. Plain English: the shaded patch you would colour in beneath the curve.
  • Signed area: area above the axis counts positive, area below the axis counts negative. Plain English: the integral is a running balance, not a plain size. A curve that dips below zero subtracts.
  • Riemann sum: a sum of the form f(x1)Δx + f(x2)Δx + ... where each term is the area of a thin rectangle of width Δx and height f at some chosen point in that slice. Plain English: add up boxes that approximate the area.
  • Δx (delta x): the width of each slice, equal to (b − a) divided by the number of boxes n. Plain English: how thick each box is.
  • Left, right and midpoint rules: the three ways to choose the box height. Left uses the curve height at the left edge of the slice, right uses the right edge, midpoint uses the middle.
  • Trapezoid rule: instead of flat-topped boxes, use slanted tops joining the curve at both edges of each slice. It is the average of the left and right sums.
  • Definite integral: the limit of the Riemann sums as the number of boxes goes to infinity and the width goes to zero, written ∫ from a to b of f(x) dx. Plain English: the exact signed area between a and b. The result is a single number.
  • Integrand: the function f(x) being integrated. Plain English: the thing under the integral sign.
  • Limits of integration: the numbers a and b at the bottom and top of the integral sign, marking where the area starts and stops.
  • dx: a reminder of which variable is being summed over, and the infinitely thin width of each slice. Plain English: it says 'width of a slice, in the x direction'.
  • Antiderivative (indefinite integral): a function F whose derivative is f, so F'(x) = f(x). Plain English: undo differentiation. It is only defined up to adding a constant C.
  • Fundamental theorem of calculus: if F' = f then the definite integral from a to b of f equals F(b) − F(a). Plain English: to get an area, find the antiderivative and subtract its values at the two ends. No box-adding needed.
  • Accumulation function: A(x) = integral from a to x of f(t) dt, the area collected so far. Plain English: the odometer reading when f is speed.
  • Change of variables (substitution): replace x with a new variable u = g(x) to make an integral easier; the dx changes accordingly. Plain English: re-measure the axis to make the shape simpler.
  • Multiple integral: an integral over two or more variables, such as the volume under a surface. Plain English: area-under-curve one dimension up.
  • Probability density function (PDF): a non-negative function p(x) whose total area is 1. Plain English: probability lives in area, not in the height.
  • Expected value: E[g(X)] = integral of g(x) p(x) dx. Plain English: the probability-weighted average of g, with an integral standing in for the usual sum.
  • Numerical integration (quadrature): computing an integral by adding up function values by machine instead of finding an antiderivative.
  • Improper integral: an integral with an infinite limit or an unbounded integrand, such as the whole real line for a normal density.

4. Step-by-step explanation, from basics to the full picture

Step 1. Rate times time is an amount. If something moves at constant speed v for time t, the distance is v x t. On a chart with time on the horizontal axis and speed on the vertical axis, that product is the area of a rectangle of height v and width t. So 4 m/s for 3 s is a rectangle 4 tall and 3 wide, area 12 m. This is the seed of the whole idea: height times width is an amount, whenever the height is a rate.

Step 2. Shapes with straight edges are still geometry. For v = 2t over 3 seconds, the speed at the end is 6 m/s and the shape is a right triangle with base 3 and height 6. The area is 1/2 x base x height = 9 m. A school formula answers the question without any calculus. Kiran can check it: at t = 3 the odometer should read 9 m.

Step 3. Curved edges break the formulas. For a curve such as f(x) = x^2 there is no rectangle or triangle formula. The trick is to chop the region into narrow vertical strips. Each strip is almost a rectangle: its top is nearly flat if the strip is thin. Replace each strip with a true rectangle, add the areas, and you get an estimate.

Step 4. Choose the box height. The rectangle's height can be the curve height at the left edge, the right edge or the middle. For an increasing curve, left boxes sit under the curve and underestimate; right boxes poke above and overestimate; midpoint boxes cancel much of the error. This is why the three estimates for x^2 in Section 6 bracket the true answer.

Step 5. More boxes, less error. Doubling the number of boxes roughly halves the gap for left and right sums, and shrinks the midpoint gap even faster. In the limit of infinitely many infinitely thin boxes, every choice of height gives the same number. That shared limit is the definite integral. The notation says exactly this: the long S in the integral sign stands for 'sum', and dx stands for 'a very thin width'.

Step 6. The shortcut: the fundamental theorem. Summing boxes is slow. The remarkable fact is that area-accumulation and slope are opposites. If A(x) is the area collected from 0 up to x, then the rate at which A grows is the height of the curve there: A'(x) = f(x). So A is an antiderivative of f. To compute the area from a to b, find any antiderivative F and calculate F(b) − F(a). For x^2 the antiderivative is x^3/3, so the area from 0 to 2 is 8/3 − 0 = 2.6667. The constant C cancels in the subtraction, which is why the definite integral is a single number.

Step 7. Signed area. If f dips below the axis, those boxes have negative height and subtract. The integral of sin x over a full period is zero because the hump above cancels the hump below. If you want total size regardless of sign, integrate the absolute value of f instead.

Step 8. Why this matters for machines. Many quantities in AI are integrals: the total probability under a density, the average of a function under a distribution, the area under a classifier's ROC curve. Most of them cannot be solved by hand, so we use the same box idea in computers (numerical integration) or random sampling (Monte Carlo). The picture in your head, thin slices added up, is the same one.

5. Everything the video skipped

Rules worth knowing (formulas in simple words).

  • Power rule: the integral of x^n is x^(n+1) divided by (n+1), for n not equal to −1. Raise the power by one and divide by the new power.
  • The integral of 1/x is the natural log of the absolute value of x. This is the one power the rule cannot handle, and it links to 1.28 on logs.
  • The integral of e^x is e^x, the only function that is its own antiderivative (up to a constant factor).
  • Linearity: the integral of (a f + b g) is a times the integral of f plus b times the integral of g.
  • Splitting: the area from a to c equals the area from a to b plus b to c.
  • Reversing the limits flips the sign.
  • Integration by parts and substitution (change of variables) are the two workhorse techniques for harder integrals. Substitution is the chain rule run backwards.

Variants of the idea.

  • Riemann integral: the box construction described above. It works for continuous and well-behaved functions.
  • Improper integrals: let a limit run to infinity, as with the normal density over the whole line. They converge only if the tails shrink fast enough.
  • Multiple integrals: slice in two directions and add up small columns. Probability over several variables, such as a joint density p(x, y), uses these. The d2l appendix on integral calculus covers multiple integrals and change of variables.
  • Numerical rules: midpoint, trapezoid and Simpson's rule (which fits small parabolas). Error shrinks faster for smoother functions.
  • Monte Carlo integration: pick random points, average the function values, and multiply by the interval length. It scales better than boxes when there are many dimensions, because a grid with 10 boxes per axis needs 10^d boxes in d dimensions.

Background (history). The area-by-exhaustion idea goes back to ancient Greek mathematicians, who bracketed areas with shapes they could measure. In the 1600s Newton and Leibniz independently saw the link between slope and area, which became the fundamental theorem. Riemann made the box construction rigorous in the 1800s, hence the name Riemann sum. Treat these as background context rather than precise dates.

Limitations.

  • Many useful functions have no antiderivative in neat closed form. The normal density e^(−x^2/2) is the classic case, so its areas are tabulated or computed numerically.
  • Boxes struggle in high dimensions (the curse of dimensionality).
  • A very spiky function can fool a rough grid.
  • Always check that the area is finite before trusting it.

Where it sits on the roadmap. Integrals are the partner of derivatives from the earlier calculus topics, including 1.25 Jacobian and Hessian and 1.26 Taylor approximation (Taylor series can be integrated term by term). Right next door, 1.28 Logs, exponentials, sigmoid and softmax uses the integral of 1/x to define the natural log, and 1.29 Numerical stability shows what goes wrong when machines handle huge or tiny numbers. Module 2 later brings in expectations, likelihoods and loss functions such as 2.05, which all lean on integrals or their discrete sums.

6. Worked examples with real numbers

Example A: constant and linear speed (the video's chart).

  1. Constant speed 4 m/s for 3 s. Area = 4 x 3 = 12 m.
  2. Speed v = 2t from 0 to 3 s. At t = 3, v = 6 m/s. Triangle area = 1/2 x 3 x 6 = 9 m.
  3. Check with calculus: the antiderivative of 2t is t^2. F(3) − F(0) = 9 − 0 = 9 m. The geometry and the calculus agree.

Example B: the area under x^2 from 0 to 2, by boxes. The exact answer is F(2) − F(0) with F(x) = x^3/3, so 8/3 = 2.6667.

Four boxes: each has width 0.5. The curve heights are at x = 0, 0.5, 1, 1.5, 2: 0, 0.25, 1, 2.25, 4.

  • Right endpoints: 0.5 x (0.25 + 1 + 2.25 + 4) = 3.75.
  • Left endpoints: 0.5 x (0 + 0.25 + 1 + 2.25) = 1.75.
  • Midpoints at 0.25, 0.75, 1.25, 1.75: heights 0.0625, 0.5625, 1.5625, 3.0625. Sum 5.25, times 0.5 gives 2.625.
  • Trapezoid rule (average of left and right): (1.75 + 3.75) / 2 = 2.75.

With 100 boxes: left 2.6268, right 2.7068, midpoint 2.6666. The exact value is 2.6667. Notice that the left and right sums squeeze the truth from below and above, and the gap between them is just the width of one box times the total rise (0.02 x 4 = 0.08, and 2.7068 − 2.6268 = 0.08). The midpoint rule is far more accurate for the same effort.

Example C: the normal curve. For a standard normal density, the area between −1 and 1 is 0.6827, so about 68 percent of values land within one standard deviation of the mean. The total area from minus infinity to plus infinity is 1, as it is for every density. No neat antiderivative exists, so this 0.6827 comes from numerical integration.

Example D: an expected value as an integral. If X is uniform on 0 to 4, the density is the constant 1/4 over that interval, because the area must be 1 (a rectangle 4 wide and 1/4 tall). Then E[X] = integral from 0 to 4 of x x (1/4) dx = (1/4) x (4^2 / 2) = (1/4) x 8 = 2. The mean is the midpoint, as common sense predicts.

7. Comparison tables

Box rules for the same curve (x^2 on 0 to 2, exact 2.6667)

Rule

4 boxes

100 boxes

Behaviour on an increasing curve

Left endpoints

1.75

2.6268

Always too low

Right endpoints

3.75

2.7068

Always too high

Midpoints

2.625

2.6666

Errors largely cancel

Trapezoid (average of left and right)

2.75

not computed

Slightly high for a bowl-shaped curve

Derivative versus integral

Question

Derivative

Integral

Asks

How fast is it changing right now?

How much has it added up in total?

Picture

Slope of the tangent line

Area under the curve

Output

A function

A number (definite) or a function (indefinite)

Inverse of

Integral

Derivative

Example with speed

Acceleration

Distance

Sum versus integral in AI

Discrete world

Continuous world

Probabilities add to 1

Density area is 1

E[g(X)] is the sum of g(x) p(x)

E[g(X)] is the integral of g(x) p(x) dx

Histogram bars

Smooth density curve

Counting

Measuring

8. Common mistakes and myths

  • Myth: an integral is just an area. Area is the picture, but the integral is signed. Area below the axis is negative. Use the absolute value if you want total size.
  • Mistake: forgetting the limits. An indefinite integral has a +C and is a function. A definite integral has limits and is a number.
  • Mistake: reading height as probability. For a continuous density the height can exceed 1 (a narrow, tall density is fine). Only the area is a probability.
  • Mistake: a single point has area. The probability of exactly one value of a continuous variable is zero. Probability comes from intervals.
  • Mistake: thinking more boxes always fix everything. They help for smooth functions, but a function with a spike narrower than the box width can be missed entirely.
  • Mistake: forgetting to subtract F(a). The fundamental theorem needs F(b) − F(a), not just F(b).
  • Mistake: mixing up units. Speed times time gives distance; the units multiply. This is a good sanity check on any integral.
  • Myth: every function has a neat antiderivative. Many do not, which is why numerical integration exists.
  • Mistake: differentiating when you should integrate (and vice versa) in the speed, distance and acceleration chain. Going from acceleration to speed to distance is integration; the other way is differentiation.

9. Real-life and AI uses

  • Probability densities. Every continuous distribution (normal, uniform, exponential) is defined by a curve whose area is 1. Questions such as 'what is the chance the value lies between a and b?' are integrals.
  • Expected value. The mean of a function g of a random variable is E[g(X)] = integral of g(x) p(x) dx (Mathematics for Machine Learning, Definition 6.3). Training objectives are often expectations over data, and Monte Carlo sampling approximates them.
  • ROC AUC. The area under the receiver operating characteristic curve summarises how well a classifier ranks positives above negatives. An AUC of 0.5 is random ranking and 1 is perfect. Software computes it by adding trapezoids (scikit-learn describes it as computing area under the ROC curve from prediction scores).
  • Bayesian inference and normalising constants. Posterior distributions need an integral to make them add up to 1, which is often the hard part and motivates sampling methods.
  • Physics and engineering. Distance from speed, energy from power, total rainfall from rate, charge from current.
  • Generative models. Models such as normalising flows use a change of variables, and the change-of-variables formula in integrals is its foundation.
  • Everyday. Your electricity bill is the integral of power over time: kilowatts times hours gives kilowatt-hours. A fuel gauge is an integral of flow rate.

10. Self-check questions (with answers)

  1. What is the distance travelled at a constant 4 m/s for 3 s, and why is it an area? 12 m. On a speed-time chart it is a rectangle of height 4 and width 3.
  2. What is the area under v = 2t from 0 to 3? 9 m, a triangle with base 3 and height 6, which is 1/2 x 3 x 6.
  3. Why do left boxes underestimate an increasing curve? Each box top sits at the curve height at its left edge, which is the lowest point in that slice, so the box lies under the curve.
  4. What happens to the estimate as the number of boxes grows? Left and right sums converge to the same number, the definite integral. For x^2 on 0 to 2 that number is 8/3 = 2.6667.
  5. State the fundamental theorem in words. The integral of f from a to b equals F(b) minus F(a), where F is any antiderivative of f.
  6. Why does the +C vanish in a definite integral? It appears in both F(b) and F(a), so it cancels in the subtraction.
  7. Why can a density have a height above 1? Because probability is the area, not the height. A narrow curve with height 5 and width 0.2 has area 1.
  8. What is the total area under any probability density? Exactly 1.
  9. What is the area under the standard normal curve between −1 and 1? About 0.6827.
  10. How does an integral appear in an expected value? E[g(X)] is the integral of g(x) p(x) dx, a probability-weighted average where a sum is replaced by an integral.

11. Key takeaways, go deeper, and next

Key takeaways

  • An integral is a limit of sums of thin boxes. The picture is area under a curve; the meaning is accumulation.
  • Speed to distance is the model case: area under a rate chart is the amount.
  • The fundamental theorem links area to antiderivatives: F(b) − F(a).
  • Boxes bracket the truth: left and right squeeze it, midpoint is the best of the three.
  • In AI, integrals show up as probability, expectation and AUC; computers usually evaluate them numerically.

Go deeper

  • Work through the d2l.ai appendix section on integral calculus, including multiple integrals and change of variables.
  • Code a small Riemann-sum function in Python and watch the error fall as n rises.
  • Look up the trapezoid and Simpson rules and compare their errors with the box rules.
  • Read the definition of expected value in Mathematics for Machine Learning.

Next on the roadmap: 1.28 Logs, exponentials, sigmoid and softmax math.

12. Sources and further reading

  • Dive into Deep Learning (d2l.ai), section 22.5 'Integral Calculus': https://d2l.ai/chapter_appendix-mathematics-for-deep-learning/integral-calculus.html. Covers area as a sum of thin rectangles, the fundamental theorem, change of variables and multiple integrals.
  • OpenStax, Calculus Volume 1, section 5.2 'The Definite Integral': https://openstax.org/books/calculus-volume-1/pages/5-2-the-definite-integral. Riemann sums and the limit definition of the definite integral.
  • Mathematics for Machine Learning (Deisenroth, Faisal, Ong, 2020), section 6.4.1 'Means and Covariances' (Definition 6.3, expected value as an integral): https://mml-book.github.io/book/mml-book.pdf
  • scikit-learn documentation, roc_auc_score ('Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores'): https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html

Accuracy note: The numbers in the worked examples (box sums, 8/3, 0.6827) were checked in Python on 2026-11-03; the AUC reading of 0.5 and 1 is standard background, and the history paragraph is general background rather than sourced dates.

Comments

Popular posts from this blog

What is AI? Narrow vs General Intelligence (Study Notes)

The five kinds of learning: study notes

Rules vs learning: study notes