SkillAgentSearch skills...

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/Measure

README

<p align="center"> <h1 align="center">๐Ÿ“ Measure</h1> <p align="center"> <em>A formal language for physics โ€” where compilation is proof.</em> </p> <p align="center"> <a href="#-getting-started"><img src="https://img.shields.io/badge/Lean_4-Mathlib-blue?style=flat-square&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xMiAyTDIgMTloMjBMMTIgMnoiLz48L3N2Zz4=" alt="Lean 4"></a> <a href="#-verification-stats"><img src="https://img.shields.io/badge/theorems-267-brightgreen?style=flat-square" alt="Theorems"></a> <a href="#-verification-stats"><img src="https://img.shields.io/badge/sorry-0-success?style=flat-square" alt="Sorry"></a> <a href="#-verification-stats"><img src="https://img.shields.io/badge/axioms-23-yellow?style=flat-square" alt="Axioms"></a> <a href="#-physics-coverage"><img src="https://img.shields.io/badge/physics_domains-25-blueviolet?style=flat-square" alt="Domains"></a> <a href="#-verification-stats"><img src="https://img.shields.io/badge/build-2881_jobs_passing-brightgreen?style=flat-square" alt="Build"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License"></a> </p> </p>

๐Ÿ“‘ Table of Contents


๐Ÿ”ญ 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

View on GitHub
GitHub Stars8
CategoryDevelopment
Updated1mo ago
Forks0

Languages

Lean

Security Score

90/100

Audited on Feb 21, 2026

No findings