Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Capacity Atlas uses Lean 4 for formal verification.
nonempty Lean docstrings (`/-- ... -/`), or use `@[inherit_doc source]` when the
meaning is shared. State the purpose, domain, and units when they are not clear
from the type. The documentation linter runs with warnings as errors in CI.
- Remove unused theorem parameters instead of hiding them behind underscore names
or linter exclusions. The compiled audit checks the proof, result, and dependent
parameter types. Derive redundant conditions inside the proof where possible;
review mathematical generalizations even when the current proof uses the condition.
- Attach `@[capacity_problem "problem-id"]` to problem-specific declarations.
- Mark declaration roles with `@[capacity_definition]`,
`@[capacity_statement]`, or `@[capacity_shared_api]`.
Expand Down
9 changes: 5 additions & 4 deletions data/problems/finite-dmc-input-cost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
id: finite-dmc-input-cost
title: Finite discrete memoryless channel with input cost
status: solved
updated: '2026-10-11'
updated: '2026-11-05'
summary: A finite DMC under a feasible maximum-codeword average-cost constraint has a constrained mutual-information capacity formula.
tags:
model: [point-to-point]
Expand Down Expand Up @@ -40,16 +40,17 @@ formalization:
kind: exact-capacity
category: solved
formal_status: proved
version: 1
description: For nonnegative cost with a feasible symbol, maximum-codeword-cost operational capacity
version: 2
description: For real-valued cost with a feasible symbol, maximum-codeword-cost operational capacity
equals constrained information capacity.
notes: The local proof uses cost-controlled random coding and a finite-mixture converse. It covers the
minimum feasible budget and proves that an admissible input attains the information supremum.
The version 2 theorem also permits signed costs; nonnegativity is not needed by the proof.
files:
- path: lean/CapacityAtlas/Channels/InputCost.lean
declaration: CapacityAtlas.FiniteChannel.finiteDMCInputCostCapacityStatement
role: claim
description: For nonnegative cost with a feasible symbol, maximum-codeword-cost operational capacity
description: For real-valued cost with a feasible symbol, maximum-codeword-cost operational capacity
equals constrained information capacity.
claim_id: exact-capacity
proofs: []
Expand Down
5 changes: 3 additions & 2 deletions data/problems/two-user-discrete-memoryless-mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ id: two-user-discrete-memoryless-mac
title: Two-user discrete memoryless multiple-access channel
abbreviation: DM-MAC
status: solved
updated: '2026-10-11'
updated: '2026-11-05'
summary: Two independent senders communicate to one receiver through a finite memoryless channel.
tags:
model: [multiple-access]
Expand Down Expand Up @@ -48,10 +48,11 @@ formalization:
kind: exact-capacity
category: solved
formal_status: proved
version: 1
version: 2
description: The complete average-error capacity region with separate deterministic encoders equals the three single-letter inequalities over arbitrary finite time sharing, including boundary rates and zero-rate axes.
notes: The local proof uses separate random codebooks and a fixed time-sharing schedule. Three Fano bounds
share one time coordinate; compactness handles boundary rates. The region allows arbitrary finite Q.
The version 2 theorem also covers empty input alphabets, without separate nonemptiness assumptions.
files:
- path: lean/CapacityAtlasForMathlib/InformationTheory/MultipleAccess.lean
declaration: CapacityAtlas.MultipleAccess.BlockCode
Expand Down
15 changes: 15 additions & 0 deletions docs/lean.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ The builds below treat documentation warnings as errors. Documentation regressio
tests also check missing and empty docstrings, structure fields, private helpers,
and `inherit_doc`, so disabling the package option breaks the test suite.

Unused-variable linting is enabled explicitly. The compiled audit also rejects
unused parameters of public proved theorems across the local libraries: a
parameter must occur in the proof, the result, or another parameter's type or
value. This check includes typeclass instances and underscore-prefixed names;
source linter options and `nolint` attributes do not disable it. Private helpers,
generated declarations, and admitted research statements are excluded. The
existing trust checks still reject admissions in reusable infrastructure and
local proofs.

Compiled dependency checks cannot establish every mathematical generalization.
An assumption used by the current proof may still be removable with a stronger
proof; those changes need mathematical review and a regression check of the
stronger theorem signature. A materially strengthened registered claim must
increment its version in both Lean and YAML.

```bash
cd lean
lake exe cache get
Expand Down
11 changes: 5 additions & 6 deletions lean/CapacityAtlas/Channels/InputCost.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ namespace CapacityAtlas.FiniteChannel

variable {X Y : Type*} [Fintype X] [Fintype Y]

/-- The finite-DMC coding theorem with a feasible nonnegative input-cost constraint. -/
/-- The finite-DMC coding theorem with a feasible input-cost constraint. -/
@[capacity_problem "finite-dmc-input-cost", capacity_statement, capacity_solved,
capacity_claim "exact-capacity" 1, capacity_formal_proof]
capacity_claim "exact-capacity" 2, capacity_formal_proof]
theorem finiteDMCInputCostCapacityStatement (channel : FiniteChannel X Y)
(cost : X → ℝ) (budget : ℝ) :
(∀ symbol, 0 ≤ cost symbol) →
(∃ symbol, cost symbol ≤ budget) →
channel.constrainedOperationalCapacityBits cost budget =
channel.constrainedInformationCapacityBits cost budget :=
(∃ symbol, cost symbol ≤ budget) →
channel.constrainedOperationalCapacityBits cost budget =
channel.constrainedInformationCapacityBits cost budget :=
CapacityAtlasCost.finiteDMCInputCostCapacity channel cost budget

end CapacityAtlas.FiniteChannel
4 changes: 2 additions & 2 deletions lean/CapacityAtlas/Channels/MultipleAccess.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ variable {X₁ X₂ Y : Type*} [Fintype X₁] [Fintype X₂] [Fintype Y]

/-- The average-error capacity region of a finite two-user MAC. -/
@[capacity_problem "two-user-discrete-memoryless-mac", capacity_statement,
capacity_formal_proof, capacity_solved, capacity_claim "exact-capacity" 1]
theorem multipleAccessCapacityStatement [Nonempty X₁] [Nonempty X₂]
capacity_formal_proof, capacity_solved, capacity_claim "exact-capacity" 2]
theorem multipleAccessCapacityStatement
(channel : FiniteChannel (X₁ × X₂) Y) :
MultipleAccess.operationalRegion channel = MultipleAccess.informationRegion channel :=
CapacityAtlasMAC.capacityRegion channel
Expand Down
15 changes: 7 additions & 8 deletions lean/CapacityAtlas/Channels/QarySymmetric.lean
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ private theorem sum_ite_zero (q : ℕ) [NeZero q] (a b : ℝ) :

/-- The atlas q-ary noise range is contained in the probability interval. -/
@[capacity_api]
theorem qarySymmetric_p_le_one (q : ℕ) (hq : 2 ≤ q) {p : ℝ}
theorem qarySymmetric_p_le_one (q : ℕ) {p : ℝ}
(hp : p ≤ ((q - 1 : ℕ) : ℝ) / q) : p ≤ 1 := by
have hqpos : (0 : ℝ) < q := by exact_mod_cast (lt_of_lt_of_le (by norm_num) hq)
have hsuble : ((q - 1 : ℕ) : ℝ) ≤ q := by exact_mod_cast Nat.sub_le q 1
exact hp.trans ((div_le_one hqpos).2 hsuble)
exact hp.trans (div_le_one_of_le₀ hsuble (Nat.cast_nonneg q))

/-- The q-ary symmetric noise distribution on the cyclic group with `q` elements. -/
@[capacity_problem "q-ary-symmetric-channel", capacity_definition]
Expand Down Expand Up @@ -103,7 +102,7 @@ theorem qarySymmetricNoise_entropy (q : ℕ) [NeZero q] (hq : 2 ≤ q)
capacity_formal_proof, capacity_claim "information-capacity" 1]
theorem qarySymmetric_informationCapacity (q : ℕ) [NeZero q] (hq : 2 ≤ q)
(p : ℝ) (hp0 : 0 ≤ p) (hpMax : p ≤ ((q - 1 : ℕ) : ℝ) / q) :
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hq hpMax)).informationCapacityBits =
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hpMax)).informationCapacityBits =
Real.log q / Real.log 2 - Real.binEntropy p / Real.log 2 -
p * Real.log ((q - 1 : ℕ) : ℝ) / Real.log 2 := by
rw [qarySymmetric, additiveNoise_informationCapacity, ZMod.card,
Expand All @@ -115,15 +114,15 @@ theorem qarySymmetric_informationCapacity (q : ℕ) [NeZero q] (hq : 2 ≤ q)
capacity_formal_proof, capacity_claim "operational-capacity" 1]
theorem qarySymmetric_operationalCapacity (q : ℕ) [NeZero q] (hq : 2 ≤ q)
(p : ℝ) (hp0 : 0 ≤ p) (hpMax : p ≤ ((q - 1 : ℕ) : ℝ) / q) :
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hq hpMax)).operationalCapacityBits =
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hpMax)).operationalCapacityBits =
Real.log q / Real.log 2 - Real.binEntropy p / Real.log 2 -
p * Real.log ((q - 1 : ℕ) : ℝ) / Real.log 2 := by
calc
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hq hpMax)).operationalCapacityBits =
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hpMax)).operationalCapacityBits =
(qarySymmetric q hq p hp0
(qarySymmetric_p_le_one q hq hpMax)).informationCapacityBits :=
(qarySymmetric_p_le_one q hpMax)).informationCapacityBits :=
FiniteChannel.codingTheorem
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hq hpMax))
(qarySymmetric q hq p hp0 (qarySymmetric_p_le_one q hpMax))
_ = Real.log q / Real.log 2 - Real.binEntropy p / Real.log 2 -
p * Real.log ((q - 1 : ℕ) : ℝ) / Real.log 2 :=
qarySymmetric_informationCapacity q hq p hp0 hpMax
Expand Down
4 changes: 2 additions & 2 deletions lean/CapacityAtlas/Claims/GaussianInterference.lean
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace CapacityAtlas.Claims
capacity_formal_proof]
theorem gaussianInterferenceDegreesOfFreedom (μ : Measure ℂ) [IsProbabilityMeasure μ]
[NullSingletonClass μ] {K : ℕ} (hK : 2 ≤ K) {hmin hmax : ℝ}
(hmin_pos : 0 < hmin) (hmax_nonneg : 0 ≤ hmax)
(hmin_pos : 0 < hmin)
(hfading : ∀ᵐ h ∂μ, hmin ≤ ‖h‖ ∧ ‖h‖ ≤ hmax) :
Tendsto (fun P : ℝ => Gaussian.Interference.sumCapacity μ K P / Real.logb 2 P)
atTop (𝓝 ((K : ℝ) / 2)) :=
Gaussian.Interference.sum_degrees_of_freedom μ hK hmin_pos hmax_nonneg hfading
Gaussian.Interference.sum_degrees_of_freedom μ hK hmin_pos hfading

end CapacityAtlas.Claims
3 changes: 1 addition & 2 deletions lean/CapacityAtlas/Tests/GaussianMIMOBroadcast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ theorem gaussianMIMOBroadcast_zero_channel {K tx : ℕ} {rx : Fin K → ℕ}
Gaussian.MIMOBroadcast.capacityRegion W.channelMatrix W.noiseCovariance W.totalPower =
Gaussian.MIMOBroadcast.region W.channelMatrix W.noiseCovariance W.totalPower := by
rw [hH]
exact Gaussian.MIMOBroadcast.capacityRegion_eq_region_zero_channel _
W.noiseCovariance_posDef W.totalPower_nonnegative
exact Gaussian.MIMOBroadcast.capacityRegion_eq_region_zero_channel _ W.totalPower_nonnegative

private def constantDecoder {Observation : Type*} [MeasurableSpace Observation]
{messages : ℕ} (m : Fin messages) : Gaussian.Decoder Observation messages where
Expand Down
4 changes: 3 additions & 1 deletion lean/CapacityAtlasAudit.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ See https://www.apache.org/licenses/LICENSE-2.0

import CapacityAtlas
import CapacityAtlasAuditCore
import CapacityAtlasAuditCore.SourceModules

open Lean

Expand All @@ -14,7 +15,8 @@ namespace CapacityAtlas.Audit
private def runAudit : IO Report := do
unsafe Lean.enableInitializersExecution
initSearchPath (← findSysroot)
let env ← importModules #[{ module := `CapacityAtlas }] {} (loadExts := true)
let modules ← discoverSourceModules (← IO.currentDir)
let env ← importModules (modules.map fun module => { module }) {} (loadExts := true)
let context : Core.Context := { fileName := "", fileMap := default }
let state : Core.State := { env }
Prod.fst <$> (audit env).toIO context state
Expand Down
50 changes: 44 additions & 6 deletions lean/CapacityAtlasAuditCore.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See https://www.apache.org/licenses/LICENSE-2.0
import CapacityAtlasUtil.Metadata
import Lean.AutoDecl
import Lean.Util.CollectAxioms
import Lean.Util.CollectFVars

