Lean 语言参考

20.1. 自然数🔗

自然数 是非负整数。 从逻辑上讲,它们是数字 0、1、2、3……,由构造函数 Nat.zeroNat.succ 生成。 除了计算机可用内存施加的物理约束之外,Lean 对自然数的表示没有施加上限。

由于自然数是数学推理和编程的基础,因此 Lean 的实现特别支持它们。自然数的逻辑模型为 归纳类型,并且使用该模型指定算术运算。在 Lean 的内核中,解释器和编译代码、封闭的自然数被表示为高效的任意精度整数。足够小的数字是不需要通过指针间接寻址的值。算术运算是通过利用高效表示的原语来实现的。

20.1.1. 逻辑模型🔗

🔗inductive type
Nat : Type
Nat : Type

The natural numbers, starting at zero.

This type is special-cased by both the kernel and the compiler, and overridden with an efficient implementation. Both use a fast arbitrary-precision arithmetic library (usually GMP); at runtime, Nat values that are sufficiently small are unboxed.

Constructors

Nat.zero : Nat

Zero, the smallest natural number.

Using Nat.zero explicitly should usually be avoided in favor of the literal 0, which is the simp normal form.

Nat.succ (n : Nat) : Nat

The successor of a natural number n.

Using Nat.succ n should usually be avoided in favor of n + 1, which is the simp normal form.

Proofs by Induction

自然数是 归纳类型,因此 induction策略可用于证明全称量化陈述。 归纳证明需要基例和归纳步骤。 基例证明该陈述对于 0 是正确的。 归纳步骤证明某个任意数 i 的陈述的真实性意味着 i + 1 的陈述的真实性。

该证明在归纳步骤中使用引理 Nat.succ_lt_succ

example (n : Nat) : n < n + 1 := i:Natn:Natn < n + 1 induction n with i:Nat0 < 0 + 1 i:Nat0 < 1 All goals completed! 🐙 i✝:Nati:Natih:i < i + 1i + 1 < i + 1 + 1 -- ih : i < i + 1 i✝:Nati:Natih:i < i + 1i + 1 < i + 1 + 1 All goals completed! 🐙

20.1.1.1. 皮亚诺公理🔗

皮亚诺公理是这个定义的结果。 Nat 生成的归纳原理是归纳公理所要求的:

Nat.rec.{u} {motive : Nat Sort u} (zero : motive zero) (succ : (n : Nat) motive n motive n.succ) (t : Nat) : motive t

这个归纳原理也实现了原始递归。 Nat.succ 的单射性以及 Nat.succNat.zero 的不相交是归纳原理的结果,使用通常称为“无混淆”的结构:

def NoConfusion : Nat Nat Prop | 0, 0 => True | 0, _ + 1 | _ + 1, 0 => False | n + 1, k + 1 => n = k theorem noConfusionDiagonal (n : Nat) : NoConfusion n n := Nat.rec True.intro (fun _ _ => rfl) n theorem noConfusion (n k : Nat) (eq : n = k) : NoConfusion n k := eq noConfusionDiagonal n theorem succ_injective : n + 1 = k + 1 n = k := noConfusion (n + 1) (k + 1) theorem succ_not_zero : ¬n + 1 = 0 := noConfusion (n + 1) 0

20.1.2. 运行时表示🔗

Nat 声明所建议的表示效率极其低下,因为它本质上是一个链表。 列表的长度就是数字。 通过这种表示,加法所花费的时间与一个加数的大小成线性关系,而数字所花费的机器字数至少与其在内存中的大小一样多。 因此,自然数在内核和编译器中都有特殊支持,可以避免这种开销。

在内核中,有特殊的 Nat 文字值,它们使用广泛信任的高效任意精度整数库(通常为 GMP)。 诸如加法之类的基本函数被使用此表示的原语覆盖。 由于它们是内核的一部分,因此如果这些原语不符合其作为 Lean 函数的定义,则可能会破坏健全性。

