Index Mathematics Conjectures nbv lettuce Widgets

lt_bits

stdlib/bits/lt_bits.nbv

lt_bits(lhs, rhs)

return 1 if lhs is less than rhs lhs and rhs should both be vectors of bits

Calls
bits/and_bits, bits/xor_bits
Precompiles
assert_eq!, len!, loop!
Used by
polynomial/poly_norm_inf, polynomial/poly_norm_inf_lt, polynomial/poly_norm_l1

Source

# return 1 if lhs is less than rhs
# lhs and rhs should both be vectors of bits
(lhs, rhs)

assert_eq! (len! lhs), (len! rhs)

let mut is_lt = 0
let mut found_diff = 0

loop! (len! lhs), i {
  # iterate in reverse because the inputs are little endian
  static i = (len! lhs) - i - 1
  let is_diff = xor_bits(lhs[i], rhs[i])
  let is_first_diff = and_bits(1 - found_diff, is_diff)
  let bit_lt = and_bits(1 - lhs[i], rhs[i])

  is_lt = is_lt + is_first_diff * bit_lt
  found_diff = found_diff + is_first_diff
}

is_lt