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
How to use calc
calc
is an environment -- so a "mode" like tactic mode, term mode and conv mode. Documentation and basic examples for how to use it are in Theorem Proving In Lean, in section 4.3.
Basic example usage:
Error messages, and how to avoid them.
Note that the error messages can be quite obscure when things aren't quite right, and often the red squiggles end up under a random ...
. A tip to avoid these problems with calc usage is to first populate a skeleton proof such as
(in tactic mode this might look more like
with a comma at the end), and then to start filling in the sorries after that. (Idle thought: could one write a VS Code snippet to write this skeleton?)
Using operators other than equality.
Many of the basic examples in TPIL use equality for most or all of the operators, but actually calc
will work with any relation for which the corresponding transitivity statement is tagged [trans]
:
Using more than one operator.
This is possible; TPIL has the following example:
What is actually going on here? The proofs themselves are not a mystery, for example nat.succ_le_succ h2
is a proof of b + 1 ≤ c + 1
. The clever part is that lean can put all of these together to correctly deduce that if U = V < W ≤ X < Y
then U < Y
. The way this is done, Kevin thinks (can someone verify this?) is that Lean continually tries to amalgamate the first two operators in the list, until there is only one left. In other words, Lean will attempt to reduce the equations thus:
Note the following subtlety: given U op1 V
and V op2 W
Lean has to conclude U op3 W
for some operator, which might be op1
or op2
(or even, as we shall see, a new operator). How is Lean doing this? The easiest case is when one of op1
and op2
is =
. Lean knows
and (Kevin believes) uses them if one of the operators is an equality operator. If however neither operator is the equality operator, Lean looks through the theorems in its database which are tagged [trans]
and applies these instead. For example Lean has the following definitions:
and it is easily seen that these lemmas can be used to justify the example in the manual.
Using user-defined operators
It is as simple as tagging the relevant results with trans
. For example
This example shows us that the third operator op3
can be different to both op1
and op2
.