Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09...

30
1 2020/01/09 Ullrich - Lean 4: State of the IPD Snelting Programming paradigms group - IPD Snelting Lean 4: State of the Sebastian Ullrich KIT – The Research University in the Helmholtz Association www.kit.edu

Transcript of Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09...

Page 1: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

1 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Programming paradigms group - IPD Snelting

Lean 4: State of the ⋃

Sebastian Ullrich

KIT – The Research University in the Helmholtz Association www.kit.edu

Page 2: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

A brief history of Lean

2 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Lean 0.1 (2014)Lean 2 (2015)

first official releasefixed tactic language

Lean 3 (2017)make Lean a meta-programming language: build tactics in Leanbacked by a bytecode interpreter

Lean 4 (201X)make Lean a general-purpose language: native back end, FFI, ...reimplement Lean in Lean

X ≥ 10

Page 3: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

A brief history of Lean

2 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Lean 0.1 (2014)Lean 2 (2015)

first official releasefixed tactic language

Lean 3 (2017)make Lean a meta-programming language: build tactics in Leanbacked by a bytecode interpreter

Lean 4 (201X)make Lean a general-purpose language: native back end, FFI, ...reimplement Lean in Lean

X ≥ 10

Page 4: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

The Lean dream team

3 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Leonardo de Moura: everything, reallySebastian Ullrich: macros, interpreter

Daniel Selsam: new typeclass resolutionSimon Hudon: language server

Page 5: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

The Lean dream team

3 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Leonardo de Moura: everything, reallySebastian Ullrich: macros, interpreterDaniel Selsam: new typeclass resolution

Simon Hudon: language server

Page 6: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

The Lean dream team

3 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Leonardo de Moura: everything, reallySebastian Ullrich: macros, interpreterDaniel Selsam: new typeclass resolutionSimon Hudon: language server

Page 7: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Lean 4 progress: Jan 2019

4 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

editor

language server

parser

elaborator

kernel compiler

tactic frameworkmodule system

meta monad

typeclass resolution

macro expander

FFI

C++

Lean

other

Page 8: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Lean 4 progress: Jun 2019

4 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

editor

language server

parser

elaborator

kernel compiler

tactic frameworkmodule system

meta monad

typeclass resolution

macro hygiene

FFI

C++

Lean

other

Page 9: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Lean 4 progress: Dec 2019

4 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

editor

language server

parser

elaborator

kernel compiler

tactic frameworkmodule system

meta monad

typeclass resolution

macro hygiene

FFI interpreter

C++

Lean

other

Page 10: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Lean 4 progress: Jan 2020

4 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

editor

language server

parser

elaborator

kernel compiler

tactic frameworkmodule system

meta monad

typeclass resolution

macro hygiene

FFI interpreter

C++

Lean

other

Page 11: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Cosmetics

5 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Minor syntax changes to make Lean a more consistent and pleasant language

naming convention: TypeName, ModuleName, termName

lemma convention termName_property_of_assumption?consistent pattern syntax

def hiThere : ...

| pat1, ... => ...

| ...

match ... with

| pat1, ... => ...

| ...

etc...

fun x =>

let y := 1;

do a; b

Page 12: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Cosmetics

5 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Minor syntax changes to make Lean a more consistent and pleasant language

naming convention: TypeName, ModuleName, termName

lemma convention termName_property_of_assumption?

consistent pattern syntax

def hiThere : ...

| pat1, ... => ...

| ...

match ... with

| pat1, ... => ...

| ...

etc...

fun x =>

let y := 1;

do a; b

Page 13: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Cosmetics

5 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Minor syntax changes to make Lean a more consistent and pleasant language

naming convention: TypeName, ModuleName, termName

lemma convention termName_property_of_assumption?consistent pattern syntax

def hiThere : ...

| pat1, ... => ...

| ...

match ... with

| pat1, ... => ...

| ...

etc...

fun x =>

let y := 1;

do a; b

Page 14: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Cosmetics

5 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Minor syntax changes to make Lean a more consistent and pleasant language

naming convention: TypeName, ModuleName, termName

lemma convention termName_property_of_assumption?consistent pattern syntax

def hiThere : ...

| pat1, ... => ...

| ...

match ... with

| pat1, ... => ...

| ...

etc...

fun x =>

let y := 1;

do a; b

Page 15: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Compiler

6 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Ullrich and de Moura. Counting Immutable Beans: Reference CountingOptimized for Purely Functional Programming. IFL’19.

Page 16: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

New typeclass resolution

7 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Performance issues with the old implementation:diamonds can lead to exponential runtimecycles can lead to nontermination

Typeclass resolution follows a “Prolog-like search”⇒ adapt known Prolog optimization, tabled resolution, to Lean!

Guarantees termination if size of typeclass problems is bounded

Page 17: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

New typeclass resolution

7 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Performance issues with the old implementation:diamonds can lead to exponential runtimecycles can lead to nontermination

Typeclass resolution follows a “Prolog-like search”

⇒ adapt known Prolog optimization, tabled resolution, to Lean!

Guarantees termination if size of typeclass problems is bounded

Page 18: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

New typeclass resolution

7 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

