The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V01. The language of Mathlib

Mathlib.Lean.Expr.Rat

2 declarations. Mathlib docs · Source

Additional operations on Expr and rational numbers

This file defines some operations involving Expr and rational numbers.

Main definitions

  • Lean.Expr.isExplicitNumber: is an expression a number in normal form? This includes natural numbers, integers and rationals.

def Lean.Expr.rat? E1 #

Lean.Expr → Option ℚ

Check if an expression is a "rational in normal form", i.e. either an integer number in normal form, or n / d where n is an integer in normal form, d is a natural number in normal form, d ≠ 1, and n and d are coprime (in particular, we check that (mkRat n d).den = d). If so returns the rational number.

def Lean.Expr.isExplicitNumber E3 #

Lean.Expr → Bool

Test if an expression represents an explicit number written in normal form:

  • A "natural number in normal form" is an expression OfNat.ofNat n, even if it is not of type ℕ, as long as n is a literal.
  • An "integer in normal form" is an expression which is either a natural number in number form, or -n, where n is a natural number in normal form.
  • A "rational in normal form" is an expressions which is either an integer in normal form, or n / d where n is an integer in normal form, d is a natural number in normal form, d ≠ 1, and n and d are coprime (in particular, we check that (mkRat n d).den = d).