Proofs about Programs
busy-beavers.tigyog.app
busy-beavers.tigyog.app
There's the manual [1] and "Functional programming in lean" [2] and they enabled me to get programming with it and solving some basic puzzles, but they are both WIP and unfinished.
I would love to explore Lean 4 more but with the current situation it's a bit too time consuming. Hope there will be more in the future.
[1]: https://leanprover.github.io/lean4/doc/
[2]: https://leanprover.github.io/functional_programming_in_lean/
The editor support is quite interesting, and the live updates of #eval statements have helped. I look forward to finding time to do a deeper dive into the language.
You can only write programs that will halt in it.
> ... interactive theorem proving focuses on the "verification" aspect of theorem proving, requiring that every claim is supported by a proof in a suitable axiomatic foundation. This sets a very high standard: every rule of inference and every step of a calculation has to be justified by appealing to prior definitions and theorems, all the way down to basic axioms and rules. In fact, most such systems provide fully elaborated "proof objects" that can be communicated to other systems and checked independently. Constructing such proofs typically requires much more input and interaction from users, but it allows you to obtain deeper and more complex proofs.
https://leanprover.github.io/theorem_proving_in_lean4/introd...
Which sounds very much like a type system to me. You can build complex statements out of finitely many previously-proven statements. The system may try to help you bridge the gap, but as I understand it, ultimately it's up to the user/programmer to find the proof that something will halt.
That's correct, and the consequence is that Coq will reject some valid recursive functions that always terminate. You can't describe the Collatz function in Coq and then ask the compiler if it terminates or not, for example. The compiler will reject the function, but it may still terminate - we don't know.
The general reason for this is that Coq allows you to write recursive proofs (such as the induction in the article), and these recursive proofs need to have limited power - otherwise the proof system becomes inconsistent and it's possible to prove any statement. Since Coq proofs are just programs, if you could write a recursive non-terminating function, you could write such a function that lets you construct ill-founded proofs e.g.
(* Non-terminating Coq function *)
fix : (A -> A) -> A
fix f := f (fix f)
(* Use of that function as a Coq proof building tool *)
my_false_statement : ⊥
my_false_statement := fix (fun x => x)And indeed, you can write programs that do not halt. You just have to explicitly tell Lean that you want to do that.
"That’s because Lean only lets you write functions that halt. "
Is that incorrect?
* You can't unfold the definition to try to prove `foo = foo + 1` (which is of course false for any natural number), it is an "opaque" definition and its value for specification purposes is essentially arbitrary and does not need to match the definition.
* Even then there is a possibility of proving false things as in `partial def loop : False := loop`, so to prevent inconsistency the target type (`Nat` in the previous example, `False` in this one) must be inhabited (proved automatically by the typeclass machinery). So it would reject the `loop` example but not `foo`.
https://strathprints.strath.ac.uk/60166/1/McBride_LNCS2015_T...