Skip to content
AriadneTechnology

The Inner Ring · Chamber 9 of 9

Integrals: From Riemann Sums to Neural ODEs

Area as a limit of sums, the theorem that ties it to slope, and integrals at work in expectations, Monte Carlo and neural ODEs.

45 min 60 XP + 9 questions + 1 challengeMathVideoPapersProofsCodeLab

In this chamber you will

  • Approximate integrals with Riemann sums, and know which rules converge fastest
  • Prove and use the fundamental theorem of calculus
  • Integrate by substitution and by parts, and compute the Gaussian integral
  • Read a residual network as Euler's method and a neural ODE as an integral
DiscoverLearnRead beyondPapers & lecturesYour turn

A residual layer adds a small change to its current state. Let those changes become a continuous velocity field and the network becomes a differential equation. Recovering its final state requires accumulating change over time.

Spotted in the wild

z(t1)=z(t0)+∫t0t1f(z(t),t,θ) dt\mathbf z(t_1)=\mathbf z(t_0)+\int_{t_0}^{t_1}f(\mathbf z(t),t,\theta)\,dt
Neural Ordinary Differential Equations
DiscoverLearnRead beyondPapers & lecturesYour turn
Symbols for this chamber
  • Δx\Delta x“delta x”
    Width of one integration strip.
  • ∫abf(x)dx\int_a^b f(x)dx“integral of f from a to b”
    Signed accumulation over an interval.
  • F′=fF'=f“F prime equals f”
    An antiderivative relation.
  • ∣det⁡J∣\left|\det J\right|“absolute Jacobian determinant”
    Local volume factor in a change of variables.
  • O(n−2)O(n^{-2})“order n to the minus two”
    Error bounded by a constant times n to the minus two for large n.
  • z˙\dot z“z dot”
    Time derivative of the state.

An area is a limit of sums

Partition [a,b][a,b] into nn equal intervals of width Δx=(b−a)/n\Delta x=(b-a)/n. Pick xi∗x_i^* within each strip. For a continuous function,

∫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.

The integral is signed: contributions below the axis are negative. To measure unsigned area, integrate ∣f∣|f|. For x2x^2 on [0,1][0,1], the right sum is n−3∑i=1ni2=(n+1)(2n+1)/(6n2)n^{-3}\sum_{i=1}^n i^2=(n+1)(2n+1)/(6n^2), tending to 1/31/3.

Quick check +20 XP

What is ∫01x2dx\int_0^1 x^2dx?

The fundamental theorem

Define F(x)=∫axf(t) dtF(x)=\int_a^x f(t)\,dt for continuous f. Then

F(x+h)−F(x)h=1h∫xx+hf(t) dt.\frac{F(x+h)-F(x)}h=\frac1h\int_x^{x+h}f(t)\,dt.

The average value over the shrinking interval tends to f(x)f(x) by continuity. Thus F′=fF'=f. Conversely, if A′=fA'=f, the definite integral is A(b)−A(a)A(b)-A(a).

This converts accumulation into differentiation in reverse. It also differentiates integrals with moving boundaries: d[∫0x2f(t)dt]/dx=2xf(x2)d[\int_0^{x^2}f(t)dt]/dx=2xf(x^2) by the chain rule.

Quick check +20 XP

What is the derivative of ∫0x2t dt\int_0^{x^2}t\,dt at x=2?

Substitution and integration by parts

For a differentiable change x=g(u)x=g(u), substitution gives ∫f(g(u))g′(u)du=∫f(x)dx\int f(g(u))g'(u)du=\int f(x)dx. Definite integrals need transformed bounds. The formula comes directly from the chain rule.

Integrating the product rule gives ∫u dv=uv−∫v du\int u\,dv=uv-\int v\,du. For example, ∫01xexdx=[xex−ex]01=1\int_0^1 xe^x dx=[xe^x-e^x]_0^1=1.

In multiple dimensions, volume changes by the absolute Jacobian determinant. Polar coordinates have area element r dr dθr\,dr\,d\theta. This factor is essential in the Gaussian integral. Let I=∫−∞∞e−x2dxI=\int_{-\infty}^{\infty}e^{-x^2}dx. Then, using positivity to combine integrals,

I2=∫R2e−(x2+y2)dxdy=∫02π∫0∞e−r2r dr dθ=π.I^2=\int_{\mathbb R^2}e^{-(x^2+y^2)}dxdy=\int_0^{2\pi}\int_0^\infty e^{-r^2}r\,dr\,d\theta=\pi.

Since I>0I>0, I=πI=\sqrt\pi. Rescaling gives the standard normal normalising constant 2π\sqrt{2\pi}.

Numerical accumulation

For sufficiently smooth functions and a fixed interval, left and right rules generally have error O(n−1)O(n^{-1}); midpoint and trapezoid have O(n−2)O(n^{-2}); composite Simpson has O(n−4)O(n^{-4}) and requires an even number of strips. Endpoint singularities can spoil these rates.

A Monte Carlo estimator uses uniform UiU_i on [a,b][a,b]: (b−a)n−1∑if(Ui)(b-a)n^{-1}\sum_i f(U_i). It is unbiased when the expectation exists, and has standard error proportional to n−1/2n^{-1/2} when the variance is finite. Its strength is handling high dimensions, rather than fast convergence for smooth one-dimensional curves.

From residual steps to an ODE

Euler's method for z′=f(z,t)z'=f(z,t) is zk+1=zk+hf(zk,tk)z_{k+1}=z_k+h f(z_k,t_k). A residual update has this form. For z′=zz'=z with z(0)=1z(0)=1, n equal steps to time 1 give (1+1/n)n(1+1/n)^n, approaching ee. Finer discretisation improves this example, but some ODEs require much smaller steps for stability.

