Trait concrete_npe::lwe::LWE [−][src]
pub trait LWE: Sized {
type STorus;
fn single_scalar_mul(variance: f64, n: Self) -> f64;
fn scalar_mul(var_out: &mut [f64], var_in: &[f64], t: &[Self]);
fn scalar_mul_inplace(var: &mut [f64], t: &[Self]);
fn multisum_uncorrelated(variances: &[f64], weights: &[Self]) -> f64;
fn key_switch(
dimension_before: usize,
l_ks: usize,
base_log: usize,
var_ks: f64,
var_input_lwe: f64
) -> f64;
}
Associated Types
Required methods
fn single_scalar_mul(variance: f64, n: Self) -> f64
Implementations on Foreign Types
Return the variance of the keyswitch on a LWE sample given a set of parameters. To see how to use it, please refer to the test of the keyswitch
Warning
- This function compute the noise of the keyswitch without functional evaluation
Arguments
dimension_before
- size of the input LWE mask
l_ks
- number of level max for the torus decomposition
base_log
- number of bits for the base B (B=2^base_log)
var_ks
- variance of the keyswitching key
var_input
- variance of the input LWE
Example
use concrete_npe::LWE ;
type Torus = u32;
// settings
let dimension_before: usize = 630 ;
let l_ks: usize = 4 ;
let base_log: usize = 7 ;
let var_ks: f64 = f64::powi(2., -38) ;
let var_input: f64 = f64::powi(2., -40) ;
// Computing the noise
let var_ks = <Torus as LWE>::key_switch(dimension_before, l_ks, base_log, var_ks,
var_input) ;
Computes the variance of the error distribution after a multiplication of a ciphertext by a scalar i.e. sigma_out^2 <- n^2 * sigma^2 Arguments
variance
- variance of the input LWEn
- a signed integer Output- the output variance
Example
use concrete_npe::LWE ;
type Torus = u32;
// parameters
let variance: f64 = f64::powi(2., -48) ;
let n: Torus = (-543 as i64) as Torus ;
// noise computation
let noise: f64 = <Torus as LWE>::single_scalar_mul(variance, n) ;
Computes the variance of the error distribution after a multisum between uncorrelated ciphertexts and scalar weights i.e. sigma_out^2 <- \Sum_i weight_i^2 * sigma_i^2 Arguments
variances
- a slice of f64 with the error variances of all the input uncorrelated ciphertextsweights
- a slice of Torus with the input weights Output- the output variance
Example
use concrete_npe::LWE ;
type Torus = u32;
// parameters
let variances: Vec<f64> = vec![f64::powi(2., -30), f64::powi(2., -32)] ;
let weights: Vec<Torus> = vec![(-543 as i64) as Torus, 10 as Torus] ;
// noise computation
let noise: f64 = <Torus as LWE>::multisum_uncorrelated(&variances, &weights) ;
Computes the variance of the error distribution after a multiplication of several ciphertexts by several scalars Arguments
var_out
- variances of the output LWEs (output)var_in
- variances of the input LWEst
- a slice of signed integer
Example
use concrete_npe::LWE ;
type Torus = u32;
// parameters
let var_in: Vec<f64> = vec![f64::powi(2., -30), f64::powi(2., -32)] ;
let weights: Vec<Torus> = vec![(-543 as i64) as Torus, 10 as Torus] ;
// noise computation
let mut var_out: Vec<f64> = vec![0.; 2] ;
<Torus as LWE>::scalar_mul(&mut var_out, &var_in, &weights) ;
Computes the variance of the error distribution after a multiplication of several ciphertexts by several scalars Arguments
var
- variances of the input/output LWEs (output)t
- a slice of signed integer
Example
use concrete_npe::LWE ;
type Torus = u32;
// parameters
let mut var: Vec<f64> = vec![f64::powi(2., -30), f64::powi(2., -32)] ;
let weights: Vec<Torus> = vec![(-543 as i64) as Torus, 10 as Torus] ;
// noise computation
<Torus as LWE>::scalar_mul_inplace(&mut var, &weights) ;
Return the variance of the keyswitch on a LWE sample given a set of parameters. To see how to use it, please refer to the test of the keyswitch
Warning
- This function compute the noise of the keyswitch without functional evaluation
Arguments
dimension_before
- size of the input LWE mask
l_ks
- number of level max for the torus decomposition
base_log
- number of bits for the base B (B=2^base_log)
var_ks
- variance of the keyswitching key
var_input
- variance of the input LWE
Example
use concrete_npe::LWE ;
type Torus = u64;
// settings
let dimension_before: usize = 630 ;
let l_ks: usize = 4 ;
let base_log: usize = 7 ;
let var_ks: f64 = f64::powi(2., -38) ;
let var_input: f64 = f64::powi(2., -40) ;
// Computing the noise
let var_ks = <Torus as LWE>::key_switch(dimension_before, l_ks, base_log, var_ks,
var_input) ;
Computes the variance of the error distribution after a multiplication of a ciphertext by a scalar i.e. sigma_out^2 <- n^2 * sigma^2 Arguments
variance
- variance of the input LWEn
- a signed integer Output- the output variance
Example
use concrete_npe::LWE ;
type Torus = u64;
// parameters
let variance: f64 = f64::powi(2., -48) ;
let n: Torus = (-543 as i64) as Torus ;
// noise computation
let noise: f64 = <Torus as LWE>::single_scalar_mul(variance, n) ;
Computes the variance of the error distribution after a multisum between uncorrelated ciphertexts and scalar weights i.e. sigma_out^2 <- \Sum_i weight_i^2 * sigma_i^2 Arguments
variances
- a slice of f64 with the error variances of all the input uncorrelated ciphertextsweights
- a slice of Torus with the input weights Output- the output variance
Example
use concrete_npe::LWE ;
type Torus = u64;
// parameters
let variances: Vec<f64> = vec![f64::powi(2., -30), f64::powi(2., -32)] ;
let weights: Vec<Torus> = vec![(-543 as i64) as Torus, 10 as Torus] ;
// noise computation
let noise: f64 = <Torus as LWE>::multisum_uncorrelated(&variances, &weights) ;
Computes the variance of the error distribution after a multiplication of several ciphertexts by several scalars Arguments
var_out
- variances of the output LWEs (output)var_in
- variances of the input LWEst
- a slice of signed integer
Example
use concrete_npe::LWE ;
type Torus = u64;
// parameters
let var_in: Vec<f64> = vec![f64::powi(2., -30), f64::powi(2., -32)] ;
let weights: Vec<Torus> = vec![(-543 as i64) as Torus, 10 as Torus] ;
// noise computation
let mut var_out: Vec<f64> = vec![0.; 2] ;
<Torus as LWE>::scalar_mul(&mut var_out, &var_in, &weights) ;
Computes the variance of the error distribution after a multiplication of several ciphertexts by several scalars Arguments
var
- variances of the input/output LWEs (output)t
- a slice of signed integer
Example
use concrete_npe::LWE ;
type Torus = u64;
// parameters
let mut var: Vec<f64> = vec![f64::powi(2., -30), f64::powi(2., -32)] ;
let weights: Vec<Torus> = vec![(-543 as i64) as Torus, 10 as Torus] ;
// noise computation
<Torus as LWE>::scalar_mul_inplace(&mut var, &weights) ;