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 in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

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.)

In fact, authors have earned over $15 million writing, publishing and selling 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