Quick check +20 XP

For z prime = z, z(0)=1, one Euler step of size 0.1 gives which state?

DiscoverLearnRead beyondPapers & lecturesYour turn

Read beyond

Book · free online · ~20 min

Calculus, Volume 1

OpenStax · Sections 5.2–5.5: definite integrals and substitution

Read both parts of the fundamental theorem and their assumptions.

Book · free online · ~20 min

Calculus, Volume 2

OpenStax · Sections 3.1 and 3.6: integration by parts and numerical integration

Compare an exact antiderivative with a numerical estimate.

Book · free online · ~20 min

Mathematics for Machine Learning

Deisenroth, Faisal & Ong · Section 6.2: probability distributions

Interpret integrals as continuous weighted sums.

DiscoverLearnRead beyondPapers & lecturesYour turn

Read the equation in context

Neural Ordinary Differential EquationsRicky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt & David Duvenaud · 2018

Neural ODEs define the hidden-state evolution through a learned derivative and use an ODE solver to obtain later states. The integral contains the unknown trajectory z(t); it is not generally an ordinary integral of a known fixed curve. Solver tolerance and computational cost become part of evaluating the model.

Decode the paper · Equation (2): continuous hidden-state dynamics

Neural Ordinary Differential Equations

Ricky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt & David Duvenaud · 2018

+25 XP
z(t1)=z(t0)+∫t0t1f(z(t),t,θ) dt\mathbf z(t_1)=\mathbf z(t_0)+\int_{t_0}^{t_1}f(\mathbf z(t),t,\theta)\,dt

Neural ODEs define the hidden-state evolution through a learned derivative and use an ODE solver to obtain later states. The integral contains the unknown trajectory z(t); it is not generally an ordinary integral of a known fixed curve. Solver tolerance and computational cost become part of evaluating the model.

z(t)\mathbf z(t)
ff
θ\theta
∫t0t1\int_{t_0}^{t_1}

Options

Integration and the fundamental theorem of calculus3Blue1Brown
DiscoverLearnRead beyondPapers & lecturesYour turn

Your turn

Compare left, midpoint, trapezoid and Simpson estimates. Reach an absolute error below 0.001 for three integrals with at most sixteen strips each.

Interactive lab

Riemann racer

Change the integration rule and strip count. Certify three different integrals with error below 0.001 and no more than sixteen strips.
∫01ex dx\int_0^1 e^x\,dx
Integrand and numerical integration panels000.250.7250.51.450.752.1712.9xy
● Integrand● Left panels

Estimate

1.512437

Exact integral

1.718282

Absolute error

2.058e-1

Challenge: Riemann racerEstimate three integrals to within 0.001 using no more than 16 strips each.+40 XP

Match · Expression ↔ Meaning

Integration rules

+20 XP
f(a+iΔx)f(a+i\Delta x)
f(a+(i−1/2)Δx)f(a+(i-1/2)\Delta x)
[f(xi)+f(xi+1)]/2[f(x_i)+f(x_{i+1})]/2

Options

Match · Expression ↔ Meaning

From calculus to models

+20 XP
∫f(x)p(x)dx\int f(x)p(x)dx
zk+1=zk+hf(zk,tk)z_{k+1}=z_k+hf(z_k,t_k)
∫e−x2dx\int e^{-x^2}dx over the real line

Options

Proof puzzle

Accumulation has a derivative

+25 XP

Claim

For continuous f, show F(x)=∫axf(t)dtF(x)=\int_a^x f(t)dt has derivative f(x).

Tap lines in the order they should appear. Tap a line in your proof to send it back.

Your proof

  1. Pick the first line below.

Available lines

Prove it yourself

Unbiased Monte Carlo integration

+35 XP

Claim

For independent uniform U_i on [a,b] and integrable f, prove (b−a)n−1∑if(Ui)(b-a)n^{-1}\sum_i f(U_i) is unbiased for the integral.

Preview

Your typeset proof appears here.

Coding problems

Problem 25·Warm-up

A right Riemann sum

+20 XP

Approximate ∫01x2dx\int_0^1 x^2dx with 100 right-endpoint strips. Submit the result as a reduced fraction.

An exact integer (or a fraction like 7/12)

Problem 26·Standard

Euler’s network

+35 XP

Start z=1 and repeat z←z+z/100z\leftarrow z+z/100 one hundred times. Report the final state to 6 decimal places.

A number, rounded to 6 decimal places

Problem 27·Challenge

Find an integration budget

+50 XP

Use composite midpoint integration for x2x^2 on [0,1][0,1]. Find the smallest positive n for which the absolute error is strictly below 10−610^{-6}.

An exact integer (or a fraction like 7/12)

Key takeaways

  • Integrals accumulate signed change through limits of sums.
  • The fundamental theorem connects accumulation to derivatives.
  • Substitution and multidimensional changes of variables require the correct scale factor.
  • Residual steps can approximate continuous dynamics, with numerical error and stability to monitor.

Checkpoint

Prove it to the labyrinth

Answer every question to clear this chamber. First-try answers earn the most XP.

0/6
Question 1 of 6 +20 XP

An integral over a curve below the horizontal axis contributes what?

Question 2 of 6 +20 XP

What is ∫01xexdx\int_0^1 xe^x dx?

Question 3 of 6 +20 XP

Which factor appears in polar area integration?

Question 4 of 6 +20 XP

Composite Simpson’s rule requires which strip count?

Question 5 of 6 +20 XP

How many times more independent samples reduce Monte Carlo standard error by half?

Question 6 of 6 +20 XP

Why is a neural ODE integral more involved than integrating a known curve?

End of the chamber

Clear this chamber

+60 XPRiemann SumFundamental TheoremChange of VariablesGaussian Integral