Stokes’ Theorem for Smooth Singular Cubes in Lean 4:
True Pullback, Bridges to mathlib4, and Chain-Level \(\partial^2{=}0\)
May 01, 2026
We present a sorry-free Lean 4/mathlib4 formalization of Stokes’ theorem for smooth singular cubes in arbitrary dimension: \[\int_{[0,1]^{n+1}} \sigma^*(\mathrm{d}\omega) = \sum_{i=0}^{n} (-1)^i \Bigl(
\int_{\mathrm{face}_i(1)} \sigma^*\omega - \int_{\mathrm{face}_i(0)} \sigma^*\omega \Bigr)\] for any globally \(C^\infty\) map \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) and any
\(C^\infty\) \(n\)-form \(\omega\) on \(\mathbb{R}^m\). Here \(\sigma^*\) is the
true differential-form pullback via the Fréchet derivative, \((\sigma^*\omega)(x)(v_1,\ldots,v_n) = \omega(\sigma(x))(D\sigma(x)\cdot v_1,
\ldots, D\sigma(x)\cdot v_n)\). The proof reduces to box Stokes on \([0,1]^{n+1}\) via mathlib4’s extDeriv_pullback (giving \(\mathrm{d}(\sigma^*\omega) = \sigma^*(\mathrm{d}\omega)\)) and a chain-rule face-matching identity that we formalize.
We additionally formalize: a bridge theorem relating our coordinate representation to mathlib4’s abstract extDeriv; chain-level Stokes extended by \(\mathbb{Z}\)-linearity
to finite formal combinations of singular cubes; the chain-complex identity \(\partial(\partial\sigma) = 0\), proved via a sign-reversing involution on the double-boundary index set; an underlying box Stokes theorem for
axis-aligned cubes (reduced to mathlib4’s divergence theorem); dimensional specializations (FTC, rectangular Green, 3D Gauss, divergence consistency, integration by parts, Leibniz); and a structured comparison with Harrison’s HOL Light
formalization [1] of Stokes for convex/polyhedral domains.
The development comprises 44 Lean modules (4028 source lines, 205 named declarations), is verified with zero sorry uses, and depends only on the three standard Lean 4 axioms (propext, Classical.choice,
Quot.sound), confirmed by 79 systematic #print axioms checks.
MSC 2020: 58A10 (Differential forms), 68V20 (Formalization of mathematics).
Keywords: Stokes’ theorem, formal proof, Lean 4, mathlib, differential forms, singular cubes, exterior derivative, pullback.
For any globally \(C^\infty\) map \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) and any \(C^\infty\) \(n\)-form \(\omega\) on \(\mathbb{R}^m\), integrating the pullback of \(\mathrm{d}\omega\) over the unit cube equals the alternating sum of pullback integrals over the \(2(n{+}1)\) faces—formalized in Lean 4 with zero sorry and only the standard foundational axioms. The precise scope and limitations, including the relationship to manifold Stokes, are discussed in 13.
| Feature | This paper | Harrison (HOL) | Manifold Stokes |
|---|---|---|---|
| Singular cubes | Yes | No (polyhedral) | Via charts |
| Pullback of forms | Yes (fderiv) |
Yes | Yes |
| Chain-level \(\partial\) | Yes (\(\partial^2{=}0\)) | Yes (polyhedral) | Yes |
| Library integration | Lean 4/mathlib4 |
HOL Light | N/A |
| Integration domain | Parameter cube | Convex polytopes | Oriented manifold |
| Global smoothness required | Yes | Less restrictive | Local suffices |
| Smooth manifolds | No | No (convex/polyhedral) | Yes |
| Charts / atlases | No | No | Yes |
| Partition of unity | No | No | Often needed |
The generalized Stokes’ theorem [2], [3] is one of the central results in differential
geometry, unifying the fundamental theorem of calculus, Green’s theorem, the classical divergence theorem, and the curl theorem into a single statement: for an oriented smooth manifold \(M\) with boundary and a differential
form \(\omega\) of appropriate degree, \[\label{eq:stokes} \int_M \mathrm{d}\omega = \int_{\partial M} \omega\tag{1}\] Prior to this work, to
our knowledge no complete formalization of the differential-form Stokes theorem (for smooth manifolds with boundary, singular chains, or comparable generality) exists in Lean 4 [4]/mathlib4 [5], [6] as of
April 2026. Harrison [1] formalized Stokes’ theorem in HOL Light for convex and polyhedral domains, building on the Euclidean space
foundations of [7]. Harrison’s published development does not cover smooth manifolds with boundary (see 13.3
for a detailed comparison).
In this paper, we present a sorry-free Lean 4 formalization of Stokes’ theorem at two levels:
Smooth singular cubes: For any \(C^\infty\) map \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) and smooth \(n\)-form \(\omega\) on \(\mathbb{R}^m\), the integral of the pullback \(\sigma^*(\mathrm{d}\omega)\) over the unit cube equals the oriented sum of face integrals of \(\sigma^*\omega\). The pullback is the true differential-form pullback, using the Fréchet derivative of \(\sigma\).
Axis-aligned boxes: For any \(C^\infty\) coordinate \(n\)-form on \(\mathbb{R}^{n+1}\) and any box \([a, b]\), the integral of \(\mathrm{d}\omega\) (evaluated on the standard frame) equals the boundary integral.
The singular cube theorem (singularStokes) allows smooth maps \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) that can parametrize curves, surfaces, and higher-dimensional objects (possibly
degenerate or self-overlapping), with integration always over the parameter cube—broader as a parametrized-chain statement than axis-aligned boxes alone, though still short of smooth manifolds with boundary or image-domain theory.
Our central contribution is the singular-cube theorem; the box, bridge, and chain results form the technical infrastructure that makes the singular case go through.
Stokes for smooth singular cubes with true pullback via fderiv (2). The proof reduces to box Stokes via mathlib4’s extDeriv_pullback, which gives \(\mathrm{d}(\sigma^*\omega) = \sigma^*(\mathrm{d}\omega)\), and a chain-rule face-matching identity (3) that we formalize.
Chain-level \(\partial^2{=}0\) for singular cubical chains, proved via a sign-reversing fixed-point-free involution on the double-boundary index set (23); chain-level Stokes is also formalized by extending the singular theorem \(\mathbb{Z}\)-linearly over Finsupp.
A formal bridge from our coordinate representation to mathlib4’s abstract extDeriv (5), proving that our coordinate formula is the evaluation of the abstract
exterior derivative on standard basis vectors, and a unified statement (stokes_extDeriv_smooth) that needs only one ContDiff hypothesis.
A sorry-free proof of box Stokes for axis-aligned cubes in arbitrary dimension \(n+1\) (4), reducing to mathlib4’s divergence theorem [8] via a signed-coefficient construction (short proof body; the work is in the definitions).
Box chain infrastructure: \(\mathbb{Z}\)-linear combinations of boxes with Stokes extended by linearity, two-box additivity, and shared-face cancellation (7).
Box-level \(\partial^2{=}0\) sign and face cancellation: for each codimension-2 face, the two boundary paths produce the same face box with opposite signs—proved without defining \(\partial\) as a chain homomorphism on undecorated boxes.
Dimensional specializations: FTC (\(n{=}0\)), rectangular Green’s theorem (\(n{=}1\), with four-edge decomposition), divergence consistency, and 3D Gauss; plus
calculus corollaries (integration by parts, Leibniz product rule). All are direct instantiations of stokes_smooth, not independent derivations.
A 1D agreement check (6.1) showing that the Stokes-derived FTC equals mathlib4’s interval-integral FTC.
A structured comparison with Harrison’s HOL Light Stokes for convex/polyhedral domains (13.3), and an honest assessment of what remains for full manifold Stokes (13).
stokes_on_box is a direct wrapper around mathlib4’s divergence theorem (the mathematical content is the signed-coefficient construction). stokes_smooth derives hypotheses from \(C^\infty\) and calls stokes_on_box. singularStokes reduces to stokes_smooth via extDeriv_pullback and the face-matching
identity. stokes_singular_boundary restates singularStokes with the boundary integral on the left; stokes_singular_chain is the corresponding formal-chain version using singularBoundarySingle. stokes_chain extends by \(\mathbb{Z}\)-linearity (Finsupp.induction for singular chains, Finsupp.sum_congr for box chains). The FTC, Green, divergence, and Gauss results are dimensional instantiations of stokes_smooth. dd_zero_abstract is a direct invocation of
mathlib4’s extDeriv_extDeriv. bdry_sq_sign_cancel is independent sign arithmetic (no analysis dependency; uses only omega and ring lemmas).
Harrison [1] formalized a version of Stokes’ theorem in HOL Light for convex and polyhedral domains in \(\mathbb{R}^N\), extended to polyhedral chains. Contrary to what some summaries suggest, Harrison’s formalization does not cover arbitrary smooth manifolds with boundary; it operates on convex polytopes with the
Henstock–Kurzweil gauge integral. With our singular cube extension, the mathematical scope of the two developments is complementary but different: Harrison proves Stokes for convex/polyhedral domains in \(\mathbb{R}^n\) extended to polyhedral chains, while our work uses smooth singular cubical parametrizations from the unit cube. The key infrastructure differences remain: (1) Harrison works in HOL’s simple type theory; we use
Lean 4’s dependent types; (2) Harrison builds all integration from scratch; we reduce to mathlib4’s divergence theorem; (3) we provide a bridge to mathlib4’s abstract extDeriv and use extDeriv_pullback for the singular theorem; we are not aware of a directly comparable bridge to an independently developed abstract exterior-derivative API in HOL Light, since HOL Light does not maintain such an independent abstract
exterior algebra alongside its integration theory. A detailed structural comparison appears in 13.3.
As of the mathlib4 version pinned in this project (April 2026), the library provides:
The box divergence theorem (integral_divergence_of_hasFDerivAt_off_countable'), which uses the Bochner set integral despite its historical connection with Henstock–Kurzweil-style divergence theorems [8]. Our box Stokes is a direct wrapper around this result.
The abstract exterior derivative (extDeriv) for differential forms [9]
Naturality of pullback (extDeriv_pullback) [9]
Continuous alternating maps (ContinuousAlternatingMap)
Smooth manifold infrastructure (SmoothManifoldWithCorners) [10]
However, mathlib4 does not yet provide: integration of differential forms on manifolds, orientation theory for manifolds with boundary, or a differential-form Stokes theorem comparable to the present statement (though it does
provide the box divergence theorem from which our box Stokes reduces). Our work provides the first Lean 4 formalization of Stokes’ theorem for smooth singular cubes, contributing to the growing body of Lean 4 formalizations reported in venues such as
AFM [11] and ITP [12].
Beyond Harrison’s HOL Light work, integration and measure theory have been formalized extensively in Isabelle/HOL by Hölzl, Immler, and others [13], providing foundational infrastructure for Lebesgue integration. The closest non-HOL-Light formalization of a Stokes-type theorem is Abdulaziz and Paulson’s Isabelle/HOL formalization of Green’s theorem on 2-dimensional cells [14], which is a 2D specialization of Stokes; we extend that line of work to arbitrary dimension and to true differential-form pullback under smooth singular parametrizations. We are not aware of a Coq, Mizar, Metamath, or HOL4 formalization of Stokes’ theorem for singular cubes or smooth manifolds with boundary.
2 presents the main singular Stokes theorem first for motivation; it depends on the box infrastructure of §§3–5, which is developed subsequently. §§6–10 give specializations and extensions. §§11–13 discuss architecture, insights, and limitations.
The main result of this paper is Stokes’ theorem for smooth singular cubes—a generalization of the box Stokes theorem that allows the integrand to come from a globally smooth map \(\sigma:\mathbb{R}^{n+1}\to\mathbb{R}^m\), with the integral still taken over the parameter cube \([0,1]^{n+1}\) (the box case is recovered as \(\sigma=\mathrm{id}\) on \(\mathbb{R}^{n+1}\)). No image-domain theory is formalized.
Remark 1 (On the term “smooth singular cube”). In the algebraic-topology literature, a singular \(n\)-cube is usually a continuous map from the standard cube \(I^n\) into a topological space; smoothness is imposed only on \(I^n\). Our formal objects are globally smooth extensions: the map \(\sigma\) is required to be \(C^\infty\) on all of \(\mathbb{R}^{n+1}\), and integration is over \([0,1]^{n+1}\). This is mathematically stronger than the conventional definition—any map smooth on the closed cube with compatible jet data admits a smooth extension by Whitney’s theorem [15], but we impose the extension as a hypothesis rather than constructing it. This choice substantially simplifies the formalization (12); we discuss the trade-off explicitly in 13.
Definition 1 (Smooth singular cube). A smooth singular \((n{+}1)\)-cube in \(\mathbb{R}^m\) is a globally \(C^\infty\) map \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\), integrated over the unit cube \([0,1]^{n+1}\).
In Lean 4:4
structure SmoothSingularCube (n m : Nat) where
toFun : (Fin n -> Real) -> (Fin m -> Real)
smooth : ContDiff Real Top toFun
Remark 2. In the Lean code, SmoothSingularCube n m takes the cube dimension directly: an \((n{+}1)\)-cube has type SmoothSingularCube (n+1) m with
domain \(\mathrm{Fin}(n{+}1) \to \mathbb{R}\). The smoothness hypothesis is global (\(C^\infty\) on all of \(\mathbb{R}^{n+1}\)), not just on the
unit cube. This is a stronger hypothesis than strictly necessary but simplifies the formalization considerably, as ContDiff at the top level derives all needed differentiability properties automatically.
Definition 2 (Face inclusion and singular faces). The face inclusion \(\iota_{i,\varepsilon} : \mathbb{R}^n \to \mathbb{R}^{n+1}\) inserts the constant \(\varepsilon\) at position \(i\): \[\iota_{i,\varepsilon}(t)_j = \begin{cases} t_j & \text{if } j < i \\ \varepsilon & \text{if } j = i \\ t_{j-1} & \text{if } j > i \end{cases}\] The \(i\)-th face at \(\varepsilon\) of a singular cube \(\sigma\) is the composition \(\sigma \circ \iota_{i,\varepsilon}\), itself a smooth singular \(n\)-cube.
def faceInclusion (i : Fin (n + 1)) (eps : Real) (t : Fin n -> Real) :
Fin (n + 1) -> Real := ...
def singularFace (sigma : SmoothSingularCube (n + 1) m)
(i : Fin (n + 1)) (eps : Real) : SmoothSingularCube n m where
toFun := sigma.toFun comp faceInclusion i eps
smooth := sigma.smooth.comp (faceInclusion_contDiff i eps)
The central construction of the singular cube formalization is the use of the true differential-form pullback, defined via the Fréchet derivative. We write \(d\) for the domain dimension. In the Stokes application, \(d = n{+}1\) and \(k = n\), but the pullback definition is general:
Definition 3 (Pullback form). For a smooth singular cube \(\sigma : \mathbb{R}^d \to \mathbb{R}^m\) and a \(k\)-form \(\omega\) on \(\mathbb{R}^m\), the pullback \(\sigma^*\omega\) is the \(k\)-form on \(\mathbb{R}^d\) defined by: \[(\sigma^*\omega)(x)(v_1, \ldots, v_k) = \omega(\sigma(x))(D\sigma(x) \cdot v_1, \ldots, D\sigma(x) \cdot v_k)\] where \(D\sigma(x) = \mathrm{fderiv}\;\mathbb{R}\;\sigma\;x\) is the Fréchet derivative.
In Lean 4, this is expressed via ContinuousAlternatingMap.compContinuousLinearMap:5
def pullbackForm (sigma : SmoothSingularCube d m)
(omega : (Fin m -> Real) ->
(Fin m -> Real) [Alt^Fin k]->L[Real] Real) :
(Fin d -> Real) -> (Fin d -> Real) [Alt^Fin k]->L[Real] Real :=
fun x => (omega (sigma.toFun x)).compContinuousLinearMap
(fderiv Real sigma.toFun x)
This is genuinely the differential-geometric pullback: it applies the form \(\omega\) at the image point \(\sigma(x)\) to vectors pushed forward by the derivative \(D\sigma(x)\). This contrasts with the “coefficient precomposition” \((A \cdot \omega)_i(x) := \omega_i(Ax)\) used in the box infrastructure, which does not mix coefficients or involve determinants.
Definition 4 (Integration of forms over singular cubes). The integral of a \(d\)-form \(\omega\) over a singular \(d\)-cube \(\sigma\) is: \[\int_\sigma \omega := \int_{[0,1]^d} (\sigma^*\omega)(x)(e_0, \ldots, e_{d-1})\, \mathrm{d}x\] where \(e_j = \mathrm{Pi.single}\;j\;1\) are the standard basis vectors (zero-indexed).
def integrateForm (sigma : SmoothSingularCube d m)
(omega : (Fin m -> Real) ->
(Fin m -> Real) [Alt^Fin d]->L[Real] Real) : Real :=
integral (x in Icc (fun _ => 0) (fun _ => 1))
(pullbackForm sigma omega x) (fun j => Pi.single j 1)
The proof of singular Stokes proceeds in three steps:
The key identity is commutativity of pullback with the exterior derivative: \[\mathrm{d}(\sigma^*\omega) = \sigma^*(\mathrm{d}\omega)\] In Lean 4, this follows directly from mathlib4’s extDeriv_pullback:
theorem pullback_extDeriv (sigma : SmoothSingularCube (n + 1) m)
(omega : ...) (h_omega : ContDiff Real Top omega)
(x : Fin (n + 1) -> Real) :
extDeriv (pullbackForm sigma omega) x =
(extDeriv omega (sigma.toFun x)).compContinuousLinearMap
(fderiv Real sigma.toFun x)
Since \(\sigma^*\omega\) is a smooth differential form on \(\mathbb{R}^{n+1}\), the existing box Stokes theorem (stokes_extDeriv, 4) applies on \([0,1]^{n+1}\): \[\int_{[0,1]^{n+1}} \mathrm{d}(\sigma^*\omega) \;=\; \int_{\partial[0,1]^{n+1}} \sigma^*\omega\] (in Lean: boxIntegral (extDerivCoord ...) = bdryIntegral ...). Smoothness of the coordinate coefficients of \(\sigma^*\omega\) is proved via toCoordNForm_pullback_isSmooth, which
derives it from the global \(C^\infty\) hypotheses on \(\sigma\) and \(\omega\) using the chain rule for ContDiff.
The face matching identity connects the box boundary integral of \(\sigma^*\omega\) to the face integrals of the singular cube. The core lemma is:
Theorem 3 (Face matching). For \(\sigma\), \(\omega\), face index \(i\), value \(\varepsilon\), and point \(x \in \mathbb{R}^n\), writing \(\mathrm{succAbove}(i,k)\) for the \(k\)-th element of \(\{0,\ldots,n\} \setminus \{i\}\) in increasing order (the order-preserving injection \(\{0,\ldots,n{-}1\} \hookrightarrow \{0,\ldots,n\} \setminus \{i\}\)): \[(\sigma^*\omega)(\iota_{i,\varepsilon}(x))(e_{\mathrm{succAbove}(i,0)}, \ldots, e_{\mathrm{succAbove}(i,n-1)}) = ((\sigma \circ \iota_{i,\varepsilon})^*\omega)(x)(e_0, \ldots, e_{n-1})\]
The proof uses the chain rule: \(D(\sigma \circ \iota_{i,\varepsilon})(x)
= D\sigma(\iota_{i,\varepsilon}(x)) \circ D\iota_{i,\varepsilon}(x)\), together with the derivative identity \(D\iota_{i,\varepsilon}(x) \cdot e_j = e_{\mathrm{succAbove}(i,j)}\) (proved as fderiv_faceInclusion_single). The alternating map’s multilinearity then transforms the \(n\) basis vectors \(e_{\mathrm{succAbove}(i,0)}, \ldots,
e_{\mathrm{succAbove}(i,n{-}1)}\) applied inside \(\sigma^*\omega\) into \(e_0, \ldots, e_{n-1}\) applied inside \((\sigma \circ
\iota_{i,\varepsilon})^*\omega\).
Theorem 4 (Singular cubical Stokes, ). singularStokes]Let \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) be a smooth singular \((n{+}1)\)-cube and \(\omega\) a \(C^\infty\) \(n\)-form on \(\mathbb{R}^m\). Then: \[\int_\sigma \mathrm{d}\omega = \sum_{i=0}^{n} (-1)^i \Bigl( \int_{\mathrm{face}_i(1)} \omega - \int_{\mathrm{face}_i(0)} \omega \Bigr)\] where all integrals use the true pullback and the unit cube domain.
Proof sketch. The argument proceeds in three steps. (1) Naturality: by mathlib4’s extDeriv_pullback, applied to the globally \(C^\infty\) hypotheses on \(\sigma\) and \(\omega\), we have \(\mathrm{d}(\sigma^*\omega)(x) = (\sigma^*(\mathrm{d}\omega))(x)\) pointwise. The pullback uses fderiv, and the hypotheses are satisfied because \(\sigma\) is globally \(C^\infty\) and \(\omega\) is \(C^\infty\) as a ContinuousAlternatingMap-valued function. (2) Box Stokes: integrating both sides over \([0,1]^{n+1}\) and applying the existing box Stokes theorem to \(\sigma^*\omega\) (whose coordinate coefficients are smooth by the chain rule), the left-hand side equals the boundary integral \(\sum_i (-1)^i (F_i(1) - F_i(0))\) where \(F_i(\varepsilon)\) is the box-boundary integral on the \(i\)-th face at value \(\varepsilon\). (3) Face matching: the face-matching identity (3) converts each box-boundary term into the corresponding singular-face integral, matching the right-hand side. ◻
The Lean statement:
theorem singularStokes (sigma : SmoothSingularCube (n + 1) m)
(omega : (Fin m -> Real) ->
(Fin m -> Real) [Alt^Fin n]->L[Real] Real)
(h_omega : ContDiff Real Top omega) :
integrateForm sigma (fun y => extDeriv omega y) =
sum i : Fin (n + 1),
(-1 : Real) ^ (i : Nat) *
(integrateForm (singularFace sigma i 1) omega -
integrateForm (singularFace sigma i 0) omega)
The theorem holds for any globally smooth \(\sigma\), not only for box-aligned parametrizations. As an informal illustration (this specific computation is not formalized; it serves as a paper-only sanity check), take the
polar parametrization of an annulus, \[\sigma : \mathbb{R}^2 \to \mathbb{R}^2,\qquad \sigma(r,\theta) = \bigl((1+r)\cos(2\pi\theta),\; (1+r)\sin(2\pi\theta)\bigr),\] together with the 1-form \(\omega = \tfrac{1}{2}(x\,\mathrm{d}y - y\,\mathrm{d}x)\) on \(\mathbb{R}^2\) (so \(\mathrm{d}\omega = \mathrm{d}x\wedge\mathrm{d}y\)). Because \(\sigma\) is real-analytic on all of \(\mathbb{R}^2\), the global \(C^\infty\) hypothesis of 4 is satisfied. The theorem then equates the parameter-cube integral \(\int_{[0,1]^2}\sigma^*(\mathrm{d}\omega)\) with the alternating sum of pullback integrals over the four edges
of the unit square: by direct computation, the parameter-cube integrand reduces to the Jacobian \(\det D\sigma(r,\theta) = 2\pi(1+r)\), consistent with the classical Jacobian formula for area. Concretely, \(\int_0^1\!\int_0^1 2\pi(1+r)\,dr\,d\theta = 3\pi\), and the alternating face-integral sum yields the same value (the two \(\theta{=}0\) and \(\theta{=}1\) edge
integrals cancel by periodicity)—providing a numerical sanity check of the theorem. The development includes LeanStokes/CubeStokes/Demo.lean, which exercises box Stokes (the specialization of 4 to \(\sigma = \mathrm{id}\)) in 4D, 5D, and 10D; the full singular theorem with non-trivial \(\sigma\) is exercised
at the type-checking level via the singularStokes declaration.
Stokes extends by \(\mathbb{Z}\)-linearity to formal chains of singular cubes:
Definition 5 (Singular chain). A smooth singular \(n\)-chain in \(\mathbb{R}^m\) is a formal \(\mathbb{Z}\)-linear combination
of smooth singular \(n\)-cubes, implemented as a finitely-supported function (Finsupp) from singular cubes to \(\mathbb{Z}\): \[C_n(\mathbb{R}^m) := \left\{ \sum_{\text{finite}} c_\sigma \cdot \sigma \;\middle|\; c_\sigma \in \mathbb{Z},\; \sigma \text{ a smooth singular n-cube} \right\}\]
Theorem 5 (Stokes for singular boundary, ). stokes_singular_boundary]
For a smooth singular cube \(\sigma\) and smooth form \(\omega\): \[\int_{\partial\sigma} \omega = \int_\sigma \mathrm{d}\omega\] where \(\int_{\partial\sigma}\omega = \sum_i (-1)^i (\int_{\mathrm{face}_i(1)}\omega - \int_{\mathrm{face}_i(0)}\omega)\). This is a direct restatement of singularStokes (swapped sides) using bdryIntegral_singular. The corresponding formal-chain version, stokes_singular_chain, equates integrateChain (singularBoundarySingle sigma) omega with the interior integral.
Remark 6. We have a boundary operator on individual cubes (singularBoundarySingle) and chain-level Stokes (stokes_chain) extending by linearity to formal chains. The chain complex
identity \(\partial^2 = 0\) is proved as bdry_bdry_chain_zero (10.2).
Chain integration satisfies additivity (integrateChain_add) and scalar compatibility (integrateChain_smul):
\[\int_{c_1 + c_2} \omega = \int_{c_1}\omega + \int_{c_2}\omega \qquad\text{and}\qquad \int_{k \cdot c}\omega = k \cdot \int_c \omega\] where \(k \in \mathbb{Z}\) acts via the canonical embedding \(\mathbb{Z}\hookrightarrow \mathbb{R}\).
The singular Stokes theorem reduces to the box Stokes theorem, which we now describe. This section presents the coordinate-level infrastructure that serves as the foundation for the entire development.
An \(n\)-form on \(\mathbb{R}^{n+1}\) can be written in coordinates as: \[\omega = \sum_{i=0}^{n} \omega_i(x)\, \mathrm{d}x_0 \wedge \cdots \wedge \widehat{\mathrm{d}x_i} \wedge \cdots \wedge \mathrm{d}x_n\] where \(\widehat{\mathrm{d}x_i}\) denotes omission. We represent this as a family of coefficient functions:
Definition 6 (Coordinate \(n\)-form). A coordinate \(n\)-form on \(\mathbb{R}^{n+1}\) is a function \(\omega : \mathrm{Fin}(n{+}1) \to (\mathbb{R}^{n+1} \to \mathbb{R})\) where \(\omega_i(x)\) is the coefficient of the \(i\)-th basis \(n\)-form at \(x\).
In Lean 4:
def CoordNForm (n : Nat) := Fin (n + 1) -> (Fin (n + 1) -> Real) -> Real
The exterior derivative of \(\omega\) is the \((n{+}1)\)-form (i.e., a top form on \(\mathbb{R}^{n+1}\)): \[\mathrm{d}\omega = \left(\sum_{i=0}^{n} (-1)^i \frac{\partial\omega_i}{\partial x_i}\right) \mathrm{d}x_0 \wedge \cdots \wedge \mathrm{d}x_n\]
The key insight for our proof is the signed coefficient construction:
Definition 7 (Signed coefficient). \(f_i(x) := (-1)^i \cdot \omega_i(x)\)
The sign arises because \(\mathrm{d}(\omega_i\,\mathrm{d}x_0\wedge\cdots \wedge\widehat{\mathrm{d}x_i}\wedge\cdots\wedge\mathrm{d}x_n)\) requires \(i\) adjacent transpositions to place \(\mathrm{d}x_i\) in position \(i\), yielding the factor \((-1)^i\). With this convention, the exterior derivative coefficient becomes the divergence of the vector field \((f_0, \ldots, f_n)\): \[\mathrm{d}\omega = \left(\sum_{i=0}^{n} \frac{\partial f_i}{\partial x_i}\right) \mathrm{d}x_0 \wedge \cdots \wedge \mathrm{d}x_n\]
This is precisely what mathlib4’s divergence theorem computes.
For a box \([a, b] = \prod_{i=0}^{n} [a_i, b_i] \subset \mathbb{R}^{n+1}\), the oriented boundary integral of \(\omega\) is: \[\int_{\partial[a, b]} \omega = \sum_{i=0}^{n} \left( \int_{\text{face}_i} f_i(b_i, \hat{x}_i)\, \mathrm{d}\hat{x}_i - \int_{\text{face}_i} f_i(a_i, \hat{x}_i)\, \mathrm{d}\hat{x}_i \right)\] where \(\text{face}_i = \prod_{j \neq i} [a_j, b_j]\) is the \(n\)-dimensional face box, \(\hat{x}_i = (x_0, \ldots, x_{i-1}, x_{i+1}, \ldots, x_n)\) denotes all coordinates except \(i\), and \(f_i(c, \hat{x}_i)\) denotes inserting \(c\) at position \(i\).
This exactly matches the right-hand side of mathlib4’s divergence theorem.
Theorem 7 (Cubical Stokes on boxes, full-hypothesis version). Let \(\omega\) be a coordinate \(n\)-form on \(\mathbb{R}^{n+1}\), \(a \leq b\) component-wise, and \(s\) a countable subset. If the signed coefficients \(f_i = (-1)^i \omega_i\) are:
continuous on \([a, b]\),
differentiable on the interior minus \(s\), and
the exterior derivative is integrable on \([a, b]\),
then \(\displaystyle\int_{[a, b]} \mathrm{d}\omega = \int_{\partial[a, b]} \omega\).
The Lean statement:
theorem stokes_on_box (a b : Fin (n + 1) -> Real) (hle : a <= b)
(omega : CoordNForm n)
(s : Set (Fin (n + 1) -> Real)) (hs : s.Countable)
(hc : forall i, ContinuousOn (signedCoeff omega i) (Icc a b))
(hd : forall x in (pi univ fun i => Ioo (a i) (b i)) \;s,
forall i, HasFDerivAt (signedCoeff omega i)
((-1 : Real) ^ (i : Nat) smul fderiv Real (omega i) x) x)
(hi : IntegrableOn (fun x => Finset.sum i : Fin (n + 1),
((-1 : Real) ^ (i : Nat) smul fderiv Real (omega i) x) (Pi.single i 1))
(Icc a b)) :
boxIntegral (extDerivCoord omega) a b = bdryIntegral omega a b
Proof (3 lines). The proof unfolds definitions and applies the divergence theorem directly:
unfold boxIntegral bdryIntegral extDerivCoord
exact integral_divergence_of_hasFDerivAt_off_countable'
a b hle (signedCoeff omega)
(fun i x => (-1 : Real) ^ (i : Nat) smul fderiv Real (omega i) x)
s hs hc hd hi
The key mathematical content is in the definitions: choosing signedCoeff so that the divergence theorem’s hypotheses align exactly with our boundary integral. ◻
Theorem 8 (Smooth version). If all coefficient functions \(\omega_i\) are \(C^\infty\) (i.e., ContDiff Real Top (omega i) for all \(i\), abbreviated IsSmooth omega in the formalization), then Stokes holds with no countable exceptional set:
theorem stokes_smooth (a b : Fin (n + 1) -> Real) (hle : a <= b)
(omega : CoordNForm n) (homega : IsSmooth omega) :
boxIntegral (extDerivCoord omega) a b = bdryIntegral omega a b
The proof derives the hypotheses of 7 (integrability, differentiability off a countable set) from ContDiff using standard
mathlib4 lemmas, then applies the box theorem.
mathlib4 Exterior Derivative to Box Stokes↩︎The bridge theorem validates our coordinate formula against mathlib’s independently-defined abstract exterior derivative. It proves that evaluating mathlib4’s extDeriv—defined via Fréchet derivatives of
alternating maps—on standard basis vectors recovers our coordinate extDerivCoord, confirming that the sign convention is mathematically correct. This does not establish a full theory of form integration or pullbacks, but it
provides the independent consistency guarantee a referee would expect.
Definition 8 (Coefficient extraction). Given a mathlib4 differential form \(\omega : \mathbb{R}^{n+1} \to \Lambda^n(\mathbb{R}^{n+1}, \mathbb{R})\), its \(i\)-th coordinate coefficient is: \[(\mathrm{toCoordNForm}\;\omega)_i(x) = \omega(x)(e_{s(i,0)}, \ldots, e_{s(i,n-1)})\] where \(s(i,k) = \mathrm{succAbove}(i,
k)\) enumerates \(\{0,\ldots,n\}\setminus\{i\}\).
Theorem 9 (Bridge theorem). For a form \(\omega\) differentiable at \(x\): \[(\mathrm{d}\omega)(x)(e_0, \ldots, e_n) = \mathrm{extDerivCoord}(\mathrm{toCoordNForm}\;\omega)(x)\]
The proof uses extDeriv_apply_vectorField_of_pairwise_commute with constant vector fields \(V_j(x) = e_j\), which have zero Lie bracket. This mathlib4 lemma expresses \((\mathrm{d}\omega)(V_0, \ldots, V_n)\) as an alternating sum of directional derivatives \(V_j[\omega(V_0, \ldots, \widehat{V_j}, \ldots, V_n)]\); the Lie bracket terms vanish because the \(V_j\) are constant:
theorem extDeriv_topCoeff_eq_extDerivCoord
(omega : (Fin (n + 1) -> Real) ->
(Fin (n + 1) -> Real) [Alt^Fin n] -> L[Real] Real)
(x : Fin (n + 1) -> Real)
(homega : DifferentiableAt Real omega x) :
extDeriv omega x (fun j => Pi.single j 1)
= extDerivCoord (toCoordNForm omega) x
Theorem 10 (Unified Stokes on boxes via ). extDeriv]Combining the bridge with cubical Stokes: \[\int_{[a, b]} (\mathrm{d}\omega)(e_0,\ldots,e_n) = \int_{\partial[a, b]} \omega\] for any \(C^\infty\) differential form \(\omega\). The cleanest Lean statement is:
theorem stokes_extDeriv_smooth
(omega : (Fin (n + 1) -> Real) ->
(Fin (n + 1) -> Real) [Alt^Fin n] -> L[Real] Real)
(a b : Fin (n + 1) -> Real) (hle : a <= b)
(homega : ContDiff Real Top omega) :
integral (x in Icc a b) (extDeriv omega x (fun j => Pi.single j 1))
= bdryIntegral (toCoordNForm omega) a b
This requires only a single hypothesis: global \(C^\infty\) smoothness of \(\omega\). Differentiability and coefficient smoothness are derived automatically.
Each result below is a box/interval specialization of stokes_smooth (a direct dimensional instantiation, not an independent derivation):
Corollary 1 (Fundamental Theorem of Calculus, ). ftc_stokes]For smooth \(f : \mathbb{R}\to \mathbb{R}\) and \(a \leq b\): \[\int_{[a,b]}
f'(x)\,\mathrm{d}x = f(b) - f(a)\] Proved by defining \(\omega_0(y) = f(y_0)\) for \(y \in \mathbb{R}^1\) and applying stokes_smooth at \(n=0\). The boundary integral reduces via bdryIntegral_fin1 (which uses Fin.insertNth_apply_same to evaluate face values) and the volume integral via extDerivCoord_of_comp_proj (which computes fderiv of \(f \circ \mathrm{proj}_0\)).
Corollary 2 (Rectangular Green’s theorem, ). green_stokes]For smooth \(Q, P : \mathbb{R}^2 \to \mathbb{R}\) and a rectangle \([a, b]\), writing \([Q, P]\) for the coordinate 1-form with coefficients \((\omega_0, \omega_1) = (Q, P)\): \[\int_{[a, b]} \left(\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y}\right) \mathrm{d}x\,\mathrm{d}y = \int_{\partial[a, b]} [Q, P]\] The coordinate convention is: a 1-form on \(\mathbb{R}^2\) in coordinates \((x_0, x_1) = (x, y)\) is \(\omega = \omega_0\,\mathrm{d}x_1 + \omega_1\,\mathrm{d}x_0\) where \(\omega_i\) is the coefficient of the 1-form that omits \(\mathrm{d}x_i\). Thus \(\omega_0 = Q\) (paired with \(\mathrm{d}y\) since \(\mathrm{d}x_0 = \mathrm{d}x\) is omitted) and \(\omega_1 = P\) (paired with \(\mathrm{d}x\) since \(\mathrm{d}x_1 = \mathrm{d}y\) is omitted), recovering the classical \(\omega = P\,\mathrm{d}x + Q\,\mathrm{d}y\).
Corollary 3 (Divergence consistency, ). divergence_stokes]For a smooth vector field \(F : \mathbb{R}^{n+1} \to \mathbb{R}^{n+1}\) and a box \([a, b]\): \[\int_{[a, b]} \mathrm{div}(F)\,\mathrm{d}V = \sum_{i=0}^{n} \left( \int_{\mathrm{face}_i} F_i(b_i, \hat{x}_i)\,\mathrm{d}\hat{x}_i - \int_{\mathrm{face}_i} F_i(a_i, \hat{x}_i)\,\mathrm{d}\hat{x}_i \right)\] The signs cancel:
the form uses \(\omega_i = (-1)^i F_i\) and signedCoeff applies another \((-1)^i\), so the boundary integrand is \((-1)^{2i} F_i =
F_i\) (since \((-1)^{2i} = 1\)). This is a consistency check: since our main theorem is proved FROM the box divergence theorem, recovering the divergence theorem from Stokes shows the sign conventions
round-trip correctly. It is not an independent derivation.
Corollary 4 (Rectangular Green’s four-edge decomposition, ). green_four_edges]For the 1-form \(\omega = P\,\mathrm{d}x + Q\,\mathrm{d}y\) (standard convention with \(\mathrm{d}\omega = (\partial_x Q - \partial_y P)\,\mathrm{d}x\wedge\mathrm{d}y\)), the double integral decomposes into four oriented face integrals: \[\iint_R \left(\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y}\right) dA = \int_{\text{right}} Q - \int_{\text{left}} Q - \int_{\text{top}} P + \int_{\text{bottom}} P\] where right (\(x{=}b_0\)), left (\(x{=}a_0\)), top (\(y{=}b_1\)), bottom (\(y{=}a_1\)). This gives the explicit face-integral decomposition of the boundary sum.
Corollary 5 (Integration by parts, ). integration_by_parts]For smooth \(f, g : \mathbb{R}\to \mathbb{R}\) and \(a \leq b\): \[\int_a^b f(x)
g'(x)\,\mathrm{d}x = f(b)g(b) - f(a)g(a) - \int_a^b f'(x)g(x)\,\mathrm{d}x\] Derived from ftc_stokes applied to \(f \cdot g\) together with the product rule.
A natural concern with the coordinate approach is whether the Stokes theorem produces correct integral values. We validate this for the 1D case (\(n{=}0\), the FTC) by computing via two independent paths and showing they agree:
Path 1 (Stokes): stokes_smooth \(\to\) ftc_stokes \(\to\) \(f(b) -
f(a)\)
Path 2 (interval integral):
intervalIntegral.integral_eq_sub_of_hasDerivAt \(\to\) ftc_intervalIntegral \(\to\) \(f(b) -
f(a)\)
The agreement theorem (ftc_paths_agree) shows both paths produce the same result. The Stokes path uses set integrals over \(\mathrm{Fin}\,1 \to \mathbb{R}\) of \(\mathrm{fderiv}\), while the interval-integral path uses mathlib’s direct FTC (intervalIntegral.integral_eq_sub_of_hasDerivAt). Their agreement provides a sanity check that our box-integral machinery
computes standard calculus integrals correctly in the \(n{=}0\) case, though both paths ultimately rely on mathlib’s analysis library (the divergence theorem for path 1, direct FTC for path 2). The validation is therefore a
consistency check of our definitions and sign conventions against mathlib’s independent FTC path, not a check of mathlib’s analysis foundations themselves.
We define formal \(\mathbb{Z}\)-linear combinations of boxes and extend Stokes by linearity:
Definition 9 (Cubical box and chain). A cubical box is a structure \((a, b, h)\) where \(a \leq b\) componentwise. A cubical chain is a formal \(\mathbb{Z}\)-linear combination of boxes: CubicalChain n := CubicalBox n ->0 Z (where ->0 denotes finitely-supported functions, i.e., Finsupp).
Integration extends linearly to chains:
def integrateExterior (c : CubicalChain n) (omega : CoordNForm n) : Real :=
c.sum fun B k => (k : Real) * boxIntegral (extDerivCoord omega) B.lo B.hi
Theorem 11 (Stokes for chains, ). stokes_chain]For any smooth form \(\omega\) and chain \(c\): \[\mathrm{integrateExterior}(c, \omega) =
\mathrm{integrateBdry}(c, \omega)\] The proof is by Finsupp.sum_congr, applying stokes_smooth to each box.
Additivity properties (integrateExterior_add, integrateBdry_add) are proved via Finsupp.sum_add_index'.
A natural question is whether the Stokes identity is compatible with decomposing a box into two adjacent sub-boxes. The subdivision module shows that for any two boxes (forming a 2-element chain), the Stokes identity holds for the combined chain:
Theorem 12 (Two-box Stokes additivity, ). subdivision_stokes_equiv] For two boxes \(B_1\), \(B_2\) (with \(a_i \le b_i\)) and a smooth form \(\omega\): \[\int_{B_1} d\omega + \int_{B_2} d\omega = \int_{\partial B_1} \omega + \int_{\partial B_2} \omega\] When \(B_1\) and \(B_2\) share a face (subdivision of a larger box), the shared face contributions cancel in the boundary sum, recovering the Stokes identity for the two-box formal chain.
This is proved as a direct consequence of the single-box Stokes theorem (by linarith). The chain-level version (stokes_two_boxes) follows from stokes_chain.
We additionally formalize the key shared-face cancellation:
Definition 10 (Adjacency, ). Adjacent] Two boxes \(B_1, B_2\) are adjacent in direction \(i\) if \(B_1.\mathrm{hi}[i] = B_2.\mathrm{lo}[i]\) and the remaining coordinates agree.
Theorem 13 (Shared-face cancellation, ). shared_face_cancel] If \(B_1\) and \(B_2\) are adjacent in direction \(i\), then the integral over the high-face of \(B_1\) at direction \(i\) equals the integral over the low-face of \(B_2\) at direction \(i\): \[\int_{\mathrm{face}}\!f_i|_{x_i = B_1.\mathrm{hi}[i]} = \int_{\mathrm{face}}\!f_i|_{x_i = B_2.\mathrm{lo}[i]}\] Since these appear with opposite signs in the combined boundary sum, they cancel.
Corollary 6 (). adjacent_boundary_simplifies] The net contribution of the shared face to the combined boundary is zero.
The fundamental property of the boundary operator in a chain complex is \(\partial^2 = 0\): applying the boundary twice gives zero. We prove the sign-arithmetic core of this identity: for each codimension-2 face in the double boundary, the two paths that reach it produce opposite signed contributions. This is the essential algebraic content of \(\partial^2 = 0\), though we do not define \(\partial\) as a chain-group homomorphism (our undecorated box type does not distinguish upper/lower faces as separate chain elements).
Theorem 14 (Sign cancellation, ). bdry_sq_sign_cancel]For any \(n\), indices \(i : \mathrm{Fin}(n+3)\), \(j : \mathrm{Fin}(n+2)\), and
orientation booleans \(\varepsilon, \eta\): \[(-1)^{(i + \varepsilon)} \cdot (-1)^{(j + \eta)} + (-1)^{(\mathrm{succAbove}(i,j) + \eta)} \cdot (-1)^{(\mathrm{predAbove}(j,i) + \varepsilon)} =
0\] The proof uses the parity lemma (succAbove_predAbove_neg_one_pow): \[(\mathrm{succAbove}(i,j) + \mathrm{predAbove}(j,i)) \not\equiv (i + j) \pmod{2}\] which is proved by unfolding
succAbove/predAbove to natural number arithmetic and using split_ifs <;> omega, the same technique used by mathlib’s succAbove_succAbove_succAbove_predAbove.
Theorem 15 (Geometric + algebraic, ). bdry_sq_geometric]For a box \(B\) in \(\mathbb{R}^{n+3}\), the two paths to each codimension-2 face produce:
The same face box (by the face-of-face identity), and
Opposite signs (by sign cancellation).
This establishes the sign-arithmetic component of \(\partial^2 = 0\) in cubical homology. A full \(\partial^2 = 0\) would additionally require defining \(\partial\) as a map between chain groups, which requires distinguishing upper/lower faces (not possible with our undecorated box type).
The exterior derivative extDerivCoord is a linear operator:
Proposition 16 (Linearity). For differentiable forms \(\omega, \eta\) and scalar \(c \in \mathbb{R}\): \[\begin{align} \mathrm{d}(\omega +
\eta) &= \mathrm{d}\omega + \mathrm{d}\eta \\ \mathrm{d}(c \cdot \omega) &= c \cdot \mathrm{d}\omega \\ \mathrm{d}(-\omega) &= -\mathrm{d}\omega \\ \mathrm{d}(0) &= 0
\end{align}\] Each is proved by the corresponding linearity property of fderiv (fderiv_add, fderiv_const_mul, etc.).
Combined with Stokes, these give:
theorem stokes_smooth_add (a b) (hle : a <= b) (omega eta) (ho he) :
boxIntegral (extDerivCoord (CoordNForm.add omega eta)) a b =
bdryIntegral (CoordNForm.add omega eta) a b
Proposition 17 (Product Rule / Leibniz). For a smooth scalar function \(f\) and smooth coordinate form \(\omega\): \[\mathrm{d}(f \cdot
\omega)(x) = f(x) \cdot \mathrm{d}\omega(x) + \sum_i (-1)^i \frac{\partial f}{\partial x_i}(x) \cdot \omega_i(x)\] This is the coordinate expression of the graded Leibniz rule \(d(f \wedge \omega) = df \wedge \omega + f
\cdot d\omega\); the \((-1)^i\) factor arises from wedging \(df\) (a 1-form) with the basis \(n\)-form \(dx_0\wedge\cdots\wedge\widehat{dx_i}\wedge\cdots\wedge dx_n\). The proof uses HasFDerivAt.mul from mathlib4.
Proposition 18 (Concrete Computations). We verify the formalization on concrete forms:
\(d(\text{const}) = 0\): constant forms are closed.
\(d(x_0) = 1\) in 1D: the exterior derivative of the coordinate function recovers the constant 1 (the derivative underlying FTC).
For coordinate forms on boxes, we additionally provide precomposition of coefficients by continuous linear maps and prove functoriality. We emphasize that this is coefficient-wise precomposition \((A \cdot \omega)_i(x) := \omega_i(Ax)\), which is not the true exterior-algebraic pullback used in 2: the true pullback acts via the full Fréchet derivative and mixes coefficients, while coefficient precomposition merely pre-composes each coefficient function individually.
The development includes the expected lemmas: smoothness preservation under continuous linear \(A\) (pullback_smooth, proved via ContDiff.comp); contravariant
functoriality \((A \cdot (B \cdot \omega)) = (B \circ A) \cdot \omega\) (pullback_comp); identity \(\mathrm{id}\cdot\omega = \omega\) (pullback_id); linearity in \(\omega\) (pullback_add, pullback_smul); and a Stokes specialization for precomposed forms (stokes_pullback), which follows immediately from stokes_smooth applied to \(A\cdot\omega\). We do not claim that this operation commutes with the exterior derivative
in general; it satisfies Stokes only because Stokes holds for every smooth coordinate form, regardless of its origin.
Remark 19. The Lean declaration names (pullback_comp, pullback_id, etc.) use the term “pullback” for historical reasons, but these are coefficient-wise precomposition lemmas,
not differential-form pullbacks. The true differential-form pullback via fderiv appears only in the singular cube module (2).
mathlib4↩︎A fundamental property of the exterior derivative is nilpotency: \(d(d\omega) = 0\). We derive this at the coordinate level through our bridge to mathlib4:
Theorem 20 (\(d^2{=}0\), ). dd_zero_abstract] For any smooth \(n\)-form \(\omega\) on \(\mathbb{R}^{n+1}\) (valued in \(n\)-fold continuous alternating maps \(\mathbb{R}^{n+1} \to \mathbb{R}\)), the iterated abstract exterior derivative vanishes:
\(\mathrm{extDeriv}(\mathrm{extDeriv}\;\omega) = 0\). The proof is a direct invocation of extDeriv_extDeriv from mathlib4.
Corollary 7 (Vanishing of double exterior derivative integral, ). stokes_dd_zero] For any smooth \(\omega\) and vector tuple \(v\): \(\int_{[a, b]} (\mathrm{d}(\mathrm{d}\omega))(x)(v)\,\mathrm{d}x = 0\). This follows immediately from \(\mathrm{d}^2 = 0\): the integrand is identically zero.
We formalize the sign-arithmetic and geometric core underlying \(\partial^2 = 0\) at the box level. For a box \(B \subset \mathbb{R}^{n+3}\), the double boundary \(\partial^2 B\) consists of codimension-2 faces, each appearing via two paths:
Path 1: face \(j\) of (face \(i\) of \(B\))
Path 2: face \((\mathrm{predAbove}\;j\;i)\) of (face \((\mathrm{succAbove}\;i\;j)\) of \(B\))
Theorem 21 (Face-of-face, ). double_boundary_same_face] The two paths give the same geometric box: \[\mathrm{face}_j(\mathrm{face}_i(B)) = \mathrm{face}_{\mathrm{predAbove}(j,i)}\bigl( \mathrm{face}_{\mathrm{succAbove}(i,j)}(B)\bigr).\]
Theorem 22 (Sign cancellation, ). double_boundary_cancels] The signed coefficients for the two paths sum to zero: \[(-1)^{i+\varepsilon}(-1)^{j+\eta} + (-1)^{\mathrm{succAbove}(i,j)+\eta} (-1)^{\mathrm{predAbove}(j,i)+\varepsilon} = 0.\]
Together these establish the face-of-face composition identity and sign-arithmetic core of \(\partial^2 = 0\): each codimension-2 face appears with opposite signs in the double boundary. However, this is not a full \(\partial^2 = 0\) at the chain level, since we do not define \(\partial\) as a chain-group homomorphism (our undecorated box type does not distinguish upper/lower faces as separate chain elements).
In the smooth singular cube module, we do prove the full chain complex identity \(\partial^2 = 0\) for singular chains (cf. the textbook treatment in [16]). Here the boundary operator \(\partial\) is a genuine \(\mathbb{Z}\)-linear map \(\partial : C_{n+1}(\mathbb{R}^m) \to C_n(\mathbb{R}^m)\) between singular chain groups.
Theorem 23 (\(\partial^2 = 0\), ). bdry_bdry_chain_zero]For any smooth singular \((n{+}2)\)-cube \(\sigma\): \[\partial(\partial\sigma) = 0 \quad\text{as a formal singular n-chain.}\]
The proof uses a sign-reversing fixed-point-free involution on the index set \(\mathrm{Fin}(n{+}2) \times \mathrm{Fin}(n{+}1)\) of the double sum, combined with Finset.sum_ninvolution from
mathlib4.
The involution maps: \[g(i, j) = \begin{cases} (j{+}1,\; i) & \text{if } i \leq j \\ (j,\; i{-}1) & \text{if } i > j \end{cases}\]
For each pair \((i,j)\) with \(i \leq j\), the cancellation argument has two components:
Same cube: The face-of-face identity (singularFace_comp) shows that \(\mathrm{face}_j(\delta, \mathrm{face}_i(\varepsilon, \sigma)) = \mathrm{face}_i(\varepsilon,
\mathrm{face}_{j+1}(\delta, \sigma))\), so paired terms produce the same singular cube.
Opposite sign: The coefficients \((-1)^i(-1)^j\) and \((-1)^{j+1}(-1)^i\) satisfy \((-1)^{i+j} + (-1)^{i+j+1} = 0\).
After applying the face-of-face identity, the proof uses ext\(\tau\); simp [Finsupp.single_apply]; split_ifs <;> ring to close all 256 goals of the split case analysis
automatically (goal count observed with Lean 4.29.1; may vary across versions).
Theorem 24 (\(\partial^2 = 0\) for chains, ). bdry_bdry_chain_zero_general] For any singular chain \(c \in C_{n+2}(\mathbb{R}^m)\): \[\partial(\partial c) = 0\] The proof extends from individual cubes by induction on the chain support, using the \(\mathbb{Z}\)-linearity of \(\partial\).
Corollary 8 (Integral vanishing, ). bdry_bdry_integral_zero] For any smooth singular \((n{+}2)\)-cube \(\sigma\) and \(n\)-form \(\omega\): \[\int_{\partial(\partial\sigma)} \omega = 0\]
This establishes that \((\{C_n(\mathbb{R}^m)\}, \partial)\) forms a genuine chain complex. Combined with stokes_chain, this yields the identity one would use to define integration as a cochain
map from the de Rham complex to singular cubical cochains; however, we do not formally package these complexes or prove the commuting-square diagram as a Lean structure.
The formalization consists of 44 Lean 4 source files in the LeanStokes/ directory totaling 4028 source lines, plus a root import file LeanStokes.lean. Selected modules and their roles:
| Module | Content | Key Theorems |
|---|---|---|
| Singular Cube Stokes | ||
.../Defs |
Singular cubes, faces | SmoothSingularCube, singularFace |
.../Pullback |
True pullback via fderiv | pullbackForm, integrateForm |
.../Smoothness |
Pullback smoothness | toCoordNForm_pullback_isSmooth |
.../FaceMatching |
Face matching identity | face_matching |
.../Theorem |
Main singular Stokes | singularStokes, pullback_extDeriv |
.../Chain |
Singular chains | stokes_singular_boundary |
.../BdryBdry |
\(\partial^2{=}0\) chain-level | bdry_bdry_chain_zero |
| Box Stokes Infrastructure | ||
Defs |
Core definitions | CoordNForm, extDerivCoord |
Theorem |
Main box identity | stokes_on_box |
Smooth |
Smooth-form version | stokes_smooth |
Classical |
Dim.specializations | green_on_rectangle |
Bridge |
extDeriv connection | extDeriv_topCoeff_eq_extDerivCoord |
Unified |
Combined statement | stokes_extDeriv_smooth |
FTC |
Fund.Thm.of Calculus | ftc_stokes |
Green |
Green’s theorem | green_stokes |
Divergence |
Divergence consistency | divergence_stokes |
IBP |
Integration by parts | integration_by_parts |
Chains |
Formal sums + linearity | stokes_chain |
Subdivision |
Two-box decomposition | subdivision_stokes_equiv |
Naturality |
Coeff.precomp.functoriality | pullback_comp |
DDZero |
\(d^2{=}0\) from mathlib4 |
dd_zero_abstract |
BdryOp |
\(\partial^2{=}0\) sign arith. | bdry_sq_sign_cancel |
Gauss3D |
3D divergence theorem | gauss_3d |
Demo |
Usage examples | 4D/5D/10D Stokes |
Check |
Axiom verification | 79 \#print axioms calls |
All modules are sorry-free.
We use Fin (n + 1) for the ambient dimension, avoiding the subtraction issue where (d - 1) + 1 \(\neq\) d in natural number arithmetic.
The key insight enabling the 3-line proof is defining \(f_i(x) = (-1)^i \omega_i(x)\), so that:
\(\mathrm{div}(f) = \sum_i \partial f_i / \partial x_i\), which equals the single coefficient of the top-form \(\mathrm{d}\omega\)
The divergence theorem’s boundary terms match our boundary integral
The general theorem (stokes_on_box) takes explicit hypotheses about continuity, differentiability, and integrability. The smooth version (stokes_smooth) derives these automatically from ContDiff Real Top.
Every key theorem was verified via \#print axioms (79 declarations checked, covering all main results and their transitive dependencies). All produce the same axiom set:
propext (propositional extensionality)
Classical.choice (classical logic)
Quot.sound (quotient soundness)
These are the standard axioms of Lean 4’s foundation, present in all nontrivial mathlib4 proofs. No sorry or additional axioms are used.
This section describes what the formalization process revealed about the mathematics of Stokes’ theorem and cubical chains. We present both “what was proved” and “what was learned,” following established practice in formalization papers [11], [12].
The most reusable methodological contribution of this work is the bridge theorem pattern. mathlib4’s extDeriv operates on ContinuousAlternatingMap-valued functions in full
generality, while our box-level infrastructure uses coordinate-indexed functions \(\omega_i : \mathbb{R}^{n+1} \to \mathbb{R}\). The bridge theorem (stokes_extDeriv_smooth, 5) proves that evaluating the abstract extDeriv on standard basis vectors recovers our coordinate formula.
This pattern—where a concrete computational representation is validated against an abstract library definition—may be reusable wherever formalizers face the choice between “build from scratch in a concrete representation” and “use the library’s abstract API directly” [17]. The bridge makes both approaches compatible.
A recurring obstacle in the chain-level \(\partial^2 = 0\) proof was Lean 4’s treatment of natural-number subtraction in exponents. The ring tactic cannot simplify \((-1)^{n-1}\) when \(n\) is a natural-number variable, because \(n - 1\) is not a polynomial operation (it truncates to 0 when \(n = 0\)).
Our solution was the helper lemma neg_one_pow_pred: for \(n > 0\), \((-1 : \mathbb{Z})^{n-1} = -(-1)^n\). This allows simp only [neg_one_pow_pred ...] to preprocess sign expressions before ring closes the goal. This illustrates a general principle: ring-normalizable expressions must avoid Nat subtraction, and
dedicated lemmas are needed to bridge the gap.
Lean 4’s kernel does not always reduce \((\langle e, h\rangle : \mathrm{Fin}\;n).val\) to \(e\) during unification. This caused repeated failures when proving equalities involving
composed face maps (e.g., \(\mathrm{faceInclusion}\;i\;\varepsilon \circ
\mathrm{faceInclusion}\;j\;\delta\)). The solution is explicit use of Fin.val_mk or dsimp to force projection reduction before omega can close the arithmetic goal.
We require singular cubes to be globally \(C^\infty\) (not just smooth on \([0,1]^{n+1}\)). This is mathematically stronger than necessary but has a cascade of simplification effects:
ContDiff composes freely: \(\sigma \circ \iota_{i,\varepsilon}\) is automatically \(C^\infty\) without boundary regularity arguments.
fderiv is well-defined everywhere, avoiding the need for HasFDerivAt hypotheses localized to the cube interior.
The pullback \(\sigma^*\omega\) is smooth on all of \(\mathbb{R}^{n+1}\), so box Stokes applies directly without restriction arguments.
A formalization that required smoothness only on the cube would need ContDiffOn (which composes less freely) and careful bookkeeping of open neighborhoods—substantial additional infrastructure with no mathematical payoff for
the theorem statement.
Without mathlib4’s extDeriv_pullback, the singular Stokes theorem would have been substantially harder. That single theorem provides \(d(\sigma^*\omega) = \sigma^*(d\omega)\)
pointwise and reduces singular Stokes to box Stokes in three steps: (1) apply naturality, (2) apply box Stokes to the pullback, (3) match faces. Without it we would have had to reprove naturality of the exterior derivative under pullback—a substantial
undertaking involving the Leibniz rule for wedge products and the composition of multilinear maps.
The chain-level \(\partial^2 = 0\) proof uses Finset.sum_ninvolution: to show \(\sum_{p \in S} f(p) = 0\), it suffices to find a fixed-point-free involution
\(g : S \to S\) such that \(f(p) + f(g(p)) = 0\) for all \(p\). This is a standard combinatorial technique, but its application to cubical boundary algebra
required careful construction: the involution \(g(i,j) = (j{+}1, i)\) when \(i \leq j\) and \((j, i{-}1)\) otherwise produces 256 case-split goals in the
cancellation proof, all of which close with ring after sign preprocessing.
The mathematical lesson is that \(\partial^2 = 0\) for cubical chains is fundamentally a combinatorial identity (sign-reversing involution on index pairs) rather than an algebraic identity (in the sense of ring operations). The formal proof makes this distinction precise in a way informal proofs typically obscure.
Our formalization proves Stokes’ theorem at two levels: (1) for smooth singular cubes—globally \(C^\infty\) maps \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) integrated over
\([0,1]^{n+1}\) with true pullback via fderiv—and (2) for axis-aligned boxes and their formal \(\mathbb{Z}\)-linear combinations. We state the concrete limitations
explicitly:
No manifolds or partitions of unity: The integration domain is always \([0,1]^{n+1}\) (or \([a, b]\) for boxes). No charts, atlases, smooth structures, or partition-of-unity arguments are used. Singular cubes must be single smooth parametrizations.
Global smoothness: Singular cubes are required to be \(C^\infty\) on all of \(\mathbb{R}^{n+1}\), not just on \([0,1]^{n+1}\). This is stronger than necessary mathematically, but simplifies the formalization.
Box-level form degree: The box-level infrastructure handles only coordinate \(n\)-forms on \(\mathbb{R}^{n+1}\) (one degree below top). The pullback construction is defined for arbitrary form degree \(k\); the singular Stokes theorem applies to \(n\)-forms integrated over smooth singular \((n{+}1)\)-cubes.
Box Stokes reduces to divergence theorem: The core box theorem reduces to mathlib4’s divergence theorem. The mathematical content is in the sign-convention construction, the bridge to extDeriv, and the singular-cube extension via extDeriv_pullback.
No image-domain semantics: \(\int_\sigma \omega\) is defined as an integral over \([0,1]^d\) of the pullback. We do not prove that \(\sigma([0,1]^d)\) is a submanifold or oriented geometric chain. The singular-cube module does achieve a genuine chain-complex structure: \(\partial^2 = 0\) is proved as a Finsupp identity (bdry_bdry_chain_zero).
Despite these limitations, the formalization provides:
True pullback of differential forms via the Fréchet derivative—the standard differential-geometric operation.
Smooth singular parametrizations: Singular cubes provide smooth parametrizations of curves, surfaces, and higher-dimensional objects in \(\mathbb{R}^m\), not just axis-aligned boxes. We do not prove image-domain theory (e.g., that the image is a submanifold).
Genuinely \(n\)-dimensional results for arbitrary \(n\) (instantiated in demos up to \(n{=}9\), i.e., 10D).
A bridge theorem validated against mathlib4’s abstract extDeriv.
Two-box additivity with shared-face cancellation showing composability.
1D agreement check confirming correct integral values for the FTC case.
Reusable infrastructure: the singular-cube framework, face matching, coordinate forms, and the bridge pattern may serve as building blocks for further development.
A formalization of Stokes on smooth manifolds with boundary [3] would additionally require:
Integration of forms on manifolds: defining \(\int_M \omega\) via partition of unity and chart pullbacks.
Boundary orientation: the induced orientation on \(\partial M\) from the outward normal.
Change of variables for forms: proving that the integral is chart-independent.
Stokes on half-spaces: the local compactly-supported version.
Singular chains on manifolds: extending our singular cube infrastructure to manifold-valued maps.
Each of these is a substantial formalization project in its own right. Our singular cube framework provides a natural starting point: once manifold charts and partition of unity are available, singular cubes may serve as the local parametrizations over which Stokes is applied.
Harrison’s HOL Light formalization [1] is the closest prior work. A key finding of our investigation is that Harrison’s development proves Stokes for convex and polyhedral domains extended to polyhedral chains—not for arbitrary smooth manifolds with boundary, as some secondary sources suggest.
With the addition of singular cubes, the mathematical scope of our development is complementary to Harrison’s: Harrison’s singular simplices/polytopes are parametrized by smooth maps from convex domains; our singular cubes are parametrized by
smooth maps from the unit cube. Harrison has strictly broader geometric domain coverage (convex polytopes with simplicial decomposition); our contribution is a Lean 4/mathlib4 formalization with direct bridge to extDeriv and reuse of extDeriv_pullback. Both use the true differential-form pullback.
| Aspect | Harrison (HOL Light) | This work (Lean 4) |
|---|---|---|
| Domain | Convex polytopes | Singular cubes + boxes |
| Parametrization | Smooth maps on polytopes | \(C^\infty\) maps \(\sigma : \mathbb{R}^{n+1} \to \mathbb{R}^m\) |
| Pullback | True (smooth maps) | True (via fderiv) |
| Chains | Polyhedral chains | \(\mathbb{Z}\)-singular + cubical chains |
| Integration | Gauge (HK) | Bochner (set integral) |
| Ext.derivative | Custom definition | Via divergence + extDeriv_pullback |
| \(d^2{=}0\) | Algebraic | Via extDeriv_extDeriv + chain involution |
| Bridge | None | To extDeriv |
| Type theory | Simple (HOL) | Dependent (Lean 4) |
| Library reuse | Self-contained | Reduces to mathlib4 |
The distinguishing feature of our approach is the bridge to mathlib4’s abstract exterior algebra and the use of extDeriv_pullback for the singular theorem. We are not aware of a directly comparable bridge to an
independently developed abstract exterior-derivative API in HOL Light, since HOL Light does not maintain an independent abstract exterior algebra alongside its integration theory. This means our infrastructure is directly connected to the abstract theory
and may benefit from future growth in mathlib4’s manifold integration API.
Harrison’s advantage is strictly broader domain generality: convex polytopes include simplices and other non-cubical shapes. Our singular cubes always have the unit cube as the parameter domain; the smooth map \(\sigma\) can produce many parametrized images (possibly degenerate or self-overlapping), but the theorem remains a statement about integration over the parameter cube, not over the image as a domain.
The complete formalization is available at:
A Software Heritage archive (SWHID) will be deposited prior to publication. It builds with Lean 4.29.1 and mathlib4 (pinned to rev = "v4.29.1" in lakefile.toml; both version pins are in the repository). To
verify:
lake exe cache get && lake build
Representative \#print axioms output (all checked theorems produce the same three axioms):
'SingularCubeStokes.singularStokes' depends on axioms:
[propext, Classical.choice, Quot.sound]
'CubeStokes.stokes_on_box' depends on axioms:
[propext, Classical.choice, Quot.sound]
'SingularCubeStokes.stokes_singular_boundary' depends on axioms:
[propext, Classical.choice, Quot.sound]
We have presented a sorry-free Lean 4 formalization of Stokes’ theorem for smooth singular cubes and axis-aligned boxes in arbitrary dimension, comprising 44 modules with 205 named declarations across approximately 4000 source lines. All results depend
only on the standard axioms (propext, Classical.choice, Quot.sound), confirmed by 79 \#print axioms checks covering both the box and singular cubical layers.
The headline theorem—Stokes for smooth singular cubes with true differential-form pullback—reduces to the box theorem in three steps: naturality of the pullback under the exterior derivative (\(\mathrm{d}(\sigma^*\omega) = \sigma^*(\mathrm{d}\omega)\), from mathlib4’s extDeriv_pullback), box Stokes applied to \(\sigma^*\omega\), and a chain-rule
face-matching identity. The same machinery extends by \(\mathbb{Z}\)-linearity to singular chains, on which we prove \(\partial(\partial\sigma)=0\) via a sign-reversing involution on the
double-boundary index set.
Three ingredients seem most likely to be useful for downstream formalizations: (i) the bridge theorem pattern, which validates a concrete coordinate formula against an abstract library definition; (ii) the face matching identity relating box-boundary integrals of pullback forms to face integrals of singular cubes; and (iii) the involution-based proof of \(\partial^2 = 0\) on singular cubical chains.
A full Lean 4 formalization of Stokes for smooth manifolds with boundary still requires integration of forms via partition of unity and chart pullbacks, boundary orientation, and image-domain singular chains. Our singular-cube framework provides a
natural local building block for such an effort once mathlib4’s manifold integration API matures.
The artifact is reproducible via lake exe cache get && lake build and is available at https://github.com/d0d1/lean-stokes-theorem under GPL-3.0-only, with
versions pinned via lean-toolchain and lakefile.toml.
We thank the mathlib4 community for maintaining the mathematical library on which this work depends, and the Lean 4 developers for the proof assistant infrastructure.
Mathlib.MeasureTheory.Integral.DivergenceTheorem,
https://leanprover-community.github.io/mathlib4_docs/.Mathlib.Analysis.Calculus.DifferentialForm.Basic,
https://leanprover-community.github.io/mathlib4_docs/.Mathlib.Geometry.Manifold.SmoothManifoldWithCorners,
https://leanprover-community.github.io/mathlib4_docs/.Independent Researcher. ORCID: 0009-0002-8056-1774.↩︎
Microsoft. ORCID: 0009-0003-3568-0325.↩︎
Centro de Informática, Universidade Federal de Pernambuco. ORCID: 0000-0003-1482-0977.↩︎
Lean code excerpts use ASCII equivalents of Unicode operators (e.g., -> for \(\to\), forall for \(\forall\)) for typesetting compatibility. The
repository uses standard Unicode Lean 4 syntax.↩︎
The type E [Alt^Fin k]->L[R] F denotes ContinuousAlternatingMap R E F (Fin k)—a continuous \(k\)-linear alternating map.↩︎