Zulip Chat Archive

Stream: general

Topic: Lean's implementation


crab (Jan 14 2022 at 22:59):

also, what language was lean originally implemented in?

Mario Carneiro (Jan 14 2022 at 22:59):

C++

crab (Jan 14 2022 at 22:59):

Mario Carneiro said:

C++

why tho lol

Mario Carneiro (Jan 14 2022 at 23:00):

because leo knows C++ really well

crab (Jan 14 2022 at 23:00):

i would think that it was implementedin haskell or some functional lang

Mario Carneiro (Jan 14 2022 at 23:00):

They certainly felt the pain, that's why they rewrote it in some functional lang

Mario Carneiro (Jan 14 2022 at 23:00):

namely lean

crab (Jan 14 2022 at 23:00):

lean lol

Mario Carneiro (Jan 14 2022 at 23:01):

but it's hard to get the performance characteristics you want with functional languages

crab (Jan 14 2022 at 23:02):

i thought it is said that the programming language you use to make the compiler in doesnt really affect the speed

Mario Carneiro (Jan 14 2022 at 23:02):

lean 3 is being used in a very computationally heavy way, I can't imagine how many more CPU hours we would have burned on mathlib if the elaborator was less efficient

crab (Jan 14 2022 at 23:02):

i feel like rust is going to take over c++ for lang dev imo

Mario Carneiro (Jan 14 2022 at 23:02):

The programming language you use to make the compiler certainly affects the speed of the compiler

crab (Jan 14 2022 at 23:03):

c++ doesnt even have pattern matching

Mario Carneiro (Jan 14 2022 at 23:03):

and in theorem proving you spend all your time in "compilation"

Eric Wieser (Jan 14 2022 at 23:05):

(I split this thread in case anyone has something to add to the logo conversation which we seem to have diverted from)

crab (Jan 14 2022 at 23:06):

Mario Carneiro said:

The programming language you use to make the compiler certainly affects the speed of the compiler

well, maybe the first implementation. for instance, rust was originally written in ocaml, but then rewritten in rust, and is now one of the fastest langs

crab (Jan 14 2022 at 23:07):

explain that

Mario Carneiro (Jan 14 2022 at 23:08):

Well, lean hasn't been self hosting prior to lean 4

Mario Carneiro (Jan 14 2022 at 23:10):

plus, that's only a good strategy for improving the compiler if your programming language is actually faster than the original language. Rust can definitely beat OCaml in some domains. I think it will be hard for Lean to compete with C++ on speed, but certainly there are some aspects that were being done inefficiently in C++ just because the setup is so much boilerplate work (e.g. everything was an expr because making inductive types in C++ is incredibly painful)

crab (Jan 14 2022 at 23:13):

im just showing

crab (Jan 14 2022 at 23:14):

that the programing lang you use doesnt affect the speed of the compiler nessacerily

Mario Carneiro (Jan 14 2022 at 23:14):

For a self hosting compiler, the speed of the compiler depends on how good it is. Good compilers are a ton of work

crab (Jan 14 2022 at 23:15):

right

crab (Jan 14 2022 at 23:15):

that is what matters

crab (Jan 14 2022 at 23:15):

rust was a good compiler

Mario Carneiro (Jan 14 2022 at 23:15):

Rust eventually became a good compiler after a ton of work

Mario Carneiro (Jan 14 2022 at 23:15):

Every compiler is born crappy

Mario Carneiro (Jan 14 2022 at 23:16):

and it's really hard to compete with e.g. LLVM, which is why even rust doesn't go there

crab (Jan 14 2022 at 23:17):

Mario Carneiro said:

Every compiler is born crappy

im gonna be honest, when rust first started, it was shitty like hell

Mario Carneiro (Jan 14 2022 at 23:18):

You realize that there is 1 or 2 orders of magnitude between the rust community and the lean community, right?

crab (Jan 14 2022 at 23:18):

im not saying lean is shitty

Mario Carneiro (Jan 14 2022 at 23:19):

We're doing our best to scale up but all theorem prover langs are in the rounding error compared to regular programming languages

crab (Jan 14 2022 at 23:21):

tbh, the rust community is really huge

Mario Carneiro (Jan 14 2022 at 23:22):

I don't think that speed is the main reason for self-hosting lean 4. It's more about the expressiveness and enabling user code to interact directly with the elaborator

Mario Carneiro (Jan 14 2022 at 23:25):

It's going to hugely speed up mathlib compilation, but that's because we're able to compile tactics now. It was too much work and too organizationally complicated to write tactics in C++, so most tactics were written in lean and interpreted. So Lean 4 is competing with (and beating the pants off) the lean 3 interpreter, not C++

Kyle Miller (Jan 14 2022 at 23:26):

It also opens up being able to give Lean proofs that different parts of Lean written in Lean operate correctly, which is cool (at least in theory -- don't know if anyone is planning on doing this).

Mario Carneiro (Jan 14 2022 at 23:29):

I think there are still a number of challenges to solve before that becomes theoretically possible. Most of the elaborator is in a lifted IO monad

Mario Carneiro (Jan 14 2022 at 23:29):

and partial and extern make everything interesting

Mario Carneiro (Jan 14 2022 at 23:31):

but hats off to the lean team for making almost everything be non-unsafe, so at least it's logically consistent for those functions to exist

Mario Carneiro (Jan 14 2022 at 23:32):

by contrast to lean 3 where everything is meta (= unsafe)


Last updated: Dec 20 2023 at 11:08 UTC