Little Bits of Lean 4
Preface
- What’s Up With Lean 4?
Introduction
- Installing Lean on macOS
- Running the examples
- What each chapter needs
A Short Tour of Lean 4
- Functions
- #eval
- Lists, arrays, and tuples
- String helpers
- Structures
- Type classes and instances
- abbrev and dot calls
- Coercions
- Inductive types and pattern matching
- Option and do
- More monads: Except and StateM
- Loops and local variables
- Typing the symbols
- Numbers
- Sorting and exact fractions
- Bool and Prop
- Proofs
- Programs
- A helper you will see again
- Cheat sheet
Bayesian Inference
- The Code
- How It Works
- Checking the Numbers
- Lean 4 Notes
- Running It
- Using It
A Tiny Triple Store
- The Code
- How It Works
- Lean 4 Notes
- Running It
- Using It
Ranking Documents with BM25
- The Code
- How It Works
- Checking a Score
- Lean 4 Notes
- Running It
- Using It
Extractive Summarization
- The Code
- How It Works
- Checking a Score
- Lean 4 Notes
- Running It
- Using It
A Tiny Vector Store
- The Code
- How It Works
- The Geometry
- Lean 4 Notes
- Running It
- Using It
Associative Memory with Hopfield Networks
- The Code
- How It Works
- Lean 4 Notes
- Running It
- Testing Recall
- Using It
Symbolic Polynomial Calculus
- The Code
- How It Works
- Multiplication
- Lean 4 Notes
- Running It
- Using It
Automatic Differentiation
- The Code
- How It Works
- Checking the Gradients
- Lean 4 Notes
- Running It
- Using It
On-Device AI with Apple Foundation Models
- The Code
- How It Works
- The fm Command
- Lean 4 Notes
- Running It
- Using It
JavaScript-Rendered Pages with Lightpanda
- Dump Formats
- The Code
- How It Works
- Lean 4 Notes
- Running It
- Using It
Local LLMs with Ollama
- The Code
- How It Works
- The Reply
- Multi-turn Chat
- Generation Options
- Lean 4 Notes
- Running It
- Using It
Calling Google Gemini
- The Code
- How It Works
- Keeping the Key Private
- The Response
- Generation Options
- Lean 4 Notes
- Running It
- Using It
Querying Knowledge Graphs with SPARQL
- The Code
- How It Works
- The Result Format
- Lean 4 Notes
- Running It
- Using It
Web Search with Exa and Brave
- The Two APIs
- The Code
- How It Works
- Lean 4 Notes
- Running It
- Using It
From One File to a Lake Project
- Modules and Files
- Adding an Executable
- A Project for This Book
- Troubleshooting
Making Stand Alone Programs With Lean 4
- Four Steps With Lake
- What the Build Leaves Behind
- Building One File by Hand
- Start-Up Time
- A Command-Line Tool That Calls C
- Linking a System Library
- Shipping the Binary
- Try This
Errors You May See
- A reserved word as a name
- A line that starts with a minus sign
- A field of an unknown type
- A missing default value
- An import after code
- An identifier from a missing import
- A Nat where a Float is expected
- A missing match case
- A subtraction that floors at zero
- Summary
- Reading an Error
Where to Go Next
- Properties to Prove
- A First Proof
- Tactics and Mathlib
Use Cases: Mathematical Discovery, Verification, and AI
- Why a Checked Proof Means Something
- Proving Things About Programs
- Verification in Production
- Mathlib
- Lean and AI
- What This Means for You