Basic theorems about natural numbers #
The primary purpose of the theorems in this file is to assist with reasoning about sizes of objects, array indices and such.
The content of this file was upstreamed from Batteries and mathlib, and later these theorems should be organised into other files more systematically.
succ/pred #
add #
sub #
Equations
Instances For
A version of Nat.sub_succ in the form _ - 1 instead of Nat.pred _.
min/max #
mul #
div/mod #
pow #
log2 #
mod, dvd #
shiftLeft and shiftRight #
Decidability of predicates #
Tail-recursive runtime replacements for the bounded-quantifier decision procedures #
decidableBallLT, decidableExistsLT, and decidableExistsLT' recurse to depth n in non-tail
position, so running the compiled instance is either quadratic (decidableBallLT rebuilds the
predicate at every level) or overflows the stack for large n. Each is replaced at runtime by a
proven-equivalent tail-recursive version via @[csimp]; kernel reduction (by decide) is
unaffected, as it uses the original structural definitions.
The roots are marked noncomputable so the non-tail-recursive code is never compiled at all, and
each @[csimp] replacement is registered immediately after its root and before the Fin/≤
wrappers (decidableForallFin, decidableExistsFin, decidableBall/ExistsLE, …). The wrappers
reduce to these roots through @[inline] decidable_of_iff, so they pick up the tail-recursive
versions; and because the roots are noncomputable, a wrapper placed before its replacement fails
to compile rather than silently regressing.
Tail-recursive Bool loop: true iff f i h holds for every i < n
(short-circuits on the first false). Used at runtime by decidableBallLT via @[csimp].
Equations
- n.allLTTR f = Nat.allLTTR.loop✝ n f n ⋯
Instances For
Tail-recursive Bool loop: true iff f i h holds for some i < n
(short-circuits on the first true). Used at runtime by decidableExistsLT/' via @[csimp].
Equations
- n.anyLTTR f = Nat.anyLTTR.loop✝ n f n ⋯
Instances For
Tail-recursive runtime replacement for decidableBallLT.
Equations
- n.decidableBallLTTR P = decidable_of_iff ((n.allLTTR fun (i : Nat) (h : i < n) => decide (P i h)) = true) ⋯
Instances For
Equations
- Nat.decidableForallFin P = decidable_of_iff (∀ (k : Nat) (h : k < n), P ⟨k, h⟩) ⋯
Equations
Tail-recursive runtime replacement for decidableExistsLT.
Equations
- n.decidableExistsLTTR = decidable_of_iff ((n.anyLTTR fun (i : Nat) (x : i < n) => decide (p i)) = true) ⋯
Instances For
Dependent version of decidableExistsLT.
Tail-recursive runtime replacement for decidableExistsLT'.
Equations
- Nat.decidableExistsLT'TR = decidable_of_iff ((k.anyLTTR fun (i : Nat) (h : i < k) => decide (p i h)) = true) ⋯
Instances For
Dependent version of decidableExistsLE.