Convert Figma logo to code with AI

leanprover logolean4

Lean 4 programming language and theorem prover

4,597
407
4,597
755

Top Related Projects

4,883

Coq is a formal proof management system. It provides a formal language to write mathematical definitions, executable algorithms and theorems together with an environment for semi-interactive development of machine-checked proofs.

2,490

Agda is a dependently typed programming language / interactive theorem prover.

2,540

A purely functional programming language with first class types

A Coq library for Homotopy Type Theory

Quick Overview

Lean 4 is an open-source theorem prover and programming language developed by Microsoft Research and the Lean community. It combines powerful automation with expressive logic, allowing users to write and verify mathematical proofs as well as develop correct-by-construction software.

Pros

  • Powerful theorem proving capabilities with a strong type system
  • Supports both interactive and automated theorem proving
  • Integrates well with software development practices
  • Active and growing community with extensive documentation

Cons

  • Steep learning curve for those new to formal verification
  • Limited ecosystem compared to more established programming languages
  • Performance can be slower compared to traditional programming languages
  • May require significant effort to formalize complex mathematical concepts

Code Examples

  1. Defining a simple function:
def add (a b : Nat) : Nat :=
  a + b

#eval add 3 5 -- Output: 8
  1. Proving a simple theorem:
theorem add_comm (a b : Nat) : add a b = add b a := by
  simp [add]
  rw [Nat.add_comm]
  1. Defining an inductive type:
inductive BinTree (α : Type)
  | leaf : BinTree α
  | node : BinTree α → α → BinTree α → BinTree α

def BinTree.size {α : Type} : BinTree α → Nat
  | leaf => 0
  | node l _ r => l.size + r.size + 1

Getting Started

  1. Install Lean 4:

    curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh
    
  2. Create a new Lean project:

    mkdir my_project
    cd my_project
    lake init my_project
    
  3. Open Main.lean in your preferred editor with Lean support (e.g., VS Code with the Lean 4 extension).

  4. Start writing Lean code and theorems in Main.lean.

Competitor Comparisons

4,883

Coq is a formal proof management system. It provides a formal language to write mathematical definitions, executable algorithms and theorems together with an environment for semi-interactive development of machine-checked proofs.

Pros of Coq

  • Longer history and more established ecosystem
  • Larger community and more extensive libraries
  • More powerful and flexible tactics system

Cons of Coq

  • Steeper learning curve for beginners
  • Less focus on automation and performance
  • Slower development pace compared to Lean 4

Code Comparison

Coq example:

Theorem add_comm : forall n m : nat,
  n + m = m + n.
Proof.
  intros n m. induction n as [| n' IHn'].
  - simpl. rewrite -> plus_n_O. reflexivity.
  - simpl. rewrite -> IHn'. rewrite -> plus_n_Sm. reflexivity.
Qed.

Lean 4 example:

theorem add_comm (n m : Nat) : n + m = m + n := by
  induction n with
  | zero => simp
  | succ n ih => simp [ih, Nat.add_succ]

Both examples prove the commutativity of addition for natural numbers. Coq's proof is more verbose and uses tactics explicitly, while Lean 4's proof is more concise and leverages its automation capabilities.

2,490

Agda is a dependently typed programming language / interactive theorem prover.

Pros of Agda

  • More established and mature project with a longer history
  • Stronger focus on dependent types and type theory research
  • Larger community and ecosystem of libraries

Cons of Agda

  • Steeper learning curve for beginners
  • Less emphasis on automation and proof tactics
  • Slower compilation times for large projects

Code Comparison

Agda example:

data ℕ : Set where
  zero : ℕ
  suc  : ℕ → ℕ

_+_ : ℕ → ℕ → ℕ
zero  + n = n
suc m + n = suc (m + n)

Lean4 example:

inductive Nat where
  | zero : Nat
  | succ : Nat → Nat

def add : Nat → Nat → Nat
  | Nat.zero, n => n
  | Nat.succ m, n => Nat.succ (add m n)

Both examples define natural numbers and addition, but Lean4's syntax is more similar to traditional functional programming languages, potentially making it more accessible to newcomers from that background. Agda's syntax is more closely aligned with type theory notation, which may be preferred by those with a strong theoretical background.

2,540

A purely functional programming language with first class types

Pros of Idris2

  • More mature implementation of dependent types, offering advanced features like uniqueness types and quantitative type theory
  • Stronger focus on general-purpose programming, with better support for I/O and effects
  • More extensive standard library and ecosystem for practical development

Cons of Idris2

  • Smaller community and less industry adoption compared to Lean4
  • Slower compilation times and less optimized runtime performance
  • Less emphasis on formal mathematics and theorem proving capabilities

Code Comparison

Idris2:

data Vec : Nat -> Type -> Type where
  Nil  : Vec Z a
  (::) : a -> Vec n a -> Vec (S n) a

append : Vec n a -> Vec m a -> Vec (n + m) a
append Nil ys = ys
append (x :: xs) ys = x :: append xs ys

Lean4:

inductive Vec (α : Type u) : Nat → Type u
  | nil : Vec α 0
  | cons : α → {n : Nat} → Vec α n → Vec α (n + 1)

def append : {n m : Nat} → Vec α n → Vec α m → Vec α (n + m)
  | [], ys => ys
  | x::xs, ys => x :: append xs ys

Both examples demonstrate vector concatenation with length-indexed vectors, showcasing similar syntax and dependent type usage.

A Coq library for Homotopy Type Theory

Pros of Coq-HoTT

  • Built on the well-established Coq proof assistant, benefiting from its mature ecosystem and extensive libraries
  • Focuses specifically on Homotopy Type Theory (HoTT), providing specialized tools and axioms for this area of mathematics
  • Has a larger community of contributors and users in the HoTT space

Cons of Coq-HoTT

  • Less modern syntax compared to Lean4, which can be more verbose and harder to read
  • Slower compilation times and potentially less efficient code generation
  • Limited support for metaprogramming compared to Lean4's powerful metaprogramming capabilities

Code Comparison

Coq-HoTT:

Definition compose {A B C : Type} (g : B -> C) (f : A -> B) :=
  fun x : A => g (f x).

Lean4:

def compose {α β γ : Type} (g : β → γ) (f : α → β) : α → γ :=
  fun x => g (f x)

Both examples define function composition, but Lean4's syntax is more concise and closer to mathematical notation. Lean4 also uses Unicode characters for Greek letters, which can improve readability for some users.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

This is the repository for Lean 4.

About

Installation

See Setting Up Lean.

Contributing

Please read our Contribution Guidelines first.

Building from Source

See Building Lean (documentation source: doc/make/index.md).