I tried to implement the algorithm for approximating the square root from https://eprint.iacr.org/2019/417.pdf Section 3.2
I know i can use chebyshev approximation but i tried to experiment with alternatives.
auto ct_a = ctScaledSquares; // vector of downscaled values to meet the condition for 0 ≤ x ≤ 1
auto ct_b = cc->EvalSub(ct_a, 1);
int d = 15; // higher d consumes more levels and results in smaller values for every n
for (int n = 0; n < d; n++) {
auto ct1 = cc->EvalMult(cc->EvalSub(1, ct_b), 0.5);
ct_a = cc->EvalMult(ct_a, ct1);
cout << ct_a->GetLevel() << endl;
auto ct2 = cc->EvalMult(cc->EvalSub(ct_b, 3), 0.25);
ct_b = cc->EvalMult(cc->EvalSquare(ct_b), ct2);
cout << ct_b->GetLevel() << endl;
}
Did i forget something in that code? I am getting incorrect results and the approximation gets smaller with every iteration, so a higher d
will result in smaller values.