mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-09 14:47:56 -05:00
chore: update noise formulas with latest automated code gen
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
/// This formula is only valid when going from a larger to a smaller modulus
|
||||
/// This formula is based on a heuristic, so may not always be valid
|
||||
pub fn centered_binary_shifted_modulus_switch_additive_variance(
|
||||
input_lwe_dimension: LweDimension,
|
||||
modulus: f64,
|
||||
new_modulus: f64,
|
||||
) -> Variance {
|
||||
Variance(
|
||||
centered_binary_shifted_modulus_switch_additive_variance_impl(
|
||||
input_lwe_dimension.0 as f64,
|
||||
modulus,
|
||||
new_modulus,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// This formula is only valid when going from a larger to a smaller modulus
|
||||
/// This formula is based on a heuristic, so may not always be valid
|
||||
pub fn centered_binary_shifted_modulus_switch_additive_variance_impl(
|
||||
input_lwe_dimension: f64,
|
||||
modulus: f64,
|
||||
new_modulus: f64,
|
||||
) -> f64 {
|
||||
input_lwe_dimension
|
||||
* (0.0416666666666667 * modulus.powf(-2.0) + 0.0208333333333333 * new_modulus.powf(-2.0))
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
@@ -41,8 +45,14 @@ pub fn multi_bit_pbs_variance_132_bits_security_gaussian_gf_2_fft_mul_impl(
|
||||
(1_f64 / 2.0)
|
||||
* input_lwe_dimension
|
||||
* (0.0022
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.04148)
|
||||
* output_glwe_dimension.powf(1.94548)
|
||||
@@ -105,8 +115,14 @@ pub fn multi_bit_pbs_variance_132_bits_security_gaussian_gf_3_fft_mul_impl(
|
||||
(1_f64 / 3.0)
|
||||
* input_lwe_dimension
|
||||
* (0.00492
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.0111)
|
||||
* output_glwe_dimension.powf(1.90722)
|
||||
@@ -169,8 +185,14 @@ pub fn multi_bit_pbs_variance_132_bits_security_gaussian_gf_4_fft_mul_impl(
|
||||
(1_f64 / 4.0)
|
||||
* input_lwe_dimension
|
||||
* (0.00855
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.00715)
|
||||
* output_glwe_dimension.powf(1.90759)
|
||||
@@ -233,8 +255,14 @@ pub fn multi_bit_pbs_variance_132_bits_security_tuniform_gf_2_fft_mul_impl(
|
||||
(1_f64 / 2.0)
|
||||
* input_lwe_dimension
|
||||
* (0.0022
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.04148)
|
||||
* output_glwe_dimension.powf(1.94548)
|
||||
@@ -303,8 +331,14 @@ pub fn multi_bit_pbs_variance_132_bits_security_tuniform_gf_3_fft_mul_impl(
|
||||
(1_f64 / 3.0)
|
||||
* input_lwe_dimension
|
||||
* (0.00492
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.0111)
|
||||
* output_glwe_dimension.powf(1.90722)
|
||||
@@ -373,8 +407,14 @@ pub fn multi_bit_pbs_variance_132_bits_security_tuniform_gf_4_fft_mul_impl(
|
||||
(1_f64 / 4.0)
|
||||
* input_lwe_dimension
|
||||
* (0.00855
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.00715)
|
||||
* output_glwe_dimension.powf(1.90759)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
@@ -28,7 +32,6 @@ pub fn pbs_variance_132_bits_security_gaussian_fft_mul(
|
||||
/// if the keys used are encrypted using secure noise given by the
|
||||
/// [`minimal_glwe_variance`](`super::secure_noise`)
|
||||
/// and [`minimal_lwe_variance`](`super::secure_noise`) family of functions.
|
||||
#[allow(clippy::suspicious_operation_groupings)]
|
||||
pub fn pbs_variance_132_bits_security_gaussian_fft_mul_impl(
|
||||
input_lwe_dimension: f64,
|
||||
output_glwe_dimension: f64,
|
||||
@@ -39,8 +42,14 @@ pub fn pbs_variance_132_bits_security_gaussian_fft_mul_impl(
|
||||
) -> f64 {
|
||||
input_lwe_dimension
|
||||
* (0.00705
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.01827)
|
||||
* output_glwe_dimension.powf(1.22003)
|
||||
@@ -100,8 +109,14 @@ pub fn pbs_variance_132_bits_security_tuniform_fft_mul_impl(
|
||||
) -> f64 {
|
||||
input_lwe_dimension
|
||||
* (0.00705
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(core::f64::consts::LOG2_E * modulus.ln() - 53.0))
|
||||
* (2.0
|
||||
* if (core::f64::consts::LOG2_E * modulus.ln() - 53.0 <= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
core::f64::consts::LOG2_E * modulus.ln() - 53.0
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.01827)
|
||||
* output_glwe_dimension.powf(1.22003)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
@@ -30,7 +34,6 @@ pub fn pbs_128_variance_132_bits_security_gaussian_fft_mul(
|
||||
/// if the keys used are encrypted using secure noise given by the
|
||||
/// [`minimal_glwe_variance`](`super::secure_noise`)
|
||||
/// and [`minimal_lwe_variance`](`super::secure_noise`) family of functions.
|
||||
#[allow(clippy::suspicious_operation_groupings)]
|
||||
pub fn pbs_128_variance_132_bits_security_gaussian_fft_mul_impl(
|
||||
input_lwe_dimension: f64,
|
||||
output_glwe_dimension: f64,
|
||||
@@ -42,8 +45,14 @@ pub fn pbs_128_variance_132_bits_security_gaussian_fft_mul_impl(
|
||||
) -> f64 {
|
||||
input_lwe_dimension
|
||||
* (0.00705
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(-mantissa_size + core::f64::consts::LOG2_E * modulus.ln()))
|
||||
* (2.0
|
||||
* if (1.0 * mantissa_size - core::f64::consts::LOG2_E * modulus.ln() >= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
-1.0 * mantissa_size + core::f64::consts::LOG2_E * modulus.ln()
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.01827)
|
||||
* output_glwe_dimension.powf(1.22003)
|
||||
@@ -106,8 +115,14 @@ pub fn pbs_128_variance_132_bits_security_tuniform_fft_mul_impl(
|
||||
) -> f64 {
|
||||
input_lwe_dimension
|
||||
* (0.00705
|
||||
* (2.88539008177793 * decomposition_base.ln() - 2.88539008177793 * modulus.ln()
|
||||
+ 2.0 * 0.0f64.max(-mantissa_size + core::f64::consts::LOG2_E * modulus.ln()))
|
||||
* (2.0
|
||||
* if (1.0 * mantissa_size - core::f64::consts::LOG2_E * modulus.ln() >= 0.0) {
|
||||
0.0
|
||||
} else {
|
||||
-1.0 * mantissa_size + core::f64::consts::LOG2_E * modulus.ln()
|
||||
}
|
||||
+ 2.88539008177793 * decomposition_base.ln()
|
||||
- 2.88539008177793 * modulus.ln())
|
||||
.exp2()
|
||||
* decomposition_level_count.powf(1.01827)
|
||||
* output_glwe_dimension.powf(1.22003)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
pub mod centered_mean_shifted_modulus_switch;
|
||||
pub mod generalized_modulus_switch;
|
||||
pub mod lwe_keyswitch;
|
||||
pub mod lwe_multi_bit_programmable_bootstrap;
|
||||
@@ -7,5 +8,6 @@ pub mod lwe_programmable_bootstrap;
|
||||
pub mod lwe_programmable_bootstrap_128;
|
||||
pub mod modulus_switch;
|
||||
pub mod multi_bit_modulus_switch;
|
||||
pub mod noise_simulation;
|
||||
pub mod secure_noise;
|
||||
|
||||
pub mod noise_simulation;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
@@ -24,10 +28,14 @@ pub fn multi_bit_modulus_switch_additive_variance_impl(
|
||||
modulus: f64,
|
||||
new_modulus: f64,
|
||||
) -> f64 {
|
||||
(1_f64 / 12.0) / new_modulus.powi(2) - (1_f64 / 12.0) / modulus.powi(2)
|
||||
+ input_lwe_dimension
|
||||
* (1.0 - (-grouping_factor).exp2())
|
||||
* ((-grouping_factor - 2.0).exp2()
|
||||
+ (1_f64 / 12.0) * (modulus.powi(2) - new_modulus.powi(2)) / new_modulus.powi(2))
|
||||
/ (grouping_factor * modulus.powi(2))
|
||||
grouping_factor.recip()
|
||||
* input_lwe_dimension
|
||||
* modulus.powf(-2.0)
|
||||
* (1.0 - 1.0 * (-1.0 * grouping_factor).exp2())
|
||||
* ((-1.0 * grouping_factor - 2.0).exp2()
|
||||
+ (1_f64 / 12.0)
|
||||
* new_modulus.powf(-2.0)
|
||||
* (modulus.powf(2.0) - 1.0 * new_modulus.powf(2.0)))
|
||||
- 1_f64 / 12.0 * modulus.powf(-2.0)
|
||||
+ (1_f64 / 12.0) * new_modulus.powf(-2.0)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// This file was autogenerated, do not modify by hand.
|
||||
#![allow(unused_parens)]
|
||||
#![allow(clippy::neg_multiply)]
|
||||
#![allow(clippy::suspicious_operation_groupings)]
|
||||
|
||||
use crate::core_crypto::commons::dispersion::Variance;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user