# Course Description

Proof assistants are tools that are used to check the correctness of programs. Unlike tools like model checkers and SAT solvers, proof assistants are highly interactive. Machine-checked formal proofs lead to trustworthy programs and fully specified reliable mathematics. This course introduces students to the theory and use of proof assistants, using the system Lean. We will use Lean to verify properties of functional programs and theorems from pure mathematics. We will learn the theory of deductive reasoning and the logic that these tools are based on.

Syllabus: syllabus.pdf

Lecture: MW 3:00–4:20 p.m., CIT 368

Lab: Th 4:30–6:00 p.m., CIT 210

# Course Content

We plan to cover most of the Hitchhiker’s Guide to Logical Verification. We'll cover chapters roughly according to the schedule below, but topics may shift slightly as the semester progresses.

• Basics
• 1. Definitions
• 2. Backward Proofs
• 3. Forward Proofs
• Functional-Logic Programming
• 4. Functional Programming
• 5. Inductive Predicates
• Program Semantics
• 8. Operational Semantics
• 10. Denotational Semantics
• Mathematics
• 11. Logical Foundations
• 12. Basic Mathematical Structures
• 13. Rational and Real Numbers
• Meta-Reasoning
• 7. Metaprogramming

# Assignments

## Homework

Homework will be submitted via Gradescope. Please ensure you have familiarized yourself with the grading and collaboration policies in the syllabus.

Homework Material Covered Released Due
HW 1 Ch. 1 9/12/22 9/21/22
HW 2 Ch. 2 9/19/22 9/28/22
HW 3 Ch. 3 9/26/22 10/5/22
HW 4 Ch. 4 10/3/22 10/12/22
HW 5 Ch. 5, 8 10/17/22 10/26/22
HW 6 Ch. 8, 10 10/24/22 11/2/22
HW 7 Ch. 12 10/31/22 11/9/22
HW 8 Ch. 11 11/7/22 11/16/22
HW 9 Ch. 13 11/14/22 11/23/22
HW 10 Ch. 6, 7 11/21/22 11/30/22
Final Project 12/16/22

## Labs

Labs are optional, TA-led sessions that provide an opportunity to practice and reinforce the content covered in lecture. Labs are held every Thursday, 4:30–6:00 p.m., in CIT 210.

Lab Date
Lab 1 (Lean Basics) 9/15/22
Lab 2 (Backward Proofs) 9/22/22
Lab 3 (Forward Proofs) 9/29/22
Lab 4 (Functional Programming) 10/6/22
Lab 5 (Inductive Predicates) 10/13/22
Lab 6 (Operational Semantics) 10/20/22
Lab 7 (Denotational Semantics) 10/27/22
Lab 8 (Algebraic Structures) 11/3/22
Lab 9 (Logical Foundations) 11/10/22
Lab 10 (Rationals and Reals) 11/17/22
Lab 11 (Monads and Tactics) 12/1/22

# Lectures

You can download lecture demo files and view lecture recordings here. We will aim to update this table shortly after each lecture. All lecture recordings can also be found on Panopto.

9/7 Introduction We’ll talk about what Lean is and see what it can do, and also go over some organizational points about the course.

Takeaways: Verified programming is fun and powerful!
9/12 The basics of Lean syntax In this lecture we’ll learn the basics of the Lean programming and specification language: types and terms, type inhabitation, and writing and evaluating very simple functional programs. No proving yet!
9/14 The basics of Lean syntax, contd. We’ll finish Chapter 1 of the HHG, and get a head start on Chapter 2, where we’ll actually start proving some theorems. Today’s topics: inductive types (continued), function definition and evaluation, specifications.

