Documentation

CslibFrontier.Foundations.Data.Nat.ToDigits

Decimal digits that the kernel can evaluate #

Nat.toDecimal n is the list of the decimal digits of n, most significant first: Lean core's Nat.toDigits 10 n, behind toString n (Nat.toDecimal_eq_toDigits). It is defined again, by recursion on a fuel argument and with its body exposed, so that the kernel evaluates it: Nat.toDigits has no exposed body. Int.toDecimal writes an integer, with - if it is negative.

Nat.ofDecimal? is the checked reader of decimal numerals shared by the DIMACS and OPB front ends: one or more decimal digits, read from the left by Nat.digitStep, which is the step of core's Nat.ofDigitChars 10 (Nat.foldl_digitStep_eq_ofDigitChars). Each front end adds its own syntax at its boundary: DIMACS its _ digit separators, OPB its signs. Reading back what Nat.toDecimal writes gives the number (Nat.ofDecimal?_toDecimal), by core's Nat.ofDigitChars_ten_toDigits.

Main definitions #

Main statements #

The decimal digit of d < 10, and '9' above.

The decimal digits of n, with fuel bounding their number.

The decimal digits of n, most significant first, without leading zeros: ['0'] for 0.

def Nat.digitStep (m : ℕ) (c : Char) :

The value 10 * m + d of the digit c, with value d, after the value m of the digits before it: the step of Nat.ofDigitChars 10.

A decimal numeral: one or more decimal digits, read from the left.

The decimal digits of an integer, with - in front if it is negative.

The decimal digit of d < 10 is core's Nat.digitChar d.

The digits are those of Lean core's Nat.toDigits 10, which toString writes.

theorem Nat.isDigit_of_mem_toDecimal {n : ℕ} {c : Char} (h : c ∈ n.toDecimal) :

The decimal digits of a number are digits.

A number has at least one decimal digit.

theorem Nat.ofDecimal?_eq_some_iff {cs : List Char} {n : ℕ} :
ofDecimal? cs = some n ↔ cs ≠ [] ∧ (∀ c ∈ cs, c.isDigit = true) ∧ ofDigitChars 10 cs 0 = n

Reading a decimal numeral: the value of its digits, if it has one or more and only digits.

@[simp]

Reading back the decimal digits of a number gives it.

theorem Nat.exists_toDecimal_eq_cons (n : ℕ) :
∃ (d : Char) (ds : List Char), n.toDecimal = d :: ds ∧ d.isDigit = true

A number has a first decimal digit.

theorem Int.mem_toDecimal {a : ℤ} {c : Char} (h : c ∈ a.toDecimal) :
c = '-' ∨ c.isDigit = true

The characters of an integer are - and decimal digits.

theorem Int.exists_toDecimal_eq_cons (a : ℤ) :
∃ (d : Char) (ds : List Char), a.toDecimal = d :: ds ∧ (d = '-' ∨ d.isDigit = true)

The first character of an integer is - or a decimal digit.

An integer has at least one character.