Load libraries that will be used.
Set a working seed for random numbers (so that random numbers can be replicated exactly).
Set some parameters.
Create the (complex) numbers we will encode.
Now we encode the vector of complex numbers to a polynomial.
pi_z <- pi_inverse(z)
scaled_pi_z <- scale * pi_z
rounded_scale_pi_zi <- sigma_R_discretization(xi, M, scaled_pi_z)
p <- sigma_inverse(xi, M, rounded_scale_pi_zi)
coef <- as.vector(round(Re(p)))
p <- polynomial(coef)
Let’s view the result.
Let’s decode to obtain the original number:
rescaled_p <- coef(p) / scale
z <- sigma_function(xi, M, rescaled_p)
decoded_z <-pi_function(M, z)
print(decoded_z)
#> [1] 3.03033+3.737437i 1.96967-1.262563i
The decoded z is indeed very close to the original z, we round the result to make the clearer.
Next, work through the CKKS-encode-2 vignette, which breaks down the encode and decode functions into the individual steps.