Top Related Projects
Lean 4 programming language and theorem prover
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.
Agda is a dependently typed programming language / interactive theorem prover.
A purely functional programming language with first class types
A Coq library for Homotopy Type Theory
Quick Overview
Lean3 is an open-source theorem prover and programming language developed by Microsoft Research. It is designed for writing formal proofs and programs, combining powerful automation with expressive logic. Lean3 aims to bridge the gap between interactive and automated theorem proving.
Pros
- Powerful type system that supports dependent types and inductive definitions
- Strong automation capabilities for proof assistance
- Active community and extensive library of mathematical theorems
- Seamless integration of programming and proving
Cons
- Steep learning curve for users new to formal verification
- Limited documentation compared to more established theorem provers
- Performance can be slow for complex proofs
- Smaller ecosystem compared to some other proof assistants
Code Examples
- Defining a simple function:
def add_one (n : ℕ) : ℕ := n + 1
#eval add_one 5 -- Output: 6
- Proving a simple theorem:
theorem add_comm (a b : ℕ) : a + b = b + a :=
begin
induction b with d hd,
{ rw [nat.add_zero, nat.zero_add] },
{ rw [nat.add_succ, hd, nat.succ_add] }
end
- Defining an inductive type:
inductive binary_tree (α : Type)
| leaf : binary_tree
| node : α → binary_tree → binary_tree → binary_tree
#check binary_tree.node 5 (binary_tree.leaf) (binary_tree.leaf)
Getting Started
To get started with Lean3:
- Install Lean3 following the instructions at https://leanprover-community.github.io/get_started.html
- Create a new
.lean
file and open it in your preferred editor with Lean support - Begin with a simple example:
import data.nat.basic
def hello_world : string := "Hello, Lean!"
#eval hello_world
theorem two_plus_two : 2 + 2 = 4 :=
begin
reflexivity,
end
- Use
#eval
to evaluate expressions and#check
to inspect types - Explore the Lean community resources and documentation for more advanced topics
Competitor Comparisons
Lean 4 programming language and theorem prover
Pros of Lean4
- Improved performance and compilation speed
- Enhanced metaprogramming capabilities
- More user-friendly syntax and improved error messages
Cons of Lean4
- Less mature ecosystem and library support
- Potential compatibility issues with existing Lean3 projects
- Steeper learning curve for users familiar with Lean3
Code Comparison
Lean3
def factorial : ℕ → ℕ
| 0 := 1
| (n+1) := (n+1) * factorial n
#eval factorial 5
Lean4
def factorial : Nat → Nat
| 0 => 1
| n+1 => (n+1) * factorial n
#eval factorial 5
The code examples demonstrate the syntax differences between Lean3 and Lean4. Lean4 uses =>
instead of :=
for function definitions and pattern matching. Additionally, Lean4 has a more streamlined syntax for recursive functions.
Lean4 represents a significant evolution from Lean3, offering improved performance and metaprogramming capabilities. However, it may require some adjustment for users accustomed to Lean3, and the ecosystem is still developing. The choice between Lean3 and Lean4 depends on project requirements and familiarity with each version.
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
- Larger and more established community with extensive libraries
- More mature ecosystem with a wider range of tools and plugins
- Better documentation and learning resources available
Cons of Coq
- Steeper learning curve, especially for beginners
- Less focus on automation compared to Lean
- Slower compilation times for large projects
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.
Lean3 example:
theorem add_comm (n m : ℕ) : n + m = m + n :=
begin
induction n with n' ih,
{ simp },
{ simp [ih, nat.add_succ, nat.succ_add] }
end
Both examples prove the commutativity of addition for natural numbers. Coq's syntax is more verbose, while Lean3's is more concise. Lean3's simp
tactic provides more automation, reducing the proof steps needed.
Agda is a dependently typed programming language / interactive theorem prover.
Pros of Agda
- More mature and established project with a longer history
- Larger community and ecosystem of libraries
- More flexible syntax and notation capabilities
Cons of Agda
- Steeper learning curve for beginners
- Slower compilation times for large projects
- Less focus on automation and proof tactics
Code Comparison
Agda example:
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
Lean3 example:
inductive nat : Type
| 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 Agda's syntax is more concise and allows for custom operators. Lean3's syntax is more verbose but may be more familiar to programmers from other languages. Agda's flexibility in notation can lead to more readable code in complex proofs, while Lean3's consistency can be beneficial for larger projects and collaboration.
A purely functional programming language with first class types
Pros of Idris2
- More advanced dependent types system, allowing for more expressive proofs and specifications
- Self-hosted implementation, written in Idris itself, which demonstrates the language's capabilities
- Stronger focus on general-purpose programming and practical applications
Cons of Idris2
- Smaller community and ecosystem compared to Lean3
- Less emphasis on mathematical formalization and theorem proving
- Potentially steeper learning curve for programmers new to dependent types
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
Lean3:
inductive vector (α : Type u) : nat → Type u
| nil : vector α 0
| cons : Π {n : nat}, α → vector α n → vector α (n+1)
def append {α : Type u} {n m : nat} :
vector α n → vector α m → vector α (n + m)
| vector.nil v := v
| (vector.cons h t) v := vector.cons h (append t v)
Both examples demonstrate vector concatenation with length preservation, showcasing the dependent type systems in each language. Idris2's syntax is generally more concise, while Lean3's approach is more explicit in type annotations.
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
- Offers a more comprehensive implementation of HoTT concepts compared to Lean3
Cons of Coq-HoTT
- Steeper learning curve due to Coq's syntax and the complexity of HoTT concepts
- Less active development and smaller community compared to Lean3
- May be less suitable for general-purpose theorem proving outside of HoTT
Code Comparison
Coq-HoTT:
Definition funext :=
forall (A B : Type) (f g : A -> B),
(forall x : A, f x = g x) -> f = g.
Lean3:
axiom funext {α : Sort u} {β : α → Sort v} {f g : Π (x : α), β x} :
(∀ (x : α), f x = g x) → f = g
Both examples define function extensionality, but Coq-HoTT uses Coq's syntax while Lean3 uses its own notation. Lean3's version is more concise and uses unicode symbols, which some users find more readable.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
This repository has been frozen. Lean 4 is now the official release.
About
Installation
Stable and nightly binary releases of Lean are available on the homepage. For building Lean from source, see the build instructions.
Top Related Projects
Lean 4 programming language and theorem prover
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.
Agda is a dependently typed programming language / interactive theorem prover.
A purely functional programming language with first class types
A Coq library for Homotopy Type Theory
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot