# Chebyshev fails for degree 6

**URL:** <https://openfhe.discourse.group/t/chebyshev-fails-for-degree-6/1268>\
**Category:** Library Questions\
**Tags:** bugs\
**Created:** [May 15, 2024, 1:40pm UTC](https://openfhe.discourse.group/t/chebyshev-fails-for-degree-6/1268 "2024-05-15T13:40:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lujoho](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@lujoho](https://openfhe.discourse.group/u/lujoho)\
**Post date:** [May 15, 2024, 1:40pm UTC](https://openfhe.discourse.group/t/chebyshev-fails-for-degree-6/1268/1 "2024-05-15T13:40:33Z")

</div>

Hello together,

we are currently benchmarking different kinds of polynomial approximations and found some strange patterns in our data.  
We are doing Chebyshev Evaluations with EvalChebyshevFunction and it works perfectly fine except for one certain degree. For degree 6 the results are off by a lot. At first we thought this was a problem with the parameters or that the degree is too low to obtain a good accuracy as mentioned in other posts. But this seems not to be the case since the values are reasonably precise for degree 5 and 7. Even when evaluating more and higher degrees, the problem only does not occur again. So only the sixth degree seems to have a problem.

The following is a MWE where the error occurs:

```auto
    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetSecretKeyDist(UNIFORM_TERNARY);
    parameters.SetSecurityLevel(lbcrypto::HEStd_128_classic);
    parameters.SetMultiplicativeDepth(10);
    parameters.SetScalingModSize(30);
    parameters.SetBatchSize(8);
    CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
    cc->Enable(PKE);
    cc->Enable(FHE);
    cc->Enable(LEVELEDSHE);
    cc->Enable(ADVANCEDSHE);
    auto keyPair = cc->KeyGen();
    cc->EvalMultKeyGen(keyPair.secretKey);

    vector<double> vals = {1,2,3,4,5,6,7,8};
    Plaintext ptx = cc ->MakeCKKSPackedPlaintext(vals);
    Ciphertext<DCRTPoly> c = cc ->Encrypt(keyPair.publicKey, ptx);
    for(int i = 1; i<11; i++){
       auto res = cc ->EvalChebyshevFunction([](double val) -> double{return std::sqrt(val);},c,1,8,i);
       Plaintext out;
       cc ->Decrypt(keyPair.secretKey, res, &out);
       std::cout << out << std::endl;
    } 

```

We also tried different functions, not only the square root, but the problem occurred for all of them.  
Is this a bug?

---

<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:** [May 15, 2024, 11:07pm UTC](https://openfhe.discourse.group/t/chebyshev-fails-for-degree-6/1268/2 "2024-05-15T23:07:20Z")

</div>

Thank you for reporting this. At a first glance, it seem to be a weird bug.  
I ran the Chebyshev evaluation with the linear evaluation technique instead of the Paterson-Stockmeyer technique and it was returning the correct results. But the Paterson-Stockmeyer parameters are also chosen correctly. The same behavior is observed for the identity function, which for all purposes should be the same for degree 6 and degree 7.  
It seems that when fixing the inputs and the interval, a constant value is added for degree 6 regardless of the evaluated function. We will look into this.

---

<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:** [May 16, 2024, 1:48am UTC](https://openfhe.discourse.group/t/chebyshev-fails-for-degree-6/1268/3 "2024-05-16T01:48:06Z")

</div>

We identified the bug and will fix it soon and add it to 1.1.5. Thanks again for pointing this out.

---

<div class="post-metadata">

**Author:** ![lujoho](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@lujoho](https://openfhe.discourse.group/u/lujoho)\
**Post date:** [May 16, 2024, 12:26pm UTC](https://openfhe.discourse.group/t/chebyshev-fails-for-degree-6/1268/4 "2024-05-16T12:26:40Z")

</div>

Thank you for your quick answer and the confirmation of the bug
