The Proofs and Programs Club @ RHUL

A verified relational algebra library in Lean, by hand

We Have a Challenge for You!

We welcome your challenges!

Got a program you wish were proved correct? A theorem you would love to see Lean check?

Pitch it to us: it could be another challenge for the club!

Have a go at the challenges you find intriguing.

Tell us on Discord, or come along any Thursday (papc-rhul.github.io).

Our challenge: teach Lean to answer questions about tables

Here are two tables of our club: who is a member, in which department; and who came to which weekly session.

\(\rel{Member}\)
\(\att{name}\)\(\att{dept}\)
AdaMaths
AlanCS
GraceCS
\(\rel{Attended}\)
\(\att{name}\)\(\att{week}\)
Ada1
Alan1
Alan2
Grace3

Which CS members came in week 1? Alan.

In the language you will learn, the question is \(\proj{\att{name}}(\sel{\att{dept} = \val{CS}}(\rel{Member}) \join \sel{\att{week} = 1}(\rel{Attended}))\). Do not worry if it means nothing to you yet: each symbol in it gets a level of its own, and Level 1 starts from what a table is.

Why prove it? Databases rewrite your questions

A law can be proved. In this challenge, you prove them.

Start at Level 1, then pick a track, or both

Everyone starts at Level 1. Then come two tracks, which you can take in either order, or side by side:

The tracks meet at Level 6, which needs both: there, you prove that your programs compute exactly what the laws are about.

What you will have built

  1. Your first proof: Lean checks a fact about the club's tables (Level 1).
  2. A query engine on lists: you program selection, projection, product, union, difference and joins, and run them on the club's tables (Levels 2F to 4F).
  3. Laws for every table: you prove laws 1 to 5 once, for all tables; law 5 needs a side condition (Levels 2T to 4T).
  4. A query language: queries become terms, and eval answers them (Level 5F). With induction, you prove facts about every list (Level 5T).
  5. Programs proved correct: your programs compute the operators, so every law holds for them (Level 6).
  6. Laws for every query: each side condition becomes a precise hypothesis about attribute names (Level 7).
  7. A verified optimiser: it rewrites queries and never changes an answer (Level 8).
  8. A verified fast join: it computes the same table as the definition, much faster (Level 9).

How to start, whenever you like

  1. Play the Natural Number Game, in your browser: start with its Tutorial World.
  2. Open Level 1: it shows how to install Lean, what a table is, and how to write your first proof.
  3. Then pick a track, or both.

Stuck, or curious? Ask us on Discord, or come along any Thursday.

Your progress

Tick the milestones on each level page as you go: the map above shows how far you are. Your ticks are saved in this browser only.

References