Scripts2026年7月13日·1 分钟阅读

Lean 4 — Theorem Prover and Functional Programming Language

Lean 4 is both a programming language and an interactive theorem prover, enabling mathematically verified software and formalized proofs in a single environment.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Lean 4 Overview
先审查命令
npx -y tokrepo@latest install 12d61c2b-7ef8-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

Lean 4 is a functional programming language and interactive theorem prover developed at Microsoft Research and Carnegie Mellon University. It lets developers write ordinary programs and formal mathematical proofs in the same language, making it a tool for both verified software and research-level mathematics.

What Lean 4 Does

  • Provides a dependent type system for expressing and verifying complex properties
  • Supports writing executable programs alongside machine-checked proofs
  • Includes a tactic framework for interactive proof construction
  • Compiles to efficient native code via C intermediate representation
  • Powers the Mathlib library with hundreds of thousands of formalized theorems

Architecture Overview

Lean 4 is implemented in Lean itself (self-hosted). The compiler type-checks source code against a dependent type theory kernel, ensuring logical consistency. Code that passes the type checker is compiled to C for native execution. The tactic framework allows users to build proofs step-by-step, with the kernel verifying each step.

Self-Hosting & Configuration

  • Install via elan, the Lean version manager
  • Manage projects and dependencies with lake, the built-in build system
  • Configure dependencies in lakefile.lean or lakefile.toml
  • Use VS Code with the Lean 4 extension for interactive development
  • Pin toolchain versions in lean-toolchain file per project

Key Features

  • Dependent types enabling proofs as programs and programs as proofs
  • Powerful metaprogramming and custom tactic authoring
  • Mathlib: one of the largest libraries of formalized mathematics
  • Efficient compiled execution for non-proof code
  • Interactive feedback in editors with goal state display

Comparison with Similar Tools

  • Coq (Rocq) — Coq has a longer history and different tactic language; Lean 4 offers a more modern syntax and self-hosted compiler
  • Agda — Agda focuses on dependently typed programming; Lean 4 adds a richer tactic framework for proof automation
  • Haskell — Haskell has a powerful type system but cannot verify arbitrary properties; Lean 4 can
  • Idris 2 — Idris targets practical dependently typed programming; Lean 4 covers both proofs and practical code
  • F* — F* targets verified security code; Lean 4 is more general-purpose for both math and programs

FAQ

Q: Is Lean 4 only for mathematicians? A: No. Lean 4 is a general-purpose functional language. You can write regular programs without proofs, or combine both.

Q: What is Mathlib? A: Mathlib is a community-maintained library of formalized mathematics in Lean 4, covering algebra, analysis, topology, and more.

Q: Can Lean 4 produce fast executables? A: Yes. Lean 4 compiles to C and produces native binaries with performance suitable for practical applications.

Q: How does Lean 4 relate to Lean 3? A: Lean 4 is a complete rewrite with a new compiler, build system, and syntax. It is not backward-compatible with Lean 3.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产