open Lean

Expand Down Expand Up @@ -79,6 +80,43 @@ private def unexpectedAxioms (axioms : Array Name) (allowSorry : Bool) : Array N
axioms.filter fun axiomName =>
!standardAxioms.contains axiomName && !(allowSorry && axiomName == ``sorryAx)

private def unusedTheoremArguments (info : ConstantInfo) : MetaM (Array String) := do
let .thmInfo theoremInfo := info | return #[]
Meta.forallTelescope theoremInfo.type fun args resultType => do
let localDeclarations ← args.mapM Meta.getFVarLocalDecl
let mut dependencies := mkApp ((mkAppN theoremInfo.value args).headBeta) resultType
for localDeclaration in localDeclarations do
dependencies := mkApp dependencies localDeclaration.type
if let some value := localDeclaration.value? then
dependencies := mkApp dependencies value
let usedVariables := (Lean.collectFVars {} dependencies).fvarSet
let mut errors := #[]
for index in [:localDeclarations.size] do
let localDeclaration := localDeclarations[index]!
unless usedVariables.contains localDeclaration.fvarId do
let type ← Meta.ppExpr localDeclaration.type
let argument ← Meta.ppExpr (.fvar localDeclaration.fvarId)
let binder := if localDeclaration.binderInfo.isInstImplicit then
s!"[{type}]" else s!"({argument} : {type})"
errors := errors.push s!"unused argument {index + 1}: {binder}; remove this parameter"
return errors

