floating_point.basic_functions module¶
Module that extends the functions available for secure integers, fixed-point numbers and floating-point numbers.
- floating_point.basic_functions.anorm(to_reduce, apply_sign=True)[source]¶
Secure function that securely calculates 1/2**k, k for k such that to_reduce / 2**k is in the domain [0.5, 1)
- Parameters:
to_reduce (
TypeVar(SecureNumberT, bound=SecureNumber)) – the number to be normalized.apply_sign (
bool) – whether the normalization factor should preserve the sign.
- Return type:
tuple[TypeVar(SecureNumberT, bound=SecureNumber),TypeVar(SecureNumberT, bound=SecureNumber)]- Returns:
A tuple containing the secret-shared normalization factor 1/2**k and the secret-shared bit length k.
- Raises:
ValueError – When the secure type has not been initialized properly.
- floating_point.basic_functions.exp2_fxp_integral(exponent, int_size=None)[source]¶
Secure base-2 exponentiation of the input.
- Parameters:
exponent (
SecureFixedPoint) – exponent of the exponentiation. It is assumed that the value is integer. if a non-integer fixed-point number is provided as input, there is a chance the wrong answer is returned.int_size (
int|None) – upper-bound on the bit length of the input value. This helps make the calculations more efficient.
- Return type:
SecureFixedPoint- Returns:
The base-2 exponentation of the exponent.
- floating_point.basic_functions.exp2_int(exponent, int_size=None)[source]¶
Secure base-2 exponentiation of the input.
- Parameters:
exponent (
SecureInteger) – Exponent of the exponentiation. It is assumed that the value is a secure Integer. If the value is negative, the multiplicative inverse of 2**(-exponent) is calculated.int_size (
int|None) – Upper bound on the bit length of the input value. This helps make the calculations more efficient.
- Return type:
SecureInteger- Returns:
The base-2 exponentation of the exponent.
- floating_point.basic_functions.exp2_int_pos(exponent, int_size=None)[source]¶
Secure base-2 exponentiation of the input.
- Parameters:
exponent (
SecureInteger) – exponent of the exponentiation. It is assumed that the value is integer and positive. if a non-integer fixed-point number is provided as input, there is a chance the wrong answer is returned. If a negative value is provided as input, the answer will be wrong.int_size (
int|None) – upper-bound on the bit length of the input value. This helps make the calculations more efficient.
- Return type:
SecureInteger- Returns:
The base-2 exponentation of the exponent.
- floating_point.basic_functions.integer(value)[source]¶
Function that securely truncates a number to its integer part.
- Parameters:
value (
TypeVar(SecureNumberT, bound=SecureNumber)) – The secure number.- Return type:
TypeVar(SecureNumberT, bound=SecureNumber)- Returns:
the floor function securely applied to value (similar to int).
- floating_point.basic_functions.ln_small(value)[source]¶
Secure natural logarithm approximation of the input value in the domain [0.5, 1).
- Parameters:
value (
SecureFixedPoint) – Secure fixed point number in the range [0.5, 1)- Return type:
SecureFixedPoint- Returns:
secure fixed point containing an approximation of the natural logarithm of the provided input value
- floating_point.basic_functions.log_flp(secure_flp, secfxp_type)[source]¶
Base-2 logarithm of a secure floating point number. This method abuses the structure of secure floating point numbers to obtain a more efficient solution than the Taylor approximation. During this process, the significand needs to be converted from a secure integer to a secure fixed point to enable a base-2 logarithm subroutine for fixed points.
- Parameters:
secure_flp (
SecureFloatingPoint) – Secure floating point number.secfxp_type (
type[SecureFixedPoint]) – Secure fixed point type that is used in the conversion.
- Return type:
SecureFloatingPoint- Returns:
Secure floating point number containing the base-2 logarithm of the input value.
- Raises:
ValueError – Significand has smaller bit length than exponent.
- floating_point.basic_functions.log_fxp(value, base)[source]¶
Secure logarithm of a secure fixed point number in a public base
- Parameters:
base (
int|float) – plaintext base of the logarithm.value (
SecureFixedPoint) – Secure fixed point number of which the logarithm is taken with respect to the base.
- Return type:
SecureFixedPoint- Returns:
Secure fixed point number containing the natural logarithm of the input in the given base
- floating_point.basic_functions.natural_log(value)[source]¶
Secure natural logarithm of a secure fixed point.
- Parameters:
value (
SecureFixedPoint) – Secure fixed point number- Return type:
SecureFixedPoint- Returns:
Secure fixed point number containing the natural logarithm of the input
- floating_point.basic_functions.parity(value)[source]¶
Function that securely calculates the parity of the integer part of the given secure number.
- Parameters:
value (
TypeVar(SecureNumberT, bound=SecureNumber)) – The secure number.- Return type:
TypeVar(SecureNumberT, bound=SecureNumber)- Returns:
The parity of the integer part of the secure number.
- floating_point.basic_functions.poly_approximation(coefficients, value)[source]¶
Function for securely approximating a certain function using a polynomial
- Parameters:
coefficients (
list[int] |list[float]) – List of polynomial coefficients. The coefficients go from degree zero upward. e.g. coefficients[i] correspond to the term of degree i.value (
TypeVar(SecureNumberT, bound=SecureNumber)) – value to be evaluated
- Return type:
TypeVar(SecureNumberT, bound=SecureNumber)- Returns:
The polynomial evaluation of value with respect to the coefficients.
- Raises:
TypeError – When the first coefficient is not compatible with the secure type.
- floating_point.basic_functions.sqrt_flp(secure_flp, secfxp_type)[source]¶
Square root of a secure floating point number. This method abuses the structure of secure floating point numbers to obtain a more efficient solution than the Taylor approximation. During this process, the significand needs to be converted from a secure integer to a secure fixed point to enable a square root subroutine for fixed points.
- Parameters:
secure_flp (
SecureFloatingPoint) – Secure floating point number.secfxp_type (
type[SecureFixedPoint]) – Secure fixed point type that is used in the conversion.
- Return type:
SecureFloatingPoint- Returns:
Secure floating point number containing the square root of the input value.
- floating_point.basic_functions.sqrt_fxp(value)[source]¶
Secure square root of the input value.
- Parameters:
value (
SecureFixedPoint) – Secure fixed point number- Return type:
SecureFixedPoint- Returns:
secure fixed point number containing the square root of the input
- floating_point.basic_functions.sqrt_small(value)[source]¶
Secure approximation of the square root in the domain [0.5,1).
- Parameters:
value (
SecureFixedPoint) – Secure fixed point number- Return type:
SecureFixedPoint- Returns:
secure fixed point number containing an approximation of the square root of the input value