BaDaaS/lean4-courses

Lean

47

21 commits

updated Jun 26, 2026

See the code

README

Lean 4 Crash Course

A hands-on crash course in Lean 4 for mathematicians and computer scientists. The goal is to go from zero to contributing to Mathlib, CSLib, and ArkLib.

How to Use

Each directory NNNN-topic/ contains:

  • README.md - Lecture notes with explanations
  • Exercises.lean - Exercises (replace sorry with proofs/definitions)
  • Solutions.lean - Reference solutions

Courses are sequential. Complete them in order.

Prerequisites

Course Outline

Part I: Foundations (0000-0009)

#TopicMath FocusCS Focus
0000StartupLean as a proof assistantLean as a programming language
0001TypesTypes as mathematical setsTypes as data specifications
0002FunctionsFunctions as mapsFunctions as computations
0003Propositions and ProofsCurry-Howard, logic in LeanProps as types
0004TacticsInteractive proofsTactic DSL, proof automation
0005Inductive TypesConstructing N, Z, treesADTs, enums, recursive types
0006Structures/TypeclassesAlgebraic structuresInterfaces and polymorphism
0007Monads and Do NotationKleisli compositionIO, Option, error handling
0008Pattern Matching/RecurseStructural inductionExhaustive matching, termination
0009Dependent TypesPi and Sigma typesIndexed families, Vec n

Part II: Core Mathematics and CS (0010-0017)

#TopicMath FocusCS Focus
0010Nat and InductionPeano axioms, inductionRecursive algorithms on Nat
0011Lists/Data StructuresSequences, finite setsFunctional data structures
0012Finite Types/DecidableDecidable predicatesBool vs Prop, Fin n
0013Algebraic StructuresGroups, rings, fieldsAbstract interfaces
0014Basic Number TheoryDivisibility, primesVerified algorithms
0015Automation and SimpSimplificationsimp, omega, ring, norm_num
0016Metaprogramming IntroCustom tacticsLean 4 macro system
0017ProjectsFormalise a theoremBuild a verified program

Part III: Systems Programming (0018-0024)

#TopicFocus
0018IO and System ProgFile IO, processes, environment
0019Lakefile and LakeBuild system, dependencies, targets
0020Compiled ProgramsLake projects, multi-file, executables
0021FFI and C InteropCalling C from Lean, opaque types
0022Concurrency and TasksTasks, Mutex, IO.Ref, channels
0023File IO and CLIBuilding real CLI tools
0024Performance/CompileTail recursion, Array, @[inline], FFI

Part IV: Contributing to Libraries (0025-0027)

#TopicFocus
0025Contributing to MathlibConventions, PR workflow, linting
0026Contributing to CSLibLTS, bisimulation, process algebra
0027Contributing to ArkLibCryptographic formalization

Part V: Deep Lean Expertise (0028-0031)

#TopicFocus
0028Lean InternalsKernel, elaborator, compiler, IR
0029Elaboration/UnificationMetaM, type inference, debugging
0030Advanced MetaprogrammingCustom tactics, elaborators, DSLs
0031Type Theory FoundationsCIC, universes, proof irrelevance

Building

lake build

This compiles all Solutions.lean files (0000-0015) and verifies they type-check.

Lore

The lore/ directory contains behind-the-scenes stories, etymologies, and deep explanations. Why is it called a "tactic"? What does omega actually do? How did we get from LCF to Lean?

Each lore file is self-contained and linked from the relevant course.

Running Exercises

lake env lean 0000-startup/Exercises.lean

Contributors

dannywillems

19 commits

BaDaaS/lean4-courses

Lean

47

21 commits

updated Jun 26, 2026

See the code

README

Lean 4 Crash Course

A hands-on crash course in Lean 4 for mathematicians and computer scientists. The goal is to go from zero to contributing to Mathlib, CSLib, and ArkLib.

How to Use

Each directory NNNN-topic/ contains:

  • README.md - Lecture notes with explanations
  • Exercises.lean - Exercises (replace sorry with proofs/definitions)
  • Solutions.lean - Reference solutions

Courses are sequential. Complete them in order.

Prerequisites

Course Outline

Part I: Foundations (0000-0009)

#TopicMath FocusCS Focus
0000StartupLean as a proof assistantLean as a programming language
0001TypesTypes as mathematical setsTypes as data specifications
0002FunctionsFunctions as mapsFunctions as computations
0003Propositions and ProofsCurry-Howard, logic in LeanProps as types
0004TacticsInteractive proofsTactic DSL, proof automation
0005Inductive TypesConstructing N, Z, treesADTs, enums, recursive types
0006Structures/TypeclassesAlgebraic structuresInterfaces and polymorphism
0007Monads and Do NotationKleisli compositionIO, Option, error handling
0008Pattern Matching/RecurseStructural inductionExhaustive matching, termination
0009Dependent TypesPi and Sigma typesIndexed families, Vec n

Part II: Core Mathematics and CS (0010-0017)

#TopicMath FocusCS Focus
0010Nat and InductionPeano axioms, inductionRecursive algorithms on Nat
0011Lists/Data StructuresSequences, finite setsFunctional data structures
0012Finite Types/DecidableDecidable predicatesBool vs Prop, Fin n
0013Algebraic StructuresGroups, rings, fieldsAbstract interfaces
0014Basic Number TheoryDivisibility, primesVerified algorithms
0015Automation and SimpSimplificationsimp, omega, ring, norm_num
0016Metaprogramming IntroCustom tacticsLean 4 macro system
0017ProjectsFormalise a theoremBuild a verified program

Part III: Systems Programming (0018-0024)

#TopicFocus
0018IO and System ProgFile IO, processes, environment
0019Lakefile and LakeBuild system, dependencies, targets
0020Compiled ProgramsLake projects, multi-file, executables
0021FFI and C InteropCalling C from Lean, opaque types
0022Concurrency and TasksTasks, Mutex, IO.Ref, channels
0023File IO and CLIBuilding real CLI tools
0024Performance/CompileTail recursion, Array, @[inline], FFI

Part IV: Contributing to Libraries (0025-0027)

#TopicFocus
0025Contributing to MathlibConventions, PR workflow, linting
0026Contributing to CSLibLTS, bisimulation, process algebra
0027Contributing to ArkLibCryptographic formalization

Part V: Deep Lean Expertise (0028-0031)

#TopicFocus
0028Lean InternalsKernel, elaborator, compiler, IR
0029Elaboration/UnificationMetaM, type inference, debugging
0030Advanced MetaprogrammingCustom tactics, elaborators, DSLs
0031Type Theory FoundationsCIC, universes, proof irrelevance

Building

lake build

This compiles all Solutions.lean files (0000-0015) and verifies they type-check.

Lore

The lore/ directory contains behind-the-scenes stories, etymologies, and deep explanations. Why is it called a "tactic"? What does omega actually do? How did we get from LCF to Lean?

Each lore file is self-contained and linked from the relevant course.

Running Exercises

lake env lean 0000-startup/Exercises.lean

Contributors

dannywillems

19 commits

Languages

Lean

99.4%