<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=Lean_theorem_prover%2FExplainers%2FA_library_of_mathematics</id>
	<title>Lean theorem prover/Explainers/A library of mathematics - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://invarians.org/index.php?action=history&amp;feed=atom&amp;title=Lean_theorem_prover%2FExplainers%2FA_library_of_mathematics"/>
	<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=Lean_theorem_prover/Explainers/A_library_of_mathematics&amp;action=history"/>
	<updated>2026-10-21T08:25:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://invarians.org/index.php?title=Lean_theorem_prover/Explainers/A_library_of_mathematics&amp;diff=6772&amp;oldid=prev</id>
		<title>PMA Publisher: Published from the Principia Machina source</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=Lean_theorem_prover/Explainers/A_library_of_mathematics&amp;diff=6772&amp;oldid=prev"/>
		<updated>2026-10-15T19:34:43Z</updated>

		<summary type="html">&lt;p&gt;Published from the Principia Machina source&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:34, 15 October 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{DISPLAYTITLE:A library of mathematics}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{DISPLAYTITLE:A library of mathematics}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Technical|Lean theorem prover/System/Type classes and instance resolution|Lean theorem prover/System/Lake and Lean projects}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Technical|Lean theorem prover/System/Type classes and instance resolution|Lean theorem prover/System/Lake and Lean projects}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Lean theorem prover map}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A proof assistant without a library can prove only what someone has first defined from nothing.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A proof assistant without a library can prove only what someone has first defined from nothing.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pma_cutover_20261020t051351z-soft_:diff:1.41:old-6565:rev-6772:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>PMA Publisher</name></author>
	</entry>
	<entry>
		<id>https://invarians.org/index.php?title=Lean_theorem_prover/Explainers/A_library_of_mathematics&amp;diff=6565&amp;oldid=prev</id>
		<title>PMA Publisher: Published from the Principia Machina source</title>
		<link rel="alternate" type="text/html" href="https://invarians.org/index.php?title=Lean_theorem_prover/Explainers/A_library_of_mathematics&amp;diff=6565&amp;oldid=prev"/>
		<updated>2026-10-14T18:00:56Z</updated>

		<summary type="html">&lt;p&gt;Published from the Principia Machina source&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:A library of mathematics}}&lt;br /&gt;
{{Technical|Lean theorem prover/System/Type classes and instance resolution|Lean theorem prover/System/Lake and Lean projects}}&lt;br /&gt;
&lt;br /&gt;
A proof assistant without a library can prove only what someone has first defined from nothing.&lt;br /&gt;
This page describes what Lean users build on: the libraries that come with Lean, and Mathlib, the&lt;br /&gt;
community&amp;#039;s library of mathematics. It says what Mathlib is, how it grows, how changes to it are&lt;br /&gt;
reviewed, how it is organised, and how a project obtains it.&lt;br /&gt;
&lt;br /&gt;
== What comes with Lean ==&lt;br /&gt;
&lt;br /&gt;
Lean arrives with a core library: natural numbers, integers, lists, arrays, strings, and the&lt;br /&gt;
logic and tactics used throughout this edition. It also ships a library named &amp;lt;code&amp;gt;Std&amp;lt;/code&amp;gt;,&lt;br /&gt;
with data structures for programs, such as the lookup table &amp;lt;code&amp;gt;Std.HashMap&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;lean&amp;quot; style=&amp;quot;background: #f8f9fa; border: 1px solid #c8ccd1; padding: 0.6em; margin: 0.3em 0; font-size: 0.85em; line-height: 1.35; overflow-x: auto; white-space: pre;&amp;quot;&amp;gt;&lt;br /&gt;
import Std.Data.HashMap&lt;br /&gt;
&lt;br /&gt;
#eval ((∅ : Std.HashMap String Nat).insert &amp;quot;one&amp;quot; 1).get? &amp;quot;one&amp;quot;&lt;br /&gt;
#eval [3, 1, 2].reverse&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lean 4.34.1 prints &amp;lt;code&amp;gt;some 1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;[2, 1, 3]&amp;lt;/code&amp;gt;. A further community library,&lt;br /&gt;
Batteries, describes itself as the &amp;quot;batteries included&amp;quot; extended library for Lean 4, with data&lt;br /&gt;
structures and tactics for both programming and mathematics.&amp;lt;ref name=&amp;quot;batteries&amp;quot;&amp;gt;&amp;#039;&amp;#039;Batteries&amp;#039;&amp;#039; (README). [https://github.com/leanprover-community/batteries github.com/leanprover-community/batteries], consulted 14 October 2026.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What core Lean does not have is most of mathematics. It does not even have the real numbers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;lean lean-fails&amp;quot; style=&amp;quot;background: #f8f9fa; border: 1px solid #c8ccd1; padding: 0.6em; margin: 0.3em 0; font-size: 0.85em; line-height: 1.35; overflow-x: auto; white-space: pre;&amp;quot;&amp;gt;&lt;br /&gt;
#check Real&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lean answers: Unknown identifier `Real`. The real numbers, and almost everything built on them,&lt;br /&gt;
come from Mathlib.&lt;br /&gt;
&lt;br /&gt;
== Mathlib ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Mathlib&amp;#039;&amp;#039;&amp;#039; is a single, unified library of mathematics formalised in Lean, built by a community&lt;br /&gt;
rather than by one research group. A paper of 2020 describing it, written by &amp;quot;the mathlib Community&amp;quot;, stressed&lt;br /&gt;
its focus on classical mathematics, its large hierarchy of mathematical structures, and its&lt;br /&gt;
distributed organisation.&amp;lt;ref name=&amp;quot;cpp2020&amp;quot;&amp;gt;The mathlib Community, &amp;quot;The Lean mathematical library&amp;quot;, in &amp;#039;&amp;#039;Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP 2020)&amp;#039;&amp;#039;, ACM, 2020, pp. 367–381. [https://doi.org/10.1145/3372885.3373824 doi:10.1145/3372885.3373824]; also arXiv:1910.09336.&amp;lt;/ref&amp;gt;&lt;br /&gt;
It was begun in 2017.&amp;lt;ref name=&amp;quot;growing&amp;quot;&amp;gt;Anne Baanen, Matthew R. Ballard, Johan Commelin, Bryan Gin-ge Chen, Michael Rothgang and Damiano Testa, &amp;quot;Growing Mathlib: maintenance of a large scale mathematical library&amp;quot;, arXiv:2508.21593, version 2, 7 October 2025; to appear at the Conference on Intelligent Computer Mathematics (CICM) 2025. [https://arxiv.org/abs/2508.21593 arxiv.org/abs/2508.21593]&amp;lt;/ref&amp;gt;&lt;br /&gt;
It was first written for Lean 3 and later translated to Lean 4 (see&lt;br /&gt;
[[Lean theorem prover/History/Mathlib and its community|Mathlib and its community]]).&lt;br /&gt;
&lt;br /&gt;
Its size has been reported at several dates, each counted in its own way:&lt;br /&gt;
&lt;br /&gt;
* in the 2020 paper (figures of 2019): 140,000 lines of code, not counting blank lines and comments, from 73 contributors, with 11 maintainers;&amp;lt;ref name=&amp;quot;cpp2020&amp;quot; /&amp;gt;&lt;br /&gt;
* in a paper of 2025 on Mathlib&amp;#039;s maintenance: 1.9 million lines of code, with about 30 maintainers;&amp;lt;ref name=&amp;quot;growing&amp;quot; /&amp;gt;&lt;br /&gt;
* on the community&amp;#039;s statistics page, consulted on 14 October 2026: 137,993 definitions, 290,354 theorems and 772 contributors.&amp;lt;ref name=&amp;quot;stats&amp;quot;&amp;gt;Lean community, &amp;quot;Mathlib statistics&amp;quot;. [https://leanprover-community.github.io/mathlib_stats.html leanprover-community.github.io/mathlib_stats.html], consulted 14 October 2026.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The 2020 paper gives a reason, drawn from mathematics itself, for one library rather than&lt;br /&gt;
many: its topics are intertwined, and rather than each building a separate project on a small common core,&lt;br /&gt;
the mathematicians involved joined their work to each other&amp;#039;s and to Mathlib.&amp;lt;ref name=&amp;quot;cpp2020&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How changes are reviewed ==&lt;br /&gt;
&lt;br /&gt;
Anyone may propose a change to Mathlib, and everyone is allowed, and encouraged, to review the&lt;br /&gt;
changes others propose. A reviewer who is satisfied passes the change to the maintainers, who have&lt;br /&gt;
the final say; in the year before the 2025 paper on Mathlib&amp;#039;s maintenance, about one change in three that was&lt;br /&gt;
accepted had first been approved by a reviewer in this way. Automatic checks called linters point&lt;br /&gt;
out common mistakes before a person looks.&amp;lt;ref name=&amp;quot;growing&amp;quot; /&amp;gt; The 2020 paper describes the&lt;br /&gt;
same open arrangement: design is discussed in public, with little central control over what the&lt;br /&gt;
library contains.&amp;lt;ref name=&amp;quot;cpp2020&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Review is what makes a shared library trustworthy in the sense that matters for&lt;br /&gt;
[[Lean theorem prover/Explainers/Stating the right thing|stating the right thing]]: a definition that&lt;br /&gt;
many people have read and used is more likely to mean what it says than one written for a single&lt;br /&gt;
proof.&lt;br /&gt;
&lt;br /&gt;
== Organised by structures ==&lt;br /&gt;
&lt;br /&gt;
Much of mathematics is organised by structures: a group, a ring, a field, an ordered field, a&lt;br /&gt;
topological space. A theorem proved for every group holds for each particular group. Mathlib&lt;br /&gt;
expresses each structure as a &amp;#039;&amp;#039;&amp;#039;type class&amp;#039;&amp;#039;&amp;#039;: a description of what a type must provide, which&lt;br /&gt;
Lean finds automatically for a particular type when a theorem needs it.&amp;lt;ref name=&amp;quot;cpp2020&amp;quot; /&amp;gt; A&lt;br /&gt;
small version, in core Lean:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;lean&amp;quot; style=&amp;quot;background: #f8f9fa; border: 1px solid #c8ccd1; padding: 0.6em; margin: 0.3em 0; font-size: 0.85em; line-height: 1.35; overflow-x: auto; white-space: pre;&amp;quot;&amp;gt;&lt;br /&gt;
class Semigroup&amp;#039; (α : Type) extends Mul α where&lt;br /&gt;
  mul_assoc : ∀ a b c : α, a * b * c = a * (b * c)&lt;br /&gt;
&lt;br /&gt;
theorem regroup {α : Type} [Semigroup&amp;#039; α] (a b c d : α) :&lt;br /&gt;
    a * b * c * d = a * (b * (c * d)) := by&lt;br /&gt;
  rw [Semigroup&amp;#039;.mul_assoc, Semigroup&amp;#039;.mul_assoc]&lt;br /&gt;
&lt;br /&gt;
instance : Semigroup&amp;#039; Nat where&lt;br /&gt;
  mul_assoc := Nat.mul_assoc&lt;br /&gt;
&lt;br /&gt;
instance : Semigroup&amp;#039; Int where&lt;br /&gt;
  mul_assoc := Int.mul_assoc&lt;br /&gt;
&lt;br /&gt;
example (a b c d : Nat) : a * b * c * d = a * (b * (c * d)) := regroup a b c d&lt;br /&gt;
example (a b c d : Int) : a * b * c * d = a * (b * (c * d)) := regroup a b c d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The class says what a semigroup is: a multiplication in which brackets can be moved. The theorem&lt;br /&gt;
&amp;lt;code&amp;gt;regroup&amp;lt;/code&amp;gt; is proved once, for every semigroup. The two instances declare that natural&lt;br /&gt;
numbers and integers are semigroups, and the last two lines use the one theorem for both; Lean&lt;br /&gt;
finds the right instance itself. Lean accepts all of it.&lt;br /&gt;
&lt;br /&gt;
Mathlib&amp;#039;s version of this is large. Its class for fields, for instance, has 19 fields that carry&lt;br /&gt;
data, and keeping the automatic search for instances fast is a continuing part of the work of&lt;br /&gt;
maintaining it.&amp;lt;ref name=&amp;quot;growing&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting a library ==&lt;br /&gt;
&lt;br /&gt;
A Lean project obtains its libraries through &amp;#039;&amp;#039;&amp;#039;Lake&amp;#039;&amp;#039;&amp;#039;, the tool that comes with Lean for&lt;br /&gt;
compiling Lean code and fetching what it depends on. A project names its dependencies; Lake records&lt;br /&gt;
the exact version of each in a file, &amp;lt;code&amp;gt;lake-manifest.json&amp;lt;/code&amp;gt;, which Lean&amp;#039;s reference says&lt;br /&gt;
should be kept with the project&amp;#039;s own code; and before compiling, Lake brings each dependency to&lt;br /&gt;
the recorded version. The command &amp;lt;code&amp;gt;lake update&amp;lt;/code&amp;gt; looks for newer versions, fetches them&lt;br /&gt;
and updates that record.&amp;lt;ref name=&amp;quot;lake&amp;quot;&amp;gt;&amp;#039;&amp;#039;The Lean Language Reference&amp;#039;&amp;#039;, version for Lean 4.34.0, section &amp;quot;Lake&amp;quot;. [https://lean-lang.org/doc/reference/4.34.0/Build-Tools-and-Distribution/Lake/ lean-lang.org/doc/reference/4.34.0/Build-Tools-and-Distribution/Lake], consulted 14 October 2026.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than compile all of Mathlib from its source, a project can download Mathlib&amp;#039;s compiled&lt;br /&gt;
files with a command the community provides, &amp;lt;code&amp;gt;lake exe cache get&amp;lt;/code&amp;gt;. The community&amp;#039;s&lt;br /&gt;
instructions also advise giving a project the same version of Lean as Mathlib uses.&amp;lt;ref name=&amp;quot;install&amp;quot;&amp;gt;Lean community, &amp;quot;Lean projects&amp;quot; (installation instructions). [https://leanprover-community.github.io/install/project.html leanprover-community.github.io/install/project.html], consulted 14 October 2026.&amp;lt;/ref&amp;gt;&lt;br /&gt;
Together with the version file described on&lt;br /&gt;
[[Lean theorem prover/Explainers/Checking a proof again later|checking a proof again later]],&lt;br /&gt;
this fixes the version of everything a proof depends on.&lt;br /&gt;
&lt;br /&gt;
Whether the project this wiki records will adopt Mathlib or stay with core Lean is one of its open&lt;br /&gt;
questions (see [[Principia Machina/Lean transition|the move to Lean]]).&lt;br /&gt;
&lt;br /&gt;
== Next ==&lt;br /&gt;
&lt;br /&gt;
[[Lean theorem prover/Explainers/Lean and physics|Lean and physics]] asks what such a library can&lt;br /&gt;
and cannot do for physics.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>PMA Publisher</name></author>
	</entry>
</feed>