Lean 4: State of the Sebastian Ullrich Ullrich - Lean 4: State of - - PowerPoint PPT Presentation

lean 4 state of the
SMART_READER_LITE
LIVE PREVIEW

Lean 4: State of the Sebastian Ullrich Ullrich - Lean 4: State of - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

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)

fjrst offjcial release fjxed tactic language

Lean 3 (2017)

make Lean a meta-programming language: build tactics in Lean backed by a bytecode interpreter

Lean 4 (201X)

make Lean a general-purpose language: native back end, FFI, ... reimplement Lean in Lean

X 10

slide-3
SLIDE 3

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)

fjrst offjcial release fjxed tactic language

Lean 3 (2017)

make Lean a meta-programming language: build tactics in Lean backed by a bytecode interpreter

Lean 4 (201X)

make Lean a general-purpose language: native back end, FFI, ... reimplement Lean in Lean

X ≥ 10

slide-4
SLIDE 4

The Lean dream team

3

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

Leonardo de Moura: everything, really Sebastian Ullrich: macros, interpreter Daniel Selsam: new typeclass resolution Simon Hudon: language server

slide-5
SLIDE 5

The Lean dream team

3

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

Leonardo de Moura: everything, really Sebastian Ullrich: macros, interpreter Daniel Selsam: new typeclass resolution Simon Hudon: language server

slide-6
SLIDE 6

The Lean dream team

3

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

Leonardo de Moura: everything, really Sebastian Ullrich: macros, interpreter Daniel Selsam: new typeclass resolution Simon Hudon: language server

slide-7
SLIDE 7

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 framework module system meta monad typeclass resolution macro expander FFI C++ Lean

  • ther
slide-8
SLIDE 8

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 framework module system meta monad typeclass resolution macro hygiene FFI C++ Lean

  • ther
slide-9
SLIDE 9

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 framework module system meta monad typeclass resolution macro hygiene FFI interpreter C++ Lean

  • ther
slide-10
SLIDE 10

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 framework module system meta monad typeclass resolution macro hygiene FFI interpreter C++ Lean

  • ther
slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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

slide-15
SLIDE 15

Compiler

6

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

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

slide-16
SLIDE 16

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 runtime cycles 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

slide-17
SLIDE 17

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 runtime cycles 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

slide-18
SLIDE 18

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 runtime cycles 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

slide-19
SLIDE 19

State of the ⋃

8

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

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

slide-20
SLIDE 20

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 ':='

slide-21
SLIDE 21

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
slide-22
SLIDE 22

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!
slide-23
SLIDE 23

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!
slide-24
SLIDE 24

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))

slide-25
SLIDE 25

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))

slide-26
SLIDE 26

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))

slide-27
SLIDE 27

Thoughts about eventual porting of Lean 3 code

9

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

syntax changes: mostly superfjcial, automatable One possible path: Incrementally reimplement Lean 3 syntax as macros fjrst, then unfold them as fjnal step

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

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

but not necessarily in the stdlib

slide-28
SLIDE 28

Thoughts about eventual porting of Lean 3 code

9

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

syntax changes: mostly superfjcial, automatable One possible path: Incrementally reimplement Lean 3 syntax as macros fjrst, then unfold them as fjnal step

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

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

but not necessarily in the stdlib

slide-29
SLIDE 29

Thoughts about eventual porting of Lean 3 code

9

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

syntax changes: mostly superfjcial, automatable One possible path: Incrementally reimplement Lean 3 syntax as macros fjrst, then unfold them as fjnal step

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

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

but not necessarily in the stdlib

slide-30
SLIDE 30

Thoughts about eventual porting of Lean 3 code

9

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

syntax changes: mostly superfjcial, automatable One possible path: Incrementally reimplement Lean 3 syntax as macros fjrst, then unfold them as fjnal step

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

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

but not necessarily in the stdlib