Skip to content
YUENIX-FHEContact
Preview documentation. The YUENIX-FHE 1.0 API is in development and names or signatures may change before release. Request an evaluation

Encrypted comparison

Comparison is not a native CKKS operation. YUENIX evaluates it with polynomial approximations of the sign function, combined with functional bootstrapping. Every comparison program declares an input range and a minimum separation. Inputs closer together than that separation may compare either way.

Function Result
yuenix_compare(a, b) encrypted 1 where a > b, 0 otherwise, slot by slot
yuenix_less_than(a, t) encrypted 1 where a < t, for a public threshold t
yuenix_min, yuenix_max encrypted minimum or maximum across slots
yuenix_argmax encrypted one-hot mask of the maximum
yuenix_rank encrypted rank of each slot
yuenix_topk_mask encrypted mask of the k largest slots
yuenix_sort encrypted values in ascending order

In 1.0 the ranking and sorting programs work on up to 128 values. Inputs must lie in [0, 1], and the count must be a power of two. Shorter inputs are padded automatically. Scale other ranges into [0, 1] with mul_scalar and add_scalar before comparing.

Equal inputs keep their original order. Inputs that are distinct but closer than the program’s tie band are not guaranteed to be ordered correctly. Each program reports its tie band through yuenix_plan_query.

plan = ctx.plan(yuenix.Profile.CI_SLIM64, program=yuenix.Sort(count=64))
keys = plan.generate_keys(); ev = keys.evaluator()
x = keys.encrypt(values) # 64 reals in [0, 1]
s = ev.sort(x)
print(keys.decrypt(s)[:64].real)