EconLib4

Formal Economics in Lean 4

A comprehensive Lean 4 library formalising economics, game theory, mechanism design, trust, cryptography, information theory, and semantic compression. 12,500 lines. 253 theorems. Built on Mathlib4.

50
Files
12,500
Lines
253
Theorems
349
Definitions
122
Structures
11
Domains

12 new sorry-free theorems proved downstream in CSC Phases 1–5 (EscalationGate, PathwayAudit, ClientProfile, DataAdapter)

View on GitHub

Layered Dependency DAG

Six layers of formalisation, from Mathlib foundations to applied economics and finance.

L5 Economics & Finance
Finance Decision Learning
L4 Info & Compression
Coding SemanticCompression
L3 Trust & Security
Trust Crypto
L2 Strategic Interaction
GameTheory MechanismDesign SocialChoice ContractTheory
L1 Foundations
Utility Information
L0 Mathlib
Algebra Topology Measure Theory Category Theory

↑ Dependencies flow downward — each layer imports from layers below

11 Domains

Each module formalises a complete subfield with structures, definitions, and theorems.

Layer 1 — Foundations

Utility

1,201 lines

Expected utility theory with full VNM axiomatisation, risk aversion classification, and the Arrow-Pratt measure of absolute risk aversion.

PreferenceRelation VNM axioms ExpectedUtility RiskAversion CARA/CRRA Arrow-Pratt Jensen's inequality
Layer 1 — Foundations

Information

782 lines

Shannon information theory: entropy, mutual information, channel capacity, and the data processing inequality. Includes f-divergences and Fano's inequality.

Shannon Entropy MutualInformation KL divergence Channel ChannelCapacity DataProcessingInequality Fano's inequality f-divergences
Layer 2 — Strategic Interaction

GameTheory

2,233 lines

Normal-form and extensive-form games, Nash equilibria, mixed strategies, Bayesian games, cooperative game theory with Shapley value and nucleolus. Includes classic games.

NormalForm Nash MixedStrategy ExtensiveForm Bayesian ShapleyValue Nucleolus PD Stag Hunt BoS
Layer 2 — Strategic Interaction

MechanismDesign

1,059 lines

Direct mechanisms, the revelation principle, VCG with dominant strategy incentive compatibility proof, Clarke payments, and auction theory with revenue equivalence.

DirectMechanism Revelation Principle VCG vcg_is_dsic Clarke payment Auctions Revenue equivalence Myerson
Layer 2 — Strategic Interaction

SocialChoice

514 lines

Voting rules (plurality, Borda, Condorcet, IRV), Arrow's impossibility theorem, Gibbard-Satterthwaite, and strategy-proofness.

Plurality Borda Condorcet IRV Arrow's impossibility Gibbard-Satterthwaite Strategy-proofness
Layer 2 — Strategic Interaction

ContractTheory

589 lines

Moral hazard (principal-agent, first/second best) and adverse selection (screening, signalling, Rothschild-Stiglitz separation).

MoralHazard Principal-Agent First/Second Best AdverseSelection Screening Signalling Rothschild-Stiglitz
Layer 3 — Trust & Security

Trust

559 lines

Reputation systems with Bayesian updating (Milgrom-Roberts), commitment devices, escrow, staking, and trust transitivity.

Reputation Bayesian updates Milgrom-Roberts Commitment Escrow Staking Trust transitivity
Layer 3 — Trust & Security

Crypto

885 lines

Game-based cryptographic security definitions (IND-CPA/CCA, OWF, PRG, PRF), commitment schemes with hiding/binding, and zero-knowledge proofs.

IND-CPA/CCA OWF PRG PRF Commitment Hiding/Binding Sigma protocols Fiat-Shamir Schnorr
Layer 4 — Information & Compression

Coding

486 lines

Source coding theory, Kraft inequality, Shannon's source coding theorem, Huffman coding, Kolmogorov complexity, NCD, and minimum description length.

Source coding Kraft inequality Shannon's theorem Huffman Kolmogorov NCD MDL
Layer 4 — Information & Compression

SemanticCompression

1,309 lines

Verified semantic-preserving compression of LLM prompts. Groundtrace with proved soundness and compression. NoisyChannel models LLMs as Shannon channels. Tersiture metric and confabulation risk. The groundtrace_sound theorem (fully proved ✓) is the formal ancestor of CSC.GroundtraceRecord — a 20-field tamper-evident audit struct deployed in production with SHA-256 hash chaining and Rule 17a-4 compliance path.

Novel TokenEntropy Groundtrace NoisyChannel Tersiture ConfabulationRisk semantic_channel_coding
Layer 5 — Economics & Finance

Finance

460 lines

Fundamental theorem of asset pricing, no-arbitrage conditions, Black-Scholes, put-call parity (proved), and martingale pricing.

Arbitrage NoArbitrage FTAP Black-Scholes PutCallParity Martingale
Layer 5 — Economics & Finance

Decision

399 lines

Prospect theory, Kahneman-Tversky value function, probability weighting, Allais paradox, and framing effects.

Prospect theory Kahneman-Tversky Probability weighting Allais paradox Framing effects
Layer 5 — Economics & Finance

Learning

474 lines

Online learning with regret bounds, multiplicative weights update (proved regret bound), follow-the-regularised-leader, UCB, and no-regret implies coarse correlated equilibrium.

