Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Coulomb field of a charge density, divergence, and flux through a sphere in R3\mathbb R^3R3

Definition
CoulombGauss_basic

by LG · Sep 30, 2026 · Mathlib 0df444a (Lean v4.33.1)

electrostaticsmathematical-physicsvector-calculus

This file fixes the objects used in the derivation of Gauss's law from Coulomb's law.

  1. Space. R3\mathbb R^3R3 is the Euclidean space of triples with the usual inner product ⟨⋅,⋅⟩\langle\cdot,\cdot\rangle⟨⋅,⋅⟩ and norm ∣⋅∣|\cdot|∣⋅∣.
  2. Coulomb kernel. For r,r′∈R3r, r' \in \mathbb R^3r,r′∈R3,
e(r,r′)  =  r−r′∣r−r′∣3,e(r,r') \;=\; \frac{r-r'}{|r-r'|^{3}},e(r,r′)=∣r−r′∣3r−r′​,

the field (up to the factor 1/(4πε0)1/(4\pi\varepsilon_0)1/(4πε0​)) of a unit point charge at r′r'r′, evaluated at rrr. 3. Electric field of a charge distribution. For a constant ε0\varepsilon_0ε0​, a charge density ρ:R3→R\rho:\mathbb R^3\to\mathbb Rρ:R3→R and a region Ω⊆R3\Omega\subseteq\mathbb R^3Ω⊆R3,

E(r)  =  14πε0∫Ωρ(r′) r−r′∣r−r′∣3 d3r′,\mathbf E(r) \;=\; \frac{1}{4\pi\varepsilon_0}\int_{\Omega}\rho(r')\,\frac{r-r'}{|r-r'|^{3}}\,d^3r' ,E(r)=4πε0​1​∫Ω​ρ(r′)∣r−r′∣3r−r′​d3r′,

the integral being the Lebesgue integral over Ω\OmegaΩ. 4. Divergence. For a vector field F:R3→R3F:\mathbb R^3\to\mathbb R^3F:R3→R3, ∇⋅F(r)=∑i=13∂iFi(r)\nabla\cdot F(r)=\sum_{i=1}^{3}\partial_i F_i(r)∇⋅F(r)=∑i=13​∂i​Fi​(r), computed from the (Fréchet) derivative of each coordinate function at rrr. 5. Flux through a sphere. For a centre ccc and radius RRR, the outward flux of FFF through the sphere ∂BR(c)\partial B_R(c)∂BR​(c) is

ΦF(c,R)  =  ∮∂BR(c)F⋅dS  =  R2∫S2⟨F(c+Ru), u⟩ dσ(u),\Phi_F(c,R) \;=\; \oint_{\partial B_R(c)} F\cdot dS \;=\; R^{2}\int_{S^{2}} \langle F(c+Ru),\,u\rangle\,d\sigma(u),ΦF​(c,R)=∮∂BR​(c)​F⋅dS=R2∫S2​⟨F(c+Ru),u⟩dσ(u),

where σ\sigmaσ is the standard surface-area measure on the unit sphere S2S^2S2 (total mass 4π4\pi4π).

These definitions are shared by the goal theorem and all milestones of the mission.

Formalization Note Lean's total-function conventions apply: the kernel takes the value 000 at r=r′r=r'r=r′ (where ∣r−r′∣−3|r-r'|^{-3}∣r−r′∣−3 is read as 000), a non-integrable integrand integrates to 000, and the derivative of a function that is not differentiable at a point is taken to be 000. The surface measure is Mathlib's Measure.toSphere of Lebesgue measure, which assigns S2S^2S2 the mass 3⋅∣B1(0)∣=4π3\cdot|B_1(0)| = 4\pi3⋅∣B1​(0)∣=4π.

Definition code
import Mathlib

namespace CoulombGauss

open MeasureTheory

/-- Physical three-dimensional Euclidean space `ℝ³`. -/
abbrev Vec3 : Type := EuclideanSpace ℝ (Fin 3)

/-- The Coulomb kernel `(r - r') / |r - r'|³`: the field direction-and-falloff of a unit point
charge located at `r'`, evaluated at `r` (without the factor `1 / (4π ε₀)`). At `r = r'` Lean's
conventions give the value `0`. -/
noncomputable def coulombKernel (r r' : Vec3) : Vec3 :=
  (‖r - r'‖ ^ 3)⁻¹ • (r - r')

/-- The electrostatic field generated by a charge density `ρ` occupying the region `Ω`:
`E(r) = 1/(4π ε₀) ∫_Ω ρ(r') (r - r') / |r - r'|³ d³r'`. -/
noncomputable def electricField (ε₀ : ℝ) (ρ : Vec3 → ℝ) (Ω : Set Vec3) (r : Vec3) : Vec3 :=
  (1 / (4 * Real.pi * ε₀)) • ∫ r' in Ω, ρ r' • coulombKernel r r'

/-- The divergence `∇ · F (r) = ∑ᵢ ∂ Fᵢ / ∂ xᵢ (r)` of a vector field on `ℝ³`, computed from the
Fréchet derivatives of the coordinate functions. -/
noncomputable def divergence (F : Vec3 → Vec3) (r : Vec3) : ℝ :=
  ∑ i : Fin 3, fderiv ℝ (fun x => F x i) r (EuclideanSpace.single i 1)

/-- The outward flux `∮_{∂B_R(c)} F · dS` of a vector field `F` through the sphere of radius `R`
centred at `c`, written via the standard surface measure `σ` on the unit sphere `S²`
(total mass `4π`): `R² ∫_{S²} F(c + R u) · u dσ(u)`. -/
noncomputable def sphereFlux (F : Vec3 → Vec3) (c : Vec3) (R : ℝ) : ℝ :=
  R ^ 2 * ∫ u : Metric.sphere (0 : Vec3) 1,
    inner ℝ (F (c + R • (u : Vec3))) (u : Vec3) ∂(volume.toSphere)

end CoulombGauss
Source
Wikipedia, "Coulomb's law", https://en.wikipedia.org/wiki/Coulomb%27s_law (snapshot supplied as PDF, 30 Sep 2026), section "Relation to Gauss's law" -> "Deriving Gauss's law from Coulomb's law", box "Proof (without Dirac Delta)" (PDF pp. 8-9).
Read-back

What the Lean code literally says, in plain math · Aristotle (Harmonic)

NON-BLIND READ-BACK — NOT INDEPENDENT TESTIMONY. This read-back was written by the same agent that drafted the Lean statements of this proposal (at the explicit direction of the proposal owner), with full knowledge of the source text and of the intended meaning. It is therefore not a blind audit and must not be mistaken for independent testimony. Reviewers should compare the Lean code against the source directly.

The file declares, inside the namespace CoulombGauss, one abbreviation and four noncomputable definitions.

  • Vec3\mathrm{Vec3}Vec3 is the Euclidean space R3\mathbb R^3R3 (real coordinates indexed by {0,1,2}\{0,1,2\}{0,1,2} with the ℓ2\ell^2ℓ2 norm and standard inner product).
  • coulombKernel(r,r′)=(∣r−r′∣3)−1 (r−r′)\mathrm{coulombKernel}(r,r') = (|r-r'|^3)^{-1}\,(r-r')coulombKernel(r,r′)=(∣r−r′∣3)−1(r−r′). When r=r′r=r'r=r′ the inverse of 000 is 000 by convention, so the value is the zero vector; otherwise it is (r−r′)/∣r−r′∣3(r-r')/|r-r'|^3(r−r′)/∣r−r′∣3.
  • electricField(ε0,ρ,Ω)(r)=14πε0∫Ωρ(r′) coulombKernel(r,r′) dr′\mathrm{electricField}(\varepsilon_0,\rho,\Omega)(r) = \dfrac{1}{4\pi\varepsilon_0}\displaystyle\int_\Omega \rho(r')\,\mathrm{coulombKernel}(r,r')\,dr'electricField(ε0​,ρ,Ω)(r)=4πε0​1​∫Ω​ρ(r′)coulombKernel(r,r′)dr′, a Bochner integral against Lebesgue measure restricted to Ω\OmegaΩ. No hypothesis is built in: ε0\varepsilon_0ε0​ is any real (if ε0=0\varepsilon_0=0ε0​=0 the prefactor is 1/0=01/0=01/0=0 and the field is identically 000), ρ\rhoρ is any real function, Ω\OmegaΩ any set; if the integrand is not integrable on Ω\OmegaΩ the integral, hence the field, is 000.
  • divergence(F)(r)=∑i=02DFi(r)[ei]\mathrm{divergence}(F)(r) = \sum_{i=0}^{2} DF_i(r)[e_i]divergence(F)(r)=∑i=02​DFi​(r)[ei​], where FiF_iFi​ is the iii-th coordinate of FFF, DFi(r)DF_i(r)DFi​(r) is its Fréchet derivative at rrr and eie_iei​ the iii-th standard basis vector. If FiF_iFi​ is not differentiable at rrr, its derivative is taken to be 000, so the corresponding term is 000.
  • sphereFlux(F,c,R)=R2∫S2⟨F(c+Ru),u⟩ dσ(u)\mathrm{sphereFlux}(F,c,R) = R^2\displaystyle\int_{S^2}\langle F(c+Ru),u\rangle\,d\sigma(u)sphereFlux(F,c,R)=R2∫S2​⟨F(c+Ru),u⟩dσ(u), where S2S^2S2 is the unit sphere of R3\mathbb R^3R3 and σ\sigmaσ is the measure on S2S^2S2 obtained from Lebesgue measure by the cone construction (Mathlib's toSphere, total mass 3∣B1(0)∣=4π3|B_1(0)|=4\pi3∣B1​(0)∣=4π). It is defined for every real RRR (including R≤0R\le 0R≤0), and is 000 if the integrand is not σ\sigmaσ-integrable.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me