More on Chapter 2 next time!
9/19 Backward (tactic) proofs We’ll dive into the meat of the HHG Ch. 2: what are some of the moves available to us in the tactic proving minigame, beyond intro and apply? How do we deal with logical connectives: and, or, not, and so on?
9/21 Backward (tactic) proofs, contd. We’ll continue talking about tactic proofs. How do we deal with equality? What about the natural numbers? We’ll also talk about classical vs constructive logic.
9/26 Forward proofs We’ll see another way to write proofs in Lean, incorporating forward reasoning. Structured (“proof-term”) proofs are a little closer to the underlying logic. Surprise: proofs in Lean are, literally, just terms in the type theory.
9/28 Dependent types The type theory that Lean is based on, the Calculus of Inductive Constructions, is an instance of dependent type theory. In DTT, we follow the PAT principle: propositions as types, proofs as terms. (Buzzword: the Curry-Howard correspondence!) We’ll look deeper today into these foundations.
10/3 Functional programming — data structures
Chapter 4 of the Hitchhiker’s Guide introduces some paradigms – inductive types, structures, recursive definitions, type classes – that might be familiar from other functional programming languages. The interesting thing for us is how these paradigms interact with writing proofs. For instance, how do we mix properties into data structures?
10/5 Functional programming — type classes, lists, trees
Type classes are a language feature inspired by Haskell with equivalents in Scala, ML, and other languages. They allow us a kind of ad hoc polymorphism: we can define functions on types that implement certain interfaces, and can declare that certain types implement these interfaces, without bundling the interfaces into the data type itself. We’ll see how this interacts with some of the data structures we like to use, as we implement and specify functions on these types.
10/12 Inductive predicates
We’ll cover ch. 5 of the Hitchhiker’s Guide today, on inductive predicates. This will complete what we need to know about foundations for now: inductive predicates give us a way to introduce new propositions and prove things about them. Inductive predicates are also the source of most of the propositional symbols we’ve used so far – and, or, exists, eq, ….
10/17 Big-step operational semantics
We’re jumping ahead to Chapter 8 today! Time to start putting what we’ve learned into practice. We’ll define the syntax of a toy programming language inside of Lean, discussing the difference between shallow and deep embeddings. Using inductive predicates, we’ll define a transition system and use this to prove things about the execution of programs in this toy language.
10/19 Small-step operational semantics
The big-step semantics we saw on Monday aren’t fine-grained. We can’t reason about intermediate states. An alternative is using a small-step semantics, where our program execution path is broken down much further. This comes with upsides and downsides.
10/24 Denotational semantics
Operational semantics define the meaning of a program by the process it follows to evaluate. In contrast, denotational semantics define the meaning of a program as a mathematical object, a relation between possible inputs and outputs. Today we’ll cover all of Ch 10 of the HHG.
10/26 Algebraic structures
We’ll jump ahead again to chapter 12, where we’ll start talking about algebraic structures. But we’ll also improvise a bit here. After we see some basic structures, we’ll define some mathematical types of our own.
10/31 Numbers and sets
We’ll continue the Ch 12 material we started last week, including a little more with the complex number playground. We’ll also talk about embeddings between different numerical structures, and some different kinds of “set-like” objects.
11/02 Logical foundations
As this course has progressed, we’ve gotten some insight into the foundations of Lean and its type theory. But some features have remained mysterious. In the next few lectures we’ll poke some more at this foundational theory. Today we’ll be focusing in particular on the type universe Prop, what we’re allowed and disallowed in this universe compared to the others.
11/07 Logical foundations, contd.
We’ll continue with chapter 11 today, talking about more foundational constructs. As we discussed last class, there’s a grab bag of features that we can take or leave: proof irrelevance, impredicative Prop, the axiom of choice, and others. Why should we be convinced that the collection we choose is consistent? We’ll introduce the notion of a model of the type theory to answer questions like this.
11/09 Quotients, rationals, and reals
The last bit of Ch. 11, on quotient types, is very relevant to what we want to do next! We’ll wrap up that discussion (including talking a bit about the computability properties of quotients) and then immediately use quotient types to define some familiar things. Rational and real numbers are interesting mathematically, and for programming purposes, they can be a very convenient tool for writing specifications. Even if we don’t compute with real numbers they’re useful to have around.
11/14 Real numbers
We finished last week with the rational numbers. Now we need to complete them to get the reals. This will take yet another quotient. The reals bring to light some computability issues that we’ve touched on briefly before: what does it mean to compute with real numbers? How do we do it in normal languages? If time permits, we’ll look at mathlib’s implementation of the reals and see some generalizations.
Lean has a very powerful framework for writing custom tactics. These tactics are written in Lean itself, with a number of catches to make this possible. Today we’ll see the fundamentals of this approach. We’ll learn the (very) basics about monads, a technique used in some functional languages to simulate programming with side effects. (But this isn’t an FP class and we’re not going to dwell on monads, beyond what we need to know.) Chapter 6 of the HHG is a more detailed introduction to monads. We’ll cover a bit of this, but mainly take an alternate approach to Chapter 7.
More from chapters 6 and 7 of the HHG: we’ll look at the expr type, which reflects Lean expressions as a Lean datatype. There’s a big API around creating, modifying, and using expressions – unsurprisingly, since this is what’s meta about metaprogramming!
There are lots of subtleties to writing metaprograms that we’ve skimmed over so far. In particular, there’s a disconnect between the syntax we use when writing tactics and the syntax we use within begin...end blocks. We’ll touch on these subtleties today. Time permitting, we’ll talk about design strategies for metaprograms, including certification and proof by reflection.
11/30 Linear arithmetic
The tactic linarith solves linear programs over ordered rings. It’s a great example of a “large” metaprogram that shows off a number of interesting design principles. We’ll talk both about the algorithm it implements and the strategy used in implementing the tactic itself.
12/05 TBD
TBD
12/07 TBD
TBD

# Project

The final project is open-ended and intended to give you a chance to explore a topic you enjoy in more depth. Some info and project ideas are available here. We'll update this page as the course progresses, and you're encouraged to come up with your own ideas!

The final project will be due Friday, December 16.

# Staff

The TAs can be reached via email here, and Rob can be reached here. You are also encouraged to post (and answer!) questions on our Ed Discussion board.

## Robert Y. Lewis

Call me Rob! I'm half computer scientist, half mathematician, and fully excited to go through some of my favorite material with you all this semester. Pronouns: he/him/his

## Ian Benway

Casual math and CS Junior. Hardcore oatmeal raisin cookie enjoyer.

## Joseph Rotella

I'm a junior concentrating in CS. When not extolling the virtues of functional programming, I can be found playing piano, cycling, or reading in the Rock stacks.