在编译代码中,足够小的自然数在没有指针间接表示的情况下表示:对象指针中的最低位用于指示该值实际上不是指针,其余位用于存储数字。 对于无指针 Nat,31 位可用于 32 位架构,而 63 位可用于 64 位架构。 换句话说,小于 2^{31} = 2,147,483,6482^{63} = 9,223,372,036,854,775,808 的自然数不需要分配。 如果自然数对于此表示太大,则会将其分配为普通 Lean 对象,该对象由对象标头和任意精度整数值组成。

20.1.2.1. 性能说明🔗

使用 Lean 的内置算术运算符而不是重新定义它们是至关重要的。 Nat 的逻辑模型本质上是一个链表,因此加法所需的时间与一个参数的大小成线性关系。 更糟糕的是,在此模型中,乘法需要花费二次时间。 虽然从头开始定义算术可能是一种有用的学习练习,但这些重新定义的操作不会那么快。

20.1.3. 句法🔗

自然数文字可使用 OfNat 类型类覆盖,这在 有关文字语法的部分 中进行了描述。

20.1.4. API 参考🔗

20.1.4.1. 算术🔗

🔗def

The predecessor of a natural number is one less than it. The predecessor of 0 is defined to be 0.

This definition is overridden in the compiler with an efficient implementation. This definition is the logical model.

🔗def
Nat.add : Nat Nat Nat
Nat.add : Nat Nat Nat

Addition of natural numbers, typically used via the + operator.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

🔗def
Nat.sub : Nat Nat Nat
Nat.sub : Nat Nat Nat

Subtraction of natural numbers, truncated at 0. Usually used via the - operator.

If a result would be less than zero, then the result is zero.

This definition is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

Examples:

  • 5 - 3 = 2

  • 8 - 2 = 6

  • 8 - 8 = 0

  • 8 - 20 = 0

🔗def
Nat.mul : Nat Nat Nat
Nat.mul : Nat Nat Nat

Multiplication of natural numbers, usually accessed via the * operator.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

🔗def
Nat.div (x y : Nat) : Nat
Nat.div (x y : Nat) : Nat

Division of natural numbers, discarding the remainder. Division by 0 returns 0. Usually accessed via the / operator.

This operation is sometimes called “floor division.”

This function is overridden at runtime with an efficient implementation. This definition is the logical model.

Examples:

  • 21 / 3 = 7

  • 21 / 5 = 4

  • 0 / 22 = 0

  • 5 / 0 = 0

🔗def
Nat.mod : Nat Nat Nat
Nat.mod : Nat Nat Nat

The modulo operator, which computes the remainder when dividing one natural number by another. Usually accessed via the % operator. When the divisor is 0, the result is the dividend rather than an error.

Nat.mod is a wrapper around Nat.modCore that special-cases two situations, giving better definitional reductions:

  • Nat.mod 0 m should reduce to m, for all terms m : Nat.

  • Nat.mod n (m + n + 1) should reduce to n for concrete Nat literals n.

These reductions help Fin n literals work well, because the OfNat instance for Fin uses Nat.mod. In particular, (0 : Fin (n + 1)).val should reduce definitionally to 0. Nat.modCore can handle all numbers, but its definitional reductions are not as convenient.

This function is overridden at runtime with an efficient implementation. This definition is the logical model.

Examples:

  • 7 % 2 = 1

  • 9 % 3 = 0

  • 5 % 7 = 5

  • 5 % 0 = 5

  • show (n : Nat), 0 % n = 0 from fun _ => rfl

  • show (m : Nat), 5 % (m + 6) = 5 from fun _ => rfl

🔗def
Nat.modCore (x y : Nat) : Nat
Nat.modCore (x y : Nat) : Nat

The modulo operator, which computes the remainder when dividing one natural number by another. Usually accessed via the % operator. When the divisor is 0, the result is the dividend rather than an error.

