From 956f2ee548c8a7f126ef953bcb233fa91a0c65b2 Mon Sep 17 00:00:00 2001 From: Ludo Pulles Date: Wed, 25 Sep 2024 13:02:57 +0200 Subject: [PATCH] Use hamming weight instead of own computation --- estimator/lwe_guess.py | 2 +- estimator/lwe_parameters.py | 6 +++--- estimator/lwe_primal.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/estimator/lwe_guess.py b/estimator/lwe_guess.py index 89d29f5..0b96faf 100644 --- a/estimator/lwe_guess.py +++ b/estimator/lwe_guess.py @@ -102,7 +102,7 @@ def sparse_solve(cls, f, params, log_level=5, **kwds): :param params: LWE parameters. """ base = params.Xs.bounds[1] - params.Xs.bounds[0] # we exclude zero - h = ceil(len(params.Xs) * params.Xs.density) # nr of non-zero entries + h = params.Xs.hamming_weight with local_minimum(0, params.n - 40, log_level=log_level) as it: for zeta in it: diff --git a/estimator/lwe_parameters.py b/estimator/lwe_parameters.py index 23e2522..da969ca 100644 --- a/estimator/lwe_parameters.py +++ b/estimator/lwe_parameters.py @@ -140,10 +140,10 @@ def switch_modulus(self): LWEParameters(n=128, q=5289, Xs=D(σ=0.82), Xe=D(σ=3.08), m=+Infinity, tag=None) """ - n = self.Xs.density * len(self.Xs) + h = self.Xs.hamming_weight - # n uniform in -(0.5,0.5) ± stddev(χ_s) - Xr_stddev = sqrt(n / 12) * self.Xs.stddev # rounding noise + # h uniform in -(0.5,0.5) ± stddev(χ_s) + Xr_stddev = sqrt(h / 12) * self.Xs.stddev # rounding noise # χ_r == p/q ⋅ χ_e # we want the rounding noise match the scaled noise p = ceil(Xr_stddev * self.q / self.Xe.stddev) diff --git a/estimator/lwe_primal.py b/estimator/lwe_primal.py index c47fc39..ae3f19a 100644 --- a/estimator/lwe_primal.py +++ b/estimator/lwe_primal.py @@ -390,7 +390,7 @@ def ssf(x): if zeta: # the number of non-zero entries - h = ceil(len(params.Xs) * params.Xs.density) + h = params.Xs.hamming_weight probability = RR(prob_drop(params.n, h, zeta)) hw = 1 while hw < min(h, zeta):