Leanpub Header

Skip to main content

Lean 4: Programming, Proof, and Formal Verification

A Deep Guide to Functional Programming and Interactive Theorem Proving

Lean 4: Programming, Proof, and Formal Verification
This book is 100% completeLast updated on 2026-10-02

Go beyond the basics of Lean 4. This practical deep dive explores functional programming, dependent types, theorem proving and formal verification. Learn how Lean works under the hood, build reliable proofs and automation, and tackle larger formal projects with confidence.

Minimum price

$25.00

$35.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
229
Pages
About

About

About the Book

This book provides a thorough, technically precise exploration of Lean 4 as a functional programming language and interactive theorem prover. It is intended for software engineers, mathematicians and researchers who want to understand Lean at a deep level: its type-theoretic foundations, its architecture, its facilities for programming and verification and its ecosystem for building large formal projects. By the end of this book you will be able to write executable Lean programs, develop machine-checked proofs, construct custom automation and language extensions and organize substantial formal verification projects. The material assumes familiarity with programming and basic mathematics but no prior background in type theory, dependent types, or theorem provers.

Bundle

Bundles that include this book

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience spanning software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. His work focuses on understanding complex systems, uncovering security weaknesses and developing practical solutions that make technology more secure, reliable and effective.

Through Steve Publications, he collaborates with experienced researchers, engineers and industry experts to create practical, technically rigorous books on various topics not limited to self-improvement, software development, cybersecurity, cloud computing, DevOps, artificial intelligence and enterprise technologies. His mission is to make complex technical subjects accessible through clear explanations, real-world examples and hands-on exercises that help IT professionals, students and technology enthusiasts build valuable, practical skills.

Steve Publications embraces AI as a supporting tool for translation, proofreading and editorial refinement, not as a substitute for original research, technical expertise, or hands-on experience. Some contributors choose to publish under pseudonyms to protect their privacy or maintain professional boundaries.

Behind every book is a commitment to technical accuracy, practical relevance and continuous improvement. Our publications are written, reviewed and maintained by experienced professionals, with support from a private community of more than 420 engineers and researchers. Rather than prioritizing volume or mass-produced AI-generated content, we focus on delivering reliable, useful resources that readers can apply in real-world environments.

We also welcome experienced professionals who want to share their knowledge by writing or reviewing books, particularly in specialized and emerging technology fields. If you have expertise to contribute, we invite you to get in touch and explore opportunities to collaborate.

Our commitment is simple: To deliver books that respect our readers' time, support their professional growth and provide lasting practical value. If a book does not meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

A Deep Guide to Functional Programming and Interactive Theorem Proving

Chapter 1: Why Lean

  1. The Problem of Correctness in Software and Mathematics
  2. Unifying Programs and Proofs
  3. A Brief History of Lean and Its Design Philosophy
  4. What Lean Can Do: Use Cases and Examples
  5. How to Read This Book

Chapter 2: Getting Started with Lean 4

  1. Installing Lean and Lake
  2. Your First Lean Project
  3. Editors, LSP and the Lean Environment
  4. Running and Interacting with Lean
  5. The Lake Build System and Package Manager
  6. Project Structure and Configuration

Chapter 3: The Lean Syntax and Basic Types

  1. Modules, Namespaces and Imports
  2. Identifiers and Declarations
  3. Basic Types and Literals
  4. Variables and Local Definitions
  5. Functions and Applications
  6. Pattern Matching

Chapter 4: Dependent Types and the Foundations

  1. From Simple Types to Dependent Types
  2. The Calculus of Constructions
  3. Universes and Polymorphism
  4. Pi Types and Dependent Functions
  5. Dependent Pairs and Sigma Types
  6. Definitional Equality and Conversion

Chapter 5: Inductive Types and Data Structures

  1. Defining Inductive Types
  2. Pattern Matching and Recursion
  3. Lists, Vectors and Indexed Types
  4. Inductive Families
  5. Algebraic Data Types in Practice
  6. Recursive and Well-founded Functions

