/lean

Formal Verification L2+ Production low usage

/lean

Overview

/lean is a production command in the Formal Verification category of the Prismatic Platform that enables execution of Lean 4 code and theorem proving through the dedicated lean-specialist agent. Lean 4 is a functional programming language and interactive theorem prover that serves as the formal backbone of the platform's QEVE (Quantitative Epistemic Verification Engine) framework, providing machine-checkable proofs of system properties, invariants, and correctness guarantees.

Formal verification is a cornerstone of the Prismatic Platform's epistemic integrity. While traditional testing can demonstrate the presence of specific behaviors, formal verification proves the absence of entire classes of bugs. The /lean command makes this capability accessible through a simple command interface, allowing developers and agents to write Lean 4 specifications, prove theorems about platform components, and verify that implementations satisfy their formal specifications.

This command operates under the L2+ authority level and is executed by the lean-specialist agent, which possesses expertise in dependent type theory, tactic-based proof development, and the Mathlib library. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The lean-specialist agent can translate between Elixir specifications and Lean 4 formalizations, bridging the gap between the platform's implementation language and its verification language.

Within the platform's Trinity Gate framework, the /lean command directly supports the third gate -- Formal Necessity -- by providing machine-checkable proofs that claims are not merely consistent but formally necessary. This elevates epistemic claims from the level of empirical evidence to mathematical certainty.

Architecture

The Lean integration architecture bridges the Elixir runtime with the Lean 4 toolchain through a managed execution environment.

+---------------------+     +-------------------+     +-------------------+
| Lean Source Manager | --> | Lean Compiler     | --> | Proof Checker     |
| (File + Inline)     |     | (lean4 toolchain) |     | (Kernel Verifier) |
+---------------------+     +-------------------+     +-------------------+
         |                          |                          |
         v                          v                          v
+---------------------+     +-------------------+     +-------------------+
| Spec Translator     |     | Lake Builder      |     | Result Formatter  |
| (Elixir -> Lean)    |     | (Dependency Mgmt) |     | (Proof Certificate)|
+---------------------+     +-------------------+     +-------------------+
         |                                                     |
         v                                                     v
+---------------------+                              +-------------------+
| Trinity Gate        |                              | QEVE Integration  |
| (Formal Necessity)  |                              | (Proof Storage)   |
+---------------------+                              +-------------------+

The Lean Source Manager handles both file-based and inline Lean 4 code. The Spec Translator converts Elixir module specifications (typespecs, behaviours, contracts) into Lean 4 formalizations for verification. The Lean Compiler invokes the Lean 4 toolchain with appropriate Lake build configurations. The Proof Checker validates that proofs are complete and well-typed. The Result Formatter produces human-readable proof certificates and machine-readable verification results. The QEVE Integration stores verified proofs as part of the platform's epistemic evidence base.

Usage

Executing Lean 4 Code

# Execute a Lean 4 file
/lean --file proofs/list_properties.lean

# Execute inline Lean 4 code
/lean --eval "def hello := \"Hello from Lean 4\""

# Execute with specific Lake environment
/lean --file proofs/graph_theory.lean --lake-env prismatic-proofs

# Execute with Mathlib dependency
/lean --file proofs/algebra.lean --mathlib

Theorem Proving

# Prove a specific theorem
/lean --prove "theorem list_append_nil (l : List a) : l ++ [] = l"

# Prove with tactic hints
/lean --prove "theorem nat_add_comm" --tactics "induction, simp, ring"

# Attempt automated proof search
/lean --prove --auto "theorem double_neg (p : Prop) : p -> !!p"

# Verify an existing proof
/lean --verify proofs/supervisor_invariant.lean

Specification Translation

# Translate Elixir module spec to Lean 4
/lean --translate-spec PrismaticStorage.ETS

# Translate and generate proof obligations
/lean --translate-spec PrismaticPerimeter.SecurityRating --proof-obligations

# Translate with custom type mappings
/lean --translate-spec MyModule --type-map custom_types.json

QEVE Integration

# Submit verified proof to QEVE evidence base
/lean --submit-proof proofs/safety_property.lean --claim "agent_pool_never_deadlocks"

# Query QEVE for proofs related to a module
/lean --qeve-query PrismaticAgents.Pool

# Run Monte Carlo + Lean hybrid verification
/lean --hybrid-verify "system_availability > 0.999" --monte-carlo-samples 10000

Options & Parameters

