A step-by-step hands-on guide to Lean 4, from installation and #eval evaluation to functions, structures and inductive types, polymorphism, tactic-based theorem proving, mathematical induction, Lake project builds, and verified batch reservation logic.
8 episodes
Lean 4 Basics 1. Setup and Checking Values and Types with #eval and #check
Set up elan and VS Code InfoView, then inspect how natural numbers (Nat), integers (Int), strings (String), and booleans (Bool) behave using #eval and #check.
Lean 4 Basics 2. Defining Functions, Currying, and Anonymous Functions
Define functions with def, call them by juxtaposition without parentheses, and explore currying, partial application, the pipeline operator (|>), and local let bindings.
Lean 4 Basics 3. Structures (structure), Inductive Types (inductive), and Pattern Matching
Model domain data using product types (structure) and sum types (inductive), and handle every case safely with match pattern matching and exhaustiveness checking.
Lean 4 Basics 4. Polymorphism (Type Parameters), Option, and Lists
Write polymorphic functions using curly-brace implicit type parameters {α : Type}, handle absent values with Option α, and practice structural recursion and termination checking on List α.
Lean 4 Basics 5. Propositions (Prop) and Your First Proofs: rfl, rw, intro, exact
Understand how Lean treats propositions as types in Prop and proofs as terms, then prove equalities and logical statements using rfl and tactic mode (by, rw, intro, exact).
Lean 4 Basics 6. Proving Properties of Your Own Functions by Mathematical Induction (induction)
Use the simp and induction tactics to prove universal properties over natural numbers and lists, establishing that sumList distributes over list concatenation (++).
Lean 4 Basics 7. Lake Project Structure, do Notation, and Building an IO Executable
Create a project with Lean 4's Lake build tool, separate pure functions from side effects with the IO type and do notation, and compile a native executable.
Lean 4 Basics 8. A Batch Inventory Reservation System with Rollback on Failure
Process multi-item inventory reservations in sequence, prove per-SKU quantity conservation on success and full rollback to the initial stock on failure, and build a CLI executable with Lake.