Chapter 6: Functional Programming in Lean

  1. Higher-order Functions and Composition
  2. Type Classes and Generic Programming
  3. Structures and Records
  4. Monads and Do Notation
  5. Standard Library Collections
  6. Performance and Mutation

Chapter 7: Propositions as Types

  1. Prop and Type: Two Universes of Discourse
  2. Logical Connectives as Types
  3. Quantifiers as Dependent Types
  4. Proof Terms and Proof Checking
  5. Classical and Constructive Logic
  6. Decidability and Computation

Chapter 8: Writing Proofs in Lean

  1. Term-Style Proofs
  2. Tactic Mode Basics
  3. Core Tactics: intro, apply, exact, refine
  4. Breaking Down Goals: constructor, cases, induction
  5. Structuring Proofs: have, show, calc
  6. When to Use Tactics Versus Terms

Chapter 9: Equality and Rewriting

  1. Definitional and Propositional Equality
  2. The Equality Type and Its Eliminator
  3. The rw and subst Tactics
  4. Calc Blocks for Chain Reasoning
  5. Function Extensionality and Congruence
  6. Quotients and Equivalence Relations

Chapter 10: Automation and Simplification

  1. The Simplifier: simp and simp_lemmas
  2. Rewrite Tactics and Strategies
  3. Decision Procedures: decide and native_decide
  4. Arithmetic Automation
  5. Proof Search: aesop and Other Tools
  6. When Automation Helps and Hurts

Chapter 11: The Lean Type System Deep Dive

  1. Lean’s Type Theory: A Formal View
  2. Inductive Type Recursors and Eliminators
  3. Computation Rules and Reduction
  4. Termination and Well-founded Recursion
  5. Universe Levels and Size Constraints
  6. Type Checking and Soundness

Chapter 12: Implicit Arguments and Type Class Resolution

  1. Implicit Arguments and Inference
  2. Type Classes: Concept and Mechanism
  3. Instance Resolution and Search
  4. Coercions and Canonical Constructions
  5. Type Class Hierarchies and Algebra
  6. Debugging Type Class Failures

Chapter 13: The Lean Architecture

  1. The Trusted Computing Base
  2. From Source to Proof Term: The Elaboration Pipeline
  3. The Parser and Syntax Trees
  4. The Kernel: Proof Checking
  5. The Compiler and Runtime
  6. Untrusted but Useful: Automation and Tooling

Chapter 14: Metaprogramming and Extensibility

  1. Why Extend Lean?
  2. Syntax Extensions and Custom Notation
  3. Hygienic Macros
  4. Elaborators and Commands
  5. Tactic Implementation
  6. Building Domain-Specific Languages

Chapter 15: Formal Verification and Verified Programming

  1. Specification: Pre-, Post- and Invariants
  2. Verifying Algorithms and Data Structures
  3. Functional Correctness and Properties
  4. Verified Compilers and Translations
  5. Cryptographic and Security Properties
  6. Case Study: A Verified Data Structure

Chapter 16: Mathematical Formalization with Mathlib

  1. Lean Core, Stdlib and Mathlib
  2. Working with Existing Formalizations
  3. Algebra and Type Class Hierarchies
  4. Analysis and Topology
  5. Discrete Mathematics and Combinatorics
  6. Engineering Large Formalizations

Chapter 17: Practical Engineering and Best Practices

  1. Project Organization at Scale
  2. Namespace and Module Design
  3. Performance Engineering
  4. Documentation and Readability
  5. Testing and Debugging Proofs
  6. Common Pitfalls and Solutions

Chapter 18: The Lean Ecosystem and Beyond

  1. Lean 4 Version History and Releases
  2. Tooling and Integrations
  3. Community and Contribution
  4. Interoperability and FFIs
  5. Real-World Deployments
  6. Where Lean Is Headed

Conclusion

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub