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
Maths in Lean : the natural numbers
The natural numbers begin with zero as is standard in computer science. You can call them nat
or ℕ
(you get the latter symbol by typing \N
in VS Code).
The naturals are what is called an inductive type, with two constructors. The first is nat.zero
, usually written 0
or (0:ℕ)
in practice, which is zero. The other constructor is nat.succ
, which takes a natural as input and outputs the next one.
Addition and multiplication are defined by recursion on the second variable and many proofs of basic stuff in the core library are by induction on the second variable. The notations +,-,*
are shorthand for the functions nat.add
, nat.sub
and nat.mul
and other notations (≤, <, |) mean the usual things (get the "divides" symbol with \|
. The %
symbol denotes modulus (remainder after division).
Here are some of core Lean's functions for working with nat
.
In mathlib there are more basic functions on the naturals, for example factorials, lowest common multiples, primes, square roots, and some modular arithmetic.