GenerateLUTviaFunction() must have 2 parameters?

I found in the official example that the function to be generated must have two parameters, and I didn’t see how p1 was specified. How does this example perform modular operations for different values of p1?

auto fp = [](NativeInteger m, NativeInteger p1) -> NativeInteger {
        if (m < p1)
            return (m * m * m) % p1;
        else
            return ((m - p1 / 2) * (m - p1 / 2) * (m - p1 / 2)) % p1;
};     // Generate LUT from function f(x)
    auto lut = cc.GenerateLUTviaFunction(fp, p);

The inputs and outputs to the LUT need to be supported by the plaintext of the FHEW scheme, which is why the function fp also takes in a second argument corresponding to a plaintext modulus p1. In that example, p1 is set to be equal to p, the FHEW plaintext modulus, but there can be scenarios where the output of the function fp is desired to be smaller than the FHEW plaintext modulus, so one can choose p1 < p.

1 Like

Thank you for your answer. I am still a beginner, and I was wondering if it is possible to write fp function in this way?

auto fp = [](NativeInteger m, NativeInteger p1) -> NativeInteger {
        if (m < p1)
            return  p1;
        else
            return m;
};  

Since p1 is akin to the plaintext modulus, the output of fp should be less than p1, which is not what happens in your function because of the else statement.