ChebyshevFunction evaluation error

Hi, I am using ChebyshevFunction to evaluate exp(x). But I encountered some error.

My ciphertext - a can be decrypted into:
[ 0.923663 -8.27976e-06 5.00274e-06 -9.2856e-06 -2.67874e-06 0.950437 0.999738 0.999993 -1.93079e-05 7.29427e-06 -1.34528e-05 -1.0477e-05 2.14772e-06 4.70038e-06 6.8613e-06 -1.6628e-05 1.68422e-05 -8.30343e-06 -1.22689e-05 9.37811e-06 ]
My ChebyshevFunction usage is:

    double lowerBound = -1.0;
    double upperBound = 1.0;
    uint32_t polyDegree = 27;
    a = cc->EvalBootstrap(a);
    a = cc->EvalChebyshevFunction([](double x) -> double { return std::exp(x); }, a, lowerBound,
                                              upperBound, polyDegree);

My firstModSize is 42, the multiple depth for the whole program is 14, scale factor is 35.
But I received the following error when trying to decrypt:
The decryption failed because the approximation error is too high. Check the parameters.

firstModSize and scaling factor are way too small for the bootstrapping and a precise polynomial evaluation, try to use larger values (as the ones in the examples)

Thanks for your fast reply. I am using small values because I need to use some rotation keys for this program (other parts of the program), and they have large memory sizes. To use larger parameters, I need to find out how to reduce key sizes. (I created a new topic to follow up on that) Is there a walkaround on the Chebyshev Function side? Are there ways to estimate the required first mode size and scale factor for the Chebyshev Function?

I think that the ciphertext is already “done” after the bootstrapping, try to print it before the chebyshev evaluation.

Hi, my ciphertext is printed before bootstrapping, it comes from other parts of my program. Essentially, the ciphertext a in a = cc->EvalBootstrap(a); contains the value [ 0.923663 -8.27976e-06 5.00274e-06 -9.2856e-06 -2.67874e-06 0.950437 0.999738 0.999993 -1.93079e-05 7.29427e-06 -1.34528e-05 -1.0477e-05 2.14772e-06 4.70038e-06 6.8613e-06 -1.6628e-05 1.68422e-05 -8.30343e-06 -1.22689e-05 9.37811e-06 ].

Yeah, but is it (almost) the same before and after the bootstrap?

Thanks for asking that, it raises a good point, when I try to decrypt after Bootstrap as following:

cout << "ChebyshevFunction begin" << endl;
    double lowerBound = -2.0;
    double upperBound = 2.0;
    uint32_t polyDegree = 27;
    a = cc->EvalBootstrap(a);

    Plaintext outcome;
    cc->Decrypt(keys.secretKey, a, &outcome);
    outcome->SetLength(20);
    auto dec_outcome = outcome->GetRealPackedValue();
    cout << "After bootstrapping" << ": ";
    cout << dec_outcome << endl;  
    cout << endl;

I will also get the error: The decryption failed because the approximation error is too high. Check the parameters.

The larger piece of my program follows like this:

        auto a = cc->EvalMult(x1, x2);

        Plaintext outcome;
        cc->Decrypt(keys.secretKey, a, &outcome);
        outcome->SetLength(20);
        auto dec_outcome = outcome->GetRealPackedValue();
        cout << "[Debug]" << ": ";
        cout << dec_outcome << endl;  
        cout << endl;

        double lowerBound = -1.0;
        double upperBound = 1.0;
        uint32_t polyDegree = 27;
        a = cc->EvalBootstrap(a);
        Plaintext outcome2;
        cc->Decrypt(keys.secretKey, a, &outcome2);
        outcome->SetLength(20);
        auto dec_outcome2 = outcome2->GetRealPackedValue();
        cout << "[Debug]" << ": ";
        cout << dec_outcome2 << endl;  
        cout << endl;

        a = cc->EvalChebyshevFunction([](double x) -> double { return std::exp(x); }, a, lowerBound, upperBound, polyDegree);
        

You should increase firstModSize and dcrtBits (CKKS Bootstrapping gives incorrect results on scale != 60? - #4 by ypolyakov)