Performance issues with the old implementation:diamonds can lead to exponential runtimecycles can lead to nontermination

Typeclass resolution follows a “Prolog-like search”⇒ adapt known Prolog optimization, tabled resolution, to Lean!

Guarantees termination if size of typeclass problems is bounded

Page 19: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

notation "⋃ " binders ", " r:(scoped f, Union f) := r

Page 20: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

notation "⋃ " binders ", " r:(scoped f, Union f) := r

expected ':='

Page 21: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

notation "⋃ " b ", " r := Union (fun b => r)

#check ⋃ x, x = x

#check ⋃ (x : Set Unit), x = x

#check ⋃ x ∈ univ, x = x -- error

Page 22: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

notation "⋃ " b ", " r := Union {b | r}

#check ⋃ x, x = x

#check ⋃ (x : Set Unit), x = x

#check ⋃ x ∈ univ, x = x -- works!

Page 23: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax "⋃ " term ", " term : term

macro `(⋃ $b, $r) => `(Union {$b | $r})

#check ⋃ x, x = x

#check ⋃ (x : Set Unit), x = x

#check ⋃ x ∈ univ, x = x -- works!

Page 24: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax "⋃ " term ", " term : term

macro `(⋃ $b, $r) => `(Union {$b | $r})

#check ⋃ x, x = x

#check ⋃ (x : Set Unit), x = x

#check ⋃ x ∈ univ, x = x -- works!

syntax "{" term " | " term "}" : term

macro

| `({$x ∈ $s | $p}) => `(setOf (fun $x => $x ∈ $s ∧ $p))

| `({$x ≤ $e | $p}) => `(setOf (fun $x => $x ≤ $e ∧ $p))

| `({$b | $r}) => `(setOf (fun $b => $r))

Page 25: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax "⋃ " setIdx ", " term : term

macro `(⋃ $b, $r) => `(Union {$b | $r})

#check ⋃ x, x = x

#check ⋃ x : Set Unit, x = x -- works!

#check ⋃ x ∈ univ, x = x

syntax "{" term " | " term "}" : term

macro

| `({$x ∈ $s | $p}) => `(setOf (fun $x => $x ∈ $s ∧ $p))

| `({$x ≤ $e | $p}) => `(setOf (fun $x => $x ≤ $e ∧ $p))

| `({$b | $r}) => `(setOf (fun $b => $r))

Page 26: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

State of the ⋃

8 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax "⋃ " setIdx ", " term : term

macro `(⋃ $b, $r) => `(Union {$b | $r})

#check ⋃ x, x = x

#check ⋃ x : Set Unit, x = x -- works!

#check ⋃ x ∈ univ, x = x

declare_syntax_cat setIdx

syntax term : setIdx

syntax ident " : " term : setIdx

syntax "{" setIdx " | " term "}" : term

macro

| `({$x ∈ $s | $p}) => `(setOf (fun $x => $x ∈ $s ∧ $p))

| `({$x ≤ $e | $p}) => `(setOf (fun $x => $x ≤ $e ∧ $p))

| `({$x : $t | $r}) => `(setOf (fun ($x : $t) => $r))

| `({$b | $r}) => `(setOf (fun $b => $r))

Page 27: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Thoughts about eventual porting of Lean 3 code

9 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax changes: mostly superficial, automatable

One possible path: Incrementally reimplement Lean 3 syntax as macrosfirst, then unfold them as final step

$ lean --plugin lean3-compat mathlib/src/...

elaborator changes: probably not too drasticlibrary changes: mostly missing API, needs to be reimplemented

but not necessarily in the stdlib

Page 28: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Thoughts about eventual porting of Lean 3 code

9 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax changes: mostly superficial, automatableOne possible path: Incrementally reimplement Lean 3 syntax as macrosfirst, then unfold them as final step

$ lean --plugin lean3-compat mathlib/src/...

elaborator changes: probably not too drasticlibrary changes: mostly missing API, needs to be reimplemented

but not necessarily in the stdlib

Page 29: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Thoughts about eventual porting of Lean 3 code

9 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax changes: mostly superficial, automatableOne possible path: Incrementally reimplement Lean 3 syntax as macrosfirst, then unfold them as final step

$ lean --plugin lean3-compat mathlib/src/...

elaborator changes: probably not too drastic

library changes: mostly missing API, needs to be reimplementedbut not necessarily in the stdlib

Page 30: Lean 4: State of the â - Sebastian Ullrich · AbriefhistoryofLean 2 2020/01/09 Ullrich-Lean4:Stateofthe⋃ IPDSnelting KIT Lean0.1(2014) Lean2(2015) firstofficialrelease fixedtacticlanguage

Thoughts about eventual porting of Lean 3 code

9 2020/01/09 Ullrich - Lean 4: State of the ⋃ IPD Snelting

KIT

syntax changes: mostly superficial, automatableOne possible path: Incrementally reimplement Lean 3 syntax as macrosfirst, then unfold them as final step

$ lean --plugin lean3-compat mathlib/src/...

elaborator changes: probably not too drasticlibrary changes: mostly missing API, needs to be reimplemented

but not necessarily in the stdlib