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:
Nat.fold 3 f init = (init |> f 0 (by simp) |> f 1 (by simp) |> f 2 (by simp))Nat.fold 4 (fun i _ xs => xs.push i) #[] = #[0, 1, 2, 3]Nat.fold 0 (fun i _ xs => xs.push i) #[] = #[]
Equations
Instances For
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
Instances For
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) #[] = #[]
Equations
Instances For
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) = trueNat.anyTR 7 (fun i _ => i < 5) = trueNat.anyTR 7 (fun i _ => i % 2 = 0) = trueNat.anyTR 1 (fun i _ => i % 2 = 1) = false
Equations
- n.anyTR f = Nat.anyTR.loop✝ n f n ⋯
Instances For
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) = trueNat.allTR 7 (fun i _ => i < 5) = falseNat.allTR 7 (fun i _ => i % 2 = 0) = falseNat.allTR 1 (fun i _ => i % 2 = 0) = true
Equations
- n.allTR f = Nat.allTR.loop✝ n f n ⋯
Instances For
csimp theorems #
Nat.dfold evaluates f on the numbers up to n exclusive, in increasing order:
Nat.dfold f 3 init = init |> f 0 |> f 1 |> f 2The input and output types offare indexed by the current index, i.e.f : (i : Nat) → (h : i < n) → α i → α (i + 1).
Equations
- n.dfold f init = Nat.dfold.loop✝ n f n ⋯ (Nat.dfoldCast✝ α ⋯ init)
Instances For
Nat.dfoldRev evaluates f on the numbers up to n exclusive, in decreasing order:
Nat.dfoldRev f 3 init = f 0 <| f 1 <| f 2 <| initThe input and output types offare indexed by the current index, i.e.f : (i : Nat) → (h : i < n) → α (i + 1) → α i.
Equations
Instances For
Theorems #
Combines an initial value with each natural number from a range, in increasing order.
In particular, (start, stop).foldI f init applies fon all the numbers
from start (inclusive) to stop (exclusive) in increasing order:
Examples:
(5, 8).foldI (fun j _ _ xs => xs.push j) #[] = (#[] |>.push 5 |>.push 6 |>.push 7)(5, 8).foldI (fun j _ _ xs => xs.push j) #[] = #[5, 6, 7](5, 8).foldI (fun j _ _ xs => toString j :: xs) [] = ["7", "6", "5"]
Equations
Instances For
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:
(5, 8).anyI (fun j _ _ => j == 6) = (5 == 6) || (6 == 6) || (7 == 6)(5, 8).anyI (fun j _ _ => j % 2 = 0) = true(6, 6).anyI (fun j _ _ => j % 2 = 0) = false
Instances For
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:
(5, 8).allI (fun j _ _ => j < 10) = (5 < 10) && (6 < 10) && (7 < 10)(5, 8).allI (fun j _ _ => j % 2 = 0) = false(6, 7).allI (fun j _ _ => j % 2 = 0) = true