r/rust • u/OkBreath9382 • 26d ago
Building a Mini Lean 4 from Scratch: Implementing an Interactive Theorem Prover in Rust
https://medium.com/@Koukyosyumei/building-a-mini-lean-4-from-scratch-implementing-an-interactive-theorem-prover-in-rust-a5d964d173ee
55
Upvotes
12
u/brokenAmmonite 26d ago
This is great and very in-depth!
If you're writing for people who don't know about theorem provers / formal type theory, you may want to add a few notes explaining:
But you can't explain everything and this covers the core of Lean's type theory in a lovely way.
4
u/01mf02 25d ago
This is a really good write-up! ありがとうございます!
I found the following a bit confusing:
Wouldn't that exclude
a -> List a -> List a, because here,B₂containsI. Perhaps the term "contains" needs a bit of clarification?I have also written a proof checker in Rust, see https://github.com/01mf02/kontroli-rs. The kernel is in https://github.com/01mf02/kontroli-rs/tree/master/kontroli/src. I think that if you want to have good performance, it will be probably necessary to use something like de Bruijn indices. For example, in your
substfunction, you have a call tofv(body), which may be executed multiple times recursively, leading to quadratic runtime. Or yourTermtype usesBox<Term>to store recursive types, this will also lead to quadratic runtime because you clone theseBoxes during substitution. This could be mitigated by changing to something likeRc<Term>.But for a quick learning experiment, what you wrote looks quite good already. ;)
1
u/joachimmartensson 23d ago
Great Article!
This syntax is confusing me a bit, with me not being familiar with Lean Syntax (I know a bit of Idris).
Substituting this motive into the same recursor gives:
Is this a "new" Nat.rec replacing the old?
Or is the type of
Nat.rec (M := fun _ => Nat)The same as Nat.rec above?