Measure
๐ A dependently-typed language on Lean 4 for formalizing physics. Dimensions, uncertainty & theory conflicts are first-class types. 25 domains, 267 theorems, 0 sorry. Theories can conflict, approximate or extend each other โ because physics isn't one consistent system. Compilation = proof.
Install / Use
/learn @SStarrySSky/MeasureREADME
๐ Table of Contents
- ๐ญ 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
๐ญ What is Measure?
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โ.value
If this file compiles, the theory is self-consistent. Dimensions checked. Conservation laws verified. No exceptions.
๐ก Core Ideas
โ๏ธ Compilation = Proof
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.
๐ฆ Theories as Modules
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.
๐๏ธ Four Rigor Levels
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.
๐ Uncertainty is Fundamental
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.
๐งฌ Dual-Layer Architecture
| 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).
๐ Physics Coverage
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 |
๐ Dimension System
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_decide
Wrong dimensions โ compilation error. No runtime surprises.
๐ง C++ FFI Kernel
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.
๐ฌ Physical Constants
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.
๐ External Engine Integration
Delegate heavy computation to external CAS engines via JSON-RP
Related Skills
node-connect
348.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.0kQQBot ๅฏๅชไฝๆถๅ่ฝๅใไฝฟ็จ <qqmedia> ๆ ็ญพ๏ผ็ณป็ปๆ นๆฎๆไปถๆฉๅฑๅ่ชๅจ่ฏๅซ็ฑปๅ๏ผๅพ็/่ฏญ้ณ/่ง้ข/ๆไปถ๏ผใ
