# GenerateLUTviaFunction() must have 2 parameters?

**URL:** <https://openfhe.discourse.group/t/generatelutviafunction-must-have-2-parameters/1227>\
**Category:** Library Questions\
**Created:** [April 24, 2024, 7:18am UTC](https://openfhe.discourse.group/t/generatelutviafunction-must-have-2-parameters/1227 "2024-04-24T07:18:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![capibala](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@capibala](https://openfhe.discourse.group/u/capibala)\
**Post date:** [April 24, 2024, 7:18am UTC](https://openfhe.discourse.group/t/generatelutviafunction-must-have-2-parameters/1227/1 "2024-04-24T07:18:40Z")

</div>

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
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);

```

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [April 24, 2024, 5:03pm UTC](https://openfhe.discourse.group/t/generatelutviafunction-must-have-2-parameters/1227/2 "2024-04-24T17:03:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![capibala](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@capibala](https://openfhe.discourse.group/u/capibala)\
**Post date:** [April 26, 2024, 7:22am UTC](https://openfhe.discourse.group/t/generatelutviafunction-must-have-2-parameters/1227/3 "2024-04-26T07:22:18Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [April 26, 2024, 1:58pm UTC](https://openfhe.discourse.group/t/generatelutviafunction-must-have-2-parameters/1227/4 "2024-04-26T13:58:08Z")

</div>

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.
