CSCI 0190 · Fall 2026

Return to Moravia🔗

    1 What is This Assignment’s Purpose?

    2 Theme Song

    3 The Assignment

      3.1 Translate

      3.2 Terminate

      3.3 Prove

    4 Stretch Goal

    5 Submission

1 What is This Assignment’s Purpose?🔗

The future of software development is likely to involve a lot more code accompanied by proofs of correctness, not only tests.

This trend, in particular, will likely be greatly amplified by having AI generate these proofs: if, for relatively little extra effort, you can get a proof that your code does what you want it to, why not have it?

2 Theme Song🔗

Go Your Own Way by Fleetwood Mac

3 The Assignment🔗

You will return to your implementation of Kruskal’s algorithm from MST. We will stick to the simple implementation you did for that homework, ignoring the union-find algorithm we saw in class.

3.1 Translate🔗

Have Claude translate your implementation, and manual tests, into Lean. Tell it to, as much as possible, transliterate the code, so the output Lean is very recognizable to you as the code you wrote earlier.

In doing this translation, almost certainly you (Claude!) will run into a problem with termination. Tell Claude that it is welcome to use partial where needed. With that, it should be straightforward to convert your code to Lean, convert your tests to Lean, and make sure everything works the same in that language.

Tell Claude to not use Mathlib for this project. Mathlib is an outstanding library, but it is not only huge, it will also likely greatly complicate the way your code is translated and formalized, making it much harder for you to understand; nor is it needed for this task. Telling Claude to avoid it (and telling it that you are a Lean novice) will help.

3.2 Terminate🔗

The problem you most probably ran into is the following. (If you did not run into any problems, that would be a bit surprising. It’s possible your code has a bug! But if neither of those is true, you can skip this section…)

In Lean, all functions must terminate. (Why? Read here.) Lean must be able to confirm this. partial is an “escape hatch” that lets you define functions that may not terminate (that’s what “partial” means in this context: not guaranteed to return an answer on all inputs), but as the reading above shows, that is useless for proofs.

Very roughly speaking, Lean checks whether your code is structurally recursive (what you learned from HtDP—useful, believe it or not!—and what we saw in class when discussing “natural” sorting algorithms). If not, it tries to construct a measure that shows that the total amount of work is decreasing. If these techniques don’t work, Lean requires you to convince it that the function terminates.

Lean likely can’t automatically confirm that your reachability search terminates. Your reachability search probably has two parameters: the frontier of nodes to explore, and the nodes that have been seen. If the next node in the frontier has already been seen, great: we remove that node from the frontier, the seen-list is unchanged, so the net argument size is smaller. But suppose it isn’t. We then remove that node from the frontier (good!); add it to the seen-list, increasing its size (unhelpful to Lean…); and add all its neighbors to the frontier, thereby potentially making that parameter much larger (not good!). Therefore, Lean cannot prove that either argument gets smaller—both can, in fact, get larger!

If your code is correct, reachability does in fact terminate (think about why!). Claude can construct a “measure” for you to help you prove termination. But you can make this proof a lot simpler by changing your reachability code: when you eliminate a node from the frontier, shrink the graph by getting rid of all the edges adjacent to the node.Note that this strategy also gets rid of the seen-list entirely. (Think about why this is safe to do!) This means that on any iteration that adds to the frontier, the graph itself gets smaller; on the other iterations, the frontier does. This leads to a much simpler argument for why reachability terminates.

Ask Claude to modify the code to do this, then add whatever proof is needed to remove any partial annotations. Re-run tests to make sure the Lean code is still working as expected.

3.3 Prove🔗

Now you are finally ready to prove your code correct.

Have Claude formulate each of the three key properties—minimum, spanning, and tree—as three separate Lean theorem statements. Most probably it will need to generate some hypotheses as well to make the proofs go through. Read all of these and confirm that they mean what you expect. If there are errors here, the proofs are meaningless! Use Claude to help you understand the syntax and meaning of Lean.

Once you are satisfied with the theorem statements, have Claude generate the Lean proof for you. It ought to do so completely automatically. (If it doesn’t, we’d love to hear and try it for ourselves! But don’t put this off until the last minute…) You are unlikely to understand any of the generated proof. That’s okay!

4 Stretch Goal🔗

This section is entirely optional.

You may find it a bit unsatisfying that your code still uses the slow reachability test, not the extremely fast union-find solution we saw in class. However, writing imperative programs in Lean is more complicated. Of course, Claude can do it for you, automatically; but you may not learn very much from this process.

Have Claude go through the above steps again. Start with replacing reachability checking in Pyret with a union-find implementation. Then have Claude translate it to Lean. It may well ask you if you want to use monads; you do. Then have it prove this version correct.

Now let’s think about relating these two implementations. In principle, we should be able to get Lean to prove some theorems about the two. At the very least, we would want a theorem that they both produce answers of the same weight. But do they produce the exact same trees? Use Claude to drive Lean to explore this question! Write up what you learn and turn it in along with the rest of the submission.

You aren’t required to do this part at all! This is only for people who really want to dive deep into this technology. In a few years, many of you may need to do this, but there are better ways to learn it than through this firehose. On the other hand, if all you need is a nudge…consider yourself nudged.

5 Submission🔗

Generate a zip file consisting of your Pyret and Lean source programs and support files. We should be able to run make and see Lean confirm that all your proofs discharge. We strongly urge using Claude to help you build this repository in a way that aids reproducibility on our end. It is very helpful at this kind of packaging.

The key to successfully using tools like Lean is to make sure that each theorem statement says what we want. The proof itself may not be intelligible; checking that it is correct is essentially a job for computers.The Lean community’s writeup about checking the recent purported proof of the Riemann Hypothesis shows how much math proof checking has turned into a software testing and verification problem! But if we’ve proved the wrong result, all that effort is for nought.

Therefore, also submit a written document explaining the three theorem statements for MST, in your own words. Absolutely do not use any AI to write any of this. You are most welcome to use Claude to explore the meanings of the theorem statements and supporting definitions: you don’t know Lean, and Claude can help you understand what is going on. But ultimately we want to see your understanding of this formalization.

Note: Please use PDF for all written documents. Gradescope cannot handle Word and other formats. Whatever you write in, please export to PDF.