A formal language for physics โ where compilation is proof.
- ๐ญ What is Measure?
- ๐ก Core Ideas
- ๐ Physics Coverage
- ๐ Dimension System
- ๐ง C++ FFI Kernel
- ๐ฌ Physical Constants
- ๐ External Engine Integration
- ๐ ๏ธ Tactics
- ๐๏ธ Project Structure
- ๐ Getting Started
- ๐ Verification Stats
- ๐งญ Philosophy
- ๐ License
Measure is a programming language designed for one purpose: proving that physics theories are internally self-consistent.
Physics is not mathematics. It is grounded in measurement and experiment, inherently approximate, and full of contradictions between theories. Quantum mechanics and general relativity both work โ and they disagree. Measure doesn't pretend this isn't the case. Instead, it gives you the tools to:
- ๐ Prove local self-consistency โ each theory is verified on its own terms
- โก Track contradictions explicitly โ conflicting theories are marked, not hidden
- ๐ Propagate uncertainty โ error is a first-class citizen, not an afterthought
- ๐งฑ Check dimensions at compile time โ if your equation has wrong units, it doesn't compile
theory NewtonianGravity where
axiom newton2 (m : ExactQ dimMass) (a : ExactQ dimAccel)
: ExactQ dimForce
axiom gravForce (mโ mโ : ExactQ dimMass) (r : ExactQ dimLength)
: ExactQ dimForce
axiom kineticEnergy (m : ExactQ dimMass) (v : ExactQ dimVelocity)
: ExactQ dimEnergy
axiom energyConservation
(keโ peโ keโ peโ : ExactQ dimEnergy)
(h : keโ.value + peโ.value = keโ.value + peโ.value)
: keโ.value + peโ.value = keโ.value + peโ.valueIf this file compiles, the theory is self-consistent. Dimensions checked. Conservation laws verified. No exceptions.
Every theory block triggers a 6-phase verification pipeline:
| Phase | Action |
|---|---|
| 1 | Parent compatibility check |
| 2 | C++ TheoryRegistry registration |
| 3 | FFI domain compatibility check |
| 4 | Auto-degradation (mark parents as approximations if rigor gap exists) |
| 5 | Rigor auto-propagation (weakest-link rule) |
| 6 | Self-consistency verification (dimensional consistency + conservation laws) |
If it compiles, it's consistent. If it's not consistent, it doesn't compile.
Each physics theory is an isolated module with its own axioms, rigor level, and domain. Theories relate to each other through four explicit relation types:
| Relation | Meaning |
|---|---|
extension |
Theory B extends A with new axioms |
approx |
Theory A approximates B under limiting conditions (e.g., v/c โ 0) |
conflict |
Theories have contradictory axioms (with explicit witness) |
compatible |
Theories are explicitly compatible |
When a new unifying theory arrives, old theories don't break โ they gracefully degrade to approximations.
strict > approximate > empirical > numerical
Rigor propagates by the weakest-link rule: if your theory imports an empirical module, your combined rigor is at most empirical. No pretending.
Three error propagation models, unified under one typeclass:
| Model | Method | Use Case |
|---|---|---|
| ๐ Gaussian | First-order Taylor + derivative tracking | Standard measurements |
| ๐ Affine | Noise symbols + Chebyshev bounds | Correlated errors |
| ๐ฆ Interval | Conservative closed intervals | Worst-case bounds |
Quantities carry their uncertainty in the type system. ExactQ for defined constants (speed of light), UncertainQ for measured values (gravitational constant). The type forces you to choose.
| Layer | Type | Purpose |
|---|---|---|
| ๐ Runtime | Quantity d c (Float) |
Fast computation with error propagation |
| ๐ Proof | PhysReal d (โ) |
Formal proofs backed by Mathlib |
The bridge between them is exact in one direction (Float โ โ via IEEE 754 bit decoding) and explicitly approximate in the other (โ โ Float via axiomatic rounding).
25 domains, each with multiple submodules:
| Domain | Submodules | Rigor |
|---|---|---|
| ๐ Classical Mechanics | Newton, Lagrangian, Hamiltonian, Noether, Conservation | strict |
| โก Electromagnetism | Maxwell, Potential, Wave | strict |
| ๐ฎ Quantum Mechanics | Hilbert, Schrรถdinger, Operators | strict |
| ๐ Special Relativity | Minkowski, Lorentz | strict |
| ๐ณ๏ธ General Relativity | Einstein, Metric | strict |
| ๐ก๏ธ Thermodynamics | Laws | strict |
| ๐ Statistical Mechanics | Ensemble | strict |
| ๐ Fluid Mechanics | Navier-Stokes, Waves | strict |
| โ๏ธ Atomic Physics | Hydrogen, Nuclear | strict |
| ๐ฅ Particle Physics | Standard Model, Scattering | strict |
| ๐ Quantum Information | Qubit, Entanglement | strict |
| ๐ QFT | Fields, Fock Space | approximate |
| ๐ Condensed Matter | Crystal, Band Theory | approximate |
| ๐ฆ Optics | Geometric, Wave | approximate |
| โ๏ธ Plasma Physics | MHD, Basic | approximate |
| ๐งฌ Biophysics | Diffusion, Membrane | empirical |
| ๐ Geophysics | Atmosphere, Seismology | empirical |
| ๐๏ธ Material Science | Semiconductor, Superconductivity, Elasticity | empirical |
| ๐ฆ Nonlinear Dynamics | Chaos, Dynamical Systems | numerical |
| ๐ญ Quantum Gravity | LQG, Holography | numerical |
| ๐ป String Theory | Strings, Supersymmetry | numerical |
| ๐ Astrophysics | Cosmology, Stellar Structure | approximate |
| ๐ฎ Frontier | Dark Matter, Dark Energy, Quantum Thermodynamics | numerical |
| ๐ Historical | Classical Models, Approximate Theories, Quantum Models | empirical |
| ๐ Dimensional | Cross-cutting dimensional analysis | strict |
7-component SI dimension vectors with rational exponents:
structure Dim where
L : QExp := QExp.zero -- Length (m)
M : QExp := QExp.zero -- Mass (kg)
T : QExp := QExp.zero -- Time (s)
I : QExp := QExp.zero -- Electric current (A)
ฮ : QExp := QExp.zero -- Temperature (K)
N : QExp := QExp.zero -- Amount of substance (mol)
J : QExp := QExp.zero -- Luminous intensity (cd)Dimension arithmetic is compile-time verified:
-- Force has the same dimension as mass ร acceleration
theorem force_dim_check : dimForce = Dim.mul dimMass dimAccel := by
native_decideWrong dimensions โ compilation error. No runtime surprises.
A high-performance C++ kernel handles computationally intensive operations:
| Component | Description |
|---|---|
| ๐ก๏ธ Conservation Checker | 3-pass static analysis (decompose โ compute delta โ residual analysis) with CAS delegation |
| ๐ธ๏ธ Theory Graph | 4-stage conflict detection (cache โ syntactic โ semantic โ SMT) |
| ๐ Epsilon Tracker | Tracks approximate equality error accumulation across proof chains |
| โ Approximate Equality | IEEE 754-aware comparison with configurable tolerance |
| ๐ Rigor Propagation | Weakest-link computation across theory dependency graphs |
The trust boundary between Lean and C++ is secured by a private opaque TrustToken โ external code cannot forge verification results.
Built-in CODATA 2022 + SI 2019 constants with proper uncertainty tracking:
| Constant | Symbol | Status | Source |
|---|---|---|---|
| Speed of light | c |
โ Exact | SI 2019 defining |
| Planck constant | h |
โ Exact | SI 2019 defining |
| Boltzmann constant | k_B |
โ Exact | SI 2019 defining |
| Elementary charge | e |
โ Exact | SI 2019 defining |
| Avogadro constant | N_A |
โ Exact | SI 2019 defining |
| Gravitational constant | G |
๐ Gaussian 1ฯ | CODATA 2022 |
| Electron mass | m_e |
๐ Gaussian 1ฯ | CODATA 2022 |
| Fine-structure constant | ฮฑ |
๐ Gaussian 1ฯ | CODATA 2022 |
| ... and more |
Exact constants carry zero uncertainty. Measured constants carry Gaussian error. The type system enforces the distinction.
Delegate heavy computation to external CAS engines via JSON-RPC 2.0:
| Engine | Backend | Use Case |
|---|---|---|
| ๐ฃ Julia | SymbolicUtils.jl | Symbolic algebra |
| ๐ Python | SymPy | Symbolic computation |
| ๐ด Mathematica | Wolfram Language | Full CAS |
Plus database connectors for NIST CODATA and PDG particle data, with 4-tier caching (memory โ disk โ network โ fallback).
Six physics-aware proof tactics:
| Tactic | Purpose |
|---|---|
dim_check |
๐ Verify dimensional consistency |
conserve |
๐ก๏ธ Verify conservation laws via C++ checker |
approximate |
๐ Verify approximation error bounds |
by_symmetry |
๐ Simplify proofs using symmetry arguments |
limit_of |
๐ญ Verify limiting processes between theories |
native_decide |
โก Lean's built-in decidable verification |
measure/
src/
Main.lean # ๐ช CLI entry point
Measure.lean # ๐ฆ Root barrel file
Measure/
Dim/ # ๐ 7-dimensional SI system with rational exponents
Quantity/ # ๐ข Dimensioned values with certainty tracking
Error/ # ๐ Gaussian, Affine, Interval uncertainty models
Theory/ # ๐งฉ Theory modules, relations, rigor levels
Conservation/ # ๐ก๏ธ Noether theorem, conservation law verification
Syntax/ # โ๏ธ Tactics, theory blocks, attributes
Kernel/ # ๐ง C++ FFI bridge and wrappers
External/ # ๐ CAS engine integration (Julia/Python/Mathematica)
Math/ # ๐ Mathlib bridge (real analysis, linear algebra)
Physics/ # ๐ 25 physics domain formalizations
Unit/ # โ๏ธ Unit system and conversions
Constants.lean # ๐ฌ CODATA 2022 physical constants
Examples/ # ๐ Worked examples (Newton, SR, EM, QM, Thermo)
kernel/ # โก C++ kernel source
conservation.{cpp,h} # Conservation checker
theory_graph.{cpp,h} # Theory conflict detection
epsilon_tracker.{cpp,h} # Error accumulation tracking
ffi_bridge.cpp # Lean โ C++ bridge (60+ functions)
lib/measure/
lakefile.lean # ๐๏ธ Lake build configuration
test/
TestDim.lean # Dimension system tests
TestQuantity.lean # Quantity arithmetic tests
TestConstants.lean # Physical constants tests
TestBridge.lean # FloatโReal bridge tests
TestPhysics.lean # Physics module tests
TestProperties.lean # Property-based tests
TestIntegration.lean # Integration tests
TestStress.lean # Stress tests
Prerequisites:
- elan โ Lean 4 toolchain manager
- C++17 compiler
- CMake >= 3.16
# Clone
git clone https://github.com/SStarrySSky/Measure.git
cd Measure
# Build (fetches Mathlib automatically)
cd measure/lib/measure
lake build
# Run tests
lake build MeasureTest
# CLI
lake exe measure-cli help
lake exe measure-cli check src/Measure/Physics/
lake exe measure-cli constants
lake exe measure-cli theories| Metric | Value |
|---|---|
| ๐ Source files | 161 (.lean) + 18 (C++) |
| ๐ Lines of code | ~20,000 (Lean) + ~3,000 (C++) |
| โ Theorems / Lemmas | 267 |
| ๐ Axioms | 23 (20 physics/math, 2 trust boundary, 1 computational) |
| ๐ซ Sorry | 0 |
| ๐๏ธ Build jobs | 2,881 (all passing) |
| ๐งช Test jobs | 2,639 (all passing) |
| ๐ Physics domains | 25 |
Every axiom is documented and justified. The 20 physics/math axioms represent genuine theorems that require Mathlib infrastructure not yet available (multivariate calculus, ergodic theory, etc.). The 2 trust boundary axioms are guarded by a private token. Zero sorry means zero incomplete proofs.
Physics is not mathematics. It is built on measurement, experiment, and approximation. Theories contradict each other โ and that's fine. What matters is that each theory is self-consistent on its own terms, and that the contradictions are tracked, not hidden.
Measure doesn't try to unify all of physics into one consistent framework. That's not possible, and pretending otherwise is dishonest. Instead, it provides the infrastructure to:
- ๐ Formalize any physics theory as a typed, dimension-checked module
- โ Verify its internal self-consistency at compile time
- ๐ Relate it to other theories with explicit compatibility/conflict declarations
- ๐ข Compute with proper uncertainty propagation
- ๐ Prove properties using Mathlib-backed real analysis
The goal is not to replace physicists. It's to give them a tool where the compiler catches the mistakes that humans miss โ wrong dimensions, violated conservation laws, inconsistent approximations โ so they can focus on the physics.