Definition of smart_max_parallelized(&mut a, &mut b)

Hi all, I have been trying to understand the comparison of two number in TFHE. I have been referring to the tfhe page (link I am not allowed to share being a new user)

use tfhe::integer::gen_keys_radix;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;

fn main() {
    // We generate keys to encrypt 16 bits radix-encoded integers
    // using 8 blocks of 2 bits
    let (cks, sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2, 8);

    let clear_a = 2382u16;
    let clear_b = 29374u16;

    let mut a = cks.encrypt(clear_a as u64);
    let mut b = cks.encrypt(clear_b as u64);

    let encrypted_max = sks.smart_max_parallelized(&mut a, &mut b);
    let decrypted_max: u64 = cks.decrypt(&encrypted_max);

    assert_eq!(decrypted_max as u16, clear_a.max(clear_b))
}

I would love to know how the

smart_max_parallelized(&mut a, &mut b);

works. I could not find the recipe of the function anywhere. I would really appreciate any leads.

Hello @bhavinmoriya58

I saw you asked the same question on the FHE.org discord and the answer there was correct, the code is here: tfhe-rs/tfhe/src/integer/server_key/radix_parallel/comparison.rs at 03431e41a9911b17cde885e0803ec703235792c0 · zama-ai/tfhe-rs · GitHub

Cheers

1 Like