Online learning Regret bounds MultiplicativeWeights FTRL UCB No-regret → CCE

Cross-Domain Results

Key theorems and their connections across modules.

Theorem Connects Status
Groundtrace Soundness SemanticCompression Proved ✓
Groundtrace Compression SemanticCompression Proved ✓
Put-Call Parity Finance Proved ✓
VNM Representation Utility ↔ Probability Stated
Revelation Principle MechanismDesign ↔ Bayesian Games Stated
VCG is DSIC MechanismDesign ↔ Game Theory Stated
Myerson Optimal Auction Auctions ↔ Utility Stated
Arrow's Impossibility SocialChoice ↔ Order Theory Stated
Gibbard-Satterthwaite SocialChoice ↔ MechanismDesign Stated
Shannon Source Coding Information ↔ Coding Stated
Data Processing Inequality Information ↔ all downstream Stated
FTAP (finite) Finance ↔ Probability Stated
No-Regret → CCE Learning ↔ GameTheory Stated

What It Looks Like

Lean 4 structures and proofs from the library.

Lean 4
structure GroundtraceStep (D : Type*) [SemanticDomain D] where
  before      : TokenSequence D
  after       : TokenSequence D
  rule        : RewriteRule D
  sound       : SemanticEquivalence before after
  compresses  : after.length < before.length
Lean 4
structure VCGMechanism (env : QLEnvironment) where
  allocation : (∀ i, env.Θ i) → env.X
  efficient  : ∀ θ, allocation θ  argmax (fun x =>  i, env.v i x (θ i))
  payment    : ∀ i, (∀ j, env.Θ j) → 
  dsic       : vcg_is_dsic env allocation payment
Lean 4
theorem groundtrace_sound {D : Type*} [SemanticDomain D]
    (trace : Groundtrace D) :
    SemanticEquivalence trace.source trace.target := by
  induction trace.steps with
  | nil => exact SemanticEquivalence.refl _
  | cons step rest ih =>
    exact SemanticEquivalence.trans step.sound ih
Novel Contribution

The Novel Module: SemanticCompression

Formalises verified semantic-preserving compression of LLM prompts. Each compression step carries a machine-checked certificate that meaning is preserved.

Groundtrace

Chain of meaning-preserving rewrites. Sound (semantics preserved) and compressing (tokens strictly decrease). Both properties are fully proved in Lean 4 — no sorry.

NoisyChannel

Models LLMs as Shannon channels. Defines confabulation risk as error probability. Proves rate bounds: if semantic rate exceeds channel capacity, confabulation is inevitable.

Tersiture

Quantitative metric: ratio of current length to optimal (canonical form). tersiture = 1 iff maximally compressed. Gives a precise progress measure for compression.

TokenEntropy

Per-token information content, surprisal, and redundancy. Connects Shannon information measures to the token-level structure of language model inputs.

This module doesn't exist in any other Lean 4 formalisation library. It bridges information theory and LLM optimisation with formal guarantees.

Philosophy

The guiding principles behind EconLib4's architecture.

01

Compositional via Category Theory

Mechanisms are functors, channels are Kleisli morphisms, games are indexed families in monoidal categories.

02

Witnesshood as First-Class

Proofs carry constructive witnesses. Don't just prove existence — compute the equilibrium.

03

Groundtrace Verification

Every compression step carries a machine-checked certificate. Soundness and compression are theorem-level guarantees.

04

Tersiture-Driven Optimisation

Quantitative compression progress metric. tersiture = 1 is the target; every step is measurable.

~210 Open Proofs

The sorry-marked proofs are an invitation. Each one is a well-typed statement waiting for a constructive proof.

Priority Targets

View on GitHub

Part of a Larger Stack

EconLib4 provides the formal backbone for several downstream projects.

TokenGov

Mechanism-design token allocation. Uses VCG, Reputation, and Learning modules.

CSC

Composable Skill Compiler. Uses Shapley, Groundtrace, NoisyChannel, GroundtraceRecord (Phase 2), ConfabulumRate (Phase 1), and CertaintyVocabulary (Phase 1).

LegalLean

Formal legal reasoning. Uses ExtensiveForm, MoralHazard, and Arrow.

Elan

CompanyAsCode orchestrator. Uses AdverseSelection and Regret.

CCAP

Agent protocol. Uses Commitment, ZeroKnowledge, and Trust.

Downstream Operationalisation

How EconLib4 abstract concepts are now concretely operationalised in the production stack (Phases 1–5).

EconLib4 Concept Stack Operationalisation Phase
SemanticCompression.Groundtrace (groundtrace_sound ✓) CSC.GroundtraceRecord — 20-field SHA-256 hash chain audit trail Phase 2
SemanticCompression.NoisyChannel / confabulation risk CSC.ConfabulumRate — 9-type gate, halt at 0.65 aggregate score Phase 1
SemanticCompression.Tersiture metric CSC.CertaintyVocabulary — 5-level Verified→Halted confidence vocab Phase 1
MechanismDesign.VCG + Learning.Regret TokenGov allocation (unchanged) Pre-existing
Crypto.ZeroKnowledge (special_soundness, fiat_shamir) Spectral coalition safety proofs (unchanged) Pre-existing