Index Mathematics Conjectures nbv lettuce Widgets

if_lt!

Run a block if one static scalar is less than another. Control flow

if_lt! lhs, rhs { ... }

Compares two static scalars as integers and runs the block once, in a fresh inner scope, if lhs < rhs. Elements compare by their canonical value in [0, p), so 0 - 1 is the largest value, not a negative one.

Arguments

lhs, rhs
Static scalars or witness constants.
{ ... }
Required block. It may not end in a final expression; it can assign mut variables, including static mut ones, of the enclosing scopes.

Returns

Nothing, it is used as a statement.

Constraints

None of its own. Behaves the same in the static VM.

Example

(let x)
# take at most 3 elements
static mut take = len! x
if_lt! 3, take {
  take = 3
}
sum(slice_from_start(x, take))

Notes

Used in the standard library

blake3/blake3_core, ext/ext_mul, keccak/keccak_sponge_shake, lattice/lattice_digest, lattice/lattice_expand, milli/mldsa/mldsa_reduce, mldsa/mldsa_div_rem_q, mldsa/mldsa_hint_unpack, oraccle/oraccle_squeeze, slip/slip_mask_transcript, slip/slip_r1cs_arg_verify, sym_mat_index, typed/typed_bytes_check, typed/typed_lattice_digest_bits, typed/typed_lex_width, typed/typed_varint_static, typed/typed_width