The first question I’d like to ask is that in cryptocontext.h I see the EvalMult function described as Evaluate approximate division function 1/x where x >= 1 on a ciphertext using the Chebyshev approximation. But in MWE I used x= -5 to do the calculation without any error and the result was calculated (but incorrectly). Is this allowed behavior or a bug?
The second question is whether I have set this parameter incorrectly and when I change x to 5 the calculation is still incorrect. I don’t think the upper and lower bounds for MWE are set incorrectly. Is the result error because of the degree issue?
Here is a MWE that reproduces the issue:
int main() {
uint32_t multDepth = 5;
uint32_t scaleModSize = 58;
uint32_t batchSize = 8;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetMultiplicativeDepth(multDepth);
parameters.SetScalingModSize(scaleModSize);
parameters.SetBatchSize(batchSize);
CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(KEYSWITCH);
cc->Enable(LEVELEDSHE);
cc->Enable(ADVANCEDSHE);
std::cout << "CKKS scheme is using ring dimension " << cc->GetRingDimension() << std::endl << std::endl;
auto keys = cc->KeyGen();
cc->EvalMultKeyGen(keys.secretKey);
cc->EvalRotateKeyGen(keys.secretKey, {1, -2});
std::vector<double> x1 = {-5};
Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(x1);
// Plaintext ptxt2 = cc->MakeCKKSPackedPlaintext(x2);
std::cout << "Input x1: " << ptxt1 << std::endl;
// std::cout << "Input x2: " << ptxt2 << std::endl;
auto c1 = cc->Encrypt(keys.publicKey, ptxt1);
// auto c2 = cc->Encrypt(keys.publicKey, ptxt2);
double lowerBound = -10;
double upperBound = 10;
// std::complex<double> invalid_coefficient(std::nan(""), 0.0);
std::vector<double> coefficients = {1e-10, -1.0e-10};
auto result = cc->EvalDivide(c1, lowerBound, upperBound, 1);
Plaintext res;
std::cout.precision(8);
std::cout << std::endl << "Results of homomorphic computations: " << std::endl;
cc->Decrypt(keys.secretKey, result, &res);
res->SetLength(1);
std::cout << res << std::endl;
return 0;
}
I would really appreciate any insights or explanations regarding this behavior.
Thank you for your help!
Best regards,
wowblk