private def requiresCleanProof (env : Environment) (moduleName declaration : Name) : Bool :=
moduleIn moduleName `CapacityAtlasForMathlib || moduleIn moduleName `CapacityAtlasUtil ||
capacityTestAttr.hasTag env declaration || capacityFormalProofAttr.hasTag env declaration ||
capacityApiAttr.hasTag env declaration || capacitySharedApiAttr.hasTag env declaration ||
capacityPropositionAttr.hasTag env declaration

/-- Whether a public problem-layer research declaration may use an admitted proof. -/
def allowsResearchAdmission (env : Environment) (moduleName declaration : Name) : CoreM Bool := do
let some info := env.find? declaration | return false
unless moduleIn moduleName `CapacityAtlas && isPublicTheorem info &&
!env.isProjectionFn declaration do return false
if ← Lean.isAutoDeclOrPrivate_Internal declaration then return false
return !requiresCleanProof env moduleName declaration &&
(capacityClaimAttr.getParam? env declaration).isSome &&
(capacityOpenAttr.hasTag env declaration || capacitySolvedAttr.hasTag env declaration)

/-- Check compiled declarations, including the bodies of canonical proposition definitions. -/
def audit (env : Environment) : CoreM Report := do
let mut records := #[]
Expand All @@ -92,7 +130,6 @@ def audit (env : Environment) : CoreM Report := do
let isTest := capacityTestAttr.hasTag env declaration
let isFormalProof := capacityFormalProofAttr.hasTag env declaration
let isProposition := capacityPropositionAttr.hasTag env declaration
let isApi := capacityApiAttr.hasTag env declaration
let isSharedApi := capacitySharedApiAttr.hasTag env declaration
let claim? := capacityClaimAttr.getParam? env declaration
let claimId? := claim?.map Claim.id
Expand All @@ -106,6 +143,10 @@ def audit (env : Environment) : CoreM Report := do
let isAutoOrPrivate ← Lean.isAutoDeclOrPrivate_Internal declaration
let isProblemTheorem := inProblemLayer && isPublicTheorem info && !isAutoOrPrivate &&
!env.isProjectionFn declaration
if isPublicTheorem info && !isAutoOrPrivate && !env.isProjectionFn declaration &&
!axioms.contains ``sorryAx then
for error in ← (unusedTheoremArguments info).run' do
errors := errors.push s!"{declaration}: {error}"
if inProblemLayer && isAxiom info && !isAutoOrPrivate then
errors := errors.push s!"{declaration}: public problem-layer axioms are not permitted"
if isProblemTheorem then
Expand Down Expand Up @@ -144,11 +185,8 @@ def audit (env : Environment) : CoreM Report := do
claim?.isNone then
errors := errors.push
s!"{declaration}: research claim is missing [capacity_claim] identity and version"
let admittedResearchClaim := claim?.isSome && isPublicTheorem info && !isProposition &&
(capacityOpenAttr.hasTag env declaration || capacitySolvedAttr.hasTag env declaration) &&
!isFormalProof && !isTest
let requiresCleanAxioms :=
inForMathlib || inUtil || isTest || isFormalProof || isApi || isSharedApi || isProposition
let admittedResearchClaim ← allowsResearchAdmission env moduleName declaration
let requiresCleanAxioms := requiresCleanProof env moduleName declaration
let checkedAxioms := if requiresCleanAxioms || isProblemTheorem then axioms else #[]
let unexpected := unexpectedAxioms checkedAxioms admittedResearchClaim
unless unexpected.isEmpty do
Expand Down
32 changes: 32 additions & 0 deletions lean/CapacityAtlasAuditCore/SourceModules.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/-
Copyright 2026 The Capacity Atlas Authors
Licensed under the Apache License, Version 2.0 (the "License").
See https://www.apache.org/licenses/LICENSE-2.0
-/

import Lean.Data.Name
import Lean.Util.Path

namespace CapacityAtlas.Audit

/-- Discover every current library source module under the Lean package directory. -/
def discoverSourceModules (packageDir : System.FilePath) : IO (Array Lean.Name) := do
let roots := #[`CapacityAtlas, `CapacityAtlasForMathlib, `CapacityAtlasUtil]
let invalidPackage := IO.userError
s!"capacity_audit requires the Lean package directory: {packageDir}; expected lakefile.toml and all three library source roots"
unless ← (packageDir / "lakefile.toml").pathExists do
throw invalidPackage
let mut modules := #[]
for root in roots do
let source := packageDir / s!"{root}.lean"
let directory := packageDir / root.toString
unless (← source.pathExists) && (← directory.isDir) do
throw invalidPackage
modules := modules.push root
let found ← IO.mkRef #[]
Lean.forEachModuleInDir directory fun name => do
found.modify (·.push (root ++ name))
modules := modules ++ (← found.get)
return modules.qsort Lean.Name.quickLt

end CapacityAtlas.Audit
5 changes: 5 additions & 0 deletions lean/CapacityAtlasAuditTests.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ See https://www.apache.org/licenses/LICENSE-2.0
-/

import CapacityAtlasAuditCore
import CapacityAtlasAuditTests.Assumptions
import CapacityAtlasAuditTests.AssumptionBoundaries
import CapacityAtlasAuditTests.Documentation
import CapacityAtlasAuditTests.Fixtures
import CapacityAtlasAuditTests.GaussianAssumptions
import CapacityAtlasAuditTests.SourceModules
import CapacityAtlasAuditTests.TrustBoundary

open Lean CapacityAtlas.Audit

Expand Down
Loading
Loading