Querex | November 2025

Introducing Lean 4 MCP

Mathematical Certification for Your Analytics Pipeline

Transform "I think this is right" into "I can prove this is right."

You've been using our MCP tools to build sophisticated analytics pipelines:

Power BI MCP

Extracts real-time data from semantic models

Statistics MCP

Runs hypothesis tests and fits distributions

OR-Tools MCP

Optimizes portfolios, schedules, and allocations

๐Ÿ’ก But here's a question that keeps coming up:

"How do I prove these calculations are correct?"

Not test. Not validate. Prove.

Today, we're releasing Lean 4 MCP โ€” and it answers that question definitively.

Lean is a theorem prover used by mathematicians to formally verify proofs. It's the same technology behind recent breakthroughs like the formal verification of the Polynomial Freiman-Ruzsa conjecture.

But you don't need to be a mathematician to use it.

For quantitative finance and analytics, Lean serves as a certified calculator โ€” it can mathematically prove that:

  • โœ“ Your portfolio weights sum to exactly 100%
  • โœ“ All constraints from your optimizer are satisfied
  • โœ“ Your formulas match the Basel/regulatory definitions
  • โœ“ No copy-paste or unit conversion errors crept in

Example 1

Floating Point Accumulation

-- Weights from "optimizer"
def w1 : Float := 0.333333
def w2 : Float := 0.333333
def w3 : Float := 0.333333

#eval w1 + w2 + w3        -- Returns: 0.999999
#eval (w1 + w2 + w3) == 1.0  -- Returns: false โŒ

Impact: On a $10 billion portfolio, that's $10,000 unallocated.

Example 2

Unit Confusion (15 vs 0.15)

def portfolioValue : Float := 100000000  -- $100M
def volatility_WRONG : Float := 15.0     -- Should be 0.15!

def VaR := portfolioValue * volatility_WRONG * 2.326 * 0.199
#eval VaR  -- Returns: $695,000,000 โŒ

-- VaR > Portfolio Value = Impossible!

Impact: A 15% vs 0.15 mixup creates a 100x error.

Example 3

Constraint Violation

def portfolioPD : Float := 
  0.05 * 1.80 + 0.20 * 3.85 + 0.25 * 5.35 + 
  0.25 * 7.88 + 0.15 * 9.36 + 0.10 * 13.48

#eval portfolioPD       -- Returns: 6.92%
#eval portfolioPD โ‰ค 6.0 -- Returns: false โŒ

Impact: The "optimal" solution violates your risk constraint.

Lean MCP slots naturally into your existing workflow:

Power BI
Data
โ†’
Statistics
Tests
โ†’
OR-Tools
Optimize
โ†’
Quant Fin
Price
โ†’
Lean 4
Verify โœ“

Pattern 1: Portfolio Optimization Certification

Power BI โ†’ OR-Tools โ†’ Lean

  1. Extract holdings from Power BI
  2. Optimize allocation with OR-Tools
  3. Verify all constraints in Lean

Pattern 2: Risk Calculation Audit

Power BI โ†’ Quant Finance โ†’ Lean

  1. Get portfolio positions
  2. Calculate VaR with Quant Finance MCP
  3. Verify formula implementation in Lean

You don't need Mathlib (Lean's advanced math library) for practical finance work.

Need Mathlib Base Lean Sufficient โœ“
Prove Black-Scholes is arbitrage-free Verify this VaR calculation
Prove LP convergence properties Verify optimizer output is feasible
Prove measure-theoretic properties Verify PD ร— LGD ร— EAD formula
Scenario Use Lean? Why
Ad-hoc analysis โŒ Overkill for exploration
Client deliverable โœ… Adds credibility
Regulatory submission โœ… Audit trail requirement
Model validation โœ… Proves formulas correct
Internal dashboard โŒ Speed matters more

Verify a sum constraint

def weights : List Float := [0.07, 0.30, 0.25, 0.20, 0.15, 0.03, 0.00]
#eval weights.foldl (ยท + ยท) 0.0  -- Should be 1.0

Verify a bound

def portfolioPD : Float := 5.98
#eval portfolioPD โ‰ค 6.0  -- true โœ“

Verify a formula

def expectedLoss (pd lgd ead : Float) := pd * lgd * ead
#eval expectedLoss 0.05 0.60 1000000  -- $30,000

Prove an ordering

theorem gradeA_safer : 1.80 < 16.14 := by native_decide  -- โœ“
  • Excel errors have cost billions (JPMorgan's London Whale).
  • Unit confusion crashed the Mars Climate Orbiter ($327M).
  • Rounding errors accumulate silently.

Lean transforms "I think this is right" into
"I can prove this is right."

Get Started with Lean 4 MCP

Requirements

  • โœ… Lean 4.26+ installed
  • โœ… Works on Windows, macOS, Linux
  • โœ… Integrates with existing MCP servers