Index Mathematics Conjectures nbv lettuce Widgets

slice!

A contiguous sub-vector of a vector. Vectors

slice! vector, start, [len]

Returns the elements start .. start + len of a vector. Without len the slice runs to the end of the vector. Slicing is free: the result refers to the same witness entries or static values.

Arguments

vector
Any expression, static or witness. A named variable is moved (unless it is a scalar), so use (clone! v) to keep using it, or slice_ref!.
start
Static scalar, the first index.
len
Optional static scalar, the number of elements. Defaults to len! vector - start.

Returns

A vector of length len with the location (static or witness) of the input. slice! is an expression.

Constraints

None.

Example

(let x)
let mid = slice((clone! x), 1, 2)
let tail = slice! x, 3
(sum(mid), tail)

Notes

Errors if start + len exceeds the length of the vector. The standard library function slice wraps this precompile with the same arguments, which is convenient inside other precompile arguments: concat! slice(a, 0, 2), slice(b, 0, 2).

Used in the standard library

r1cs/r1cs_assert_field, r1cs/r1cs_into_output, slice, slice_from_start, slice_to_end, split_at