Leanpub Header

Skip to main content

Little Leaner

Little Leaner

> Dependent types for beginners, taught the way *The Little Schemer* taught recursion. > Start with a pond. End with a compiler that is proved to keep its meaning. > A proposition is a type. A proof is a thing of that type.

Minimum price

$15.00

$25.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

A small pond: algae, snails and flies, frogs and fish, a duck, a heron and an otter. Eleven short lines say who eats whom. Ask a program whether the heron is above the algae and it may say yes. This book asks for more: a reason you can hold, check, and pass to another program. In Lean 4, the claim "the heron is above the algae" is a type, and a proof of it is a thing of that type. Lean checks the proof the way it checks any program, before anything runs and without trusting anyone.

That idea has a second half, and it is the one in the title. In Lean, a type can mention a value. A list can carry its length in its type, so asking for the first element of an empty list is not a crash at run time but a mistake Lean refuses to accept. Types like that are called dependent types. With them, a program can say what it promises, and a proof can show that it keeps the promise.

This little book teaches both ideas from zero, in the question-and-answer style of The Little Schemer. Each page has two columns, a short question on the left and a short answer on the right. Cover the answers with a card, try, then look. The question you will answer most often is "What is the goal now?", because proofs are written with Lean's tactics from the very first one, and the goal is the best teacher a beginner has. Now and then a box states a Maxim, a short rule the questions above it have earned, from "Every thing has a type. Ask #check before you guess." to "Make wrong programs impossible to write. Then prove the rest."

What you will learn

  1. Things and Their Types. Critters, functions by cases, and what Lean refuses before anything runs.
  2. Propositions Are Types. Claims as types, proofs as things, and the first tactics; then a look at the program a tactic built.
  3. Rules as Constructors. "Above" as a rule that asks for evidence; goals that split in two; "if", "and", "or".
  4. Nothing and Something. False and "not", "for every" and "there is": nothing eats the heron, and here is why.
  5. Numbers by Hand. Numbers from two pieces, proofs by computing, and induction.
  6. Equality. One constructor, what rfl can see, and rewriting when computing is not enough.
  7. Lists and Their Laws. Append, length and reverse written by hand, and their laws proved for every list.
  8. Types That Depend on Values. Vectors that know their length, a head with no empty case, and positions that cannot be out of range.
  9. Families of Evidence. Even numbers, decisions that bring their evidence along, and critters that carry proof they can swim.
  10. A Language That Cannot Go Wrong. Typed expressions, an evaluator that never fails, a stack machine whose stack cannot run dry, and a compiler proved to keep the meaning of every program.

Who it is for

Students and programmers who have never taken a logic course and never written a proof. You need some programming in any language, a pencil, and patience. No mathematics, no Mathlib and no prior Lean are assumed. You do not need to know what ∀ or Π means; by Chapter 8 you will have written both. The Little Elpier, the book this one follows, helps but is not required. A chapter is an evening's work.

What you get

  • 10 short chapters, 752 questions with their answers, and 12 Maxims collected on one page
  • 39 exercises graded ★ to ★★★, each with a solution that Lean checks
  • 12 diagrams: the food web, proof trees, goals that split, induction, a vector's length in its type, compile-then-run
  • A reference card of every command and tactic, with how to read it aloud, and a guided "Where to Go Next"
  • The Apache-2.0 companion code at github.com/Volland/little-leaner: every program in the book, with every printed output, error and goal kept as a golden file that a test checks

Every example is checked

Everything runs on core Lean 4 (version 4.35.0), with no libraries to install beyond Lean itself. One lake build sets up the pond on macOS, Linux and Windows. Open the companion code in VS Code with the Lean 4 extension and every goal in the book appears beside the proof as you move through it.

Share this book

Author

About the Author

Volodymyr Pavlyshyn

Hey I am Volodymyr 

Seasoned Developer's Journey from COBOL to Web 3.0, SSI, Privacy First Edge AI, and Beyond

 As a seasoned developer with over 20 years of experience, I have worked with various programming languages, including some that are considered "dead," such as COBOL and Smalltalk. However, my passion for innovation and embracing cutting-edge technology has led me to focus on the emerging fields of Web 5.0, Self-Sovereign Identity (SSI),AI Agents, Knowledge Graphs, Agentiic memory systems, and the architecture of a decentralized world that empowers data democratization.

A firm believer in the potential of agent systems and the concept of a "soft" internet, I am dedicated to exploring and promoting these transformative ideas. In addition to writing, I also enjoy sharing my knowledge and insights through videoblogging. Most of my Medium posts serve as supplementary content to the videos on my YouTube channel, which you can explore here: https://www.youtube.com/c/VolodymyrPavlyshyn. 

Join me on this exciting journey as we delve into the future of technology and the possibilities it holds.

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