Index Mathematics Conjectures nbv lettuce Widgets

poly_norm_inf

stdlib/polynomial/poly_norm_inf.nbv

poly_norm_inf(N, poly, static bitlen)

returns the coefficient with the largest norm

Calls
bits/from_bits_static, bits/lt_bits, bits/to_bits_exact, bits/to_bits_exact_static, valloc
Precompiles
assert_eq!, clone!, len!, loop!

Source

# returns the coefficient with the largest norm
(N, poly, static bitlen)

assert_eq! N, len! poly

static midpoint = from_bits_static(valloc(bitlen - 1, 1))
let midpoint_bits = to_bits_exact_static(midpoint, bitlen)

let mut out = 0

loop! N, i {
  let v = poly[i] + midpoint
  let v_bits = to_bits_exact(v, bitlen)

  let is_positive = 1 - lt_bits(v_bits, clone! midpoint_bits)
  let abs_norm = ((v - midpoint) * is_positive) + ((1 - is_positive) * (0 - (v - midpoint))) 
  let is_lt = lt_bits(to_bits_exact(abs_norm, bitlen), to_bits_exact(out, bitlen))
  out = is_lt * out + (1 - is_lt) * abs_norm
}

out