Zulip Chat Archive

Stream: lean4

Topic: Compile Lean code to a neat little executable


Huỳnh Trần Khanh (Jan 25 2021 at 12:55):

How do I compile Lean code to a neat little executable? I know how to compile the Lean code into C but I have no idea how to compile the C code into an executable, it seems that the C code depends on some runtime library (<lean/lean.h>).

Reid Barton (Jan 25 2021 at 12:57):

If you have a project set up properly, then leanmake bin should do it

Huỳnh Trần Khanh (Jan 25 2021 at 13:11):

Awesome! Where can I learn more about Lean 4 aside from the official docs? Some talks could be helpful.

Kevin Buzzard (Jan 25 2021 at 13:15):

This stream :-) It was only released three weeks ago! Leo has given a bunch of talks about it. You know about the LT2021 talks I guess but Leo has certainly given other talks

Patrick Massot (Jan 25 2021 at 13:43):

See also https://leanprover.github.io/publications/ for papers and talks.

Kevin Buzzard (Jan 25 2021 at 14:00):

@Huỳnh Trần Khanh it occurs to me that you might also like to look at Reid Barton's solutions to advent of code 2020: https://github.com/rwbarton/advent-of-lean-4 . It might be interesting to port them to the release version of Lean 4, for example.

Huỳnh Trần Khanh (Jan 25 2021 at 16:21):

It seems that the AoC solutions only use Lean as a functional programming language, not as a theorem prover. So this is not quite what I'm looking for.

Huỳnh Trần Khanh (Jan 25 2021 at 16:22):

Anyways, thanks!

Yaël Dillies (Apr 24 2023 at 16:59):

Hello from the future, how do I create an executable from my super slow Lean code?

Yaël Dillies (Apr 24 2023 at 17:02):

I am running lake build on my project with a lakefile that looks like

import Lake
open Lake DSL

package Catam

@[default_target]
lean_lib Catam

lean_exe catam where
  root := `Catam

require mathlib from git "https://github.com/leanprover-community/mathlib4"@"master"

(note that I don't have bleeding edge lake, but I'm not managing to update it). And Catam.lean contains def main : IO Unit := .... When running lake build, I would expect to find my executable as build.bin.Catam.exe, but nothing!

Yaël Dillies (Apr 24 2023 at 17:02):

Am I doing something wrong?

Sebastian Ullrich (Apr 24 2023 at 17:05):

build builds the default targets. Use build catam or apply [default_target] to it.

Yaël Dillies (Apr 24 2023 at 17:07):

What does

@[default_target]
lean_lib Catam

if not applying {default_target] to Catam.lean?

Henrik Böving (Apr 24 2023 at 17:08):

it compiles Catam.lean as a library (i.e. a set of .olean files) not as an executable (i.e. a set of .c files that get turned into .o files that get turned into a binary)

Yaël Dillies (Apr 24 2023 at 17:08):

Aaah, you mean I should make the executable a default target?

Henrik Böving (Apr 24 2023 at 17:11):

yes

Yaël Dillies (Apr 24 2023 at 17:12):

Okay, now I get a bunch more exciting errors :grinning:

Henrik Böving (Apr 24 2023 at 17:12):

Also note that just because our compiler is pretty cool :tm: doesn't mean that it will magically make everythign fast :P

Yaël Dillies (Apr 24 2023 at 17:14):

I know that the complexity of my algorithm must be through the roof, but at least I can let an executable run overnight. The examiners don't have to know

Yaël Dillies (Apr 24 2023 at 17:14):

Here are the new errors. Does that smell like I should update lake, or is it something different?

$ lake build Catam
Building Std.Linter.UnreachableTactic
Building Std.Linter.UnnecessarySeqFocus
error: > LEAN_PATH=.• PATH c: -DwarningAsError=true -Dlinter.missingDocs=true  -R  -o  -i  -c  error: stdout:
 error: invalid {...} notation, expected type is not of the form (C ...)
  Linter
error: external command `c: exited with code 1
error: > LEAN_PATH=.• PATH c: -DwarningAsError=true -Dlinter.missingDocs=true  -R  -o  -i  -c .

Sebastian Ullrich (Apr 24 2023 at 17:16):

It works in your editor?

Yaël Dillies (Apr 24 2023 at 17:16):

The file compiles in my editor, I have the infoview, yada yada

Sebastian Ullrich (Apr 24 2023 at 17:17):

But it fails on a file of your project, not on Std?

Yaël Dillies (Apr 24 2023 at 17:18):

Nevermind, I restarted the server and everything broke :sad:

Sebastian Ullrich (Apr 24 2023 at 17:20):

And it's from the [default_target] change? It looks more like a Lean version conflict between Std and your project.

Yaël Dillies (Apr 24 2023 at 17:22):

I think it's because I tried to update lake (and god knows what commands I ran), so you're right and it's a version mismatch. How do I get out of version hell?

Sebastian Ullrich (Apr 24 2023 at 17:24):

and god knows what commands I ran

That does sound like a problem

Sebastian Ullrich (Apr 24 2023 at 17:25):

Usually you shouldn't touch any more than lean-toolchain for that

Yaël Dillies (Apr 24 2023 at 17:28):

I tried elan update lake, elan update.

Mauricio Collares (Apr 24 2023 at 17:39):

Manually edit your lean-toolchain file to point to the 2023-04-20 nightly

Henrik Böving (Apr 24 2023 at 17:40):

Yaël Dillies said:

I know that the complexity of my algorithm must be through the roof, but at least I can let an executable run overnight. The examiners don't have to know

what are you doing? :eyes:

Yaël Dillies (Apr 24 2023 at 17:43):

Finding matchings in bipartite graphs. Can't be that hard :grinning:

Henrik Böving (Apr 24 2023 at 17:45):

The good matching algorithms are pretty good complexity wise right?

Yaël Dillies (Apr 24 2023 at 17:46):

You're overestimating the chair-keyboard interface

Reid Barton (Apr 24 2023 at 20:27):

The bad algorithms are also pretty bad.


Last updated: Dec 20 2023 at 11:08 UTC