FunctionEvaluator#

class FunctionEvaluator#

This class is used to evaluate different available functions on CTiles, such as approximate inverse function.

compare(self: pyhelayers.FunctionEvaluator, a: pyhelayers.CTile, b: pyhelayers.Tile, g_rep: int, f_rep: int, max_possible_abs_of_diff: float) pyhelayers.CTile#

Comparison of two numbers. This method compares two numbers a and b and return 1 if a>b, 0 if b<a and 0.5 if a==b by calculating sign(a-b).

Parameters:
  • a (CTile) – First ciphertext to compare

  • b (CTile) – Second ciphertext to compare

  • g_rep (int) – How many repetitions of g(x) See further explanation in sign()

  • f_rep (int) – How many repetitions of f(x) See further explanation in sign()

  • max_possible_abs_of_diff (double) – An upper upper bound on |a-b|. The tighter this bound is, the more accurate the result will be.

compareInPlace(self: pyhelayers.FunctionEvaluator, a: pyhelayers.CTile, b: pyhelayers.Tile, g_rep: int, f_rep: int, max_possible_abs_of_diff: float) None#

Comparison of two numbers. This method compares two numbers a and b and return 1 if a>b, 0 if b<a and 0.5 if a==b by calculating sign(a-b).

Parameters:
  • a – First CTile to compare

  • b – Second Tile to compare

  • g_rep (int) – How many repetitions of g(x) See further explanation in sign()

  • f_rep (int) – How many repetitions of f(x) See further explanation in sign()

  • max_possible_abs_of_diff (double) – An upper upper bound on |a-b|. The tighter this bound is, the more accurate the result will be.

inverse_positive(self: pyhelayers.FunctionEvaluator, src: pyhelayers.CTile, lower_bound: float, upper_bound: float, bit_resolution: int = 5) pyhelayers.CTile#

Calculates (an approximation of) 1/src. src must be between lower_bound and upper_bound, and lower_bound must be non-negative. The tighter the given bounds are, the more accurate the result will be. For more details, see “Homomorphic Encryption for Arithmetic of Approximate Numbers” paper, p. 15: https://eprint.iacr.org/2016/421.pdf.

Parameters:
  • src (CTile) – Ciphertext to calculate its inverse.

  • lower_bound (double) – a lower bound on src. The tighter this bound is, the more accurate the result will be. This lower bound must be non-negative.

  • upper_bound (double) – an upper upper bound on src. The tighter this bound is, the more accurate the result will be.

  • bit_resolution – Controls the accuracy of the result. A higher bit_resolution value will increase the accuracy of the result at the account of consuming more multiplication depth. Defaults to 5.

one_hot(self: pyhelayers.FunctionEvaluator, src: pyhelayers.CTile, possible_values: numpy.ndarray[numpy.float64]) pyhelayers.CTileVector#

Given ciphertext src and a list possible_values of the possible values inside src, calculates possible_values indicator ciphertexts that indicates which slots in src contain the corresponding value. Formally, the i’th indicator ciphertext contains 1 in slot j only if src[j]=possible_values[i], and 0 otherwise.

Parameters:
  • src (CTile) – The source ciphertext

  • possible_values (list) – A list of doubles contain the possible values inside src

sign(self: pyhelayers.FunctionEvaluator, a: pyhelayers.CTile, g_rep: int, f_rep: int, max_abs_val: float = 1, binary_res: bool = False) pyhelayers.CTile#

Returns the (approximated) sign of a. The sign is computed as the g(g(…g(f(f(…f(x)))))), where g(x) and f(x) are two degree 7 polynomials. The number of times g(x) and f(x) appear in the composition can be controlled by g_rep and f_rep arguments, respectively. a must be in the range [-max_abs_val, max_abs_val].

Parameters:
  • a (CTile) – Ciphertext we want to find its sign. a must be in the range [-max_abs_val, max_abs_val].

  • g_rep (int) – How many repetitions of g(x)

  • f_rep (int) – How many repetitions of f(x)

  • max_abs_val (double) – An upper bound on the absolute value of a. Defaults to 1.

  • binary_res (boolean) – If true the result will be close to 0 when a < 0 and close to 1 when a > 0. If false, the result will be close to -1 when a < 0 and close to 1 when a > 0. Defaults to false.