OptionTypeDefaultDescription
--filestring-Lean 4 source file to execute
--evalstring-Inline Lean 4 expression to evaluate
--provestring-Theorem statement to prove
--verifystring-Proof file to verify without re-proving
--autobooleanfalseEnable automated proof search (omega, simp, aesop)
--tacticsstring-Comma-separated tactic suggestions for proof search
--translate-specstring-Elixir module to translate to Lean 4 specification
--proof-obligationsbooleanfalseGenerate proof obligations from translated spec
--type-mapstring-Custom Elixir-to-Lean type mapping file
--mathlibbooleanfalseEnable Mathlib library dependency
--lake-envstringdefaultLake build environment to use
--submit-proofstring-Submit verified proof to QEVE evidence base
--claimstring-Claim identifier for QEVE submission
--qeve-querystring-Query QEVE for proofs related to a module
--hybrid-verifystring-Property for hybrid Monte Carlo + Lean verification
--monte-carlo-samplesinteger1000Number of Monte Carlo samples for hybrid verification
--timeoutduration60sMaximum time for proof search
--formatstringtextOutput format: text, json, proof-certificate
--verbosebooleanfalseShow detailed proof construction steps

Execution Flow

  1. Source Acquisition: Lean 4 source is acquired from a file, inline expression, theorem statement, or specification translation. For --translate-spec, the Elixir module is loaded and its typespecs, behaviours, and documented contracts are extracted.

  2. Translation (if applicable): Elixir specifications are translated to Lean 4 formalizations. Type mappings convert Elixir types to their Lean 4 equivalents (e.g., list(integer()) becomes List Int, {:ok, term()} | {:error, String.t()} becomes a sum type). Custom type mappings override defaults.

  3. Environment Preparation: The Lake build environment is configured with required dependencies (Mathlib, custom packages). The Lean toolchain version is verified for compatibility.

  4. Compilation: The Lean 4 compiler processes the source, performing type checking, elaboration, and kernel verification. Compilation errors are captured with full diagnostic information.

  5. Proof Search (for --prove and --auto): If automated proof is requested, the system applies a sequence of tactics: simp, omega, aesop, ring, norm_num, and custom tactics from --tactics. The search is bounded by --timeout.

  6. Verification: Completed proofs are verified by the Lean kernel, which checks that the proof term has the correct type. This is a foundational verification step -- the kernel is the trusted computing base.

  7. QEVE Integration (if applicable): Verified proofs are packaged as proof certificates and submitted to the QEVE evidence base, where they are indexed by the associated claim and linked to the relevant platform components.

  8. Output: Results are formatted and displayed, including proof status, verification time, and any diagnostic information.

Integration Points

ComponentIntegration TypeDescription
Prismatic AgentsExecutionExecuted by the lean-specialist agent
QEVEEvidence StorageVerified proofs stored as epistemic evidence
Trinity GateFormal NecessityLean proofs satisfy the third gate requirement
NABLA InfinityEpistemic FrameworkProofs provide maximum confidence (1.0) evidence
Monte CarloHybrid VerificationCombined probabilistic and formal verification
Quality GatesEnforcementProof requirements enforced at quality gates
TelemetryObservabilityProof metrics tracked (time, complexity, success rate)
AIAD RegistryDiscoveryCommand registered via AIAD standard

Best Practices

Start with simple properties and build incrementally. Attempting to prove complex system invariants directly often leads to proof bloat and tactic failures. Decompose complex properties into lemmas, prove each lemma independently, and compose them into the final proof.

Use --translate-spec to bootstrap formal specifications. Manual translation from Elixir to Lean is error-prone and tedious. The automated translator produces a correct starting point that can be refined with domain-specific invariants.

Leverage Mathlib for standard mathematical properties. The Mathlib library provides thousands of pre-proven theorems about numbers, lists, sets, and algebraic structures. Using --mathlib dramatically reduces the proof burden for properties involving standard mathematics.

Set appropriate timeouts for automated proof search. Complex proofs may require significantly more than the default 60-second timeout. For deep properties, increase the timeout or provide tactic hints to guide the search.

Submit all verified proofs to QEVE. The QEVE evidence base is cumulative -- each proof strengthens the platform's epistemic foundations. Even seemingly trivial proofs (e.g., a function always returns {:ok, _} for valid inputs) contribute to the overall confidence score.

Error Handling

Error ConditionResponseRecovery
Lean toolchain not installedInstallation instructions with version requirementInstall Lean 4 via elan
Proof search timeoutShows partial proof progress and tactic stateIncrease timeout or provide tactic hints
Type mismatch in translationShows Elixir type and failed Lean mappingAdd custom type mapping
Kernel verification failureShows the failing proof obligation with contextReview and correct proof construction
Mathlib version conflictShows compatible version rangeUpdate Lake dependencies
QEVE submission failureStores proof locally for retryRetry with /lean --submit-proof

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for incomplete execution or quality violations. Proofs must be complete and kernel-verified -- partial proofs and sorry-based stubs are rejected. Every formal claim must be fully proven.
  • NO DOUBTS: Full investigation before action, evidence-based results. The Lean kernel provides the highest level of evidence: machine-checked mathematical proof. No formal claim is accepted without passing through the kernel verifier.

The /lean command is the cornerstone of the platform's NABLA Infinity Provenance Mandatory axiom, ensuring that formal claims are traceable to machine-checkable proofs rather than informal arguments or empirical testing alone.


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL