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:
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:
Nat.foldTR 3 f init = (init |> f 0 (by simp) |> f 1 (by simp) |> f 2 (by simp))
Nat.foldTR 4 (fun i _ xs => xs.push i) #[] = #[0, 1, 2, 3]
Nat.foldTR 0 (fun i _ xs => xs.push i) #[] = #[]
Equations
- n.foldTR f init = Nat.foldTR.loop n f n ⋯ init
Equations
- Nat.foldTR.loop n f 0 h x = x
- Nat.foldTR.loop n f m.succ h x = Nat.foldTR.loop n f m ⋯ (f (n - m.succ) ⋯ x)
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:
Nat.foldRev 3 f init = (f 0 (by simp) <| f 1 (by simp) <| f 2 (by simp) init)
Nat.foldRev 4 (fun i _ xs => xs.push i) #[] = #[3, 2, 1, 0]
Nat.foldRev 0 (fun i _ xs => xs.push i) #[] = #[]
Checks whether there is some number less that the given bound for which f
returns true
.
Examples:
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:
Nat.anyTR 4 (fun i _ => i < 5) = true
Nat.anyTR 7 (fun i _ => i < 5) = true
Nat.anyTR 7 (fun i _ => i % 2 = 0) = true
Nat.anyTR 1 (fun i _ => i % 2 = 1) = false
Equations
- n.anyTR f = Nat.anyTR.loop n f n ⋯
Equations
- Nat.anyTR.loop n f 0 h = false
- Nat.anyTR.loop n f m.succ h = (f (n - m.succ) ⋯ || Nat.anyTR.loop n f m ⋯)
Checks whether f
returns true
for every number strictly less than a bound.
Examples:
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:
Nat.allTR 4 (fun i _ => i < 5) = true
Nat.allTR 7 (fun i _ => i < 5) = false
Nat.allTR 7 (fun i _ => i % 2 = 0) = false
Nat.allTR 1 (fun i _ => i % 2 = 0) = true
Equations
- n.allTR f = Nat.allTR.loop n f n ⋯
Equations
- Nat.allTR.loop n f 0 h = true
- Nat.allTR.loop n f m.succ h = (f (n - m.succ) ⋯ && Nat.allTR.loop n f m ⋯)
csimp theorems #
Combines an initial value with each natural number from in a range, in increasing order.
In particular, (start, stop).foldI f init
applies f
on all the numbers
from start
(inclusive) to stop
(exclusive) in increasing order:
Examples:
Checks whether a predicate holds for any natural number in a range.
In particular, (start, stop).allI f
returns true if f
is true for any natural number from
start
(inclusive) to stop
(exclusive).
Examples:
Checks whether a predicate holds for all natural numbers in a range.
In particular, (start, stop).allI f
returns true if f
is true for all natural numbers from
start
(inclusive) to stop
(exclusive).
Examples: