Lean4.ai -- Beginner's Guide

A practical guide to getting started with Lean 4

Step 1: Installation

Install Lean 4 via elan

The recommended way to install Lean 4 is through elan, the Lean version manager:

curl https://elan.lean-lang.org/elan-init.sh -sSf | sh

This installs elan, lean, and lake (the build tool).

Set up your editor

Install VS Code and the Lean 4 extension. This gives you:

Create your first project

Use Lake to set up a new project with Mathlib:

lake init my_project math

Then run lake build to download dependencies. The first build takes a while as it fetches Mathlib's cache.

Tip: Run lake exe cache get in a Mathlib-dependent project to download precompiled oleans instead of building from source. This can save hours.

Step 2: Learn the Basics

Work through these resources roughly in order:

  1. Natural Number Game -- A browser game that teaches core tactics (rfl, rw, induction, etc.) through proving properties of natural numbers. No installation needed.
  2. Theorem Proving in Lean 4 -- The standard textbook. Covers propositions, tactics, structures, type classes, and more.
  3. Mathematics in Lean -- Hands-on exercises formalizing real mathematics with Mathlib. Great for building practical skills.
  4. Functional Programming in Lean -- If you want to use Lean for programming (not just proofs), this book covers IO, monads, and practical programming patterns.

Step 3: Finding Theorems & Tactics

One of the biggest challenges in Lean is finding the right lemma or theorem. Here are the tools:

Search tools

Tip: In VS Code, you can also use #check to inspect a term's type and #print to see a definition. Example: #check Nat.add_comm

Step 4: Using AI to Help Write Proofs

AI tools can significantly speed up your workflow in Lean 4:

AI-powered tools for Lean

Tip: When using an LLM for Lean code, always paste the full goal state from the Infoview. The more context you give, the better the suggestions.

Practical Tips

What's Next?

Once you're comfortable with the basics: