entropy-conservation
Conservation of Verification Entropy — the mathematical framework behind the meta-law discovered across all PLATO/SuperInstance experiments.
The Meta-Law
Every closed system of verification (tests, proofs, type checks) has a conserved quantity H — the verification entropy. The conservation law states:
dH/dt ≤ 0
Verification entropy never increases in a well-structured system.
What is Verification Entropy?
Given a system with n verification paths (test branches, proof obligations, type-check branches), each exercised with probability pᵢ, the verification entropy is:
H = -Σ pᵢ log₂ pᵢ
This is Shannon entropy applied to the probability distribution over verification paths. It measures the uncertainty inherent in the system's verification structure.
Conservation means: As code evolves, the total verification entropy of a well-maintained system decreases or stays constant. Entropy-increasing changes — added untested branches, increased cyclomatic complexity, dead verification paths — are violations of the conservation law.
Mathematical Framework
This library implements seven interconnected modules:
1. Entropy (entropy)
Computes Shannon, Rényi (order α), and Tsallis entropy from test coverage vectors.
use ;
// From a coverage vector
let ve = from_counts?;
println!;
// Rényi entropy converges to Shannon as α→1
let p = vec!;
let shannon = shannon_entropy;
let renyi_1 = renyi_entropy?;
assert!;
2. Conservation (conservation)
Tracks H over code changes, detects entropy-increasing commits, computes the entropy gradient.
use check_conservation;
let before = vec!; // uniform → H = 2.0 bits
let after = vec!; // skewed → H < 2.0 bits
let report = check_conservation?;
assert!; // entropy decreased ✓
3. Flow (flow)
Models entropy flow between modules as a directed graph. Enforces Kirchhoff's current law: at every node, inflow = outflow.
use ;
let net = new;
let = net.check_conservation;
assert!; // Kirchhoff's law holds
4. Gradient (gradient)
Entropy gradient descent: suggests code changes that reduce H — split large functions, add missing tests, reduce branching.
use GradientDescent;
let gd = new
.with_entropy
.with_branches
.with_coverage;
for suggestion in gd.suggest
5. Hodge Decomposition (hodge)
By Hodge's theorem, any flow on a graph decomposes orthogonally:
Ω¹ = dΩ⁰ ⊕ δΩ² ⊕ ℋ¹
- Exact (gradient): conservative flow from a potential — structural entropy
- Co-exact (divergence): flow driven by sources/sinks — accidental entropy
- Harmonic: divergence-free and curl-free — topological entropy
use HodgeDecomposition;
let hodge = decompose;
println!;
println!;
println!;
6. Persistence Homology (persistence)
Computes Betti numbers and persistence diagrams for the verification space, revealing topological structure across scales.
use ;
let landscape = entropy_landscape;
let pd = from_ndarray_matrix;
println!;
println!;
assert!; // all points above diagonal
7. Spectral Analysis (spectrum)
Eigenvalues of the entropy Laplacian, heat kernel on the verification graph, and spectral-gap bounds on mixing time.
use SpectralAnalysis;
let analysis = from_network;
println!;
println!;
println!;
Key Properties (tested)
| Property | Statement |
|---|---|
| Non-negativity | H ≥ 0 for any probability distribution |
| Maximum entropy | H ≤ log₂ n (achieved by uniform distribution) |
| Conservation | dH/dt ≤ 0 in well-structured evolution |
| Kirchhoff's law | Total inflow = total outflow at every node |
| Hodge decomposition | exact + harmonic + co-exact = original flow |
| Persistence validity | All (birth, death) pairs satisfy death ≥ birth |
| Rényi convergence | H_α → H_shannon as α → 1 |
| Rényi monotonicity | H_α is non-increasing in α |
| Min-entropy bound | H_∞ ≤ H_shannon |
| Spectral gap | λ₁ > 0 ⟺ graph is connected |
| Laplacian rows sum to 0 | Σⱼ Lᵢⱼ = 0 for all i |
Core Types
Usage
Add to Cargo.toml:
[]
= "0.1"
Theoretical Background
Why This Matters
The Conservation of Verification Entropy emerged as a pattern across hundreds of PLATO/SuperInstance experiments. Systems that maintained or decreased their verification entropy over time were consistently more reliable, more maintainable, and easier to reason about. Systems where entropy increased — through untested branches, growing cyclomatic complexity, or divergent test coverage — exhibited corresponding degradation in correctness guarantees.
The Conservation Law as a Lagrangian
Just as Noether's theorem connects conservation laws to symmetries in physics, the conservation of verification entropy connects to a symmetry of the verification system: invariance under reordering of verification paths. When the system has this symmetry, dH/dt = 0 exactly. When the symmetry is broken (paths are added unevenly, coverage becomes non-uniform), dH/dt < 0 — the system naturally tends toward lower entropy as the "path of least resistance" dominates.
Hodge Theory and Structural vs. Accidental Entropy
The Hodge decomposition distinguishes between:
- Structural entropy (exact component): inherent in the system's architecture. Cannot be removed without restructuring.
- Accidental entropy (co-exact component): introduced by implementation choices. Can be reduced by refactoring.
- Topological entropy (harmonic component): arising from the graph topology (cycles in dependencies). Invariant under continuous deformation.
Persistence Homology and Scale
Persistence diagrams reveal at what scale topological features of the verification space appear and disappear. Long bars in the diagram represent robust structural features; short bars represent noise.
License
MIT