exponentiation.exponent module
Module containing all logic for securely performing exponentiation using the MPyC framework.
- exponentiation.exponent.convert_exponents_to_other_base(old_base, new_base, exponents)[source]
Convert the exponent of a given exponentiation for a given new base so that the result is the same.
More specifically, the following invariant is preserved: \(base_{old}\^exponent == base_{new}\^return_value\)
- Parameters:
old_base (
Union
[int
,float
]) – Original base of the exponentiation.new_base (
float
) – Desired base of the exponentiation.exponents (
List
[TypeVar
(SecureNumberType
, bound=SecureNumber
)]) – List of original exponents.
- Return type:
List
[TypeVar
(SecureNumberType
, bound=SecureNumber
)]- Returns:
List of exponents that satisfy the stated invariant.
- exponentiation.exponent.maximal_exponent(base, stype)[source]
Returns largest exponent x such that base**x fits within the precision of the field.
- Parameters:
base (
float
) – base of the exponentiationstype (
Union
[Type
[SecureFixedPoint
],Type
[SecureInteger
]]) – SecureNumberType class
- Return type:
int
- Returns:
largest exponent x such that base**x fits within the precision of the given types field
- exponentiation.exponent.minimal_exponent(base, stype)[source]
Returns smallest exponent x such that base**x fits within the precision of the field.
- Parameters:
base (
float
) – base of the exponentiationstype (
Union
[Type
[SecureFixedPoint
],Type
[SecureInteger
]]) – SecureNumberType class
- Return type:
int
- Returns:
smallest exponent x such that base**x fits within the precision of the given types field
- exponentiation.exponent.secure_pow(base, exponents, trunc_to_domain=False, lower=None, upper=None, bit_precision=None)[source]
Secure exponentiation.
Computes approximate secret-sharing of base**x for all given secret-shared x in [lower, upper]. May additionally enforce that x is truncated to fit in [lower, upper].
The exponentiation is approximate since it splits the computation into an exact integral computation and a approximate non-integral computation. The approximated part leverages Taylor series.
If exponents are truncated to the feasible domain, for a exponent \(x\), the function returns \(base^{upper}\) if \(x > upper\), \(base^x\) if \(x\in [lower, upper]\), and \(0\) if \(x < lower\).
- Parameters:
base (
float
) – Base of the exponentiation.exponents (
Union
[SecureInteger
,SecureFixedPoint
,TypeVar
(SecureObjectsContainerTV
,List
[SecureInteger
],List
[SecureFixedPoint
])]) – Exponents of the base.lower (
Optional
[float
]) – Lower bound of exponents range, maximized for type(exponents[0]) if None.upper (
Optional
[float
]) – Upper bound of exponents range, maximized for type(exponents[0]) if None.trunc_to_domain (
bool
) – Truncates exponents so that they fall in the given range at cost of additional resources. Additionally ensures that base**[lower] evaluates to [0].bit_precision (
Optional
[int
]) – Bound on relative error of approximation, set to half of fractional bits if None.
- Return type:
Union
[SecureInteger
,SecureFixedPoint
,TypeVar
(SecureObjectsContainerTV
,List
[SecureInteger
],List
[SecureFixedPoint
])]- Returns:
Secret-shared value of the exponentiation for every exponent provided.
- Raises:
NotImplementedError – Raised when size of domain is greater than twice the size of the maximum upper bound.