Learn Lean 4

A modern functional programming language and interactive theorem prover. Write provably correct software.

Master dependent type theory, build verified programs, and prove mathematical theorems with one of the most powerful type systems available.

Why Lean 4?

Pure Functional Design

Immutable data structures, pattern matching, and higher-order functions. Write clean, composable code with strong type guarantees.

Dependent Types

Types can depend on values, enabling you to encode invariants directly in your type signatures and prove properties at compile time.

Interactive Proving

A rich tactic language for step-by-step proof construction. The compiler guides you through proofs with precise error messages.

Real-World Ready

Compile to efficient native code. Lake build system for package management. Built for both research and production use.

As a Programming Language

Define data structures, write functions with pattern matching, and leverage Lean's powerful type inference.

lean
1structure Person where
2 name : String
3 age : Nat
4 deriving Repr
5
6def greet (p : Person) : String :=
7 s!"Hello, {p.name}!"
8
9def adults (people : List Person) : List Person :=
10 people.filter (·.age 18)
11
12#eval greet { name := "Alice", age := 30 }

As a Theorem Prover

Prove mathematical theorems interactively. Use tactics to construct proofs step by step with compiler guidance.

lean
1-- Prove that list append is associative
2theorem append_assoc {α : Type}
3 (xs ys zs : List α) :
4 xs ++ (ys ++ zs) = (xs ++ ys) ++ zs := by
5 induction xs with
6 | nil => simp
7 | cons x xs ih =>
8 simp [List.cons_append]
9 exact ih

Ready to Begin?

Start with the interactive course for a guided learning experience, or dive into the documentation if you prefer self-directed study.