This is the core implementation of Nat.mod. It computes the correct result for any two closed natural numbers, but it does not have some convenient definitional reductions when the Nats contain free variables. The wrapper Nat.mod handles those cases specially and then calls Nat.modCore.

This function is overridden at runtime with an efficient implementation. This definition is the logical model.

🔗def
Nat.pow (m : Nat) : Nat Nat
Nat.pow (m : Nat) : Nat Nat

The power operation on natural numbers, usually accessed via the ^ operator.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

🔗def
Nat.log2 (n : Nat) : Nat
Nat.log2 (n : Nat) : Nat

Base-two logarithm of natural numbers. Returns ⌊max 0 (log₂ n)⌋.

This function is overridden at runtime with an efficient implementation. This definition is the logical model.

Examples:

20.1.4.1.1. 按位运算🔗

🔗def

Shifts the binary representation of a value left by the specified number of bits. Usually accessed via the <<< operator.

Examples:

  • 1 <<< 2 = 4

  • 1 <<< 3 = 8

  • 0 <<< 3 = 0

  • 0xf1 <<< 4 = 0xf10

🔗def

Shifts the binary representation of a value right by the specified number of bits. Usually accessed via the >>> operator.

Examples:

  • 4 >>> 2 = 1

  • 8 >>> 2 = 2

  • 8 >>> 3 = 1

  • 0 >>> 3 = 0

  • 0xf13a >>> 8 = 0xf1

🔗def
Nat.xor : Nat Nat Nat
Nat.xor : Nat Nat Nat

Bitwise exclusive or. Usually accessed via the ^^^ operator.

Each bit of the resulting value is set if the corresponding bit is set in exactly one of the inputs.

🔗def
Nat.lor : Nat Nat Nat
Nat.lor : Nat Nat Nat

Bitwise or. Usually accessed via the ||| operator.

Each bit of the resulting value is set if the corresponding bit is set in at least one of the inputs.

🔗def
Nat.land : Nat Nat Nat
Nat.land : Nat Nat Nat

Bitwise and. Usually accessed via the &&& operator.

Each bit of the resulting value is set if the corresponding bit is set in both of the inputs.

🔗def
Nat.bitwise (f : Bool Bool Bool) (n m : Nat) : Nat
Nat.bitwise (f : Bool Bool Bool) (n m : Nat) : Nat

A helper for implementing bitwise operators on Nat.

Each bit of the resulting Nat is the result of applying f to the corresponding bits of the input Nats, up to the position of the highest set bit in either input.

🔗def
Nat.testBit (m n : Nat) : Bool
Nat.testBit (m n : Nat) : Bool

Returns true if the (n+1)th least significant bit is 1, or false if it is 0.

20.1.4.2. 最小值和最大值🔗

🔗def
Nat.min (n m : Nat) : Nat
Nat.min (n m : Nat) : Nat

Returns the lesser of two natural numbers. Usually accessed via Min.min.

Returns n if n m, or m if m n.

Examples:

🔗def
Nat.max (n m : Nat) : Nat
Nat.max (n m : Nat) : Nat

Returns the greater of two natural numbers. Usually accessed via Max.max.

Returns m if n m, or n if m n.

Examples:

20.1.4.3. GCD 和 LCM🔗

🔗def
Nat.gcd (m n : Nat) : Nat
Nat.gcd (m n : Nat) : Nat

Computes the greatest common divisor of two natural numbers. The GCD of two natural numbers is the largest natural number that evenly divides both.

In particular, the GCD of a number and 0 is the number itself.

This reference implementation via the Euclidean algorithm is overridden in both the kernel and the compiler to efficiently evaluate using arbitrary-precision arithmetic. The definition provided here is the logical model.

Examples:

🔗def
Nat.lcm (m n : Nat) : Nat
Nat.lcm (m n : Nat) : Nat

The least common multiple of m and n is the smallest natural number that's evenly divisible by both m and n. Returns 0 if either m or n is 0.

Examples:

