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
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)
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
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 ⋯)
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
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 ⋯)
Instances For
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 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