1 of 26

the ergonomics of

PL metatheory in Lean

7 June 2024

2 of 26

the ergonomics of

PL metatheory in Lean

or: I couldn’t convince people to use Agda for metatheory

but maybe I can convince you to try out Lean instead

3 of 26

this talk is about:

this talk is not about:

  • tooling and editor support
  • language features designed to take advantage of support
  • demonstrating this with a real PL metatheory codebase
  • how to do metatheory in Lean
  • Lean’s type theory
  • (okay maybe a little at the end. but I promise no typing rules)

3

4 of 26

Coq and Lean are:

  • interactive proof assistants
  • based on dependent types (proofs are terms)
  • with automation via tactics

4

5 of 26

my issues with Coq

  • P1: proof reading is missing ephemeral information
  • P2: term writing isn’t incremental
  • P3: proof editing is sequential
  • P4: information for learning isn’t well integrated

specifically using:

  • Coq-LSP
  • also applies to VSCoq 1/CoqIDE
  • (I don’t use emacs so idk Proof General)

5

6 of 26

P1: proof reading is missing ephemeral information

  • Q1: what changes did this tactic make?
    • in tac1; tac2, what changes did tac1 make?
  • Q2: what is the type of this subexpression?
    • what is the context of this subexpression?
  • Q3: what case is this subproof for?

6

7 of 26

P1: proof reading is missing ephemeral information

  • Q1: what changes did this tactic make?
    • in tac1; tac2, what changes did tac1 make?
  • Q2: what is the type of this subexpression?
    • what is the context of this subexpression?
  • Q3: what case is this subproof for?

7

8 of 26

P1: proof reading is missing ephemeral information

  • Q1: what changes did this tactic make?
    • in tac1; tac2, what changes did tac1 make?
  • Q2: what is the type of this subexpression?
    • what is the context of this subexpression?
  • Q3: what case is this subproof for?

8

9 of 26

P2: term writing isn’t incremental

  • Q1: how do I fill in this term later?
  • Q2: how do I fill in this term with tactics?
    • if I don’t know the exact tactic I need?
    • if I need multiple tactics/generate subgoals?

9

10 of 26

P2: term writing isn’t incremental

  • Q1: how do I fill in this term later?
  • Q2: how do I fill in this term with tactics?
    • if I don’t know the exact tactic I need?
    • if I need multiple tactics/generate subgoals?

10

11 of 26

P2: term writing isn’t incremental

  • Q1: how do I fill in this term later?
  • Q2: how do I fill in this term with tactics?
    • if I don’t know the exact tactic I need?
    • if I need multiple tactics/generate subgoals?

11

12 of 26

P2: term writing isn’t incremental

  • Q1: how do I fill in this term later?
  • Q2: how do I fill in this term with tactics?
    • if I don’t know the exact tactic I need?
    • if I need multiple tactics/generate subgoals?

12

13 of 26

P3: proof editing is (more or less) sequential

  • Q1: when I change a definition, what proofs are broken?
    • did the proofs break in an expected way? or did I change the wrong definition?
    • how much work is left? what should I repair next?
  • Q2: when I change a definition, what proof cases are broken?
    • am I missing a new case?
    • is an old case no longer covered by automation?

13

14 of 26

P3: proof editing is (more or less) sequential

  • Q1: when I change a definition, what proofs are broken?
    • did the proofs break in an expected way? or did I change the wrong definition?
    • how much work is left? what should I repair next?
  • Q2: when I change a definition, what proof cases are broken?
    • am I missing a new case?
    • is an old case no longer covered by automation?

14

15 of 26

P3: proof editing is (more or less) sequential

  • Q1: when I change a definition, what proofs are broken?
    • did the proofs break in an expected way? or did I change the wrong definition?
    • how much work is left? what should I repair next?
  • Q2: when I change a definition, what proof cases are broken?
    • am I missing a new case?
    • is an old case no longer covered by automation?

15

16 of 26

P4: information isn’t well integrated

  • Q1: what does this tactic do?
  • Q2: how do I use this syntax?
    • let’s see you try to remember full syntax for match off the top of your head

16

17 of 26

claim: Lean’s tooling & design

help solve these problems

18 of 26

P4: information isn’t well integrated

  • Q1: what does this tactic do?
  • Q2: how do I use this syntax?

A: documentation on hover!

  • bonus: cross-file ctrl-click navigation

18

19 of 26

P1: proof reading is missing ephemeral information

  • Q1: what changes did this tactic make?
    • in tac1; tac2, what changes did tac1 make?
  • Q2: what is the type of this subexpression?
    • what is the context of this subexpression?

A: infoview at cursor!

  • Q3: what case is this subproof for?�A3: tagged cases help retain this info

19

20 of 26

P2: term writing isn’t incremental

  • Q1: how do I fill in this term later?�A1: with typed holes
  • Q2: how do I fill in this term with tactics?�A2: by dropping into proof mode, anywhere

20

21 of 26

P3: proof editing is (more or less) sequential

  • Q1: when I change a definition, what proofs are broken?
    • did the proofs break in an expected way? or did I change the wrong definition?
    • how much work is left? what should I repair next?
  • Q2: when I change a definition, what proof cases are broken?
    • am I missing a new case?
    • is an old case no longer covered by automation?

A: [demo]

21

22 of 26

tactics I enjoy

  • split: pushes a goal inside of a match
  • calc: explicit equational reasoning
  • apply_rules [lem, …]: keep applying lemmas and hypotheses without backtracking (like Coq’s eauto … using …)

22

23 of 26

other tools and libraries

for Coq

for Lean

  • SSReflect�
  • CoqHammer�
  • Mathcomp�
  • Psatz

23

24 of 26

my issues with Lean

basically designed specifically targeting mathematics

  • no structural recursion on inductive predicates
    • inductive propositions are fine. smth abt decreasing measures
    • pretty sure this is a bug
  • no induction tactic on mutual inductives
    • encode mutual inductives as single inductives
    • Coq doesn’t have great mutual inductive support anyway
  • no coinduction
    • RIP itrees folks ig
  • no modules
    • use typeclasses
  • no Agda-style unification
    • :(((

24

25 of 26

ported existing development in ~1 week

25

26 of 26

learning Lean

26