Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
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
Library Style Guidelines
Author: Jeremy Avigad
In addition to the naming conventions, files in the Lean library generally adhere to the following guidelines and conventions. Having a uniform style makes it easier to browse the library and read the contents, but these are meant to be guidelines rather than rigid rules.
Variable conventions
u
,v
,w
, ... for universesα
,β
,γ
, ... for typesa
,b
,c
, ... for propositionsx
,y
,z
, ... for elements of a generic typeh
,h₁
, ... for assumptionsp
,q
,r
, ... for predicates and relationss
,t
, ... for listss
,t
, ... for setsm
,n
,k
, ... for natural numbersi
,j
,k
, ... for integers
Line length
Lines should not be longer than 100 characters. This makes files easier to read, especially on a small screen or in a small window.
Header and imports
The file header should contain copyright information, a list of all the authors who have worked on the file, and a description of the contents. Do all import
s right after the header, without a line break. You can also open namespaces in the same block.
Structuring definitions and theorems
Use spaces around ":", ":=" or infix operators. Put them before a line break rather than at the beginning of the next line.
Use two spaces to indent. You can use an extra indent when a long line forces a break to suggest the break is artificial rather than structural, as in the statement of theorem:
If you want to indent to make parameters line up, that is o.k. too:
After stating the theorem, we generally do not indent the first line of a proof, so that the proof is "flush left" in the file.
When a proof rule takes multiple arguments, it is sometimes clearer, and often necessary, to put some of the arguments on subsequent lines. In that case, indent each argument.
Don't orphan parentheses; keep them with their arguments.
Here is a longer example.
A short definition can be written on a single line:
For longer definitions, use conventions like those for theorems.
A "have" / "from" pair can be put on the same line.
You can also put it on the next line, if the justification is long.
If the justification takes more than a single line, keep the "from" on the same line as the "have", and then begin the justification indented on the next line.
When the arguments themselves are long enough to require line breaks, use an additional indent for every line after the first, as in the following example:
In a class or structure definition, we do not indent fields, as in:
When using a constructor taking several arguments in a definition, arguments line up, as in:
When defining instances, opening and closing braces are not alone on their line. The content is indented by two spaces and :=
line up, as in:
Binders
Use a space after binders:
Calculations
There is some flexibility in how you write calculational proofs. In general, it looks nice when the comparisons and justifications line up neatly:
To be more compact, for example, you may do this only after the first line:
Tactic mode
When opening a tactic block, begin
is not indented but everything inside is indented, as in:
A more complicated example, mixing term mode and tactic mode:
When new goals arise as side conditions or steps, they are enclosed in focussing braces and indented. Braces are not alone on their line.
Often t0 ; t1
is used to execute t0
and then t1
on all new goals. But ;
is not a ,
so either write the tactics in one line, or indent the following tacic.
Sections
Within a section, you can indent definitions and theorems to make the scope salient:
If the section is long, however, you can omit the indents.
We generally use a blank line to separate theorems and definitions, but this can be omitted, for example, to group together a number of short definitions, or to group together a definition and notation.
Comments
Use comment delimiters /- -/
to provide section headers and separators, and for long comments. Use --
for short or in-line comments.
Documentation strings for declarations are delimited with /-- -/
. Documentation strings for modules are delimited with /-! -/
.
Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad