How to evaluate approximate 1/x function with high precision

By setting the bounds to [1, 4] you will get almost perfect results:

Actual output
	[ 1 0.5 0.333333 0.25 ]

Of course, encode your values in a four-slots plaintexts:

Plaintext plaintext  = cc->MakeCKKSPackedPlaintext(input,1, 0, nullptr, 4);

Otherwise you would have a lot of zeros, which are not included in your interval.

In order to understand why this happens, think about 1 /x near zero:

y-1-x

Using polynomials to approximate that interval is really a hard problem, also because that function does not even exist in 0!
If you instead approximate it starting from 1 (or maybe also from 0.2/0.3, something like that) you will have less issues for sure.

1 Like