Index Mathematics Conjectures nbv lettuce Widgets

loop_map_sum!

Sum the values a block returns over a static number of iterations. Loops and mapping

loop_map_sum! count[, i] { ... }

Runs the block count times, each time in a fresh inner scope with the optional counter bound to the static iteration index, and adds the block's final expressions element-wise. All block values must have the same length.

Arguments

count
Static scalar, the number of iterations.
i
Optional. A bare variable name bound to the static iteration index.
{ ... }
Required block ending in a final expression, a non-empty vector of the same length every iteration.

Returns

The element-wise sum, an expression. Static and witness block values can be mixed, the sum is a witness if any of them is.

Constraints

None; additions are linear. The block's operations add their own. Behaves the same in the static VM.

Example

(let x)
loop_map_sum! 3, i {
  x[i] * x[i]
}

Notes

Used in the standard library

inner_prod