Skip to content

Setting up

You need three things: Lean itself, an editor that talks to Lean, and a copy of this repository. Playing the games in a browser needs two more tools, which you can add later.

Lean

Lean is installed by elan, which works like rustup or nvm: it fetches the exact version of Lean a project asks for. Install it by following the instructions at https://github.com/leanprover/elan. On macOS or Linux that is one command:

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

The repository pins its Lean version in the file lean-toolchain. The first time you run Lean inside the repository, elan downloads that version.

An editor

Use VS Code with the Lean 4 extension. Lean is meant to be used interactively: as you type, the extension shows a panel called the infoview, which tells you what Lean knows at the cursor: values, types, errors and, inside a proof, what is left to prove. Most of what this course teaches, you will learn by watching the infoview.

Open the repository's top folder in VS Code (not a subfolder), so the extension finds the project.

Build the project

From the repository's top folder:

lake build Games      # the three games' rules
make test             # the tests: examples, and thousands of random games

lake is Lean's build tool; it came with Lean. The first build takes a few minutes. make test should end with all tests passed.

Then check the proofs:

make proofs

This builds every theorem about the games and fails if any proof is missing. You will come back to this command whenever you change a rule.

Playing in a browser (optional, for now)

The chapters on changing rules end with playing your changed game. That needs Go and Node.js 24. Once they are installed:

make web-deps                                    # once
make go-server web-build && ./build/server -static web/dist -debug

Then open http://localhost:8080/?game=snap. The server embeds the same Lean rules you just built, compiled to native code. Stop it with Ctrl+C and run the same command again after changing a rule.

This course's own files

The examples on these pages live in learn/Learn/, one file per chapter. Build them all with:

lake build Learn

To build this site and read it locally, with your changes:

make learn-serve      # then open http://localhost:8000; pages rebuild as you edit them
make learn-open       # or: build once, then serve the built site at the same address

Read it through one of these rather than opening the files directly: the pages link to folders, which a browser only follows when a server sends them. Both need uv, which fetches the site builder.