20.1.4.4. 二的幂🔗

🔗def
Nat.isPowerOfTwo (n : Nat) : Prop
Nat.isPowerOfTwo (n : Nat) : Prop

A natural number n is a power of two if there exists some k : Nat such that n = 2 ^ k.

🔗def

Returns the least power of two that's greater than or equal to n.

Examples:

20.1.4.5. 比较🔗

20.1.4.5.1. 布尔比较🔗

🔗def
Nat.beq : Nat Nat Bool
Nat.beq : Nat Nat Bool

Boolean equality of natural numbers, usually accessed via the == operator.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

🔗def
Nat.ble : Nat Nat Bool
Nat.ble : Nat Nat Bool

The Boolean less-than-or-equal-to comparison on natural numbers.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

Examples:

🔗def
Nat.blt (a b : Nat) : Bool
Nat.blt (a b : Nat) : Bool

The Boolean less-than comparison on natural numbers.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

Examples:

20.1.4.5.2. 可判定的平等🔗

🔗def
Nat.decEq (n m : Nat) : Decidable (n = m)
Nat.decEq (n m : Nat) : Decidable (n = m)

A decision procedure for equality of natural numbers, usually accessed via the DecidableEq Nat instance.

This function is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model.

Examples:

🔗def

A decision procedure for non-strict inequality of natural numbers, usually accessed via the DecidableLE Nat instance.

Examples:

🔗def
Nat.decLt (n m : Nat) : Decidable (n < m)
Nat.decLt (n m : Nat) : Decidable (n < m)

A decision procedure for strict inequality of natural numbers, usually accessed via the DecidableLT Nat instance.

Examples:

20.1.4.5.3. 谓词🔗

🔗inductive predicate
Nat.le (n : Nat) : Nat Prop
Nat.le (n : Nat) : Nat Prop

Non-strict, or weak, inequality of natural numbers, usually accessed via the operator.

Constructors

Nat.le.refl {n : Nat} : n.le n

Non-strict inequality is reflexive: n n

Nat.le.step {n m : Nat} : n.le m  n.le m.succ

If n m, then n m + 1.

🔗def
Nat.lt (n m : Nat) : Prop
Nat.lt (n m : Nat) : Prop

Strict inequality of natural numbers, usually accessed via the < operator.

It is defined as n < m = n + 1 m.

20.1.4.6. 迭代🔗

许多迭代运算符有两个版本:结构递归版本和尾递归版本。 结构递归版本通常在 定义等价 很重要的上下文中更容易使用,因为它会在仅知道自然数的某些前缀时进行计算。

🔗def
Nat.repeat.{u} {α : Type u} (f : α α) (n : Nat) (a : α) : α
Nat.repeat.{u} {α : Type u} (f : α α) (n : Nat) (a : α) : α

Applies a function to a starting value the specified number of times.

In other words, f is iterated n times on a.

Examples:

  • Nat.repeat f 3 a = f <| f <| f <| a

  • Nat.repeat (· ++ "!") 4 "Hello" = "Hello!!!!"

🔗def
Nat.repeatTR.{u} {α : Type u} (f : α α) (n : Nat) (a : α) : α
Nat.repeatTR.{u} {α : Type u} (f : α α) (n : Nat) (a : α) : α

Applies a function to a starting value the specified number of times.

In other words, f is iterated n times on a.

This is a tail-recursive version of Nat.repeat that's used at runtime.

Examples:

  • Nat.repeatTR f 3 a = f <| f <| f <| a

  • Nat.repeatTR (· ++ "!") 4 "Hello" = "Hello!!!!"

🔗def
Nat.fold.{u} {α : Type u} (n : Nat) (f : (i : Nat) i < n α α) (init : α) : α
Nat.fold.{u} {α : Type u} (n : Nat) (f : (i : Nat) i < n α α) (init : α) : α

Iterates the application of a function f to a starting value init, n times. At each step, f is applied to the current value and to the next natural number less than n, in increasing order.

