Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Try doing some basic maths questions in the Lean Theorem Prover. Functions, real numbers, equivalence relations and groups. Click on README.md and then on "Open in CoCalc with one click".
License: APACHE
Documentation style
We are in the process of implementing new documentation requirements for mathlib. All future pull requests must meet the following standards.
Header comment
Each mathlib file should start with:
a header comment with copyright information;
the list of imports;
a module docstring containing general documentation, written using Markdown.
(See the example below.)
Headers use atx-style headers (with hash signs, no underlying dash). The open and close delimiters /-!
and -/
should appear on their own lines.
The mandatory title of the file is a first level header. It is followed by a summary of the content of the file.
The other sections, with second level headers are (in this order):
Main definitions (optional, can be covered in the summary)
Main statements (optional, can be covered in the summary)
Notations (omitted only if no notation is introduced in this file)
Implementation notes (description of important design decisions or interface features, including use of type classes and
simp
canonical form for new definitions)References (references to textbooks or papers, or Wikipedia pages)
Tags (a list of keywords that could be useful when doing text search in mathlib to find where something is covered)
References should refer to bibtex entries in the mathlib citations file.
The following code block is an example of a file header.
Docstrings
Every definition and major theorem is required to have a doc string. (Doc strings on lemmas are also encouraged, particularly if the lemma has any mathematical content or might be useful in another file.) These are introduced using /--
and closed by -/
above the definition. They can contain some markdown, e.g. backtick quotes. They should convey the mathematical meaning of the definition. It is allowed to lie slightly about the actual implementation. The following is a docstring example:
An example that is slightly lying but still describes the mathematical content would be:
The #doc_blame
command can be run at the bottom of a file to list all definitions that do not have doc strings. #doc_blame!
will also list theorems and lemmas.
Sectioning comments
It is common to structure a file in sections, where each section contains related declarations. By describing the sections with module documentation /-! ... -/
at the beginning, these sections can be seen in the documentation.
While these sectioning comments will often correspond to section
or namespace
commands, this is not required. You can use sectioning comments inside of a section or namespace, and you can have multiple sections or namespaces following one sectioning comment.
Sectioning comments are for display and readability only. They have no semantic meaning.
Third-level headers ###
should be used for titles inside sectioning comments.
If the comment is more than one line long, the delimiters /-!
and -/
should appear on their own lines.
See meta/expr.lean for an example in practice.
Theories documentation
In addition to documentation living in Lean file, we have tactic documentation in docs/tactics, and theory documentation in docs/theories where we give overviews spanning several Lean files, and more mathematical explanations in cases where formalization requires slightly exotic points of view, see for instance the topology documentation.
Examples
The following files are maintained as examples of good documentation style: