map_sum!
Sum the elements of a vector, or the values a block returns for each element. Loops and mapping
map_sum! vector[, v[, i]] [{ ... }]
Without a block, returns the sum of the elements of vector as a scalar. With a block, runs it once per element with v bound to the element and the optional counter to its static index, each in a fresh inner scope, and adds the block values element-wise.
Arguments
vector- Static or witness vector.
v- Required with a block, not allowed without one. A bare variable name bound to the current element.
i- Optional. A bare variable name bound to the static element index.
{ ... }- Optional block ending in a final expression, a non-empty vector of the same length for every element.
Returns
The sum, an expression; a witness if any summed value is a witness.
Constraints
None; sums are linear. Behaves the same in the static VM.
Example
(let x) map_sum! x, v { v * v }
(let x) map_sum! x
Notes
- Without a block exactly one argument is allowed.
- An empty input sums to the empty vector.