Examples:

🔗def
Nat.foldTR.{u} {α : Type u} (n : Nat) (f : (i : Nat) i < n α α) (init : α) : α
Nat.foldTR.{u} {α : Type u} (n : Nat) (f : (i : Nat) i < n α α) (init : α) : α

Iterates the application of a function f to a starting value init, n times. At each step, f is applied to the current value and to the next natural number less than n, in increasing order.

This is a tail-recursive version of Nat.fold that's used at runtime.

Examples:

🔗def
Nat.foldM.{u, v} {α : Type u} {m : Type u Type v} [Monad m] (n : Nat) (f : (i : Nat) i < n α m α) (init : α) : m α
Nat.foldM.{u, v} {α : Type u} {m : Type u Type v} [Monad m] (n : Nat) (f : (i : Nat) i < n α m α) (init : α) : m α

Iterates the application of a monadic function f to a starting value init, n times. At each step, f is applied to the current value and to the next natural number less than n, in increasing order.

🔗def
Nat.foldRev.{u} {α : Type u} (n : Nat) (f : (i : Nat) i < n α α) (init : α) : α
Nat.foldRev.{u} {α : Type u} (n : Nat) (f : (i : Nat) i < n α α) (init : α) : α

Iterates the application of a function f to a starting value init, n times. At each step, f is applied to the current value and to the next natural number less than n, in decreasing order.

Examples:

🔗def
Nat.foldRevM.{u, v} {α : Type u} {m : Type u Type v} [Monad m] (n : Nat) (f : (i : Nat) i < n α m α) (init : α) : m α
Nat.foldRevM.{u, v} {α : Type u} {m : Type u Type v} [Monad m] (n : Nat) (f : (i : Nat) i < n α m α) (init : α) : m α

Iterates the application of a monadic function f to a starting value init, n times. At each step, f is applied to the current value and to the next natural number less than n, in decreasing order.

🔗def
Nat.forM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (f : (i : Nat) i < n m Unit) : m Unit
Nat.forM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (f : (i : Nat) i < n m Unit) : m Unit

Executes a monadic action on all the numbers less than some bound, in increasing order.

Example:

0 1 2 3 4 #eval Nat.forM 5 fun i _ => IO.println i 0 1 2 3 4
🔗def
Nat.forRevM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (f : (i : Nat) i < n m Unit) : m Unit
Nat.forRevM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (f : (i : Nat) i < n m Unit) : m Unit

Executes a monadic action on all the numbers less than some bound, in decreasing order.

Example:

4 3 2 1 0 #eval Nat.forRevM 5 fun i _ => IO.println i 4 3 2 1 0
🔗def
Nat.all (n : Nat) (f : (i : Nat) i < n Bool) : Bool
Nat.all (n : Nat) (f : (i : Nat) i < n Bool) : Bool

Checks whether f returns true for every number strictly less than a bound.

Examples:

🔗def
Nat.allTR (n : Nat) (f : (i : Nat) i < n Bool) : Bool
Nat.allTR (n : Nat) (f : (i : Nat) i < n Bool) : Bool

Checks whether f returns true for every number strictly less than a bound.

This is a tail-recursive equivalent of Nat.all that's used at runtime.

Examples:

🔗def
Nat.any (n : Nat) (f : (i : Nat) i < n Bool) : Bool
Nat.any (n : Nat) (f : (i : Nat) i < n Bool) : Bool

Checks whether there is some number less that the given bound for which f returns true.

Examples:

🔗def
Nat.anyTR (n : Nat) (f : (i : Nat) i < n Bool) : Bool
Nat.anyTR (n : Nat) (f : (i : Nat) i < n Bool) : Bool

Checks whether there is some number less that the given bound for which f returns true.

This is a tail-recursive equivalent of Nat.any that's used at runtime.

Examples:

🔗def
Nat.allM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (p : (i : Nat) i < n m Bool) : m Bool
Nat.allM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (p : (i : Nat) i < n m Bool) : m Bool

Checks whether the monadic predicate p returns true for all numbers less that the given bound. Numbers are checked in increasing order until p returns false, after which no further are checked.

🔗def
Nat.anyM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (p : (i : Nat) i < n m Bool) : m Bool
Nat.anyM.{u_1} {m : Type Type u_1} [Monad m] (n : Nat) (p : (i : Nat) i < n m Bool) : m Bool

Checks whether there is some number less that the given bound for which the monadic predicate p returns true. Numbers are checked in increasing order until p returns true, after which no further are checked.

20.1.4.7. 转换🔗

🔗def

Converts a natural number to an 8-bit unsigned integer, wrapping on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:

🔗def

Converts a natural number to a 16-bit unsigned integer, wrapping on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:

🔗def

Converts a natural number to a 32-bit unsigned integer, wrapping on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:

🔗def

Converts a natural number to a 64-bit unsigned integer, wrapping on overflow.

This function is overridden at runtime with an efficient implementation.

Examples:

🔗def

Converts an arbitrary-precision natural number to an unsigned word-sized integer, wrapping around on overflow.

This function is overridden at runtime with an efficient implementation.

🔗def

Converts a natural number to an 8-bit signed integer, wrapping around to negative numbers on overflow.

Examples:

🔗def

Converts a natural number to a 16-bit signed integer, wrapping around to negative numbers on overflow.

Examples:

🔗def

Converts a natural number to a 32-bit signed integer, wrapping around to negative numbers on overflow.

Examples:

🔗def

Converts a natural number to a 64-bit signed integer, wrapping around to negative numbers on overflow.

Examples:

🔗def

Converts an arbitrary-precision natural number to a word-sized signed integer, wrapping around on overflow.

This function is overridden at runtime with an efficient implementation.

🔗def

Converts a natural number into the closest-possible 64-bit floating-point number, or an infinite floating-point value if the range of Float is exceeded.

🔗def

Converts a natural number into the closest-possible 32-bit floating-point number, or an infinite floating-point value if the range of Float32 is exceeded.

🔗def
Nat.isValidChar (n : Nat) : Prop
Nat.isValidChar (n : Nat) : Prop

A Nat denotes a valid Unicode code point if it is less than 0x110000 and it is also not a surrogate code point (the range 0xd800 to 0xdfff inclusive).

🔗def

Converts a natural number to its decimal string representation.

🔗def
Nat.toDigits (base n : Nat) : List Char
Nat.toDigits (base n : Nat) : List Char

Returns the decimal representation of a natural number as a list of digit characters in the given base. If the base is greater than 16 then '*' is returned for digits greater than 0xf.

Examples:

🔗def

Returns a single digit representation of n, which is assumed to be in a base less than or equal to 16. Returns '*' if n > 15.

Examples:

🔗def

Converts a natural number to a string that contains the its decimal representation as Unicode subscript digit characters.

Examples:

🔗def

Converts a natural number to a string that contains the its decimal representation as Unicode superscript digit characters.

Examples:

🔗def

Converts a natural number to the list of Unicode superscript digit characters that corresponds to its decimal representation.

Examples:

🔗def

Converts a natural number to the list of Unicode subscript digit characters that corresponds to its decimal representation.

Examples:

🔗def

Converts a natural number less than 10 to the corresponding Unicode subscript digit character. Returns '*' for other numbers.

Examples:

🔗def

Converts a natural number less than 10 to the corresponding Unicode superscript digit character. Returns '*' for other numbers.

Examples:

20.1.4.8. 消除🔗

Nat 自动生成的递归原理会产生以 Nat.zeroNat.succ 表述的证明目标。 这对于用户来说不是特别友好,因此提供了另一种逻辑等效的递归原则,其结果是用 0n + 1 来表述的目标。 自定义消除器 用于 inductioncases策略可以使用 induction_eliminatorcases_eliminator 属性提供。

🔗def
Nat.recAux.{u} {motive : Nat Sort u} (zero : motive 0) (succ : (n : Nat) motive n motive (n + 1)) (t : Nat) : motive t
Nat.recAux.{u} {motive : Nat Sort u} (zero : motive 0) (succ : (n : Nat) motive n motive (n + 1)) (t : Nat) : motive t

A recursor for Nat that uses the notations 0 for Nat.zero and n + 1 for Nat.succ.

It is otherwise identical to the default recursor Nat.rec. It is used by the induction tactic by default for Nat.

🔗def
Nat.casesAuxOn.{u} {motive : Nat Sort u} (t : Nat) (zero : motive 0) (succ : (n : Nat) motive (n + 1)) : motive t
Nat.casesAuxOn.{u} {motive : Nat Sort u} (t : Nat) (zero : motive 0) (succ : (n : Nat) motive (n + 1)) : motive t

A case analysis principle for Nat that uses the notations 0 for Nat.zero and n + 1 for Nat.succ.

It is otherwise identical to the default recursor Nat.casesOn. It is used as the default Nat case analysis principle for Nat by the cases tactic.

20.1.4.8.1. 替代归纳原理🔗

🔗def
Nat.strongRecOn.{u} {motive : Nat Sort u} (n : Nat) (ind : (n : Nat) ((m : Nat) m < n motive m) motive n) : motive n
Nat.strongRecOn.{u} {motive : Nat Sort u} (n : Nat) (ind : (n : Nat) ((m : Nat) m < n motive m) motive n) : motive n

Strong induction on the natural numbers.

The induction hypothesis is that all numbers less than a given number satisfy the motive, which should be demonstrated for the given number.

🔗def
Nat.caseStrongRecOn.{u} {motive : Nat Sort u} (a : Nat) (zero : motive 0) (ind : (n : Nat) ((m : Nat) m n motive m) motive n.succ) : motive a
Nat.caseStrongRecOn.{u} {motive : Nat Sort u} (a : Nat) (zero : motive 0) (ind : (n : Nat) ((m : Nat) m n motive m) motive n.succ) : motive a

Case analysis based on strong induction for the natural numbers.

🔗def
Nat.div.inductionOn.{u} {motive : Nat Nat Sort u} (x y : Nat) (ind : (x y : Nat) 0 < y y x motive (x - y) y motive x y) (base : (x y : Nat) ¬(0 < y y x) motive x y) : motive x y
Nat.div.inductionOn.{u} {motive : Nat Nat Sort u} (x y : Nat) (ind : (x y : Nat) 0 < y y x motive (x - y) y motive x y) (base : (x y : Nat) ¬(0 < y y x) motive x y) : motive x y

An induction principle customized for reasoning about the recursion pattern of natural number division by iterated subtraction.

🔗def
Nat.div2Induction.{u} {motive : Nat Sort u} (n : Nat) (ind : (n : Nat) (n > 0 motive (n / 2)) motive n) : motive n
Nat.div2Induction.{u} {motive : Nat Sort u} (n : Nat) (ind : (n : Nat) (n > 0 motive (n / 2)) motive n) : motive n

An induction principle for the natural numbers with two cases:

  • n = 0, and the motive is satisfied for 0

  • n > 0, and the motive should be satisfied for n on the assumption that it is satisfied for n / 2.

🔗def
Nat.mod.inductionOn.{u} {motive : Nat Nat Sort u} (x y : Nat) (ind : (x y : Nat) 0 < y y x motive (x - y) y motive x y) (base : (x y : Nat) ¬(0 < y y x) motive x y) : motive x y
Nat.mod.inductionOn.{u} {motive : Nat Nat Sort u} (x y : Nat) (ind : (x y : Nat) 0 < y y x motive (x - y) y motive x y) (base : (x y : Nat) ¬(0 < y y x) motive x y) : motive x y

An induction principle customized for reasoning about the recursion pattern of Nat.mod.