Chebyshev fails for degree 6

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:

    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?

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.

1 Like

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

1 Like

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