Index Mathematics Conjectures nbv lettuce Widgets

split_at!

Split a vector into the elements before and from an index, as a tuple. Vectors

split_at! vector, index

Splits a vector into two parts, 0 .. index and index .. len, returned as a two element tuple. It is typically used to peel fixed size pieces off the front of a long vector.

Arguments

vector
Any expression, static or witness. A named variable is moved.
index
Static scalar, the length of the first part.

Returns

A tuple (head, tail) with the location of the input, to be destructured with a tuple assignment. split_at! is an expression.

Constraints

None.

Example

(let x)
(let head, let tail) = split_at! x, 2
(sum(head), tail)

Notes

The index is not bounds checked by the precompile: an index larger than the vector length panics in the compiler instead of returning an error. The tail can be assigned back to the same name to consume a vector piece by piece: (let a, let arg) = split_at! arg, n. The standard library function split_at does the same with slices, taking the index first: split_at(index, vector).

Used in the standard library

bdlop/bdlop_linear_nizk_verify, mersenne61/poseidon/poseidon_mersenne61_state, milli/poseidon/poseidon_milli_state